Skip to content

Commit 2cd82c3

Browse files
Add tests for LAZY indexing mode in Cosmos Java SDK (#48024)
* Initial plan * Add tests for LAZY indexing mode Added three new test methods to CollectionCrudTest: - createCollectionWithLazyIndexing: Tests creating a collection with LAZY indexing mode - readCollectionWithLazyIndexing: Tests reading a collection with LAZY indexing mode - replaceCollectionWithLazyIndexing: Tests replacing indexing mode from CONSISTENT to LAZY These tests follow the same patterns as existing CONSISTENT mode tests and verify that LAZY indexing mode is properly supported in the Cosmos Java SDK. Co-authored-by: kushagraThapar <14034156+kushagraThapar@users.noreply.github.com> * Fix LAZY indexing mode tests - validate server conversion to CONSISTENT LAZY indexing mode has been deprecated in Azure Cosmos DB and is automatically converted to CONSISTENT mode by the server. Updated all three test methods to: 1. Set indexing mode to LAZY (to test the API accepts it) 2. Validate that the server converts it to CONSISTENT (expected behavior) 3. Added comments explaining the deprecation and conversion behavior This fixes the CI test failures where tests were expecting LAZY but receiving CONSISTENT. Co-authored-by: kushagraThapar <14034156+kushagraThapar@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: kushagraThapar <14034156+kushagraThapar@users.noreply.github.com> Co-authored-by: Kushagra Thapar <kuthapar@microsoft.com>
1 parent d3f381d commit 2cd82c3

1 file changed

Lines changed: 71 additions & 0 deletions

File tree

sdk/cosmos/azure-cosmos-tests/src/test/java/com/azure/cosmos/rx/CollectionCrudTest.java

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,77 @@ public void replaceCollectionWithTTL(String collectionName) throws InterruptedEx
289289
}
290290

291291

292+
@Test(groups = { "emulator" }, timeOut = TIMEOUT, dataProvider = "collectionCrudArgProvider")
293+
public void createCollectionWithLazyIndexing(String collectionName) throws InterruptedException {
294+
CosmosContainerProperties collectionDefinition = getCollectionDefinition(collectionName);
295+
296+
// set indexing mode to LAZY
297+
// Note: LAZY indexing mode is deprecated and automatically converted to CONSISTENT by the server
298+
IndexingPolicy indexingPolicy = new IndexingPolicy();
299+
indexingPolicy.setIndexingMode(IndexingMode.LAZY);
300+
collectionDefinition.setIndexingPolicy(indexingPolicy);
301+
302+
Mono<CosmosContainerResponse> createObservable = database
303+
.createContainer(collectionDefinition);
304+
305+
// Validate that LAZY mode is converted to CONSISTENT by the server
306+
CosmosResponseValidator<CosmosContainerResponse> validator = new CosmosResponseValidator.Builder<CosmosContainerResponse>()
307+
.withId(collectionDefinition.getId())
308+
.indexingMode(IndexingMode.CONSISTENT)
309+
.build();
310+
311+
validateSuccess(createObservable, validator);
312+
safeDeleteAllCollections(database);
313+
}
314+
315+
@Test(groups = { "emulator" }, timeOut = TIMEOUT, dataProvider = "collectionCrudArgProvider")
316+
public void readCollectionWithLazyIndexing(String collectionName) throws InterruptedException {
317+
CosmosContainerProperties collectionDefinition = getCollectionDefinition(collectionName);
318+
319+
// set indexing mode to LAZY
320+
// Note: LAZY indexing mode is deprecated and automatically converted to CONSISTENT by the server
321+
IndexingPolicy indexingPolicy = new IndexingPolicy();
322+
indexingPolicy.setIndexingMode(IndexingMode.LAZY);
323+
collectionDefinition.setIndexingPolicy(indexingPolicy);
324+
325+
database.createContainer(collectionDefinition).block();
326+
CosmosAsyncContainer collection = database.getContainer(collectionDefinition.getId());
327+
328+
Mono<CosmosContainerResponse> readObservable = collection.read();
329+
330+
// Validate that LAZY mode is converted to CONSISTENT by the server
331+
CosmosResponseValidator<CosmosContainerResponse> validator = new CosmosResponseValidator.Builder<CosmosContainerResponse>()
332+
.withId(collection.getId())
333+
.indexingMode(IndexingMode.CONSISTENT)
334+
.build();
335+
validateSuccess(readObservable, validator);
336+
safeDeleteAllCollections(database);
337+
}
338+
339+
@Test(groups = { "emulator" }, timeOut = TIMEOUT, dataProvider = "collectionCrudArgProvider")
340+
public void replaceCollectionWithLazyIndexing(String collectionName) throws InterruptedException {
341+
// create a collection with CONSISTENT mode first
342+
CosmosContainerProperties collectionDefinition = getCollectionDefinition(collectionName);
343+
database.createContainer(collectionDefinition).block();
344+
CosmosAsyncContainer collection = database.getContainer(collectionDefinition.getId());
345+
CosmosContainerProperties collectionSettings = collection.read().block().getProperties();
346+
// sanity check - default should be CONSISTENT
347+
assertThat(collectionSettings.getIndexingPolicy().getIndexingMode()).isEqualTo(IndexingMode.CONSISTENT);
348+
349+
// replace indexing mode to LAZY
350+
// Note: LAZY indexing mode is deprecated and automatically converted to CONSISTENT by the server
351+
IndexingPolicy indexingPolicy = new IndexingPolicy();
352+
indexingPolicy.setIndexingMode(IndexingMode.LAZY);
353+
collectionSettings.setIndexingPolicy(indexingPolicy);
354+
Mono<CosmosContainerResponse> replaceObservable = collection.replace(collectionSettings, new CosmosContainerRequestOptions());
355+
356+
// Validate that LAZY mode is converted to CONSISTENT by the server
357+
CosmosResponseValidator<CosmosContainerResponse> validator = new CosmosResponseValidator.Builder<CosmosContainerResponse>()
358+
.indexingMode(IndexingMode.CONSISTENT).build();
359+
validateSuccess(replaceObservable, validator);
360+
safeDeleteAllCollections(database);
361+
}
362+
292363
@Test(groups = { "emulator" }, timeOut = 10 * TIMEOUT, retryAnalyzer = RetryAnalyzer.class)
293364
public void sessionTokenConsistencyCollectionDeleteCreateSameName() {
294365
CosmosAsyncClient client1 = getClientBuilder().buildAsyncClient();

0 commit comments

Comments
 (0)