Skip to content

Commit

Permalink
refactor + test updates
Browse files Browse the repository at this point in the history
  • Loading branch information
samvaity committed Apr 17, 2023
1 parent 255ca9c commit 2acd440
Show file tree
Hide file tree
Showing 8 changed files with 10,062 additions and 2,911 deletions.
1 change: 0 additions & 1 deletion eng/versioning/version_client.txt
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,6 @@ com.azure.tools:azure-sdk-build-tool;1.0.0-beta.1;1.0.0-beta.2
# version. Unreleased dependencies are only valid for dependency versions.
# Format;
# unreleased_<groupId>:<artifactId>;dependency-version

# note: The unreleased dependencies will not be manipulated with the automatic PR creation code.
# In the pom, the version update tag after the version should name the unreleased package and the dependency version:
# <!-- {x-version-update;unreleased_com.azure:azure-core;dependency} -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,20 +78,31 @@ private ConfigurationAsyncClient getConfigurationAsyncClient(HttpClient httpClie
.connectionString(connectionString)
.serviceVersion(serviceVersion)
.httpLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BODY_AND_HEADERS));

setHttpClient(httpClient, builder);

if (interceptorManager.isRecordMode()) {
builder
.httpClient(buildAsyncAssertingClient(httpClient))
.addPolicy(interceptorManager.getRecordPolicy())
.addPolicy(new RetryPolicy());
} else if (interceptorManager.isPlaybackMode()) {
builder
.httpClient(buildAsyncAssertingClient(interceptorManager.getPlaybackClient()));
interceptorManager.addMatchers(Arrays.asList(new CustomMatcher().setHeadersKeyOnlyMatch(Arrays.asList("Sync-Token"))));
}
return builder.buildAsyncClient();
});
}

private ConfigurationClientBuilder setHttpClient(HttpClient httpClient, ConfigurationClientBuilder builder) {
if (interceptorManager.isRecordMode()) {
return builder
.httpClient(buildAsyncAssertingClient(httpClient));
} else if (interceptorManager.isPlaybackMode()) {
return builder
.httpClient(buildAsyncAssertingClient(interceptorManager.getPlaybackClient()));
}
return builder;
}

