Skip to content

Commit 8fe4387

Browse files
Merge branch 'master' into ananth/5159-hpk-normalization
2 parents 7729ece + a5c5d23 commit 8fe4387

7 files changed

Lines changed: 603 additions & 14 deletions

File tree

Directory.Build.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<ClientOfficialVersion>3.54.1</ClientOfficialVersion>
44
<ClientPreviewVersion>3.55.0</ClientPreviewVersion>
55
<ClientPreviewSuffixVersion>preview.1</ClientPreviewSuffixVersion>
6-
<DirectVersion>3.41.0</DirectVersion>
6+
<DirectVersion>3.41.2</DirectVersion>
77
<FaultInjectionVersion>1.0.0</FaultInjectionVersion>
88
<FaultInjectionSuffixVersion>beta.0</FaultInjectionSuffixVersion>
99
<EncryptionOfficialVersion>2.0.5</EncryptionOfficialVersion>

Microsoft.Azure.Cosmos/src/Query/Core/QueryAdvisor/QueryAdviceRuleDocumentation.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
</Rule>
1212
-->
1313
<QueryAdvice>
14-
<UrlPrefix>https://learn.microsoft.com/en-us/azure/cosmos-db/nosql/query/queryadvisor/</UrlPrefix>
14+
<UrlPrefix>https://aka.ms/CosmosDB/QueryAdvisor/</UrlPrefix>
1515
<Rules>
1616
<Rule Id="QA1000" Name="PartialArrayContains">
1717
<Title>[CDATA["Query uses ARRAY_CONTAINS with partial matching."]]</Title>

Microsoft.Azure.Cosmos/src/ThinClientTransportSerializer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ public static async Task<Stream> SerializeProxyRequestAsync(
113113
activityId,
114114
bufferProvider.Provider,
115115
accountName,
116-
accountName,
116+
string.Empty,
117117
out _,
118118
out _);
119119

Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/BarrierRequestReplicaRetryTests.cs

