diff --git a/sdk/tables/azure-data-tables/src/test/java/com/azure/data/tables/CosmosThrottled.java b/sdk/tables/azure-data-tables/src/test/java/com/azure/data/tables/CosmosThrottled.java deleted file mode 100644 index f33d2fd69abcc..0000000000000 --- a/sdk/tables/azure-data-tables/src/test/java/com/azure/data/tables/CosmosThrottled.java +++ /dev/null @@ -1,110 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. -package com.azure.data.tables; - -import com.azure.core.exception.AzureException; -import com.azure.data.tables.implementation.AzureTableImpl; -import com.azure.data.tables.implementation.models.TableServiceErrorException; - -import java.util.function.Consumer; -import java.util.function.Function; - -public abstract class CosmosThrottled { - protected final T client; - protected final boolean isPlaybackMode; - - protected CosmosThrottled(T client, boolean isPlaybackMode) { - this.client = client; - this.isPlaybackMode = isPlaybackMode; - } - - public abstract boolean isCosmos(); - - public void runVoid(Consumer action) { - run(c -> { - action.accept(c); - return null; - }); - } - - public T getClient() { - return client; - } - - public TResult run(Function action) { - if (!isCosmos()) { - return action.apply(client); - } - - int retryCount = 0; - int delay = 1500; - while (true) { - try { - return action.apply(client); - } catch (TableServiceErrorException e) { - if (e.getResponse().getStatusCode() != 429) { - throw e; - } - - if (++retryCount > 10) { - throw e; - } - - // Disable retry throttling in Playback mode. - if (!isPlaybackMode) { - try { - Thread.sleep(delay); - } catch (InterruptedException interruptedException) { - throw new AzureException(interruptedException); - } - delay *= 2; - } - } - } - } - - public static CosmosThrottled get(TableServiceAsyncClient client, boolean isPlaybackMode) { - return new CosmosThrottled(client, isPlaybackMode) { - @Override - public boolean isCosmos() { - return client.getServiceUrl().contains("cosmos.azure.com"); - } - }; - } - - public static CosmosThrottled get(TableServiceClient client, boolean isPlaybackMode) { - return new CosmosThrottled(client, isPlaybackMode) { - @Override - public boolean isCosmos() { - return client.getServiceUrl().contains("cosmos.azure.com"); - } - }; - } - - public static CosmosThrottled get(TableAsyncClient client, boolean isPlaybackMode) { - return new CosmosThrottled(client, isPlaybackMode) { - @Override - public boolean isCosmos() { - return client.getTableUrl().contains("cosmos.azure.com"); - } - }; - } - - public static CosmosThrottled get(TableClient client, boolean isPlaybackMode) { - return new CosmosThrottled(client, isPlaybackMode) { - @Override - public boolean isCosmos() { - return client.getTableUrl().contains("cosmos.azure.com"); - } - }; - } - - public static CosmosThrottled get(AzureTableImpl client, boolean isPlaybackMode) { - return new CosmosThrottled(client, isPlaybackMode) { - @Override - public boolean isCosmos() { - return client.getUrl().contains("cosmos.azure.com"); - } - }; - } -} diff --git a/sdk/tables/azure-data-tables/src/test/java/com/azure/data/tables/TableServiceAsyncClientTest.java b/sdk/tables/azure-data-tables/src/test/java/com/azure/data/tables/TableServiceAsyncClientTest.java index d357176772515..3bead9b4014d5 100644 --- a/sdk/tables/azure-data-tables/src/test/java/com/azure/data/tables/TableServiceAsyncClientTest.java +++ b/sdk/tables/azure-data-tables/src/test/java/com/azure/data/tables/TableServiceAsyncClientTest.java @@ -27,7 +27,7 @@ */ public class TableServiceAsyncClientTest extends TestBase { private static final Duration TIMEOUT = Duration.ofSeconds(100); - private CosmosThrottled runner; + private TableServiceAsyncClient serviceClient; @BeforeAll static void beforeAll() { @@ -57,7 +57,7 @@ protected void beforeTest() { Duration.ofSeconds(100)))); } - runner = CosmosThrottled.get(builder.buildAsyncClient(), interceptorManager.isPlaybackMode()); + serviceClient = builder.buildAsyncClient(); } @Test @@ -66,7 +66,7 @@ void serviceCreateTableAsync() { String tableName = testResourceNamer.randomName("test", 20); //Act & Assert - StepVerifier.create(runner.run(serviceClient -> serviceClient.createTable(tableName))) + StepVerifier.create(serviceClient.createTable(tableName)) .expectComplete() .verify(); } @@ -75,10 +75,10 @@ void serviceCreateTableAsync() { void serviceCreateTableFailsIfExistsAsync() { // Arrange String tableName = testResourceNamer.randomName("test", 20); - runner.run(serviceClient -> serviceClient.createTable(tableName).block(TIMEOUT)); + serviceClient.createTable(tableName).block(TIMEOUT); //Act & Assert - StepVerifier.create(runner.run(serviceClient -> serviceClient.createTable(tableName))) + StepVerifier.create(serviceClient.createTable(tableName)) .expectErrorMatches(e -> e instanceof TableServiceErrorException && ((TableServiceErrorException) e).getResponse().getStatusCode() == 409) .verify(); @@ -91,7 +91,7 @@ void serviceCreateTableWithResponseAsync() { int expectedStatusCode = 204; //Act & Assert - StepVerifier.create(runner.run(serviceClient -> serviceClient.createTableWithResponse(tableName))) + StepVerifier.create(serviceClient.createTableWithResponse(tableName)) .assertNext(response -> { Assertions.assertEquals(expectedStatusCode, response.getStatusCode()); }) @@ -105,7 +105,7 @@ void serviceCreateTableIfNotExistsAsync() { String tableName = testResourceNamer.randomName("test", 20); //Act & Assert - StepVerifier.create(runner.run(serviceClient -> serviceClient.createTableIfNotExists(tableName))) + StepVerifier.create(serviceClient.createTableIfNotExists(tableName)) .expectComplete() .verify(); } @@ -114,10 +114,10 @@ void serviceCreateTableIfNotExistsAsync() { void serviceCreateTableIfNotExistsSucceedsIfExistsAsync() { // Arrange String tableName = testResourceNamer.randomName("test", 20); - runner.run(serviceClient -> serviceClient.createTable(tableName).block(TIMEOUT)); + serviceClient.createTable(tableName).block(TIMEOUT); //Act & Assert - StepVerifier.create(runner.run(serviceClient -> serviceClient.createTableIfNotExists(tableName))) + StepVerifier.create(serviceClient.createTableIfNotExists(tableName)) .expectComplete() .verify(); } @@ -129,7 +129,7 @@ void serviceCreateTableIfNotExistsWithResponseAsync() { int expectedStatusCode = 204; //Act & Assert - StepVerifier.create(runner.run(serviceClient -> serviceClient.createTableIfNotExistsWithResponse(tableName))) + StepVerifier.create(serviceClient.createTableIfNotExistsWithResponse(tableName)) .assertNext(response -> { Assertions.assertEquals(expectedStatusCode, response.getStatusCode()); }) @@ -142,10 +142,10 @@ void serviceCreateTableIfNotExistsWithResponseSucceedsIfExistsAsync() { // Arrange String tableName = testResourceNamer.randomName("test", 20); int expectedStatusCode = 409; - runner.run(serviceClient -> serviceClient.createTable(tableName).block(TIMEOUT)); + serviceClient.createTable(tableName).block(TIMEOUT); //Act & Assert - StepVerifier.create(runner.run(serviceClient -> serviceClient.createTableIfNotExistsWithResponse(tableName))) + StepVerifier.create(serviceClient.createTableIfNotExistsWithResponse(tableName)) .assertNext(response -> { Assertions.assertEquals(expectedStatusCode, response.getStatusCode()); }) @@ -157,10 +157,10 @@ void serviceCreateTableIfNotExistsWithResponseSucceedsIfExistsAsync() { void serviceDeleteTableAsync() { // Arrange final String tableName = testResourceNamer.randomName("test", 20); - runner.run(serviceClient -> serviceClient.createTable(tableName).block(TIMEOUT)); + serviceClient.createTable(tableName).block(TIMEOUT); //Act & Assert - StepVerifier.create(runner.run(serviceClient -> serviceClient.deleteTable(tableName))) + StepVerifier.create(serviceClient.deleteTable(tableName)) .expectComplete() .verify(); } @@ -170,10 +170,10 @@ void serviceDeleteTableWithResponseAsync() { // Arrange String tableName = testResourceNamer.randomName("test", 20); int expectedStatusCode = 204; - runner.run(serviceClient -> serviceClient.createTable(tableName).block()); + serviceClient.createTable(tableName).block(); //Act & Assert - StepVerifier.create(runner.run(serviceClient -> serviceClient.deleteTableWithResponse(tableName))) + StepVerifier.create(serviceClient.deleteTableWithResponse(tableName)) .assertNext(response -> { Assertions.assertEquals(expectedStatusCode, response.getStatusCode()); }) @@ -187,11 +187,11 @@ void serviceListTablesAsync() { // Arrange final String tableName = testResourceNamer.randomName("test", 20); final String tableName2 = testResourceNamer.randomName("test", 20); - runner.run(serviceClient -> serviceClient.createTable(tableName)).block(TIMEOUT); - runner.run(serviceClient -> serviceClient.createTable(tableName2)).block(TIMEOUT); + serviceClient.createTable(tableName).block(TIMEOUT); + serviceClient.createTable(tableName2).block(TIMEOUT); // Act & Assert - StepVerifier.create(runner.run(serviceClient -> serviceClient.listTables())) + StepVerifier.create(serviceClient.listTables()) .expectNextCount(2) .thenConsumeWhile(x -> true) .expectComplete() @@ -205,11 +205,11 @@ void serviceListTablesWithFilterAsync() { final String tableName = testResourceNamer.randomName("test", 20); final String tableName2 = testResourceNamer.randomName("test", 20); ListTablesOptions options = new ListTablesOptions().setFilter("TableName eq '" + tableName + "'"); - runner.run(serviceClient -> serviceClient.createTable(tableName)).block(TIMEOUT); - runner.run(serviceClient -> serviceClient.createTable(tableName2)).block(TIMEOUT); + serviceClient.createTable(tableName).block(TIMEOUT); + serviceClient.createTable(tableName2).block(TIMEOUT); // Act & Assert - StepVerifier.create(runner.run(serviceClient -> serviceClient.listTables(options))) + StepVerifier.create(serviceClient.listTables(options)) .assertNext(table -> { assertEquals(tableName, table.getName()); }) @@ -227,12 +227,12 @@ void serviceListTablesWithTopAsync() { final String tableName2 = testResourceNamer.randomName("test", 20); final String tableName3 = testResourceNamer.randomName("test", 20); ListTablesOptions options = new ListTablesOptions().setTop(2); - runner.run(serviceClient -> serviceClient.createTable(tableName)).block(TIMEOUT); - runner.run(serviceClient -> serviceClient.createTable(tableName2)).block(TIMEOUT); - runner.run(serviceClient -> serviceClient.createTable(tableName3)).block(TIMEOUT); + serviceClient.createTable(tableName).block(TIMEOUT); + serviceClient.createTable(tableName2).block(TIMEOUT); + serviceClient.createTable(tableName3).block(TIMEOUT); // Act & Assert - StepVerifier.create(runner.run(serviceClient -> serviceClient.listTables(options))) + StepVerifier.create(serviceClient.listTables(options)) .expectNextCount(2) .thenConsumeWhile(x -> true) .expectComplete() diff --git a/sdk/tables/azure-data-tables/src/test/java/com/azure/data/tables/TableServiceClientTest.java b/sdk/tables/azure-data-tables/src/test/java/com/azure/data/tables/TableServiceClientTest.java index 1517f4ccbe950..164851e0cef87 100644 --- a/sdk/tables/azure-data-tables/src/test/java/com/azure/data/tables/TableServiceClientTest.java +++ b/sdk/tables/azure-data-tables/src/test/java/com/azure/data/tables/TableServiceClientTest.java @@ -16,7 +16,7 @@ import java.time.Duration; public class TableServiceClientTest extends TestBase { - private CosmosThrottled runner; + private TableServiceClient serviceClient; @Override protected void beforeTest() { @@ -35,7 +35,7 @@ protected void beforeTest() { builder.addPolicy(new RetryPolicy(new ExponentialBackoff(6, Duration.ofMillis(1500), Duration.ofSeconds(100)))); } - runner = CosmosThrottled.get(builder.buildClient(), interceptorManager.isPlaybackMode()); + serviceClient = builder.buildClient(); } @Test @@ -44,18 +44,18 @@ void serviceCreateTable() { String tableName = testResourceNamer.randomName("test", 20); // Act & Assert - runner.runVoid(serviceClient -> serviceClient.createTable(tableName)); + serviceClient.createTable(tableName); } @Test void serviceCreateTableFailsIfExists() { // Arrange String tableName = testResourceNamer.randomName("test", 20); - runner.runVoid(serviceClient -> serviceClient.createTable(tableName)); + serviceClient.createTable(tableName); // Act & Assert Assertions.assertThrows(TableServiceErrorException.class, - () -> runner.runVoid(serviceClient -> serviceClient.createTable(tableName))); + () -> serviceClient.createTable(tableName)); } @Test @@ -64,17 +64,17 @@ void serviceCreateTableIfNotExists() { String tableName = testResourceNamer.randomName("test", 20); // Act & Assert - runner.runVoid(serviceClient -> serviceClient.createTableIfNotExists(tableName)); + serviceClient.createTableIfNotExists(tableName); } @Test void serviceCreateTableIfNotExistsSucceedsIfExists() { // Arrange String tableName = testResourceNamer.randomName("test", 20); - runner.runVoid(serviceClient -> serviceClient.createTable(tableName)); + serviceClient.createTable(tableName); //Act & Assert - runner.runVoid(serviceClient -> serviceClient.createTableIfNotExists(tableName)); + serviceClient.createTableIfNotExists(tableName); } @Test diff --git a/sdk/tables/azure-data-tables/src/test/java/com/azure/data/tables/TablesAsyncClientTest.java b/sdk/tables/azure-data-tables/src/test/java/com/azure/data/tables/TablesAsyncClientTest.java index ef4c54a044c67..f4e2cfad7e9ec 100644 --- a/sdk/tables/azure-data-tables/src/test/java/com/azure/data/tables/TablesAsyncClientTest.java +++ b/sdk/tables/azure-data-tables/src/test/java/com/azure/data/tables/TablesAsyncClientTest.java @@ -36,7 +36,7 @@ public class TablesAsyncClientTest extends TestBase { private static final Duration TIMEOUT = Duration.ofSeconds(100); - private CosmosThrottled runner; + private TableAsyncClient tableClient; private HttpPipelinePolicy recordPolicy; private HttpClient playbackClient; @@ -72,8 +72,8 @@ protected void beforeTest() { Duration.ofSeconds(100)))); } - runner = CosmosThrottled.get(builder.buildAsyncClient(), interceptorManager.isPlaybackMode()); - runner.run(tableClient -> tableClient.create().block(TIMEOUT)); + tableClient = builder.buildAsyncClient(); + tableClient.create().block(TIMEOUT); } @Test @@ -97,11 +97,10 @@ void createTableAsync() { Duration.ofSeconds(100)))); } - final CosmosThrottled runner2 = CosmosThrottled.get(builder.buildAsyncClient(), - interceptorManager.isPlaybackMode()); + final TableAsyncClient tableClient2 = builder.buildAsyncClient(); // Act & Assert - StepVerifier.create(runner2.run(tableClient -> tableClient.create())) + StepVerifier.create(tableClient2.create()) .expectComplete() .verify(); } @@ -127,12 +126,11 @@ void createTableWithResponseAsync() { Duration.ofSeconds(100)))); } - final CosmosThrottled runner2 = CosmosThrottled.get(builder.buildAsyncClient(), - interceptorManager.isPlaybackMode()); + final TableAsyncClient tableClient2 = builder.buildAsyncClient(); final int expectedStatusCode = 204; // Act & Assert - StepVerifier.create(runner2.run(tableClient -> tableClient.createWithResponse())) + StepVerifier.create(tableClient2.createWithResponse()) .assertNext(response -> { assertEquals(expectedStatusCode, response.getStatusCode()); }) @@ -148,7 +146,7 @@ void createEntityAsync() { final TableEntity tableEntity = new TableEntity(partitionKeyValue, rowKeyValue); // Act & Assert - StepVerifier.create(runner.run(tableClient -> tableClient.createEntity(tableEntity))) + StepVerifier.create(tableClient.createEntity(tableEntity)) .expectComplete() .verify(); } @@ -162,7 +160,7 @@ void createEntityWithResponseAsync() { final int expectedStatusCode = 204; // Act & Assert - StepVerifier.create(runner.run(tableClient -> tableClient.createEntityWithResponse(entity))) + StepVerifier.create(tableClient.createEntityWithResponse(entity)) .assertNext(response -> { assertEquals(expectedStatusCode, response.getStatusCode()); }) @@ -197,11 +195,10 @@ void createEntityWithAllSupportedDataTypesAsync() { tableEntity.addProperty("Int64TypeProperty", int64Value); tableEntity.addProperty("StringTypeProperty", stringValue); - runner.run(tableClient -> tableClient.createEntity(tableEntity).block(TIMEOUT)); + tableClient.createEntity(tableEntity).block(TIMEOUT); // Act & Assert - StepVerifier.create(runner.run(tableClient -> - tableClient.getEntityWithResponse(partitionKeyValue, rowKeyValue))) + StepVerifier.create(tableClient.getEntityWithResponse(partitionKeyValue, rowKeyValue)) .assertNext(response -> { final TableEntity entity = response.getValue(); Map properties = entity.getProperties(); @@ -222,7 +219,7 @@ void createEntityWithAllSupportedDataTypesAsync() { @Test void deleteTableAsync() { // Act & Assert - StepVerifier.create(runner.run(tableClient -> tableClient.delete())) + StepVerifier.create(tableClient.delete()) .expectComplete() .verify(); } @@ -233,7 +230,7 @@ void deleteTableWithResponseAsync() { final int expectedStatusCode = 204; // Act & Assert - StepVerifier.create(runner.run(tableClient -> tableClient.deleteWithResponse())) + StepVerifier.create(tableClient.deleteWithResponse()) .assertNext(response -> { assertEquals(expectedStatusCode, response.getStatusCode()); }) @@ -248,14 +245,13 @@ void deleteEntityAsync() { final String rowKeyValue = testResourceNamer.randomName("rowKey", 20); final TableEntity tableEntity = new TableEntity(partitionKeyValue, rowKeyValue); - runner.run(tableClient -> tableClient.createEntity(tableEntity).block(TIMEOUT)); - final TableEntity createdEntity = runner.run(tableClient -> - tableClient.getEntity(partitionKeyValue, rowKeyValue).block(TIMEOUT)); + tableClient.createEntity(tableEntity).block(TIMEOUT); + final TableEntity createdEntity = tableClient.getEntity(partitionKeyValue, rowKeyValue).block(TIMEOUT); assertNotNull(createdEntity, "'createdEntity' should not be null."); assertNotNull(createdEntity.getETag(), "'eTag' should not be null."); // Act & Assert - StepVerifier.create(runner.run(tableClient -> tableClient.deleteEntity(partitionKeyValue, rowKeyValue))) + StepVerifier.create(tableClient.deleteEntity(partitionKeyValue, rowKeyValue)) .expectComplete() .verify(); } @@ -268,15 +264,13 @@ void deleteEntityWithResponseAsync() { final TableEntity tableEntity = new TableEntity(partitionKeyValue, rowKeyValue); final int expectedStatusCode = 204; - runner.run(tableClient -> tableClient.createEntity(tableEntity).block(TIMEOUT)); - final TableEntity createdEntity = runner.run(tableClient -> - tableClient.getEntity(partitionKeyValue, rowKeyValue).block(TIMEOUT)); + tableClient.createEntity(tableEntity).block(TIMEOUT); + final TableEntity createdEntity = tableClient.getEntity(partitionKeyValue, rowKeyValue).block(TIMEOUT); assertNotNull(createdEntity, "'createdEntity' should not be null."); assertNotNull(createdEntity.getETag(), "'eTag' should not be null."); // Act & Assert - StepVerifier.create(runner.run(tableClient -> - tableClient.deleteEntityWithResponse(partitionKeyValue, rowKeyValue, null))) + StepVerifier.create(tableClient.deleteEntityWithResponse(partitionKeyValue, rowKeyValue, null)) .assertNext(response -> { assertEquals(expectedStatusCode, response.getStatusCode()); }) @@ -292,15 +286,14 @@ void deleteEntityWithResponseMatchETagAsync() { final TableEntity tableEntity = new TableEntity(partitionKeyValue, rowKeyValue); final int expectedStatusCode = 204; - runner.run(tableClient -> tableClient.createEntity(tableEntity).block(TIMEOUT)); - final TableEntity createdEntity = runner.run(tableClient -> - tableClient.getEntity(partitionKeyValue, rowKeyValue).block(TIMEOUT)); + tableClient.createEntity(tableEntity).block(TIMEOUT); + final TableEntity createdEntity = tableClient.getEntity(partitionKeyValue, rowKeyValue).block(TIMEOUT); assertNotNull(createdEntity, "'createdEntity' should not be null."); assertNotNull(createdEntity.getETag(), "'eTag' should not be null."); // Act & Assert - StepVerifier.create(runner.run(tableClient -> - tableClient.deleteEntityWithResponse(partitionKeyValue, rowKeyValue, createdEntity.getETag()))) + StepVerifier.create(tableClient.deleteEntityWithResponse(partitionKeyValue, rowKeyValue, + createdEntity.getETag())) .assertNext(response -> { assertEquals(expectedStatusCode, response.getStatusCode()); }) @@ -315,11 +308,10 @@ void getEntityWithResponseAsync() { final String rowKeyValue = testResourceNamer.randomName("rowKey", 20); final TableEntity tableEntity = new TableEntity(partitionKeyValue, rowKeyValue); final int expectedStatusCode = 200; - runner.run(tableClient -> tableClient.createEntity(tableEntity).block(TIMEOUT)); + tableClient.createEntity(tableEntity).block(TIMEOUT); // Act & Assert - StepVerifier.create(runner.run(tableClient -> - tableClient.getEntityWithResponse(partitionKeyValue, rowKeyValue))) + StepVerifier.create(tableClient.getEntityWithResponse(partitionKeyValue, rowKeyValue)) .assertNext(response -> { final TableEntity entity = response.getValue(); assertEquals(expectedStatusCode, response.getStatusCode()); @@ -361,9 +353,8 @@ void updateEntityWithResponseAsync(UpdateMode mode) { final TableEntity tableEntity = new TableEntity(partitionKeyValue, rowKeyValue) .addProperty(oldPropertyKey, "valueA"); - runner.run(tableClient -> tableClient.createEntity(tableEntity).block(TIMEOUT)); - final TableEntity createdEntity = runner.run(tableClient -> - tableClient.getEntity(partitionKeyValue, rowKeyValue).block(TIMEOUT)); + tableClient.createEntity(tableEntity).block(TIMEOUT); + final TableEntity createdEntity = tableClient.getEntity(partitionKeyValue, rowKeyValue).block(TIMEOUT); assertNotNull(createdEntity, "'createdEntity' should not be null."); assertNotNull(createdEntity.getETag(), "'eTag' should not be null."); @@ -371,19 +362,19 @@ void updateEntityWithResponseAsync(UpdateMode mode) { createdEntity.addProperty(newPropertyKey, "valueB"); // Act & Assert - if (mode == UpdateMode.MERGE && runner.isCosmos()) { + if (mode == UpdateMode.MERGE && tableClient.getTableUrl().contains("cosmos.azure.com")) { // This scenario is currently broken when using the CosmosDB Table API - StepVerifier.create(runner.run(tableClient -> tableClient.updateEntityWithResponse(createdEntity, true, mode))) + StepVerifier.create(tableClient.updateEntityWithResponse(createdEntity, true, mode)) .expectError(com.azure.data.tables.implementation.models.TableServiceErrorException.class) .verify(); } else { - StepVerifier.create(runner.run(tableClient -> tableClient.updateEntityWithResponse(createdEntity, true, mode))) + StepVerifier.create(tableClient.updateEntityWithResponse(createdEntity, true, mode)) .assertNext(response -> assertEquals(expectedStatusCode, response.getStatusCode())) .expectComplete() .verify(); // Assert and verify that the new properties are in there. - StepVerifier.create(runner.run(tableClient -> tableClient.getEntity(partitionKeyValue, rowKeyValue))) + StepVerifier.create(tableClient.getEntity(partitionKeyValue, rowKeyValue)) .assertNext(entity -> { final Map properties = entity.getProperties(); assertTrue(properties.containsKey(newPropertyKey)); @@ -400,13 +391,11 @@ void listEntitiesAsync() { final String partitionKeyValue = testResourceNamer.randomName("partitionKey", 20); final String rowKeyValue = testResourceNamer.randomName("rowKey", 20); final String rowKeyValue2 = testResourceNamer.randomName("rowKey", 20); - runner.run(tableClient -> tableClient.createEntity(new TableEntity(partitionKeyValue, rowKeyValue))) - .block(TIMEOUT); - runner.run(tableClient -> tableClient.createEntity(new TableEntity(partitionKeyValue, rowKeyValue2))) - .block(TIMEOUT); + tableClient.createEntity(new TableEntity(partitionKeyValue, rowKeyValue)).block(TIMEOUT); + tableClient.createEntity(new TableEntity(partitionKeyValue, rowKeyValue2)).block(TIMEOUT); // Act & Assert - StepVerifier.create(runner.run(tableClient -> tableClient.listEntities())) + StepVerifier.create(tableClient.listEntities()) .expectNextCount(2) .thenConsumeWhile(x -> true) .expectComplete() @@ -421,13 +410,11 @@ void listEntitiesWithFilterAsync() { final String rowKeyValue = testResourceNamer.randomName("rowKey", 20); final String rowKeyValue2 = testResourceNamer.randomName("rowKey", 20); ListEntitiesOptions options = new ListEntitiesOptions().setFilter("RowKey eq '" + rowKeyValue + "'"); - runner.run(tableClient -> tableClient.createEntity(new TableEntity(partitionKeyValue, rowKeyValue))) - .block(TIMEOUT); - runner.run(tableClient -> tableClient.createEntity(new TableEntity(partitionKeyValue, rowKeyValue2))) - .block(TIMEOUT); + tableClient.createEntity(new TableEntity(partitionKeyValue, rowKeyValue)).block(TIMEOUT); + tableClient.createEntity(new TableEntity(partitionKeyValue, rowKeyValue2)).block(TIMEOUT); // Act & Assert - StepVerifier.create(runner.run(tableClient -> tableClient.listEntities(options))) + StepVerifier.create(tableClient.listEntities(options)) .assertNext(returnEntity -> { assertEquals(partitionKeyValue, returnEntity.getPartitionKey()); assertEquals(rowKeyValue, returnEntity.getRowKey()); @@ -449,10 +436,10 @@ void listEntitiesWithSelectAsync() { .addProperty("propertyD", "valueD"); ListEntitiesOptions options = new ListEntitiesOptions() .setSelect("propertyC"); - runner.run(tableClient -> tableClient.createEntity(entity).block(TIMEOUT)); + tableClient.createEntity(entity).block(TIMEOUT); // Act & Assert - StepVerifier.create(runner.run(tableClient -> tableClient.listEntities(options))) + StepVerifier.create(tableClient.listEntities(options)) .assertNext(returnEntity -> { assertNull(returnEntity.getRowKey()); assertNull(returnEntity.getPartitionKey()); @@ -472,15 +459,12 @@ void listEntitiesWithTopAsync() { final String rowKeyValue2 = testResourceNamer.randomName("rowKey", 20); final String rowKeyValue3 = testResourceNamer.randomName("rowKey", 20); ListEntitiesOptions options = new ListEntitiesOptions().setTop(2); - runner.run(tableClient -> tableClient.createEntity(new TableEntity(partitionKeyValue, rowKeyValue))) - .block(TIMEOUT); - runner.run(tableClient -> tableClient.createEntity(new TableEntity(partitionKeyValue, rowKeyValue2))) - .block(TIMEOUT); - runner.run(tableClient -> tableClient.createEntity(new TableEntity(partitionKeyValue, rowKeyValue3))) - .block(TIMEOUT); + tableClient.createEntity(new TableEntity(partitionKeyValue, rowKeyValue)).block(TIMEOUT); + tableClient.createEntity(new TableEntity(partitionKeyValue, rowKeyValue2)).block(TIMEOUT); + tableClient.createEntity(new TableEntity(partitionKeyValue, rowKeyValue3)).block(TIMEOUT); // Act & Assert - StepVerifier.create(runner.run(tableClient -> tableClient.listEntities(options))) + StepVerifier.create(tableClient.listEntities(options)) .expectNextCount(2) .thenConsumeWhile(x -> true) .expectComplete() diff --git a/sdk/tables/azure-data-tables/src/test/java/com/azure/data/tables/implementation/AzureTableImplTest.java b/sdk/tables/azure-data-tables/src/test/java/com/azure/data/tables/implementation/AzureTableImplTest.java index a64dcdafab273..a8d8e130c641e 100644 --- a/sdk/tables/azure-data-tables/src/test/java/com/azure/data/tables/implementation/AzureTableImplTest.java +++ b/sdk/tables/azure-data-tables/src/test/java/com/azure/data/tables/implementation/AzureTableImplTest.java @@ -18,7 +18,6 @@ import com.azure.core.test.TestBase; import com.azure.core.util.Context; import com.azure.core.util.logging.ClientLogger; -import com.azure.data.tables.CosmosThrottled; import com.azure.data.tables.TablesServiceVersion; import com.azure.data.tables.TablesSharedKeyCredential; import com.azure.data.tables.TablesSharedKeyCredentialPolicy; @@ -63,7 +62,7 @@ public class AzureTableImplTest extends TestBase { .setFormat(OdataMetadataFormat.APPLICATION_JSON_ODATA_FULLMETADATA); private final ClientLogger logger = new ClientLogger(AzureTableImplTest.class); - private CosmosThrottled runner; + private AzureTableImpl azureTable; @BeforeAll static void beforeAll() { @@ -84,8 +83,8 @@ protected void beforeTest() { Assertions.assertNotNull(connectionString, "Cannot continue test if connectionString is not set."); StorageAuthenticationSettings authSettings = storageConnectionString.getStorageAuthSettings(); - TablesSharedKeyCredential sharedKeyCredential = new TablesSharedKeyCredential(authSettings.getAccount().getName(), - authSettings.getAccount().getAccessKey()); + TablesSharedKeyCredential sharedKeyCredential = new TablesSharedKeyCredential( + authSettings.getAccount().getName(), authSettings.getAccount().getAccessKey()); List policies = new ArrayList<>(); policies.add(new AddDatePolicy()); @@ -112,13 +111,12 @@ protected void beforeTest() { .httpClient(httpClientToUse) .policies(policies.toArray(new HttpPipelinePolicy[0])) .build(); - runner = CosmosThrottled.get(new AzureTableImplBuilder() + azureTable = new AzureTableImplBuilder() .pipeline(pipeline) .serializerAdapter(new TablesJacksonSerializer()) .version(TablesServiceVersion.getLatest().getVersion()) .url(storageConnectionString.getTableEndpoint().getPrimaryUri()) - .buildClient(), - interceptorManager.isPlaybackMode()); + .buildClient(); } @Override @@ -126,27 +124,27 @@ protected void afterTest() { QueryOptions queryOptions = new QueryOptions() .setFormat(OdataMetadataFormat.APPLICATION_JSON_ODATA_MINIMALMETADATA); - List result = runner.run(azureTable -> azureTable.getTables().queryWithResponseAsync(testResourceNamer.randomUuid(), - null, queryOptions, Context.NONE)).block().getValue().getValue(); + List result = azureTable.getTables().queryWithResponseAsync( + testResourceNamer.randomUuid(), null, queryOptions, Context.NONE).block().getValue().getValue(); - Mono.when(Flux.fromIterable(result).flatMap(tableResponseProperty -> runner.run(azureTable -> + Mono.when(Flux.fromIterable(result).flatMap(tableResponseProperty -> azureTable.getTables().deleteWithResponseAsync(tableResponseProperty.getTableName(), - testResourceNamer.randomUuid(), Context.NONE)))).block(); + testResourceNamer.randomUuid(), Context.NONE))).block(); } void createTable(String tableName) { TableProperties tableProperties = new TableProperties().setTableName(tableName); String requestId = testResourceNamer.randomUuid(); - runner.run(azureTable -> azureTable.getTables().createWithResponseAsync(tableProperties, requestId, - ResponseFormat.RETURN_NO_CONTENT, null, Context.NONE).block()); + azureTable.getTables().createWithResponseAsync(tableProperties, requestId, ResponseFormat.RETURN_NO_CONTENT, + null, Context.NONE).block(); } void insertNoETag(String tableName, Map properties) { String requestId = testResourceNamer.randomUuid(); - runner.run(azureTable -> azureTable.getTables().insertEntityWithResponseAsync(tableName, TIMEOUT_IN_MS, - requestId, ResponseFormat.RETURN_NO_CONTENT, properties, null, Context.NONE).log().block()); + azureTable.getTables().insertEntityWithResponseAsync(tableName, TIMEOUT_IN_MS, requestId, + ResponseFormat.RETURN_NO_CONTENT, properties, null, Context.NONE).log().block(); } @Test @@ -158,8 +156,8 @@ void createTableImpl() { String requestId = testResourceNamer.randomUuid(); // Act & Assert - StepVerifier.create(runner.run(azureTable -> azureTable.getTables().createWithResponseAsync(tableProperties, - requestId, ResponseFormat.RETURN_NO_CONTENT, null, Context.NONE))) + StepVerifier.create(azureTable.getTables().createWithResponseAsync(tableProperties, requestId, + ResponseFormat.RETURN_NO_CONTENT, null, Context.NONE)) .assertNext(response -> { Assertions.assertEquals(expectedStatusCode, response.getStatusCode()); }) @@ -177,8 +175,8 @@ void createTableDuplicateNameImpl() { String requestId = testResourceNamer.randomUuid(); // Act & Assert - StepVerifier.create(runner.run(azureTable -> azureTable.getTables().createWithResponseAsync(tableProperties, - requestId, ResponseFormat.RETURN_NO_CONTENT, defaultQueryOptions, Context.NONE))) + StepVerifier.create(azureTable.getTables().createWithResponseAsync(tableProperties, requestId, + ResponseFormat.RETURN_NO_CONTENT, defaultQueryOptions, Context.NONE)) .expectErrorSatisfies(error -> { assertTrue(error instanceof TableServiceErrorException); @@ -201,8 +199,7 @@ void deleteTableImpl() { String requestId = testResourceNamer.randomUuid(); // Act & Assert - StepVerifier.create(runner.run(azureTable -> azureTable.getTables().deleteWithResponseAsync(tableName, - requestId, Context.NONE))) + StepVerifier.create(azureTable.getTables().deleteWithResponseAsync(tableName, requestId, Context.NONE)) .assertNext(response -> { Assertions.assertEquals(expectedStatusCode, response.getStatusCode()); }) @@ -217,8 +214,7 @@ void deleteNonExistentTableImpl() { String requestId = testResourceNamer.randomUuid(); // Act & Assert - StepVerifier.create(runner.run(azureTable -> azureTable.getTables().deleteWithResponseAsync(tableName, - requestId, Context.NONE))) + StepVerifier.create(azureTable.getTables().deleteWithResponseAsync(tableName, requestId, Context.NONE)) .expectError(com.azure.data.tables.implementation.models.TableServiceErrorException.class) .verify(); } @@ -239,8 +235,7 @@ void queryTableImpl() { String requestId = testResourceNamer.randomUuid(); // Act & Assert - StepVerifier.create(runner.run(azureTable -> azureTable.getTables().queryWithResponseAsync(requestId, null, - queryOptions, Context.NONE))) + StepVerifier.create(azureTable.getTables().queryWithResponseAsync(requestId, null, queryOptions, Context.NONE)) .assertNext(response -> { Assertions.assertEquals(expectedStatusCode, response.getStatusCode()); List results = response.getValue().getValue(); @@ -269,8 +264,7 @@ void queryTableWithFilterImpl() { queryOptions.setFilter(TABLE_NAME_KEY + " eq '" + tableA + "'"); // Act & Assert - StepVerifier.create(runner.run(azureTable -> azureTable.getTables().queryWithResponseAsync(requestId, null, - queryOptions, Context.NONE))) + StepVerifier.create(azureTable.getTables().queryWithResponseAsync(requestId, null, queryOptions, Context.NONE)) .assertNext(response -> { Assertions.assertEquals(expectedStatusCode, response.getStatusCode()); Assertions.assertEquals(expectedSize, response.getValue().getValue().size()); @@ -297,8 +291,7 @@ void queryTableWithTopImpl() { queryOptions.setTop(1); // Act & Assert - StepVerifier.create(runner.run(azureTable -> azureTable.getTables().queryWithResponseAsync(requestId, null, - queryOptions, Context.NONE))) + StepVerifier.create(azureTable.getTables().queryWithResponseAsync(requestId, null, queryOptions, Context.NONE)) .assertNext(response -> { Assertions.assertEquals(expectedStatusCode, response.getStatusCode()); Assertions.assertEquals(expectedSize, response.getValue().getValue().size()); @@ -325,8 +318,8 @@ void insertNoETagImpl() { String requestId = testResourceNamer.randomUuid(); // Act & Assert - StepVerifier.create(runner.run(azureTable -> azureTable.getTables().insertEntityWithResponseAsync(tableName, - TIMEOUT_IN_MS, requestId, ResponseFormat.RETURN_NO_CONTENT, properties, null, Context.NONE))) + StepVerifier.create(azureTable.getTables().insertEntityWithResponseAsync(tableName, TIMEOUT_IN_MS, requestId, + ResponseFormat.RETURN_NO_CONTENT, properties, null, Context.NONE)) .assertNext(response -> { Assertions.assertEquals(expectedStatusCode, response.getStatusCode()); }) @@ -350,15 +343,15 @@ void mergeEntityImpl() { properties.put("extraProperty", testResourceNamer.randomName("extraProperty", 16)); // Act & Assert - if (runner.isCosmos()) { + if (azureTable.getUrl().contains("cosmos.azure.com")) { // This scenario is currently broken when using the CosmosDB Table API - StepVerifier.create(runner.run(azureTable -> azureTable.getTables().mergeEntityWithResponseAsync(tableName, - partitionKeyValue, rowKeyValue, TIMEOUT_IN_MS, requestId, "*", properties, null, Context.NONE))) + StepVerifier.create(azureTable.getTables().mergeEntityWithResponseAsync(tableName, partitionKeyValue, + rowKeyValue, TIMEOUT_IN_MS, requestId, "*", properties, null, Context.NONE)) .expectError(com.azure.data.tables.implementation.models.TableServiceErrorException.class) .verify(); } else { - StepVerifier.create(runner.run(azureTable -> azureTable.getTables().mergeEntityWithResponseAsync(tableName, - partitionKeyValue, rowKeyValue, TIMEOUT_IN_MS, requestId, "*", properties, null, Context.NONE))) + StepVerifier.create(azureTable.getTables().mergeEntityWithResponseAsync(tableName, partitionKeyValue, + rowKeyValue, TIMEOUT_IN_MS, requestId, "*", properties, null, Context.NONE)) .assertNext(response -> { Assertions.assertEquals(expectedStatusCode, response.getStatusCode()); }) @@ -378,8 +371,8 @@ void mergeNonExistentEntityImpl() { String requestId = testResourceNamer.randomUuid(); // Act & Assert - StepVerifier.create(runner.run(azureTable -> azureTable.getTables().mergeEntityWithResponseAsync(tableName, - partitionKeyValue, rowKeyValue, TIMEOUT_IN_MS, requestId, "*", properties, null, Context.NONE))) + StepVerifier.create(azureTable.getTables().mergeEntityWithResponseAsync(tableName, partitionKeyValue, + rowKeyValue, TIMEOUT_IN_MS, requestId, "*", properties, null, Context.NONE)) .expectError(com.azure.data.tables.implementation.models.TableServiceErrorException.class) .verify(); } @@ -400,8 +393,8 @@ void updateEntityImpl() { properties.put("extraProperty", testResourceNamer.randomName("extraProperty", 16)); // Act & Assert - StepVerifier.create(runner.run(azureTable -> azureTable.getTables().updateEntityWithResponseAsync(tableName, - partitionKeyValue, rowKeyValue, TIMEOUT_IN_MS, requestId, "*", properties, null, Context.NONE))) + StepVerifier.create(azureTable.getTables().updateEntityWithResponseAsync(tableName, partitionKeyValue, + rowKeyValue, TIMEOUT_IN_MS, requestId, "*", properties, null, Context.NONE)) .assertNext(response -> { Assertions.assertEquals(expectedStatusCode, response.getStatusCode()); }) @@ -420,8 +413,8 @@ void updateNonExistentEntityImpl() { String requestId = testResourceNamer.randomUuid(); // Act & Assert - StepVerifier.create(runner.run(azureTable -> azureTable.getTables().updateEntityWithResponseAsync(tableName, - partitionKeyValue, rowKeyValue, TIMEOUT_IN_MS, requestId, "*", properties, null, Context.NONE))) + StepVerifier.create(azureTable.getTables().updateEntityWithResponseAsync(tableName, partitionKeyValue, + rowKeyValue, TIMEOUT_IN_MS, requestId, "*", properties, null, Context.NONE)) .expectError(com.azure.data.tables.implementation.models.TableServiceErrorException.class) .verify(); } @@ -441,8 +434,8 @@ void deleteEntityImpl() { insertNoETag(tableName, properties); // Act & Assert - StepVerifier.create(runner.run(azureTable -> azureTable.getTables().deleteEntityWithResponseAsync(tableName, - partitionKeyValue, rowKeyValue, "*", TIMEOUT_IN_MS, requestId, null, Context.NONE))) + StepVerifier.create(azureTable.getTables().deleteEntityWithResponseAsync(tableName, partitionKeyValue, + rowKeyValue, "*", TIMEOUT_IN_MS, requestId, null, Context.NONE)) .assertNext(response -> { Assertions.assertEquals(expectedStatusCode, response.getStatusCode()); }) @@ -460,8 +453,8 @@ void deleteNonExistentEntityImpl() { String requestId = testResourceNamer.randomUuid(); // Act & Assert - StepVerifier.create(runner.run(azureTable -> azureTable.getTables().deleteEntityWithResponseAsync(tableName, - partitionKeyValue, rowKeyValue, "*", TIMEOUT_IN_MS, requestId, null, Context.NONE))) + StepVerifier.create(azureTable.getTables().deleteEntityWithResponseAsync(tableName, partitionKeyValue, + rowKeyValue, "*", TIMEOUT_IN_MS, requestId, null, Context.NONE)) .expectError(com.azure.data.tables.implementation.models.TableServiceErrorException.class) .verify(); } @@ -470,7 +463,8 @@ void deleteNonExistentEntityImpl() { void queryEntityImpl() { // Arrange String requestId = testResourceNamer.randomUuid(); - QueryOptions queryOptions = new QueryOptions().setFormat(OdataMetadataFormat.APPLICATION_JSON_ODATA_FULLMETADATA); + QueryOptions queryOptions = new QueryOptions() + .setFormat(OdataMetadataFormat.APPLICATION_JSON_ODATA_FULLMETADATA); String tableName = testResourceNamer.randomName("test", 20); createTable(tableName); //insert entity A @@ -488,8 +482,8 @@ void queryEntityImpl() { int expectedStatusCode = 200; // Act & Assert - StepVerifier.create(runner.run(azureTable -> azureTable.getTables().queryEntitiesWithResponseAsync(tableName, - TIMEOUT_IN_MS, requestId, null, null, queryOptions, Context.NONE))) + StepVerifier.create(azureTable.getTables().queryEntitiesWithResponseAsync(tableName, TIMEOUT_IN_MS, requestId, + null, null, queryOptions, Context.NONE)) .assertNext(response -> { Assertions.assertEquals(expectedStatusCode, response.getStatusCode()); List> results = response.getValue().getValue(); @@ -504,7 +498,8 @@ void queryEntityImpl() { void queryEntityImplWithSelect() { // Arrange String requestId = testResourceNamer.randomUuid(); - QueryOptions queryOptions = new QueryOptions().setFormat(OdataMetadataFormat.APPLICATION_JSON_ODATA_FULLMETADATA); + QueryOptions queryOptions = new QueryOptions() + .setFormat(OdataMetadataFormat.APPLICATION_JSON_ODATA_FULLMETADATA); String tableName = testResourceNamer.randomName("test", 20); createTable(tableName); @@ -529,8 +524,8 @@ void queryEntityImplWithSelect() { queryOptions.setSelect(ROW_KEY); // Act & Assert - StepVerifier.create(runner.run(azureTable -> azureTable.getTables().queryEntitiesWithResponseAsync(tableName, - TIMEOUT_IN_MS, requestId, null, null, queryOptions, Context.NONE))) + StepVerifier.create(azureTable.getTables().queryEntitiesWithResponseAsync(tableName, TIMEOUT_IN_MS, requestId, + null, null, queryOptions, Context.NONE)) .assertNext(response -> { Assertions.assertEquals(expectedStatusCode, response.getStatusCode()); List> results = response.getValue().getValue(); @@ -546,7 +541,8 @@ void queryEntityImplWithSelect() { void queryEntityImplWithFilter() { // Arrange String requestId = testResourceNamer.randomUuid(); - QueryOptions queryOptions = new QueryOptions().setFormat(OdataMetadataFormat.APPLICATION_JSON_ODATA_FULLMETADATA); + QueryOptions queryOptions = new QueryOptions() + .setFormat(OdataMetadataFormat.APPLICATION_JSON_ODATA_FULLMETADATA); String tableName = testResourceNamer.randomName("test", 20); createTable(tableName); @@ -570,8 +566,8 @@ void queryEntityImplWithFilter() { queryOptions.setFilter(PARTITION_KEY + " eq '" + partitionKeyEntityA + "'"); // Act & Assert - StepVerifier.create(runner.run(azureTable -> azureTable.getTables().queryEntitiesWithResponseAsync(tableName, - TIMEOUT_IN_MS, requestId, null, null, queryOptions, Context.NONE))) + StepVerifier.create(azureTable.getTables().queryEntitiesWithResponseAsync(tableName, TIMEOUT_IN_MS, requestId, + null, null, queryOptions, Context.NONE)) .assertNext(response -> { Assertions.assertEquals(expectedStatusCode, response.getStatusCode()); Assertions.assertEquals(expectedSize, response.getValue().getValue().size()); @@ -585,7 +581,8 @@ void queryEntityImplWithFilter() { void queryEntityImplWithTop() { // Arrange String requestId = testResourceNamer.randomUuid(); - QueryOptions queryOptions = new QueryOptions().setFormat(OdataMetadataFormat.APPLICATION_JSON_ODATA_FULLMETADATA); + QueryOptions queryOptions = new QueryOptions() + .setFormat(OdataMetadataFormat.APPLICATION_JSON_ODATA_FULLMETADATA); String tableName = testResourceNamer.randomName("test", 20); createTable(tableName); @@ -609,8 +606,8 @@ void queryEntityImplWithTop() { queryOptions.setTop(1); // Act & Assert - StepVerifier.create(runner.run(azureTable -> azureTable.getTables().queryEntitiesWithResponseAsync(tableName, - TIMEOUT_IN_MS, requestId, null, null, queryOptions, Context.NONE))) + StepVerifier.create(azureTable.getTables().queryEntitiesWithResponseAsync(tableName, TIMEOUT_IN_MS, requestId, + null, null, queryOptions, Context.NONE)) .assertNext(response -> { Assertions.assertEquals(expectedStatusCode, response.getStatusCode()); Assertions.assertEquals(expectedSize, response.getValue().getValue().size());