Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
91 commits
Select commit Hold shift + click to select a range
4a83556
Route Execute Stored Procedure requests to Thin Proxy endpoint.
jeet1995 Jan 20, 2026
325ff0a
Route Execute Stored Procedure and QueryPlan requests to Thin Proxy e…
jeet1995 Jan 21, 2026
eb9a83e
Ensure QueryPlan gets routed to Gateway Service Endpoint (in non-TC +…
jeet1995 Jan 23, 2026
1492b36
Ensure QueryPlan gets routed to Gateway Service Endpoint (in non-TC +…
jeet1995 Jan 23, 2026
2c8a5f3
Ensure QueryPlan gets routed to Gateway Service Endpoint (in non-TC +…
jeet1995 Jan 23, 2026
1e14a7b
Obtain List<Range<String>> from List<PartitionKeyInternal>.
jeet1995 Jan 28, 2026
91116c9
Obtain List<Range<String>> from List<PartitionKeyInternal>.
jeet1995 Jan 28, 2026
688a5ac
Adding query + thin-client tests.
jeet1995 Jan 28, 2026
8ae321f
Fixing tests.
jeet1995 Jan 29, 2026
e76c84c
Fixing tests.
jeet1995 Jan 29, 2026
7f3bad8
Fixing tests.
jeet1995 Jan 30, 2026
7600598
Addressing review comments.
jeet1995 Jan 30, 2026
281bc88
Addressing review comments.
jeet1995 Mar 7, 2026
1d171f5
Refactor thin-client E2E tests based on operation type.
jeet1995 Mar 9, 2026
9f1b4ee
Refactor thin-client E2E tests based on operation type.
jeet1995 Mar 9, 2026
cfe720b
Refactor thin-client E2E tests based on operation type.
jeet1995 Mar 9, 2026
8f1615b
Refactor thin-client E2E tests based on operation type.
jeet1995 Mar 9, 2026
b037a1d
Refactor thin-client E2E tests based on operation type.
jeet1995 Mar 10, 2026
8e28d82
Refactor thin-client E2E tests based on operation type.
jeet1995 Mar 10, 2026
2be1433
Refactor thin-client E2E tests based on operation type.
jeet1995 Mar 10, 2026
4b44cd5
Refactor thin-client E2E tests based on operation type.
jeet1995 Mar 10, 2026
afa9811
Merge branch 'Azure:main' into AzCosmos_GatewayV2_QueryPlanSupport
jeet1995 Mar 10, 2026
b07b104
Refactor thin-client E2E tests based on operation type.
jeet1995 Mar 10, 2026
22db578
Merge remote-tracking branch 'azure/main' into AzCosmos_GatewayV2_Que…
jeet1995 Mar 30, 2026
a991123
Add SupportedQueryFeatures and QueryVersion RNTBD request headers for…
jeet1995 Mar 30, 2026
7ab7ffa
Add change feed tests for FeedRange.forFullRange and forLogicalPartition
jeet1995 Mar 30, 2026
f9b2874
Add thin client E2E test matrix documentation for QueryPlan review
jeet1995 Mar 30, 2026
06b1a8c
Add SupportedQueryFeatures and QueryVersion RNTBD request headers for…
jeet1995 Mar 30, 2026
d006c72
Fix testGetCurrentDateTime flaky assertion, add AAD auth support, RNT…
jeet1995 Mar 31, 2026
01b54ec
Refactor thin client query tests for reliability
jeet1995 Mar 31, 2026
37c0d9d
Fix container leaks and Direct TCP AAD auth in tests
jeet1995 Mar 31, 2026
d65e174
Use bulkDelete in AfterClass for seeded docs cleanup
jeet1995 Mar 31, 2026
c7c31c4
Address PR review feedback
jeet1995 Mar 31, 2026
9372597
Align vector/FTS/hybrid tests with existing patterns
jeet1995 Mar 31, 2026
8fb7e24
Address review agent comments + fix broken link
jeet1995 Mar 31, 2026
01feecf
Address review agent comments (round 2)
jeet1995 Mar 31, 2026
a3cded4
Refactor queryRanges deserialization — detect format from response, n…
jeet1995 Apr 1, 2026
2422cbc
Use agnostic QueryRangesFormat hint instead of PartitionKeyDefinition…
jeet1995 Apr 1, 2026
10549fc
Merge remote-tracking branch 'azure/main' into AzCosmos_GatewayV2_Que…
jeet1995 Apr 1, 2026
2d7db15
Merge remote-tracking branch 'upstream/main' into AzCosmos_GatewayV2_…
jeet1995 Jun 2, 2026
86683a8
Fix fetchQueryPlanForValidation caller after merge
jeet1995 Jun 2, 2026
e27bf3f
Make PartitionedQueryExecutionInfo(ObjectNode, RequestTimeline) ctor …
jeet1995 Jun 2, 2026
60c1dab
[Cosmos] Default thin-client to enabled and add HTTP/2 connectivity-p…
jeet1995 Jun 10, 2026
91bf62a
Merge upstream/main into jeet1995/thin-client-probe-flow
jeet1995 Jun 10, 2026
d2ec2f8
Address PR #49437 review comments: probe single-flight, body-drain li…
jeet1995 Jun 10, 2026
3f1b1be
Address PR #49437 second-batch review feedback
jeet1995 Jun 10, 2026
66fca70
Clarify CHANGELOG: probe recovery threshold is now configurable
jeet1995 Jun 10, 2026
8a602fb
Address PR #49437 review (rounds 4-8): reactor-chain probe, FQN clean…
jeet1995 Jun 10, 2026
4a31ea0
Fix CI test fallout from default ThinClient enablement
jeet1995 Jun 11, 2026
ccc7c39
Disable thin-client probe in Http2PingKeepaliveTest
jeet1995 Jun 11, 2026
ad9e3df
Disable thin-client probe by default for E2E tests in TestSuiteBase
jeet1995 Jun 11, 2026
e381f3a
Revert "Disable thin-client probe by default for E2E tests in TestSui…
jeet1995 Jun 11, 2026
da6c698
Add per-class thinclient probe disable in CosmosNotFoundTests and Per…
jeet1995 Jun 11, 2026
5473c00
Merge remote-tracking branch 'origin/jeet1995/thin-client-probe-flow'…
jeet1995 Jun 12, 2026
edfff97
Add unit tests for QueryPlan and stored-procedure thin-client routing
jeet1995 Jun 12, 2026
9d74638
Remove endpoint-probe content from QueryPlan PR branch
jeet1995 Jun 12, 2026
df1ed37
Merge upstream/main into AzCosmos_GatewayV2_QueryPlanSupport
jeet1995 Jun 12, 2026
f881c0d
Propagate hybrid query diagnostics
jeet1995 Jun 12, 2026
156aaa3
Advertise CountIf query feature
jeet1995 Jun 12, 2026
610003e
Address query plan review feedback
jeet1995 Jun 13, 2026
ffe50dc
Share thin client test property setup
jeet1995 Jun 13, 2026
1f1c7d3
Clean up query range conversion state
jeet1995 Jun 13, 2026
e95e65d
Thread DocumentCollection into readMany query-plan validation
jeet1995 Jun 14, 2026
7148ca3
Cover ReadManyByPartitionKey QueryPlan bifurcation with unit + E2E tests
jeet1995 Jun 14, 2026
c267df6
Skip RNTBD QueryPlan frames when capturing V2 feed requests
Jun 15, 2026
a4185e5
Fix thin-client QueryPlan error returning statusCode 0 instead of 400
jeet1995 Jun 16, 2026
65b23d9
Harden ThinClientQueryE2ETest assertions (F1-F5)
jeet1995 Jun 16, 2026
5b11c3b
Replace thin-client test matrix with reverse-engineered E2E test spec
jeet1995 Jun 16, 2026
5541846
Apply Aditya Sarpotdar review feedback to thin-client E2E tests
jeet1995 Jun 17, 2026
7eb5822
Merge remote-tracking branch 'upstream/main' into AzCosmos_GatewayV2_…
jeet1995 Jun 24, 2026
f554ef2
Address review feedback: opt-in thin-client QueryPlan routing + kill-…
jeet1995 Jun 24, 2026
273b31c
Address review feedback: broaden gateway error fallback to ClassCastE…
jeet1995 Jun 24, 2026
4aefb59
Make thin-client QueryPlan no-EPK-headers contract explicit in wrapIn…
jeet1995 Jun 24, 2026
a4b844d
Fix missing StandardCharsets import in RxGatewayStoreModelTest
jeet1995 Jun 24, 2026
87ab2c0
Test: add QueryOracle-derived LIKE/scalar-expression thin-client pari…
jeet1995 Jun 25, 2026
d16ab54
Test: verify a cached proxy-generated query plan still executes corre…
jeet1995 Jun 25, 2026
19204b3
Test: cross-partition tests use a dedicated multi-physical-partition …
jeet1995 Jun 25, 2026
48b0a45
Add CHANGELOG entry for QueryPlan request routing to Gateway V2
jeet1995 Jun 25, 2026
5bb942c
Call out Execute Stored Procedure support in CHANGELOG entry
jeet1995 Jun 25, 2026
a70c9f8
Fix flaky region/timing-sensitive fault-injection E2E tests
jeet1995 Jun 26, 2026
f12b34c
Remove test AAD auth toggle; move thin-client test matrix to docs/ an…
jeet1995 Jun 26, 2026
427ae9d
Merge commit 'ccb0163cad4' into AzCosmos_GatewayV2_QueryPlanSupport
jeet1995 Jun 26, 2026
94dc07f
Add cross-partition aggregate / GROUP BY parity tests for thin-client…
jeet1995 Jun 30, 2026
26e4235
Fix thin-client MULTI_HASH prefix EPK over-span; add QueryPlan parity…
jeet1995 Jun 30, 2026
dc02999
Merge upstream/main into AzCosmos_GatewayV2_QueryPlanSupport
jeet1995 Jul 8, 2026
694dc71
Enforce QueryPlan thin-client routing invariant and harden container-…
jeet1995 Jul 8, 2026
bf30911
Add kill-switch flip validation for QueryPlan thin-client routing
jeet1995 Jul 8, 2026
e578d4b
Merge remote-tracking branch 'upstream/main' into AzCosmos_GatewayV2_…
jeet1995 Jul 8, 2026
3637b39
Restore ambient COSMOS.THINCLIENT_ENABLED in ThinClientTestBase teardown
jeet1995 Jul 9, 2026
565c608
Remove redundant COSMOS.THINCLIENT_ENABLED mutation from ThinClientTe…
jeet1995 Jul 9, 2026
cbbdce7
Merge branch 'main' into AzCosmos_GatewayV2_QueryPlanSupport
jeet1995 Jul 9, 2026
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
203 changes: 203 additions & 0 deletions sdk/cosmos/azure-cosmos-tests/docs/THINCLIENT_TEST_MATRIX.md

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions sdk/cosmos/azure-cosmos-tests/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -930,6 +930,8 @@ Licensed under the MIT License.
</suiteXmlFiles>
<systemPropertyVariables>
<COSMOS.CLIENT_LEAK_DETECTION_ENABLED>true</COSMOS.CLIENT_LEAK_DETECTION_ENABLED>
<COSMOS.THINCLIENT_ENABLED>true</COSMOS.THINCLIENT_ENABLED>
<COSMOS.HTTP2_ENABLED>true</COSMOS.HTTP2_ENABLED>
<io.netty.leakDetection.samplingInterval>1</io.netty.leakDetection.samplingInterval>
<io.netty.leakDetection.targetRecords>256</io.netty.leakDetection.targetRecords>
<io.netty.leakDetection.level>paranoid</io.netty.leakDetection.level>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
package com.azure.cosmos.implementation;

import com.azure.cosmos.implementation.query.DocumentQueryExecutionContextFactory;
import com.azure.cosmos.implementation.query.IDocumentQueryClient;
import com.azure.cosmos.models.CosmosQueryRequestOptions;
import com.azure.cosmos.models.PartitionKeyDefinition;
import com.azure.cosmos.models.SqlQuerySpec;
import org.mockito.ArgumentCaptor;
import org.mockito.Mockito;
import org.testng.annotations.Test;
import reactor.core.publisher.Mono;

import java.util.Collections;

import static org.assertj.core.api.Assertions.assertThat;

/**
* Unit tests that pin the bifurcation of the validation-only QueryPlan request issued by
* {@code readManyByPartitionKeys} when a custom query is supplied.
*
* <p>The fork lives in {@code QueryPlanRetriever.getQueryPlanThroughGatewayAsync}:
* <pre>queryPlanRequest.useGatewayMode = !(queryClient.useThinClient(queryPlanRequest)
* &amp;&amp; Configs.isThinClientQueryPlanEnabled());</pre>
*
* <p>Routing is driven by the thin-client opt-in ({@link IDocumentQueryClient#useThinClient}),
* not by collection metadata. These tests assert both halves of that contract:
* <ul>
* <li>thin-client not eligible ⇒ request pinned to Gateway V1 (Compute Gateway);</li>
* <li>thin-client eligible ⇒ request is thin-client eligible (Gateway V2 / proxy) — the
* {@code useGatewayMode=false} flag is the prerequisite the store-model layer reads
* to bifurcate.</li>
* </ul>
*/
public class ReadManyByPartitionKeyQueryPlanRoutingTest {

@Test(groups = { "unit" })
public void validationQueryPlanRoutesToGatewayV1WhenThinClientNotEligible() {
ArgumentCaptor<RxDocumentServiceRequest> requestCaptor =
ArgumentCaptor.forClass(RxDocumentServiceRequest.class);
IDocumentQueryClient queryClient = mockQueryClient(requestCaptor, /* useThinClient */ false);

DocumentQueryExecutionContextFactory
.fetchQueryPlanForValidation(
Mockito.mock(DiagnosticsClientContext.class),
queryClient,
new SqlQuerySpec("SELECT * FROM c"),
"dbs/db/colls/col",
new CosmosQueryRequestOptions(),
collectionWithPartitionKey(),
/* queryPlanCachingEnabled */ false,
Collections.emptyMap())
.block();

assertThat(requestCaptor.getAllValues())
.as("a single validation query-plan request must be issued")
.hasSize(1);
assertThat(requestCaptor.getValue().useGatewayMode)
.as("validation query-plan must pin to Gateway V1 when thin client is not eligible")
.isTrue();
}

@Test(groups = { "unit" })
public void validationQueryPlanIsThinClientEligibleWhenOptedIn() {
ArgumentCaptor<RxDocumentServiceRequest> requestCaptor =
ArgumentCaptor.forClass(RxDocumentServiceRequest.class);
IDocumentQueryClient queryClient = mockQueryClient(requestCaptor, /* useThinClient */ true);

DocumentQueryExecutionContextFactory
.fetchQueryPlanForValidation(
Mockito.mock(DiagnosticsClientContext.class),
queryClient,
new SqlQuerySpec("SELECT * FROM c"),
"dbs/db/colls/col",
new CosmosQueryRequestOptions(),
collectionWithPartitionKey(),
/* queryPlanCachingEnabled */ false,
Collections.emptyMap())
.block();

assertThat(requestCaptor.getAllValues())
.as("a single validation query-plan request must be issued")
.hasSize(1);
assertThat(requestCaptor.getValue().useGatewayMode)
.as("validation query-plan must be thin-client eligible (useGatewayMode=false) "
+ "when the thin-client opt-in is satisfied")
.isFalse();
}

@Test(groups = { "unit" })
public void validationQueryPlanForcedToGatewayV1WhenKillSwitchDisabled() {
// The kill-switch (Configs.isThinClientQueryPlanEnabled(), backed by the
// COSMOS.THINCLIENT_QUERY_PLAN_ENABLED system property / COSMOS_THINCLIENT_QUERY_PLAN_ENABLED
// env var) must dominate the thin-client opt-in: even when the request is thin-client eligible
// (useThinClient=true), disabling the switch pins the validation query-plan back onto Gateway V1
// (useGatewayMode=true). This is the inverse of validationQueryPlanIsThinClientEligibleWhenOptedIn.
String previous = System.getProperty("COSMOS.THINCLIENT_QUERY_PLAN_ENABLED");
System.setProperty("COSMOS.THINCLIENT_QUERY_PLAN_ENABLED", "false");
try {
ArgumentCaptor<RxDocumentServiceRequest> requestCaptor =
ArgumentCaptor.forClass(RxDocumentServiceRequest.class);
IDocumentQueryClient queryClient = mockQueryClient(requestCaptor, /* useThinClient */ true);

DocumentQueryExecutionContextFactory
.fetchQueryPlanForValidation(
Mockito.mock(DiagnosticsClientContext.class),
queryClient,
new SqlQuerySpec("SELECT * FROM c"),
"dbs/db/colls/col",
new CosmosQueryRequestOptions(),
collectionWithPartitionKey(),
/* queryPlanCachingEnabled */ false,
Collections.emptyMap())
.block();

assertThat(requestCaptor.getAllValues())
.as("a single validation query-plan request must be issued")
.hasSize(1);
assertThat(requestCaptor.getValue().useGatewayMode)
.as("validation query-plan must be forced onto Gateway V1 (useGatewayMode=true) when "
+ "the thin-client query-plan kill-switch is disabled, even though the request is "
+ "thin-client eligible")
.isTrue();
} finally {
if (previous == null) {
System.clearProperty("COSMOS.THINCLIENT_QUERY_PLAN_ENABLED");
} else {
System.setProperty("COSMOS.THINCLIENT_QUERY_PLAN_ENABLED", previous);
}
}
}

private static DocumentCollection collectionWithPartitionKey() {
PartitionKeyDefinition partitionKeyDefinition = new PartitionKeyDefinition();
partitionKeyDefinition.setPaths(Collections.singletonList("/pk"));
DocumentCollection collection = new DocumentCollection();
collection.setPartitionKey(partitionKeyDefinition);
return collection;
}

private static IDocumentQueryClient mockQueryClient(
ArgumentCaptor<RxDocumentServiceRequest> requestCaptor,
boolean useThinClient) {
IDocumentQueryClient queryClient = Mockito.mock(IDocumentQueryClient.class);
Mockito.when(queryClient.useThinClient(Mockito.any())).thenReturn(useThinClient);
// executeFeedOperationWithAvailabilityStrategy is a generic <T> method; use doAnswer so the
// returned Mono.empty() is supplied at invocation time without forcing a generic cast on the
// stubbing call site. We only care about the captured request, not the downstream payload.
Mockito
.doAnswer(invocation -> Mono.empty())
.when(queryClient)
.executeFeedOperationWithAvailabilityStrategy(
Mockito.any(),
Mockito.any(),
Mockito.any(),
requestCaptor.capture(),
Mockito.any(),
Mockito.anyString());
return queryClient;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
import com.azure.cosmos.implementation.routing.RegionalRoutingContext;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.PooledByteBufAllocator;
import io.netty.buffer.Unpooled;
import io.netty.channel.ConnectTimeoutException;
import io.netty.handler.codec.http.HttpResponseStatus;
import io.netty.handler.timeout.ReadTimeoutException;
import org.mockito.ArgumentCaptor;
import org.mockito.Mockito;
Expand All @@ -28,6 +30,7 @@
import java.lang.reflect.Method;
import java.net.SocketException;
import java.net.URI;
import java.nio.charset.StandardCharsets;
import java.time.Duration;
import java.util.HashMap;
import java.util.Map;
Expand Down Expand Up @@ -1041,6 +1044,94 @@ private static int getGatewayRetryWithTimeoutInSeconds(RxGatewayStoreModel store
return (int) getGatewayRetryWithTimeoutInSeconds.invoke(storeModel);
}

/**
* Error bodies that {@code validateOrThrow} must turn into a CosmosException carrying the
* real HTTP status (400 here) rather than leaking the parse failure as statusCode 0.
*
* Columns: description, rawBody, expectMessageContains (null = don't assert message content).
* The Gateway V2 / thin-client proxy can return a non-JSON body (optionally NUL-padded) or a
* valid-but-non-object JSON value (scalar / array) for query-plan failures; both must fall back
* cleanly. A valid CosmosError JSON body must still parse and preserve its message.
*/
@DataProvider(name = "validateOrThrowErrorBodyProvider")
public Object[][] validateOrThrowErrorBodyProvider() {
return new Object[][]{
{"NUL-padded plain text", "Query plan generation failed\u0000\u0000\u0000\u0000", "Query plan generation failed"},
{"JSON scalar string", "\"BadRequest\"", null},
{"JSON array", "[1,2,3]", null},
{"JSON number", "42", null},
{"valid CosmosError JSON", "{\"code\":\"BadRequest\",\"message\":\"bad query syntax\"}", "bad query syntax"},
{"empty body", "", null},
};
}

/**
* Locks the contract of the {@code validateOrThrow} fallback: regardless of the shape of the
* error body the proxy returns, the thrown {@link CosmosException} must carry the real HTTP
* status code (400) and never the leaked statusCode 0. The non-object-JSON rows (scalar/array/
* number) specifically guard the ClassCastException path that previously escaped the catch.
*/
@Test(groups = "unit", dataProvider = "validateOrThrowErrorBodyProvider")
public void validateOrThrowPreservesStatusCodeForMalformedBodies(
String description,
String rawBody,
String expectMessageContains) throws Exception {

RxGatewayStoreModel storeModel = new RxGatewayStoreModel(
mockDiagnosticsClientContext(),
Mockito.mock(ISessionContainer.class),
ConsistencyLevel.SESSION,
QueryCompatibilityMode.Default,
new UserAgentContainer(),
Mockito.mock(GlobalEndpointManager.class),
Mockito.mock(HttpClient.class),
null,
null);

RxDocumentServiceRequest dsr = RxDocumentServiceRequest.createFromName(
mockDiagnosticsClientContext(),
OperationType.QueryPlan,
"/dbs/db/colls/col",
ResourceType.Document);
dsr.requestContext = new DocumentServiceRequestContext();

ByteBuf bodyBuf = Unpooled.wrappedBuffer(rawBody.getBytes(StandardCharsets.UTF_8));

try {
invokeValidateOrThrow(storeModel, dsr, HttpResponseStatus.BAD_REQUEST, new HttpHeaders(), bodyBuf);
fail("validateOrThrow should have thrown a CosmosException for: " + description);
} catch (java.lang.reflect.InvocationTargetException invocationTargetException) {
Throwable cause = invocationTargetException.getCause();
assertThat(cause)
.as("validateOrThrow should throw CosmosException for: " + description)
.isInstanceOf(CosmosException.class);
CosmosException cosmosException = (CosmosException) cause;
assertThat(cosmosException.getStatusCode())
.as("status code must be preserved (never statusCode 0) for: " + description)
.isEqualTo(HttpConstants.StatusCodes.BADREQUEST);
if (expectMessageContains != null) {
assertThat(cosmosException.getMessage())
.as("error message should be preserved for: " + description)
.contains(expectMessageContains);
}
}
}

private static void invokeValidateOrThrow(RxGatewayStoreModel storeModel,
RxDocumentServiceRequest request,
HttpResponseStatus status,
HttpHeaders headers,
ByteBuf retainedBodyAsByteBuf) throws Exception {
Method validateOrThrow = RxGatewayStoreModel.class.getDeclaredMethod(
"validateOrThrow",
RxDocumentServiceRequest.class,
HttpResponseStatus.class,
HttpHeaders.class,
ByteBuf.class);
validateOrThrow.setAccessible(true);
validateOrThrow.invoke(storeModel, request, status, headers, retainedBodyAsByteBuf);
}

enum SessionTokenType {
NONE, // no session token applied
USER, // userControlled session token
Expand Down
Loading
Loading