From 189a2d0b93fda7eb0978021229ca846cd73b535b Mon Sep 17 00:00:00 2001 From: Abhijeet Mohanty Date: Mon, 6 Jul 2026 11:17:13 -0400 Subject: [PATCH 1/7] Fix partitionLevelCircuitBreakerCfg missing from CosmosDiagnostics clientCfgs The partitionLevelCircuitBreakerCfg field disappeared from the clientCfgs section of CosmosDiagnostics when a customer explicitly enabled Per-Partition Circuit Breaker (PPCB) client-side. Root cause: the diagnostics write was coupled to the Per-Partition Automatic Failover (PPAF) initialization path, so the field was only populated when the service mandated PPAF, not when PPCB was configured client-side. Fix: move the diagnostics write into initializePerPartitionCircuitBreaker(), which is invoked unconditionally at client init, so the field appears whenever the circuit breaker is configured client-side. Adds a CI-runnable regression test asserting all clientCfgs keys are present, including partitionLevelCircuitBreakerCfg. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> --- .../RxDocumentClientImplTest.java | 122 ++++++++++++++++++ .../implementation/RxDocumentClientImpl.java | 7 +- 2 files changed, 128 insertions(+), 1 deletion(-) diff --git a/sdk/cosmos/azure-cosmos-tests/src/test/java/com/azure/cosmos/implementation/RxDocumentClientImplTest.java b/sdk/cosmos/azure-cosmos-tests/src/test/java/com/azure/cosmos/implementation/RxDocumentClientImplTest.java index 1519713a68f9..d2e9f2aebb2d 100644 --- a/sdk/cosmos/azure-cosmos-tests/src/test/java/com/azure/cosmos/implementation/RxDocumentClientImplTest.java +++ b/sdk/cosmos/azure-cosmos-tests/src/test/java/com/azure/cosmos/implementation/RxDocumentClientImplTest.java @@ -5,6 +5,7 @@ import com.azure.core.credential.AzureKeyCredential; import com.azure.core.http.ProxyOptions; import com.azure.cosmos.BridgeInternal; +import com.azure.cosmos.ConnectionMode; import com.azure.cosmos.ConsistencyLevel; import com.azure.cosmos.CosmosContainerProactiveInitConfig; import com.azure.cosmos.CosmosDiagnostics; @@ -35,6 +36,11 @@ import com.azure.cosmos.models.ModelBridgeInternal; import com.azure.cosmos.models.PartitionKey; import com.azure.cosmos.models.PartitionKeyDefinition; +import com.fasterxml.jackson.core.JsonFactory; +import com.fasterxml.jackson.core.JsonGenerator; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.SerializerProvider; +import com.fasterxml.jackson.databind.node.ObjectNode; import io.netty.buffer.ByteBufInputStream; import io.netty.buffer.Unpooled; import io.netty.handler.codec.http.HttpResponseStatus; @@ -47,6 +53,8 @@ import reactor.test.StepVerifier; import java.net.URI; +import java.io.StringWriter; +import java.lang.reflect.Method; import java.nio.charset.StandardCharsets; import java.time.Duration; import java.util.ArrayList; @@ -324,6 +332,120 @@ public void readMany() { } } + // Regression test for the "partitionLevelCircuitBreakerCfg" diagnostics field silently disappearing from the + // CosmosDiagnostics "clientCfgs" section. Prior to the fix, the field was only written on the PPAF + // (service-mandated) path, so a client that explicitly enabled Per-Partition Circuit Breaker never surfaced it. + // This test constructs a real RxDocumentClientImpl (exercising the actual constructor wiring), drives the + // private initializePerPartitionCircuitBreaker() init path, serializes the resulting DiagnosticsClientConfig, + // and asserts that every expected "clientCfgs" key is present (guarding against future serialization + // truncation as well as the specific regression). It also asserts the effective PPCB config string. + @Test(groups = {"unit"}) + public void diagnosticsClientConfigContainsAllClientCfgKeysIncludingPartitionLevelCircuitBreaker() throws Exception { + System.setProperty( + "COSMOS.PARTITION_LEVEL_CIRCUIT_BREAKER_CONFIG", + "{\"isPartitionLevelCircuitBreakerEnabled\": true, " + + "\"circuitBreakerType\": \"CONSECUTIVE_EXCEPTION_COUNT_BASED\"," + + "\"consecutiveExceptionCountToleratedForReads\": 10," + + "\"consecutiveExceptionCountToleratedForWrites\": 5,}"); + + Mockito.when(this.connectionPolicyMock.getIdleHttpConnectionTimeout()).thenReturn(Duration.ZERO); + Mockito.when(this.connectionPolicyMock.getMaxConnectionPoolSize()).thenReturn(1); + Mockito.when(this.connectionPolicyMock.getProxy()).thenReturn(null); + Mockito.when(this.connectionPolicyMock.getHttpNetworkRequestTimeout()).thenReturn(Duration.ZERO); + Mockito.when(this.connectionPolicyMock.getHttp2ConnectionConfig()).thenReturn(new Http2ConnectionConfig()); + // The serializer eagerly calls getConnectionMode().toString() for the very first "connectionMode" key; if this + // returns null (Mockito default), serialization would NPE and silently drop every subsequent key. + Mockito.when(this.connectionPolicyMock.getConnectionMode()).thenReturn(ConnectionMode.DIRECT); + + MockedStatic httpClientMock = Mockito.mockStatic(HttpClient.class); + httpClientMock + .when(() -> HttpClient.createFixed(Mockito.any(HttpClientConfig.class))) + .thenReturn(dummyHttpClient()); + + RxDocumentClientImpl rxDocumentClient = null; + + try { + rxDocumentClient = new RxDocumentClientImpl( + this.serviceEndpointMock, + this.masterKeyOrResourceTokenMock, + this.permissionFeedMock, + this.connectionPolicyMock, + this.consistencyLevelMock, + null, + this.configsMock, + this.cosmosAuthorizationTokenResolverMock, + this.azureKeyCredentialMock, + false, + false, + false, + this.metadataCachesSnapshotMock, + this.apiTypeMock, + this.cosmosClientTelemetryConfigMock, + this.clientCorrelationIdMock, + this.endToEndOperationLatencyPolicyConfig, + this.sessionRetryOptionsMock, + this.containerProactiveInitConfigMock, + this.defaultItemSerializer, + false + ); + + // Drive the exact wiring that regressed: explicit (client-side) Per-Partition Circuit Breaker + // initialization. The constructor does not invoke init() (which would require network), so invoke the + // private no-arg initializer reflectively. + Method initPpcb = RxDocumentClientImpl.class.getDeclaredMethod("initializePerPartitionCircuitBreaker"); + initPpcb.setAccessible(true); + initPpcb.invoke(rxDocumentClient); + + ObjectMapper objectMapper = new ObjectMapper(); + StringWriter jsonWriter = new StringWriter(); + JsonGenerator jsonGenerator = new JsonFactory().createGenerator(jsonWriter); + SerializerProvider serializerProvider = objectMapper.getSerializerProvider(); + DiagnosticsClientContext.DiagnosticsClientConfigSerializer.INSTANCE + .serialize(rxDocumentClient.getConfig(), jsonGenerator, serializerProvider); + jsonGenerator.flush(); + ObjectNode clientCfgs = (ObjectNode) objectMapper.readTree(jsonWriter.toString()); + + String serializedJson = clientCfgs.toString(); + + // Every key the serializer unconditionally writes, plus the (previously regressed) + // partitionLevelCircuitBreakerCfg which is present whenever PPCB is enabled. + String[] expectedKeys = new String[] { + "id", + "machineId", + "connectionMode", + "numberOfClients", + "isPpafEnabled", + "isFalseProgSessionTokenMergeEnabled", + "excrgns", + "clientEndpoints", + "connCfg", + "consistencyCfg", + "proactiveInitCfg", + "e2ePolicyCfg", + "sessionRetryCfg", + "partitionLevelCircuitBreakerCfg" + }; + + for (String expectedKey : expectedKeys) { + assertThat(clientCfgs.has(expectedKey)) + .withFailMessage("Expected clientCfgs key '%s' to be present. Serialized clientCfgs: %s", + expectedKey, serializedJson) + .isTrue(); + } + + assertThat(clientCfgs.get("partitionLevelCircuitBreakerCfg").asText()) + .withFailMessage("Unexpected partitionLevelCircuitBreakerCfg value. Serialized clientCfgs: %s", + serializedJson) + .isEqualTo("(cb: true, type: CONSECUTIVE_EXCEPTION_COUNT_BASED, rexcntt: 10, wexcntt: 5)"); + } finally { + System.clearProperty("COSMOS.PARTITION_LEVEL_CIRCUIT_BREAKER_CONFIG"); + if (rxDocumentClient != null) { + rxDocumentClient.close(); + } + httpClientMock.close(); + } + } + private static HttpClient dummyHttpClient() { return new HttpClient() { @Override diff --git a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/RxDocumentClientImpl.java b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/RxDocumentClientImpl.java index c3f01ce0afab..e859886fe7fe 100644 --- a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/RxDocumentClientImpl.java +++ b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/RxDocumentClientImpl.java @@ -8968,7 +8968,6 @@ private synchronized void initializePerPartitionFailover(DatabaseAccount databas checkNotNull(this.globalPartitionEndpointManagerForPerPartitionAutomaticFailover, "Argument 'globalPartitionEndpointManagerForPerPartitionAutomaticFailover' cannot be null."); checkNotNull(this.globalPartitionEndpointManagerForPerPartitionCircuitBreaker, "Argument 'globalPartitionEndpointManagerForPerPartitionCircuitBreaker' cannot be null."); - this.diagnosticsClientConfig.withPartitionLevelCircuitBreakerConfig(this.globalPartitionEndpointManagerForPerPartitionCircuitBreaker.getCircuitBreakerConfig()); this.diagnosticsClientConfig.withIsPerPartitionAutomaticFailoverEnabled(this.globalPartitionEndpointManagerForPerPartitionAutomaticFailover.isPerPartitionAutomaticFailoverEnabled()); } @@ -8997,6 +8996,12 @@ private void initializePerPartitionCircuitBreaker() { this.globalPartitionEndpointManagerForPerPartitionCircuitBreaker.resetCircuitBreakerConfig(partitionLevelCircuitBreakerConfig); this.globalPartitionEndpointManagerForPerPartitionCircuitBreaker.init(); + + // Populate the circuit breaker config in the diagnostics client config here (rather than in + // initializePerPartitionFailover) so the "partitionLevelCircuitBreakerCfg" field appears in + // CosmosDiagnostics whenever the circuit breaker is configured client-side, not only when + // Per-Partition Automatic Failover is mandated by the service. + this.diagnosticsClientConfig.withPartitionLevelCircuitBreakerConfig(this.globalPartitionEndpointManagerForPerPartitionCircuitBreaker.getCircuitBreakerConfig()); } private void enableAvailabilityStrategyForReads() { From f5b2d11f82412a96a9716d395c1539a7c2f1eb12 Mon Sep 17 00:00:00 2001 From: Abhijeet Mohanty Date: Mon, 6 Jul 2026 17:33:34 -0400 Subject: [PATCH 2/7] Address Copilot review: use strictly valid JSON in PPCB test system property Remove trailing comma before closing brace in the COSMOS.PARTITION_LEVEL_CIRCUIT_BREAKER_CONFIG JSON so the value is strictly valid and clearer as a customer reference. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> --- .../azure/cosmos/implementation/RxDocumentClientImplTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk/cosmos/azure-cosmos-tests/src/test/java/com/azure/cosmos/implementation/RxDocumentClientImplTest.java b/sdk/cosmos/azure-cosmos-tests/src/test/java/com/azure/cosmos/implementation/RxDocumentClientImplTest.java index d50a5a0e4057..42538e74016d 100644 --- a/sdk/cosmos/azure-cosmos-tests/src/test/java/com/azure/cosmos/implementation/RxDocumentClientImplTest.java +++ b/sdk/cosmos/azure-cosmos-tests/src/test/java/com/azure/cosmos/implementation/RxDocumentClientImplTest.java @@ -526,7 +526,7 @@ public void diagnosticsClientConfigContainsAllClientCfgKeysIncludingPartitionLev "{\"isPartitionLevelCircuitBreakerEnabled\": true, " + "\"circuitBreakerType\": \"CONSECUTIVE_EXCEPTION_COUNT_BASED\"," + "\"consecutiveExceptionCountToleratedForReads\": 10," - + "\"consecutiveExceptionCountToleratedForWrites\": 5,}"); + + "\"consecutiveExceptionCountToleratedForWrites\": 5}"); Mockito.when(this.connectionPolicyMock.getIdleHttpConnectionTimeout()).thenReturn(Duration.ZERO); Mockito.when(this.connectionPolicyMock.getMaxConnectionPoolSize()).thenReturn(1); From 5403797ab76794110e8ec48069babf67b4854c47 Mon Sep 17 00:00:00 2001 From: Abhijeet Mohanty Date: Mon, 6 Jul 2026 17:54:57 -0400 Subject: [PATCH 3/7] Add changelog entry for PPCB diagnostics fix Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> --- sdk/cosmos/azure-cosmos/CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/sdk/cosmos/azure-cosmos/CHANGELOG.md b/sdk/cosmos/azure-cosmos/CHANGELOG.md index 7f3b456f7c32..f566f3b8404e 100644 --- a/sdk/cosmos/azure-cosmos/CHANGELOG.md +++ b/sdk/cosmos/azure-cosmos/CHANGELOG.md @@ -8,6 +8,7 @@ #### Bugs Fixed * Unified request-level consistency override behavior across transports: invalid attempts to upgrade the request consistency level above the account default are now silently ignored instead of returning `BadRequest` in some gateway paths. - See PR [49606](https://github.com/Azure/azure-sdk-for-java/pull/49606). +* Fixed `partitionLevelCircuitBreakerCfg` missing from the `clientCfgs` section of `CosmosDiagnostics` when Per-Partition Circuit Breaker is explicitly enabled. - See PR [49734](https://github.com/Azure/azure-sdk-for-java/pull/49734). #### Other Changes * Reduced memory footprint of deserialized `PartitionKeyRange` instances by stripping unused fields in the `PartitionKeyRange(ObjectNode)` constructor - See PR [49513](https://github.com/Azure/azure-sdk-for-java/pull/49513). From 1769a46020e661c2d71ddc60b2310cce9034706d Mon Sep 17 00:00:00 2001 From: Abhijeet Mohanty Date: Tue, 7 Jul 2026 10:08:26 -0400 Subject: [PATCH 4/7] Add PPCB clientCfgs diagnostics validation to PerPartitionCircuitBreakerE2ETests Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> --- .../PerPartitionCircuitBreakerE2ETests.java | 71 +++++++++++++++++++ 1 file changed, 71 insertions(+) diff --git a/sdk/cosmos/azure-cosmos-tests/src/test/java/com/azure/cosmos/PerPartitionCircuitBreakerE2ETests.java b/sdk/cosmos/azure-cosmos-tests/src/test/java/com/azure/cosmos/PerPartitionCircuitBreakerE2ETests.java index 37e8bbee11ed..34cea73dc429 100644 --- a/sdk/cosmos/azure-cosmos-tests/src/test/java/com/azure/cosmos/PerPartitionCircuitBreakerE2ETests.java +++ b/sdk/cosmos/azure-cosmos-tests/src/test/java/com/azure/cosmos/PerPartitionCircuitBreakerE2ETests.java @@ -4613,6 +4613,77 @@ public void validateHandlingOnNullPartitionKeyRangeOnSmallE2ETimeout_allOps(Oper } } + /** + * Regression validation for the Per-Partition Circuit Breaker (PPCB) diagnostics fix (see PR 49734). + * + * When PPCB is explicitly enabled via the {@code COSMOS.PARTITION_LEVEL_CIRCUIT_BREAKER_CONFIG} + * system property, the {@code clientCfgs} section of the emitted {@link CosmosDiagnostics} must + * include the {@code partitionLevelCircuitBreakerCfg} field. A prior regression silently dropped + * this field. This test asserts that all the expected {@code clientCfgs} keys - including + * {@code partitionLevelCircuitBreakerCfg} - are present in the diagnostics of a real operation. + */ + @Test(groups = { "circuit-breaker-misc-direct" }, timeOut = TIMEOUT) + public void partitionLevelCircuitBreakerConfigIsPresentInClientCfgsDiagnostics() { + + System.setProperty( + "COSMOS.PARTITION_LEVEL_CIRCUIT_BREAKER_CONFIG", + "{\"isPartitionLevelCircuitBreakerEnabled\": true, " + + "\"circuitBreakerType\": \"CONSECUTIVE_EXCEPTION_COUNT_BASED\"," + + "\"consecutiveExceptionCountToleratedForReads\": 10," + + "\"consecutiveExceptionCountToleratedForWrites\": 5," + + "}"); + + try (CosmosAsyncClient client = getClientBuilder().buildAsyncClient()) { + + CosmosAsyncContainer container = client + .getDatabase(this.sharedAsyncDatabaseId) + .getContainer(this.sharedMultiPartitionAsyncContainerIdWhereIdIsPartitionKey); + + TestObject item = TestObject.create(); + + CosmosItemResponse createResponse = container + .createItem(item, new PartitionKey(item.getId()), new CosmosItemRequestOptions()) + .block(); + + assertThat(createResponse).isNotNull(); + + String diagnosticsString = createResponse.getDiagnostics().toString(); + + assertThat(diagnosticsString) + .as("clientCfgs section should be present in the CosmosDiagnostics") + .contains("\"clientCfgs\""); + + // All the clientCfgs keys unconditionally emitted by DiagnosticsClientConfigSerializer. + List expectedClientCfgsKeys = Arrays.asList( + "id", + "machineId", + "connectionMode", + "numberOfClients", + "isPpafEnabled", + "isFalseProgSessionTokenMergeEnabled", + "excrgns", + "clientEndpoints", + "connCfg", + "consistencyCfg", + "proactiveInitCfg", + "e2ePolicyCfg", + "sessionRetryCfg"); + + for (String expectedKey : expectedClientCfgsKeys) { + assertThat(diagnosticsString) + .as("clientCfgs key '%s' should be present in the CosmosDiagnostics", expectedKey) + .contains("\"" + expectedKey + "\""); + } + + // The regression fix: PPCB config must be present in clientCfgs when explicitly enabled. + assertThat(diagnosticsString) + .as("partitionLevelCircuitBreakerCfg should be present in clientCfgs when PPCB is enabled") + .contains("\"partitionLevelCircuitBreakerCfg\""); + } finally { + System.clearProperty("COSMOS.PARTITION_LEVEL_CIRCUIT_BREAKER_CONFIG"); + } + } + private static Function> resolveDataPlaneOperation(FaultInjectionOperationType faultInjectionOperationType) { switch (faultInjectionOperationType) { From afa7a519976fbdbb10f1f56af8c1cea482a81f30 Mon Sep 17 00:00:00 2001 From: Abhijeet Mohanty Date: Tue, 7 Jul 2026 10:28:23 -0400 Subject: [PATCH 5/7] Run PPCB clientCfgs diagnostics E2E test across all TestNG groups Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> --- .../com/azure/cosmos/PerPartitionCircuitBreakerE2ETests.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk/cosmos/azure-cosmos-tests/src/test/java/com/azure/cosmos/PerPartitionCircuitBreakerE2ETests.java b/sdk/cosmos/azure-cosmos-tests/src/test/java/com/azure/cosmos/PerPartitionCircuitBreakerE2ETests.java index 34cea73dc429..c3f9ffbd5316 100644 --- a/sdk/cosmos/azure-cosmos-tests/src/test/java/com/azure/cosmos/PerPartitionCircuitBreakerE2ETests.java +++ b/sdk/cosmos/azure-cosmos-tests/src/test/java/com/azure/cosmos/PerPartitionCircuitBreakerE2ETests.java @@ -4622,7 +4622,7 @@ public void validateHandlingOnNullPartitionKeyRangeOnSmallE2ETimeout_allOps(Oper * this field. This test asserts that all the expected {@code clientCfgs} keys - including * {@code partitionLevelCircuitBreakerCfg} - are present in the diagnostics of a real operation. */ - @Test(groups = { "circuit-breaker-misc-direct" }, timeOut = TIMEOUT) + @Test(groups = { "circuit-breaker-misc-gateway", "circuit-breaker-misc-direct", "circuit-breaker-read-all-read-many", "multi-region", "fi-thinclient-multi-master" }, timeOut = TIMEOUT) public void partitionLevelCircuitBreakerConfigIsPresentInClientCfgsDiagnostics() { System.setProperty( From 7157e1c90f3a59a792edc08fb58dd2cf520df503 Mon Sep 17 00:00:00 2001 From: Abhijeet Mohanty Date: Tue, 7 Jul 2026 10:39:51 -0400 Subject: [PATCH 6/7] Simplify PPCB E2E diagnostics test to verify unconditional clientCfgs keys The partitionLevelCircuitBreakerCfg field now appears in clientCfgs for every client regardless of PPCB configuration, so the E2E test no longer sets the COSMOS.PARTITION_LEVEL_CIRCUIT_BREAKER_CONFIG system property. It just builds a plain client and asserts all expected clientCfgs keys (including partitionLevelCircuitBreakerCfg) are present in CosmosDiagnostics. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> --- .../PerPartitionCircuitBreakerE2ETests.java | 32 ++++++------------- 1 file changed, 10 insertions(+), 22 deletions(-) diff --git a/sdk/cosmos/azure-cosmos-tests/src/test/java/com/azure/cosmos/PerPartitionCircuitBreakerE2ETests.java b/sdk/cosmos/azure-cosmos-tests/src/test/java/com/azure/cosmos/PerPartitionCircuitBreakerE2ETests.java index c3f9ffbd5316..1db80bd039d2 100644 --- a/sdk/cosmos/azure-cosmos-tests/src/test/java/com/azure/cosmos/PerPartitionCircuitBreakerE2ETests.java +++ b/sdk/cosmos/azure-cosmos-tests/src/test/java/com/azure/cosmos/PerPartitionCircuitBreakerE2ETests.java @@ -4616,23 +4616,16 @@ public void validateHandlingOnNullPartitionKeyRangeOnSmallE2ETimeout_allOps(Oper /** * Regression validation for the Per-Partition Circuit Breaker (PPCB) diagnostics fix (see PR 49734). * - * When PPCB is explicitly enabled via the {@code COSMOS.PARTITION_LEVEL_CIRCUIT_BREAKER_CONFIG} - * system property, the {@code clientCfgs} section of the emitted {@link CosmosDiagnostics} must - * include the {@code partitionLevelCircuitBreakerCfg} field. A prior regression silently dropped - * this field. This test asserts that all the expected {@code clientCfgs} keys - including - * {@code partitionLevelCircuitBreakerCfg} - are present in the diagnostics of a real operation. + * The {@code clientCfgs} section of the emitted {@link CosmosDiagnostics} must always include the + * {@code partitionLevelCircuitBreakerCfg} field for every client, regardless of whether PPCB is + * explicitly enabled. A prior regression silently dropped this field unless PPAF mandated it. This + * test asserts that all the expected {@code clientCfgs} keys - including + * {@code partitionLevelCircuitBreakerCfg} - are present in the diagnostics of a real operation + * without setting any PPCB configuration. */ @Test(groups = { "circuit-breaker-misc-gateway", "circuit-breaker-misc-direct", "circuit-breaker-read-all-read-many", "multi-region", "fi-thinclient-multi-master" }, timeOut = TIMEOUT) public void partitionLevelCircuitBreakerConfigIsPresentInClientCfgsDiagnostics() { - System.setProperty( - "COSMOS.PARTITION_LEVEL_CIRCUIT_BREAKER_CONFIG", - "{\"isPartitionLevelCircuitBreakerEnabled\": true, " - + "\"circuitBreakerType\": \"CONSECUTIVE_EXCEPTION_COUNT_BASED\"," - + "\"consecutiveExceptionCountToleratedForReads\": 10," - + "\"consecutiveExceptionCountToleratedForWrites\": 5," - + "}"); - try (CosmosAsyncClient client = getClientBuilder().buildAsyncClient()) { CosmosAsyncContainer container = client @@ -4653,7 +4646,8 @@ public void partitionLevelCircuitBreakerConfigIsPresentInClientCfgsDiagnostics() .as("clientCfgs section should be present in the CosmosDiagnostics") .contains("\"clientCfgs\""); - // All the clientCfgs keys unconditionally emitted by DiagnosticsClientConfigSerializer. + // All the clientCfgs keys unconditionally emitted by DiagnosticsClientConfigSerializer, + // including partitionLevelCircuitBreakerCfg (the field the regression previously dropped). List expectedClientCfgsKeys = Arrays.asList( "id", "machineId", @@ -4667,20 +4661,14 @@ public void partitionLevelCircuitBreakerConfigIsPresentInClientCfgsDiagnostics() "consistencyCfg", "proactiveInitCfg", "e2ePolicyCfg", - "sessionRetryCfg"); + "sessionRetryCfg", + "partitionLevelCircuitBreakerCfg"); for (String expectedKey : expectedClientCfgsKeys) { assertThat(diagnosticsString) .as("clientCfgs key '%s' should be present in the CosmosDiagnostics", expectedKey) .contains("\"" + expectedKey + "\""); } - - // The regression fix: PPCB config must be present in clientCfgs when explicitly enabled. - assertThat(diagnosticsString) - .as("partitionLevelCircuitBreakerCfg should be present in clientCfgs when PPCB is enabled") - .contains("\"partitionLevelCircuitBreakerCfg\""); - } finally { - System.clearProperty("COSMOS.PARTITION_LEVEL_CIRCUIT_BREAKER_CONFIG"); } } From 3dc50582f27ed46d86a6ba213c6ac52075765915 Mon Sep 17 00:00:00 2001 From: Abhijeet Mohanty Date: Tue, 7 Jul 2026 11:03:10 -0400 Subject: [PATCH 7/7] Simplify PPCB unit test to assert clientCfgs key presence only Remove PPCB System.setProperty/clearProperty and the value-specific assertion; assert only that all clientCfgs keys are present, matching the E2E test simplification. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> --- .../RxDocumentClientImplTest.java | 29 ++++++------------- 1 file changed, 9 insertions(+), 20 deletions(-) diff --git a/sdk/cosmos/azure-cosmos-tests/src/test/java/com/azure/cosmos/implementation/RxDocumentClientImplTest.java b/sdk/cosmos/azure-cosmos-tests/src/test/java/com/azure/cosmos/implementation/RxDocumentClientImplTest.java index 42538e74016d..87d856bddad5 100644 --- a/sdk/cosmos/azure-cosmos-tests/src/test/java/com/azure/cosmos/implementation/RxDocumentClientImplTest.java +++ b/sdk/cosmos/azure-cosmos-tests/src/test/java/com/azure/cosmos/implementation/RxDocumentClientImplTest.java @@ -514,20 +514,15 @@ public void lookupCollectionRoutingMapWithRetryStopsAfterBoundedAttempts() { // Regression test for the "partitionLevelCircuitBreakerCfg" diagnostics field silently disappearing from the // CosmosDiagnostics "clientCfgs" section. Prior to the fix, the field was only written on the PPAF - // (service-mandated) path, so a client that explicitly enabled Per-Partition Circuit Breaker never surfaced it. - // This test constructs a real RxDocumentClientImpl (exercising the actual constructor wiring), drives the - // private initializePerPartitionCircuitBreaker() init path, serializes the resulting DiagnosticsClientConfig, - // and asserts that every expected "clientCfgs" key is present (guarding against future serialization - // truncation as well as the specific regression). It also asserts the effective PPCB config string. + // (service-mandated) path, so a client that did not have PPAF-mandated PPCB never surfaced it. The field must + // now be present for every client regardless of any PPCB configuration. This test constructs a real + // RxDocumentClientImpl (exercising the actual constructor wiring), drives the private + // initializePerPartitionCircuitBreaker() init path without setting any PPCB configuration, serializes the + // resulting DiagnosticsClientConfig, and asserts that every expected "clientCfgs" key - including + // partitionLevelCircuitBreakerCfg - is present (guarding against future serialization truncation as well as + // the specific regression). @Test(groups = {"unit"}) public void diagnosticsClientConfigContainsAllClientCfgKeysIncludingPartitionLevelCircuitBreaker() throws Exception { - System.setProperty( - "COSMOS.PARTITION_LEVEL_CIRCUIT_BREAKER_CONFIG", - "{\"isPartitionLevelCircuitBreakerEnabled\": true, " - + "\"circuitBreakerType\": \"CONSECUTIVE_EXCEPTION_COUNT_BASED\"," - + "\"consecutiveExceptionCountToleratedForReads\": 10," - + "\"consecutiveExceptionCountToleratedForWrites\": 5}"); - Mockito.when(this.connectionPolicyMock.getIdleHttpConnectionTimeout()).thenReturn(Duration.ZERO); Mockito.when(this.connectionPolicyMock.getMaxConnectionPoolSize()).thenReturn(1); Mockito.when(this.connectionPolicyMock.getProxy()).thenReturn(null); @@ -587,8 +582,8 @@ public void diagnosticsClientConfigContainsAllClientCfgKeysIncludingPartitionLev String serializedJson = clientCfgs.toString(); - // Every key the serializer unconditionally writes, plus the (previously regressed) - // partitionLevelCircuitBreakerCfg which is present whenever PPCB is enabled. + // Every key the serializer unconditionally writes, including the (previously regressed) + // partitionLevelCircuitBreakerCfg which must be present for every client regardless of PPCB config. String[] expectedKeys = new String[] { "id", "machineId", @@ -612,13 +607,7 @@ public void diagnosticsClientConfigContainsAllClientCfgKeysIncludingPartitionLev expectedKey, serializedJson) .isTrue(); } - - assertThat(clientCfgs.get("partitionLevelCircuitBreakerCfg").asText()) - .withFailMessage("Unexpected partitionLevelCircuitBreakerCfg value. Serialized clientCfgs: %s", - serializedJson) - .isEqualTo("(cb: true, type: CONSECUTIVE_EXCEPTION_COUNT_BASED, rexcntt: 10, wexcntt: 5)"); } finally { - System.clearProperty("COSMOS.PARTITION_LEVEL_CIRCUIT_BREAKER_CONFIG"); if (rxDocumentClient != null) { rxDocumentClient.close(); }