From b7ec5c49b3fceab84644be020afb20ae3bd79c60 Mon Sep 17 00:00:00 2001 From: Kushagra Thapar Date: Mon, 30 Sep 2019 18:09:26 -0700 Subject: [PATCH 1/3] Only throw BadRequestException when initialPageSize is not != -1 and is not valid --- .../DocumentQueryExecutionContextFactory.java | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/sdk/cosmos/microsoft-azure-cosmos/src/main/java/com/azure/data/cosmos/internal/query/DocumentQueryExecutionContextFactory.java b/sdk/cosmos/microsoft-azure-cosmos/src/main/java/com/azure/data/cosmos/internal/query/DocumentQueryExecutionContextFactory.java index 6ba9e1d697cb..409a100f82bd 100644 --- a/sdk/cosmos/microsoft-azure-cosmos/src/main/java/com/azure/data/cosmos/internal/query/DocumentQueryExecutionContextFactory.java +++ b/sdk/cosmos/microsoft-azure-cosmos/src/main/java/com/azure/data/cosmos/internal/query/DocumentQueryExecutionContextFactory.java @@ -55,7 +55,7 @@ public static Flux collectionObs = Flux.empty(); - + if (resourceTypeEnum.isCollectionChild()) { collectionObs = resolveCollection(client, query, resourceTypeEnum, resourceLink).flux(); } @@ -108,10 +108,12 @@ public static Flux 0, "MaxItemCount", "INVALID MaxItemCount %s", initialPageSize); - if (validationError != null) { - return Flux.error(validationError); + if (validationError != null) { + return Flux.error(validationError); + } } QueryInfo queryInfo = partitionedQueryExecutionInfo.getQueryInfo(); @@ -144,7 +146,7 @@ public static Flux Flux Date: Mon, 30 Sep 2019 23:38:12 -0700 Subject: [PATCH 2/3] Made the change more readable --- .../query/DocumentQueryExecutionContextFactory.java | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/sdk/cosmos/microsoft-azure-cosmos/src/main/java/com/azure/data/cosmos/internal/query/DocumentQueryExecutionContextFactory.java b/sdk/cosmos/microsoft-azure-cosmos/src/main/java/com/azure/data/cosmos/internal/query/DocumentQueryExecutionContextFactory.java index 409a100f82bd..a6f704e596b6 100644 --- a/sdk/cosmos/microsoft-azure-cosmos/src/main/java/com/azure/data/cosmos/internal/query/DocumentQueryExecutionContextFactory.java +++ b/sdk/cosmos/microsoft-azure-cosmos/src/main/java/com/azure/data/cosmos/internal/query/DocumentQueryExecutionContextFactory.java @@ -108,12 +108,10 @@ public static Flux 0, "MaxItemCount", "INVALID MaxItemCount %s", initialPageSize); - if (validationError != null) { - return Flux.error(validationError); - } + BadRequestException validationError = Utils.checkRequestOrReturnException( + initialPageSize > 0 || initialPageSize == -1, "MaxItemCount", "Invalid MaxItemCount %s", initialPageSize); + if (validationError != null) { + return Flux.error(validationError); } QueryInfo queryInfo = partitionedQueryExecutionInfo.getQueryInfo(); From 105df9d75fb52da895b89c63ec72781af8512872 Mon Sep 17 00:00:00 2001 From: Kushagra Thapar Date: Wed, 2 Oct 2019 14:41:12 -0700 Subject: [PATCH 3/3] Fixed multi-master conflict resolution test --- .../rx/MultiMasterConflictResolutionTest.java | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/sdk/cosmos/microsoft-azure-cosmos/src/test/java/com/azure/data/cosmos/rx/MultiMasterConflictResolutionTest.java b/sdk/cosmos/microsoft-azure-cosmos/src/test/java/com/azure/data/cosmos/rx/MultiMasterConflictResolutionTest.java index 0f8996e31132..863197e2f83d 100644 --- a/sdk/cosmos/microsoft-azure-cosmos/src/test/java/com/azure/data/cosmos/rx/MultiMasterConflictResolutionTest.java +++ b/sdk/cosmos/microsoft-azure-cosmos/src/test/java/com/azure/data/cosmos/rx/MultiMasterConflictResolutionTest.java @@ -104,18 +104,19 @@ public void conflictResolutionPolicyCRUD() { } // Tests the following scenarios - // 1. CUSTOM with valid sprocLink - // 2. CUSTOM with null sprocLink, should default to empty string - // 3. CUSTOM with empty sprocLink, should default to empty string - testConflictResolutionPolicyRequiringPath(ConflictResolutionMode.CUSTOM, - new String[] { "randomSprocName", null, "" }, new String[] { "randomSprocName", "", "" }); + // 1. Custom with valid sprocLink + // 2. Custom with null sprocLink, should default to empty string + // 3. Custom with empty sprocLink, should default to empty string + testConflictResolutionPolicyRequiringPath(ConflictResolutionMode.CUSTOM, new String[] { "dbs/mydb/colls" + + "/mycoll/sprocs/randomSprocName", null, "" }, new String[] { "dbs/mydb/colls/mycoll/sprocs" + + "/randomSprocName", "", "" }); } private void testConflictResolutionPolicyRequiringPath(ConflictResolutionMode conflictResolutionMode, String[] paths, String[] expectedPaths) { - for (int i = 0; i < paths.length; i++) { + for (int i = 0; i < paths.length; i++) { CosmosContainerProperties collectionSettings = new CosmosContainerProperties(UUID.randomUUID().toString(), partitionKeyDef); - + if (conflictResolutionMode == ConflictResolutionMode.LAST_WRITER_WINS) { collectionSettings.conflictResolutionPolicy(ConflictResolutionPolicy.createLastWriterWinsPolicy(paths[i])); } else { @@ -123,7 +124,7 @@ private void testConflictResolutionPolicyRequiringPath(ConflictResolutionMode co } collectionSettings = database.createContainer(collectionSettings, new CosmosContainerRequestOptions()).block().properties(); assertThat(collectionSettings.conflictResolutionPolicy().mode()).isEqualTo(conflictResolutionMode); - + if (conflictResolutionMode == ConflictResolutionMode.LAST_WRITER_WINS) { assertThat(collectionSettings.conflictResolutionPolicy().conflictResolutionPath()).isEqualTo(expectedPaths[i]); } else { @@ -131,7 +132,7 @@ private void testConflictResolutionPolicyRequiringPath(ConflictResolutionMode co } } } - + @Test(groups = "multi-master", timeOut = TIMEOUT) public void invalidConflictResolutionPolicy_LastWriterWinsWithStoredProc() throws Exception { CosmosContainerProperties collection = new CosmosContainerProperties(UUID.randomUUID().toString(), partitionKeyDef);