diff --git a/sdk/eventhubs/azure-messaging-eventhubs/src/test/java/com/azure/messaging/eventhubs/BackCompatTest.java b/sdk/eventhubs/azure-messaging-eventhubs/src/test/java/com/azure/messaging/eventhubs/BackCompatTest.java index dbb62f6a9db9..a07d5d0084ae 100644 --- a/sdk/eventhubs/azure-messaging-eventhubs/src/test/java/com/azure/messaging/eventhubs/BackCompatTest.java +++ b/sdk/eventhubs/azure-messaging-eventhubs/src/test/java/com/azure/messaging/eventhubs/BackCompatTest.java @@ -72,7 +72,12 @@ protected void afterTest() { @Test public void backCompatWithJavaSDKOlderThan0110() { // Arrange + final Duration timeout = Duration.ofSeconds(30); final String messageTrackingValue = UUID.randomUUID().toString(); + final PartitionProperties properties = consumer.getPartitionProperties(PARTITION_ID).block(timeout); + + Assertions.assertNotNull(properties); + final EventPosition position = EventPosition.fromSequenceNumber(properties.getLastEnqueuedSequenceNumber(), true); // until version 0.10.0 - we used to have Properties as HashMap // This specific combination is intended to test the back compat - with the new Properties type as HashMap @@ -96,12 +101,13 @@ public void backCompatWithJavaSDKOlderThan0110() { final EventData eventData = serializer.deserialize(message, EventData.class); // Act & Assert - StepVerifier.create(consumer.receiveFromPartition(PARTITION_ID, EventPosition.latest()) + producer.send(eventData, sendOptions).block(TIMEOUT); + + StepVerifier.create(consumer.receiveFromPartition(PARTITION_ID, position) .filter(received -> isMatchingEvent(received, messageTrackingValue)).take(1)) - .then(() -> producer.send(eventData, sendOptions).block(TIMEOUT)) .assertNext(event -> validateAmqpProperties(applicationProperties, event.getData())) .expectComplete() - .verify(Duration.ofSeconds(45)); + .verify(timeout); } private void validateAmqpProperties(Map expected, EventData event) { diff --git a/sdk/eventhubs/azure-messaging-eventhubs/src/test/java/com/azure/messaging/eventhubs/EventHubAsyncClientIntegrationTest.java b/sdk/eventhubs/azure-messaging-eventhubs/src/test/java/com/azure/messaging/eventhubs/EventHubAsyncClientIntegrationTest.java index e7c54bc8865f..35ec17a48f7c 100644 --- a/sdk/eventhubs/azure-messaging-eventhubs/src/test/java/com/azure/messaging/eventhubs/EventHubAsyncClientIntegrationTest.java +++ b/sdk/eventhubs/azure-messaging-eventhubs/src/test/java/com/azure/messaging/eventhubs/EventHubAsyncClientIntegrationTest.java @@ -169,7 +169,7 @@ void getPropertiesWithCredentials() { StepVerifier.create(client.getProperties()) .assertNext(properties -> { Assertions.assertEquals(getEventHubName(), properties.getName()); - Assertions.assertEquals(2, properties.getPartitionIds().stream().count()); + Assertions.assertEquals(3, properties.getPartitionIds().stream().count()); }) .expectComplete() .verify(TIMEOUT); @@ -189,7 +189,7 @@ void getMultipleProperties() { StepVerifier.create(theClient.getProperties()) .assertNext(properties -> { Assertions.assertEquals(getEventHubName(), properties.getName()); - Assertions.assertEquals(2, properties.getPartitionIds().stream().count()); + Assertions.assertEquals(3, properties.getPartitionIds().stream().count()); }) .verifyComplete(); } diff --git a/sdk/eventhubs/azure-messaging-eventhubs/src/test/java/com/azure/messaging/eventhubs/EventHubClientMetadataIntegrationTest.java b/sdk/eventhubs/azure-messaging-eventhubs/src/test/java/com/azure/messaging/eventhubs/EventHubClientMetadataIntegrationTest.java index 0dd3db73b4bc..92941e51898c 100644 --- a/sdk/eventhubs/azure-messaging-eventhubs/src/test/java/com/azure/messaging/eventhubs/EventHubClientMetadataIntegrationTest.java +++ b/sdk/eventhubs/azure-messaging-eventhubs/src/test/java/com/azure/messaging/eventhubs/EventHubClientMetadataIntegrationTest.java @@ -19,7 +19,7 @@ * Tests the metadata operations such as fetching partition properties and event hub properties. */ public class EventHubClientMetadataIntegrationTest extends IntegrationTestBase { - private final String[] expectedPartitionIds = new String[]{"0", "1"}; + private final String[] expectedPartitionIds = new String[]{"0", "1", "2"}; private EventHubAsyncClient client; private String eventHubName; @@ -92,6 +92,7 @@ public void getPartitionPropertiesMultipleCalls() { // Assert StepVerifier.create(partitionProperties) + .assertNext(properties -> Assertions.assertEquals(eventHubName, properties.getEventHubName())) .assertNext(properties -> Assertions.assertEquals(eventHubName, properties.getEventHubName())) .assertNext(properties -> Assertions.assertEquals(eventHubName, properties.getEventHubName())) .verifyComplete(); @@ -111,16 +112,20 @@ public void getPartitionPropertiesInvalidToken() { .buildAsyncClient(); // Act & Assert - StepVerifier.create(invalidClient.getProperties()) - .expectErrorSatisfies(error -> { - Assertions.assertTrue(error instanceof AmqpException); - - AmqpException exception = (AmqpException) error; - Assertions.assertEquals(AmqpErrorCondition.UNAUTHORIZED_ACCESS, exception.getErrorCondition()); - Assertions.assertFalse(exception.isTransient()); - Assertions.assertFalse(CoreUtils.isNullOrEmpty(exception.getMessage())); - }) - .verify(); + try { + StepVerifier.create(invalidClient.getProperties()) + .expectErrorSatisfies(error -> { + Assertions.assertTrue(error instanceof AmqpException); + + AmqpException exception = (AmqpException) error; + Assertions.assertEquals(AmqpErrorCondition.UNAUTHORIZED_ACCESS, exception.getErrorCondition()); + Assertions.assertFalse(exception.isTransient()); + Assertions.assertFalse(CoreUtils.isNullOrEmpty(exception.getMessage())); + }) + .verify(); + } finally { + invalidClient.close(); + } } /** @@ -137,15 +142,19 @@ public void getPartitionPropertiesNonExistentHub() { .buildAsyncClient(); // Act & Assert - StepVerifier.create(invalidClient.getPartitionIds()) - .expectErrorSatisfies(error -> { - Assertions.assertTrue(error instanceof AmqpException); - - AmqpException exception = (AmqpException) error; - Assertions.assertEquals(AmqpErrorCondition.NOT_FOUND, exception.getErrorCondition()); - Assertions.assertFalse(exception.isTransient()); - Assertions.assertFalse(CoreUtils.isNullOrEmpty(exception.getMessage())); - }) - .verify(); + try { + StepVerifier.create(invalidClient.getPartitionIds()) + .expectErrorSatisfies(error -> { + Assertions.assertTrue(error instanceof AmqpException); + + AmqpException exception = (AmqpException) error; + Assertions.assertEquals(AmqpErrorCondition.NOT_FOUND, exception.getErrorCondition()); + Assertions.assertFalse(exception.isTransient()); + Assertions.assertFalse(CoreUtils.isNullOrEmpty(exception.getMessage())); + }) + .verify(); + } finally { + invalidClient.close(); + } } } diff --git a/sdk/eventhubs/azure-messaging-eventhubs/src/test/java/com/azure/messaging/eventhubs/EventHubConsumerAsyncClientIntegrationTest.java b/sdk/eventhubs/azure-messaging-eventhubs/src/test/java/com/azure/messaging/eventhubs/EventHubConsumerAsyncClientIntegrationTest.java index fefd49d7de73..39c46e798aa9 100644 --- a/sdk/eventhubs/azure-messaging-eventhubs/src/test/java/com/azure/messaging/eventhubs/EventHubConsumerAsyncClientIntegrationTest.java +++ b/sdk/eventhubs/azure-messaging-eventhubs/src/test/java/com/azure/messaging/eventhubs/EventHubConsumerAsyncClientIntegrationTest.java @@ -10,8 +10,10 @@ import com.azure.messaging.eventhubs.models.PartitionEvent; import com.azure.messaging.eventhubs.models.ReceiveOptions; import com.azure.messaging.eventhubs.models.SendOptions; +import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Assumptions; +import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; import reactor.core.Disposable; import reactor.core.Disposables; @@ -46,7 +48,7 @@ public class EventHubConsumerAsyncClientIntegrationTest extends IntegrationTestBase { private static final String PARTITION_ID_HEADER = "SENT_PARTITION_ID"; - private final String[] expectedPartitionIds = new String[]{"0", "1"}; + private final String[] expectedPartitionIds = new String[]{"0", "1", "2"}; private static final String MESSAGE_TRACKING_ID = UUID.randomUUID().toString(); @@ -56,6 +58,16 @@ public EventHubConsumerAsyncClientIntegrationTest() { super(new ClientLogger(EventHubConsumerAsyncClientIntegrationTest.class)); } + @BeforeAll + static void beforeAll() { + StepVerifier.setDefaultTimeout(Duration.ofSeconds(30)); + } + + @AfterAll + static void afterAll() { + StepVerifier.resetDefaultTimeout(); + } + @Override protected void beforeTest() { client = createBuilder() @@ -138,21 +150,25 @@ public void parallelCreationOfReceivers() { @Test public void lastEnqueuedInformationIsNotUpdated() { // Arrange - final String secondPartitionId = "1"; - final EventPosition position = EventPosition.fromEnqueuedTime(Instant.now()); + final String firstPartition = "0"; + final PartitionProperties properties = client.getPartitionProperties(firstPartition).block(); + Assertions.assertNotNull(properties); + + final EventPosition position = EventPosition.fromSequenceNumber(properties.getLastEnqueuedSequenceNumber()); final EventHubConsumerAsyncClient consumer = client.createConsumer(DEFAULT_CONSUMER_GROUP_NAME, 1); final ReceiveOptions options = new ReceiveOptions().setTrackLastEnqueuedEventProperties(false); final AtomicBoolean isActive = new AtomicBoolean(true); final int expectedNumber = 5; final EventHubProducerAsyncClient producer = client.createProducer(); - final Disposable producerEvents = getEvents(isActive).flatMap(event -> producer.send(event)).subscribe( - sent -> logger.info("Event sent."), - error -> logger.error("Error sending event", error)); + final SendOptions sendOptions = new SendOptions().setPartitionId(firstPartition); + final Disposable producerEvents = getEvents(isActive) + .flatMap(event -> producer.send(event, sendOptions)) + .subscribe(sent -> logger.info("Event sent."), error -> logger.error("Error sending event", error)); // Act & Assert try { - StepVerifier.create(consumer.receiveFromPartition(secondPartitionId, position, options) + StepVerifier.create(consumer.receiveFromPartition(firstPartition, position, options) .take(expectedNumber)) .assertNext(event -> { Assertions.assertNull(event.getLastEnqueuedEventProperties(), "'lastEnqueuedEventProperties' " @@ -243,7 +259,8 @@ private static void verifyLastRetrieved(AtomicReference TestUtils.isMatchingEvent(event, MESSAGE_TRACKING_ID)) .subscribe( event -> logger.info("C1:\tReceived event sequence: {}", event.getData().getSequenceNumber()), @@ -277,7 +294,7 @@ public void sameOwnerLevelClosesFirstConsumer() throws InterruptedException { logger.info("STARTED CONSUMING FROM PARTITION 1 with C3"); final EventHubConsumerAsyncClient consumer2 = client.createConsumer(DEFAULT_CONSUMER_GROUP_NAME, 1); - subscriptions.add(consumer2.receiveFromPartition(secondPartitionId, position, options) + subscriptions.add(consumer2.receiveFromPartition(lastPartition, position, options) .filter(event -> TestUtils.isMatchingEvent(event, MESSAGE_TRACKING_ID)) .subscribe( event -> logger.info("C3:\tReceived event sequence: {}", event.getData().getSequenceNumber()), @@ -310,7 +327,7 @@ public void getEventHubProperties() { .assertNext(properties -> { Assertions.assertNotNull(properties); Assertions.assertEquals(consumer.getEventHubName(), properties.getName()); - Assertions.assertEquals(2, properties.getPartitionIds().stream().count()); + Assertions.assertEquals(3, properties.getPartitionIds().stream().count()); }).verifyComplete(); } finally { dispose(consumer); @@ -463,8 +480,8 @@ public void receivesMultiplePartitions() { @Test public void multipleReceiversSamePartition() throws InterruptedException { // Arrange - final EventHubConsumerAsyncClient consumer = client.createConsumer(DEFAULT_CONSUMER_GROUP_NAME, 50); - final EventHubConsumerAsyncClient consumer2 = client.createConsumer(DEFAULT_CONSUMER_GROUP_NAME, 50); + final EventHubConsumerAsyncClient consumer = client.createConsumer(DEFAULT_CONSUMER_GROUP_NAME, 1); + final EventHubConsumerAsyncClient consumer2 = client.createConsumer(DEFAULT_CONSUMER_GROUP_NAME, 1); final String partitionId = "1"; final PartitionProperties properties = consumer.getPartitionProperties(partitionId).block(TIMEOUT); Assertions.assertNotNull(properties, "Should have been able to get partition properties."); diff --git a/sdk/eventhubs/azure-messaging-eventhubs/src/test/java/com/azure/messaging/eventhubs/EventHubConsumerClientIntegrationTest.java b/sdk/eventhubs/azure-messaging-eventhubs/src/test/java/com/azure/messaging/eventhubs/EventHubConsumerClientIntegrationTest.java index f0aa90c85b00..36085afda46e 100644 --- a/sdk/eventhubs/azure-messaging-eventhubs/src/test/java/com/azure/messaging/eventhubs/EventHubConsumerClientIntegrationTest.java +++ b/sdk/eventhubs/azure-messaging-eventhubs/src/test/java/com/azure/messaging/eventhubs/EventHubConsumerClientIntegrationTest.java @@ -30,7 +30,7 @@ public class EventHubConsumerClientIntegrationTest extends IntegrationTestBase { private static final int NUMBER_OF_EVENTS = 10; private static final AtomicBoolean HAS_PUSHED_EVENTS = new AtomicBoolean(); - private final String[] expectedPartitionIds = new String[]{"0", "1"}; + private final String[] expectedPartitionIds = new String[]{"0", "1", "2"}; private static volatile IntegrationTestEventData testData = null; @@ -63,6 +63,8 @@ protected void beforeTest() { testData = setupEventTestData(producer, NUMBER_OF_EVENTS, options); } + Assertions.assertNotNull(testData, "'testData' should have been populated."); + startingPosition = EventPosition.fromEnqueuedTime(testData.getEnqueuedTime()); consumer = client.createConsumer(DEFAULT_CONSUMER_GROUP_NAME, DEFAULT_PREFETCH_COUNT); } @@ -242,7 +244,7 @@ public void getEventHubProperties() { final EventHubProperties properties = consumer.getEventHubProperties(); Assertions.assertNotNull(properties); Assertions.assertEquals(consumer.getEventHubName(), properties.getName()); - Assertions.assertEquals(2, properties.getPartitionIds().stream().count()); + Assertions.assertEquals(3, properties.getPartitionIds().stream().count()); } finally { dispose(consumer); } @@ -262,7 +264,7 @@ public void getPartitionIds() { final IterableStream partitionIds = consumer.getPartitionIds(); final List collect = partitionIds.stream().collect(Collectors.toList()); - Assertions.assertEquals(2, collect.size()); + Assertions.assertEquals(3, collect.size()); } finally { dispose(consumer); } diff --git a/sdk/eventhubs/azure-messaging-eventhubs/src/test/java/com/azure/messaging/eventhubs/EventHubProducerAsyncClientIntegrationTest.java b/sdk/eventhubs/azure-messaging-eventhubs/src/test/java/com/azure/messaging/eventhubs/EventHubProducerAsyncClientIntegrationTest.java index ab3114c1924a..345436baf492 100644 --- a/sdk/eventhubs/azure-messaging-eventhubs/src/test/java/com/azure/messaging/eventhubs/EventHubProducerAsyncClientIntegrationTest.java +++ b/sdk/eventhubs/azure-messaging-eventhubs/src/test/java/com/azure/messaging/eventhubs/EventHubProducerAsyncClientIntegrationTest.java @@ -183,7 +183,7 @@ void sendWithCredentials() { StepVerifier.create(client.getEventHubProperties()) .assertNext(properties -> { Assertions.assertEquals(getEventHubName(), properties.getName()); - Assertions.assertEquals(2, properties.getPartitionIds().stream().count()); + Assertions.assertEquals(3, properties.getPartitionIds().stream().count()); }) .expectComplete() .verify(TIMEOUT); diff --git a/sdk/eventhubs/azure-messaging-eventhubs/src/test/java/com/azure/messaging/eventhubs/ProxySendTest.java b/sdk/eventhubs/azure-messaging-eventhubs/src/test/java/com/azure/messaging/eventhubs/ProxySendTest.java index 7de2d3698e96..369bd96276fb 100644 --- a/sdk/eventhubs/azure-messaging-eventhubs/src/test/java/com/azure/messaging/eventhubs/ProxySendTest.java +++ b/sdk/eventhubs/azure-messaging-eventhubs/src/test/java/com/azure/messaging/eventhubs/ProxySendTest.java @@ -10,6 +10,7 @@ import com.azure.messaging.eventhubs.models.EventPosition; import com.azure.messaging.eventhubs.models.SendOptions; import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; import reactor.core.publisher.Flux; @@ -20,7 +21,7 @@ import java.net.ProxySelector; import java.net.SocketAddress; import java.net.URI; -import java.time.Instant; +import java.time.Duration; import java.util.Collections; import java.util.List; import java.util.UUID; @@ -40,6 +41,8 @@ public ProxySendTest() { @BeforeAll public static void initialize() throws Exception { + StepVerifier.setDefaultTimeout(Duration.ofSeconds(30)); + proxyServer = new SimpleProxy(PROXY_PORT); proxyServer.start(t -> { }); @@ -60,6 +63,8 @@ public void connectFailed(URI uri, SocketAddress sa, IOException ioe) { @AfterAll public static void cleanupClient() throws Exception { + StepVerifier.resetDefaultTimeout(); + if (proxyServer != null) { proxyServer.stop(); } @@ -89,7 +94,11 @@ public void sendEvents() { final SendOptions options = new SendOptions().setPartitionId(PARTITION_ID); final EventHubProducerAsyncClient producer = builder.buildAsyncProducerClient(); final Flux events = TestUtils.getEvents(NUMBER_OF_EVENTS, messageId); - final Instant sendTime = Instant.now(); + final PartitionProperties information = producer.getPartitionProperties(PARTITION_ID).block(); + + Assertions.assertNotNull(information, "Should receive partition information."); + + final EventPosition position = EventPosition.fromSequenceNumber(information.getLastEnqueuedSequenceNumber()); final EventHubConsumerAsyncClient consumer = builder .consumerGroup(EventHubClientBuilder.DEFAULT_CONSUMER_GROUP_NAME) .buildAsyncConsumerClient(); @@ -101,7 +110,7 @@ public void sendEvents() { .verify(TIMEOUT); // Assert - StepVerifier.create(consumer.receiveFromPartition(PARTITION_ID, EventPosition.fromEnqueuedTime(sendTime)) + StepVerifier.create(consumer.receiveFromPartition(PARTITION_ID, position) .filter(x -> TestUtils.isMatchingEvent(x, messageId)).take(NUMBER_OF_EVENTS)) .expectNextCount(NUMBER_OF_EVENTS) .expectComplete() diff --git a/sdk/eventhubs/azure-messaging-eventhubs/src/test/java/com/azure/messaging/eventhubs/implementation/ReactorConnectionIntegrationTest.java b/sdk/eventhubs/azure-messaging-eventhubs/src/test/java/com/azure/messaging/eventhubs/implementation/ReactorConnectionIntegrationTest.java deleted file mode 100644 index f31c084fdff0..000000000000 --- a/sdk/eventhubs/azure-messaging-eventhubs/src/test/java/com/azure/messaging/eventhubs/implementation/ReactorConnectionIntegrationTest.java +++ /dev/null @@ -1,106 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -package com.azure.messaging.eventhubs.implementation; - -import com.azure.core.amqp.AmqpTransportType; -import com.azure.core.amqp.ProxyOptions; -import com.azure.core.amqp.implementation.AzureTokenManagerProvider; -import com.azure.core.amqp.implementation.CbsAuthorizationType; -import com.azure.core.amqp.implementation.ClaimsBasedSecurityChannel; -import com.azure.core.amqp.implementation.ConnectionOptions; -import com.azure.core.amqp.implementation.ConnectionStringProperties; -import com.azure.core.amqp.implementation.MessageSerializer; -import com.azure.core.amqp.implementation.ReactorConnection; -import com.azure.core.amqp.implementation.ReactorHandlerProvider; -import com.azure.core.amqp.implementation.ReactorProvider; -import com.azure.core.credential.TokenCredential; -import com.azure.core.util.CoreUtils; -import com.azure.core.util.logging.ClientLogger; -import com.azure.messaging.eventhubs.IntegrationTestBase; -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.Test; -import org.mockito.Mock; -import org.mockito.MockitoAnnotations; -import reactor.core.scheduler.Schedulers; -import reactor.test.StepVerifier; - -import java.time.OffsetDateTime; -import java.time.ZoneOffset; -import java.util.Map; - -import static com.azure.core.amqp.implementation.CbsAuthorizationType.SHARED_ACCESS_SIGNATURE; - -public class ReactorConnectionIntegrationTest extends IntegrationTestBase { - - private ReactorConnection connection; - - @Mock - private MessageSerializer serializer; - private static String product; - private static String clientVersion; - - public ReactorConnectionIntegrationTest() { - super(new ClientLogger(ReactorConnectionIntegrationTest.class)); - } - - @BeforeAll - public static void init() { - Map properties = CoreUtils.getProperties("azure-messaging-eventhubs.properties"); - product = properties.get("name"); - clientVersion = properties.get("version"); - } - - @Override - protected void beforeTest() { - MockitoAnnotations.initMocks(this); - - ConnectionStringProperties connectionString = getConnectionStringProperties(); - - TokenCredential tokenCredential = new EventHubSharedKeyCredential(connectionString.getSharedAccessKeyName(), - connectionString.getSharedAccessKey()); - - final ConnectionOptions options = new ConnectionOptions(connectionString.getEndpoint().getHost(), - connectionString.getEntityPath(), tokenCredential, SHARED_ACCESS_SIGNATURE, AmqpTransportType.AMQP, - RETRY_OPTIONS, ProxyOptions.SYSTEM_DEFAULTS, Schedulers.single()); - - AzureTokenManagerProvider tokenManagerProvider = new AzureTokenManagerProvider(options.getAuthorizationType(), - options.getFullyQualifiedNamespace(), ClientConstants.AZURE_ACTIVE_DIRECTORY_SCOPE); - ReactorProvider reactorProvider = new ReactorProvider(); - ReactorHandlerProvider handlerProvider = new ReactorHandlerProvider(reactorProvider); - connection = new ReactorConnection("test-connection-id", options, reactorProvider, - handlerProvider, tokenManagerProvider, serializer, product, clientVersion); - } - - @Override - protected void afterTest() { - if (connection != null) { - connection.dispose(); - } - } - - @Test - public void getCbsNode() { - // Act & Assert - StepVerifier.create(connection.getClaimsBasedSecurityNode()) - .assertNext(node -> Assertions.assertTrue(node instanceof ClaimsBasedSecurityChannel)) - .verifyComplete(); - } - - @Test - public void getCbsNodeAuthorize() { - // Arrange - final AzureTokenManagerProvider provider = new AzureTokenManagerProvider( - CbsAuthorizationType.SHARED_ACCESS_SIGNATURE, - getConnectionStringProperties().getEndpoint().getHost(), - ClientConstants.AZURE_ACTIVE_DIRECTORY_SCOPE); - - final String tokenAudience = provider.getScopesFromResource(getConnectionStringProperties().getEntityPath()); - - // Act & Assert - StepVerifier.create(connection.getClaimsBasedSecurityNode().flatMap(node -> node.authorize(tokenAudience, tokenAudience))) - .assertNext(expiration -> OffsetDateTime.now(ZoneOffset.UTC).isBefore(expiration)) - .verifyComplete(); - } -} diff --git a/sdk/eventhubs/test-resources.json b/sdk/eventhubs/test-resources.json index 3a1a25ce2541..d4608ba51060 100644 --- a/sdk/eventhubs/test-resources.json +++ b/sdk/eventhubs/test-resources.json @@ -3,7 +3,10 @@ "contentVersion": "1.0.0.0", "parameters": { "baseName": { - "type": "String" + "type": "string", + "metadata": { + "description": "Base name to append to Azure resources." + } }, "storageEndpointSuffix": { "type": "string", @@ -17,23 +20,23 @@ "type": "string", "defaultValue": "servicebus.windows.net" }, - "testApplicationOid": { + "tenantId": { "type": "string", + "defaultValue": "72f988bf-86f1-41af-91ab-2d7cd011db47", "metadata": { - "description": "The principal to assign the role to. This is application object id." + "description": "The tenant id to which the application and resources belong." } }, - "tenantId": { + "testApplicationId": { "type": "string", - "defaultValue": "72f988bf-86f1-41af-91ab-2d7cd011db47", "metadata": { - "description": "The tenant ID to which the application and resources belong." + "description": "The client id of the service principal used to run tests." } }, - "testApplicationId": { + "testApplicationOid": { "type": "string", "metadata": { - "description": "The application client ID used to run tests." + "description": "This is the object id of the service principal used to run tests." } }, "testApplicationSecret": { @@ -44,387 +47,233 @@ } }, "variables": { - "storageApiVersion": "2019-04-01", - "eventHubsApiVersion": "2017-04-01", - "authorizationApiVersion": "2018-09-01-preview", - "blobDataContributorRoleId": "[concat('/subscriptions/', subscription().subscriptionId, '/providers/Microsoft.Authorization/roleDefinitions/ba92f5b4-2d11-453d-a403-e96b0029c9fe')]", - "contributorRoleId": "[concat('/subscriptions/', subscription().subscriptionId, '/providers/Microsoft.Authorization/roleDefinitions/b24988ac-6180-42a0-ab88-20f7382dd24c')]", - "AuthorizationRulesName": "[concat('authr', parameters('baseName'))]", - "primaryAccountName": "[concat('prim', parameters('baseName'))]", - "secondaryAccountName": "[concat('sec', parameters('baseName'))]", - "premiumAccountName": "[concat('prem', parameters('baseName'))]", - "dataLakeAccountName": "[concat('dtlk', parameters('baseName'))]", - "location": "[resourceGroup().location]", - "eventHubNameSpaceName": "[parameters('baseName')]" + "authorizationApiVersion": "2018-09-01-preview", + "authorizationRulesName": "[concat('authr', parameters('baseName'))]", + "blobDataContributorRoleId": "[concat('/subscriptions/', subscription().subscriptionId, '/providers/Microsoft.Authorization/roleDefinitions/ba92f5b4-2d11-453d-a403-e96b0029c9fe')]", + "contributorRoleId": "[concat('/subscriptions/', subscription().subscriptionId, '/providers/Microsoft.Authorization/roleDefinitions/b24988ac-6180-42a0-ab88-20f7382dd24c')]", + "eventHubsApiVersion": "2017-04-01", + "eventHubsDataOwnerRoleId": "[concat('/subscriptions/', subscription().subscriptionId, '/providers/Microsoft.Authorization/roleDefinitions/f526a384-b230-433a-b45c-95f59c4a2dec')]", + "eventHubsNamespaceKeyName": "RootManageSharedAccessKey", + "eventHubsNamespaceName": "[concat('eventhub', parameters('baseName'))]", + "location": "[resourceGroup().location]", + "premiumAccountName": "[concat('prem', parameters('baseName'))]", + "primaryAccountName": "[concat('prim', parameters('baseName'))]", + "secondaryAccountName": "[concat('sec', parameters('baseName'))]", + "storageApiVersion": "2019-04-01" }, "resources": [ - { - "type": "Microsoft.EventHub/namespaces", - "apiVersion": "[variables('eventHubsApiVersion')]", - "name": "[variables('eventHubNameSpaceName')]", - "location": "[variables('location')]", - "sku": { - "name": "Standard", - "tier": "Standard", - "capacity": 5 - }, - "properties": { - "zoneRedundant": false, - "isAutoInflateEnabled": false, - "maximumThroughputUnits": 0, - "cors": { - "corsRules": [ - { - "allowedOrigins": [ - "example.com" - ], - "allowedMethods": [ - "GET" - ], - "maxAgeInSeconds": 8888, - "exposedHeaders": [ - "*" - ], - "allowedHeaders": [ - "*" - ] - }, - { - "allowedOrigins": [ - "*" - ], - "allowedMethods": [ - "DELETE", - "GET", - "HEAD", - "MERGE", - "POST", - "OPTIONS", - "PUT" - ], - "maxAgeInSeconds": 86400, - "exposedHeaders": [ - "*" - ], - "allowedHeaders": [ - "*" - ] - }, - { - "allowedOrigins": [ - "example.com" - ], - "allowedMethods": [ - "GET" - ], - "maxAgeInSeconds": 8888, - "exposedHeaders": [ - "*" - ], - "allowedHeaders": [ - "*" - ] - }, - { - "allowedOrigins": [ - "example.com" - ], - "allowedMethods": [ - "GET" - ], - "maxAgeInSeconds": 8888, - "exposedHeaders": [ - "*" - ], - "allowedHeaders": [ - "*" - ] - }, - { - "allowedOrigins": [ - "example.com" - ], - "allowedMethods": [ - "GET" - ], - "maxAgeInSeconds": 8888, - "exposedHeaders": [ - "*" - ], - "allowedHeaders": [ - "*" - ] - } - ] - } - } - }, - { - "apiVersion": "[variables('eventHubsApiVersion')]", - "type": "Microsoft.EventHub/namespaces/eventhubs", - "name": "[concat(parameters('baseName'), '/', parameters('eventHubName'))]", - "location": "[variables('location')]", - "dependsOn": [ - "[resourceId('Microsoft.EventHub/namespaces', variables('eventHubNameSpaceName'))]" - ], - "properties": { - "messageRetentionInDays": 7, - "partitionCount": 2 - } - }, - { - "type": "Microsoft.Authorization/roleAssignments", - "apiVersion": "[variables('authorizationApiVersion')]", - "name": "[guid(concat('dataContributorRoleId', variables('primaryAccountName')))]", - "dependsOn": [ - "[variables('primaryAccountName')]" - ], - "properties": { - "roleDefinitionId": "[variables('blobDataContributorRoleId')]", - "principalId": "[parameters('testApplicationOid')]" - } + { + "type": "Microsoft.EventHub/namespaces", + "apiVersion": "[variables('eventHubsApiVersion')]", + "name": "[variables('eventHubsNamespaceName')]", + "location": "[variables('location')]", + "sku": { + "name": "Standard", + "tier": "Standard", + "capacity": 5 }, - { - "type": "Microsoft.Authorization/roleAssignments", - "apiVersion": "[variables('authorizationApiVersion')]", - "name": "[guid(concat('contributorRoleId', variables('primaryAccountName')))]", - "dependsOn": [ - "[variables('primaryAccountName')]" - ], - "properties": { - "roleDefinitionId": "[variables('contributorRoleId')]", - "principalId": "[parameters('testApplicationOid')]" - } - }, - { - "apiVersion": "2017-04-01", - "name": "[concat(parameters('baseName'), '/', parameters('eventHubName'))]", - "type": "Microsoft.EventHub/namespaces/AuthorizationRules", - "dependsOn": [ - "[concat('Microsoft.EventHub/namespaces/', variables('eventHubNameSpaceName'))]" - ], - "properties": { - "rights": [ - "Send", - "Listen", - "Manage" - ] - } + "properties": { + "zoneRedundant": false, + "isAutoInflateEnabled": false, + "maximumThroughputUnits": 0, + "kafkaEnabled": true + } + }, + { + "type": "Microsoft.EventHub/namespaces/eventhubs", + "apiVersion": "[variables('eventHubsApiVersion')]", + "name": "[concat(variables('eventHubsNamespaceName'), '/', parameters('eventHubName'))]", + "location": "[variables('location')]", + "dependsOn": [ + "[resourceId('Microsoft.EventHub/namespaces', variables('eventHubsNamespaceName'))]" + ], + "properties": { + "messageRetentionInDays": 1, + "partitionCount": 3, + "status": "Active" + } + }, + { + "type": "Microsoft.EventHub/namespaces/AuthorizationRules", + "apiVersion": "[variables('eventHubsApiVersion')]", + "name": "[concat(variables('eventHubsNamespaceName'), '/', variables('eventHubsNamespaceKeyName'))]", + "location": "[variables('location')]", + "dependsOn": [ + "[resourceId('Microsoft.EventHub/namespaces', variables('eventHubsNamespaceName'))]" + ], + "properties": { + "rights": [ + "Send", + "Listen", + "Manage" + ] + } + }, + { + "type": "Microsoft.Authorization/roleAssignments", + "apiVersion": "[variables('authorizationApiVersion')]", + "name": "[guid(concat('eventHubsDataOwnerRoleId', variables('eventHubsNamespaceName')))]", + "dependsOn": [ + "[resourceId('Microsoft.EventHub/namespaces', variables('eventHubsNamespaceName'))]" + ], + "properties": { + "roleDefinitionId": "[variables('eventHubsDataOwnerRoleId')]", + "principalId": "[parameters('testApplicationOid')]" + } + }, + { + "type": "Microsoft.Storage/storageAccounts", + "apiVersion": "[variables('storageApiVersion')]", + "name": "[variables('primaryAccountName')]", + "location": "[variables('location')]", + "sku": { + "name": "Standard_RAGRS", + "tier": "Standard" }, - { - "type": "Microsoft.Storage/storageAccounts", - "apiVersion": "[variables('storageApiVersion')]", - "name": "[variables('primaryAccountName')]", - "location": "[variables('location')]", - "sku": { - "name": "Standard_RAGRS", - "tier": "Standard" + "kind": "StorageV2", + "properties": { + "networkAcls": { + "bypass": "AzureServices", + "virtualNetworkRules": [], + "ipRules": [], + "defaultAction": "Allow" }, - "kind": "StorageV2", - "properties": { - "networkAcls": { - "bypass": "AzureServices", - "virtualNetworkRules": [], - "ipRules": [], - "defaultAction": "Allow" - }, - "supportsHttpsTrafficOnly": true, - "encryption": { - "services": { - "file": { - "enabled": true - }, - "blob": { - "enabled": true - } + "supportsHttpsTrafficOnly": true, + "encryption": { + "services": { + "file": { + "enabled": true }, - "keySource": "Microsoft.Storage" + "blob": { + "enabled": true + } }, - "accessTier": "Hot" - } - }, - { - "type": "Microsoft.Storage/storageAccounts", - "apiVersion": "[variables('storageApiVersion')]", - "name": "[variables('secondaryAccountName')]", - "location": "[variables('location')]", - "sku": { - "name": "Standard_RAGRS", - "tier": "Standard" + "keySource": "Microsoft.Storage" }, - "kind": "StorageV2", - "properties": { - "networkAcls": { - "bypass": "AzureServices", - "virtualNetworkRules": [], - "ipRules": [], - "defaultAction": "Allow" - }, - "supportsHttpsTrafficOnly": true, - "encryption": { - "services": { - "file": { - "enabled": true - }, - "blob": { - "enabled": true - } - }, - "keySource": "Microsoft.Storage" - }, - "accessTier": "Hot" - } + "accessTier": "Hot" + } + }, + { + "type": "Microsoft.Storage/storageAccounts", + "apiVersion": "[variables('storageApiVersion')]", + "name": "[variables('secondaryAccountName')]", + "location": "[variables('location')]", + "sku": { + "name": "Standard_RAGRS", + "tier": "Standard" }, - { - "type": "Microsoft.Storage/storageAccounts", - "apiVersion": "[variables('storageApiVersion')]", - "name": "[variables('premiumAccountName')]", - "location": "[variables('location')]", - "sku": { - "name": "Premium_LRS", - "tier": "Premium" + "kind": "StorageV2", + "properties": { + "networkAcls": { + "bypass": "AzureServices", + "virtualNetworkRules": [], + "ipRules": [], + "defaultAction": "Allow" }, - "kind": "StorageV2", - "properties": { - "networkAcls": { - "bypass": "AzureServices", - "virtualNetworkRules": [], - "ipRules": [], - "defaultAction": "Allow" - }, - "supportsHttpsTrafficOnly": true, - "encryption": { - "services": { - "file": { - "enabled": true - }, - "blob": { - "enabled": true - } + "supportsHttpsTrafficOnly": true, + "encryption": { + "services": { + "file": { + "enabled": true }, - "keySource": "Microsoft.Storage" + "blob": { + "enabled": true + } }, - "accessTier": "Hot" - } + "keySource": "Microsoft.Storage" + }, + "accessTier": "Hot" + } + }, + { + "type": "Microsoft.Storage/storageAccounts", + "apiVersion": "[variables('storageApiVersion')]", + "name": "[variables('premiumAccountName')]", + "location": "[variables('location')]", + "sku": { + "name": "Premium_LRS", + "tier": "Premium" }, - { - "type": "Microsoft.Storage/storageAccounts", - "apiVersion": "[variables('storageApiVersion')]", - "name": "[variables('dataLakeAccountName')]", - "location": "[variables('location')]", - "sku": { - "name": "Standard_RAGRS", - "tier": "Standard" + "kind": "StorageV2", + "properties": { + "networkAcls": { + "bypass": "AzureServices", + "virtualNetworkRules": [], + "ipRules": [], + "defaultAction": "Allow" }, - "kind": "StorageV2", - "properties": { - "isHnsEnabled": true, - "networkAcls": { - "bypass": "AzureServices", - "virtualNetworkRules": [], - "ipRules": [], - "defaultAction": "Allow" - }, - "supportsHttpsTrafficOnly": true, - "encryption": { - "services": { - "file": { - "enabled": true - }, - "blob": { - "enabled": true - } + "supportsHttpsTrafficOnly": true, + "encryption": { + "services": { + "file": { + "enabled": true }, - "keySource": "Microsoft.Storage" + "blob": { + "enabled": true + } }, - "accessTier": "Hot" - } + "keySource": "Microsoft.Storage" + }, + "accessTier": "Hot" } + } ], "outputs": { - "AZURE_TENANT_ID": { - "type": "string", - "value": "[parameters('tenantId')]" - }, - "AZURE_CLIENT_ID": { - "type": "string", - "value": "[parameters('testApplicationId')]" - }, - "AZURE_CLIENT_SECRET": { - "type": "string", - "value": "[parameters('testApplicationSecret')]" - }, - "AZURE_EVENTHUBS_CONNECTION_STRING": { - "type": "string", - "value": "[concat(listKeys(resourceId('Microsoft.EventHub/namespaces/authorizationRules', parameters('baseName'), 'RootManageSharedAccessKey'), variables('eventHubsApiVersion')).primaryConnectionString, ';EntityPath=', parameters('eventHubName') )]" - }, - "AZURE_EVENTHUBS_EVENT_HUB_NAME": { - "type": "string", - "value": "[parameters('eventHubName')]" - }, - "AZURE_EVENTHUBS_FULLY_QUALIFIED_DOMAIN_NAME": { - "type": "string", - "value": "[concat(variables('eventHubNameSpaceName'), '.', parameters('eventHubNamespaceHostNameSuffix'))]" - }, - "BLOB_STORAGE_ACCOUNT_NAME": { - "type": "string", - "value": "[variables('secondaryAccountName')]" - }, - "BLOB_STORAGE_ACCOUNT_KEY": { - "type": "string", - "value": "[listKeys(resourceId('Microsoft.Storage/storageAccounts', variables('secondaryAccountName')), variables('storageApiVersion')).keys[0].value]" - }, - "PREMIUM_STORAGE_ACCOUNT_NAME": { - "type": "string", - "value": "[variables('premiumAccountName')]" - }, - "PREMIUM_STORAGE_ACCOUNT_KEY": { - "type": "string", - "value": "[listKeys(resourceId('Microsoft.Storage/storageAccounts', variables('premiumAccountName')), variables('storageApiVersion')).keys[0].value]" - }, - "AZURE_STORAGE_BLOB_CONNECTION_STRING": { - "type": "string", - "value": "[concat('DefaultEndpointsProtocol=https;AccountName=', variables('primaryAccountName'), ';AccountKey=', listKeys(resourceId('Microsoft.Storage/storageAccounts', variables('primaryAccountName')), variables('storageApiVersion')).keys[0].value, ';EndpointSuffix=', parameters('storageEndpointSuffix'))]" - }, - "AZURE_STORAGE_FILE_CONNECTION_STRING": { - "type": "string", - "value": "[concat('DefaultEndpointsProtocol=https;AccountName=', variables('primaryAccountName'), ';AccountKey=', listKeys(resourceId('Microsoft.Storage/storageAccounts', variables('primaryAccountName')), variables('storageApiVersion')).keys[0].value, ';EndpointSuffix=', parameters('storageEndpointSuffix'))]" - }, - "AZURE_STORAGE_FILE_ENDPOINT": { - "type": "string", - "value": "[reference(resourceId('Microsoft.Storage/storageAccounts', variables('primaryAccountName')), variables('storageApiVersion')).primaryEndpoints.file]" - }, - "AZURE_STORAGE_QUEUE_CONNECTION_STRING": { - "type": "string", - "value": "[concat('DefaultEndpointsProtocol=https;AccountName=', variables('primaryAccountName'), ';AccountKey=', listKeys(resourceId('Microsoft.Storage/storageAccounts', variables('primaryAccountName')), variables('storageApiVersion')).keys[0].value, ';EndpointSuffix=', parameters('storageEndpointSuffix'))]" - }, - "AZURE_STORAGE_QUEUE_ENDPOINT": { - "type": "string", - "value": "[reference(resourceId('Microsoft.Storage/storageAccounts', variables('primaryAccountName')), variables('storageApiVersion')).primaryEndpoints.queue]" - }, - "PRIMARY_STORAGE_ACCOUNT_NAME": { - "type": "string", - "value": "[variables('primaryAccountName')]" - }, - "PRIMARY_STORAGE_ACCOUNT_KEY": { - "type": "string", - "value": "[listKeys(resourceId('Microsoft.Storage/storageAccounts', variables('primaryAccountName')), variables('storageApiVersion')).keys[0].value]" - }, - "STORAGE_DATA_LAKE_ACCOUNT_KEY": { - "type": "string", - "value": "[listKeys(resourceId('Microsoft.Storage/storageAccounts', variables('dataLakeAccountName')), variables('storageApiVersion')).keys[0].value]" - }, - "STORAGE_DATA_LAKE_ACCOUNT_NAME": { - "type": "string", - "value": "[variables('dataLakeAccountName')]" - }, - "SECONDARY_STORAGE_ACCOUNT_NAME": { - "type": "string", - "value": "[variables('secondaryAccountName')]" - }, - "SECONDARY_STORAGE_ACCOUNT_KEY": { - "type": "string", - "value": "[listKeys(resourceId('Microsoft.Storage/storageAccounts', variables('secondaryAccountName')), variables('storageApiVersion')).keys[0].value]" - } + "AZURE_TENANT_ID": { + "type": "string", + "value": "[parameters('tenantId')]" + }, + "AZURE_CLIENT_ID": { + "type": "string", + "value": "[parameters('testApplicationId')]" + }, + "AZURE_CLIENT_SECRET": { + "type": "string", + "value": "[parameters('testApplicationSecret')]" + }, + "AZURE_EVENTHUBS_CONNECTION_STRING": { + "type": "string", + "value": "[concat(listKeys(resourceId('Microsoft.EventHub/namespaces/authorizationRules', variables('eventHubsNamespaceName'), variables('eventHubsNamespaceKeyName')), variables('eventHubsApiVersion')).primaryConnectionString, ';EntityPath=', parameters('eventHubName'))]" + }, + "AZURE_EVENTHUBS_EVENT_HUB_NAME": { + "type": "string", + "value": "[parameters('eventHubName')]" + }, + "AZURE_EVENTHUBS_FULLY_QUALIFIED_DOMAIN_NAME": { + "type": "string", + "value": "[concat(variables('eventHubsNamespaceName'), '.', parameters('eventHubNamespaceHostNameSuffix'))]" + }, + "BLOB_STORAGE_ACCOUNT_NAME": { + "type": "string", + "value": "[variables('secondaryAccountName')]" + }, + "BLOB_STORAGE_ACCOUNT_KEY": { + "type": "string", + "value": "[listKeys(resourceId('Microsoft.Storage/storageAccounts', variables('secondaryAccountName')), variables('storageApiVersion')).keys[0].value]" + }, + "PREMIUM_STORAGE_ACCOUNT_NAME": { + "type": "string", + "value": "[variables('premiumAccountName')]" + }, + "PREMIUM_STORAGE_ACCOUNT_KEY": { + "type": "string", + "value": "[listKeys(resourceId('Microsoft.Storage/storageAccounts', variables('premiumAccountName')), variables('storageApiVersion')).keys[0].value]" + }, + "PRIMARY_STORAGE_ACCOUNT_NAME": { + "type": "string", + "value": "[variables('primaryAccountName')]" + }, + "PRIMARY_STORAGE_ACCOUNT_KEY": { + "type": "string", + "value": "[listKeys(resourceId('Microsoft.Storage/storageAccounts', variables('primaryAccountName')), variables('storageApiVersion')).keys[0].value]" + }, + "SECONDARY_STORAGE_ACCOUNT_NAME": { + "type": "string", + "value": "[variables('secondaryAccountName')]" + }, + "SECONDARY_STORAGE_ACCOUNT_KEY": { + "type": "string", + "value": "[listKeys(resourceId('Microsoft.Storage/storageAccounts', variables('secondaryAccountName')), variables('storageApiVersion')).keys[0].value]" } } +} diff --git a/sdk/eventhubs/tests.yml b/sdk/eventhubs/tests.yml index eefd68daa071..67f91bfd8807 100644 --- a/sdk/eventhubs/tests.yml +++ b/sdk/eventhubs/tests.yml @@ -7,4 +7,4 @@ jobs: TimeoutInMinutes: 120 EnvVars: AZURE_TEST_MODE: RECORD - AZURE_LOG_LEVEL: 4 + AZURE_LOG_LEVEL: 2