Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

[Tables] Fix tables livetest #14797

Merged
merged 12 commits into from
Sep 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package com.azure.data.tables;

import com.azure.core.http.HttpClient;
import com.azure.core.http.policy.ExponentialBackoff;
import com.azure.core.http.policy.HttpLogDetailLevel;
import com.azure.core.http.policy.HttpLogOptions;
import com.azure.core.http.policy.RetryPolicy;
Expand All @@ -15,7 +16,6 @@
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
import reactor.core.publisher.Mono;
import reactor.test.StepVerifier;

import java.time.Duration;
Expand All @@ -26,7 +26,7 @@
* Tests methods for {@link TableServiceAsyncClient}.
*/
public class TableServiceAsyncClientTest extends TestBase {
private static final Duration TIMEOUT = Duration.ofSeconds(30);
private static final Duration TIMEOUT = Duration.ofSeconds(100);
private TableServiceAsyncClient serviceClient;

@BeforeAll
Expand All @@ -49,9 +49,12 @@ protected void beforeTest() {
if (interceptorManager.isPlaybackMode()) {
builder.httpClient(interceptorManager.getPlaybackClient());
} else {
builder.httpClient(HttpClient.createDefault())
.addPolicy(interceptorManager.getRecordPolicy())
.addPolicy(new RetryPolicy());
builder.httpClient(HttpClient.createDefault());
if (!interceptorManager.isLiveMode()) {
builder.addPolicy(interceptorManager.getRecordPolicy());
}
builder.addPolicy(new RetryPolicy(new ExponentialBackoff(6, Duration.ofMillis(1500),
Duration.ofSeconds(100))));
}

serviceClient = builder.buildAsyncClient();
Expand Down Expand Up @@ -184,10 +187,8 @@ void serviceListTablesAsync() {
// Arrange
final String tableName = testResourceNamer.randomName("test", 20);
final String tableName2 = testResourceNamer.randomName("test", 20);
Mono.when(
serviceClient.createTable(tableName),
serviceClient.createTable(tableName2)
).block(TIMEOUT);
serviceClient.createTable(tableName).block(TIMEOUT);
serviceClient.createTable(tableName2).block(TIMEOUT);

// Act & Assert
StepVerifier.create(serviceClient.listTables())
Expand All @@ -204,10 +205,8 @@ void serviceListTablesWithFilterAsync() {
final String tableName = testResourceNamer.randomName("test", 20);
final String tableName2 = testResourceNamer.randomName("test", 20);
ListTablesOptions options = new ListTablesOptions().setFilter("TableName eq '" + tableName + "'");
Mono.when(
serviceClient.createTable(tableName),
serviceClient.createTable(tableName2)
).block(TIMEOUT);
serviceClient.createTable(tableName).block(TIMEOUT);
serviceClient.createTable(tableName2).block(TIMEOUT);

// Act & Assert
StepVerifier.create(serviceClient.listTables(options))
Expand All @@ -228,12 +227,10 @@ void serviceListTablesWithTopAsync() {
final String tableName2 = testResourceNamer.randomName("test", 20);
final String tableName3 = testResourceNamer.randomName("test", 20);
ListTablesOptions options = new ListTablesOptions().setTop(2);
Mono.when(
serviceClient.createTable(tableName),
serviceClient.createTable(tableName2),
serviceClient.createTable(tableName3)
).block(TIMEOUT);

serviceClient.createTable(tableName).block(TIMEOUT);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason for splitting this into three sequential blocks rather than running them concurrently?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was having intermittent 429 issues with failures when using Mono.when with multiple streams against the CosmosDB API.

serviceClient.createTable(tableName2).block(TIMEOUT);
serviceClient.createTable(tableName3).block(TIMEOUT);

// Act & Assert
StepVerifier.create(serviceClient.listTables(options))
.expectNextCount(2)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package com.azure.data.tables;

import com.azure.core.http.HttpClient;
import com.azure.core.http.policy.ExponentialBackoff;
import com.azure.core.http.policy.HttpLogDetailLevel;
import com.azure.core.http.policy.HttpLogOptions;
import com.azure.core.http.policy.RetryPolicy;
Expand All @@ -12,6 +13,8 @@
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

import java.time.Duration;

public class TableServiceClientTest extends TestBase {
private TableServiceClient serviceClient;

Expand All @@ -25,11 +28,13 @@ protected void beforeTest() {
if (interceptorManager.isPlaybackMode()) {
builder.httpClient(interceptorManager.getPlaybackClient());
} else {
builder.httpClient(HttpClient.createDefault())
.addPolicy(interceptorManager.getRecordPolicy())
.addPolicy(new RetryPolicy());
builder.httpClient(HttpClient.createDefault());
if (!interceptorManager.isLiveMode()) {
builder.addPolicy(interceptorManager.getRecordPolicy());
}
builder.addPolicy(new RetryPolicy(new ExponentialBackoff(6, Duration.ofMillis(1500),
Duration.ofSeconds(100))));
}

serviceClient = builder.buildClient();
}

Expand All @@ -49,7 +54,8 @@ void serviceCreateTableFailsIfExists() {
serviceClient.createTable(tableName);

// Act & Assert
Assertions.assertThrows(TableServiceErrorException.class, () -> serviceClient.createTable(tableName));
Assertions.assertThrows(TableServiceErrorException.class,
() -> serviceClient.createTable(tableName));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package com.azure.data.tables;

import com.azure.core.http.HttpClient;
import com.azure.core.http.policy.ExponentialBackoff;
import com.azure.core.http.policy.HttpLogDetailLevel;
import com.azure.core.http.policy.HttpLogOptions;
import com.azure.core.http.policy.HttpPipelinePolicy;
Expand All @@ -12,9 +13,10 @@
import com.azure.data.tables.models.ListEntitiesOptions;
import com.azure.data.tables.models.TableEntity;
import com.azure.data.tables.models.UpdateMode;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
import reactor.core.publisher.Mono;
import reactor.test.StepVerifier;

import java.time.Duration;
Expand All @@ -32,12 +34,22 @@
* Tests {@link TableAsyncClient}.
*/
public class TablesAsyncClientTest extends TestBase {
private static final Duration TIMEOUT = Duration.ofSeconds(30);
private static final Duration TIMEOUT = Duration.ofSeconds(100);

private TableAsyncClient tableClient;
private HttpPipelinePolicy recordPolicy;
private HttpClient playbackClient;

@BeforeAll
static void beforeAll() {
StepVerifier.setDefaultTimeout(TIMEOUT);
}

@AfterAll
static void afterAll() {
StepVerifier.resetDefaultTimeout();
}

@Override
protected void beforeTest() {
final String tableName = testResourceNamer.randomName("tableName", 20);
Expand All @@ -51,10 +63,13 @@ protected void beforeTest() {
playbackClient = interceptorManager.getPlaybackClient();
builder.httpClient(playbackClient);
} else {
recordPolicy = interceptorManager.getRecordPolicy();
builder.httpClient(HttpClient.createDefault())
.addPolicy(recordPolicy)
.addPolicy(new RetryPolicy());
builder.httpClient(HttpClient.createDefault());
if (!interceptorManager.isLiveMode()) {
recordPolicy = interceptorManager.getRecordPolicy();
builder.addPolicy(recordPolicy);
}
builder.addPolicy(new RetryPolicy(new ExponentialBackoff(6, Duration.ofMillis(1500),
Duration.ofSeconds(100))));
}

tableClient = builder.buildAsyncClient();
Expand All @@ -74,15 +89,18 @@ void createTableAsync() {
if (interceptorManager.isPlaybackMode()) {
builder.httpClient(playbackClient);
} else {
builder.httpClient(HttpClient.createDefault())
.addPolicy(recordPolicy)
.addPolicy(new RetryPolicy());
builder.httpClient(HttpClient.createDefault());
if (!interceptorManager.isLiveMode()) {
builder.addPolicy(recordPolicy);
}
builder.addPolicy(new RetryPolicy(new ExponentialBackoff(6, Duration.ofMillis(1500),
Duration.ofSeconds(100))));
}

final TableAsyncClient asyncClient2 = builder.buildAsyncClient();
final TableAsyncClient tableClient2 = builder.buildAsyncClient();

// Act & Assert
StepVerifier.create(asyncClient2.create())
StepVerifier.create(tableClient2.create())
.expectComplete()
.verify();
}
Expand All @@ -100,16 +118,19 @@ void createTableWithResponseAsync() {
if (interceptorManager.isPlaybackMode()) {
builder.httpClient(playbackClient);
} else {
builder.httpClient(HttpClient.createDefault())
.addPolicy(recordPolicy)
.addPolicy(new RetryPolicy());
builder.httpClient(HttpClient.createDefault());
if (!interceptorManager.isLiveMode()) {
builder.addPolicy(recordPolicy);
}
builder.addPolicy(new RetryPolicy(new ExponentialBackoff(6, Duration.ofMillis(1500),
Duration.ofSeconds(100))));
}

final TableAsyncClient asyncClient2 = builder.buildAsyncClient();
final TableAsyncClient tableClient2 = builder.buildAsyncClient();
final int expectedStatusCode = 204;

// Act & Assert
StepVerifier.create(asyncClient2.createWithResponse())
StepVerifier.create(tableClient2.createWithResponse())
.assertNext(response -> {
assertEquals(expectedStatusCode, response.getStatusCode());
})
Expand Down Expand Up @@ -271,7 +292,8 @@ void deleteEntityWithResponseMatchETagAsync() {
assertNotNull(createdEntity.getETag(), "'eTag' should not be null.");

// Act & Assert
StepVerifier.create(tableClient.deleteEntityWithResponse(partitionKeyValue, rowKeyValue, createdEntity.getETag()))
StepVerifier.create(tableClient.deleteEntityWithResponse(partitionKeyValue, rowKeyValue,
createdEntity.getETag()))
.assertNext(response -> {
assertEquals(expectedStatusCode, response.getStatusCode());
})
Expand Down Expand Up @@ -339,20 +361,27 @@ void updateEntityWithResponseAsync(UpdateMode mode) {
createdEntity.getProperties().remove(oldPropertyKey);
createdEntity.addProperty(newPropertyKey, "valueB");

// Act
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(tableClient.getEntity(partitionKeyValue, rowKeyValue))
.assertNext(entity -> {
final Map<String, Object> properties = entity.getProperties();
assertTrue(properties.containsKey(newPropertyKey));
assertEquals(expectOldProperty, properties.containsKey(oldPropertyKey));
})
.verifyComplete();
// Act & Assert
if (mode == UpdateMode.MERGE && tableClient.getTableUrl().contains("cosmos.azure.com")) {
// This scenario is currently broken when using the CosmosDB Table API
StepVerifier.create(tableClient.updateEntityWithResponse(createdEntity, true, mode))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we split this into another test case and disable it? I feel it'll get lost as a comment since there is no issue or TODO tracking this.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, once support is merged for multiple tests with the same name (#14801) I will separate these into two test classes, one for Cosmos and one for Storage, each with their own recordings.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tracking this work in #14930

.expectError(com.azure.data.tables.implementation.models.TableServiceErrorException.class)
.verify();
} else {
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(tableClient.getEntity(partitionKeyValue, rowKeyValue))
.assertNext(entity -> {
final Map<String, Object> properties = entity.getProperties();
assertTrue(properties.containsKey(newPropertyKey));
assertEquals(expectOldProperty, properties.containsKey(oldPropertyKey));
})
.verifyComplete();
}
}

@Test
Expand All @@ -362,10 +391,8 @@ void listEntitiesAsync() {
final String partitionKeyValue = testResourceNamer.randomName("partitionKey", 20);
final String rowKeyValue = testResourceNamer.randomName("rowKey", 20);
final String rowKeyValue2 = testResourceNamer.randomName("rowKey", 20);
Mono.when(
tableClient.createEntity(new TableEntity(partitionKeyValue, rowKeyValue)),
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(tableClient.listEntities())
Expand All @@ -383,10 +410,8 @@ void listEntitiesWithFilterAsync() {
final String rowKeyValue = testResourceNamer.randomName("rowKey", 20);
final String rowKeyValue2 = testResourceNamer.randomName("rowKey", 20);
ListEntitiesOptions options = new ListEntitiesOptions().setFilter("RowKey eq '" + rowKeyValue + "'");
Mono.when(
tableClient.createEntity(new TableEntity(partitionKeyValue, rowKeyValue)),
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(tableClient.listEntities(options))
Expand Down Expand Up @@ -434,11 +459,9 @@ void listEntitiesWithTopAsync() {
final String rowKeyValue2 = testResourceNamer.randomName("rowKey", 20);
final String rowKeyValue3 = testResourceNamer.randomName("rowKey", 20);
ListEntitiesOptions options = new ListEntitiesOptions().setTop(2);
Mono.when(
tableClient.createEntity(new TableEntity(partitionKeyValue, rowKeyValue)),
tableClient.createEntity(new TableEntity(partitionKeyValue, rowKeyValue2)),
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(tableClient.listEntities(options))
Expand Down
Loading