Skip to content

Commit

Permalink
Update some tests to reduce runtime (#39545)
Browse files Browse the repository at this point in the history
  • Loading branch information
alzimmermsft authored Apr 4, 2024
1 parent f10cd0f commit 6f9f7d0
Show file tree
Hide file tree
Showing 7 changed files with 156 additions and 178 deletions.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import com.azure.core.exception.HttpResponseException;
import com.azure.core.http.HttpClient;
import com.azure.core.http.policy.ExponentialBackoffOptions;
import com.azure.core.http.policy.FixedDelay;
import com.azure.core.http.policy.FixedDelayOptions;
import com.azure.core.http.policy.HttpLogDetailLevel;
import com.azure.core.http.policy.HttpLogOptions;
import com.azure.core.http.policy.RetryOptions;
Expand Down Expand Up @@ -158,6 +158,7 @@ public void nullAADCredential() {
public void timeoutPolicy() {
final ConfigurationClient client = new ConfigurationClientBuilder()
.connectionString(FAKE_CONNECTION_STRING)
.retryOptions(new RetryOptions(new FixedDelayOptions(0, Duration.ofMillis(1))))
.addPolicy(new TimeoutPolicy(Duration.ofMillis(1))).buildClient();

assertThrows(RuntimeException.class, () -> client.setConfigurationSetting(key, null, value));
Expand Down Expand Up @@ -239,33 +240,31 @@ public void defaultPipeline() {
@Test
@DoNotRecord
public void clientOptionsIsPreferredOverLogOptions() {
ConfigurationClient configurationClient =
new ConfigurationClientBuilder()
.connectionString(FAKE_CONNECTION_STRING)
.httpLogOptions(new HttpLogOptions().setApplicationId("anOldApplication"))
.clientOptions(new ClientOptions().setApplicationId("aNewApplication"))
.httpClient(httpRequest -> {
assertTrue(httpRequest.getHeaders().getValue("User-Agent").contains("aNewApplication"));
return Mono.just(new MockHttpResponse(httpRequest, 400));
})
.buildClient();
ConfigurationClient configurationClient = new ConfigurationClientBuilder()
.connectionString(FAKE_CONNECTION_STRING)
.retryOptions(new RetryOptions(new FixedDelayOptions(0, Duration.ofMillis(1))))
.httpLogOptions(new HttpLogOptions().setApplicationId("anOldApplication"))
.clientOptions(new ClientOptions().setApplicationId("aNewApplication"))
.httpClient(httpRequest -> {
assertTrue(httpRequest.getHeaders().getValue("User-Agent").contains("aNewApplication"));
return Mono.just(new MockHttpResponse(httpRequest, 400));
})
.buildClient();
assertThrows(HttpResponseException.class, () -> configurationClient.setConfigurationSetting(key, null, value));
}

@Test
@DoNotRecord
public void clientOptionHeadersAreAddedLast() {
ConfigurationClient configurationClient =
new ConfigurationClientBuilder()
.connectionString(FAKE_CONNECTION_STRING)
.clientOptions(new ClientOptions()
.setHeaders(Collections.singletonList(new Header("User-Agent", "custom"))))
.retryPolicy(new RetryPolicy(new FixedDelay(3, Duration.ofMillis(1))))
.httpClient(httpRequest -> {
assertEquals("custom", httpRequest.getHeaders().getValue("User-Agent"));
return Mono.just(new MockHttpResponse(httpRequest, 400));
})
.buildClient();
ConfigurationClient configurationClient = new ConfigurationClientBuilder()
.connectionString(FAKE_CONNECTION_STRING)
.clientOptions(new ClientOptions().setHeaders(Collections.singleton(new Header("User-Agent", "custom"))))
.retryOptions(new RetryOptions(new FixedDelayOptions(0, Duration.ofMillis(1))))
.httpClient(httpRequest -> {
assertEquals("custom", httpRequest.getHeaders().getValue("User-Agent"));
return Mono.just(new MockHttpResponse(httpRequest, 400));
})
.buildClient();
assertThrows(HttpResponseException.class, () -> configurationClient.setConfigurationSetting(key, null, value));
}

Expand Down
Loading

0 comments on commit 6f9f7d0

Please sign in to comment.