Skip to content
Draft
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 @@ -144,6 +144,30 @@ public void validate(List<FeedResponse<T>> feedList) {
return this;
}

/**
* Asserts the results CONTAIN all of the expected resource IDs, allowing additional
* unexpected results. Unlike {@link #exactlyContainsInAnyOrder(List)} this does not
* require the result set to be limited to the expected IDs, so it is safe for
* account-global reads (e.g. readAllDatabases) that run against shared test accounts
* where other resources may exist concurrently.
*/
public Builder<T> containsResourceIds(List<String> expectedIds) {
validators.add(new FeedResponseListValidator<T>() {
@Override
public void validate(List<FeedResponse<T>> feedList) {
List<String> actualIds = feedList
.stream()
.flatMap(f -> f.getResults().stream())
.map(r -> getResource(r).getResourceId())
.collect(Collectors.toList());
assertThat(actualIds)
.describedAs("Resource IDs of results")
.containsAll(expectedIds);
}
});
return this;
}

public Builder<T> exactlyContainsIdsInAnyOrder(List<String> expectedIds) {
validators.add(new FeedResponseListValidator<T>() {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
public class ReadFeedDatabasesTest extends TestSuiteBase {

private List<CosmosDatabaseProperties> createdDatabases = new ArrayList<>();
private List<CosmosDatabaseProperties> allDatabases = new ArrayList<>();

private CosmosAsyncClient client;

Expand All @@ -38,11 +37,13 @@ public void readDatabases() throws Exception {

CosmosPagedFlux<CosmosDatabaseProperties> feedObservable = client.readAllDatabases();

int expectedPageSize = (allDatabases.size() + maxItemCount - 1) / maxItemCount;
// readAllDatabases is an account-global read. Live tests share a fixed account, so
// other test runs may create/delete databases concurrently. Assert only that the
// databases created by this test are present (containment) rather than asserting the
// exact account-wide set/count/page-count, which would be non-deterministic.
FeedResponseListValidator<CosmosDatabaseProperties> validator = new FeedResponseListValidator.Builder<CosmosDatabaseProperties>()
.totalSize(allDatabases.size())
.exactlyContainsInAnyOrder(allDatabases.stream().map(d -> d.getResourceId()).collect(Collectors.toList()))
.numberOfPages(expectedPageSize)
.containsResourceIds(createdDatabases.stream().map(d -> d.getResourceId()).collect(Collectors.toList()))
.numberOfPagesIsGreaterThanOrEqualTo(1)
.pageSatisfy(0, new FeedResponseValidator.Builder<CosmosDatabaseProperties>()
.requestChargeGreaterThanOrEqualTo(1.0).build())
.build();
Expand All @@ -53,13 +54,9 @@ public void readDatabases() throws Exception {
@BeforeClass(groups = { "query" }, timeOut = SETUP_TIMEOUT)
public void before_ReadFeedDatabasesTest() throws URISyntaxException {
client = getClientBuilder().buildAsyncClient();
allDatabases = client.readAllDatabases()
.collectList()
.block();
for(int i = 0; i < 5; i++) {
createdDatabases.add(createDatabase(client));
}
allDatabases.addAll(createdDatabases);
}

public CosmosDatabaseProperties createDatabase(CosmosAsyncClient client) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ public class ReadFeedOffersTest extends TestSuiteBase {
public final String databaseId = DatabaseForTest.generateId();

private Database createdDatabase;
private List<Offer> allOffers = new ArrayList<>();
private final List<DocumentCollection> createdCollections = new ArrayList<>();
private List<Offer> expectedOffers = new ArrayList<>();

private AsyncDocumentClient client;

Expand Down Expand Up @@ -78,13 +79,13 @@ public void readOffers() throws Exception {

Flux<FeedResponse<Offer>> feedObservable = client.readOffers(dummyState);

int maxItemCount = ModelBridgeInternal.getMaxItemCountFromQueryRequestOptions(options);
int expectedPageSize = (allOffers.size() + maxItemCount - 1) / maxItemCount;

// readOffers is an account-global read. Live tests share a fixed account, so
// other test runs may create/delete containers (and thus offers) concurrently.
// Assert only that the offers for the containers created by this test are present
// (containment) rather than asserting the exact account-wide set/count/page-count.
FeedResponseListValidator<Offer> validator = new FeedResponseListValidator.Builder<Offer>()
.totalSize(allOffers.size())
.exactlyContainsInAnyOrder(allOffers.stream().map(d -> d.getResourceId()).collect(Collectors.toList()))
.numberOfPages(expectedPageSize)
.containsResourceIds(expectedOffers.stream().map(d -> d.getResourceId()).collect(Collectors.toList()))
.numberOfPagesIsGreaterThanOrEqualTo(1)
.pageSatisfy(0, new FeedResponseValidator.Builder<Offer>()
.requestChargeGreaterThanOrEqualTo(1.0).build())
.build();
Expand All @@ -98,7 +99,7 @@ public void before_ReadFeedOffersTest() {
createdDatabase = createDatabase(client, databaseId);

for(int i = 0; i < 3; i++) {
createCollections(client);
createdCollections.add(createCollections(client));
}

QueryFeedOperationState offerDummyState = TestUtils.createDummyQueryFeedOperationState(
Expand All @@ -109,12 +110,18 @@ public void before_ReadFeedOffersTest() {
);

try {
allOffers = client.readOffers(offerDummyState)
List<String> createdCollectionRids = createdCollections.stream()
.map(DocumentCollection::getResourceId)
.collect(Collectors.toList());
expectedOffers = client.readOffers(offerDummyState)
.map(FeedResponse::getResults)
.collectList()
.map(list -> list.stream().flatMap(Collection::stream).collect(Collectors.toList()))
.single()
.block();
.block()
.stream()
.filter(o -> createdCollectionRids.contains(o.getOfferResourceId()))
.collect(Collectors.toList());
} finally {
safeClose(offerDummyState);
}
Expand Down
Loading
Loading