Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integrate sync stack in schema registry via AutoRest. #32576

Merged
merged 11 commits into from
Feb 22, 2023
Prev Previous commit
Next Next commit
add asserting client wrapper to unit tests.
  • Loading branch information
Vinay Gera committed Feb 22, 2023
commit 806e398afba35f2ae1306837ff42510e43f2f0b5
Original file line number Diff line number Diff line change
@@ -6,10 +6,12 @@
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.http.policy.RetryPolicy;
import com.azure.core.test.TestBase;
import com.azure.core.test.http.AssertingHttpClientBuilder;
import com.azure.data.schemaregistry.models.SchemaFormat;
import com.azure.identity.DefaultAzureCredentialBuilder;
import org.junit.jupiter.api.Test;
@@ -65,7 +67,7 @@ protected void beforeTest() {
.fullyQualifiedNamespace(endpoint);

if (interceptorManager.isPlaybackMode()) {
builder.httpClient(interceptorManager.getPlaybackClient());
builder.httpClient(buildAsyncAssertingClient(interceptorManager.getPlaybackClient()));
} else {
builder.addPolicy(new RetryPolicy())
.httpLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BODY_AND_HEADERS))
@@ -80,6 +82,13 @@ protected void afterTest() {
Mockito.framework().clearInlineMock(this);
}

private HttpClient buildAsyncAssertingClient(HttpClient httpClient) {
return new AssertingHttpClientBuilder(httpClient)
.assertAsync()
.skipRequest((httpRequest, context) -> false)
.build();
}

/**
* Verifies that we can register a schema and then get it by its schemaId.
*/
Original file line number Diff line number Diff line change
@@ -6,10 +6,12 @@
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.http.policy.RetryPolicy;
import com.azure.core.test.TestBase;
import com.azure.core.test.http.AssertingHttpClientBuilder;
import com.azure.data.schemaregistry.models.SchemaFormat;
import com.azure.identity.DefaultAzureCredentialBuilder;
import org.junit.jupiter.api.Test;
@@ -68,7 +70,7 @@ protected void beforeTest() {
.fullyQualifiedNamespace(endpoint);

if (interceptorManager.isPlaybackMode()) {
builder.httpClient(interceptorManager.getPlaybackClient());
builder.httpClient(buildAsyncAssertingClient(interceptorManager.getPlaybackClient()));
} else {
builder.addPolicy(new RetryPolicy())
.httpLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BODY_AND_HEADERS))
@@ -83,6 +85,13 @@ protected void afterTest() {
Mockito.framework().clearInlineMock(this);
}

private HttpClient buildAsyncAssertingClient(HttpClient httpClient) {
return new AssertingHttpClientBuilder(httpClient)
.assertAsync()
.skipRequest((httpRequest, context) -> false)
.build();
}

/**
* Verifies that we can register a schema and then get it by its schemaId.
*/
Original file line number Diff line number Diff line change
@@ -6,9 +6,11 @@
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.test.InterceptorManager;
import com.azure.core.test.TestContextManager;
import com.azure.core.test.TestMode;
import com.azure.core.test.http.AssertingHttpClientBuilder;
import com.azure.core.test.implementation.TestingHelpers;
import com.azure.data.schemaregistry.models.SchemaFormat;
import org.junit.jupiter.api.AfterEach;
@@ -86,6 +88,13 @@ public void teardownTest() {
Mockito.framework().clearInlineMock(this);
}

private HttpClient buildAsyncAssertingClient(HttpClient httpClient) {
return new AssertingHttpClientBuilder(httpClient)
.assertAsync()
.skipRequest((httpRequest, context) -> false)
.build();
}

/**
* This is run in playback mode because the GUID is unique for each schema. This is a schema that was previously
* registered in Azure Portal.
@@ -98,7 +107,7 @@ public void getSchemaByIdFromPortal() {
final SchemaRegistryAsyncClient client = new SchemaRegistryClientBuilder()
.fullyQualifiedNamespace(endpoint)
.credential(tokenCredential)
.httpClient(interceptorManager.getPlaybackClient())
.httpClient(buildAsyncAssertingClient(interceptorManager.getPlaybackClient()))
.serviceVersion(SchemaRegistryVersion.V2021_10)
.buildAsyncClient();
final String schemaId = "f45b841fcb88401e961ca45477906be9";
Original file line number Diff line number Diff line change
@@ -8,8 +8,11 @@
import com.azure.core.credential.TokenRequestContext;
import com.azure.core.exception.HttpResponseException;
import com.azure.core.exception.ResourceNotFoundException;
import com.azure.core.http.HttpClient;
import com.azure.core.http.policy.RetryPolicy;
import com.azure.core.test.TestBase;
import com.azure.core.test.http.AssertingHttpClientBuilder;
import com.azure.core.util.Context;
import com.azure.data.schemaregistry.models.SchemaFormat;
import com.azure.data.schemaregistry.models.SchemaProperties;
import com.azure.data.schemaregistry.models.SchemaRegistrySchema;
@@ -73,7 +76,7 @@ protected void beforeTest() {
.fullyQualifiedNamespace(endpoint);

if (interceptorManager.isPlaybackMode()) {
builder.httpClient(interceptorManager.getPlaybackClient());
builder.httpClient(buildSyncAssertingClient(interceptorManager.getPlaybackClient()));
} else {
builder.addPolicy(new RetryPolicy())
.addPolicy(interceptorManager.getRecordPolicy());
@@ -85,6 +88,14 @@ protected void afterTest() {
Mockito.framework().clearInlineMock(this);
}


private HttpClient buildSyncAssertingClient(HttpClient httpClient) {
return new AssertingHttpClientBuilder(httpClient)
.assertSync()
.skipRequest((httpRequest, context) -> false)
.build();
}

/**
* Verifies that we can register a schema and then get it by its schemaId.
*/
@@ -200,18 +211,16 @@ public void registerBadRequest() {
public void registerSchemaInvalidFormat() {
// Arrange
final String schemaName = testResourceNamer.randomName("sch", RESOURCE_LENGTH);
final SchemaRegistryAsyncClient client = builder.buildAsyncClient();
final SchemaRegistryClient client = builder.buildClient();
final SchemaFormat unknownSchemaFormat = SchemaFormat.fromString("protobuf");

// Act & Assert
StepVerifier.create(client.registerSchemaWithResponse(schemaGroup, schemaName, SCHEMA_CONTENT, unknownSchemaFormat))
.expectErrorSatisfies(error -> {
assertTrue(error instanceof HttpResponseException);

final HttpResponseException responseException = ((HttpResponseException) error);
assertEquals(403, responseException.getResponse().getStatusCode());
})
.verify();
try {
client.registerSchemaWithResponse(schemaGroup, schemaName, SCHEMA_CONTENT, unknownSchemaFormat, Context.NONE);

} catch (HttpResponseException e) {
assertEquals(403, e.getResponse().getStatusCode());
}
}

/**