-
Notifications
You must be signed in to change notification settings - Fork 2k
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
[Tables] Fix tables livetest #14797
Changes from all commits
6853bab
2c2ba82
701ffe6
e8eeabe
b464164
4969d95
c775e68
39d2300
d08fd47
2366f82
2bebd0f
582c6db
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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; | ||
|
@@ -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; | ||
|
@@ -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); | ||
|
@@ -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(); | ||
|
@@ -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(); | ||
} | ||
|
@@ -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()); | ||
}) | ||
|
@@ -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()); | ||
}) | ||
|
@@ -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)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
@@ -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()) | ||
|
@@ -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)) | ||
|
@@ -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)) | ||
|
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.