Skip to content

Commit

Permalink
update to test proxy re-record
Browse files Browse the repository at this point in the history
  • Loading branch information
samvaity committed Apr 12, 2023
1 parent e8fd6ea commit 6a2288d
Show file tree
Hide file tree
Showing 142 changed files with 28,951 additions and 12,102 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -170,10 +170,10 @@ private MetricsAdvisorAdministrationClientBuilder createClientBuilder(HttpClient
final MetricsAdvisorAdministrationClientBuilder clientBuilder = new MetricsAdvisorAdministrationClientBuilder()
.credential(credential)
.endpoint(endpoint)
.httpClient(httpClient == null ? interceptorManager.getPlaybackClient() : httpClient)
.httpClient(interceptorManager.isPlaybackMode() ? interceptorManager.getPlaybackClient() : httpClient)
.serviceVersion(serviceVersion);

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,24 @@

import com.azure.ai.metricsadvisor.administration.MetricsAdvisorAdministrationClientBuilder;
import com.azure.ai.metricsadvisor.models.MetricsAdvisorKeyCredential;
import com.azure.core.credential.AccessToken;
import com.azure.core.credential.TokenCredential;
import com.azure.core.credential.TokenRequestContext;
import com.azure.core.http.HttpClient;
import com.azure.core.http.policy.HttpLogDetailLevel;
import com.azure.core.http.policy.HttpLogOptions;
import com.azure.core.test.TestBase;
import com.azure.core.test.TestMode;
import com.azure.core.test.TestProxyTestBase;
import com.azure.core.test.http.AssertingHttpClientBuilder;
import com.azure.core.util.Configuration;
import com.azure.identity.DefaultAzureCredentialBuilder;
import reactor.core.publisher.Mono;

import java.time.OffsetDateTime;

import static com.azure.ai.metricsadvisor.MetricsAdvisorClientBuilderTest.PLAYBACK_ENDPOINT;
import static com.azure.ai.metricsadvisor.TestUtils.AZURE_METRICS_ADVISOR_ENDPOINT;

public abstract class MetricsAdvisorAdministrationClientTestBase extends TestBase {
public abstract class MetricsAdvisorAdministrationClientTestBase extends TestProxyTestBase {

@Override
protected void beforeTest() {
Expand All @@ -37,11 +42,11 @@ private HttpClient buildSyncAssertingClient(HttpClient httpClient) {

MetricsAdvisorAdministrationClientBuilder getMetricsAdvisorAdministrationBuilder(HttpClient httpClient,
MetricsAdvisorServiceVersion serviceVersion, boolean isSync) {
HttpClient httpClient1;
HttpClient httpClient1 = interceptorManager.isPlaybackMode() ? interceptorManager.getPlaybackClient() : httpClient;
if (isSync) {
httpClient1 = buildSyncAssertingClient(httpClient == null ? interceptorManager.getPlaybackClient() : httpClient);
httpClient1 = buildSyncAssertingClient(httpClient1);
} else {
httpClient1 = buildAsyncAssertingClient(httpClient == null ? interceptorManager.getPlaybackClient() : httpClient);
httpClient1 = buildAsyncAssertingClient(httpClient1);
}
return getMetricsAdvisorAdministrationBuilderInternal(httpClient1, serviceVersion, true);
}
Expand All @@ -57,20 +62,32 @@ MetricsAdvisorAdministrationClientBuilder getMetricsAdvisorAdministrationBuilder
boolean useKeyCredential) {
MetricsAdvisorAdministrationClientBuilder builder = new MetricsAdvisorAdministrationClientBuilder()
.endpoint(getEndpoint())
.httpClient(httpClient == null ? interceptorManager.getPlaybackClient() : httpClient)
.httpClient(httpClient)
.httpLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BODY_AND_HEADERS))
.serviceVersion(serviceVersion)
.addPolicy(interceptorManager.getRecordPolicy());
.serviceVersion(serviceVersion);

if (getTestMode() == TestMode.PLAYBACK) {
builder.credential(new MetricsAdvisorKeyCredential("subscription_key", "api_key"));
if (useKeyCredential) {
if (interceptorManager.isPlaybackMode()) {
builder.credential(new MetricsAdvisorKeyCredential("subscription_key", "api_key"));
} else if (interceptorManager.isRecordMode()) {
builder
.credential(new MetricsAdvisorKeyCredential(
Configuration.getGlobalConfiguration().get("AZURE_METRICS_ADVISOR_SUBSCRIPTION_KEY"),
Configuration.getGlobalConfiguration().get("AZURE_METRICS_ADVISOR_API_KEY")))
.addPolicy(interceptorManager.getRecordPolicy());
}
} else {
if (useKeyCredential) {
builder.credential(new MetricsAdvisorKeyCredential(
Configuration.getGlobalConfiguration().get("AZURE_METRICS_ADVISOR_SUBSCRIPTION_KEY"),
Configuration.getGlobalConfiguration().get("AZURE_METRICS_ADVISOR_API_KEY")));
} else {
builder.credential(new DefaultAzureCredentialBuilder().build());
if (interceptorManager.isPlaybackMode()) {
builder.credential(new TokenCredential() {
@Override
public Mono<AccessToken> getToken(TokenRequestContext tokenRequestContext) {
return Mono.just(new AccessToken("mockToken", OffsetDateTime.now().plusHours(2)));
}
});
} else if (interceptorManager.isRecordMode()) {
builder
.credential(new DefaultAzureCredentialBuilder().build())
.addPolicy(interceptorManager.getRecordPolicy());
}
}
return builder;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,10 +185,10 @@ private MetricsAdvisorClientBuilder createClientBuilder(HttpClient httpClient, M
final MetricsAdvisorClientBuilder clientBuilder = new MetricsAdvisorClientBuilder()
.credential(credential)
.endpoint(endpoint)
.httpClient(httpClient == null ? interceptorManager.getPlaybackClient() : httpClient)
.httpClient(interceptorManager.isPlaybackMode() ? interceptorManager.getPlaybackClient() : httpClient)
.serviceVersion(serviceVersion);

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,24 @@
package com.azure.ai.metricsadvisor;

import com.azure.ai.metricsadvisor.models.MetricsAdvisorKeyCredential;
import com.azure.core.credential.AccessToken;
import com.azure.core.credential.TokenCredential;
import com.azure.core.credential.TokenRequestContext;
import com.azure.core.http.HttpClient;
import com.azure.core.http.policy.HttpLogDetailLevel;
import com.azure.core.http.policy.HttpLogOptions;
import com.azure.core.test.TestBase;
import com.azure.core.test.TestMode;
import com.azure.core.test.TestProxyTestBase;
import com.azure.core.test.http.AssertingHttpClientBuilder;
import com.azure.core.util.Configuration;
import com.azure.identity.DefaultAzureCredentialBuilder;
import reactor.core.publisher.Mono;

import java.time.OffsetDateTime;

import static com.azure.ai.metricsadvisor.TestUtils.AZURE_METRICS_ADVISOR_ENDPOINT;

public abstract class MetricsAdvisorClientTestBase extends TestBase {
public abstract class MetricsAdvisorClientTestBase extends TestProxyTestBase {

@Override
protected void beforeTest() {
Expand All @@ -35,11 +41,11 @@ private HttpClient buildSyncAssertingClient(HttpClient httpClient) {

MetricsAdvisorClientBuilder getMetricsAdvisorBuilder(HttpClient httpClient,
MetricsAdvisorServiceVersion serviceVersion, boolean isSync) {
HttpClient httpClient1;
HttpClient httpClient1 = interceptorManager.isPlaybackMode() ? interceptorManager.getPlaybackClient() : httpClient;
if (isSync) {
httpClient1 = buildSyncAssertingClient(httpClient == null ? interceptorManager.getPlaybackClient() : httpClient);
httpClient1 = buildSyncAssertingClient(httpClient1);
} else {
httpClient1 = buildAsyncAssertingClient(httpClient == null ? interceptorManager.getPlaybackClient() : httpClient);
httpClient1 = buildAsyncAssertingClient(httpClient1);
}
return getMetricsAdvisorBuilderInternal(httpClient1, serviceVersion, true);
}
Expand All @@ -49,20 +55,32 @@ MetricsAdvisorClientBuilder getMetricsAdvisorBuilderInternal(HttpClient httpClie
boolean useKeyCredential) {
MetricsAdvisorClientBuilder builder = new MetricsAdvisorClientBuilder()
.endpoint(getEndpoint())
.httpClient(httpClient == null ? interceptorManager.getPlaybackClient() : httpClient)
.httpClient(httpClient)
.httpLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BODY_AND_HEADERS))
.serviceVersion(serviceVersion)
.addPolicy(interceptorManager.getRecordPolicy());
.serviceVersion(serviceVersion);

if (getTestMode() == TestMode.PLAYBACK) {
builder.credential(new MetricsAdvisorKeyCredential("subscription_key", "api_key"));
if (useKeyCredential) {
if (interceptorManager.isPlaybackMode()) {
builder.credential(new MetricsAdvisorKeyCredential("subscription_key", "api_key"));
} else if (interceptorManager.isRecordMode()) {
builder
.credential(new MetricsAdvisorKeyCredential(
Configuration.getGlobalConfiguration().get("AZURE_METRICS_ADVISOR_SUBSCRIPTION_KEY"),
Configuration.getGlobalConfiguration().get("AZURE_METRICS_ADVISOR_API_KEY")))
.addPolicy(interceptorManager.getRecordPolicy());
}
} else {
if (useKeyCredential) {
builder.credential(new MetricsAdvisorKeyCredential(
Configuration.getGlobalConfiguration().get("AZURE_METRICS_ADVISOR_SUBSCRIPTION_KEY"),
Configuration.getGlobalConfiguration().get("AZURE_METRICS_ADVISOR_API_KEY")));
} else {
builder.credential(new DefaultAzureCredentialBuilder().build());
if (interceptorManager.isPlaybackMode()) {
builder.credential(new TokenCredential() {
@Override
public Mono<AccessToken> getToken(TokenRequestContext tokenRequestContext) {
return Mono.just(new AccessToken("mockToken", OffsetDateTime.now().plusHours(2)));
}
});
} else if (interceptorManager.isRecordMode()) {
builder
.credential(new DefaultAzureCredentialBuilder().build())
.addPolicy(interceptorManager.getRecordPolicy());
}
}
return builder;
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

Loading

0 comments on commit 6a2288d

Please sign in to comment.