Source:
public void queryItemsWithEventualConsistency() throws Exception{ CosmosAsyncContainer asyncContainer = getSharedMultiPartitionCosmosContainer(this.client.asyncClient()); container = client.getDatabase(asyncContainer.getDatabase().getId()).getContainer(asyncContainer.getId()); String idAndPkValue = UUID.randomUUID().toString(); ObjectNode properties = getDocumentDefinition(idAndPkValue, idAndPkValue); CosmosItemResponse<ObjectNode> itemResponse = container.createItem(properties); String query = String.format("SELECT * from c where c.id = '%s'", idAndPkValue); CosmosQueryRequestOptions cosmosQueryRequestOptions = new CosmosQueryRequestOptions() .setSessionToken(StringUtils.repeat("SomeManualInvalidSessionToken", 2000)) .setConsistencyLevel(ConsistencyLevel.EVENTUAL); CosmosPagedIterable<ObjectNode> feedResponseIterator1 = container.queryItems(query, cosmosQueryRequestOptions, ObjectNode.class); feedResponseIterator1.handle((r) -> System.out.println("Query RequestDiagnostics: " + r.getCosmosDiagnostics().toString())); System.out.println("hello world"); assertThat(feedResponseIterator1.iterator().hasNext()).isTrue(); assertThat(feedResponseIterator1.stream().count() == 1); SqlQuerySpec querySpec = new SqlQuerySpec(query); CosmosPagedIterable<ObjectNode> feedResponseIterator3 = container.queryItems(querySpec, cosmosQueryRequestOptions, ObjectNode.class); feedResponseIterator3.handle((r) -> System.out.println("Query RequestDiagnostics: " + r.getCosmosDiagnostics().toString())); assertThat(feedResponseIterator3.iterator().hasNext()).isTrue(); assertThat(feedResponseIterator3.stream().count() == 1); }

Target:
public void queryItemsWithEventualConsistency() throws Exception{ CosmosAsyncContainer asyncContainer = getSharedMultiPartitionCosmosContainer(this.client.asyncClient()); container = client.getDatabase(asyncContainer.getDatabase().getId()).getContainer(asyncContainer.getId()); String idAndPkValue = UUID.randomUUID().toString(); ObjectNode properties = getDocumentDefinition(idAndPkValue, idAndPkValue); CosmosItemResponse<ObjectNode> itemResponse = container.createItem(properties); String query = String.format("SELECT * from c where c.id = '%s'", idAndPkValue); CosmosQueryRequestOptions cosmosQueryRequestOptions = new CosmosQueryRequestOptions() .setSessionToken(StringUtils.repeat("SomeManualInvalidSessionToken", 2000)) .setConsistencyLevel(ConsistencyLevel.EVENTUAL); CosmosPagedIterable<ObjectNode> feedResponseIterator1 = container.queryItems(query, cosmosQueryRequestOptions, ObjectNode.class); feedResponseIterator1.handle( (r) -> logger.info("Query RequestDiagnostics: {}", r.getCosmosDiagnostics().toString())); assertThat(feedResponseIterator1.iterator().hasNext()).isTrue(); assertThat(feedResponseIterator1.stream().count() == 1); SqlQuerySpec querySpec = new SqlQuerySpec(query); CosmosPagedIterable<ObjectNode> feedResponseIterator3 = container.queryItems(querySpec, cosmosQueryRequestOptions, ObjectNode.class); feedResponseIterator3.handle( (r) -> logger.info("Query RequestDiagnostics: {}", r.getCosmosDiagnostics().toString())); assertThat(feedResponseIterator3.iterator().hasNext()).isTrue(); assertThat(feedResponseIterator3.stream().count() == 1); }