Lines changed: 520 additions & 0 deletions
Large diffs are not rendered by default.

Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/BaselineTest/TestBaseline/QueryAdvisorBaselineTest.QueryAdviceParse.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
WHERE CONTAINS(r.name, "Abc") ]]></Query>
88
</Input>
99
<Output>
10-
<QueryAdvice><![CDATA[QA1002: Instead of CONTAINS, consider using STARTSWTIH or computed properties, which may improve performance. For more information, please visit https://learn.microsoft.com/en-us/azure/cosmos-db/nosql/query/queryadvisor/QA1002
10+
<QueryAdvice><![CDATA[QA1002: If you are matching on a string prefix, consider using STARTSWITH. For more information, please visit https://aka.ms/CosmosDB/QueryAdvisor/QA1002
1111
]]></QueryAdvice>
1212
</Output>
1313
</Result>
@@ -19,8 +19,8 @@
1919
WHERE GetCurrentTimestamp() > 10 ]]></Query>
2020
</Input>
2121
<Output>
22-
<QueryAdvice><![CDATA[QA1009: Instead of using GetCurrentTimestamp, consider using GetCurrentTimestampStatic, which may improve performance. For more information, please visit https://learn.microsoft.com/en-us/azure/cosmos-db/nosql/query/queryadvisor/QA1009
23-
QA1008: Instead of using GetCurrentTicks, consider using GetCurrentTicksStatic, which may improve performance. For more information, please visit https://learn.microsoft.com/en-us/azure/cosmos-db/nosql/query/queryadvisor/QA1008
22+
<QueryAdvice><![CDATA[QA1009: Consider using GetCurrentTimestampStatic instead of GetCurrentTimestamp in the WHERE clause . For more information, please visit https://aka.ms/CosmosDB/QueryAdvisor/QA1009
23+
QA1008: Consider using GetCurrentTicksStatic instead of GetCurrentTicks in the WHERE clause. For more information, please visit https://aka.ms/CosmosDB/QueryAdvisor/QA1008
2424
]]></QueryAdvice>
2525
</Output>
2626
</Result>

Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/CosmosItemTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ public async Task NegativeCreateItemTest(bool binaryEncodingEnabledInClient)
275275
{
276276
Assert.AreEqual(999999, ce.SubStatusCode);
277277
string exception = ce.ToString();
278-
Assert.IsTrue(exception.StartsWith("Microsoft.Azure.Cosmos.CosmosException : Response status code does not indicate success: Forbidden (403); Substatus: 999999; "));
278+
Assert.IsTrue(exception.Contains("Response status code does not indicate success: Forbidden (403); Substatus: 999999; "));
279279
string diagnostics = ce.Diagnostics.ToString();
280280
Assert.IsTrue(diagnostics.Contains("999999"));
281281
CosmosItemTests.ValidateCosmosException(ce);

Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/CosmosItemThinClientTests.cs

Lines changed: 76 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ namespace Microsoft.Azure.Cosmos.SDK.EmulatorTests
1313
using System.Text.Json;
1414
using System.Text.Json.Serialization;
1515
using System.Threading.Tasks;
16+
using global::Azure;
1617
using global::Azure.Core;
1718
using Microsoft.Azure.Cosmos.Fluent;
1819
using Microsoft.VisualStudio.TestTools.UnitTesting;
@@ -113,6 +114,76 @@ private async Task<List<TestObject>> CreateItemsSafeAsync(IEnumerable<TestObject
113114
return itemsCreated;
114115
}
115116

117+
[TestMethod]
118+
[TestCategory("ThinClient")]
119+
public async Task RegionalDatabaseAccountNameIsEmptyInPayload()
120+
{
121+
byte[] capturedPayload = null;
122+
Environment.SetEnvironmentVariable(ConfigurationManager.ThinClientModeEnabled, "True");
123+
this.connectionString = Environment.GetEnvironmentVariable("COSMOSDB_THINCLIENT");
124+
125+
// Initialize the serializer locally
126+
JsonSerializerOptions jsonSerializerOptions = new JsonSerializerOptions
127+
{
128+
PropertyNamingPolicy = null,
129+
PropertyNameCaseInsensitive = true,
130+
DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull
131+
};
132+
CosmosSystemTextJsonSerializer serializer = new CosmosSystemTextJsonSerializer(jsonSerializerOptions);
133+
134+
CosmosClientBuilder builder = new CosmosClientBuilder(this.connectionString)
135+
.WithConnectionModeGateway()
136+
.WithCustomSerializer(serializer)
137+
.WithSendingRequestEventArgs(async (sender, e) =>
138+
{
139+
if (e.HttpRequest.Version == new Version(2, 0))
140+
{
141+
if (e.HttpRequest.Content != null)
142+
{
143+
capturedPayload = await e.HttpRequest.Content.ReadAsByteArrayAsync();
144+
}
145+
}
146+
});
147+
148+
using CosmosClient client = builder.Build();
149+
string uniqueDbName = "TestRegional_" + Guid.NewGuid().ToString();
150+
Database database = await client.CreateDatabaseIfNotExistsAsync(uniqueDbName);
151+
string uniqueContainerName = "TestRegionalContainer_" + Guid.NewGuid().ToString();
152+
Container container = await database.CreateContainerIfNotExistsAsync(uniqueContainerName, "/pk");
153+
154+
string pk = "pk_regional";
155+
TestObject testItem = this.GenerateItems(pk).First();
156+
157+
// Act
158+
ItemResponse<TestObject> response = await container.CreateItemAsync(testItem, new PartitionKey(testItem.Pk));
159+
Assert.AreEqual(HttpStatusCode.Created, response.StatusCode);
160+
161+
// Assert
162+
Assert.IsNotNull(capturedPayload, "The request payload was not captured.");
163+
164+
165+
// The RNTBD protocol serializes an empty string as a token with a length of 0.
166+
// For `regionalDatabaseAccountName`, which is a SmallString (type 0x02), this is
167+
// serialized as two bytes: 0x02 (type) and 0x00 (length).
168+
// This byte pair represents an empty string value in RNTBD’s small-string encoding.
169+
byte[] emptyStringToken = { 0x02, 0x00 };
170+
171+
bool foundEmptyStringToken = false;
172+
for (int i = 0; i <= capturedPayload.Length - emptyStringToken.Length; i++)
173+
{
174+
if (capturedPayload[i] == emptyStringToken[0] && capturedPayload[i + 1] == emptyStringToken[1])
175+
{
176+
foundEmptyStringToken = true;
177+
break;
178+
}
179+
}
180+
181+
Assert.IsTrue(foundEmptyStringToken, "The RNTBD payload should contain a token representing an empty string for the regional account name.");
182+
183+
// Cleanup
184+
await database.DeleteAsync();
185+
}
186+
116187
[TestMethod]
117188
[TestCategory("ThinClient")]
118189
public async Task HttpRequestVersionIsTwoPointZeroWhenUsingThinClientMode()
@@ -173,12 +244,9 @@ public async Task CreateItemsTest()
173244
public async Task CreateItemsTestWithThinClientFlagEnabledAndAccountDisabled()
174245
{
175246
Environment.SetEnvironmentVariable(ConfigurationManager.ThinClientModeEnabled, "True");
176-
string connectionString = ConfigurationManager.GetEnvironmentVariable<string>("COSMOSDB_MULTI_REGION", string.Empty);
177-
178-
if (string.IsNullOrEmpty(connectionString))
179-
{
180-
Assert.Fail("Set environment variable COSMOSDB_MULTI_REGION to run the tests");
181-
}
247+
string authKey = Utils.ConfigurationManager.AppSettings["MasterKey"];
248+
string endpoint = Utils.ConfigurationManager.AppSettings["GatewayEndpoint"];
249+
AzureKeyCredential masterKeyCredential = new AzureKeyCredential(authKey);
182250

183251
JsonSerializerOptions jsonSerializerOptions = new JsonSerializerOptions
184252
{
@@ -189,7 +257,8 @@ public async Task CreateItemsTestWithThinClientFlagEnabledAndAccountDisabled()
189257
this.cosmosSystemTextJsonSerializer = new MultiRegionSetupHelpers.CosmosSystemTextJsonSerializer(jsonSerializerOptions);
190258

191259
this.client = new CosmosClient(
192-
connectionString,
260+
endpoint,
261+
masterKeyCredential,
193262
new CosmosClientOptions()
194263
{
195264
ConnectionMode = ConnectionMode.Gateway,

0 commit comments

Comments
 (0)