private HttpClient buildAsyncAssertingClient(HttpClient httpClient) {
//skip paging requests until #30031 resolved
BiFunction<HttpRequest, com.azure.core.util.Context, Boolean> skipRequestFunction = (request, context) -> {
Expand Down Expand Up @@ -1223,7 +1234,7 @@ public void listRevisionsWithPaginationAndRepeatIterator(HttpClient httpClient,
@MethodSource("com.azure.data.appconfiguration.TestHelper#getTestParameters")
public void listConfigurationSettingsWithPagination(HttpClient httpClient, ConfigurationServiceVersion serviceVersion) {
client = getConfigurationAsyncClient(httpClient, serviceVersion);
final int numberExpected = 13;
final int numberExpected = 50;
List<ConfigurationSetting> settings = new ArrayList<>(numberExpected);
for (int value = 0; value < numberExpected; value++) {
settings.add(new ConfigurationSetting().setKey(keyPrefix + "-" + value).setValue("myValue").setLabel(labelPrefix));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,11 +188,15 @@ public void nullServiceVersion(HttpClient httpClient) {
.connectionString(connectionString)
.retryPolicy(new RetryPolicy())
.httpLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BODY_AND_HEADERS))
.serviceVersion(null)
.httpClient(interceptorManager.isPlaybackMode() ? interceptorManager.getPlaybackClient() : httpClient);
.serviceVersion(null);

if (interceptorManager.isPlaybackMode()) {
clientBuilder.httpClient(interceptorManager.getPlaybackClient());
}
if (interceptorManager.isRecordMode()) {
clientBuilder.addPolicy(interceptorManager.getRecordPolicy());
clientBuilder
.httpClient(httpClient)
.addPolicy(interceptorManager.getRecordPolicy());
}

ConfigurationSetting addedSetting = clientBuilder.buildClient().setConfigurationSetting(key, null, value);
Expand All @@ -215,20 +219,19 @@ public void defaultPipeline() {
.httpLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BODY_AND_HEADERS));

if (interceptorManager.isRecordMode()) {
clientBuilder.addPolicy(interceptorManager.getRecordPolicy());
clientBuilder
.addPolicy(interceptorManager.getRecordPolicy())
.httpClient(HttpClient.createDefault());
}

HttpClient defaultHttpClient = interceptorManager.isPlaybackMode() ? interceptorManager.getPlaybackClient()
: HttpClient.createDefault();
if (interceptorManager.isPlaybackMode()) {
clientBuilder.httpClient(interceptorManager.getPlaybackClient());
}

ConfigurationSetting addedSetting = clientBuilder
.httpClient(defaultHttpClient)
.buildClient()
.setConfigurationSetting(key, null, value);

if (interceptorManager.isPlaybackMode()) {
clientBuilder.httpClient(defaultHttpClient);
}
assertEquals(addedSetting.getKey(), key);
assertEquals(addedSetting.getValue(), value);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,20 +74,30 @@ private ConfigurationClient getConfigurationClient(HttpClient httpClient,
.serviceVersion(serviceVersion)
.httpLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BODY_AND_HEADERS));

setHttpClient(httpClient, builder);

if (interceptorManager.isRecordMode()) {
builder
.httpClient(buildSyncAssertingClient(httpClient))
.addPolicy(interceptorManager.getRecordPolicy())
.addPolicy(new RetryPolicy());
} else if (interceptorManager.isPlaybackMode()) {
builder
.httpClient(buildSyncAssertingClient(interceptorManager.getPlaybackClient()));
interceptorManager.addMatchers(Arrays.asList(new CustomMatcher().setHeadersKeyOnlyMatch(Arrays.asList("Sync-Token"))));
}
return builder.buildClient();
});
}

private ConfigurationClientBuilder setHttpClient(HttpClient httpClient, ConfigurationClientBuilder builder) {
if (interceptorManager.isRecordMode()) {
return builder
.httpClient(buildSyncAssertingClient(httpClient));
} else if (interceptorManager.isPlaybackMode()) {
return builder
.httpClient(buildSyncAssertingClient(interceptorManager.getPlaybackClient()));
}
return builder;
}

private HttpClient buildSyncAssertingClient(HttpClient httpClient) {
//skip paging requests until #30031 resolved
BiFunction<HttpRequest, Context, Boolean> skipRequestFunction = (request, context) -> {
Expand Down Expand Up @@ -625,7 +635,6 @@ public void listWithMultipleKeys(HttpClient httpClient, ConfigurationServiceVers

@ParameterizedTest(name = DISPLAY_NAME_WITH_ARGUMENTS)
@MethodSource("com.azure.data.appconfiguration.TestHelper#getTestParameters")
@Disabled("This was failing even before re-record with Test Proxy")
public void listConfigurationSettingsWithNullSelector(HttpClient httpClient,
ConfigurationServiceVersion serviceVersion) {
client = getConfigurationClient(httpClient, serviceVersion);
Expand Down Expand Up @@ -943,7 +952,7 @@ public void listRevisionsWithPaginationAndRepeatIterator(HttpClient httpClient,
@MethodSource("com.azure.data.appconfiguration.TestHelper#getTestParameters")
public void listConfigurationSettingsWithPagination(HttpClient httpClient, ConfigurationServiceVersion serviceVersion) {
client = getConfigurationClient(httpClient, serviceVersion);
final int numberExpected = 33;
final int numberExpected = 50;
for (int value = 0; value < numberExpected; value++) {
client.setConfigurationSettingWithResponse(new ConfigurationSetting().setKey(keyPrefix + "-" + value).setValue("myValue").setLabel(labelPrefix), false, Context.NONE).getValue();
}
Expand Down
Loading

0 comments on commit 2acd440

Please sign in to comment.