Skip to content

Commit

Permalink
Updates/Removes recordings to use Proxy (#35544)
Browse files Browse the repository at this point in the history
* Use ProxyTestBase.

* Fix issue with choosing non-existent subscription.

* RE-record

* Add sanitizers and matchers.

* Only add sanitizers in non-live mode. Fix usage of wrong subscription name.
  • Loading branch information
conniey authored Jun 20, 2023
1 parent a209338 commit cf5c9fa
Show file tree
Hide file tree
Showing 87 changed files with 70 additions and 1,982 deletions.
6 changes: 6 additions & 0 deletions sdk/servicebus/azure-messaging-servicebus/assets.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"AssetsRepo": "Azure/azure-sdk-assets",
"AssetsRepoPrefixPath": "java",
"TagPrefix": "java/servicebus/azure-messaging-servicebus",
"Tag": "java/servicebus/azure-messaging-servicebus_cfc0818a47"
}
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ protected ServiceBusReceiverClientBuilder getReceiverBuilder(boolean useCredenti
return builder.receiver().receiveMode(ServiceBusReceiveMode.PEEK_LOCK).queueName(queueName);
case SUBSCRIPTION:
final String topicName = getTopicName(entityIndex);
final String subscriptionName = getEntityName(getSubscriptionBaseName(), 2);
final String subscriptionName = getSubscriptionBaseName();
assertNotNull(topicName, "'topicName' cannot be null.");
assertNotNull(subscriptionName, "'subscriptionName' cannot be null.");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,12 +240,20 @@ void crossEntitySubscriptionTransaction(boolean isSessionEnabled) throws Interru
final ServiceBusProcessorClient processorA;
// Initialize processor client
if (isSessionEnabled) {
processorA = toClose(builder.sessionProcessor().disableAutoComplete().topicName(topicA).subscriptionName("subscription-session")
.processMessage(processMessage).processError(processError)
processorA = toClose(builder.sessionProcessor()
.disableAutoComplete()
.topicName(topicA)
.subscriptionName(TestUtils.getSessionSubscriptionBaseName())
.processMessage(processMessage)
.processError(processError)
.buildProcessorClient());
} else {
processorA = toClose(builder.processor().disableAutoComplete().topicName(topicA).subscriptionName("subscription")
.processMessage(processMessage).processError(processError)
processorA = toClose(builder.processor()
.disableAutoComplete()
.topicName(topicA)
.subscriptionName(TestUtils.getSubscriptionBaseName())
.processMessage(processMessage)
.processError(processError)
.buildProcessorClient());
}

Expand Down Expand Up @@ -404,10 +412,10 @@ void crossEntitySubscriptionTransactionWithReceiverSenderTest(boolean isSessionE
final ServiceBusReceiverAsyncClient receiverA;

if (isSessionEnabled) {
receiverA = builder.sessionReceiver().disableAutoComplete().topicName(topicA).subscriptionName("subscription-session")
receiverA = builder.sessionReceiver().disableAutoComplete().topicName(topicA).subscriptionName(TestUtils.getSessionSubscriptionBaseName())
.buildAsyncClient().acceptNextSession().block();
} else {
receiverA = builder.receiver().disableAutoComplete().topicName(topicA).subscriptionName("subscription")
receiverA = builder.receiver().disableAutoComplete().topicName(topicA).subscriptionName(TestUtils.getSubscriptionBaseName())
.buildAsyncClient();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicReference;

import static com.azure.messaging.servicebus.TestUtils.getEntityName;
import static com.azure.messaging.servicebus.TestUtils.getServiceBusMessage;
import static com.azure.messaging.servicebus.TestUtils.getSessionSubscriptionBaseName;
import static com.azure.messaging.servicebus.TestUtils.getSubscriptionBaseName;
Expand Down Expand Up @@ -210,7 +209,7 @@ private ServiceBusClientBuilder.ServiceBusProcessorClientBuilder getProcessorBui
return builder.processor().queueName(queueName);
case SUBSCRIPTION:
final String topicName = getTopicName(entityIndex);
final String subscriptionName = getEntityName(getSubscriptionBaseName(), 2);
final String subscriptionName = getSubscriptionBaseName();
assertNotNull(topicName, "'topicName' cannot be null.");
assertNotNull(subscriptionName, "'subscriptionName' cannot be null.");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public class TestUtils {
/**
* Namespace used to record tests.
*/
public static final String TEST_NAMESPACE = "sb-java-conniey-sbd";
public static final String TEST_NAMESPACE = "sb-java-conniey-sba";

/**
* Gets the namespace connection string.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@
import com.azure.core.http.netty.NettyAsyncHttpClientBuilder;
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.TestProxyTestBase;
import com.azure.core.test.models.CustomMatcher;
import com.azure.core.test.models.TestProxyRequestMatcher;
import com.azure.core.test.models.TestProxySanitizer;
import com.azure.core.test.models.TestProxySanitizerType;
import com.azure.identity.DefaultAzureCredentialBuilder;
import com.azure.messaging.servicebus.TestUtils;
import com.azure.messaging.servicebus.administration.models.AccessRights;
Expand Down Expand Up @@ -47,6 +51,7 @@
import java.time.Clock;
import java.time.Duration;
import java.time.OffsetDateTime;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.stream.Stream;
Expand All @@ -67,9 +72,30 @@
* Tests {@link ServiceBusAdministrationAsyncClient}.
*/
@Tag("integration")
class ServiceBusAdministrationAsyncClientIntegrationTest extends TestBase {
class ServiceBusAdministrationAsyncClientIntegrationTest extends TestProxyTestBase {
private static final Duration TIMEOUT = Duration.ofSeconds(20);

/**
* Sanitizer to remove header values for ServiceBusDlqSupplementaryAuthorization and
* ServiceBusSupplementaryAuthorization.
*/
static final TestProxySanitizer AUTHORIZATION_HEADER;

static final List<TestProxySanitizer> TEST_PROXY_SANITIZERS;

static final List<TestProxyRequestMatcher> TEST_PROXY_REQUEST_MATCHERS;


static {
AUTHORIZATION_HEADER = new TestProxySanitizer("SupplementaryAuthorization", "SharedAccessSignature sr=https%3A%2F%2Ffoo.servicebus.windows.net&sig=dummyValue%3D&se=1687267490&skn=dummyKey", TestProxySanitizerType.HEADER);
TEST_PROXY_SANITIZERS = Collections.singletonList(AUTHORIZATION_HEADER);

final List<String> skippedHeaders = Arrays.asList("ServiceBusDlqSupplementaryAuthorization", "ServiceBusSupplementaryAuthorization");
final CustomMatcher customMatcher = new CustomMatcher().setExcludedHeaders(skippedHeaders);

TEST_PROXY_REQUEST_MATCHERS = Collections.singletonList(customMatcher);
}

@BeforeAll
static void beforeAll() {
StepVerifier.setDefaultTimeout(Duration.ofSeconds(10));
Expand Down Expand Up @@ -1025,6 +1051,11 @@ private ServiceBusAdministrationAsyncClient createClient(HttpClient httpClient)
.addPolicy(interceptorManager.getRecordPolicy());
}

if (!interceptorManager.isLiveMode()) {
interceptorManager.addSanitizers(TEST_PROXY_SANITIZERS);
interceptorManager.addMatchers(TEST_PROXY_REQUEST_MATCHERS);
}

return builder.buildAsyncClient();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import com.azure.core.http.policy.RetryOptions;
import com.azure.core.http.rest.PagedIterable;
import com.azure.core.http.rest.Response;
import com.azure.core.test.TestBase;
import com.azure.core.test.TestProxyTestBase;
import com.azure.messaging.servicebus.TestUtils;
import com.azure.messaging.servicebus.administration.implementation.models.ServiceBusManagementErrorException;
import com.azure.messaging.servicebus.administration.models.AccessRights;
Expand Down Expand Up @@ -67,7 +67,7 @@
* Tests {@link ServiceBusAdministrationClient}.
*/
@Tag("integration")
public class ServiceBusAdministrationClientIntegrationTest extends TestBase {
public class ServiceBusAdministrationClientIntegrationTest extends TestProxyTestBase {
private static final Duration TIMEOUT = Duration.ofSeconds(20);

/**
Expand Down Expand Up @@ -210,7 +210,7 @@ void createRule() {

final String ruleName = testResourceNamer.randomName("rule", 5);
final String topicName = getEntityName(getTopicBaseName(), 2);
final String subscriptionName = getEntityName(getSubscriptionBaseName(), 2);
final String subscriptionName = getSubscriptionBaseName();
final SqlRuleAction action = new SqlRuleAction("SET Label = 'test'");
final CreateRuleOptions options = new CreateRuleOptions()
.setAction(action)
Expand Down Expand Up @@ -501,7 +501,7 @@ void getSubscriptionDoesNotExist() {
void getSubscriptionExists() {
final ServiceBusAdministrationClient client = getClient();
final String topicName = getEntityName(getTopicBaseName(), 2);
final String subscriptionName = getEntityName(getSubscriptionBaseName(), 2);
final String subscriptionName = getSubscriptionBaseName();

assertTrue(client.getSubscriptionExists(topicName, subscriptionName));
}
Expand All @@ -510,7 +510,7 @@ void getSubscriptionExists() {
void getSubscriptionRuntimeProperties() {
final ServiceBusAdministrationClient client = getClient();
final String topicName = getEntityName(getTopicBaseName(), 2);
final String subscriptionName = getEntityName(getSubscriptionBaseName(), 2);
final String subscriptionName = getSubscriptionBaseName();
final OffsetDateTime nowUtc = OffsetDateTime.now(Clock.systemUTC());

final SubscriptionRuntimeProperties properties = client.getSubscriptionRuntimeProperties(topicName, subscriptionName);
Expand Down Expand Up @@ -594,7 +594,7 @@ void deleteRule() {
final ServiceBusAdministrationClient client = getClient();
final String ruleName = getEntityName(getRuleBaseName(), 9);
final String topicName = getEntityName(getTopicBaseName(), 2);
final String subscriptionName = getEntityName(getSubscriptionBaseName(), 2);
final String subscriptionName = getSubscriptionBaseName();
client.createRule(topicName, subscriptionName, ruleName);

client.deleteRule(topicName, subscriptionName, ruleName);
Expand Down Expand Up @@ -698,6 +698,12 @@ private ServiceBusAdministrationClient getClient() {
} else if (interceptorManager.isRecordMode()) {
builder.addPolicy(interceptorManager.getRecordPolicy());
}

if (!interceptorManager.isLiveMode()) {
interceptorManager.addSanitizers(ServiceBusAdministrationAsyncClientIntegrationTest.TEST_PROXY_SANITIZERS);
interceptorManager.addMatchers(ServiceBusAdministrationAsyncClientIntegrationTest.TEST_PROXY_REQUEST_MATCHERS);
}

return builder.buildClient();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import com.azure.core.http.policy.HttpPipelinePolicy;
import com.azure.core.http.policy.UserAgentPolicy;
import com.azure.core.http.rest.Response;
import com.azure.core.test.TestBase;
import com.azure.core.test.TestProxyTestBase;
import com.azure.core.util.Context;
import com.azure.core.util.logging.ClientLogger;
import com.azure.messaging.servicebus.ServiceBusServiceVersion;
Expand Down Expand Up @@ -49,7 +49,7 @@
/**
* Integration tests for {@link ServiceBusManagementClientImpl}.
*/
class ServiceBusAdministrationClientImplIntegrationTests extends TestBase {
class ServiceBusAdministrationClientImplIntegrationTests extends TestProxyTestBase {
private static final ClientLogger LOGGER = new ClientLogger(ServiceBusAdministrationClientImplIntegrationTests.class);
private final ServiceBusManagementSerializer serializer = new ServiceBusManagementSerializer();
private final Duration timeout = Duration.ofSeconds(30);
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Loading

0 comments on commit cf5c9fa

Please sign in to comment.