From 8e4977f90fc77288f554c8106801fd9e92b5e6c6 Mon Sep 17 00:00:00 2001 From: Heet Date: Fri, 10 Jun 2022 09:24:34 -0700 Subject: [PATCH 01/32] Binary Serilaization Response test --- .../BinarySerializationResponseTest.sln | 25 +++++++++ .../BinarySerializationResponseTest.csproj | 14 +++++ .../Program.cs | 53 +++++++++++++++++++ 3 files changed, 92 insertions(+) create mode 100644 Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/BinarySerializationResponseTest/BinarySerializationResponseTest.sln create mode 100644 Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/BinarySerializationResponseTest/BinarySerializationResponseTest/BinarySerializationResponseTest.csproj create mode 100644 Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/BinarySerializationResponseTest/BinarySerializationResponseTest/Program.cs diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/BinarySerializationResponseTest/BinarySerializationResponseTest.sln b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/BinarySerializationResponseTest/BinarySerializationResponseTest.sln new file mode 100644 index 0000000000..42a894a8d8 --- /dev/null +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/BinarySerializationResponseTest/BinarySerializationResponseTest.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.2.32516.85 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BinarySerializationResponseTest", "BinarySerializationResponseTest\BinarySerializationResponseTest.csproj", "{D77AA9EC-10D7-4AE0-BC4C-56F467833194}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {D77AA9EC-10D7-4AE0-BC4C-56F467833194}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {D77AA9EC-10D7-4AE0-BC4C-56F467833194}.Debug|Any CPU.Build.0 = Debug|Any CPU + {D77AA9EC-10D7-4AE0-BC4C-56F467833194}.Release|Any CPU.ActiveCfg = Release|Any CPU + {D77AA9EC-10D7-4AE0-BC4C-56F467833194}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {0BA34800-842C-4FA1-A79E-742850AF5177} + EndGlobalSection +EndGlobal diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/BinarySerializationResponseTest/BinarySerializationResponseTest/BinarySerializationResponseTest.csproj b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/BinarySerializationResponseTest/BinarySerializationResponseTest/BinarySerializationResponseTest.csproj new file mode 100644 index 0000000000..ddf988c106 --- /dev/null +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/BinarySerializationResponseTest/BinarySerializationResponseTest/BinarySerializationResponseTest.csproj @@ -0,0 +1,14 @@ + + + + Exe + net6.0 + enable + enable + + + + + + + diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/BinarySerializationResponseTest/BinarySerializationResponseTest/Program.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/BinarySerializationResponseTest/BinarySerializationResponseTest/Program.cs new file mode 100644 index 0000000000..9184b10e93 --- /dev/null +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/BinarySerializationResponseTest/BinarySerializationResponseTest/Program.cs @@ -0,0 +1,53 @@ +using Microsoft.Azure.Cosmos; + +namespace DotNetTool +{ + public class StressTest + { + private static readonly string databaseId = "db"; + private static readonly string containerId = "container3"; + + private static async Task Main(string[] args) + { + try + { + string endpoint = "https://binarycomparison-binary.documents.azure.com:443/"; + string authKey = "7jJjxJcoUzsDfgR7nnYeGrlJI7dizU4u6dhM7xYlZidTjYPhbh1wdABIncBwNpCLjUwjzxOFtVRz3U3hZ4rRzQ=="; + using (CosmosClient client = new CosmosClient(endpoint, authKey)) + { + await RunQueryAsync(client); + } + } + catch (CosmosException ex) + { + Console.WriteLine(ex); + } + } + + private static async Task RunQueryAsync(CosmosClient client) + { + Database database = client.GetDatabase(databaseId); + Container container = database.GetContainer(containerId); + QueryRequestOptions requestOptions = new QueryRequestOptions() + { + CosmosSerializationFormatOptions = new CosmosSerializationFormatOptions( + contentSerializationFormat: "CosmosBinary", + createCustomNavigator: (content) => JsonNavigator.Create(content), + createCustomWriter: () => JsonWriter.Create(JsonSerializationFormat.Binary)) + }; + FeedIterator iterator = container.GetItemQueryStreamIterator( + queryText: "select * from c where c.id = 'bb67343e-3651-40fe-ae8e-bb1613f7d9e0'"); + + { + while (iterator.HasMoreResults) + { + using (ResponseMessage response = await iterator.ReadNextAsync()) + { + response.Diagnostics.ToString(); + Console.WriteLine(response.Diagnostics.ToString()); + } + } + } + } + } +} \ No newline at end of file From 34a5a93bd1fd0fdb7b5eb022264e58354e7178e2 Mon Sep 17 00:00:00 2001 From: Heet Date: Wed, 11 Jan 2023 13:40:57 -0800 Subject: [PATCH 02/32] Added new header SupportedSerializationFormats --- Microsoft.Azure.Cosmos/src/FeedOptions.cs | 9 ++++ .../Headers/CosmosMessageHeadersInternal.cs | 6 +++ Microsoft.Azure.Cosmos/src/Headers/Headers.cs | 6 +++ .../BinarySerializationResponseTest.sln | 25 --------- .../BinarySerializationResponseTest.csproj | 14 ----- .../Program.cs | 53 ------------------- 6 files changed, 21 insertions(+), 92 deletions(-) delete mode 100644 Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/BinarySerializationResponseTest/BinarySerializationResponseTest.sln delete mode 100644 Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/BinarySerializationResponseTest/BinarySerializationResponseTest/BinarySerializationResponseTest.csproj delete mode 100644 Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/BinarySerializationResponseTest/BinarySerializationResponseTest/Program.cs diff --git a/Microsoft.Azure.Cosmos/src/FeedOptions.cs b/Microsoft.Azure.Cosmos/src/FeedOptions.cs index 6f4cae7e0d..e01aa1e429 100644 --- a/Microsoft.Azure.Cosmos/src/FeedOptions.cs +++ b/Microsoft.Azure.Cosmos/src/FeedOptions.cs @@ -69,6 +69,7 @@ internal FeedOptions(FeedOptions options) this.EnableGroupBy = options.EnableGroupBy; this.MergeStaticId = options.MergeStaticId; this.Properties = options.Properties; + this.SupportedSerializationFormats = options.SupportedSerializationFormats; } /// @@ -405,6 +406,14 @@ internal FeedOptions(FeedOptions options) /// internal ContentSerializationFormat? ContentSerializationFormat { get; set; } + /// + /// Gets or sets the SupportedSerializationFormats for the feed (query/read feed) operation in the Azure Cosmos DB service. + /// + /// + /// Serialization format is selected based on the values requested and the serialization format the document is stored in. + /// + internal SupportedSerializationFormats? SupportedSerializationFormats { get; set; } + internal bool EnableGroupBy { get; set; } /// diff --git a/Microsoft.Azure.Cosmos/src/Headers/CosmosMessageHeadersInternal.cs b/Microsoft.Azure.Cosmos/src/Headers/CosmosMessageHeadersInternal.cs index e8c584d782..fd247ffe44 100644 --- a/Microsoft.Azure.Cosmos/src/Headers/CosmosMessageHeadersInternal.cs +++ b/Microsoft.Azure.Cosmos/src/Headers/CosmosMessageHeadersInternal.cs @@ -159,6 +159,12 @@ public virtual string ContentSerializationFormat set => this.SetProperty(HttpConstants.HttpHeaders.ContentSerializationFormat, value); } + public virtual string SupportedSerializationFormats + { + get => this.GetValueOrDefault(HttpConstants.HttpHeaders.SupportedSerializationFormats); + set => this.SetProperty(HttpConstants.HttpHeaders.SupportedSerializationFormats, value); + } + public virtual string ReadFeedKeyType { get => this.GetValueOrDefault(HttpConstants.HttpHeaders.ReadFeedKeyType); diff --git a/Microsoft.Azure.Cosmos/src/Headers/Headers.cs b/Microsoft.Azure.Cosmos/src/Headers/Headers.cs index fda0536da2..e9eac1c180 100644 --- a/Microsoft.Azure.Cosmos/src/Headers/Headers.cs +++ b/Microsoft.Azure.Cosmos/src/Headers/Headers.cs @@ -228,6 +228,12 @@ internal virtual string ContentSerializationFormat set => this.CosmosMessageHeaders.ContentSerializationFormat = value; } + internal virtual string Supportedserializationformats + { + get => this.CosmosMessageHeaders.SupportedSerializationFormats; + set => this.CosmosMessageHeaders.SupportedSerializationFormats = value; + } + internal virtual string ReadFeedKeyType { get => this.CosmosMessageHeaders.ReadFeedKeyType; diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/BinarySerializationResponseTest/BinarySerializationResponseTest.sln b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/BinarySerializationResponseTest/BinarySerializationResponseTest.sln deleted file mode 100644 index 42a894a8d8..0000000000 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/BinarySerializationResponseTest/BinarySerializationResponseTest.sln +++ /dev/null @@ -1,25 +0,0 @@ - -Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio Version 17 -VisualStudioVersion = 17.2.32516.85 -MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BinarySerializationResponseTest", "BinarySerializationResponseTest\BinarySerializationResponseTest.csproj", "{D77AA9EC-10D7-4AE0-BC4C-56F467833194}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Any CPU = Debug|Any CPU - Release|Any CPU = Release|Any CPU - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {D77AA9EC-10D7-4AE0-BC4C-56F467833194}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {D77AA9EC-10D7-4AE0-BC4C-56F467833194}.Debug|Any CPU.Build.0 = Debug|Any CPU - {D77AA9EC-10D7-4AE0-BC4C-56F467833194}.Release|Any CPU.ActiveCfg = Release|Any CPU - {D77AA9EC-10D7-4AE0-BC4C-56F467833194}.Release|Any CPU.Build.0 = Release|Any CPU - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection - GlobalSection(ExtensibilityGlobals) = postSolution - SolutionGuid = {0BA34800-842C-4FA1-A79E-742850AF5177} - EndGlobalSection -EndGlobal diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/BinarySerializationResponseTest/BinarySerializationResponseTest/BinarySerializationResponseTest.csproj b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/BinarySerializationResponseTest/BinarySerializationResponseTest/BinarySerializationResponseTest.csproj deleted file mode 100644 index ddf988c106..0000000000 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/BinarySerializationResponseTest/BinarySerializationResponseTest/BinarySerializationResponseTest.csproj +++ /dev/null @@ -1,14 +0,0 @@ - - - - Exe - net6.0 - enable - enable - - - - - - - diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/BinarySerializationResponseTest/BinarySerializationResponseTest/Program.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/BinarySerializationResponseTest/BinarySerializationResponseTest/Program.cs deleted file mode 100644 index 9184b10e93..0000000000 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/BinarySerializationResponseTest/BinarySerializationResponseTest/Program.cs +++ /dev/null @@ -1,53 +0,0 @@ -using Microsoft.Azure.Cosmos; - -namespace DotNetTool -{ - public class StressTest - { - private static readonly string databaseId = "db"; - private static readonly string containerId = "container3"; - - private static async Task Main(string[] args) - { - try - { - string endpoint = "https://binarycomparison-binary.documents.azure.com:443/"; - string authKey = "7jJjxJcoUzsDfgR7nnYeGrlJI7dizU4u6dhM7xYlZidTjYPhbh1wdABIncBwNpCLjUwjzxOFtVRz3U3hZ4rRzQ=="; - using (CosmosClient client = new CosmosClient(endpoint, authKey)) - { - await RunQueryAsync(client); - } - } - catch (CosmosException ex) - { - Console.WriteLine(ex); - } - } - - private static async Task RunQueryAsync(CosmosClient client) - { - Database database = client.GetDatabase(databaseId); - Container container = database.GetContainer(containerId); - QueryRequestOptions requestOptions = new QueryRequestOptions() - { - CosmosSerializationFormatOptions = new CosmosSerializationFormatOptions( - contentSerializationFormat: "CosmosBinary", - createCustomNavigator: (content) => JsonNavigator.Create(content), - createCustomWriter: () => JsonWriter.Create(JsonSerializationFormat.Binary)) - }; - FeedIterator iterator = container.GetItemQueryStreamIterator( - queryText: "select * from c where c.id = 'bb67343e-3651-40fe-ae8e-bb1613f7d9e0'"); - - { - while (iterator.HasMoreResults) - { - using (ResponseMessage response = await iterator.ReadNextAsync()) - { - response.Diagnostics.ToString(); - Console.WriteLine(response.Diagnostics.ToString()); - } - } - } - } - } -} \ No newline at end of file From 17eb226065108b06203bc845ecd2e356a3ee2f23 Mon Sep 17 00:00:00 2001 From: Heet Date: Wed, 11 Jan 2023 13:56:58 -0800 Subject: [PATCH 03/32] Modified existing use of CosmosSerializationFormatOptions --- .../src/Headers/StoreRequestHeaders.cs | 6 + .../DocumentQueryExecutionContextBase.cs | 9 ++ .../src/RequestOptions/QueryRequestOptions.cs | 7 + .../CosmosSerializationFormatOptions.cs | 12 ++ .../CosmosItemTests.cs | 1 + .../HeadersValidationTests.cs | 141 ++++++++++++++++++ .../ContentSerializationPerformanceTests.cs | 3 +- .../Query/EndToEnd.cs | 1 + .../BinaryEncodingOverTheWireTests.cs | 2 + .../OrderByQueryResultTests.cs | 1 + 10 files changed, 182 insertions(+), 1 deletion(-) diff --git a/Microsoft.Azure.Cosmos/src/Headers/StoreRequestHeaders.cs b/Microsoft.Azure.Cosmos/src/Headers/StoreRequestHeaders.cs index 9147c31026..4c82bff8bf 100644 --- a/Microsoft.Azure.Cosmos/src/Headers/StoreRequestHeaders.cs +++ b/Microsoft.Azure.Cosmos/src/Headers/StoreRequestHeaders.cs @@ -70,6 +70,12 @@ public override string ContentSerializationFormat set => this.requestNameValueCollection.ContentSerializationFormat = value; } + public override string SupportedSerializationFormats + { + get => this.requestNameValueCollection.SupportedSerializationFormats; + set => this.requestNameValueCollection.SupportedSerializationFormats = value; + } + public override string ReadFeedKeyType { get => this.requestNameValueCollection.ReadFeedKeyType; diff --git a/Microsoft.Azure.Cosmos/src/Query/v2Query/DocumentQueryExecutionContextBase.cs b/Microsoft.Azure.Cosmos/src/Query/v2Query/DocumentQueryExecutionContextBase.cs index ec4e6d9185..d89ae6951f 100644 --- a/Microsoft.Azure.Cosmos/src/Query/v2Query/DocumentQueryExecutionContextBase.cs +++ b/Microsoft.Azure.Cosmos/src/Query/v2Query/DocumentQueryExecutionContextBase.cs @@ -335,6 +335,15 @@ await this.Client.EnsureValidOverwriteAsync( requestHeaders[HttpConstants.HttpHeaders.ContentSerializationFormat] = this.feedOptions.ContentSerializationFormat.Value.ToString(); } + if (this.feedOptions.CosmosSerializationFormatOptions != null) + { + requestHeaders[HttpConstants.HttpHeaders.SupportedSerializationFormats] = this.feedOptions.CosmosSerializationFormatOptions.SupportedSerializationFormats; + } + else if (this.feedOptions.SupportedSerializationFormats.HasValue) + { + requestHeaders[HttpConstants.HttpHeaders.SupportedSerializationFormats] = this.feedOptions.SupportedSerializationFormats.Value.ToString(); + } + return requestHeaders; } diff --git a/Microsoft.Azure.Cosmos/src/RequestOptions/QueryRequestOptions.cs b/Microsoft.Azure.Cosmos/src/RequestOptions/QueryRequestOptions.cs index 9e478c96b9..b0b75c9c17 100644 --- a/Microsoft.Azure.Cosmos/src/RequestOptions/QueryRequestOptions.cs +++ b/Microsoft.Azure.Cosmos/src/RequestOptions/QueryRequestOptions.cs @@ -172,6 +172,8 @@ public ConsistencyLevel? ConsistencyLevel internal CosmosSerializationFormatOptions CosmosSerializationFormatOptions { get; set; } + internal BackendSerializationFormatOptions BackendSerializationFormatOptions { get; set; } + internal ExecutionEnvironment? ExecutionEnvironment { get; set; } internal bool? ReturnResultsInDeterministicOrder { get; set; } @@ -230,6 +232,11 @@ internal override void PopulateRequestOptions(RequestMessage request) request.Headers.CosmosMessageHeaders.ContentSerializationFormat = this.CosmosSerializationFormatOptions.ContentSerializationFormat; } + if (this.BackendSerializationFormatOptions != null) + { + request.Headers.CosmosMessageHeaders.SupportedSerializationFormats = this.BackendSerializationFormatOptions.SupportedSerializationFormats; + } + if (this.StartId != null) { request.Headers.Set(HttpConstants.HttpHeaders.StartId, Convert.ToBase64String(Encoding.UTF8.GetBytes(this.StartId))); diff --git a/Microsoft.Azure.Cosmos/src/Serializer/CosmosSerializationFormatOptions.cs b/Microsoft.Azure.Cosmos/src/Serializer/CosmosSerializationFormatOptions.cs index 81ab5fd1e4..649d838a07 100644 --- a/Microsoft.Azure.Cosmos/src/Serializer/CosmosSerializationFormatOptions.cs +++ b/Microsoft.Azure.Cosmos/src/Serializer/CosmosSerializationFormatOptions.cs @@ -17,6 +17,11 @@ internal sealed class CosmosSerializationFormatOptions         /// public string ContentSerializationFormat { get; } + /// +        /// Request multiple serialization formats, backend will decide which formats is best and choose appropriate format. +        /// + public string SupportedSerializationFormats { get; } +         ///         /// Creates a navigator that can navigate a JSON in the specified ContentSerializationFormat         /// @@ -29,6 +34,7 @@ internal sealed class CosmosSerializationFormatOptions public CosmosSerializationFormatOptions( string contentSerializationFormat, + string supportedSerializationFormats, CreateCustomNavigator createCustomNavigator, CreateCustomWriter createCustomWriter) { @@ -37,6 +43,11 @@ public CosmosSerializationFormatOptions( throw new ArgumentNullException(nameof(contentSerializationFormat)); } + if (supportedSerializationFormats == null) + { + throw new ArgumentNullException(nameof(supportedSerializationFormats)); + } + if (createCustomNavigator == null) { throw new ArgumentNullException(nameof(createCustomNavigator)); @@ -48,6 +59,7 @@ public CosmosSerializationFormatOptions( } this.ContentSerializationFormat = contentSerializationFormat; + this.SupportedSerializationFormats = supportedSerializationFormats.Length == 0 ? "JsonText, CosmosBinary" : supportedSerializationFormats; this.CreateCustomNavigatorCallback = createCustomNavigator; this.CreateCustomWriterCallback = createCustomWriter; } diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/CosmosItemTests.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/CosmosItemTests.cs index da6d79c333..95e4583df2 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/CosmosItemTests.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/CosmosItemTests.cs @@ -1631,6 +1631,7 @@ public async Task ItemQueryStreamSerializationSetting() CosmosSerializationFormatOptions options = new CosmosSerializationFormatOptions( ContentSerializationFormat.CosmosBinary.ToString(), + "CosmosBinary", (content) => JsonNavigator.Create(content), () => JsonWriter.Create(JsonSerializationFormat.Binary)); diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/HeadersValidationTests.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/HeadersValidationTests.cs index d8cf36f5de..9c7839e61b 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/HeadersValidationTests.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/HeadersValidationTests.cs @@ -328,6 +328,147 @@ private void ValidateJsonSerializationFormatQuery(DocumentClient client, Documen Assert.IsTrue(response.ResponseBody.ReadByte() == HeadersValidationTests.BinarySerializationByteMarkValue); } + [TestMethod] + [Owner("hdetroja")] + public void ValidateSupportedSerializationFormatsGateway() + { + DocumentClient client = TestCommon.CreateClient(true); + this.ValidateSupportedSerializationFormats(client); + } + + [TestMethod] + public void ValidateSupportedSerializationFormatsRntbd() + { + DocumentClient client = TestCommon.CreateClient(false, Protocol.Tcp); + this.ValidateSupportedSerializationFormats(client); + } + + [TestMethod] + public void ValidateSupportedSerializationFormatsHttps() + { + DocumentClient client = TestCommon.CreateClient(false, Protocol.Https); + this.ValidateSupportedSerializationFormats(client); + } + private void ValidateSupportedSerializationFormats(DocumentClient client) + { + DocumentCollection collection = TestCommon.CreateOrGetDocumentCollection(client); + this.ValidateSupportedSerializationFormatsReadFeed(client, collection); + this.ValidateSupportedSerializationFormatsQuery(client, collection); + } + + private void ValidateSupportedSerializationFormatsReadFeed(DocumentClient client, DocumentCollection collection) + { + // Value not supported + INameValueCollection headers = new Documents.Collections.RequestNameValueCollection(); + headers.Add(HttpConstants.HttpHeaders.SupportedSerializationFormats, "Not a valid value"); + + try + { + this.ReadDocumentFeedRequestSinglePartition(client, collection.ResourceId, headers); + Assert.Fail("Should throw an exception"); + } + catch (Exception ex) + { + DocumentClientException innerException = ex.InnerException as DocumentClientException; + Assert.IsTrue(innerException.StatusCode == HttpStatusCode.BadRequest, "invalid status code"); + } + + // Supported values + + // Text + headers = new Documents.Collections.RequestNameValueCollection(); + headers.Add(HttpConstants.HttpHeaders.SupportedSerializationFormats, "JsonTEXT"); + DocumentServiceResponse response = this.ReadDocumentFeedRequestAsync(client, collection.ResourceId, headers).Result; + Assert.IsTrue(response.StatusCode == HttpStatusCode.OK, "Invalid status code"); + Assert.IsTrue(response.ResponseBody.ReadByte() < HeadersValidationTests.BinarySerializationByteMarkValue); + + // None + headers = new Documents.Collections.RequestNameValueCollection(); + response = this.ReadDocumentFeedRequestAsync(client, collection.ResourceId, headers).Result; + Assert.IsTrue(response.StatusCode == HttpStatusCode.OK, "Invalid status code"); + Assert.IsTrue(response.ResponseBody.ReadByte() < HeadersValidationTests.BinarySerializationByteMarkValue); + + // Binary (Read feed should ignore all options) + headers = new Documents.Collections.RequestNameValueCollection(); + headers.Add(HttpConstants.HttpHeaders.SupportedSerializationFormats, "COSMOSbinary"); + response = this.ReadDocumentFeedRequestAsync(client, collection.ResourceId, headers).Result; + Assert.IsTrue(response.StatusCode == HttpStatusCode.OK, "Invalid status code"); + Assert.IsTrue(response.ResponseBody.ReadByte() < HeadersValidationTests.BinarySerializationByteMarkValue); + } + + private void ValidateSupportedSerializationFormatsQuery(DocumentClient client, DocumentCollection collection) + { + SqlQuerySpec sqlQuerySpec = new SqlQuerySpec("SELECT * FROM c"); + // Value not supported + INameValueCollection headers = new Documents.Collections.RequestNameValueCollection(); + headers.Add(HttpConstants.HttpHeaders.SupportedSerializationFormats, "Not a valid value"); + + try + { + this.QueryRequest(client, collection.ResourceId, sqlQuerySpec, headers); + Assert.Fail("Should throw an exception"); + } + catch (Exception ex) + { + DocumentClientException innerException = ex.InnerException as DocumentClientException; + Assert.IsTrue(innerException.StatusCode == HttpStatusCode.BadRequest, "invalid status code"); + } + + // Supported values + + // Text + headers = new Documents.Collections.RequestNameValueCollection(); + headers.Add(HttpConstants.HttpHeaders.SupportedSerializationFormats, "jsontext"); + DocumentServiceResponse response = this.QueryRequest(client, collection.ResourceId, sqlQuerySpec, headers); + Assert.IsTrue(response.StatusCode == HttpStatusCode.OK, "Invalid status code"); + Assert.IsTrue(response.ResponseBody.ReadByte() < HeadersValidationTests.BinarySerializationByteMarkValue); + + // None + headers = new Documents.Collections.RequestNameValueCollection(); + response = this.QueryRequest(client, collection.ResourceId, sqlQuerySpec, headers); + Assert.IsTrue(response.StatusCode == HttpStatusCode.OK, "Invalid status code"); + Assert.IsTrue(response.ResponseBody.ReadByte() < HeadersValidationTests.BinarySerializationByteMarkValue); + + // Binary + headers = new Documents.Collections.RequestNameValueCollection(); + headers.Add(HttpConstants.HttpHeaders.SupportedSerializationFormats, "COSMOSBINARY"); + response = this.QueryRequest(client, collection.ResourceId, sqlQuerySpec, headers); + Assert.IsTrue(response.StatusCode == HttpStatusCode.OK, "Invalid status code"); + Assert.IsTrue(response.ResponseBody.ReadByte() == HeadersValidationTests.BinarySerializationByteMarkValue); + + headers = new Documents.Collections.RequestNameValueCollection(); + headers.Add(HttpConstants.HttpHeaders.SupportedSerializationFormats, "JsonText, CosmosBinary"); + response = this.QueryRequest(client, collection.ResourceId, sqlQuerySpec, headers); + Assert.IsTrue(response.StatusCode == HttpStatusCode.OK, "Invalid status code"); + Assert.IsTrue(response.ResponseBody.ReadByte() < HeadersValidationTests.BinarySerializationByteMarkValue); + + headers = new Documents.Collections.RequestNameValueCollection(); + headers.Add(HttpConstants.HttpHeaders.SupportedSerializationFormats, "CosmosBinary, HybridRow"); + response = this.QueryRequest(client, collection.ResourceId, sqlQuerySpec, headers); + Assert.IsTrue(response.StatusCode == HttpStatusCode.OK, "Invalid status code"); + Assert.IsTrue(response.ResponseBody.ReadByte() == HeadersValidationTests.BinarySerializationByteMarkValue); + + headers = new Documents.Collections.RequestNameValueCollection(); + headers.Add(HttpConstants.HttpHeaders.SupportedSerializationFormats, "JsonText, CosmosBinary, HybridRow"); + response = this.QueryRequest(client, collection.ResourceId, sqlQuerySpec, headers); + Assert.IsTrue(response.StatusCode == HttpStatusCode.OK, "Invalid status code"); + Assert.IsTrue(response.ResponseBody.ReadByte() < HeadersValidationTests.BinarySerializationByteMarkValue); + + headers = new Documents.Collections.RequestNameValueCollection(); + headers.Add(HttpConstants.HttpHeaders.ContentSerializationFormat, "CosmosBinary"); + headers.Add(HttpConstants.HttpHeaders.SupportedSerializationFormats, "JsonText, CosmosBinary, HybridRow"); + response = this.QueryRequest(client, collection.ResourceId, sqlQuerySpec, headers); + Assert.IsTrue(response.StatusCode == HttpStatusCode.OK, "Invalid status code"); + Assert.IsTrue(response.ResponseBody.ReadByte() == HeadersValidationTests.BinarySerializationByteMarkValue); + + headers = new Documents.Collections.RequestNameValueCollection(); + headers.Add(HttpConstants.HttpHeaders.ContentSerializationFormat, "JsonText"); + headers.Add(HttpConstants.HttpHeaders.SupportedSerializationFormats, "JsonText, CosmosBinary, HybridRow"); + response = this.QueryRequest(client, collection.ResourceId, sqlQuerySpec, headers); + Assert.IsTrue(response.StatusCode == HttpStatusCode.OK, "Invalid status code"); + Assert.IsTrue(response.ResponseBody.ReadByte() < HeadersValidationTests.BinarySerializationByteMarkValue); + } + [TestMethod] public void ValidateIndexingDirectiveGateway() { diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/QueryPerfTest/ContentSerializationPerformanceTests.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/QueryPerfTest/ContentSerializationPerformanceTests.cs index c18ac5e420..8f4c383f2a 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/QueryPerfTest/ContentSerializationPerformanceTests.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/QueryPerfTest/ContentSerializationPerformanceTests.cs @@ -8,7 +8,7 @@ using Microsoft.Azure.Cosmos.Json; using Microsoft.VisualStudio.TestTools.UnitTesting; - [Ignore] + //[Ignore] [TestClass] public class ContentSerializationPerformanceTests { @@ -85,6 +85,7 @@ private async Task RunQueryAsync(Container container) MaxItemCount = this.MaxItemCount, CosmosSerializationFormatOptions = new CosmosSerializationFormatOptions( contentSerializationFormat: this.contentSerialization, + supportedSerializationFormats: "JsonText, CosmosBinary, HybridRow", createCustomNavigator: (content) => JsonNavigator.Create(content), createCustomWriter: () => JsonWriter.Create(this.contentSerialization == "JsonText" ? JsonSerializationFormat.Text : JsonSerializationFormat.Binary)) }; diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Performance.Tests/Query/EndToEnd.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Performance.Tests/Query/EndToEnd.cs index 24cb907be8..f76fc316c7 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Performance.Tests/Query/EndToEnd.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Performance.Tests/Query/EndToEnd.cs @@ -219,6 +219,7 @@ private static void SetSerializationFormat( CosmosSerializationFormatOptions formatOptions = new CosmosSerializationFormatOptions( contentSerializationFormat, + "CosmosBinary", (content) => JsonNavigator.Create(content), () => JsonWriter.Create(JsonSerializationFormat.Text)); diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/BinaryEncodingOverTheWireTests.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/BinaryEncodingOverTheWireTests.cs index b55e837844..e86f09b5ef 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/BinaryEncodingOverTheWireTests.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/BinaryEncodingOverTheWireTests.cs @@ -250,6 +250,7 @@ async Task AssertQueryDrainsCorrectlyAsync(FeedIterator feedIterator) { CosmosSerializationFormatOptions = new CosmosSerializationFormatOptions( "JsonText", + "CosmosBinary", (content) => JsonNavigator.Create(content), () => Cosmos.Json.JsonWriter.Create(JsonSerializationFormat.Text)), }); @@ -261,6 +262,7 @@ async Task AssertQueryDrainsCorrectlyAsync(FeedIterator feedIterator) requestOptions: new QueryRequestOptions() { CosmosSerializationFormatOptions = new CosmosSerializationFormatOptions( + "CosmosBinary", "CosmosBinary", (content) => JsonNavigator.Create(content), () => Cosmos.Json.JsonWriter.Create(JsonSerializationFormat.Text)), diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Query/ContinuationTokens/OrderByQueryResultTests.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Query/ContinuationTokens/OrderByQueryResultTests.cs index 86093aa296..fc2fd3ca79 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Query/ContinuationTokens/OrderByQueryResultTests.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Query/ContinuationTokens/OrderByQueryResultTests.cs @@ -34,6 +34,7 @@ public void TestOrderByUndefined() Documents.ResourceType.Document, new CosmosSerializationFormatOptions( "JsonText", + "CosmosBinary", (content) => JsonNavigator.Create(content), () => JsonWriter.Create(JsonSerializationFormat.Text))); From 55b8038b204392f7eccea4e653cc3a6be7b6feae Mon Sep 17 00:00:00 2001 From: Heet Date: Wed, 11 Jan 2023 16:05:19 -0800 Subject: [PATCH 04/32] Modified tests and removed unused code --- Microsoft.Azure.Cosmos/src/FeedOptions.cs | 2 +- .../src/RequestOptions/QueryRequestOptions.cs | 8 +------- .../HeadersValidationTests.cs | 6 ++++++ .../QueryPerfTest/ContentSerializationPerformanceTests.cs | 4 ++-- .../Query/EndToEnd.cs | 2 +- .../BinaryEncodingOverTheWireTests.cs | 4 ++-- .../Query/ContinuationTokens/OrderByQueryResultTests.cs | 2 +- 7 files changed, 14 insertions(+), 14 deletions(-) diff --git a/Microsoft.Azure.Cosmos/src/FeedOptions.cs b/Microsoft.Azure.Cosmos/src/FeedOptions.cs index e01aa1e429..cc3c85aa6a 100644 --- a/Microsoft.Azure.Cosmos/src/FeedOptions.cs +++ b/Microsoft.Azure.Cosmos/src/FeedOptions.cs @@ -410,7 +410,7 @@ internal FeedOptions(FeedOptions options) /// Gets or sets the SupportedSerializationFormats for the feed (query/read feed) operation in the Azure Cosmos DB service. /// /// - /// Serialization format is selected based on the values requested and the serialization format the document is stored in. + /// Serialization format for the response is selected based on the values requested and the serialization format the document is stored in. /// internal SupportedSerializationFormats? SupportedSerializationFormats { get; set; } diff --git a/Microsoft.Azure.Cosmos/src/RequestOptions/QueryRequestOptions.cs b/Microsoft.Azure.Cosmos/src/RequestOptions/QueryRequestOptions.cs index b0b75c9c17..ab4bd2a794 100644 --- a/Microsoft.Azure.Cosmos/src/RequestOptions/QueryRequestOptions.cs +++ b/Microsoft.Azure.Cosmos/src/RequestOptions/QueryRequestOptions.cs @@ -172,8 +172,6 @@ public ConsistencyLevel? ConsistencyLevel internal CosmosSerializationFormatOptions CosmosSerializationFormatOptions { get; set; } - internal BackendSerializationFormatOptions BackendSerializationFormatOptions { get; set; } - internal ExecutionEnvironment? ExecutionEnvironment { get; set; } internal bool? ReturnResultsInDeterministicOrder { get; set; } @@ -230,11 +228,7 @@ internal override void PopulateRequestOptions(RequestMessage request) if (this.CosmosSerializationFormatOptions != null) { request.Headers.CosmosMessageHeaders.ContentSerializationFormat = this.CosmosSerializationFormatOptions.ContentSerializationFormat; - } - - if (this.BackendSerializationFormatOptions != null) - { - request.Headers.CosmosMessageHeaders.SupportedSerializationFormats = this.BackendSerializationFormatOptions.SupportedSerializationFormats; + request.Headers.CosmosMessageHeaders.SupportedSerializationFormats = this.CosmosSerializationFormatOptions.SupportedSerializationFormats; } if (this.StartId != null) diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/HeadersValidationTests.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/HeadersValidationTests.cs index 9c7839e61b..41ea0a05ca 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/HeadersValidationTests.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/HeadersValidationTests.cs @@ -394,6 +394,12 @@ private void ValidateSupportedSerializationFormatsReadFeed(DocumentClient client response = this.ReadDocumentFeedRequestAsync(client, collection.ResourceId, headers).Result; Assert.IsTrue(response.StatusCode == HttpStatusCode.OK, "Invalid status code"); Assert.IsTrue(response.ResponseBody.ReadByte() < HeadersValidationTests.BinarySerializationByteMarkValue); + + headers = new Documents.Collections.RequestNameValueCollection(); + headers.Add(HttpConstants.HttpHeaders.SupportedSerializationFormats, "JsonText, CosmosBinary"); + response = this.ReadDocumentFeedRequestAsync(client, collection.ResourceId, headers).Result; + Assert.IsTrue(response.StatusCode == HttpStatusCode.OK, "Invalid status code"); + Assert.IsTrue(response.ResponseBody.ReadByte() < HeadersValidationTests.BinarySerializationByteMarkValue); } private void ValidateSupportedSerializationFormatsQuery(DocumentClient client, DocumentCollection collection) diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/QueryPerfTest/ContentSerializationPerformanceTests.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/QueryPerfTest/ContentSerializationPerformanceTests.cs index 8f4c383f2a..0b0929978f 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/QueryPerfTest/ContentSerializationPerformanceTests.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/QueryPerfTest/ContentSerializationPerformanceTests.cs @@ -8,7 +8,7 @@ using Microsoft.Azure.Cosmos.Json; using Microsoft.VisualStudio.TestTools.UnitTesting; - //[Ignore] + [Ignore] [TestClass] public class ContentSerializationPerformanceTests { @@ -85,7 +85,7 @@ private async Task RunQueryAsync(Container container) MaxItemCount = this.MaxItemCount, CosmosSerializationFormatOptions = new CosmosSerializationFormatOptions( contentSerializationFormat: this.contentSerialization, - supportedSerializationFormats: "JsonText, CosmosBinary, HybridRow", + supportedSerializationFormats: "", createCustomNavigator: (content) => JsonNavigator.Create(content), createCustomWriter: () => JsonWriter.Create(this.contentSerialization == "JsonText" ? JsonSerializationFormat.Text : JsonSerializationFormat.Binary)) }; diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Performance.Tests/Query/EndToEnd.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Performance.Tests/Query/EndToEnd.cs index f76fc316c7..c2677fdb86 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Performance.Tests/Query/EndToEnd.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Performance.Tests/Query/EndToEnd.cs @@ -219,7 +219,7 @@ private static void SetSerializationFormat( CosmosSerializationFormatOptions formatOptions = new CosmosSerializationFormatOptions( contentSerializationFormat, - "CosmosBinary", + "", (content) => JsonNavigator.Create(content), () => JsonWriter.Create(JsonSerializationFormat.Text)); diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/BinaryEncodingOverTheWireTests.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/BinaryEncodingOverTheWireTests.cs index e86f09b5ef..55a0cb5bf0 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/BinaryEncodingOverTheWireTests.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/BinaryEncodingOverTheWireTests.cs @@ -250,7 +250,7 @@ async Task AssertQueryDrainsCorrectlyAsync(FeedIterator feedIterator) { CosmosSerializationFormatOptions = new CosmosSerializationFormatOptions( "JsonText", - "CosmosBinary", + "", (content) => JsonNavigator.Create(content), () => Cosmos.Json.JsonWriter.Create(JsonSerializationFormat.Text)), }); @@ -263,7 +263,7 @@ async Task AssertQueryDrainsCorrectlyAsync(FeedIterator feedIterator) { CosmosSerializationFormatOptions = new CosmosSerializationFormatOptions( "CosmosBinary", - "CosmosBinary", + "", (content) => JsonNavigator.Create(content), () => Cosmos.Json.JsonWriter.Create(JsonSerializationFormat.Text)), }); diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Query/ContinuationTokens/OrderByQueryResultTests.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Query/ContinuationTokens/OrderByQueryResultTests.cs index fc2fd3ca79..fbee8dcaf6 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Query/ContinuationTokens/OrderByQueryResultTests.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Query/ContinuationTokens/OrderByQueryResultTests.cs @@ -34,7 +34,7 @@ public void TestOrderByUndefined() Documents.ResourceType.Document, new CosmosSerializationFormatOptions( "JsonText", - "CosmosBinary", + "", (content) => JsonNavigator.Create(content), () => JsonWriter.Create(JsonSerializationFormat.Text))); From 455f20c5d74c2325e6985f041758bf6ec09dd7aa Mon Sep 17 00:00:00 2001 From: Heet Date: Mon, 23 Jan 2023 13:12:36 -0800 Subject: [PATCH 05/32] Addressed comments --- .../DocumentQueryExecutionContextBase.cs | 8 +- .../src/RequestOptions/QueryRequestOptions.cs | 11 +- .../CosmosSerializationFormatOptions.cs | 12 -- .../CosmosItemTests.cs | 39 ++-- .../HeadersValidationTests.cs | 202 +++++++++--------- .../ContentSerializationPerformanceTests.cs | 1 - .../Query/EndToEnd.cs | 1 - .../BinaryEncodingOverTheWireTests.cs | 2 - .../OrderByQueryResultTests.cs | 1 - 9 files changed, 135 insertions(+), 142 deletions(-) diff --git a/Microsoft.Azure.Cosmos/src/Query/v2Query/DocumentQueryExecutionContextBase.cs b/Microsoft.Azure.Cosmos/src/Query/v2Query/DocumentQueryExecutionContextBase.cs index d89ae6951f..4151590d58 100644 --- a/Microsoft.Azure.Cosmos/src/Query/v2Query/DocumentQueryExecutionContextBase.cs +++ b/Microsoft.Azure.Cosmos/src/Query/v2Query/DocumentQueryExecutionContextBase.cs @@ -335,13 +335,13 @@ await this.Client.EnsureValidOverwriteAsync( requestHeaders[HttpConstants.HttpHeaders.ContentSerializationFormat] = this.feedOptions.ContentSerializationFormat.Value.ToString(); } - if (this.feedOptions.CosmosSerializationFormatOptions != null) + if (this.feedOptions.SupportedSerializationFormats != null) { - requestHeaders[HttpConstants.HttpHeaders.SupportedSerializationFormats] = this.feedOptions.CosmosSerializationFormatOptions.SupportedSerializationFormats; + requestHeaders[HttpConstants.HttpHeaders.SupportedSerializationFormats] = this.feedOptions.SupportedSerializationFormats.Value.ToString(); } - else if (this.feedOptions.SupportedSerializationFormats.HasValue) + else { - requestHeaders[HttpConstants.HttpHeaders.SupportedSerializationFormats] = this.feedOptions.SupportedSerializationFormats.Value.ToString(); + requestHeaders[HttpConstants.HttpHeaders.SupportedSerializationFormats] = Headers.defaultSupportedSerializationFormats; } return requestHeaders; diff --git a/Microsoft.Azure.Cosmos/src/RequestOptions/QueryRequestOptions.cs b/Microsoft.Azure.Cosmos/src/RequestOptions/QueryRequestOptions.cs index ab4bd2a794..164f5799e5 100644 --- a/Microsoft.Azure.Cosmos/src/RequestOptions/QueryRequestOptions.cs +++ b/Microsoft.Azure.Cosmos/src/RequestOptions/QueryRequestOptions.cs @@ -171,6 +171,7 @@ public ConsistencyLevel? ConsistencyLevel internal EnumerationDirection? EnumerationDirection { get; set; } internal CosmosSerializationFormatOptions CosmosSerializationFormatOptions { get; set; } + internal SupportedSerializationFormats? SupportedSerializationFormats { get; set; } internal ExecutionEnvironment? ExecutionEnvironment { get; set; } @@ -228,7 +229,15 @@ internal override void PopulateRequestOptions(RequestMessage request) if (this.CosmosSerializationFormatOptions != null) { request.Headers.CosmosMessageHeaders.ContentSerializationFormat = this.CosmosSerializationFormatOptions.ContentSerializationFormat; - request.Headers.CosmosMessageHeaders.SupportedSerializationFormats = this.CosmosSerializationFormatOptions.SupportedSerializationFormats; + } + + if (this.SupportedSerializationFormats != null) + { + request.Headers.CosmosMessageHeaders.SupportedSerializationFormats = this.SupportedSerializationFormats.ToString(); + } + else + { + request.Headers.CosmosMessageHeaders.SupportedSerializationFormats = Headers.defaultSupportedSerializationFormats; } if (this.StartId != null) diff --git a/Microsoft.Azure.Cosmos/src/Serializer/CosmosSerializationFormatOptions.cs b/Microsoft.Azure.Cosmos/src/Serializer/CosmosSerializationFormatOptions.cs index 649d838a07..81ab5fd1e4 100644 --- a/Microsoft.Azure.Cosmos/src/Serializer/CosmosSerializationFormatOptions.cs +++ b/Microsoft.Azure.Cosmos/src/Serializer/CosmosSerializationFormatOptions.cs @@ -17,11 +17,6 @@ internal sealed class CosmosSerializationFormatOptions         /// public string ContentSerializationFormat { get; } - /// -        /// Request multiple serialization formats, backend will decide which formats is best and choose appropriate format. -        /// - public string SupportedSerializationFormats { get; } -         ///         /// Creates a navigator that can navigate a JSON in the specified ContentSerializationFormat         /// @@ -34,7 +29,6 @@ internal sealed class CosmosSerializationFormatOptions public CosmosSerializationFormatOptions( string contentSerializationFormat, - string supportedSerializationFormats, CreateCustomNavigator createCustomNavigator, CreateCustomWriter createCustomWriter) { @@ -43,11 +37,6 @@ public CosmosSerializationFormatOptions( throw new ArgumentNullException(nameof(contentSerializationFormat)); } - if (supportedSerializationFormats == null) - { - throw new ArgumentNullException(nameof(supportedSerializationFormats)); - } - if (createCustomNavigator == null) { throw new ArgumentNullException(nameof(createCustomNavigator)); @@ -59,7 +48,6 @@ public CosmosSerializationFormatOptions( } this.ContentSerializationFormat = contentSerializationFormat; - this.SupportedSerializationFormats = supportedSerializationFormats.Length == 0 ? "JsonText, CosmosBinary" : supportedSerializationFormats; this.CreateCustomNavigatorCallback = createCustomNavigator; this.CreateCustomWriterCallback = createCustomWriter; } diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/CosmosItemTests.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/CosmosItemTests.cs index 95e4583df2..ccac6111a9 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/CosmosItemTests.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/CosmosItemTests.cs @@ -772,9 +772,9 @@ public async Task PartitionKeyDeleteTestForSubpartitionedContainer() try { CosmosClient client = TestCommon.CreateCosmosClient(true); - + database = await client.CreateDatabaseIfNotExistsAsync("mydb"); - + ContainerProperties containerProperties = new ContainerProperties("subpartitionedcontainer", new List { "/Country", "/City" }); Container container = await database.CreateContainerAsync(containerProperties); ContainerInternal containerInternal = (ContainerInternal)container; @@ -805,7 +805,7 @@ public async Task PartitionKeyDeleteTestForSubpartitionedContainer() doc1.SetValue("Country", "USA"); doc1.SetValue("City", "Stonybrook"); documents[4] = await container.CreateItemAsync(doc1); - + Cosmos.PartitionKey partitionKey1 = new PartitionKeyBuilder().Add("USA").Add("Stonybrook").Build(); using (ResponseMessage pKDeleteResponse = await containerInternal.DeleteAllItemsByPartitionKeyStreamAsync(partitionKey1)) @@ -837,7 +837,7 @@ public async Task PartitionKeyDeleteTestForSubpartitionedContainer() finally { HttpConstants.Versions.CurrentVersion = currentVersion; - if(database != null) await database.DeleteAsync(); + if (database != null) await database.DeleteAsync(); } } @@ -966,7 +966,7 @@ public async Task ItemCustomSerialzierTest() // Each parameter in query spec should be a call to the custom serializer int parameterCount = queryDefinition.ToSqlQuerySpec().Parameters.Count; - Assert.AreEqual((parameterCount*pageCount)+parameterCount, toStreamCount, $"missing to stream call. Expected: {(parameterCount * pageCount) + parameterCount}, Actual: {toStreamCount} for query:{queryDefinition.ToSqlQuerySpec().QueryText}"); + Assert.AreEqual((parameterCount * pageCount) + parameterCount, toStreamCount, $"missing to stream call. Expected: {(parameterCount * pageCount) + parameterCount}, Actual: {toStreamCount} for query:{queryDefinition.ToSqlQuerySpec().QueryText}"); Assert.AreEqual(pageCount, fromStreamCount); } } @@ -1188,7 +1188,7 @@ public async Task QueryStreamValueTest() { Assert.AreEqual(3, pageCount); } - + IReadOnlyList<(string Name, object Value)> parameters1 = queryDefinition.GetQueryParameters(); @@ -1339,7 +1339,7 @@ public async Task ItemMultiplePartitionQuery() { FeedResponse iter = await feedIterator.ReadNextAsync(); Assert.IsTrue(iter.Count() <= 1); - if(iter.Count() == 1) + if (iter.Count() == 1) { found = true; ToDoActivity response = iter.First(); @@ -1365,8 +1365,8 @@ public async Task ItemMultiplePartitionOrderByQueryStream() }; IList deleteList = await ToDoActivity.CreateRandomItems( - this.Container, - 300, + this.Container, + 300, randomPartitionKey: true, randomTaskNumber: true); @@ -1623,15 +1623,14 @@ public async Task ItemEpkQuerySingleKeyRangeValidation() public async Task ItemQueryStreamSerializationSetting() { IList deleteList = await ToDoActivity.CreateRandomItems( - container: this.Container, - pkCount: 101, + container: this.Container, + pkCount: 101, randomTaskNumber: true); QueryDefinition sql = new QueryDefinition("SELECT * FROM toDoActivity t ORDER BY t.taskNum"); CosmosSerializationFormatOptions options = new CosmosSerializationFormatOptions( ContentSerializationFormat.CosmosBinary.ToString(), - "CosmosBinary", (content) => JsonNavigator.Create(content), () => JsonWriter.Create(JsonSerializationFormat.Binary)); @@ -2907,16 +2906,16 @@ public async Task CustomPropertiesItemRequestOptionsTest() builder => builder.WithTransportClientHandlerFactory(transportClient => new TransportClientHelper.TransportClientWrapper( transportClient, (uri, resourceOperation, request) => + { + if (resourceOperation.resourceType == ResourceType.Document && + resourceOperation.operationType == OperationType.Create) { - if (resourceOperation.resourceType == ResourceType.Document && - resourceOperation.operationType == OperationType.Create) - { - bool customHeaderExists = request.Properties.TryGetValue(customHeaderName, out object value); + bool customHeaderExists = request.Properties.TryGetValue(customHeaderName, out object value); - Assert.IsTrue(customHeaderExists); - Assert.AreEqual(customHeaderValue, value); - } - }))); + Assert.IsTrue(customHeaderExists); + Assert.AreEqual(customHeaderValue, value); + } + }))); Container container = clientWithIntercepter.GetContainer(this.database.Id, this.Container.Id); diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/HeadersValidationTests.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/HeadersValidationTests.cs index 41ea0a05ca..acc082586f 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/HeadersValidationTests.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/HeadersValidationTests.cs @@ -356,123 +356,125 @@ private void ValidateSupportedSerializationFormats(DocumentClient client) this.ValidateSupportedSerializationFormatsQuery(client, collection); } - private void ValidateSupportedSerializationFormatsReadFeed(DocumentClient client, DocumentCollection collection) + private void SupportedSerializationFormatsNegativeCases(DocumentClient client, DocumentCollection collection, string value, bool isQuery = true, SqlQuerySpec sqlQuerySpec = null) { - // Value not supported - INameValueCollection headers = new Documents.Collections.RequestNameValueCollection(); - headers.Add(HttpConstants.HttpHeaders.SupportedSerializationFormats, "Not a valid value"); + INameValueCollection headers = new RequestNameValueCollection(); + headers.Add(HttpConstants.HttpHeaders.SupportedSerializationFormats, value); - try + if (isQuery) { - this.ReadDocumentFeedRequestSinglePartition(client, collection.ResourceId, headers); - Assert.Fail("Should throw an exception"); + try + { + this.QueryRequest(client, collection.ResourceId, sqlQuerySpec, headers); + Assert.Fail("Should throw an exception"); + } + catch (Exception ex) + { + DocumentClientException innerException = ex.InnerException as DocumentClientException; + Assert.IsTrue(innerException.StatusCode == HttpStatusCode.BadRequest, "invalid status code"); + } } - catch (Exception ex) + else { - DocumentClientException innerException = ex.InnerException as DocumentClientException; - Assert.IsTrue(innerException.StatusCode == HttpStatusCode.BadRequest, "invalid status code"); + try + { + this.ReadDocumentFeedRequestSinglePartition(client, collection.ResourceId, headers); + Assert.Fail("Should throw an exception"); + } + catch (Exception ex) + { + DocumentClientException innerException = ex.InnerException as DocumentClientException; + Assert.IsTrue(innerException.StatusCode == HttpStatusCode.BadRequest, "invalid status code"); + } } - - // Supported values - - // Text - headers = new Documents.Collections.RequestNameValueCollection(); - headers.Add(HttpConstants.HttpHeaders.SupportedSerializationFormats, "JsonTEXT"); - DocumentServiceResponse response = this.ReadDocumentFeedRequestAsync(client, collection.ResourceId, headers).Result; - Assert.IsTrue(response.StatusCode == HttpStatusCode.OK, "Invalid status code"); - Assert.IsTrue(response.ResponseBody.ReadByte() < HeadersValidationTests.BinarySerializationByteMarkValue); - - // None - headers = new Documents.Collections.RequestNameValueCollection(); - response = this.ReadDocumentFeedRequestAsync(client, collection.ResourceId, headers).Result; - Assert.IsTrue(response.StatusCode == HttpStatusCode.OK, "Invalid status code"); - Assert.IsTrue(response.ResponseBody.ReadByte() < HeadersValidationTests.BinarySerializationByteMarkValue); - - // Binary (Read feed should ignore all options) - headers = new Documents.Collections.RequestNameValueCollection(); - headers.Add(HttpConstants.HttpHeaders.SupportedSerializationFormats, "COSMOSbinary"); - response = this.ReadDocumentFeedRequestAsync(client, collection.ResourceId, headers).Result; - Assert.IsTrue(response.StatusCode == HttpStatusCode.OK, "Invalid status code"); - Assert.IsTrue(response.ResponseBody.ReadByte() < HeadersValidationTests.BinarySerializationByteMarkValue); - - headers = new Documents.Collections.RequestNameValueCollection(); - headers.Add(HttpConstants.HttpHeaders.SupportedSerializationFormats, "JsonText, CosmosBinary"); - response = this.ReadDocumentFeedRequestAsync(client, collection.ResourceId, headers).Result; - Assert.IsTrue(response.StatusCode == HttpStatusCode.OK, "Invalid status code"); - Assert.IsTrue(response.ResponseBody.ReadByte() < HeadersValidationTests.BinarySerializationByteMarkValue); } - private void ValidateSupportedSerializationFormatsQuery(DocumentClient client, DocumentCollection collection) + private void SupportedSerializationFormatsPositiveCases( + DocumentClient client, + DocumentCollection collection, + bool expectedResultIsBinary, + SqlQuerySpec sqlQuerySpec, + string supportedSerializationFormats, + string contentSerializationFormats = "") { - SqlQuerySpec sqlQuerySpec = new SqlQuerySpec("SELECT * FROM c"); - // Value not supported - INameValueCollection headers = new Documents.Collections.RequestNameValueCollection(); - headers.Add(HttpConstants.HttpHeaders.SupportedSerializationFormats, "Not a valid value"); - - try + INameValueCollection headers = new RequestNameValueCollection(); + if (sqlQuerySpec != null) { - this.QueryRequest(client, collection.ResourceId, sqlQuerySpec, headers); - Assert.Fail("Should throw an exception"); + if (!expectedResultIsBinary) + { + headers.Add(HttpConstants.HttpHeaders.ContentSerializationFormat, contentSerializationFormats); + headers.Add(HttpConstants.HttpHeaders.SupportedSerializationFormats, supportedSerializationFormats); + DocumentServiceResponse response = this.QueryRequest(client, collection.ResourceId, sqlQuerySpec, headers); + Assert.IsTrue(response.StatusCode == HttpStatusCode.OK, "Invalid status code"); + Assert.IsTrue(response.ResponseBody.ReadByte() < HeadersValidationTests.BinarySerializationByteMarkValue); + } + else + { + headers.Add(HttpConstants.HttpHeaders.ContentSerializationFormat, contentSerializationFormats); + headers.Add(HttpConstants.HttpHeaders.SupportedSerializationFormats, supportedSerializationFormats); + DocumentServiceResponse response = this.QueryRequest(client, collection.ResourceId, sqlQuerySpec, headers); + Assert.IsTrue(response.StatusCode == HttpStatusCode.OK, "Invalid status code"); + Assert.IsTrue(response.ResponseBody.ReadByte() == HeadersValidationTests.BinarySerializationByteMarkValue); + } } - catch (Exception ex) + else { - DocumentClientException innerException = ex.InnerException as DocumentClientException; - Assert.IsTrue(innerException.StatusCode == HttpStatusCode.BadRequest, "invalid status code"); + headers.Add(HttpConstants.HttpHeaders.SupportedSerializationFormats, supportedSerializationFormats); + DocumentServiceResponse response = this.ReadDocumentFeedRequestAsync(client, collection.ResourceId, headers).Result; + Assert.IsTrue(response.StatusCode == HttpStatusCode.OK, "Invalid status code"); + Assert.IsTrue(response.ResponseBody.ReadByte() < HeadersValidationTests.BinarySerializationByteMarkValue); } + } + private void ValidateSupportedSerializationFormatsReadFeed(DocumentClient client, DocumentCollection collection) + { + INameValueCollection headers = new RequestNameValueCollection(); + // Value not supported + this.SupportedSerializationFormatsNegativeCases(client, collection, "Invalid value", isQuery: false); // Supported values + this.SupportedSerializationFormatsPositiveCases(client, collection, expectedResultIsBinary: false, sqlQuerySpec: null, supportedSerializationFormats: "JSONText"); + this.SupportedSerializationFormatsPositiveCases(client, collection, expectedResultIsBinary: false, sqlQuerySpec: null, supportedSerializationFormats: "COSMOSbinary"); + this.SupportedSerializationFormatsPositiveCases(client, collection, expectedResultIsBinary: false, sqlQuerySpec: null, supportedSerializationFormats: "JsonText, CosmosBinary"); + } - // Text - headers = new Documents.Collections.RequestNameValueCollection(); - headers.Add(HttpConstants.HttpHeaders.SupportedSerializationFormats, "jsontext"); - DocumentServiceResponse response = this.QueryRequest(client, collection.ResourceId, sqlQuerySpec, headers); - Assert.IsTrue(response.StatusCode == HttpStatusCode.OK, "Invalid status code"); - Assert.IsTrue(response.ResponseBody.ReadByte() < HeadersValidationTests.BinarySerializationByteMarkValue); - - // None - headers = new Documents.Collections.RequestNameValueCollection(); - response = this.QueryRequest(client, collection.ResourceId, sqlQuerySpec, headers); - Assert.IsTrue(response.StatusCode == HttpStatusCode.OK, "Invalid status code"); - Assert.IsTrue(response.ResponseBody.ReadByte() < HeadersValidationTests.BinarySerializationByteMarkValue); - - // Binary - headers = new Documents.Collections.RequestNameValueCollection(); - headers.Add(HttpConstants.HttpHeaders.SupportedSerializationFormats, "COSMOSBINARY"); - response = this.QueryRequest(client, collection.ResourceId, sqlQuerySpec, headers); - Assert.IsTrue(response.StatusCode == HttpStatusCode.OK, "Invalid status code"); - Assert.IsTrue(response.ResponseBody.ReadByte() == HeadersValidationTests.BinarySerializationByteMarkValue); - - headers = new Documents.Collections.RequestNameValueCollection(); - headers.Add(HttpConstants.HttpHeaders.SupportedSerializationFormats, "JsonText, CosmosBinary"); - response = this.QueryRequest(client, collection.ResourceId, sqlQuerySpec, headers); - Assert.IsTrue(response.StatusCode == HttpStatusCode.OK, "Invalid status code"); - Assert.IsTrue(response.ResponseBody.ReadByte() < HeadersValidationTests.BinarySerializationByteMarkValue); - - headers = new Documents.Collections.RequestNameValueCollection(); - headers.Add(HttpConstants.HttpHeaders.SupportedSerializationFormats, "CosmosBinary, HybridRow"); - response = this.QueryRequest(client, collection.ResourceId, sqlQuerySpec, headers); - Assert.IsTrue(response.StatusCode == HttpStatusCode.OK, "Invalid status code"); - Assert.IsTrue(response.ResponseBody.ReadByte() == HeadersValidationTests.BinarySerializationByteMarkValue); - - headers = new Documents.Collections.RequestNameValueCollection(); - headers.Add(HttpConstants.HttpHeaders.SupportedSerializationFormats, "JsonText, CosmosBinary, HybridRow"); - response = this.QueryRequest(client, collection.ResourceId, sqlQuerySpec, headers); - Assert.IsTrue(response.StatusCode == HttpStatusCode.OK, "Invalid status code"); - Assert.IsTrue(response.ResponseBody.ReadByte() < HeadersValidationTests.BinarySerializationByteMarkValue); - - headers = new Documents.Collections.RequestNameValueCollection(); - headers.Add(HttpConstants.HttpHeaders.ContentSerializationFormat, "CosmosBinary"); - headers.Add(HttpConstants.HttpHeaders.SupportedSerializationFormats, "JsonText, CosmosBinary, HybridRow"); - response = this.QueryRequest(client, collection.ResourceId, sqlQuerySpec, headers); - Assert.IsTrue(response.StatusCode == HttpStatusCode.OK, "Invalid status code"); - Assert.IsTrue(response.ResponseBody.ReadByte() == HeadersValidationTests.BinarySerializationByteMarkValue); + private void ValidateSupportedSerializationFormatsQuery(DocumentClient client, DocumentCollection collection) + { + SqlQuerySpec sqlQuerySpec = new SqlQuerySpec("SELECT * FROM c"); + INameValueCollection headers = new RequestNameValueCollection(); + // Values not supported + this.SupportedSerializationFormatsNegativeCases(client, collection, "Invalid value"); - headers = new Documents.Collections.RequestNameValueCollection(); - headers.Add(HttpConstants.HttpHeaders.ContentSerializationFormat, "JsonText"); - headers.Add(HttpConstants.HttpHeaders.SupportedSerializationFormats, "JsonText, CosmosBinary, HybridRow"); - response = this.QueryRequest(client, collection.ResourceId, sqlQuerySpec, headers); - Assert.IsTrue(response.StatusCode == HttpStatusCode.OK, "Invalid status code"); - Assert.IsTrue(response.ResponseBody.ReadByte() < HeadersValidationTests.BinarySerializationByteMarkValue); + // Supported values + this.SupportedSerializationFormatsPositiveCases(client, collection, + expectedResultIsBinary: false, + sqlQuerySpec: sqlQuerySpec, + supportedSerializationFormats: "jsontext"); + this.SupportedSerializationFormatsPositiveCases(client, collection, + expectedResultIsBinary: true, + sqlQuerySpec: sqlQuerySpec, + supportedSerializationFormats: "COSMOSBINARY"); + this.SupportedSerializationFormatsPositiveCases(client, collection, + expectedResultIsBinary: false, + sqlQuerySpec: sqlQuerySpec, + supportedSerializationFormats: "JsonText, CosmosBinary"); + this.SupportedSerializationFormatsPositiveCases(client, collection, + expectedResultIsBinary: true, + sqlQuerySpec: sqlQuerySpec, + supportedSerializationFormats: "CosmosBinary, HybridRow"); + this.SupportedSerializationFormatsPositiveCases(client, collection, + expectedResultIsBinary: false, + sqlQuerySpec: sqlQuerySpec, + supportedSerializationFormats: "JsonText, CosmosBinary, HybridRow"); + this.SupportedSerializationFormatsPositiveCases(client, collection, + expectedResultIsBinary: true, + sqlQuerySpec: sqlQuerySpec, + supportedSerializationFormats: "JsonText, CosmosBinary, HybridRow", + contentSerializationFormats: "CosmosBinary"); + this.SupportedSerializationFormatsPositiveCases(client, collection, + expectedResultIsBinary: false, + sqlQuerySpec: sqlQuerySpec, + supportedSerializationFormats: "JsonText, CosmosBinary, HybridRow", + contentSerializationFormats: "JsonText"); } [TestMethod] diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/QueryPerfTest/ContentSerializationPerformanceTests.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/QueryPerfTest/ContentSerializationPerformanceTests.cs index 0b0929978f..c18ac5e420 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/QueryPerfTest/ContentSerializationPerformanceTests.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/QueryPerfTest/ContentSerializationPerformanceTests.cs @@ -85,7 +85,6 @@ private async Task RunQueryAsync(Container container) MaxItemCount = this.MaxItemCount, CosmosSerializationFormatOptions = new CosmosSerializationFormatOptions( contentSerializationFormat: this.contentSerialization, - supportedSerializationFormats: "", createCustomNavigator: (content) => JsonNavigator.Create(content), createCustomWriter: () => JsonWriter.Create(this.contentSerialization == "JsonText" ? JsonSerializationFormat.Text : JsonSerializationFormat.Binary)) }; diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Performance.Tests/Query/EndToEnd.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Performance.Tests/Query/EndToEnd.cs index c2677fdb86..24cb907be8 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Performance.Tests/Query/EndToEnd.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Performance.Tests/Query/EndToEnd.cs @@ -219,7 +219,6 @@ private static void SetSerializationFormat( CosmosSerializationFormatOptions formatOptions = new CosmosSerializationFormatOptions( contentSerializationFormat, - "", (content) => JsonNavigator.Create(content), () => JsonWriter.Create(JsonSerializationFormat.Text)); diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/BinaryEncodingOverTheWireTests.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/BinaryEncodingOverTheWireTests.cs index 55a0cb5bf0..b55e837844 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/BinaryEncodingOverTheWireTests.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/BinaryEncodingOverTheWireTests.cs @@ -250,7 +250,6 @@ async Task AssertQueryDrainsCorrectlyAsync(FeedIterator feedIterator) { CosmosSerializationFormatOptions = new CosmosSerializationFormatOptions( "JsonText", - "", (content) => JsonNavigator.Create(content), () => Cosmos.Json.JsonWriter.Create(JsonSerializationFormat.Text)), }); @@ -263,7 +262,6 @@ async Task AssertQueryDrainsCorrectlyAsync(FeedIterator feedIterator) { CosmosSerializationFormatOptions = new CosmosSerializationFormatOptions( "CosmosBinary", - "", (content) => JsonNavigator.Create(content), () => Cosmos.Json.JsonWriter.Create(JsonSerializationFormat.Text)), }); diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Query/ContinuationTokens/OrderByQueryResultTests.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Query/ContinuationTokens/OrderByQueryResultTests.cs index fbee8dcaf6..86093aa296 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Query/ContinuationTokens/OrderByQueryResultTests.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Query/ContinuationTokens/OrderByQueryResultTests.cs @@ -34,7 +34,6 @@ public void TestOrderByUndefined() Documents.ResourceType.Document, new CosmosSerializationFormatOptions( "JsonText", - "", (content) => JsonNavigator.Create(content), () => JsonWriter.Create(JsonSerializationFormat.Text))); From 78be9f154e5afd5a1daec98de31c4cdbd5a99ef6 Mon Sep 17 00:00:00 2001 From: Heet Date: Mon, 23 Jan 2023 13:31:43 -0800 Subject: [PATCH 06/32] Added more negative cases --- .../HeadersValidationTests.cs | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/HeadersValidationTests.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/HeadersValidationTests.cs index acc082586f..e00b6ff9b5 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/HeadersValidationTests.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/HeadersValidationTests.cs @@ -356,12 +356,16 @@ private void ValidateSupportedSerializationFormats(DocumentClient client) this.ValidateSupportedSerializationFormatsQuery(client, collection); } - private void SupportedSerializationFormatsNegativeCases(DocumentClient client, DocumentCollection collection, string value, bool isQuery = true, SqlQuerySpec sqlQuerySpec = null) + private void SupportedSerializationFormatsNegativeCases( + DocumentClient client, + DocumentCollection collection, + string value, + SqlQuerySpec sqlQuerySpec) { INameValueCollection headers = new RequestNameValueCollection(); headers.Add(HttpConstants.HttpHeaders.SupportedSerializationFormats, value); - if (isQuery) + if (sqlQuerySpec != null) { try { @@ -429,7 +433,7 @@ private void ValidateSupportedSerializationFormatsReadFeed(DocumentClient client { INameValueCollection headers = new RequestNameValueCollection(); // Value not supported - this.SupportedSerializationFormatsNegativeCases(client, collection, "Invalid value", isQuery: false); + this.SupportedSerializationFormatsNegativeCases(client, collection, "Invalid value", sqlQuerySpec: null); // Supported values this.SupportedSerializationFormatsPositiveCases(client, collection, expectedResultIsBinary: false, sqlQuerySpec: null, supportedSerializationFormats: "JSONText"); @@ -442,7 +446,14 @@ private void ValidateSupportedSerializationFormatsQuery(DocumentClient client, D SqlQuerySpec sqlQuerySpec = new SqlQuerySpec("SELECT * FROM c"); INameValueCollection headers = new RequestNameValueCollection(); // Values not supported - this.SupportedSerializationFormatsNegativeCases(client, collection, "Invalid value"); + this.SupportedSerializationFormatsNegativeCases(client, collection, "Invalid value", sqlQuerySpec:sqlQuerySpec); + this.SupportedSerializationFormatsNegativeCases(client, collection, ", ,", sqlQuerySpec: sqlQuerySpec); + this.SupportedSerializationFormatsNegativeCases(client, collection, ",,", sqlQuerySpec: sqlQuerySpec); + this.SupportedSerializationFormatsNegativeCases(client, collection, "JsonText CosmosBinary", sqlQuerySpec: sqlQuerySpec); + this.SupportedSerializationFormatsNegativeCases(client, collection, ",JsonText|CosmosBinary", sqlQuerySpec: sqlQuerySpec); + this.SupportedSerializationFormatsNegativeCases(client, collection, "Json Text", sqlQuerySpec: sqlQuerySpec); + this.SupportedSerializationFormatsNegativeCases(client, collection, "Json,Text", sqlQuerySpec: sqlQuerySpec); + this.SupportedSerializationFormatsNegativeCases(client, collection, "JsonText, ", sqlQuerySpec: sqlQuerySpec); // Supported values this.SupportedSerializationFormatsPositiveCases(client, collection, From f48768989db55ddf024ef2c1eabda85c40eca17e Mon Sep 17 00:00:00 2001 From: Heet Date: Mon, 23 Jan 2023 13:34:50 -0800 Subject: [PATCH 07/32] Revert changes --- .../Microsoft.Azure.Cosmos.EmulatorTests/CosmosItemTests.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/CosmosItemTests.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/CosmosItemTests.cs index ccac6111a9..8c00938cdb 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/CosmosItemTests.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/CosmosItemTests.cs @@ -837,7 +837,7 @@ public async Task PartitionKeyDeleteTestForSubpartitionedContainer() finally { HttpConstants.Versions.CurrentVersion = currentVersion; - if (database != null) await database.DeleteAsync(); + if(database != null) await database.DeleteAsync(); } } @@ -966,7 +966,7 @@ public async Task ItemCustomSerialzierTest() // Each parameter in query spec should be a call to the custom serializer int parameterCount = queryDefinition.ToSqlQuerySpec().Parameters.Count; - Assert.AreEqual((parameterCount * pageCount) + parameterCount, toStreamCount, $"missing to stream call. Expected: {(parameterCount * pageCount) + parameterCount}, Actual: {toStreamCount} for query:{queryDefinition.ToSqlQuerySpec().QueryText}"); + Assert.AreEqual((parameterCount*pageCount)+parameterCount, toStreamCount, $"missing to stream call. Expected: {(parameterCount * pageCount) + parameterCount}, Actual: {toStreamCount} for query:{queryDefinition.ToSqlQuerySpec().QueryText}"); Assert.AreEqual(pageCount, fromStreamCount); } } @@ -1339,7 +1339,7 @@ public async Task ItemMultiplePartitionQuery() { FeedResponse iter = await feedIterator.ReadNextAsync(); Assert.IsTrue(iter.Count() <= 1); - if (iter.Count() == 1) + if(iter.Count() == 1) { found = true; ToDoActivity response = iter.First(); From ff2c2e46690bbdf932e6694bf64d5e21dd3d8a3b Mon Sep 17 00:00:00 2001 From: Heet Date: Mon, 23 Jan 2023 13:37:18 -0800 Subject: [PATCH 08/32] Added spaces --- Microsoft.Azure.Cosmos/src/Headers/Headers.cs | 1 + Microsoft.Azure.Cosmos/src/RequestOptions/QueryRequestOptions.cs | 1 + 2 files changed, 2 insertions(+) diff --git a/Microsoft.Azure.Cosmos/src/Headers/Headers.cs b/Microsoft.Azure.Cosmos/src/Headers/Headers.cs index e9eac1c180..8b4dfd8de7 100644 --- a/Microsoft.Azure.Cosmos/src/Headers/Headers.cs +++ b/Microsoft.Azure.Cosmos/src/Headers/Headers.cs @@ -18,6 +18,7 @@ namespace Microsoft.Azure.Cosmos /// public class Headers : IEnumerable { + internal static readonly string defaultSupportedSerializationFormats = "JsonText, CosmosBinary"; internal static readonly string SDKSUPPORTEDCAPABILITIES = SDKSupportedCapabilitiesHelpers.GetSDKSupportedCapabilities().ToString( CultureInfo.InvariantCulture); diff --git a/Microsoft.Azure.Cosmos/src/RequestOptions/QueryRequestOptions.cs b/Microsoft.Azure.Cosmos/src/RequestOptions/QueryRequestOptions.cs index 164f5799e5..391aff5320 100644 --- a/Microsoft.Azure.Cosmos/src/RequestOptions/QueryRequestOptions.cs +++ b/Microsoft.Azure.Cosmos/src/RequestOptions/QueryRequestOptions.cs @@ -171,6 +171,7 @@ public ConsistencyLevel? ConsistencyLevel internal EnumerationDirection? EnumerationDirection { get; set; } internal CosmosSerializationFormatOptions CosmosSerializationFormatOptions { get; set; } + internal SupportedSerializationFormats? SupportedSerializationFormats { get; set; } internal ExecutionEnvironment? ExecutionEnvironment { get; set; } From a379d0d82afaa6e02f835503f06ad78867f64d72 Mon Sep 17 00:00:00 2001 From: Heet Date: Mon, 30 Jan 2023 14:39:07 -0800 Subject: [PATCH 09/32] Addressed comments --- Microsoft.Azure.Cosmos/src/Headers/Headers.cs | 2 +- .../DocumentQueryExecutionContextBase.cs | 2 +- .../src/RequestOptions/QueryRequestOptions.cs | 2 +- .../HeadersValidationTests.cs | 120 ++++++++---------- .../SupportedSerializationFormatsTest.cs | 50 ++++++++ 5 files changed, 109 insertions(+), 67 deletions(-) create mode 100644 Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/Query/SupportedSerializationFormatsTest.cs diff --git a/Microsoft.Azure.Cosmos/src/Headers/Headers.cs b/Microsoft.Azure.Cosmos/src/Headers/Headers.cs index 8b4dfd8de7..c2ae530a3d 100644 --- a/Microsoft.Azure.Cosmos/src/Headers/Headers.cs +++ b/Microsoft.Azure.Cosmos/src/Headers/Headers.cs @@ -18,7 +18,7 @@ namespace Microsoft.Azure.Cosmos /// public class Headers : IEnumerable { - internal static readonly string defaultSupportedSerializationFormats = "JsonText, CosmosBinary"; + internal const string DefaultSupportedSerializationFormats = "JsonText, CosmosBinary"; internal static readonly string SDKSUPPORTEDCAPABILITIES = SDKSupportedCapabilitiesHelpers.GetSDKSupportedCapabilities().ToString( CultureInfo.InvariantCulture); diff --git a/Microsoft.Azure.Cosmos/src/Query/v2Query/DocumentQueryExecutionContextBase.cs b/Microsoft.Azure.Cosmos/src/Query/v2Query/DocumentQueryExecutionContextBase.cs index 4151590d58..6ae6d98d3b 100644 --- a/Microsoft.Azure.Cosmos/src/Query/v2Query/DocumentQueryExecutionContextBase.cs +++ b/Microsoft.Azure.Cosmos/src/Query/v2Query/DocumentQueryExecutionContextBase.cs @@ -341,7 +341,7 @@ await this.Client.EnsureValidOverwriteAsync( } else { - requestHeaders[HttpConstants.HttpHeaders.SupportedSerializationFormats] = Headers.defaultSupportedSerializationFormats; + requestHeaders[HttpConstants.HttpHeaders.SupportedSerializationFormats] = Headers.DefaultSupportedSerializationFormats; } return requestHeaders; diff --git a/Microsoft.Azure.Cosmos/src/RequestOptions/QueryRequestOptions.cs b/Microsoft.Azure.Cosmos/src/RequestOptions/QueryRequestOptions.cs index 391aff5320..73140e1deb 100644 --- a/Microsoft.Azure.Cosmos/src/RequestOptions/QueryRequestOptions.cs +++ b/Microsoft.Azure.Cosmos/src/RequestOptions/QueryRequestOptions.cs @@ -238,7 +238,7 @@ internal override void PopulateRequestOptions(RequestMessage request) } else { - request.Headers.CosmosMessageHeaders.SupportedSerializationFormats = Headers.defaultSupportedSerializationFormats; + request.Headers.CosmosMessageHeaders.SupportedSerializationFormats = Headers.DefaultSupportedSerializationFormats; } if (this.StartId != null) diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/HeadersValidationTests.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/HeadersValidationTests.cs index e00b6ff9b5..ce6b4d7019 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/HeadersValidationTests.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/HeadersValidationTests.cs @@ -353,43 +353,41 @@ private void ValidateSupportedSerializationFormats(DocumentClient client) { DocumentCollection collection = TestCommon.CreateOrGetDocumentCollection(client); this.ValidateSupportedSerializationFormatsReadFeed(client, collection); - this.ValidateSupportedSerializationFormatsQuery(client, collection); + + SqlQuerySpec sqlQuerySelectStar = new SqlQuerySpec("SELECT * FROM c"); + SqlQuerySpec sqlQueryOrderBy = new SqlQuerySpec("SELECT c.id FROM c ORDER BY c.partitionKey"); + SqlQuerySpec sqlQueryGroupBy = new SqlQuerySpec("SELECT c.name FROM c GROUP BY c.name"); + this.ValidateSupportedSerializationFormatsQuery(client, collection, sqlQuerySelectStar); + this.ValidateSupportedSerializationFormatsQuery(client, collection, sqlQueryOrderBy); + this.ValidateSupportedSerializationFormatsQuery(client, collection, sqlQueryGroupBy); } private void SupportedSerializationFormatsNegativeCases( DocumentClient client, DocumentCollection collection, string value, - SqlQuerySpec sqlQuerySpec) + SqlQuerySpec sqlQuerySpec = null) { INameValueCollection headers = new RequestNameValueCollection(); headers.Add(HttpConstants.HttpHeaders.SupportedSerializationFormats, value); - if (sqlQuerySpec != null) + try { - try + if (sqlQuerySpec != null) { this.QueryRequest(client, collection.ResourceId, sqlQuerySpec, headers); - Assert.Fail("Should throw an exception"); } - catch (Exception ex) + else { - DocumentClientException innerException = ex.InnerException as DocumentClientException; - Assert.IsTrue(innerException.StatusCode == HttpStatusCode.BadRequest, "invalid status code"); + this.ReadDocumentFeedRequestSinglePartition(client, collection.ResourceId, headers); } + + Assert.Fail("Should throw an exception"); } - else + catch (Exception ex) { - try - { - this.ReadDocumentFeedRequestSinglePartition(client, collection.ResourceId, headers); - Assert.Fail("Should throw an exception"); - } - catch (Exception ex) - { - DocumentClientException innerException = ex.InnerException as DocumentClientException; - Assert.IsTrue(innerException.StatusCode == HttpStatusCode.BadRequest, "invalid status code"); - } + DocumentClientException innerException = ex.InnerException as DocumentClientException; + Assert.IsTrue(innerException.StatusCode == HttpStatusCode.BadRequest, "invalid status code"); } } @@ -397,54 +395,43 @@ private void SupportedSerializationFormatsPositiveCases( DocumentClient client, DocumentCollection collection, bool expectedResultIsBinary, - SqlQuerySpec sqlQuerySpec, string supportedSerializationFormats, - string contentSerializationFormats = "") + string contentSerializationFormats, + SqlQuerySpec sqlQuerySpec = null) { INameValueCollection headers = new RequestNameValueCollection(); - if (sqlQuerySpec != null) + if(contentSerializationFormats!=null) { - if (!expectedResultIsBinary) - { - headers.Add(HttpConstants.HttpHeaders.ContentSerializationFormat, contentSerializationFormats); - headers.Add(HttpConstants.HttpHeaders.SupportedSerializationFormats, supportedSerializationFormats); - DocumentServiceResponse response = this.QueryRequest(client, collection.ResourceId, sqlQuerySpec, headers); - Assert.IsTrue(response.StatusCode == HttpStatusCode.OK, "Invalid status code"); - Assert.IsTrue(response.ResponseBody.ReadByte() < HeadersValidationTests.BinarySerializationByteMarkValue); - } - else - { - headers.Add(HttpConstants.HttpHeaders.ContentSerializationFormat, contentSerializationFormats); - headers.Add(HttpConstants.HttpHeaders.SupportedSerializationFormats, supportedSerializationFormats); - DocumentServiceResponse response = this.QueryRequest(client, collection.ResourceId, sqlQuerySpec, headers); - Assert.IsTrue(response.StatusCode == HttpStatusCode.OK, "Invalid status code"); - Assert.IsTrue(response.ResponseBody.ReadByte() == HeadersValidationTests.BinarySerializationByteMarkValue); - } + headers.Add(HttpConstants.HttpHeaders.ContentSerializationFormat, contentSerializationFormats); + } + headers.Add(HttpConstants.HttpHeaders.SupportedSerializationFormats, supportedSerializationFormats); + DocumentServiceResponse response = sqlQuerySpec != null ? this.QueryRequest(client, collection.ResourceId, sqlQuerySpec, headers) : + this.ReadDocumentFeedRequestAsync(client, collection.ResourceId, headers).Result; + Assert.IsTrue(response.StatusCode == HttpStatusCode.OK, "Invalid status code"); + + if(!expectedResultIsBinary) + { + Assert.IsTrue(response.ResponseBody.ReadByte() < BinarySerializationByteMarkValue); } else { - headers.Add(HttpConstants.HttpHeaders.SupportedSerializationFormats, supportedSerializationFormats); - DocumentServiceResponse response = this.ReadDocumentFeedRequestAsync(client, collection.ResourceId, headers).Result; - Assert.IsTrue(response.StatusCode == HttpStatusCode.OK, "Invalid status code"); - Assert.IsTrue(response.ResponseBody.ReadByte() < HeadersValidationTests.BinarySerializationByteMarkValue); + Assert.IsTrue(response.ResponseBody.ReadByte() == BinarySerializationByteMarkValue); } + } private void ValidateSupportedSerializationFormatsReadFeed(DocumentClient client, DocumentCollection collection) { - INameValueCollection headers = new RequestNameValueCollection(); // Value not supported - this.SupportedSerializationFormatsNegativeCases(client, collection, "Invalid value", sqlQuerySpec: null); + this.SupportedSerializationFormatsNegativeCases(client, collection, "Invalid value"); // Supported values - this.SupportedSerializationFormatsPositiveCases(client, collection, expectedResultIsBinary: false, sqlQuerySpec: null, supportedSerializationFormats: "JSONText"); - this.SupportedSerializationFormatsPositiveCases(client, collection, expectedResultIsBinary: false, sqlQuerySpec: null, supportedSerializationFormats: "COSMOSbinary"); - this.SupportedSerializationFormatsPositiveCases(client, collection, expectedResultIsBinary: false, sqlQuerySpec: null, supportedSerializationFormats: "JsonText, CosmosBinary"); + this.SupportedSerializationFormatsPositiveCases(client, collection, expectedResultIsBinary: false, supportedSerializationFormats: "JSONText", contentSerializationFormats: null); + this.SupportedSerializationFormatsPositiveCases(client, collection, expectedResultIsBinary: false, supportedSerializationFormats: "COSMOSbinary", contentSerializationFormats: null); + this.SupportedSerializationFormatsPositiveCases(client, collection, expectedResultIsBinary: false, supportedSerializationFormats: "JsonText, CosmosBinary", contentSerializationFormats: null); } - private void ValidateSupportedSerializationFormatsQuery(DocumentClient client, DocumentCollection collection) + private void ValidateSupportedSerializationFormatsQuery(DocumentClient client, DocumentCollection collection, SqlQuerySpec sqlQuerySpec) { - SqlQuerySpec sqlQuerySpec = new SqlQuerySpec("SELECT * FROM c"); - INameValueCollection headers = new RequestNameValueCollection(); // Values not supported this.SupportedSerializationFormatsNegativeCases(client, collection, "Invalid value", sqlQuerySpec:sqlQuerySpec); this.SupportedSerializationFormatsNegativeCases(client, collection, ", ,", sqlQuerySpec: sqlQuerySpec); @@ -458,34 +445,39 @@ private void ValidateSupportedSerializationFormatsQuery(DocumentClient client, D // Supported values this.SupportedSerializationFormatsPositiveCases(client, collection, expectedResultIsBinary: false, - sqlQuerySpec: sqlQuerySpec, - supportedSerializationFormats: "jsontext"); + supportedSerializationFormats: "jsontext", + contentSerializationFormats: null, + sqlQuerySpec: sqlQuerySpec); this.SupportedSerializationFormatsPositiveCases(client, collection, expectedResultIsBinary: true, - sqlQuerySpec: sqlQuerySpec, - supportedSerializationFormats: "COSMOSBINARY"); + supportedSerializationFormats: "COSMOSBINARY", + contentSerializationFormats: null, + sqlQuerySpec: sqlQuerySpec); this.SupportedSerializationFormatsPositiveCases(client, collection, expectedResultIsBinary: false, - sqlQuerySpec: sqlQuerySpec, - supportedSerializationFormats: "JsonText, CosmosBinary"); + supportedSerializationFormats: "JsonText, CosmosBinary", + contentSerializationFormats: null, + sqlQuerySpec: sqlQuerySpec); this.SupportedSerializationFormatsPositiveCases(client, collection, expectedResultIsBinary: true, - sqlQuerySpec: sqlQuerySpec, - supportedSerializationFormats: "CosmosBinary, HybridRow"); + supportedSerializationFormats: "CosmosBinary, HybridRow", + contentSerializationFormats: null, + sqlQuerySpec: sqlQuerySpec); this.SupportedSerializationFormatsPositiveCases(client, collection, expectedResultIsBinary: false, - sqlQuerySpec: sqlQuerySpec, - supportedSerializationFormats: "JsonText, CosmosBinary, HybridRow"); + supportedSerializationFormats: "JsonText, CosmosBinary, HybridRow", + contentSerializationFormats: null, + sqlQuerySpec: sqlQuerySpec); this.SupportedSerializationFormatsPositiveCases(client, collection, expectedResultIsBinary: true, - sqlQuerySpec: sqlQuerySpec, supportedSerializationFormats: "JsonText, CosmosBinary, HybridRow", - contentSerializationFormats: "CosmosBinary"); + contentSerializationFormats: "CosmosBinary", + sqlQuerySpec: sqlQuerySpec); this.SupportedSerializationFormatsPositiveCases(client, collection, expectedResultIsBinary: false, - sqlQuerySpec: sqlQuerySpec, supportedSerializationFormats: "JsonText, CosmosBinary, HybridRow", - contentSerializationFormats: "JsonText"); + contentSerializationFormats: "JsonText", + sqlQuerySpec: sqlQuerySpec); } [TestMethod] diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/Query/SupportedSerializationFormatsTest.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/Query/SupportedSerializationFormatsTest.cs new file mode 100644 index 0000000000..9a701bdd17 --- /dev/null +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/Query/SupportedSerializationFormatsTest.cs @@ -0,0 +1,50 @@ +namespace Microsoft.Azure.Cosmos.Query +{ + using System; + using System.Collections.Generic; + using System.Threading.Tasks; + using Microsoft.Azure.Cosmos.CosmosElements; + using Microsoft.Azure.Cosmos.EmulatorTests.Query; + using Microsoft.Azure.Cosmos.SDK.EmulatorTests.QueryOracle; + using Microsoft.VisualStudio.TestTools.UnitTesting; + + [TestClass] + [TestCategory("Query")] + public sealed class SupportedSerializationFormatsTest : QueryTestsBase + { + [TestMethod] + public async Task TestSupportedSerializationFormats() + { + int seed = (int)(DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalSeconds; + uint numberOfDocuments = 1; + QueryOracleUtil util = new QueryOracle2(seed); + IEnumerable inputDocuments = util.GetDocuments(numberOfDocuments); + + await this.CreateIngestQueryDeleteAsync( + ConnectionModes.Direct, + CollectionTypes.SinglePartition | CollectionTypes.MultiPartition, + inputDocuments, + ImplementationAsync, + "/id"); + + static async Task ImplementationAsync(Container container, IReadOnlyList documents) + { + string query = string.Format("SELECT * FROM c"); + + QueryRequestOptions requestOptions = new QueryRequestOptions + { + SupportedSerializationFormats = Documents.SupportedSerializationFormats.JsonText | Documents.SupportedSerializationFormats.CosmosBinary + }; + + FeedIterator feedIterator = container.GetItemQueryIterator( + query, + requestOptions: requestOptions); + + while (feedIterator.HasMoreResults) + { + FeedResponse page = await feedIterator.ReadNextAsync(); + } + } + } + } +} From c88af8fdad9c50ac25d8b8a571bd8d29f4191f5c Mon Sep 17 00:00:00 2001 From: Heet Date: Tue, 31 Jan 2023 11:37:09 -0800 Subject: [PATCH 10/32] Addressed comments --- .../SupportedSerializationFormatsTest.cs | 2 +- .../Query/FeedOptionTests.cs | 22 +++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/Query/SupportedSerializationFormatsTest.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/Query/SupportedSerializationFormatsTest.cs index 9a701bdd17..369a1240c1 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/Query/SupportedSerializationFormatsTest.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/Query/SupportedSerializationFormatsTest.cs @@ -33,7 +33,7 @@ static async Task ImplementationAsync(Container container, IReadOnlyList feedIterator = container.GetItemQueryIterator( diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Query/FeedOptionTests.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Query/FeedOptionTests.cs index 54c965cce8..51e0e8ec3c 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Query/FeedOptionTests.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Query/FeedOptionTests.cs @@ -50,6 +50,28 @@ public void TestCopyConstructor() _ = new FeedOptions(fo); } + [TestMethod] + public async Task TestSupportedSerializationFormatsAsync() + { + FeedOptions fo = new FeedOptions(); + Mock dcClient = new Mock(); + Expression> randomFunc = x => x * 2; + + TestQueryExecutionContext cxt = new TestQueryExecutionContext( + dcClient.Object, + ResourceType.Document, + typeof(TestQueryExecutionContext), + randomFunc, + fo, + string.Empty, + true, Guid.NewGuid()); + INameValueCollection headers = await cxt.CreateCommonHeadersAsync(fo); + Assert.AreEqual("JsonText, CosmosBinary", headers[HttpConstants.HttpHeaders.SupportedSerializationFormats]); + + fo.SupportedSerializationFormats = SupportedSerializationFormats.CosmosBinary | SupportedSerializationFormats.HybridRow; + headers = await cxt.CreateCommonHeadersAsync(fo); + Assert.AreEqual("CosmosBinary, HybridRow", headers[HttpConstants.HttpHeaders.SupportedSerializationFormats]); + } internal class TestQueryExecutionContext : DocumentQueryExecutionContextBase { public TestQueryExecutionContext( From 70a55bff57c995f85ca1f15d296b06ddee78d72c Mon Sep 17 00:00:00 2001 From: Heet Date: Wed, 1 Feb 2023 10:47:23 -0800 Subject: [PATCH 11/32] Removed SupportedSerializationFormats from Headers file --- Microsoft.Azure.Cosmos/src/Headers/Headers.cs | 6 ------ 1 file changed, 6 deletions(-) diff --git a/Microsoft.Azure.Cosmos/src/Headers/Headers.cs b/Microsoft.Azure.Cosmos/src/Headers/Headers.cs index c2ae530a3d..79385f1e9c 100644 --- a/Microsoft.Azure.Cosmos/src/Headers/Headers.cs +++ b/Microsoft.Azure.Cosmos/src/Headers/Headers.cs @@ -229,12 +229,6 @@ internal virtual string ContentSerializationFormat set => this.CosmosMessageHeaders.ContentSerializationFormat = value; } - internal virtual string Supportedserializationformats - { - get => this.CosmosMessageHeaders.SupportedSerializationFormats; - set => this.CosmosMessageHeaders.SupportedSerializationFormats = value; - } - internal virtual string ReadFeedKeyType { get => this.CosmosMessageHeaders.ReadFeedKeyType; From 7ecbb0da4bc6e567a7763e373af95b9e05600867 Mon Sep 17 00:00:00 2001 From: Heet Date: Wed, 1 Feb 2023 11:07:40 -0800 Subject: [PATCH 12/32] Removed unused JsonSerilazationFormats option --- .../src/ChangeFeed/Pagination/ChangeFeedPaginationOptions.cs | 5 ++++- .../src/Pagination/NetworkAttachedDocumentContainer.cs | 5 ----- Microsoft.Azure.Cosmos/src/Pagination/PaginationOptions.cs | 4 ---- .../Query/Core/Pipeline/Pagination/QueryPaginationOptions.cs | 3 +-- .../src/ReadFeed/Pagination/ReadFeedPaginationOptions.cs | 3 +-- 5 files changed, 6 insertions(+), 14 deletions(-) diff --git a/Microsoft.Azure.Cosmos/src/ChangeFeed/Pagination/ChangeFeedPaginationOptions.cs b/Microsoft.Azure.Cosmos/src/ChangeFeed/Pagination/ChangeFeedPaginationOptions.cs index 8579c6de42..de11129e1b 100644 --- a/Microsoft.Azure.Cosmos/src/ChangeFeed/Pagination/ChangeFeedPaginationOptions.cs +++ b/Microsoft.Azure.Cosmos/src/ChangeFeed/Pagination/ChangeFeedPaginationOptions.cs @@ -33,10 +33,11 @@ public ChangeFeedPaginationOptions( JsonSerializationFormat? jsonSerializationFormat = null, Dictionary additionalHeaders = null, ChangeFeedQuerySpec changeFeedQuerySpec = null) - : base(pageSizeHint, jsonSerializationFormat, additionalHeaders) + : base(pageSizeHint, additionalHeaders) { this.Mode = mode ?? throw new ArgumentNullException(nameof(mode)); this.ChangeFeedQuerySpec = changeFeedQuerySpec; + this.JsonSerializationFormat = jsonSerializationFormat; } public ChangeFeedMode Mode { get; } @@ -44,5 +45,7 @@ public ChangeFeedPaginationOptions( public ChangeFeedQuerySpec ChangeFeedQuerySpec { get; } protected override ImmutableHashSet BannedAdditionalHeaders => BannedHeaders; + + public JsonSerializationFormat? JsonSerializationFormat { get; } } } diff --git a/Microsoft.Azure.Cosmos/src/Pagination/NetworkAttachedDocumentContainer.cs b/Microsoft.Azure.Cosmos/src/Pagination/NetworkAttachedDocumentContainer.cs index 1132a40a35..154442cc95 100644 --- a/Microsoft.Azure.Cosmos/src/Pagination/NetworkAttachedDocumentContainer.cs +++ b/Microsoft.Azure.Cosmos/src/Pagination/NetworkAttachedDocumentContainer.cs @@ -192,11 +192,6 @@ public async Task> MonadicReadFeedAsync( request.Headers.ContinuationToken = ((CosmosString)readFeedContinuationState.ContinuationToken).Value; } - if (readFeedPaginationOptions.JsonSerializationFormat.HasValue) - { - request.Headers.ContentSerializationFormat = readFeedPaginationOptions.JsonSerializationFormat.Value.ToContentSerializationFormatString(); - } - foreach (KeyValuePair kvp in readFeedPaginationOptions.AdditionalHeaders) { request.Headers[kvp.Key] = kvp.Value; diff --git a/Microsoft.Azure.Cosmos/src/Pagination/PaginationOptions.cs b/Microsoft.Azure.Cosmos/src/Pagination/PaginationOptions.cs index 5558f2be24..593d761ec0 100644 --- a/Microsoft.Azure.Cosmos/src/Pagination/PaginationOptions.cs +++ b/Microsoft.Azure.Cosmos/src/Pagination/PaginationOptions.cs @@ -23,11 +23,9 @@ internal abstract class PaginationOptions protected PaginationOptions( int? pageSizeLimit = null, - JsonSerializationFormat? jsonSerializationFormat = null, Dictionary additionalHeaders = null) { this.PageSizeLimit = pageSizeLimit; - this.JsonSerializationFormat = jsonSerializationFormat; this.AdditionalHeaders = additionalHeaders != null ? additionalHeaders.ToImmutableDictionary() : EmptyDictionary; foreach (string key in this.AdditionalHeaders.Keys) @@ -41,8 +39,6 @@ protected PaginationOptions( public int? PageSizeLimit { get; } - public JsonSerializationFormat? JsonSerializationFormat { get; } - public ImmutableDictionary AdditionalHeaders { get; } protected abstract ImmutableHashSet BannedAdditionalHeaders { get; } diff --git a/Microsoft.Azure.Cosmos/src/Query/Core/Pipeline/Pagination/QueryPaginationOptions.cs b/Microsoft.Azure.Cosmos/src/Query/Core/Pipeline/Pagination/QueryPaginationOptions.cs index 0b692160be..eb830a3b8f 100644 --- a/Microsoft.Azure.Cosmos/src/Query/Core/Pipeline/Pagination/QueryPaginationOptions.cs +++ b/Microsoft.Azure.Cosmos/src/Query/Core/Pipeline/Pagination/QueryPaginationOptions.cs @@ -29,9 +29,8 @@ internal sealed class QueryPaginationOptions : PaginationOptions public QueryPaginationOptions( int? pageSizeHint = null, - JsonSerializationFormat? jsonSerializationFormat = null, Dictionary additionalHeaders = null) - : base(pageSizeHint, jsonSerializationFormat, additionalHeaders) + : base(pageSizeHint, additionalHeaders) { } diff --git a/Microsoft.Azure.Cosmos/src/ReadFeed/Pagination/ReadFeedPaginationOptions.cs b/Microsoft.Azure.Cosmos/src/ReadFeed/Pagination/ReadFeedPaginationOptions.cs index 757473c02c..ad219dfd99 100644 --- a/Microsoft.Azure.Cosmos/src/ReadFeed/Pagination/ReadFeedPaginationOptions.cs +++ b/Microsoft.Azure.Cosmos/src/ReadFeed/Pagination/ReadFeedPaginationOptions.cs @@ -27,9 +27,8 @@ internal sealed class ReadFeedPaginationOptions : PaginationOptions public ReadFeedPaginationOptions( PaginationDirection? paginationDirection = null, int? pageSizeHint = null, - JsonSerializationFormat? jsonSerializationFormat = null, Dictionary additionalHeaders = null) - : base(pageSizeHint, jsonSerializationFormat, additionalHeaders) + : base(pageSizeHint, additionalHeaders) { this.Direction = paginationDirection; } From aa4fa0ba98d550df23b47a3c78de526eb4bc3024 Mon Sep 17 00:00:00 2001 From: Heet Date: Thu, 2 Feb 2023 13:15:36 -0800 Subject: [PATCH 13/32] Addressed comments --- Microsoft.Azure.Cosmos/src/Headers/Headers.cs | 1 - .../src/Headers/StoreRequestHeaders.cs | 2 + .../DocumentQueryExecutionContextBase.cs | 2 +- .../src/RequestOptions/QueryRequestOptions.cs | 2 +- .../HeadersValidationTests.cs | 16 ++++- .../SupportedSerializationFormatsTest.cs | 58 +++++++++++++++---- 6 files changed, 63 insertions(+), 18 deletions(-) diff --git a/Microsoft.Azure.Cosmos/src/Headers/Headers.cs b/Microsoft.Azure.Cosmos/src/Headers/Headers.cs index c39113188d..611de5f147 100644 --- a/Microsoft.Azure.Cosmos/src/Headers/Headers.cs +++ b/Microsoft.Azure.Cosmos/src/Headers/Headers.cs @@ -18,7 +18,6 @@ namespace Microsoft.Azure.Cosmos /// public class Headers : IEnumerable { - internal const string DefaultSupportedSerializationFormats = "JsonText, CosmosBinary"; internal static readonly string SDKSUPPORTEDCAPABILITIES = SDKSupportedCapabilitiesHelpers.GetSDKSupportedCapabilities().ToString( CultureInfo.InvariantCulture); diff --git a/Microsoft.Azure.Cosmos/src/Headers/StoreRequestHeaders.cs b/Microsoft.Azure.Cosmos/src/Headers/StoreRequestHeaders.cs index 4c82bff8bf..3cfa6d5838 100644 --- a/Microsoft.Azure.Cosmos/src/Headers/StoreRequestHeaders.cs +++ b/Microsoft.Azure.Cosmos/src/Headers/StoreRequestHeaders.cs @@ -14,6 +14,8 @@ namespace Microsoft.Azure.Cosmos /// internal sealed class StoreRequestHeaders : CosmosMessageHeadersInternal { + internal const string DefaultSupportedSerializationFormats = "JsonText, CosmosBinary"; + private readonly RequestNameValueCollection requestNameValueCollection; public override string Continuation diff --git a/Microsoft.Azure.Cosmos/src/Query/v2Query/DocumentQueryExecutionContextBase.cs b/Microsoft.Azure.Cosmos/src/Query/v2Query/DocumentQueryExecutionContextBase.cs index 6ae6d98d3b..1094ef61d8 100644 --- a/Microsoft.Azure.Cosmos/src/Query/v2Query/DocumentQueryExecutionContextBase.cs +++ b/Microsoft.Azure.Cosmos/src/Query/v2Query/DocumentQueryExecutionContextBase.cs @@ -341,7 +341,7 @@ await this.Client.EnsureValidOverwriteAsync( } else { - requestHeaders[HttpConstants.HttpHeaders.SupportedSerializationFormats] = Headers.DefaultSupportedSerializationFormats; + requestHeaders[HttpConstants.HttpHeaders.SupportedSerializationFormats] = StoreRequestHeaders.DefaultSupportedSerializationFormats; } return requestHeaders; diff --git a/Microsoft.Azure.Cosmos/src/RequestOptions/QueryRequestOptions.cs b/Microsoft.Azure.Cosmos/src/RequestOptions/QueryRequestOptions.cs index 4de71ce9f6..27ac59facd 100644 --- a/Microsoft.Azure.Cosmos/src/RequestOptions/QueryRequestOptions.cs +++ b/Microsoft.Azure.Cosmos/src/RequestOptions/QueryRequestOptions.cs @@ -246,7 +246,7 @@ internal override void PopulateRequestOptions(RequestMessage request) } else { - request.Headers.CosmosMessageHeaders.SupportedSerializationFormats = Headers.DefaultSupportedSerializationFormats; + request.Headers.CosmosMessageHeaders.SupportedSerializationFormats = StoreRequestHeaders.DefaultSupportedSerializationFormats; } if (this.StartId != null) diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/HeadersValidationTests.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/HeadersValidationTests.cs index ce6b4d7019..5ef3ec271e 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/HeadersValidationTests.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/HeadersValidationTests.cs @@ -404,9 +404,19 @@ private void SupportedSerializationFormatsPositiveCases( { headers.Add(HttpConstants.HttpHeaders.ContentSerializationFormat, contentSerializationFormats); } + headers.Add(HttpConstants.HttpHeaders.SupportedSerializationFormats, supportedSerializationFormats); - DocumentServiceResponse response = sqlQuerySpec != null ? this.QueryRequest(client, collection.ResourceId, sqlQuerySpec, headers) : - this.ReadDocumentFeedRequestAsync(client, collection.ResourceId, headers).Result; + DocumentServiceResponse response; + if(sqlQuerySpec!=null) + { + response = this.QueryRequest(client, collection.ResourceId, sqlQuerySpec, headers); + } + else + { + Assert.IsFalse(expectedResultIsBinary); + response = this.ReadDocumentFeedRequestAsync(client, collection.ResourceId, headers).Result; + } + Assert.IsTrue(response.StatusCode == HttpStatusCode.OK, "Invalid status code"); if(!expectedResultIsBinary) @@ -417,8 +427,8 @@ private void SupportedSerializationFormatsPositiveCases( { Assert.IsTrue(response.ResponseBody.ReadByte() == BinarySerializationByteMarkValue); } - } + private void ValidateSupportedSerializationFormatsReadFeed(DocumentClient client, DocumentCollection collection) { // Value not supported diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/Query/SupportedSerializationFormatsTest.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/Query/SupportedSerializationFormatsTest.cs index 369a1240c1..0659e9ddb6 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/Query/SupportedSerializationFormatsTest.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/Query/SupportedSerializationFormatsTest.cs @@ -1,11 +1,13 @@ namespace Microsoft.Azure.Cosmos.Query { - using System; + using System.Collections; using System.Collections.Generic; + using System.Linq; using System.Threading.Tasks; using Microsoft.Azure.Cosmos.CosmosElements; using Microsoft.Azure.Cosmos.EmulatorTests.Query; using Microsoft.Azure.Cosmos.SDK.EmulatorTests.QueryOracle; + using Microsoft.Azure.Documents; using Microsoft.VisualStudio.TestTools.UnitTesting; [TestClass] @@ -15,13 +17,12 @@ public sealed class SupportedSerializationFormatsTest : QueryTestsBase [TestMethod] public async Task TestSupportedSerializationFormats() { - int seed = (int)(DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalSeconds; uint numberOfDocuments = 1; - QueryOracleUtil util = new QueryOracle2(seed); + QueryOracleUtil util = new QueryOracle2(seed: 1675371967); IEnumerable inputDocuments = util.GetDocuments(numberOfDocuments); await this.CreateIngestQueryDeleteAsync( - ConnectionModes.Direct, + ConnectionModes.Direct | ConnectionModes.Gateway, CollectionTypes.SinglePartition | CollectionTypes.MultiPartition, inputDocuments, ImplementationAsync, @@ -30,19 +31,52 @@ await this.CreateIngestQueryDeleteAsync( static async Task ImplementationAsync(Container container, IReadOnlyList documents) { string query = string.Format("SELECT * FROM c"); - - QueryRequestOptions requestOptions = new QueryRequestOptions + List resultsList = new List(); + List requestOptionsList = new List() { - SupportedSerializationFormats = Documents.SupportedSerializationFormats.CosmosBinary | Documents.SupportedSerializationFormats.HybridRow + new QueryRequestOptions() + { + SupportedSerializationFormats = SupportedSerializationFormats.CosmosBinary | SupportedSerializationFormats.HybridRow + }, + new QueryRequestOptions() + { + SupportedSerializationFormats = SupportedSerializationFormats.JsonText | SupportedSerializationFormats.CosmosBinary + }, + new QueryRequestOptions() + { + SupportedSerializationFormats = SupportedSerializationFormats.JsonText | SupportedSerializationFormats.HybridRow + }, + new QueryRequestOptions() + { + SupportedSerializationFormats = SupportedSerializationFormats.JsonText | SupportedSerializationFormats.CosmosBinary | SupportedSerializationFormats.HybridRow + }, + new QueryRequestOptions() + { + SupportedSerializationFormats = SupportedSerializationFormats.JsonText + }, + new QueryRequestOptions() + { + SupportedSerializationFormats = SupportedSerializationFormats.CosmosBinary + } }; - FeedIterator feedIterator = container.GetItemQueryIterator( - query, - requestOptions: requestOptions); + foreach (QueryRequestOptions requestOptions in requestOptionsList) + { + FeedIterator feedIterator = container.GetItemQueryIterator(new QueryDefinition(query), requestOptions: requestOptions); + ArrayList results = new ArrayList(); + + while (feedIterator.HasMoreResults) + { + FeedResponse page = await feedIterator.ReadNextAsync(); + results.AddRange(page.ToList()); + } + + resultsList.Add(results); + } - while (feedIterator.HasMoreResults) + for (int i = 0; i < resultsList.Count - 1; i++) { - FeedResponse page = await feedIterator.ReadNextAsync(); + Assert.AreEqual(resultsList[i].Count, resultsList[i + 1].Count); } } } From edab02f4ae28dd285528403c9d6556ae1a99c20d Mon Sep 17 00:00:00 2001 From: Heet Date: Tue, 7 Feb 2023 09:52:45 -0800 Subject: [PATCH 14/32] Addressed comments --- .../HeadersValidationTests.cs | 3 +- .../SupportedSerializationFormatsTest.cs | 134 +++++++++++------- .../Query/FeedOptionTests.cs | 1 + 3 files changed, 82 insertions(+), 56 deletions(-) diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/HeadersValidationTests.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/HeadersValidationTests.cs index 5ef3ec271e..cd00536653 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/HeadersValidationTests.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/HeadersValidationTests.cs @@ -349,6 +349,7 @@ public void ValidateSupportedSerializationFormatsHttps() DocumentClient client = TestCommon.CreateClient(false, Protocol.Https); this.ValidateSupportedSerializationFormats(client); } + private void ValidateSupportedSerializationFormats(DocumentClient client) { DocumentCollection collection = TestCommon.CreateOrGetDocumentCollection(client); @@ -413,7 +414,7 @@ private void SupportedSerializationFormatsPositiveCases( } else { - Assert.IsFalse(expectedResultIsBinary); + Assert.IsFalse(expectedResultIsBinary, "ReadFeed response should be in Text"); response = this.ReadDocumentFeedRequestAsync(client, collection.ResourceId, headers).Result; } diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/Query/SupportedSerializationFormatsTest.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/Query/SupportedSerializationFormatsTest.cs index 0659e9ddb6..9866cf65bd 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/Query/SupportedSerializationFormatsTest.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/Query/SupportedSerializationFormatsTest.cs @@ -1,84 +1,108 @@ namespace Microsoft.Azure.Cosmos.Query { - using System.Collections; + using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; - using Microsoft.Azure.Cosmos.CosmosElements; - using Microsoft.Azure.Cosmos.EmulatorTests.Query; - using Microsoft.Azure.Cosmos.SDK.EmulatorTests.QueryOracle; using Microsoft.Azure.Documents; using Microsoft.VisualStudio.TestTools.UnitTesting; [TestClass] [TestCategory("Query")] - public sealed class SupportedSerializationFormatsTest : QueryTestsBase + public sealed class SupportedSerializationFormatsTest { + private readonly string endpoint = Utils.ConfigurationManager.AppSettings["GatewayEndpoint"]; + private readonly string authKey = Utils.ConfigurationManager.AppSettings["MasterKey"]; + [TestMethod] - public async Task TestSupportedSerializationFormats() + public async Task ConnectEndpoint() { - uint numberOfDocuments = 1; - QueryOracleUtil util = new QueryOracle2(seed: 1675371967); - IEnumerable inputDocuments = util.GetDocuments(numberOfDocuments); + using (CosmosClient client = new CosmosClient(this.endpoint, this.authKey, + new CosmosClientOptions + { + ConnectionMode = ConnectionMode.Direct + })) + { + await this.TestSetup(client); + } + } - await this.CreateIngestQueryDeleteAsync( - ConnectionModes.Direct | ConnectionModes.Gateway, - CollectionTypes.SinglePartition | CollectionTypes.MultiPartition, - inputDocuments, - ImplementationAsync, - "/id"); + private async Task TestSetup(CosmosClient client) + { + await client.CreateDatabaseIfNotExistsAsync("db"); + Container container = await client.GetDatabase("db").CreateContainerIfNotExistsAsync("container", "/partitionKey"); + for (int i = 0; i < 10; i++) + { + await container.CreateItemAsync(new { id = Guid.NewGuid().ToString(), name = "document_" + i, score = i + 1 }); + } - static async Task ImplementationAsync(Container container, IReadOnlyList documents) + List queryRequestOptionsList = new List() { - string query = string.Format("SELECT * FROM c"); - List resultsList = new List(); - List requestOptionsList = new List() + new QueryRequestOptions() { - new QueryRequestOptions() - { - SupportedSerializationFormats = SupportedSerializationFormats.CosmosBinary | SupportedSerializationFormats.HybridRow - }, - new QueryRequestOptions() - { - SupportedSerializationFormats = SupportedSerializationFormats.JsonText | SupportedSerializationFormats.CosmosBinary - }, - new QueryRequestOptions() - { - SupportedSerializationFormats = SupportedSerializationFormats.JsonText | SupportedSerializationFormats.HybridRow - }, - new QueryRequestOptions() - { - SupportedSerializationFormats = SupportedSerializationFormats.JsonText | SupportedSerializationFormats.CosmosBinary | SupportedSerializationFormats.HybridRow - }, - new QueryRequestOptions() - { - SupportedSerializationFormats = SupportedSerializationFormats.JsonText - }, - new QueryRequestOptions() - { - SupportedSerializationFormats = SupportedSerializationFormats.CosmosBinary - } - }; - - foreach (QueryRequestOptions requestOptions in requestOptionsList) + SupportedSerializationFormats = SupportedSerializationFormats.CosmosBinary | SupportedSerializationFormats.HybridRow + }, + new QueryRequestOptions() + { + SupportedSerializationFormats = SupportedSerializationFormats.JsonText | SupportedSerializationFormats.CosmosBinary + }, + new QueryRequestOptions() + { + SupportedSerializationFormats = SupportedSerializationFormats.JsonText | SupportedSerializationFormats.HybridRow + }, + new QueryRequestOptions() + { + SupportedSerializationFormats = SupportedSerializationFormats.JsonText | SupportedSerializationFormats.CosmosBinary | SupportedSerializationFormats.HybridRow + }, + new QueryRequestOptions() { - FeedIterator feedIterator = container.GetItemQueryIterator(new QueryDefinition(query), requestOptions: requestOptions); - ArrayList results = new ArrayList(); + SupportedSerializationFormats = SupportedSerializationFormats.JsonText + }, + new QueryRequestOptions() + { + SupportedSerializationFormats = SupportedSerializationFormats.CosmosBinary + } + }; + + await this.RunQueryWithOptionsAsync(client, container, queryRequestOptionsList); + } + private async Task RunQueryWithOptionsAsync(CosmosClient client, Container container, List queryRequestOptionsList) + { + string query = string.Format("SELECT c.name FROM c"); + List expectedResults = new List() + { + new { name = "document_0"}, + new { name = "document_1"}, + new { name = "document_2"}, + new { name = "document_3"}, + new { name = "document_4"}, + new { name = "document_5"}, + new { name = "document_6"}, + new { name = "document_7"}, + new { name = "document_8"}, + new { name = "document_9"}, + }; + + foreach (QueryRequestOptions requestOptions in queryRequestOptionsList) + { + List actualResults = new List(); + using (FeedIterator feedIterator = container.GetItemQueryIterator(new QueryDefinition(query), requestOptions: requestOptions)) + { while (feedIterator.HasMoreResults) { - FeedResponse page = await feedIterator.ReadNextAsync(); - results.AddRange(page.ToList()); + FeedResponse response = await feedIterator.ReadNextAsync(); + actualResults.AddRange(response.ToList()); } - - resultsList.Add(results); } - for (int i = 0; i < resultsList.Count - 1; i++) + for (int i = 0; i < actualResults.Count; i++) { - Assert.AreEqual(resultsList[i].Count, resultsList[i + 1].Count); + Assert.AreEqual(expectedResults[i].name, actualResults[i].name.ToString()); } } + + await client.GetDatabase("db").DeleteAsync(); } } -} +} \ No newline at end of file diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Query/FeedOptionTests.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Query/FeedOptionTests.cs index 51e0e8ec3c..27b363a5f4 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Query/FeedOptionTests.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Query/FeedOptionTests.cs @@ -72,6 +72,7 @@ public async Task TestSupportedSerializationFormatsAsync() headers = await cxt.CreateCommonHeadersAsync(fo); Assert.AreEqual("CosmosBinary, HybridRow", headers[HttpConstants.HttpHeaders.SupportedSerializationFormats]); } + internal class TestQueryExecutionContext : DocumentQueryExecutionContextBase { public TestQueryExecutionContext( From aa907cd66ee5fd9e6ce7049683dbfc2728c8a80b Mon Sep 17 00:00:00 2001 From: Heet Date: Mon, 13 Feb 2023 13:03:40 -0800 Subject: [PATCH 15/32] Addressed comments --- .../src/Headers/StoreRequestHeaders.cs | 2 - .../DocumentQueryExecutionContextBase.cs | 3 +- .../CosmosItemTests.cs | 32 +++---- .../HeadersValidationTests.cs | 17 ++-- .../SupportedSerializationFormatsTest.cs | 86 ++++++++----------- .../Query/FeedOptionTests.cs | 14 +-- 6 files changed, 72 insertions(+), 82 deletions(-) diff --git a/Microsoft.Azure.Cosmos/src/Headers/StoreRequestHeaders.cs b/Microsoft.Azure.Cosmos/src/Headers/StoreRequestHeaders.cs index 3cfa6d5838..4c82bff8bf 100644 --- a/Microsoft.Azure.Cosmos/src/Headers/StoreRequestHeaders.cs +++ b/Microsoft.Azure.Cosmos/src/Headers/StoreRequestHeaders.cs @@ -14,8 +14,6 @@ namespace Microsoft.Azure.Cosmos /// internal sealed class StoreRequestHeaders : CosmosMessageHeadersInternal { - internal const string DefaultSupportedSerializationFormats = "JsonText, CosmosBinary"; - private readonly RequestNameValueCollection requestNameValueCollection; public override string Continuation diff --git a/Microsoft.Azure.Cosmos/src/Query/v2Query/DocumentQueryExecutionContextBase.cs b/Microsoft.Azure.Cosmos/src/Query/v2Query/DocumentQueryExecutionContextBase.cs index 1094ef61d8..e501041c55 100644 --- a/Microsoft.Azure.Cosmos/src/Query/v2Query/DocumentQueryExecutionContextBase.cs +++ b/Microsoft.Azure.Cosmos/src/Query/v2Query/DocumentQueryExecutionContextBase.cs @@ -31,6 +31,7 @@ namespace Microsoft.Azure.Cosmos.Query internal abstract class DocumentQueryExecutionContextBase : IDocumentQueryExecutionContext { + internal static readonly string DefaultSupportedSerializationFormats = string.Join(",", SupportedSerializationFormats.JsonText, SupportedSerializationFormats.CosmosBinary); public readonly struct InitParams { public IDocumentQueryClient Client { get; } @@ -341,7 +342,7 @@ await this.Client.EnsureValidOverwriteAsync( } else { - requestHeaders[HttpConstants.HttpHeaders.SupportedSerializationFormats] = StoreRequestHeaders.DefaultSupportedSerializationFormats; + requestHeaders[HttpConstants.HttpHeaders.SupportedSerializationFormats] = DefaultSupportedSerializationFormats; } return requestHeaders; diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/CosmosItemTests.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/CosmosItemTests.cs index 71e63846a7..50bc71f276 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/CosmosItemTests.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/CosmosItemTests.cs @@ -771,9 +771,9 @@ public async Task PartitionKeyDeleteTestForSubpartitionedContainer() try { CosmosClient client = TestCommon.CreateCosmosClient(true); - + database = await client.CreateDatabaseIfNotExistsAsync("mydb"); - + ContainerProperties containerProperties = new ContainerProperties("subpartitionedcontainer", new List { "/Country", "/City" }); Container container = await database.CreateContainerAsync(containerProperties); ContainerInternal containerInternal = (ContainerInternal)container; @@ -804,7 +804,7 @@ public async Task PartitionKeyDeleteTestForSubpartitionedContainer() doc1.SetValue("Country", "USA"); doc1.SetValue("City", "Stonybrook"); documents[4] = await container.CreateItemAsync(doc1); - + Cosmos.PartitionKey partitionKey1 = new PartitionKeyBuilder().Add("USA").Add("Stonybrook").Build(); using (ResponseMessage pKDeleteResponse = await containerInternal.DeleteAllItemsByPartitionKeyStreamAsync(partitionKey1)) @@ -1187,7 +1187,7 @@ public async Task QueryStreamValueTest() { Assert.AreEqual(3, pageCount); } - + IReadOnlyList<(string Name, object Value)> parameters1 = queryDefinition.GetQueryParameters(); @@ -1364,8 +1364,8 @@ public async Task ItemMultiplePartitionOrderByQueryStream() }; IList deleteList = await ToDoActivity.CreateRandomItems( - this.Container, - 300, + this.Container, + 300, randomPartitionKey: true, randomTaskNumber: true); @@ -1622,8 +1622,8 @@ public async Task ItemEpkQuerySingleKeyRangeValidation() public async Task ItemQueryStreamSerializationSetting() { IList deleteList = await ToDoActivity.CreateRandomItems( - container: this.Container, - pkCount: 101, + container: this.Container, + pkCount: 101, randomTaskNumber: true); QueryDefinition sql = new QueryDefinition("SELECT * FROM toDoActivity t ORDER BY t.taskNum"); @@ -2905,16 +2905,16 @@ public async Task CustomPropertiesItemRequestOptionsTest() builder => builder.WithTransportClientHandlerFactory(transportClient => new TransportClientHelper.TransportClientWrapper( transportClient, (uri, resourceOperation, request) => - { - if (resourceOperation.resourceType == ResourceType.Document && - resourceOperation.operationType == OperationType.Create) { - bool customHeaderExists = request.Properties.TryGetValue(customHeaderName, out object value); + if (resourceOperation.resourceType == ResourceType.Document && + resourceOperation.operationType == OperationType.Create) + { + bool customHeaderExists = request.Properties.TryGetValue(customHeaderName, out object value); - Assert.IsTrue(customHeaderExists); - Assert.AreEqual(customHeaderValue, value); - } - }))); + Assert.IsTrue(customHeaderExists); + Assert.AreEqual(customHeaderValue, value); + } + }))); Container container = clientWithIntercepter.GetContainer(this.database.Id, this.Container.Id); diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/HeadersValidationTests.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/HeadersValidationTests.cs index 051e94638f..5d0b2c599b 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/HeadersValidationTests.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/HeadersValidationTests.cs @@ -333,12 +333,17 @@ private void ValidateSupportedSerializationFormats(DocumentClient client) DocumentCollection collection = TestCommon.CreateOrGetDocumentCollection(client); this.ValidateSupportedSerializationFormatsReadFeed(client, collection); - SqlQuerySpec sqlQuerySelectStar = new SqlQuerySpec("SELECT * FROM c"); - SqlQuerySpec sqlQueryOrderBy = new SqlQuerySpec("SELECT c.id FROM c ORDER BY c.partitionKey"); - SqlQuerySpec sqlQueryGroupBy = new SqlQuerySpec("SELECT c.name FROM c GROUP BY c.name"); - this.ValidateSupportedSerializationFormatsQuery(client, collection, sqlQuerySelectStar); - this.ValidateSupportedSerializationFormatsQuery(client, collection, sqlQueryOrderBy); - this.ValidateSupportedSerializationFormatsQuery(client, collection, sqlQueryGroupBy); + List sqlQueryList = new List() + { + new SqlQuerySpec("SELECT * FROM c"), + new SqlQuerySpec("SELECT c.id FROM c ORDER BY c.partitionKey"), + new SqlQuerySpec("SELECT c.name FROM c GROUP BY c.name") + }; + + foreach(SqlQuerySpec sqlQuery in sqlQueryList) + { + this.ValidateSupportedSerializationFormatsQuery(client, collection, sqlQuery); + } } private void SupportedSerializationFormatsNegativeCases( diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/Query/SupportedSerializationFormatsTest.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/Query/SupportedSerializationFormatsTest.cs index 9866cf65bd..4ce33b325d 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/Query/SupportedSerializationFormatsTest.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/Query/SupportedSerializationFormatsTest.cs @@ -4,38 +4,45 @@ using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; + using Microsoft.Azure.Cosmos.CosmosElements; + using Microsoft.Azure.Cosmos.EmulatorTests.Query; + using Microsoft.Azure.Cosmos.SDK.EmulatorTests.QueryOracle; using Microsoft.Azure.Documents; using Microsoft.VisualStudio.TestTools.UnitTesting; [TestClass] [TestCategory("Query")] - public sealed class SupportedSerializationFormatsTest + public sealed class SupportedSerializationFormatsTest : QueryTestsBase { - private readonly string endpoint = Utils.ConfigurationManager.AppSettings["GatewayEndpoint"]; - private readonly string authKey = Utils.ConfigurationManager.AppSettings["MasterKey"]; - [TestMethod] - public async Task ConnectEndpoint() + public async Task TestSupportedSerializationFormats() { - using (CosmosClient client = new CosmosClient(this.endpoint, this.authKey, - new CosmosClientOptions - { - ConnectionMode = ConnectionMode.Direct - })) + string[] inputDocuments = new[] { - await this.TestSetup(client); - } + @"{""id"":""0"",""name"":""document_0""}", + @"{""id"":""1"",""name"":""document_1""}", + @"{""id"":""2"",""name"":""document_2""}", + @"{""id"":""3"",""name"":""document_3""}", + @"{""id"":""4"",""name"":""document_4""}", + @"{""id"":""5"",""name"":""document_5""}", + @"{""id"":""6"",""name"":""document_6""}", + @"{""id"":""7"",""name"":""document_7""}", + @"{""id"":""8"",""name"":""document_8""}", + @"{""id"":""9"",""name"":""document_9""}", + }; + + await this.CreateIngestQueryDeleteAsync( + ConnectionModes.Direct, + CollectionTypes.SinglePartition | CollectionTypes.MultiPartition, + inputDocuments, + this.TestSupportedSerializationFormatsHelper, + "/id"); } - private async Task TestSetup(CosmosClient client) + private async Task TestSupportedSerializationFormatsHelper(Container container, IReadOnlyList documents) { - await client.CreateDatabaseIfNotExistsAsync("db"); - Container container = await client.GetDatabase("db").CreateContainerIfNotExistsAsync("container", "/partitionKey"); - for (int i = 0; i < 10; i++) - { - await container.CreateItemAsync(new { id = Guid.NewGuid().ToString(), name = "document_" + i, score = i + 1 }); - } - + string[] expectedResults = new[] { "document_0", "document_1", "document_2", "document_3", "document_4", "document_5", "document_6", "document_7", "document_8", "document_9" }; + string query = string.Format("SELECT c.name FROM c"); List queryRequestOptionsList = new List() { new QueryRequestOptions() @@ -64,45 +71,24 @@ private async Task TestSetup(CosmosClient client) } }; - await this.RunQueryWithOptionsAsync(client, container, queryRequestOptionsList); - } - - private async Task RunQueryWithOptionsAsync(CosmosClient client, Container container, List queryRequestOptionsList) - { - string query = string.Format("SELECT c.name FROM c"); - List expectedResults = new List() - { - new { name = "document_0"}, - new { name = "document_1"}, - new { name = "document_2"}, - new { name = "document_3"}, - new { name = "document_4"}, - new { name = "document_5"}, - new { name = "document_6"}, - new { name = "document_7"}, - new { name = "document_8"}, - new { name = "document_9"}, - }; - foreach (QueryRequestOptions requestOptions in queryRequestOptionsList) { - List actualResults = new List(); - using (FeedIterator feedIterator = container.GetItemQueryIterator(new QueryDefinition(query), requestOptions: requestOptions)) + List results = new List(); + using (FeedIterator feedIterator = container.GetItemQueryIterator(new QueryDefinition(query), requestOptions: requestOptions)) { while (feedIterator.HasMoreResults) { - FeedResponse response = await feedIterator.ReadNextAsync(); - actualResults.AddRange(response.ToList()); + FeedResponse response = await feedIterator.ReadNextAsync(); + results.AddRange(response.ToList()); } } - for (int i = 0; i < actualResults.Count; i++) - { - Assert.AreEqual(expectedResults[i].name, actualResults[i].name.ToString()); - } - } + string[] actualResults = results + .Select(doc => ((CosmosString)(doc as CosmosObject)["name"]).Value.ToString()) + .ToArray(); - await client.GetDatabase("db").DeleteAsync(); + CollectionAssert.AreEquivalent(expectedResults, actualResults); + } } } } \ No newline at end of file diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Query/FeedOptionTests.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Query/FeedOptionTests.cs index 27b363a5f4..1da167603a 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Query/FeedOptionTests.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Query/FeedOptionTests.cs @@ -53,23 +53,23 @@ public void TestCopyConstructor() [TestMethod] public async Task TestSupportedSerializationFormatsAsync() { - FeedOptions fo = new FeedOptions(); - Mock dcClient = new Mock(); + FeedOptions feedOptions = new FeedOptions(); + Mock client = new Mock(MockBehavior.Strict); Expression> randomFunc = x => x * 2; TestQueryExecutionContext cxt = new TestQueryExecutionContext( - dcClient.Object, + client.Object, ResourceType.Document, typeof(TestQueryExecutionContext), randomFunc, - fo, + feedOptions, string.Empty, true, Guid.NewGuid()); - INameValueCollection headers = await cxt.CreateCommonHeadersAsync(fo); + INameValueCollection headers = await cxt.CreateCommonHeadersAsync(feedOptions); Assert.AreEqual("JsonText, CosmosBinary", headers[HttpConstants.HttpHeaders.SupportedSerializationFormats]); - fo.SupportedSerializationFormats = SupportedSerializationFormats.CosmosBinary | SupportedSerializationFormats.HybridRow; - headers = await cxt.CreateCommonHeadersAsync(fo); + feedOptions.SupportedSerializationFormats = SupportedSerializationFormats.CosmosBinary | SupportedSerializationFormats.HybridRow; + headers = await cxt.CreateCommonHeadersAsync(feedOptions); Assert.AreEqual("CosmosBinary, HybridRow", headers[HttpConstants.HttpHeaders.SupportedSerializationFormats]); } From 6f04f1dcfd1b12e8efdfc19d193d793c711275da Mon Sep 17 00:00:00 2001 From: Heet Date: Mon, 27 Feb 2023 12:57:46 -0800 Subject: [PATCH 16/32] Addressed comments --- .../Pagination/ChangeFeedPaginationOptions.cs | 3 +- Microsoft.Azure.Cosmos/src/FeedOptions.cs | 16 +++---- .../DocumentQueryExecutionContextBase.cs | 3 +- .../HeadersValidationTests.cs | 43 ++++++++++++------- .../SupportedSerializationFormatsTest.cs | 12 +++--- 5 files changed, 46 insertions(+), 31 deletions(-) diff --git a/Microsoft.Azure.Cosmos/src/ChangeFeed/Pagination/ChangeFeedPaginationOptions.cs b/Microsoft.Azure.Cosmos/src/ChangeFeed/Pagination/ChangeFeedPaginationOptions.cs index de11129e1b..d41743bcc0 100644 --- a/Microsoft.Azure.Cosmos/src/ChangeFeed/Pagination/ChangeFeedPaginationOptions.cs +++ b/Microsoft.Azure.Cosmos/src/ChangeFeed/Pagination/ChangeFeedPaginationOptions.cs @@ -44,8 +44,9 @@ public ChangeFeedPaginationOptions( public ChangeFeedQuerySpec ChangeFeedQuerySpec { get; } + public JsonSerializationFormat? JsonSerializationFormat { get; } + protected override ImmutableHashSet BannedAdditionalHeaders => BannedHeaders; - public JsonSerializationFormat? JsonSerializationFormat { get; } } } diff --git a/Microsoft.Azure.Cosmos/src/FeedOptions.cs b/Microsoft.Azure.Cosmos/src/FeedOptions.cs index cc3c85aa6a..668e60b2b6 100644 --- a/Microsoft.Azure.Cosmos/src/FeedOptions.cs +++ b/Microsoft.Azure.Cosmos/src/FeedOptions.cs @@ -357,6 +357,14 @@ internal FeedOptions(FeedOptions options) /// public ConsistencyLevel? ConsistencyLevel { get; set; } + /// + /// Gets or sets the SupportedSerializationFormats for the feed (query/read feed) operation in the Azure Cosmos DB service. + /// + /// + /// Default value of 'JsonText, CosmosBinary' will be passed if null. The backend will choose the best suited format for the response. + /// + public SupportedSerializationFormats? SupportedSerializationFormats { get; set; } + /// /// Gets or sets the flag that tells the backend to forces the query to perform a scan (at a request level). /// @@ -406,14 +414,6 @@ internal FeedOptions(FeedOptions options) /// internal ContentSerializationFormat? ContentSerializationFormat { get; set; } - /// - /// Gets or sets the SupportedSerializationFormats for the feed (query/read feed) operation in the Azure Cosmos DB service. - /// - /// - /// Serialization format for the response is selected based on the values requested and the serialization format the document is stored in. - /// - internal SupportedSerializationFormats? SupportedSerializationFormats { get; set; } - internal bool EnableGroupBy { get; set; } /// diff --git a/Microsoft.Azure.Cosmos/src/Query/v2Query/DocumentQueryExecutionContextBase.cs b/Microsoft.Azure.Cosmos/src/Query/v2Query/DocumentQueryExecutionContextBase.cs index e501041c55..39776781f2 100644 --- a/Microsoft.Azure.Cosmos/src/Query/v2Query/DocumentQueryExecutionContextBase.cs +++ b/Microsoft.Azure.Cosmos/src/Query/v2Query/DocumentQueryExecutionContextBase.cs @@ -31,7 +31,8 @@ namespace Microsoft.Azure.Cosmos.Query internal abstract class DocumentQueryExecutionContextBase : IDocumentQueryExecutionContext { - internal static readonly string DefaultSupportedSerializationFormats = string.Join(",", SupportedSerializationFormats.JsonText, SupportedSerializationFormats.CosmosBinary); + public static readonly string DefaultSupportedSerializationFormats = string.Join(",", SupportedSerializationFormats.JsonText, SupportedSerializationFormats.CosmosBinary); + public readonly struct InitParams { public IDocumentQueryClient Client { get; } diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/HeadersValidationTests.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/HeadersValidationTests.cs index 1e4f445f87..0e2bc8b794 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/HeadersValidationTests.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/HeadersValidationTests.cs @@ -13,6 +13,7 @@ namespace Microsoft.Azure.Cosmos.SDK.EmulatorTests using System.Net; using System.Text; using System.Threading.Tasks; + using Microsoft.Azure.Cosmos.Json; using Microsoft.Azure.Cosmos.Query.Core; using Microsoft.Azure.Cosmos.Routing; using Microsoft.Azure.Cosmos.Tracing; @@ -378,7 +379,7 @@ private void SupportedSerializationFormatsNegativeCases( private void SupportedSerializationFormatsPositiveCases( DocumentClient client, DocumentCollection collection, - bool expectedResultIsBinary, + SupportedSerializationFormats expectedFormat, string supportedSerializationFormats, string contentSerializationFormats, SqlQuerySpec sqlQuerySpec = null) @@ -397,19 +398,19 @@ private void SupportedSerializationFormatsPositiveCases( } else { - Assert.IsFalse(expectedResultIsBinary, "ReadFeed response should be in Text"); + Assert.IsTrue(expectedFormat == SupportedSerializationFormats.JsonText, "ReadFeed response should be in Text"); response = this.ReadDocumentFeedRequestAsync(client, collection.ResourceId, headers).Result; } Assert.IsTrue(response.StatusCode == HttpStatusCode.OK, "Invalid status code"); - if(!expectedResultIsBinary) + if(expectedFormat == SupportedSerializationFormats.JsonText) { - Assert.IsTrue(response.ResponseBody.ReadByte() < BinarySerializationByteMarkValue); + Assert.IsTrue(this.CheckSerializationFormat(response) == JsonSerializationFormat.Text); } else { - Assert.IsTrue(response.ResponseBody.ReadByte() == BinarySerializationByteMarkValue); + Assert.IsTrue(this.CheckSerializationFormat(response) == JsonSerializationFormat.Binary); } } @@ -419,9 +420,9 @@ private void ValidateSupportedSerializationFormatsReadFeed(DocumentClient client this.SupportedSerializationFormatsNegativeCases(client, collection, "Invalid value"); // Supported values - this.SupportedSerializationFormatsPositiveCases(client, collection, expectedResultIsBinary: false, supportedSerializationFormats: "JSONText", contentSerializationFormats: null); - this.SupportedSerializationFormatsPositiveCases(client, collection, expectedResultIsBinary: false, supportedSerializationFormats: "COSMOSbinary", contentSerializationFormats: null); - this.SupportedSerializationFormatsPositiveCases(client, collection, expectedResultIsBinary: false, supportedSerializationFormats: "JsonText, CosmosBinary", contentSerializationFormats: null); + this.SupportedSerializationFormatsPositiveCases(client, collection, expectedFormat: SupportedSerializationFormats.JsonText, supportedSerializationFormats: "JSONText", contentSerializationFormats: null); + this.SupportedSerializationFormatsPositiveCases(client, collection, expectedFormat: SupportedSerializationFormats.JsonText, supportedSerializationFormats: "COSMOSbinary", contentSerializationFormats: null); + this.SupportedSerializationFormatsPositiveCases(client, collection, expectedFormat: SupportedSerializationFormats.JsonText, supportedSerializationFormats: "JsonText, CosmosBinary", contentSerializationFormats: null); } private void ValidateSupportedSerializationFormatsQuery(DocumentClient client, DocumentCollection collection, SqlQuerySpec sqlQuerySpec) @@ -438,42 +439,54 @@ private void ValidateSupportedSerializationFormatsQuery(DocumentClient client, D // Supported values this.SupportedSerializationFormatsPositiveCases(client, collection, - expectedResultIsBinary: false, + expectedFormat: SupportedSerializationFormats.JsonText, supportedSerializationFormats: "jsontext", contentSerializationFormats: null, sqlQuerySpec: sqlQuerySpec); this.SupportedSerializationFormatsPositiveCases(client, collection, - expectedResultIsBinary: true, + expectedFormat: SupportedSerializationFormats.CosmosBinary, supportedSerializationFormats: "COSMOSBINARY", contentSerializationFormats: null, sqlQuerySpec: sqlQuerySpec); this.SupportedSerializationFormatsPositiveCases(client, collection, - expectedResultIsBinary: false, + expectedFormat: SupportedSerializationFormats.JsonText, supportedSerializationFormats: "JsonText, CosmosBinary", contentSerializationFormats: null, sqlQuerySpec: sqlQuerySpec); this.SupportedSerializationFormatsPositiveCases(client, collection, - expectedResultIsBinary: true, + expectedFormat: SupportedSerializationFormats.CosmosBinary, supportedSerializationFormats: "CosmosBinary, HybridRow", contentSerializationFormats: null, sqlQuerySpec: sqlQuerySpec); this.SupportedSerializationFormatsPositiveCases(client, collection, - expectedResultIsBinary: false, + expectedFormat: SupportedSerializationFormats.JsonText, supportedSerializationFormats: "JsonText, CosmosBinary, HybridRow", contentSerializationFormats: null, sqlQuerySpec: sqlQuerySpec); this.SupportedSerializationFormatsPositiveCases(client, collection, - expectedResultIsBinary: true, + expectedFormat: SupportedSerializationFormats.CosmosBinary, supportedSerializationFormats: "JsonText, CosmosBinary, HybridRow", contentSerializationFormats: "CosmosBinary", sqlQuerySpec: sqlQuerySpec); this.SupportedSerializationFormatsPositiveCases(client, collection, - expectedResultIsBinary: false, + expectedFormat: SupportedSerializationFormats.JsonText, supportedSerializationFormats: "JsonText, CosmosBinary, HybridRow", contentSerializationFormats: "JsonText", sqlQuerySpec: sqlQuerySpec); } + private JsonSerializationFormat CheckSerializationFormat(DocumentServiceResponse response) + { + if(response.ResponseBody.ReadByte() < BinarySerializationByteMarkValue) + { + return JsonSerializationFormat.Text; + } + else + { + return JsonSerializationFormat.Binary; + } + } + [TestMethod] public void ValidateIndexingDirectiveGateway() { diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/Query/SupportedSerializationFormatsTest.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/Query/SupportedSerializationFormatsTest.cs index 4ce33b325d..1406c70b02 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/Query/SupportedSerializationFormatsTest.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/Query/SupportedSerializationFormatsTest.cs @@ -47,27 +47,27 @@ private async Task TestSupportedSerializationFormatsHelper(Container container, { new QueryRequestOptions() { - SupportedSerializationFormats = SupportedSerializationFormats.CosmosBinary | SupportedSerializationFormats.HybridRow + SupportedSerializationFormats = SupportedSerializationFormats.CosmosBinary | SupportedSerializationFormats.HybridRow }, new QueryRequestOptions() { - SupportedSerializationFormats = SupportedSerializationFormats.JsonText | SupportedSerializationFormats.CosmosBinary + SupportedSerializationFormats = SupportedSerializationFormats.JsonText | SupportedSerializationFormats.CosmosBinary }, new QueryRequestOptions() { - SupportedSerializationFormats = SupportedSerializationFormats.JsonText | SupportedSerializationFormats.HybridRow + SupportedSerializationFormats = SupportedSerializationFormats.JsonText | SupportedSerializationFormats.HybridRow }, new QueryRequestOptions() { - SupportedSerializationFormats = SupportedSerializationFormats.JsonText | SupportedSerializationFormats.CosmosBinary | SupportedSerializationFormats.HybridRow + SupportedSerializationFormats = SupportedSerializationFormats.JsonText | SupportedSerializationFormats.CosmosBinary | SupportedSerializationFormats.HybridRow }, new QueryRequestOptions() { - SupportedSerializationFormats = SupportedSerializationFormats.JsonText + SupportedSerializationFormats = SupportedSerializationFormats.JsonText }, new QueryRequestOptions() { - SupportedSerializationFormats = SupportedSerializationFormats.CosmosBinary + SupportedSerializationFormats = SupportedSerializationFormats.CosmosBinary } }; From 01df5e29c0c3fdd9bcaaeec0afb76436e2d5bc3e Mon Sep 17 00:00:00 2001 From: Heet Date: Mon, 6 Mar 2023 12:36:30 -0800 Subject: [PATCH 17/32] Added new enum TransportSerializationFormat --- Microsoft.Azure.Cosmos/src/FeedOptions.cs | 16 ++++---- .../DocumentQueryExecutionContextBase.cs | 12 ++---- .../src/RequestOptions/QueryRequestOptions.cs | 21 ++++++---- .../CosmosSerializationFormatOptions.cs | 14 +------ .../src/TransportSerializationFormat.cs | 27 ++++++++++++ .../CosmosItemTests.cs | 2 +- .../HeadersValidationTests.cs | 41 +++++++++++++------ .../SupportedSerializationFormatsTest.cs | 18 ++++++++ .../ContentSerializationPerformanceTests.cs | 5 +-- .../Query/EndToEnd.cs | 14 ++----- .../BinaryEncodingOverTheWireTests.cs | 4 +- .../OrderByQueryResultTests.cs | 1 - .../Query/FeedOptionTests.cs | 17 +++++--- 13 files changed, 119 insertions(+), 73 deletions(-) create mode 100644 Microsoft.Azure.Cosmos/src/TransportSerializationFormat.cs diff --git a/Microsoft.Azure.Cosmos/src/FeedOptions.cs b/Microsoft.Azure.Cosmos/src/FeedOptions.cs index 668e60b2b6..dd9033cccb 100644 --- a/Microsoft.Azure.Cosmos/src/FeedOptions.cs +++ b/Microsoft.Azure.Cosmos/src/FeedOptions.cs @@ -65,11 +65,11 @@ internal FeedOptions(FeedOptions options) this.EndId = options.EndId; this.StartEpk = options.StartEpk; this.EndEpk = options.EndEpk; - this.ContentSerializationFormat = options.ContentSerializationFormat; this.EnableGroupBy = options.EnableGroupBy; this.MergeStaticId = options.MergeStaticId; this.Properties = options.Properties; this.SupportedSerializationFormats = options.SupportedSerializationFormats; + this.TransportSerializationFormat = options.TransportSerializationFormat; } /// @@ -365,6 +365,12 @@ internal FeedOptions(FeedOptions options) /// public SupportedSerializationFormats? SupportedSerializationFormats { get; set; } + /// + /// Gets or sets the serialization format for requests. + /// Request the query response in specifed serialization format. + /// + public TransportSerializationFormat? TransportSerializationFormat { get; set; } + /// /// Gets or sets the flag that tells the backend to forces the query to perform a scan (at a request level). /// @@ -406,14 +412,6 @@ internal FeedOptions(FeedOptions options) /// internal string EndEpk { get; set; } - /// - /// Gets or sets the ContentSerializationFormat for the feed (query/read feed) operation in the Azure Cosmos DB service. - /// - /// - /// If the document is stored in a different serialization format then the one requested, then there will be a rewrite over the wire, but the source document will be untouched. - /// - internal ContentSerializationFormat? ContentSerializationFormat { get; set; } - internal bool EnableGroupBy { get; set; } /// diff --git a/Microsoft.Azure.Cosmos/src/Query/v2Query/DocumentQueryExecutionContextBase.cs b/Microsoft.Azure.Cosmos/src/Query/v2Query/DocumentQueryExecutionContextBase.cs index 39776781f2..6eee7837cb 100644 --- a/Microsoft.Azure.Cosmos/src/Query/v2Query/DocumentQueryExecutionContextBase.cs +++ b/Microsoft.Azure.Cosmos/src/Query/v2Query/DocumentQueryExecutionContextBase.cs @@ -328,23 +328,19 @@ await this.Client.EnsureValidOverwriteAsync( requestHeaders.Set(HttpConstants.HttpHeaders.MergeStaticId, this.feedOptions.MergeStaticId); } - if (this.feedOptions.CosmosSerializationFormatOptions != null) + if (this.feedOptions.TransportSerializationFormat != null) { - requestHeaders[HttpConstants.HttpHeaders.ContentSerializationFormat] = this.feedOptions.CosmosSerializationFormatOptions.ContentSerializationFormat; + requestHeaders[HttpConstants.HttpHeaders.ContentSerializationFormat] = this.feedOptions.TransportSerializationFormat.Value.ToString(); } - else if (this.feedOptions.ContentSerializationFormat.HasValue) + else { - requestHeaders[HttpConstants.HttpHeaders.ContentSerializationFormat] = this.feedOptions.ContentSerializationFormat.Value.ToString(); + requestHeaders[HttpConstants.HttpHeaders.SupportedSerializationFormats] = DefaultSupportedSerializationFormats; } if (this.feedOptions.SupportedSerializationFormats != null) { requestHeaders[HttpConstants.HttpHeaders.SupportedSerializationFormats] = this.feedOptions.SupportedSerializationFormats.Value.ToString(); } - else - { - requestHeaders[HttpConstants.HttpHeaders.SupportedSerializationFormats] = DefaultSupportedSerializationFormats; - } return requestHeaders; } diff --git a/Microsoft.Azure.Cosmos/src/RequestOptions/QueryRequestOptions.cs b/Microsoft.Azure.Cosmos/src/RequestOptions/QueryRequestOptions.cs index 27ac59facd..bab9a296ce 100644 --- a/Microsoft.Azure.Cosmos/src/RequestOptions/QueryRequestOptions.cs +++ b/Microsoft.Azure.Cosmos/src/RequestOptions/QueryRequestOptions.cs @@ -7,6 +7,7 @@ namespace Microsoft.Azure.Cosmos using System; using System.Text; using Microsoft.Azure.Cosmos.CosmosElements; + using Microsoft.Azure.Cosmos.Query; using Microsoft.Azure.Cosmos.Query.Core; using Microsoft.Azure.Cosmos.Query.Core.Pipeline; using Microsoft.Azure.Documents; @@ -170,6 +171,12 @@ public ConsistencyLevel? ConsistencyLevel /// public DedicatedGatewayRequestOptions DedicatedGatewayRequestOptions { get; set; } + /// + /// Gets or sets the serialization format for requests. + /// Sends the query response over wire in the specified format. + /// + public TransportSerializationFormat? TransportSerializationFormat { get; set; } + internal CosmosElement CosmosElementContinuationToken { get; set; } internal string StartId { get; set; } @@ -235,18 +242,18 @@ internal override void PopulateRequestOptions(RequestMessage request) request.Headers.Add(HttpConstants.HttpHeaders.ResponseContinuationTokenLimitInKB, this.ResponseContinuationTokenLimitInKb.ToString()); } - if (this.CosmosSerializationFormatOptions != null) + if (this.TransportSerializationFormat != null) { - request.Headers.CosmosMessageHeaders.ContentSerializationFormat = this.CosmosSerializationFormatOptions.ContentSerializationFormat; + request.Headers.CosmosMessageHeaders.ContentSerializationFormat = this.TransportSerializationFormat.ToString(); } - - if (this.SupportedSerializationFormats != null) + else { - request.Headers.CosmosMessageHeaders.SupportedSerializationFormats = this.SupportedSerializationFormats.ToString(); + request.Headers.CosmosMessageHeaders.SupportedSerializationFormats = DocumentQueryExecutionContextBase.DefaultSupportedSerializationFormats; } - else + + if (this.SupportedSerializationFormats != null) { - request.Headers.CosmosMessageHeaders.SupportedSerializationFormats = StoreRequestHeaders.DefaultSupportedSerializationFormats; + request.Headers.CosmosMessageHeaders.SupportedSerializationFormats = this.SupportedSerializationFormats.ToString(); } if (this.StartId != null) diff --git a/Microsoft.Azure.Cosmos/src/Serializer/CosmosSerializationFormatOptions.cs b/Microsoft.Azure.Cosmos/src/Serializer/CosmosSerializationFormatOptions.cs index 81ab5fd1e4..a4b57f85ce 100644 --- a/Microsoft.Azure.Cosmos/src/Serializer/CosmosSerializationFormatOptions.cs +++ b/Microsoft.Azure.Cosmos/src/Serializer/CosmosSerializationFormatOptions.cs @@ -13,12 +13,7 @@ internal sealed class CosmosSerializationFormatOptions public delegate IJsonWriter CreateCustomWriter();         /// -        /// What serialization format to request the response in from the backend -        /// - public string ContentSerializationFormat { get; } - -        /// -        /// Creates a navigator that can navigate a JSON in the specified ContentSerializationFormat +        /// Creates a navigator that can navigate a JSON in the specified SerializationFormat         /// public CreateCustomNavigator CreateCustomNavigatorCallback { get; } @@ -28,15 +23,9 @@ internal sealed class CosmosSerializationFormatOptions public CreateCustomWriter CreateCustomWriterCallback { get; } public CosmosSerializationFormatOptions( - string contentSerializationFormat, CreateCustomNavigator createCustomNavigator, CreateCustomWriter createCustomWriter) { - if (contentSerializationFormat == null) - { - throw new ArgumentNullException(nameof(contentSerializationFormat)); - } - if (createCustomNavigator == null) { throw new ArgumentNullException(nameof(createCustomNavigator)); @@ -47,7 +36,6 @@ public CosmosSerializationFormatOptions( throw new ArgumentNullException(nameof(createCustomWriter)); } - this.ContentSerializationFormat = contentSerializationFormat; this.CreateCustomNavigatorCallback = createCustomNavigator; this.CreateCustomWriterCallback = createCustomWriter; } diff --git a/Microsoft.Azure.Cosmos/src/TransportSerializationFormat.cs b/Microsoft.Azure.Cosmos/src/TransportSerializationFormat.cs new file mode 100644 index 0000000000..d282ccad6c --- /dev/null +++ b/Microsoft.Azure.Cosmos/src/TransportSerializationFormat.cs @@ -0,0 +1,27 @@ +// ------------------------------------------------------------ +// Copyright (c) Microsoft Corporation. All rights reserved. +// ------------------------------------------------------------ + +namespace Microsoft.Azure.Cosmos +{ + using System; + + /// + /// Defines serialization format for query response + /// + /// + /// Requests query response over the wire in specified serialization format. + /// + public enum TransportSerializationFormat + { + /// + /// Plain text + /// + JsonText, + + /// + /// Binary Encoding + /// + CosmosBinary, + } +} diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/CosmosItemTests.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/CosmosItemTests.cs index c5d6347dd1..b64de92c98 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/CosmosItemTests.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/CosmosItemTests.cs @@ -1630,12 +1630,12 @@ public async Task ItemQueryStreamSerializationSetting() QueryDefinition sql = new QueryDefinition("SELECT * FROM toDoActivity t ORDER BY t.taskNum"); CosmosSerializationFormatOptions options = new CosmosSerializationFormatOptions( - ContentSerializationFormat.CosmosBinary.ToString(), (content) => JsonNavigator.Create(content), () => JsonWriter.Create(JsonSerializationFormat.Binary)); QueryRequestOptions requestOptions = new QueryRequestOptions() { + TransportSerializationFormat = TransportSerializationFormat.CosmosBinary, CosmosSerializationFormatOptions = options, MaxConcurrency = 5, MaxItemCount = 5, diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/HeadersValidationTests.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/HeadersValidationTests.cs index 0e2bc8b794..b26ac110ae 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/HeadersValidationTests.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/HeadersValidationTests.cs @@ -13,6 +13,7 @@ namespace Microsoft.Azure.Cosmos.SDK.EmulatorTests using System.Net; using System.Text; using System.Threading.Tasks; + using global::Azure; using Microsoft.Azure.Cosmos.Json; using Microsoft.Azure.Cosmos.Query.Core; using Microsoft.Azure.Cosmos.Routing; @@ -307,6 +308,20 @@ private void ValidateJsonSerializationFormatQuery(DocumentClient client, Documen Assert.IsTrue(response.ResponseBody.ReadByte() == HeadersValidationTests.BinarySerializationByteMarkValue); } + [TestMethod] + [Owner("hdetroja")] + public void TransportSerializationFormatTest() + { + QueryRequestOptions requestOption = new QueryRequestOptions() + { + TransportSerializationFormat = TransportSerializationFormat.CosmosBinary + }; + + RequestMessage testrequestMessage = new RequestMessage(); + requestOption.PopulateRequestOptions(testrequestMessage); + Assert.AreEqual("CosmosBinary", testrequestMessage.Headers.ContentSerializationFormat); + } + [TestMethod] [Owner("hdetroja")] public void ValidateSupportedSerializationFormatsGateway() @@ -381,13 +396,13 @@ private void SupportedSerializationFormatsPositiveCases( DocumentCollection collection, SupportedSerializationFormats expectedFormat, string supportedSerializationFormats, - string contentSerializationFormats, + string transportSerializationFormat, SqlQuerySpec sqlQuerySpec = null) { INameValueCollection headers = new RequestNameValueCollection(); - if(contentSerializationFormats!=null) + if(transportSerializationFormat != null) { - headers.Add(HttpConstants.HttpHeaders.ContentSerializationFormat, contentSerializationFormats); + headers.Add(HttpConstants.HttpHeaders.ContentSerializationFormat, transportSerializationFormat); } headers.Add(HttpConstants.HttpHeaders.SupportedSerializationFormats, supportedSerializationFormats); @@ -420,9 +435,9 @@ private void ValidateSupportedSerializationFormatsReadFeed(DocumentClient client this.SupportedSerializationFormatsNegativeCases(client, collection, "Invalid value"); // Supported values - this.SupportedSerializationFormatsPositiveCases(client, collection, expectedFormat: SupportedSerializationFormats.JsonText, supportedSerializationFormats: "JSONText", contentSerializationFormats: null); - this.SupportedSerializationFormatsPositiveCases(client, collection, expectedFormat: SupportedSerializationFormats.JsonText, supportedSerializationFormats: "COSMOSbinary", contentSerializationFormats: null); - this.SupportedSerializationFormatsPositiveCases(client, collection, expectedFormat: SupportedSerializationFormats.JsonText, supportedSerializationFormats: "JsonText, CosmosBinary", contentSerializationFormats: null); + this.SupportedSerializationFormatsPositiveCases(client, collection, expectedFormat: SupportedSerializationFormats.JsonText, supportedSerializationFormats: "JSONText", transportSerializationFormat: null); + this.SupportedSerializationFormatsPositiveCases(client, collection, expectedFormat: SupportedSerializationFormats.JsonText, supportedSerializationFormats: "COSMOSbinary", transportSerializationFormat: null); + this.SupportedSerializationFormatsPositiveCases(client, collection, expectedFormat: SupportedSerializationFormats.JsonText, supportedSerializationFormats: "JsonText, CosmosBinary", transportSerializationFormat: null); } private void ValidateSupportedSerializationFormatsQuery(DocumentClient client, DocumentCollection collection, SqlQuerySpec sqlQuerySpec) @@ -441,37 +456,37 @@ private void ValidateSupportedSerializationFormatsQuery(DocumentClient client, D this.SupportedSerializationFormatsPositiveCases(client, collection, expectedFormat: SupportedSerializationFormats.JsonText, supportedSerializationFormats: "jsontext", - contentSerializationFormats: null, + transportSerializationFormat: null, sqlQuerySpec: sqlQuerySpec); this.SupportedSerializationFormatsPositiveCases(client, collection, expectedFormat: SupportedSerializationFormats.CosmosBinary, supportedSerializationFormats: "COSMOSBINARY", - contentSerializationFormats: null, + transportSerializationFormat: null, sqlQuerySpec: sqlQuerySpec); this.SupportedSerializationFormatsPositiveCases(client, collection, expectedFormat: SupportedSerializationFormats.JsonText, supportedSerializationFormats: "JsonText, CosmosBinary", - contentSerializationFormats: null, + transportSerializationFormat: null, sqlQuerySpec: sqlQuerySpec); this.SupportedSerializationFormatsPositiveCases(client, collection, expectedFormat: SupportedSerializationFormats.CosmosBinary, supportedSerializationFormats: "CosmosBinary, HybridRow", - contentSerializationFormats: null, + transportSerializationFormat: null, sqlQuerySpec: sqlQuerySpec); this.SupportedSerializationFormatsPositiveCases(client, collection, expectedFormat: SupportedSerializationFormats.JsonText, supportedSerializationFormats: "JsonText, CosmosBinary, HybridRow", - contentSerializationFormats: null, + transportSerializationFormat: null, sqlQuerySpec: sqlQuerySpec); this.SupportedSerializationFormatsPositiveCases(client, collection, expectedFormat: SupportedSerializationFormats.CosmosBinary, supportedSerializationFormats: "JsonText, CosmosBinary, HybridRow", - contentSerializationFormats: "CosmosBinary", + transportSerializationFormat: "CosmosBinary", sqlQuerySpec: sqlQuerySpec); this.SupportedSerializationFormatsPositiveCases(client, collection, expectedFormat: SupportedSerializationFormats.JsonText, supportedSerializationFormats: "JsonText, CosmosBinary, HybridRow", - contentSerializationFormats: "JsonText", + transportSerializationFormat: "JsonText", sqlQuerySpec: sqlQuerySpec); } diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/Query/SupportedSerializationFormatsTest.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/Query/SupportedSerializationFormatsTest.cs index 1406c70b02..10672d00a3 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/Query/SupportedSerializationFormatsTest.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/Query/SupportedSerializationFormatsTest.cs @@ -68,6 +68,24 @@ private async Task TestSupportedSerializationFormatsHelper(Container container, new QueryRequestOptions() { SupportedSerializationFormats = SupportedSerializationFormats.CosmosBinary + }, + new QueryRequestOptions() + { + TransportSerializationFormat = TransportSerializationFormat.JsonText + }, + new QueryRequestOptions() + { + TransportSerializationFormat = TransportSerializationFormat.CosmosBinary + }, + new QueryRequestOptions() + { + TransportSerializationFormat = TransportSerializationFormat.JsonText, + SupportedSerializationFormats = SupportedSerializationFormats.CosmosBinary + }, + new QueryRequestOptions() + { + TransportSerializationFormat = TransportSerializationFormat.CosmosBinary, + SupportedSerializationFormats = SupportedSerializationFormats.JsonText } }; diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/QueryPerfTest/ContentSerializationPerformanceTests.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/QueryPerfTest/ContentSerializationPerformanceTests.cs index c18ac5e420..062ba93322 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/QueryPerfTest/ContentSerializationPerformanceTests.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/QueryPerfTest/ContentSerializationPerformanceTests.cs @@ -83,10 +83,7 @@ private async Task RunQueryAsync(Container container) { MaxConcurrency = this.MaxConcurrency, MaxItemCount = this.MaxItemCount, - CosmosSerializationFormatOptions = new CosmosSerializationFormatOptions( - contentSerializationFormat: this.contentSerialization, - createCustomNavigator: (content) => JsonNavigator.Create(content), - createCustomWriter: () => JsonWriter.Create(this.contentSerialization == "JsonText" ? JsonSerializationFormat.Text : JsonSerializationFormat.Binary)) + TransportSerializationFormat = this.contentSerialization == "JsonText" ? TransportSerializationFormat.JsonText : TransportSerializationFormat.CosmosBinary, }; if (this.useStronglyTypedIterator) diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Performance.Tests/Query/EndToEnd.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Performance.Tests/Query/EndToEnd.cs index 24cb907be8..fb641a6265 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Performance.Tests/Query/EndToEnd.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Performance.Tests/Query/EndToEnd.cs @@ -209,20 +209,14 @@ private static void SetSerializationFormat( QueryRequestOptions queryRequestOptions, JsonSerializationFormat jsonSerializationFormat) { - string contentSerializationFormat = jsonSerializationFormat switch + TransportSerializationFormat contentSerializationFormat = jsonSerializationFormat switch { - JsonSerializationFormat.Text => "JsonText", - JsonSerializationFormat.Binary => "CosmosBinary", - JsonSerializationFormat.HybridRow => "HybridRow", + JsonSerializationFormat.Text => TransportSerializationFormat.JsonText, + JsonSerializationFormat.Binary => TransportSerializationFormat.CosmosBinary, _ => throw new Exception(), }; - CosmosSerializationFormatOptions formatOptions = new CosmosSerializationFormatOptions( - contentSerializationFormat, - (content) => JsonNavigator.Create(content), - () => JsonWriter.Create(JsonSerializationFormat.Text)); - - queryRequestOptions.CosmosSerializationFormatOptions = formatOptions; + queryRequestOptions.TransportSerializationFormat = contentSerializationFormat; } public IEnumerable Data() diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/BinaryEncodingOverTheWireTests.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/BinaryEncodingOverTheWireTests.cs index b55e837844..da5c659d0f 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/BinaryEncodingOverTheWireTests.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/BinaryEncodingOverTheWireTests.cs @@ -249,9 +249,9 @@ async Task AssertQueryDrainsCorrectlyAsync(FeedIterator feedIterator) requestOptions: new QueryRequestOptions() { CosmosSerializationFormatOptions = new CosmosSerializationFormatOptions( - "JsonText", (content) => JsonNavigator.Create(content), () => Cosmos.Json.JsonWriter.Create(JsonSerializationFormat.Text)), + TransportSerializationFormat = TransportSerializationFormat.JsonText, }); await AssertQueryDrainsCorrectlyAsync(textFeedIterator); @@ -261,9 +261,9 @@ async Task AssertQueryDrainsCorrectlyAsync(FeedIterator feedIterator) requestOptions: new QueryRequestOptions() { CosmosSerializationFormatOptions = new CosmosSerializationFormatOptions( - "CosmosBinary", (content) => JsonNavigator.Create(content), () => Cosmos.Json.JsonWriter.Create(JsonSerializationFormat.Text)), + TransportSerializationFormat = TransportSerializationFormat.CosmosBinary }); await AssertQueryDrainsCorrectlyAsync(binaryFeedIterator); diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Query/ContinuationTokens/OrderByQueryResultTests.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Query/ContinuationTokens/OrderByQueryResultTests.cs index 86093aa296..a78229a460 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Query/ContinuationTokens/OrderByQueryResultTests.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Query/ContinuationTokens/OrderByQueryResultTests.cs @@ -33,7 +33,6 @@ public void TestOrderByUndefined() memoryStream, Documents.ResourceType.Document, new CosmosSerializationFormatOptions( - "JsonText", (content) => JsonNavigator.Create(content), () => JsonWriter.Create(JsonSerializationFormat.Text))); diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Query/FeedOptionTests.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Query/FeedOptionTests.cs index 1da167603a..6ad555e804 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Query/FeedOptionTests.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Query/FeedOptionTests.cs @@ -13,6 +13,7 @@ namespace Microsoft.Azure.Cosmos.Query using Microsoft.Azure.Documents; using Microsoft.Azure.Documents.Collections; using Microsoft.Azure.Cosmos.CosmosElements; + using Microsoft.Azure.Cosmos.Tests; [TestClass] public class FeedOptionTests @@ -51,13 +52,15 @@ public void TestCopyConstructor() } [TestMethod] - public async Task TestSupportedSerializationFormatsAsync() + public async Task TestSupportedSerializationFormats() { FeedOptions feedOptions = new FeedOptions(); Mock client = new Mock(MockBehavior.Strict); + client.Setup(x => x.GetDefaultConsistencyLevelAsync()).Returns(Task.FromResult(ConsistencyLevel.BoundedStaleness)); + client.Setup(x => x.GetDesiredConsistencyLevelAsync()).Returns(Task.FromResult(ConsistencyLevel.BoundedStaleness)); Expression> randomFunc = x => x * 2; - TestQueryExecutionContext cxt = new TestQueryExecutionContext( + TestQueryExecutionContext testQueryExecutionContext = new TestQueryExecutionContext( client.Object, ResourceType.Document, typeof(TestQueryExecutionContext), @@ -65,12 +68,16 @@ public async Task TestSupportedSerializationFormatsAsync() feedOptions, string.Empty, true, Guid.NewGuid()); - INameValueCollection headers = await cxt.CreateCommonHeadersAsync(feedOptions); - Assert.AreEqual("JsonText, CosmosBinary", headers[HttpConstants.HttpHeaders.SupportedSerializationFormats]); + INameValueCollection headers = await testQueryExecutionContext.CreateCommonHeadersAsync(feedOptions); + Assert.AreEqual("JsonText,CosmosBinary", headers[HttpConstants.HttpHeaders.SupportedSerializationFormats]); feedOptions.SupportedSerializationFormats = SupportedSerializationFormats.CosmosBinary | SupportedSerializationFormats.HybridRow; - headers = await cxt.CreateCommonHeadersAsync(feedOptions); + headers = await testQueryExecutionContext.CreateCommonHeadersAsync(feedOptions); Assert.AreEqual("CosmosBinary, HybridRow", headers[HttpConstants.HttpHeaders.SupportedSerializationFormats]); + + feedOptions.TransportSerializationFormat = TransportSerializationFormat.CosmosBinary; + headers = await testQueryExecutionContext.CreateCommonHeadersAsync(feedOptions); + Assert.AreEqual("CosmosBinary", headers[HttpConstants.HttpHeaders.ContentSerializationFormat]); } internal class TestQueryExecutionContext : DocumentQueryExecutionContextBase From 0d06a9c8dd35e0a8ad18ffe4bd20e5d73e8e005a Mon Sep 17 00:00:00 2001 From: Heet Date: Mon, 6 Mar 2023 12:54:47 -0800 Subject: [PATCH 18/32] Added new enum TransportSerializationFormat --- .../HeadersValidationTests.cs | 3 +-- .../Query/EndToEnd.cs | 4 ++-- .../Microsoft.Azure.Cosmos.Tests/Query/FeedOptionTests.cs | 1 - 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/HeadersValidationTests.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/HeadersValidationTests.cs index b26ac110ae..5cf69696df 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/HeadersValidationTests.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/HeadersValidationTests.cs @@ -13,7 +13,6 @@ namespace Microsoft.Azure.Cosmos.SDK.EmulatorTests using System.Net; using System.Text; using System.Threading.Tasks; - using global::Azure; using Microsoft.Azure.Cosmos.Json; using Microsoft.Azure.Cosmos.Query.Core; using Microsoft.Azure.Cosmos.Routing; @@ -310,7 +309,7 @@ private void ValidateJsonSerializationFormatQuery(DocumentClient client, Documen [TestMethod] [Owner("hdetroja")] - public void TransportSerializationFormatTest() + public void ValidateTransportSerializationFormat() { QueryRequestOptions requestOption = new QueryRequestOptions() { diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Performance.Tests/Query/EndToEnd.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Performance.Tests/Query/EndToEnd.cs index fb641a6265..5bb0357275 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Performance.Tests/Query/EndToEnd.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Performance.Tests/Query/EndToEnd.cs @@ -209,14 +209,14 @@ private static void SetSerializationFormat( QueryRequestOptions queryRequestOptions, JsonSerializationFormat jsonSerializationFormat) { - TransportSerializationFormat contentSerializationFormat = jsonSerializationFormat switch + TransportSerializationFormat transportSerializationFormat = jsonSerializationFormat switch { JsonSerializationFormat.Text => TransportSerializationFormat.JsonText, JsonSerializationFormat.Binary => TransportSerializationFormat.CosmosBinary, _ => throw new Exception(), }; - queryRequestOptions.TransportSerializationFormat = contentSerializationFormat; + queryRequestOptions.TransportSerializationFormat = transportSerializationFormat; } public IEnumerable Data() diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Query/FeedOptionTests.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Query/FeedOptionTests.cs index 6ad555e804..80eec62bad 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Query/FeedOptionTests.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Query/FeedOptionTests.cs @@ -13,7 +13,6 @@ namespace Microsoft.Azure.Cosmos.Query using Microsoft.Azure.Documents; using Microsoft.Azure.Documents.Collections; using Microsoft.Azure.Cosmos.CosmosElements; - using Microsoft.Azure.Cosmos.Tests; [TestClass] public class FeedOptionTests From 4eb2fa2e6be697b5d10748db50f973f55728214d Mon Sep 17 00:00:00 2001 From: Heet Date: Tue, 7 Mar 2023 09:57:17 -0800 Subject: [PATCH 19/32] Addressed comments --- Microsoft.Azure.Cosmos/src/FeedOptions.cs | 8 ++--- .../DocumentQueryExecutionContextBase.cs | 30 +++++-------------- .../Query/v3Query/CosmosQueryClientCore.cs | 16 ++-------- .../src/RequestOptions/QueryRequestOptions.cs | 15 +++++----- .../CosmosSerializationFormatOptions.cs | 14 --------- .../src/TransportSerializationFormat.cs | 13 ++++---- .../CosmosItemTests.cs | 3 +- .../HeadersValidationTests.cs | 21 +++++++++---- .../SupportedSerializationFormatsTest.cs | 8 ++--- .../ContentSerializationPerformanceTests.cs | 2 +- .../Query/EndToEnd.cs | 4 +-- .../BinaryEncodingOverTheWireTests.cs | 14 ++------- .../OrderByQueryResultTests.cs | 5 +--- .../Query/FeedOptionTests.cs | 2 +- 14 files changed, 53 insertions(+), 102 deletions(-) diff --git a/Microsoft.Azure.Cosmos/src/FeedOptions.cs b/Microsoft.Azure.Cosmos/src/FeedOptions.cs index dd9033cccb..45cbb34285 100644 --- a/Microsoft.Azure.Cosmos/src/FeedOptions.cs +++ b/Microsoft.Azure.Cosmos/src/FeedOptions.cs @@ -358,16 +358,12 @@ internal FeedOptions(FeedOptions options) public ConsistencyLevel? ConsistencyLevel { get; set; } /// - /// Gets or sets the SupportedSerializationFormats for the feed (query/read feed) operation in the Azure Cosmos DB service. + /// Gets or sets the SupportedSerializationFormats for the query response from the service. /// - /// - /// Default value of 'JsonText, CosmosBinary' will be passed if null. The backend will choose the best suited format for the response. - /// public SupportedSerializationFormats? SupportedSerializationFormats { get; set; } /// - /// Gets or sets the serialization format for requests. - /// Request the query response in specifed serialization format. + /// Gets or sets the transport serialization format for the query response from the service. /// public TransportSerializationFormat? TransportSerializationFormat { get; set; } diff --git a/Microsoft.Azure.Cosmos/src/Query/v2Query/DocumentQueryExecutionContextBase.cs b/Microsoft.Azure.Cosmos/src/Query/v2Query/DocumentQueryExecutionContextBase.cs index 6eee7837cb..428ec50485 100644 --- a/Microsoft.Azure.Cosmos/src/Query/v2Query/DocumentQueryExecutionContextBase.cs +++ b/Microsoft.Azure.Cosmos/src/Query/v2Query/DocumentQueryExecutionContextBase.cs @@ -330,17 +330,19 @@ await this.Client.EnsureValidOverwriteAsync( if (this.feedOptions.TransportSerializationFormat != null) { - requestHeaders[HttpConstants.HttpHeaders.ContentSerializationFormat] = this.feedOptions.TransportSerializationFormat.Value.ToString(); - } - else - { - requestHeaders[HttpConstants.HttpHeaders.SupportedSerializationFormats] = DefaultSupportedSerializationFormats; + requestHeaders[HttpConstants.HttpHeaders.ContentSerializationFormat] = this.feedOptions.TransportSerializationFormat == TransportSerializationFormat.Text + ? ContentSerializationFormat.JsonText.ToString() + : ContentSerializationFormat.CosmosBinary.ToString(); } if (this.feedOptions.SupportedSerializationFormats != null) { requestHeaders[HttpConstants.HttpHeaders.SupportedSerializationFormats] = this.feedOptions.SupportedSerializationFormats.Value.ToString(); } + else + { + requestHeaders[HttpConstants.HttpHeaders.SupportedSerializationFormats] = DefaultSupportedSerializationFormats; + } return requestHeaders; } @@ -695,23 +697,7 @@ private DocumentFeedResponse GetFeedResponse( { content = memoryStream.ToArray(); } - - IJsonNavigator jsonNavigator = null; - - // Use the users custom navigator first. If it returns null back try the - // internal navigator. - if (this.feedOptions.CosmosSerializationFormatOptions != null) - { - jsonNavigator = this.feedOptions.CosmosSerializationFormatOptions.CreateCustomNavigatorCallback(content); - if (jsonNavigator == null) - { - throw new InvalidOperationException("The CosmosSerializationOptions did not return a JSON navigator."); - } - } - else - { - jsonNavigator = JsonNavigator.Create(content); - } + IJsonNavigator jsonNavigator = JsonNavigator.Create(content); string resourceName = this.GetRootNodeName(documentServiceRequest.ResourceType); diff --git a/Microsoft.Azure.Cosmos/src/Query/v3Query/CosmosQueryClientCore.cs b/Microsoft.Azure.Cosmos/src/Query/v3Query/CosmosQueryClientCore.cs index 138f32c593..da1072087c 100644 --- a/Microsoft.Azure.Cosmos/src/Query/v3Query/CosmosQueryClientCore.cs +++ b/Microsoft.Azure.Cosmos/src/Query/v3Query/CosmosQueryClientCore.cs @@ -449,7 +449,7 @@ private Task GetRoutingMapProviderAsync() public static CosmosArray ParseElementsFromRestStream( Stream stream, ResourceType resourceType, - CosmosSerializationFormatOptions cosmosSerializationOptions) + CosmosSerializationFormatOptions cosmosSerializationOptions = null) { if (!(stream is MemoryStream memoryStream)) { @@ -479,19 +479,7 @@ public static CosmosArray ParseElementsFromRestStream( ReadOnlyMemory content = memoryStream.TryGetBuffer(out ArraySegment buffer) ? buffer : (ReadOnlyMemory)memoryStream.ToArray(); IJsonNavigator jsonNavigator; - if (cosmosSerializationOptions != null) - { - // Use the users custom navigator - jsonNavigator = cosmosSerializationOptions.CreateCustomNavigatorCallback(content); - if (jsonNavigator == null) - { - throw new InvalidOperationException("The CosmosSerializationOptions did not return a JSON navigator."); - } - } - else - { - jsonNavigator = JsonNavigator.Create(content); - } + jsonNavigator = JsonNavigator.Create(content); string resourceName = resourceType switch { diff --git a/Microsoft.Azure.Cosmos/src/RequestOptions/QueryRequestOptions.cs b/Microsoft.Azure.Cosmos/src/RequestOptions/QueryRequestOptions.cs index bab9a296ce..328c4fab8a 100644 --- a/Microsoft.Azure.Cosmos/src/RequestOptions/QueryRequestOptions.cs +++ b/Microsoft.Azure.Cosmos/src/RequestOptions/QueryRequestOptions.cs @@ -172,8 +172,7 @@ public ConsistencyLevel? ConsistencyLevel public DedicatedGatewayRequestOptions DedicatedGatewayRequestOptions { get; set; } /// - /// Gets or sets the serialization format for requests. - /// Sends the query response over wire in the specified format. + /// Gets or sets the transport serialization format for the query response from the service. /// public TransportSerializationFormat? TransportSerializationFormat { get; set; } @@ -244,17 +243,19 @@ internal override void PopulateRequestOptions(RequestMessage request) if (this.TransportSerializationFormat != null) { - request.Headers.CosmosMessageHeaders.ContentSerializationFormat = this.TransportSerializationFormat.ToString(); - } - else - { - request.Headers.CosmosMessageHeaders.SupportedSerializationFormats = DocumentQueryExecutionContextBase.DefaultSupportedSerializationFormats; + request.Headers.CosmosMessageHeaders.ContentSerializationFormat = this.TransportSerializationFormat == Cosmos.TransportSerializationFormat.Text + ? ContentSerializationFormat.JsonText.ToString() + : ContentSerializationFormat.CosmosBinary.ToString(); } if (this.SupportedSerializationFormats != null) { request.Headers.CosmosMessageHeaders.SupportedSerializationFormats = this.SupportedSerializationFormats.ToString(); } + else + { + request.Headers.CosmosMessageHeaders.SupportedSerializationFormats = DocumentQueryExecutionContextBase.DefaultSupportedSerializationFormats; + } if (this.StartId != null) { diff --git a/Microsoft.Azure.Cosmos/src/Serializer/CosmosSerializationFormatOptions.cs b/Microsoft.Azure.Cosmos/src/Serializer/CosmosSerializationFormatOptions.cs index a4b57f85ce..c83da114a1 100644 --- a/Microsoft.Azure.Cosmos/src/Serializer/CosmosSerializationFormatOptions.cs +++ b/Microsoft.Azure.Cosmos/src/Serializer/CosmosSerializationFormatOptions.cs @@ -8,35 +8,21 @@ namespace Microsoft.Azure.Cosmos internal sealed class CosmosSerializationFormatOptions { - public delegate IJsonNavigator CreateCustomNavigator(ReadOnlyMemory content); - public delegate IJsonWriter CreateCustomWriter(); -        /// -        /// Creates a navigator that can navigate a JSON in the specified SerializationFormat -        /// - public CreateCustomNavigator CreateCustomNavigatorCallback { get; } -         ///         /// Creates a writer to use to write out the stream.         /// public CreateCustomWriter CreateCustomWriterCallback { get; } public CosmosSerializationFormatOptions( - CreateCustomNavigator createCustomNavigator, CreateCustomWriter createCustomWriter) { - if (createCustomNavigator == null) - { - throw new ArgumentNullException(nameof(createCustomNavigator)); - } - if (createCustomWriter == null) { throw new ArgumentNullException(nameof(createCustomWriter)); } - this.CreateCustomNavigatorCallback = createCustomNavigator; this.CreateCustomWriterCallback = createCustomWriter; } } diff --git a/Microsoft.Azure.Cosmos/src/TransportSerializationFormat.cs b/Microsoft.Azure.Cosmos/src/TransportSerializationFormat.cs index d282ccad6c..eeb50c42e8 100644 --- a/Microsoft.Azure.Cosmos/src/TransportSerializationFormat.cs +++ b/Microsoft.Azure.Cosmos/src/TransportSerializationFormat.cs @@ -7,21 +7,18 @@ namespace Microsoft.Azure.Cosmos using System; /// - /// Defines serialization format for query response + /// Specifies the serialization format for query response. /// - /// - /// Requests query response over the wire in specified serialization format. - /// public enum TransportSerializationFormat { /// - /// Plain text + /// Indicates text format to be used for transport serialization. /// - JsonText, + Text, /// - /// Binary Encoding + /// Indicates binary format to be used for transport serialization. /// - CosmosBinary, + Binary, } } diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/CosmosItemTests.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/CosmosItemTests.cs index b64de92c98..95f45246a6 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/CosmosItemTests.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/CosmosItemTests.cs @@ -1630,12 +1630,11 @@ public async Task ItemQueryStreamSerializationSetting() QueryDefinition sql = new QueryDefinition("SELECT * FROM toDoActivity t ORDER BY t.taskNum"); CosmosSerializationFormatOptions options = new CosmosSerializationFormatOptions( - (content) => JsonNavigator.Create(content), () => JsonWriter.Create(JsonSerializationFormat.Binary)); QueryRequestOptions requestOptions = new QueryRequestOptions() { - TransportSerializationFormat = TransportSerializationFormat.CosmosBinary, + TransportSerializationFormat = TransportSerializationFormat.Binary, CosmosSerializationFormatOptions = options, MaxConcurrency = 5, MaxItemCount = 5, diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/HeadersValidationTests.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/HeadersValidationTests.cs index 5cf69696df..681ff94bf3 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/HeadersValidationTests.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/HeadersValidationTests.cs @@ -311,14 +311,25 @@ private void ValidateJsonSerializationFormatQuery(DocumentClient client, Documen [Owner("hdetroja")] public void ValidateTransportSerializationFormat() { - QueryRequestOptions requestOption = new QueryRequestOptions() + List queryRequestOptionsList = new List() { - TransportSerializationFormat = TransportSerializationFormat.CosmosBinary + new QueryRequestOptions() + { + TransportSerializationFormat = TransportSerializationFormat.Binary + }, + new QueryRequestOptions() + { + TransportSerializationFormat = TransportSerializationFormat.Text + } }; - RequestMessage testrequestMessage = new RequestMessage(); - requestOption.PopulateRequestOptions(testrequestMessage); - Assert.AreEqual("CosmosBinary", testrequestMessage.Headers.ContentSerializationFormat); + string[] expectedResults = new[] { "CosmosBinary", "JsonText" }; + for (int i = 0; i < queryRequestOptionsList.Count; i++) + { + RequestMessage testrequestMessage = new RequestMessage(); + queryRequestOptionsList[i].PopulateRequestOptions(testrequestMessage); + Assert.AreEqual(expectedResults[i], testrequestMessage.Headers.ContentSerializationFormat); + } } [TestMethod] diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/Query/SupportedSerializationFormatsTest.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/Query/SupportedSerializationFormatsTest.cs index 10672d00a3..b6368dc4e0 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/Query/SupportedSerializationFormatsTest.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/Query/SupportedSerializationFormatsTest.cs @@ -71,20 +71,20 @@ private async Task TestSupportedSerializationFormatsHelper(Container container, }, new QueryRequestOptions() { - TransportSerializationFormat = TransportSerializationFormat.JsonText + TransportSerializationFormat = TransportSerializationFormat.Text }, new QueryRequestOptions() { - TransportSerializationFormat = TransportSerializationFormat.CosmosBinary + TransportSerializationFormat = TransportSerializationFormat.Binary }, new QueryRequestOptions() { - TransportSerializationFormat = TransportSerializationFormat.JsonText, + TransportSerializationFormat = TransportSerializationFormat.Text, SupportedSerializationFormats = SupportedSerializationFormats.CosmosBinary }, new QueryRequestOptions() { - TransportSerializationFormat = TransportSerializationFormat.CosmosBinary, + TransportSerializationFormat = TransportSerializationFormat.Binary, SupportedSerializationFormats = SupportedSerializationFormats.JsonText } }; diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/QueryPerfTest/ContentSerializationPerformanceTests.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/QueryPerfTest/ContentSerializationPerformanceTests.cs index 062ba93322..cc3d3c707d 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/QueryPerfTest/ContentSerializationPerformanceTests.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/QueryPerfTest/ContentSerializationPerformanceTests.cs @@ -83,7 +83,7 @@ private async Task RunQueryAsync(Container container) { MaxConcurrency = this.MaxConcurrency, MaxItemCount = this.MaxItemCount, - TransportSerializationFormat = this.contentSerialization == "JsonText" ? TransportSerializationFormat.JsonText : TransportSerializationFormat.CosmosBinary, + TransportSerializationFormat = this.contentSerialization == "JsonText" ? TransportSerializationFormat.Text : TransportSerializationFormat.Binary, }; if (this.useStronglyTypedIterator) diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Performance.Tests/Query/EndToEnd.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Performance.Tests/Query/EndToEnd.cs index 5bb0357275..1ee8d0e1cf 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Performance.Tests/Query/EndToEnd.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Performance.Tests/Query/EndToEnd.cs @@ -211,8 +211,8 @@ private static void SetSerializationFormat( { TransportSerializationFormat transportSerializationFormat = jsonSerializationFormat switch { - JsonSerializationFormat.Text => TransportSerializationFormat.JsonText, - JsonSerializationFormat.Binary => TransportSerializationFormat.CosmosBinary, + JsonSerializationFormat.Text => TransportSerializationFormat.Text, + JsonSerializationFormat.Binary => TransportSerializationFormat.Binary, _ => throw new Exception(), }; diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/BinaryEncodingOverTheWireTests.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/BinaryEncodingOverTheWireTests.cs index da5c659d0f..8b3db98a6a 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/BinaryEncodingOverTheWireTests.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/BinaryEncodingOverTheWireTests.cs @@ -245,14 +245,7 @@ async Task AssertQueryDrainsCorrectlyAsync(FeedIterator feedIterator) } FeedIterator textFeedIterator = container.GetItemQueryIterator( - queryDefinition: new QueryDefinition("SELECT * FROM c ORDER BY c._ts"), - requestOptions: new QueryRequestOptions() - { - CosmosSerializationFormatOptions = new CosmosSerializationFormatOptions( - (content) => JsonNavigator.Create(content), - () => Cosmos.Json.JsonWriter.Create(JsonSerializationFormat.Text)), - TransportSerializationFormat = TransportSerializationFormat.JsonText, - }); + queryDefinition: new QueryDefinition("SELECT * FROM c ORDER BY c._ts")); await AssertQueryDrainsCorrectlyAsync(textFeedIterator); @@ -260,10 +253,7 @@ async Task AssertQueryDrainsCorrectlyAsync(FeedIterator feedIterator) queryDefinition: new QueryDefinition("SELECT * FROM c ORDER BY c._ts"), requestOptions: new QueryRequestOptions() { - CosmosSerializationFormatOptions = new CosmosSerializationFormatOptions( - (content) => JsonNavigator.Create(content), - () => Cosmos.Json.JsonWriter.Create(JsonSerializationFormat.Text)), - TransportSerializationFormat = TransportSerializationFormat.CosmosBinary + TransportSerializationFormat = TransportSerializationFormat.Binary }); await AssertQueryDrainsCorrectlyAsync(binaryFeedIterator); diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Query/ContinuationTokens/OrderByQueryResultTests.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Query/ContinuationTokens/OrderByQueryResultTests.cs index a78229a460..7207f897be 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Query/ContinuationTokens/OrderByQueryResultTests.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Query/ContinuationTokens/OrderByQueryResultTests.cs @@ -31,10 +31,7 @@ public void TestOrderByUndefined() CosmosArray documents = CosmosQueryClientCore.ParseElementsFromRestStream( memoryStream, - Documents.ResourceType.Document, - new CosmosSerializationFormatOptions( - (content) => JsonNavigator.Create(content), - () => JsonWriter.Create(JsonSerializationFormat.Text))); + Documents.ResourceType.Document); List orderByQueryResults = documents.Select(x => new OrderByQueryResult(x)).ToList(); Assert.AreEqual(14, orderByQueryResults.Count); diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Query/FeedOptionTests.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Query/FeedOptionTests.cs index 80eec62bad..769329cd45 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Query/FeedOptionTests.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Query/FeedOptionTests.cs @@ -74,7 +74,7 @@ public async Task TestSupportedSerializationFormats() headers = await testQueryExecutionContext.CreateCommonHeadersAsync(feedOptions); Assert.AreEqual("CosmosBinary, HybridRow", headers[HttpConstants.HttpHeaders.SupportedSerializationFormats]); - feedOptions.TransportSerializationFormat = TransportSerializationFormat.CosmosBinary; + feedOptions.TransportSerializationFormat = TransportSerializationFormat.Binary; headers = await testQueryExecutionContext.CreateCommonHeadersAsync(feedOptions); Assert.AreEqual("CosmosBinary", headers[HttpConstants.HttpHeaders.ContentSerializationFormat]); } From 4b71297b159443c247aebdd1411d51e282a30b67 Mon Sep 17 00:00:00 2001 From: Heet Date: Tue, 7 Mar 2023 10:09:01 -0800 Subject: [PATCH 20/32] Removed unused parameter --- .../src/Query/v3Query/CosmosQueryClientCore.cs | 12 +++--------- .../ReadFeedCrossFeedRangeAsyncEnumerator.cs | 3 +-- 2 files changed, 4 insertions(+), 11 deletions(-) diff --git a/Microsoft.Azure.Cosmos/src/Query/v3Query/CosmosQueryClientCore.cs b/Microsoft.Azure.Cosmos/src/Query/v3Query/CosmosQueryClientCore.cs index da1072087c..df40a343ad 100644 --- a/Microsoft.Azure.Cosmos/src/Query/v3Query/CosmosQueryClientCore.cs +++ b/Microsoft.Azure.Cosmos/src/Query/v3Query/CosmosQueryClientCore.cs @@ -155,7 +155,6 @@ public override async Task> ExecuteItemQueryAsync( cancellationToken: cancellationToken); return CosmosQueryClientCore.GetCosmosElementResponse( - requestOptions, resourceType, message, trace); @@ -297,7 +296,6 @@ public override void ClearSessionTokenCache(string collectionFullName) } private static TryCatch GetCosmosElementResponse( - QueryRequestOptions requestOptions, ResourceType resourceType, ResponseMessage cosmosResponseMessage, ITrace trace) @@ -336,8 +334,7 @@ private static TryCatch GetCosmosElementResponse( long responseLengthBytes = memoryStream.Length; CosmosArray documents = CosmosQueryClientCore.ParseElementsFromRestStream( memoryStream, - resourceType, - requestOptions.CosmosSerializationFormatOptions); + resourceType); QueryState queryState; if (cosmosResponseMessage.Headers.ContinuationToken != null) @@ -444,12 +441,10 @@ private Task GetRoutingMapProviderAsync() /// /// The memory stream response for the query REST response Azure Cosmos /// The resource type - /// The custom serialization options. This allows custom serialization types like BSON, JSON, or other formats /// An array of CosmosElements parsed from the response body. public static CosmosArray ParseElementsFromRestStream( Stream stream, - ResourceType resourceType, - CosmosSerializationFormatOptions cosmosSerializationOptions = null) + ResourceType resourceType) { if (!(stream is MemoryStream memoryStream)) { @@ -478,8 +473,7 @@ public static CosmosArray ParseElementsFromRestStream( // You want to create a CosmosElement for each document in "Documents". ReadOnlyMemory content = memoryStream.TryGetBuffer(out ArraySegment buffer) ? buffer : (ReadOnlyMemory)memoryStream.ToArray(); - IJsonNavigator jsonNavigator; - jsonNavigator = JsonNavigator.Create(content); + IJsonNavigator jsonNavigator = JsonNavigator.Create(content); string resourceName = resourceType switch { diff --git a/Microsoft.Azure.Cosmos/src/ReadFeed/ReadFeedCrossFeedRangeAsyncEnumerator.cs b/Microsoft.Azure.Cosmos/src/ReadFeed/ReadFeedCrossFeedRangeAsyncEnumerator.cs index 2f611840f7..95fb8b23cf 100644 --- a/Microsoft.Azure.Cosmos/src/ReadFeed/ReadFeedCrossFeedRangeAsyncEnumerator.cs +++ b/Microsoft.Azure.Cosmos/src/ReadFeed/ReadFeedCrossFeedRangeAsyncEnumerator.cs @@ -45,8 +45,7 @@ public async ValueTask MoveNextAsync() CosmosArray documents = CosmosQueryClientCore.ParseElementsFromRestStream( innerReadFeedPage.Page.Content, - Documents.ResourceType.Document, - cosmosSerializationOptions: null); + Documents.ResourceType.Document); ReadFeedPage page = new ReadFeedPage( documents, innerReadFeedPage.Page.RequestCharge, From 1e2451bce9292fde45b74675ac91e3e250630f52 Mon Sep 17 00:00:00 2001 From: Heet Date: Tue, 14 Mar 2023 10:51:26 -0700 Subject: [PATCH 21/32] Addressed comments --- Microsoft.Azure.Cosmos/src/FeedOptions.cs | 48 +++++++++---------- .../DocumentQueryExecutionContextBase.cs | 21 ++++---- .../src/RequestOptions/QueryRequestOptions.cs | 21 ++++---- .../src/TransportSerializationFormat.cs | 8 ++-- .../HeadersValidationTests.cs | 6 +-- 5 files changed, 51 insertions(+), 53 deletions(-) diff --git a/Microsoft.Azure.Cosmos/src/FeedOptions.cs b/Microsoft.Azure.Cosmos/src/FeedOptions.cs index 45cbb34285..382feb149c 100644 --- a/Microsoft.Azure.Cosmos/src/FeedOptions.cs +++ b/Microsoft.Azure.Cosmos/src/FeedOptions.cs @@ -24,7 +24,7 @@ public FeedOptions() { } - internal FeedOptions(FeedOptions options) + public FeedOptions(FeedOptions options) { if (options == null) { @@ -283,7 +283,7 @@ internal FeedOptions(FeedOptions options) /// /// Option is true if query tracing is enabled; otherwise, false. /// - internal bool? EmitVerboseTracesInQuery { get; set; } + public bool? EmitVerboseTracesInQuery { get; set; } /// /// Gets or sets the schema rid which could be used to filter the document feed response @@ -293,7 +293,7 @@ internal FeedOptions(FeedOptions options) /// By default, it is null which means no filtering will be applied. /// Otherwise, it must be a valid resource id of Schema resource. /// - internal string FilterBySchemaResourceId { get; set; } + public string FilterBySchemaResourceId { get; set; } /// /// Gets or sets the request option for document query requests in the Azure Cosmos DB service. @@ -357,70 +357,70 @@ internal FeedOptions(FeedOptions options) /// public ConsistencyLevel? ConsistencyLevel { get; set; } - /// - /// Gets or sets the SupportedSerializationFormats for the query response from the service. - /// - public SupportedSerializationFormats? SupportedSerializationFormats { get; set; } - - /// - /// Gets or sets the transport serialization format for the query response from the service. - /// - public TransportSerializationFormat? TransportSerializationFormat { get; set; } - /// /// Gets or sets the flag that tells the backend to forces the query to perform a scan (at a request level). /// - internal bool ForceQueryScan { get; set; } + public bool ForceQueryScan { get; set; } /// /// Gets or sets the EnumerationDirection /// To be used along with Read feed operation /// - internal EnumerationDirection? EnumerationDirection { get; set; } + public EnumerationDirection? EnumerationDirection { get; set; } /// /// Gets or sets the ReadFeedKeyType /// To be used along with Read feed operation /// - internal ReadFeedKeyType? ReadFeedKeyType { get; set; } + public ReadFeedKeyType? ReadFeedKeyType { get; set; } /// /// Gets or sets the StartId /// To be used along with Read feed operation /// - internal string StartId { get; set; } + public string StartId { get; set; } /// /// Gets or sets the EndId /// To be used along with Read feed operation /// - internal string EndId { get; set; } + public string EndId { get; set; } /// /// Gets or sets the StartEpk /// To be used along with Read feed operation /// - internal string StartEpk { get; set; } + public string StartEpk { get; set; } /// /// Gets or sets the EndEpk /// To be used along with Read feed operation /// - internal string EndEpk { get; set; } + public string EndEpk { get; set; } + + /// + /// Gets or sets the SupportedSerializationFormats for the query response from the service. + /// + public SupportedSerializationFormats? SupportedSerializationFormats { get; set; } + + /// + /// Gets or sets the transport serialization format for the query response from the service. + /// + public TransportSerializationFormat? TransportSerializationFormat { get; set; } - internal bool EnableGroupBy { get; set; } + public bool EnableGroupBy { get; set; } /// /// Gets or sets the MergeStaticId. /// To be used along with Read feed operation when Static Column merge is desired. /// - internal string MergeStaticId { get; set; } + public string MergeStaticId { get; set; } /// /// Gets or sets the custom serialization options for query /// - internal CosmosSerializationFormatOptions CosmosSerializationFormatOptions { get; set; } + public CosmosSerializationFormatOptions CosmosSerializationFormatOptions { get; set; } - internal IDictionary Properties { get; set; } + public IDictionary Properties { get; set; } } } diff --git a/Microsoft.Azure.Cosmos/src/Query/v2Query/DocumentQueryExecutionContextBase.cs b/Microsoft.Azure.Cosmos/src/Query/v2Query/DocumentQueryExecutionContextBase.cs index 428ec50485..6fc57e89b6 100644 --- a/Microsoft.Azure.Cosmos/src/Query/v2Query/DocumentQueryExecutionContextBase.cs +++ b/Microsoft.Azure.Cosmos/src/Query/v2Query/DocumentQueryExecutionContextBase.cs @@ -6,6 +6,7 @@ namespace Microsoft.Azure.Cosmos.Query { using System; using System.Collections.Generic; + using System.ComponentModel; using System.Globalization; using System.IO; using System.Linq; @@ -330,19 +331,17 @@ await this.Client.EnsureValidOverwriteAsync( if (this.feedOptions.TransportSerializationFormat != null) { - requestHeaders[HttpConstants.HttpHeaders.ContentSerializationFormat] = this.feedOptions.TransportSerializationFormat == TransportSerializationFormat.Text - ? ContentSerializationFormat.JsonText.ToString() - : ContentSerializationFormat.CosmosBinary.ToString(); + requestHeaders[HttpConstants.HttpHeaders.ContentSerializationFormat] = this.feedOptions.TransportSerializationFormat switch + { + TransportSerializationFormat.Binary => ContentSerializationFormat.CosmosBinary.ToString(), + TransportSerializationFormat.Text => ContentSerializationFormat.JsonText.ToString(), + _ => throw new InvalidEnumArgumentException(), + }; } - if (this.feedOptions.SupportedSerializationFormats != null) - { - requestHeaders[HttpConstants.HttpHeaders.SupportedSerializationFormats] = this.feedOptions.SupportedSerializationFormats.Value.ToString(); - } - else - { - requestHeaders[HttpConstants.HttpHeaders.SupportedSerializationFormats] = DefaultSupportedSerializationFormats; - } + requestHeaders[HttpConstants.HttpHeaders.SupportedSerializationFormats] = this.feedOptions.SupportedSerializationFormats != null + ? this.feedOptions.SupportedSerializationFormats.Value.ToString() + : DefaultSupportedSerializationFormats; return requestHeaders; } diff --git a/Microsoft.Azure.Cosmos/src/RequestOptions/QueryRequestOptions.cs b/Microsoft.Azure.Cosmos/src/RequestOptions/QueryRequestOptions.cs index 328c4fab8a..cd99ed7536 100644 --- a/Microsoft.Azure.Cosmos/src/RequestOptions/QueryRequestOptions.cs +++ b/Microsoft.Azure.Cosmos/src/RequestOptions/QueryRequestOptions.cs @@ -5,6 +5,7 @@ namespace Microsoft.Azure.Cosmos { using System; + using System.ComponentModel; using System.Text; using Microsoft.Azure.Cosmos.CosmosElements; using Microsoft.Azure.Cosmos.Query; @@ -243,19 +244,17 @@ internal override void PopulateRequestOptions(RequestMessage request) if (this.TransportSerializationFormat != null) { - request.Headers.CosmosMessageHeaders.ContentSerializationFormat = this.TransportSerializationFormat == Cosmos.TransportSerializationFormat.Text - ? ContentSerializationFormat.JsonText.ToString() - : ContentSerializationFormat.CosmosBinary.ToString(); + request.Headers.CosmosMessageHeaders.ContentSerializationFormat = this.TransportSerializationFormat switch + { + Cosmos.TransportSerializationFormat.Binary => ContentSerializationFormat.CosmosBinary.ToString(), + Cosmos.TransportSerializationFormat.Text => ContentSerializationFormat.JsonText.ToString(), + _ => throw new InvalidEnumArgumentException(), + }; } - if (this.SupportedSerializationFormats != null) - { - request.Headers.CosmosMessageHeaders.SupportedSerializationFormats = this.SupportedSerializationFormats.ToString(); - } - else - { - request.Headers.CosmosMessageHeaders.SupportedSerializationFormats = DocumentQueryExecutionContextBase.DefaultSupportedSerializationFormats; - } + request.Headers.CosmosMessageHeaders.SupportedSerializationFormats = this.SupportedSerializationFormats != null + ? this.SupportedSerializationFormats.ToString() + : DocumentQueryExecutionContextBase.DefaultSupportedSerializationFormats; if (this.StartId != null) { diff --git a/Microsoft.Azure.Cosmos/src/TransportSerializationFormat.cs b/Microsoft.Azure.Cosmos/src/TransportSerializationFormat.cs index eeb50c42e8..4398815138 100644 --- a/Microsoft.Azure.Cosmos/src/TransportSerializationFormat.cs +++ b/Microsoft.Azure.Cosmos/src/TransportSerializationFormat.cs @@ -12,13 +12,13 @@ namespace Microsoft.Azure.Cosmos public enum TransportSerializationFormat { /// - /// Indicates text format to be used for transport serialization. + /// Indicates binary format to be used for transport serialization. /// - Text, + Binary, /// - /// Indicates binary format to be used for transport serialization. + /// Indicates text format to be used for transport serialization. /// - Binary, + Text, } } diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/HeadersValidationTests.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/HeadersValidationTests.cs index 681ff94bf3..7669b48dd7 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/HeadersValidationTests.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/HeadersValidationTests.cs @@ -315,7 +315,7 @@ public void ValidateTransportSerializationFormat() { new QueryRequestOptions() { - TransportSerializationFormat = TransportSerializationFormat.Binary + TransportSerializationFormat = TransportSerializationFormat.Binary }, new QueryRequestOptions() { @@ -375,11 +375,11 @@ private void ValidateSupportedSerializationFormats(DocumentClient client) private void SupportedSerializationFormatsNegativeCases( DocumentClient client, DocumentCollection collection, - string value, + string invalidValue, SqlQuerySpec sqlQuerySpec = null) { INameValueCollection headers = new RequestNameValueCollection(); - headers.Add(HttpConstants.HttpHeaders.SupportedSerializationFormats, value); + headers.Add(HttpConstants.HttpHeaders.SupportedSerializationFormats, invalidValue); try { From f79c6684159705d795fde56b103ed7a4b1743db6 Mon Sep 17 00:00:00 2001 From: Maya-Painter Date: Thu, 1 Jun 2023 11:52:41 -0700 Subject: [PATCH 22/32] updating API --- .../Contracts/DotNetSDKAPI.json | 59 +++++++++++++++++++ 1 file changed, 59 insertions(+) diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Contracts/DotNetSDKAPI.json b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Contracts/DotNetSDKAPI.json index e5b95a7ed9..8f17c1164c 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Contracts/DotNetSDKAPI.json +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Contracts/DotNetSDKAPI.json @@ -6313,6 +6313,18 @@ "Attributes": [], "MethodInfo": "System.Nullable`1[Microsoft.Azure.Cosmos.PartitionKey] PartitionKey;CanRead:True;CanWrite:True;System.Nullable`1[Microsoft.Azure.Cosmos.PartitionKey] get_PartitionKey();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;Void set_PartitionKey(System.Nullable`1[Microsoft.Azure.Cosmos.PartitionKey]);IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" }, + "System.Nullable`1[Microsoft.Azure.Cosmos.TransportSerializationFormat] get_TransportSerializationFormat()[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]": { + "Type": "Method", + "Attributes": [ + "CompilerGeneratedAttribute" + ], + "MethodInfo": "System.Nullable`1[Microsoft.Azure.Cosmos.TransportSerializationFormat] get_TransportSerializationFormat();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" + }, + "System.Nullable`1[Microsoft.Azure.Cosmos.TransportSerializationFormat] TransportSerializationFormat": { + "Type": "Property", + "Attributes": [], + "MethodInfo": "System.Nullable`1[Microsoft.Azure.Cosmos.TransportSerializationFormat] TransportSerializationFormat;CanRead:True;CanWrite:True;System.Nullable`1[Microsoft.Azure.Cosmos.TransportSerializationFormat] get_TransportSerializationFormat();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;Void set_TransportSerializationFormat(System.Nullable`1[Microsoft.Azure.Cosmos.TransportSerializationFormat]);IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" + }, "System.Nullable`1[System.Boolean] EnableLowPrecisionOrderBy": { "Type": "Property", "Attributes": [], @@ -6488,6 +6500,13 @@ "CompilerGeneratedAttribute" ], "MethodInfo": "Void set_SessionToken(System.String);IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" + }, + "Void set_TransportSerializationFormat(System.Nullable`1[Microsoft.Azure.Cosmos.TransportSerializationFormat])[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]": { + "Type": "Method", + "Attributes": [ + "CompilerGeneratedAttribute" + ], + "MethodInfo": "Void set_TransportSerializationFormat(System.Nullable`1[Microsoft.Azure.Cosmos.TransportSerializationFormat]);IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" } }, "NestedTypes": {} @@ -7335,6 +7354,18 @@ "Attributes": [], "MethodInfo": "System.Nullable`1[Microsoft.Azure.Cosmos.PartitionKey] PartitionKey;CanRead:True;CanWrite:True;System.Nullable`1[Microsoft.Azure.Cosmos.PartitionKey] get_PartitionKey();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;Void set_PartitionKey(System.Nullable`1[Microsoft.Azure.Cosmos.PartitionKey]);IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" }, + "System.Nullable`1[Microsoft.Azure.Cosmos.TransportSerializationFormat] get_TransportSerializationFormat()[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]": { + "Type": "Method", + "Attributes": [ + "CompilerGeneratedAttribute" + ], + "MethodInfo": "System.Nullable`1[Microsoft.Azure.Cosmos.TransportSerializationFormat] get_TransportSerializationFormat();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" + }, + "System.Nullable`1[Microsoft.Azure.Cosmos.TransportSerializationFormat] TransportSerializationFormat": { + "Type": "Property", + "Attributes": [], + "MethodInfo": "System.Nullable`1[Microsoft.Azure.Cosmos.TransportSerializationFormat] TransportSerializationFormat;CanRead:True;CanWrite:True;System.Nullable`1[Microsoft.Azure.Cosmos.TransportSerializationFormat] get_TransportSerializationFormat();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;Void set_TransportSerializationFormat(System.Nullable`1[Microsoft.Azure.Cosmos.TransportSerializationFormat]);IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" + }, "System.Nullable`1[System.Boolean] EnableLowPrecisionOrderBy": { "Type": "Property", "Attributes": [], @@ -7510,6 +7541,13 @@ "CompilerGeneratedAttribute" ], "MethodInfo": "Void set_SessionToken(System.String);IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" + }, + "Void set_TransportSerializationFormat(System.Nullable`1[Microsoft.Azure.Cosmos.TransportSerializationFormat])[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]": { + "Type": "Method", + "Attributes": [ + "CompilerGeneratedAttribute" + ], + "MethodInfo": "Void set_TransportSerializationFormat(System.Nullable`1[Microsoft.Azure.Cosmos.TransportSerializationFormat]);IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" } }, "NestedTypes": {} @@ -10929,6 +10967,27 @@ }, "NestedTypes": {} }, + "Microsoft.Azure.Cosmos.TransportSerializationFormat;System.Enum;IsAbstract:False;IsSealed:True;IsInterface:False;IsEnum:True;IsClass:False;IsValueType:True;IsNested:False;IsGenericType:False;IsSerializable:True": { + "Subclasses": {}, + "Members": { + "Int32 value__": { + "Type": "Field", + "Attributes": [], + "MethodInfo": "Int32 value__;IsInitOnly:False;IsStatic:False;" + }, + "Microsoft.Azure.Cosmos.TransportSerializationFormat Binary": { + "Type": "Field", + "Attributes": [], + "MethodInfo": "Microsoft.Azure.Cosmos.TransportSerializationFormat Binary;IsInitOnly:False;IsStatic:True;" + }, + "Microsoft.Azure.Cosmos.TransportSerializationFormat Text": { + "Type": "Field", + "Attributes": [], + "MethodInfo": "Microsoft.Azure.Cosmos.TransportSerializationFormat Text;IsInitOnly:False;IsStatic:True;" + } + }, + "NestedTypes": {} + }, "Microsoft.Azure.Cosmos.UniqueKey;System.Object;IsAbstract:False;IsSealed:False;IsInterface:False;IsEnum:False;IsClass:True;IsValueType:False;IsNested:False;IsGenericType:False;IsSerializable:False": { "Subclasses": {}, "Members": { From 9352b1a7835418c7b84fa45c4ae682e533a67015 Mon Sep 17 00:00:00 2001 From: Maya-Painter Date: Tue, 13 Jun 2023 15:14:57 -0700 Subject: [PATCH 23/32] remove tests --- .../HeadersValidationTests.cs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/HeadersValidationTests.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/HeadersValidationTests.cs index 7669b48dd7..358928e262 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/HeadersValidationTests.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/HeadersValidationTests.cs @@ -389,6 +389,7 @@ private void SupportedSerializationFormatsNegativeCases( } else { + headers.Set(HttpConstants.HttpHeaders.PartitionKey, "[\"test\"]"); this.ReadDocumentFeedRequestSinglePartition(client, collection.ResourceId, headers); } @@ -468,31 +469,37 @@ private void ValidateSupportedSerializationFormatsQuery(DocumentClient client, D supportedSerializationFormats: "jsontext", transportSerializationFormat: null, sqlQuerySpec: sqlQuerySpec); + /* this.SupportedSerializationFormatsPositiveCases(client, collection, expectedFormat: SupportedSerializationFormats.CosmosBinary, supportedSerializationFormats: "COSMOSBINARY", transportSerializationFormat: null, sqlQuerySpec: sqlQuerySpec); + */ this.SupportedSerializationFormatsPositiveCases(client, collection, expectedFormat: SupportedSerializationFormats.JsonText, supportedSerializationFormats: "JsonText, CosmosBinary", transportSerializationFormat: null, sqlQuerySpec: sqlQuerySpec); + /* this.SupportedSerializationFormatsPositiveCases(client, collection, expectedFormat: SupportedSerializationFormats.CosmosBinary, supportedSerializationFormats: "CosmosBinary, HybridRow", transportSerializationFormat: null, sqlQuerySpec: sqlQuerySpec); + */ this.SupportedSerializationFormatsPositiveCases(client, collection, expectedFormat: SupportedSerializationFormats.JsonText, supportedSerializationFormats: "JsonText, CosmosBinary, HybridRow", transportSerializationFormat: null, sqlQuerySpec: sqlQuerySpec); + /* this.SupportedSerializationFormatsPositiveCases(client, collection, expectedFormat: SupportedSerializationFormats.CosmosBinary, supportedSerializationFormats: "JsonText, CosmosBinary, HybridRow", transportSerializationFormat: "CosmosBinary", sqlQuerySpec: sqlQuerySpec); + */ this.SupportedSerializationFormatsPositiveCases(client, collection, expectedFormat: SupportedSerializationFormats.JsonText, supportedSerializationFormats: "JsonText, CosmosBinary, HybridRow", From a5b16ca3ca0e87d3bfeff9e342b17f269285a988 Mon Sep 17 00:00:00 2001 From: Maya-Painter Date: Tue, 13 Jun 2023 23:23:22 -0700 Subject: [PATCH 24/32] Text fixes --- .../HeadersValidationTests.cs | 51 +++++++++++-------- 1 file changed, 31 insertions(+), 20 deletions(-) diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/HeadersValidationTests.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/HeadersValidationTests.cs index 358928e262..e6a6a21e2a 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/HeadersValidationTests.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/HeadersValidationTests.cs @@ -337,27 +337,27 @@ public void ValidateTransportSerializationFormat() public void ValidateSupportedSerializationFormatsGateway() { DocumentClient client = TestCommon.CreateClient(true); - this.ValidateSupportedSerializationFormats(client); + this.ValidateSupportedSerializationFormats(client, true); } [TestMethod] public void ValidateSupportedSerializationFormatsRntbd() { DocumentClient client = TestCommon.CreateClient(false, Protocol.Tcp); - this.ValidateSupportedSerializationFormats(client); + this.ValidateSupportedSerializationFormats(client, false); } [TestMethod] public void ValidateSupportedSerializationFormatsHttps() { DocumentClient client = TestCommon.CreateClient(false, Protocol.Https); - this.ValidateSupportedSerializationFormats(client); + this.ValidateSupportedSerializationFormats(client, true); } - private void ValidateSupportedSerializationFormats(DocumentClient client) + private void ValidateSupportedSerializationFormats(DocumentClient client, bool isHttps) { DocumentCollection collection = TestCommon.CreateOrGetDocumentCollection(client); - this.ValidateSupportedSerializationFormatsReadFeed(client, collection); + this.ValidateSupportedSerializationFormatsReadFeed(client, collection, isHttps); List sqlQueryList = new List() { @@ -368,7 +368,7 @@ private void ValidateSupportedSerializationFormats(DocumentClient client) foreach(SqlQuerySpec sqlQuery in sqlQueryList) { - this.ValidateSupportedSerializationFormatsQuery(client, collection, sqlQuery); + this.ValidateSupportedSerializationFormatsQuery(client, collection, sqlQuery, isHttps); } } @@ -376,6 +376,7 @@ private void SupportedSerializationFormatsNegativeCases( DocumentClient client, DocumentCollection collection, string invalidValue, + bool isHttps, SqlQuerySpec sqlQuerySpec = null) { INameValueCollection headers = new RequestNameValueCollection(); @@ -383,17 +384,27 @@ private void SupportedSerializationFormatsNegativeCases( try { + DocumentServiceResponse response; if (sqlQuerySpec != null) { - this.QueryRequest(client, collection.ResourceId, sqlQuerySpec, headers); + response = this.QueryRequest(client, collection.ResourceId, sqlQuerySpec, headers); } else { headers.Set(HttpConstants.HttpHeaders.PartitionKey, "[\"test\"]"); - this.ReadDocumentFeedRequestSinglePartition(client, collection.ResourceId, headers); + response = this.ReadDocumentFeedRequestSinglePartition(client, collection.ResourceId, headers); } - Assert.Fail("Should throw an exception"); + if (isHttps) + { + // Invalid value is treated as default JsonText if HTTPS + Assert.IsTrue(response.StatusCode == HttpStatusCode.OK, "Invalid status code"); + Assert.IsTrue(this.CheckSerializationFormat(response) == JsonSerializationFormat.Text); + } + else + { + Assert.Fail("Should throw an exception"); + } } catch (Exception ex) { @@ -440,10 +451,10 @@ private void SupportedSerializationFormatsPositiveCases( } } - private void ValidateSupportedSerializationFormatsReadFeed(DocumentClient client, DocumentCollection collection) + private void ValidateSupportedSerializationFormatsReadFeed(DocumentClient client, DocumentCollection collection, bool isHttps) { // Value not supported - this.SupportedSerializationFormatsNegativeCases(client, collection, "Invalid value"); + this.SupportedSerializationFormatsNegativeCases(client, collection, "Invalid value", isHttps); // Supported values this.SupportedSerializationFormatsPositiveCases(client, collection, expectedFormat: SupportedSerializationFormats.JsonText, supportedSerializationFormats: "JSONText", transportSerializationFormat: null); @@ -451,17 +462,17 @@ private void ValidateSupportedSerializationFormatsReadFeed(DocumentClient client this.SupportedSerializationFormatsPositiveCases(client, collection, expectedFormat: SupportedSerializationFormats.JsonText, supportedSerializationFormats: "JsonText, CosmosBinary", transportSerializationFormat: null); } - private void ValidateSupportedSerializationFormatsQuery(DocumentClient client, DocumentCollection collection, SqlQuerySpec sqlQuerySpec) + private void ValidateSupportedSerializationFormatsQuery(DocumentClient client, DocumentCollection collection, SqlQuerySpec sqlQuerySpec, bool isHttps) { // Values not supported - this.SupportedSerializationFormatsNegativeCases(client, collection, "Invalid value", sqlQuerySpec:sqlQuerySpec); - this.SupportedSerializationFormatsNegativeCases(client, collection, ", ,", sqlQuerySpec: sqlQuerySpec); - this.SupportedSerializationFormatsNegativeCases(client, collection, ",,", sqlQuerySpec: sqlQuerySpec); - this.SupportedSerializationFormatsNegativeCases(client, collection, "JsonText CosmosBinary", sqlQuerySpec: sqlQuerySpec); - this.SupportedSerializationFormatsNegativeCases(client, collection, ",JsonText|CosmosBinary", sqlQuerySpec: sqlQuerySpec); - this.SupportedSerializationFormatsNegativeCases(client, collection, "Json Text", sqlQuerySpec: sqlQuerySpec); - this.SupportedSerializationFormatsNegativeCases(client, collection, "Json,Text", sqlQuerySpec: sqlQuerySpec); - this.SupportedSerializationFormatsNegativeCases(client, collection, "JsonText, ", sqlQuerySpec: sqlQuerySpec); + this.SupportedSerializationFormatsNegativeCases(client, collection, "Invalid value", isHttps, sqlQuerySpec: sqlQuerySpec); + this.SupportedSerializationFormatsNegativeCases(client, collection, ", ,", isHttps, sqlQuerySpec: sqlQuerySpec); + this.SupportedSerializationFormatsNegativeCases(client, collection, ",,", isHttps, sqlQuerySpec: sqlQuerySpec); + this.SupportedSerializationFormatsNegativeCases(client, collection, "JsonText CosmosBinary", isHttps, sqlQuerySpec: sqlQuerySpec); + this.SupportedSerializationFormatsNegativeCases(client, collection, ",JsonText|CosmosBinary", isHttps, sqlQuerySpec: sqlQuerySpec); + this.SupportedSerializationFormatsNegativeCases(client, collection, "Json Text", isHttps, sqlQuerySpec: sqlQuerySpec); + this.SupportedSerializationFormatsNegativeCases(client, collection, "Json,Text", isHttps, sqlQuerySpec: sqlQuerySpec); + this.SupportedSerializationFormatsNegativeCases(client, collection, "JsonText, ", isHttps, sqlQuerySpec: sqlQuerySpec); // Supported values this.SupportedSerializationFormatsPositiveCases(client, collection, From f083f64345928787e011df865f26ef8c28859abc Mon Sep 17 00:00:00 2001 From: Maya-Painter Date: Wed, 14 Jun 2023 10:33:55 -0700 Subject: [PATCH 25/32] fix typo --- .../HeadersValidationTests.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/HeadersValidationTests.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/HeadersValidationTests.cs index e6a6a21e2a..63fd8a60a9 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/HeadersValidationTests.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/HeadersValidationTests.cs @@ -165,17 +165,17 @@ private void ValidatePageSize(DocumentClient client) public async Task ValidateConsistencyLevelGateway() { DocumentClient client = TestCommon.CreateClient(true); - await ValidateCosistencyLevel(client); + await ValidateConsistencyLevel(client); } [TestMethod] public async Task ValidateConsistencyLevelRntbd() { DocumentClient client = TestCommon.CreateClient(false, Protocol.Tcp); - await ValidateCosistencyLevel(client); + await ValidateConsistencyLevel(client); } - private async Task ValidateCosistencyLevel(DocumentClient client) + private async Task ValidateConsistencyLevel(DocumentClient client) { DocumentCollection collection = TestCommon.CreateOrGetDocumentCollection(client); From 6511d32e63cb52c2bd94601c75393bc7ceac9396 Mon Sep 17 00:00:00 2001 From: Maya-Painter Date: Thu, 15 Jun 2023 12:48:21 -0700 Subject: [PATCH 26/32] remove TransportSerializationFormat header --- .../Pagination/ChangeFeedPaginationOptions.cs | 1 - Microsoft.Azure.Cosmos/src/FeedOptions.cs | 16 ++--- .../DocumentQueryExecutionContextBase.cs | 10 ---- .../src/RequestOptions/QueryRequestOptions.cs | 15 ----- .../src/TransportSerializationFormat.cs | 24 -------- .../CosmosItemTests.cs | 1 - .../HeadersValidationTests.cs | 43 +------------- .../SupportedSerializationFormatsTest.cs | 10 ---- .../ContentSerializationPerformanceTests.cs | 1 - .../Query/EndToEnd.cs | 16 ----- .../BinaryEncodingOverTheWireTests.cs | 42 ++++++------- .../Contracts/DotNetSDKAPI.json | 59 ------------------- .../Query/FeedOptionTests.cs | 1 - 13 files changed, 27 insertions(+), 212 deletions(-) delete mode 100644 Microsoft.Azure.Cosmos/src/TransportSerializationFormat.cs diff --git a/Microsoft.Azure.Cosmos/src/ChangeFeed/Pagination/ChangeFeedPaginationOptions.cs b/Microsoft.Azure.Cosmos/src/ChangeFeed/Pagination/ChangeFeedPaginationOptions.cs index d41743bcc0..85a2895774 100644 --- a/Microsoft.Azure.Cosmos/src/ChangeFeed/Pagination/ChangeFeedPaginationOptions.cs +++ b/Microsoft.Azure.Cosmos/src/ChangeFeed/Pagination/ChangeFeedPaginationOptions.cs @@ -47,6 +47,5 @@ public ChangeFeedPaginationOptions( public JsonSerializationFormat? JsonSerializationFormat { get; } protected override ImmutableHashSet BannedAdditionalHeaders => BannedHeaders; - } } diff --git a/Microsoft.Azure.Cosmos/src/FeedOptions.cs b/Microsoft.Azure.Cosmos/src/FeedOptions.cs index 382feb149c..5d2922da06 100644 --- a/Microsoft.Azure.Cosmos/src/FeedOptions.cs +++ b/Microsoft.Azure.Cosmos/src/FeedOptions.cs @@ -69,7 +69,6 @@ public FeedOptions(FeedOptions options) this.MergeStaticId = options.MergeStaticId; this.Properties = options.Properties; this.SupportedSerializationFormats = options.SupportedSerializationFormats; - this.TransportSerializationFormat = options.TransportSerializationFormat; } /// @@ -398,16 +397,6 @@ public FeedOptions(FeedOptions options) /// public string EndEpk { get; set; } - /// - /// Gets or sets the SupportedSerializationFormats for the query response from the service. - /// - public SupportedSerializationFormats? SupportedSerializationFormats { get; set; } - - /// - /// Gets or sets the transport serialization format for the query response from the service. - /// - public TransportSerializationFormat? TransportSerializationFormat { get; set; } - public bool EnableGroupBy { get; set; } /// @@ -422,5 +411,10 @@ public FeedOptions(FeedOptions options) public CosmosSerializationFormatOptions CosmosSerializationFormatOptions { get; set; } public IDictionary Properties { get; set; } + + /// + /// Gets or sets the SupportedSerializationFormats for the query response from the service. + /// + internal SupportedSerializationFormats? SupportedSerializationFormats { get; set; } } } diff --git a/Microsoft.Azure.Cosmos/src/Query/v2Query/DocumentQueryExecutionContextBase.cs b/Microsoft.Azure.Cosmos/src/Query/v2Query/DocumentQueryExecutionContextBase.cs index 6fc57e89b6..824d992734 100644 --- a/Microsoft.Azure.Cosmos/src/Query/v2Query/DocumentQueryExecutionContextBase.cs +++ b/Microsoft.Azure.Cosmos/src/Query/v2Query/DocumentQueryExecutionContextBase.cs @@ -329,16 +329,6 @@ await this.Client.EnsureValidOverwriteAsync( requestHeaders.Set(HttpConstants.HttpHeaders.MergeStaticId, this.feedOptions.MergeStaticId); } - if (this.feedOptions.TransportSerializationFormat != null) - { - requestHeaders[HttpConstants.HttpHeaders.ContentSerializationFormat] = this.feedOptions.TransportSerializationFormat switch - { - TransportSerializationFormat.Binary => ContentSerializationFormat.CosmosBinary.ToString(), - TransportSerializationFormat.Text => ContentSerializationFormat.JsonText.ToString(), - _ => throw new InvalidEnumArgumentException(), - }; - } - requestHeaders[HttpConstants.HttpHeaders.SupportedSerializationFormats] = this.feedOptions.SupportedSerializationFormats != null ? this.feedOptions.SupportedSerializationFormats.Value.ToString() : DefaultSupportedSerializationFormats; diff --git a/Microsoft.Azure.Cosmos/src/RequestOptions/QueryRequestOptions.cs b/Microsoft.Azure.Cosmos/src/RequestOptions/QueryRequestOptions.cs index cb7d804113..fca6f470ac 100644 --- a/Microsoft.Azure.Cosmos/src/RequestOptions/QueryRequestOptions.cs +++ b/Microsoft.Azure.Cosmos/src/RequestOptions/QueryRequestOptions.cs @@ -172,11 +172,6 @@ public ConsistencyLevel? ConsistencyLevel /// public DedicatedGatewayRequestOptions DedicatedGatewayRequestOptions { get; set; } - /// - /// Gets or sets the transport serialization format for the query response from the service. - /// - public TransportSerializationFormat? TransportSerializationFormat { get; set; } - internal CosmosElement CosmosElementContinuationToken { get; set; } internal string StartId { get; set; } @@ -241,16 +236,6 @@ internal override void PopulateRequestOptions(RequestMessage request) { request.Headers.Add(HttpConstants.HttpHeaders.ResponseContinuationTokenLimitInKB, this.ResponseContinuationTokenLimitInKb.ToString()); } - - if (this.TransportSerializationFormat != null) - { - request.Headers.CosmosMessageHeaders.ContentSerializationFormat = this.TransportSerializationFormat switch - { - Cosmos.TransportSerializationFormat.Binary => ContentSerializationFormat.CosmosBinary.ToString(), - Cosmos.TransportSerializationFormat.Text => ContentSerializationFormat.JsonText.ToString(), - _ => throw new InvalidEnumArgumentException(), - }; - } request.Headers.CosmosMessageHeaders.SupportedSerializationFormats = this.SupportedSerializationFormats != null ? this.SupportedSerializationFormats.ToString() diff --git a/Microsoft.Azure.Cosmos/src/TransportSerializationFormat.cs b/Microsoft.Azure.Cosmos/src/TransportSerializationFormat.cs deleted file mode 100644 index 4398815138..0000000000 --- a/Microsoft.Azure.Cosmos/src/TransportSerializationFormat.cs +++ /dev/null @@ -1,24 +0,0 @@ -// ------------------------------------------------------------ -// Copyright (c) Microsoft Corporation. All rights reserved. -// ------------------------------------------------------------ - -namespace Microsoft.Azure.Cosmos -{ - using System; - - /// - /// Specifies the serialization format for query response. - /// - public enum TransportSerializationFormat - { - /// - /// Indicates binary format to be used for transport serialization. - /// - Binary, - - /// - /// Indicates text format to be used for transport serialization. - /// - Text, - } -} diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/CosmosItemTests.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/CosmosItemTests.cs index f972702e5a..cdf0bb9853 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/CosmosItemTests.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/CosmosItemTests.cs @@ -1634,7 +1634,6 @@ public async Task ItemQueryStreamSerializationSetting() QueryRequestOptions requestOptions = new QueryRequestOptions() { - TransportSerializationFormat = TransportSerializationFormat.Binary, CosmosSerializationFormatOptions = options, MaxConcurrency = 5, MaxItemCount = 5, diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/HeadersValidationTests.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/HeadersValidationTests.cs index 63fd8a60a9..ae66d2ad8b 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/HeadersValidationTests.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/HeadersValidationTests.cs @@ -307,31 +307,6 @@ private void ValidateJsonSerializationFormatQuery(DocumentClient client, Documen Assert.IsTrue(response.ResponseBody.ReadByte() == HeadersValidationTests.BinarySerializationByteMarkValue); } - [TestMethod] - [Owner("hdetroja")] - public void ValidateTransportSerializationFormat() - { - List queryRequestOptionsList = new List() - { - new QueryRequestOptions() - { - TransportSerializationFormat = TransportSerializationFormat.Binary - }, - new QueryRequestOptions() - { - TransportSerializationFormat = TransportSerializationFormat.Text - } - }; - - string[] expectedResults = new[] { "CosmosBinary", "JsonText" }; - for (int i = 0; i < queryRequestOptionsList.Count; i++) - { - RequestMessage testrequestMessage = new RequestMessage(); - queryRequestOptionsList[i].PopulateRequestOptions(testrequestMessage); - Assert.AreEqual(expectedResults[i], testrequestMessage.Headers.ContentSerializationFormat); - } - } - [TestMethod] [Owner("hdetroja")] public void ValidateSupportedSerializationFormatsGateway() @@ -418,14 +393,9 @@ private void SupportedSerializationFormatsPositiveCases( DocumentCollection collection, SupportedSerializationFormats expectedFormat, string supportedSerializationFormats, - string transportSerializationFormat, SqlQuerySpec sqlQuerySpec = null) { INameValueCollection headers = new RequestNameValueCollection(); - if(transportSerializationFormat != null) - { - headers.Add(HttpConstants.HttpHeaders.ContentSerializationFormat, transportSerializationFormat); - } headers.Add(HttpConstants.HttpHeaders.SupportedSerializationFormats, supportedSerializationFormats); DocumentServiceResponse response; @@ -457,9 +427,9 @@ private void ValidateSupportedSerializationFormatsReadFeed(DocumentClient client this.SupportedSerializationFormatsNegativeCases(client, collection, "Invalid value", isHttps); // Supported values - this.SupportedSerializationFormatsPositiveCases(client, collection, expectedFormat: SupportedSerializationFormats.JsonText, supportedSerializationFormats: "JSONText", transportSerializationFormat: null); - this.SupportedSerializationFormatsPositiveCases(client, collection, expectedFormat: SupportedSerializationFormats.JsonText, supportedSerializationFormats: "COSMOSbinary", transportSerializationFormat: null); - this.SupportedSerializationFormatsPositiveCases(client, collection, expectedFormat: SupportedSerializationFormats.JsonText, supportedSerializationFormats: "JsonText, CosmosBinary", transportSerializationFormat: null); + this.SupportedSerializationFormatsPositiveCases(client, collection, expectedFormat: SupportedSerializationFormats.JsonText, supportedSerializationFormats: "JSONText"); + this.SupportedSerializationFormatsPositiveCases(client, collection, expectedFormat: SupportedSerializationFormats.JsonText, supportedSerializationFormats: "COSMOSbinary"); + this.SupportedSerializationFormatsPositiveCases(client, collection, expectedFormat: SupportedSerializationFormats.JsonText, supportedSerializationFormats: "JsonText, CosmosBinary"); } private void ValidateSupportedSerializationFormatsQuery(DocumentClient client, DocumentCollection collection, SqlQuerySpec sqlQuerySpec, bool isHttps) @@ -478,43 +448,36 @@ private void ValidateSupportedSerializationFormatsQuery(DocumentClient client, D this.SupportedSerializationFormatsPositiveCases(client, collection, expectedFormat: SupportedSerializationFormats.JsonText, supportedSerializationFormats: "jsontext", - transportSerializationFormat: null, sqlQuerySpec: sqlQuerySpec); /* this.SupportedSerializationFormatsPositiveCases(client, collection, expectedFormat: SupportedSerializationFormats.CosmosBinary, supportedSerializationFormats: "COSMOSBINARY", - transportSerializationFormat: null, sqlQuerySpec: sqlQuerySpec); */ this.SupportedSerializationFormatsPositiveCases(client, collection, expectedFormat: SupportedSerializationFormats.JsonText, supportedSerializationFormats: "JsonText, CosmosBinary", - transportSerializationFormat: null, sqlQuerySpec: sqlQuerySpec); /* this.SupportedSerializationFormatsPositiveCases(client, collection, expectedFormat: SupportedSerializationFormats.CosmosBinary, supportedSerializationFormats: "CosmosBinary, HybridRow", - transportSerializationFormat: null, sqlQuerySpec: sqlQuerySpec); */ this.SupportedSerializationFormatsPositiveCases(client, collection, expectedFormat: SupportedSerializationFormats.JsonText, supportedSerializationFormats: "JsonText, CosmosBinary, HybridRow", - transportSerializationFormat: null, sqlQuerySpec: sqlQuerySpec); /* this.SupportedSerializationFormatsPositiveCases(client, collection, expectedFormat: SupportedSerializationFormats.CosmosBinary, supportedSerializationFormats: "JsonText, CosmosBinary, HybridRow", - transportSerializationFormat: "CosmosBinary", sqlQuerySpec: sqlQuerySpec); */ this.SupportedSerializationFormatsPositiveCases(client, collection, expectedFormat: SupportedSerializationFormats.JsonText, supportedSerializationFormats: "JsonText, CosmosBinary, HybridRow", - transportSerializationFormat: "JsonText", sqlQuerySpec: sqlQuerySpec); } diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/Query/SupportedSerializationFormatsTest.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/Query/SupportedSerializationFormatsTest.cs index b6368dc4e0..f4cdab6e51 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/Query/SupportedSerializationFormatsTest.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/Query/SupportedSerializationFormatsTest.cs @@ -71,20 +71,10 @@ private async Task TestSupportedSerializationFormatsHelper(Container container, }, new QueryRequestOptions() { - TransportSerializationFormat = TransportSerializationFormat.Text - }, - new QueryRequestOptions() - { - TransportSerializationFormat = TransportSerializationFormat.Binary - }, - new QueryRequestOptions() - { - TransportSerializationFormat = TransportSerializationFormat.Text, SupportedSerializationFormats = SupportedSerializationFormats.CosmosBinary }, new QueryRequestOptions() { - TransportSerializationFormat = TransportSerializationFormat.Binary, SupportedSerializationFormats = SupportedSerializationFormats.JsonText } }; diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/QueryPerfTest/ContentSerializationPerformanceTests.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/QueryPerfTest/ContentSerializationPerformanceTests.cs index cc3d3c707d..759e63b345 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/QueryPerfTest/ContentSerializationPerformanceTests.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/QueryPerfTest/ContentSerializationPerformanceTests.cs @@ -83,7 +83,6 @@ private async Task RunQueryAsync(Container container) { MaxConcurrency = this.MaxConcurrency, MaxItemCount = this.MaxItemCount, - TransportSerializationFormat = this.contentSerialization == "JsonText" ? TransportSerializationFormat.Text : TransportSerializationFormat.Binary, }; if (this.useStronglyTypedIterator) diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Performance.Tests/Query/EndToEnd.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Performance.Tests/Query/EndToEnd.cs index 1ee8d0e1cf..7e64560a5c 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Performance.Tests/Query/EndToEnd.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Performance.Tests/Query/EndToEnd.cs @@ -164,7 +164,6 @@ private static async Task QueryWithTextStream( MaxBufferedItemCount = -1, MaxConcurrency = -1, }; - SetSerializationFormat(queryRequestOptions, jsonSerializationFormat); FeedIterator feedIterator = container.GetItemQueryStreamIterator( queryText: query, @@ -190,7 +189,6 @@ private static async Task QueryWithCosmosElements( MaxBufferedItemCount = -1, MaxConcurrency = -1, }; - SetSerializationFormat(queryRequestOptions, jsonSerializationFormat); FeedIterator feedIterator = container.GetItemQueryStreamIterator( queryText: query, @@ -205,20 +203,6 @@ private static async Task QueryWithCosmosElements( } } - private static void SetSerializationFormat( - QueryRequestOptions queryRequestOptions, - JsonSerializationFormat jsonSerializationFormat) - { - TransportSerializationFormat transportSerializationFormat = jsonSerializationFormat switch - { - JsonSerializationFormat.Text => TransportSerializationFormat.Text, - JsonSerializationFormat.Binary => TransportSerializationFormat.Binary, - _ => throw new Exception(), - }; - - queryRequestOptions.TransportSerializationFormat = transportSerializationFormat; - } - public IEnumerable Data() { foreach (FieldInfo fieldInfo in typeof(Queries).GetFields(BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic)) diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/BinaryEncodingOverTheWireTests.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/BinaryEncodingOverTheWireTests.cs index 8b3db98a6a..dc62511dab 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/BinaryEncodingOverTheWireTests.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/BinaryEncodingOverTheWireTests.cs @@ -124,7 +124,7 @@ public void CheckThatAllTestsAreRunning() [TestMethod] public async Task CombinedScriptsDataTest() { - await this.TestCurratedDocs("CombinedScriptsData.json"); + await this.TestCuratedDocs("CombinedScriptsData.json"); } // For now we are skipping this test since the documents are too large to ingest and we get a rate size too large (HTTP 413). @@ -139,96 +139,96 @@ public async Task CountriesTest() [TestMethod] public async Task DevTestCollTest() { - await this.TestCurratedDocs("devtestcoll.json"); + await this.TestCuratedDocs("devtestcoll.json"); } [TestMethod] public async Task LastFMTest() { - await this.TestCurratedDocs("lastfm"); + await this.TestCuratedDocs("lastfm"); } [TestMethod] public async Task LogDataTest() { - await this.TestCurratedDocs("LogData.json"); + await this.TestCuratedDocs("LogData.json"); } [TestMethod] public async Task MillionSong1KDocumentsTest() { - await this.TestCurratedDocs("MillionSong1KDocuments.json"); + await this.TestCuratedDocs("MillionSong1KDocuments.json"); } [TestMethod] public async Task MsnCollectionTest() { - await this.TestCurratedDocs("MsnCollection.json"); + await this.TestCuratedDocs("MsnCollection.json"); } [TestMethod] public async Task NutritionDataTest() { - await this.TestCurratedDocs("NutritionData"); + await this.TestCuratedDocs("NutritionData"); } [TestMethod] public async Task RunsCollectionTest() { - await this.TestCurratedDocs("runsCollection"); + await this.TestCuratedDocs("runsCollection"); } [TestMethod] public async Task StatesCommitteesTest() { - await this.TestCurratedDocs("states_committees.json"); + await this.TestCuratedDocs("states_committees.json"); } [TestMethod] public async Task StatesLegislatorsTest() { - await this.TestCurratedDocs("states_legislators"); + await this.TestCuratedDocs("states_legislators"); } [TestMethod] public async Task Store01Test() { - await this.TestCurratedDocs("store01C.json"); + await this.TestCuratedDocs("store01C.json"); } [TestMethod] public async Task TicinoErrorBucketsTest() { - await this.TestCurratedDocs("TicinoErrorBuckets"); + await this.TestCuratedDocs("TicinoErrorBuckets"); } [TestMethod] public async Task TwitterDataTest() { - await this.TestCurratedDocs("twitter_data"); + await this.TestCuratedDocs("twitter_data"); } [TestMethod] public async Task Ups1Test() { - await this.TestCurratedDocs("ups1"); + await this.TestCuratedDocs("ups1"); } [TestMethod] public async Task XpertEventsTest() { - await this.TestCurratedDocs("XpertEvents"); + await this.TestCuratedDocs("XpertEvents"); } - private async Task TestCurratedDocs(string path) + private async Task TestCuratedDocs(string path) { IEnumerable documents = BinaryEncodingOverTheWireTests.GetDocumentsFromCurratedDoc(path); await BinaryEncodingOverTheWireTests.CreateIngestQueryDelete( documents.Select(x => x.ToString()), - this.TestCurratedDocs); + this.TestCuratedDocs); } - private async Task TestCurratedDocs(CosmosClient cosmosClient, Container container, List items) + private async Task TestCuratedDocs(CosmosClient cosmosClient, Container container, List items) { HashSet inputItems = new HashSet(items, JsonTokenEqualityComparer.Value); @@ -250,11 +250,7 @@ async Task AssertQueryDrainsCorrectlyAsync(FeedIterator feedIterator) await AssertQueryDrainsCorrectlyAsync(textFeedIterator); FeedIterator binaryFeedIterator = container.GetItemQueryIterator( - queryDefinition: new QueryDefinition("SELECT * FROM c ORDER BY c._ts"), - requestOptions: new QueryRequestOptions() - { - TransportSerializationFormat = TransportSerializationFormat.Binary - }); + queryDefinition: new QueryDefinition("SELECT * FROM c ORDER BY c._ts")); await AssertQueryDrainsCorrectlyAsync(binaryFeedIterator); } diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Contracts/DotNetSDKAPI.json b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Contracts/DotNetSDKAPI.json index 462b5503ea..8a3bc7b462 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Contracts/DotNetSDKAPI.json +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Contracts/DotNetSDKAPI.json @@ -6325,18 +6325,6 @@ "Attributes": [], "MethodInfo": "System.Nullable`1[Microsoft.Azure.Cosmos.PartitionKey] PartitionKey;CanRead:True;CanWrite:True;System.Nullable`1[Microsoft.Azure.Cosmos.PartitionKey] get_PartitionKey();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;Void set_PartitionKey(System.Nullable`1[Microsoft.Azure.Cosmos.PartitionKey]);IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" }, - "System.Nullable`1[Microsoft.Azure.Cosmos.TransportSerializationFormat] get_TransportSerializationFormat()[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]": { - "Type": "Method", - "Attributes": [ - "CompilerGeneratedAttribute" - ], - "MethodInfo": "System.Nullable`1[Microsoft.Azure.Cosmos.TransportSerializationFormat] get_TransportSerializationFormat();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" - }, - "System.Nullable`1[Microsoft.Azure.Cosmos.TransportSerializationFormat] TransportSerializationFormat": { - "Type": "Property", - "Attributes": [], - "MethodInfo": "System.Nullable`1[Microsoft.Azure.Cosmos.TransportSerializationFormat] TransportSerializationFormat;CanRead:True;CanWrite:True;System.Nullable`1[Microsoft.Azure.Cosmos.TransportSerializationFormat] get_TransportSerializationFormat();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;Void set_TransportSerializationFormat(System.Nullable`1[Microsoft.Azure.Cosmos.TransportSerializationFormat]);IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" - }, "System.Nullable`1[System.Boolean] EnableLowPrecisionOrderBy": { "Type": "Property", "Attributes": [], @@ -6519,13 +6507,6 @@ "CompilerGeneratedAttribute" ], "MethodInfo": "Void set_SessionToken(System.String);IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" - }, - "Void set_TransportSerializationFormat(System.Nullable`1[Microsoft.Azure.Cosmos.TransportSerializationFormat])[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]": { - "Type": "Method", - "Attributes": [ - "CompilerGeneratedAttribute" - ], - "MethodInfo": "Void set_TransportSerializationFormat(System.Nullable`1[Microsoft.Azure.Cosmos.TransportSerializationFormat]);IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" } }, "NestedTypes": {} @@ -7385,18 +7366,6 @@ "Attributes": [], "MethodInfo": "System.Nullable`1[Microsoft.Azure.Cosmos.PartitionKey] PartitionKey;CanRead:True;CanWrite:True;System.Nullable`1[Microsoft.Azure.Cosmos.PartitionKey] get_PartitionKey();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;Void set_PartitionKey(System.Nullable`1[Microsoft.Azure.Cosmos.PartitionKey]);IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" }, - "System.Nullable`1[Microsoft.Azure.Cosmos.TransportSerializationFormat] get_TransportSerializationFormat()[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]": { - "Type": "Method", - "Attributes": [ - "CompilerGeneratedAttribute" - ], - "MethodInfo": "System.Nullable`1[Microsoft.Azure.Cosmos.TransportSerializationFormat] get_TransportSerializationFormat();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" - }, - "System.Nullable`1[Microsoft.Azure.Cosmos.TransportSerializationFormat] TransportSerializationFormat": { - "Type": "Property", - "Attributes": [], - "MethodInfo": "System.Nullable`1[Microsoft.Azure.Cosmos.TransportSerializationFormat] TransportSerializationFormat;CanRead:True;CanWrite:True;System.Nullable`1[Microsoft.Azure.Cosmos.TransportSerializationFormat] get_TransportSerializationFormat();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;Void set_TransportSerializationFormat(System.Nullable`1[Microsoft.Azure.Cosmos.TransportSerializationFormat]);IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" - }, "System.Nullable`1[System.Boolean] EnableLowPrecisionOrderBy": { "Type": "Property", "Attributes": [], @@ -7579,13 +7548,6 @@ "CompilerGeneratedAttribute" ], "MethodInfo": "Void set_SessionToken(System.String);IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" - }, - "Void set_TransportSerializationFormat(System.Nullable`1[Microsoft.Azure.Cosmos.TransportSerializationFormat])[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]": { - "Type": "Method", - "Attributes": [ - "CompilerGeneratedAttribute" - ], - "MethodInfo": "Void set_TransportSerializationFormat(System.Nullable`1[Microsoft.Azure.Cosmos.TransportSerializationFormat]);IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" } }, "NestedTypes": {} @@ -11005,27 +10967,6 @@ }, "NestedTypes": {} }, - "Microsoft.Azure.Cosmos.TransportSerializationFormat;System.Enum;IsAbstract:False;IsSealed:True;IsInterface:False;IsEnum:True;IsClass:False;IsValueType:True;IsNested:False;IsGenericType:False;IsSerializable:True": { - "Subclasses": {}, - "Members": { - "Int32 value__": { - "Type": "Field", - "Attributes": [], - "MethodInfo": "Int32 value__;IsInitOnly:False;IsStatic:False;" - }, - "Microsoft.Azure.Cosmos.TransportSerializationFormat Binary": { - "Type": "Field", - "Attributes": [], - "MethodInfo": "Microsoft.Azure.Cosmos.TransportSerializationFormat Binary;IsInitOnly:False;IsStatic:True;" - }, - "Microsoft.Azure.Cosmos.TransportSerializationFormat Text": { - "Type": "Field", - "Attributes": [], - "MethodInfo": "Microsoft.Azure.Cosmos.TransportSerializationFormat Text;IsInitOnly:False;IsStatic:True;" - } - }, - "NestedTypes": {} - }, "Microsoft.Azure.Cosmos.UniqueKey;System.Object;IsAbstract:False;IsSealed:False;IsInterface:False;IsEnum:False;IsClass:True;IsValueType:False;IsNested:False;IsGenericType:False;IsSerializable:False": { "Subclasses": {}, "Members": { diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Query/FeedOptionTests.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Query/FeedOptionTests.cs index 769329cd45..ea22b3ef26 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Query/FeedOptionTests.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Query/FeedOptionTests.cs @@ -74,7 +74,6 @@ public async Task TestSupportedSerializationFormats() headers = await testQueryExecutionContext.CreateCommonHeadersAsync(feedOptions); Assert.AreEqual("CosmosBinary, HybridRow", headers[HttpConstants.HttpHeaders.SupportedSerializationFormats]); - feedOptions.TransportSerializationFormat = TransportSerializationFormat.Binary; headers = await testQueryExecutionContext.CreateCommonHeadersAsync(feedOptions); Assert.AreEqual("CosmosBinary", headers[HttpConstants.HttpHeaders.ContentSerializationFormat]); } From a59048296820075edc7aabac7d8f07751d3cc45f Mon Sep 17 00:00:00 2001 From: Maya-Painter Date: Thu, 15 Jun 2023 13:05:32 -0700 Subject: [PATCH 27/32] text reverts --- Microsoft.Azure.Cosmos/src/FeedOptions.cs | 10 +++---- .../CosmosSerializationFormatOptions.cs | 28 ++++++++++++++++++- .../Query/EndToEnd.cs | 22 +++++++++++++++ .../BinaryEncodingOverTheWireTests.cs | 18 ++++++++++-- 4 files changed, 70 insertions(+), 8 deletions(-) diff --git a/Microsoft.Azure.Cosmos/src/FeedOptions.cs b/Microsoft.Azure.Cosmos/src/FeedOptions.cs index 5d2922da06..4d6ce52f41 100644 --- a/Microsoft.Azure.Cosmos/src/FeedOptions.cs +++ b/Microsoft.Azure.Cosmos/src/FeedOptions.cs @@ -397,6 +397,11 @@ public FeedOptions(FeedOptions options) /// public string EndEpk { get; set; } + /// + /// Gets or sets the SupportedSerializationFormats for the query response from the service. + /// + public SupportedSerializationFormats? SupportedSerializationFormats { get; set; } + public bool EnableGroupBy { get; set; } /// @@ -411,10 +416,5 @@ public FeedOptions(FeedOptions options) public CosmosSerializationFormatOptions CosmosSerializationFormatOptions { get; set; } public IDictionary Properties { get; set; } - - /// - /// Gets or sets the SupportedSerializationFormats for the query response from the service. - /// - internal SupportedSerializationFormats? SupportedSerializationFormats { get; set; } } } diff --git a/Microsoft.Azure.Cosmos/src/Serializer/CosmosSerializationFormatOptions.cs b/Microsoft.Azure.Cosmos/src/Serializer/CosmosSerializationFormatOptions.cs index c83da114a1..8ebefa502a 100644 --- a/Microsoft.Azure.Cosmos/src/Serializer/CosmosSerializationFormatOptions.cs +++ b/Microsoft.Azure.Cosmos/src/Serializer/CosmosSerializationFormatOptions.cs @@ -8,22 +8,48 @@ namespace Microsoft.Azure.Cosmos internal sealed class CosmosSerializationFormatOptions { + public delegate IJsonNavigator CreateCustomNavigator(ReadOnlyMemory content); + public delegate IJsonWriter CreateCustomWriter(); +        /// +        /// What serialization format to request the response in from the backend +        /// + public string ContentSerializationFormat { get; } + +        /// +        /// Creates a navigator that can navigate a JSON in the specified ContentSerializationFormat +        /// + public CreateCustomNavigator CreateCustomNavigatorCallback { get; } +         ///         /// Creates a writer to use to write out the stream.         /// public CreateCustomWriter CreateCustomWriterCallback { get; } public CosmosSerializationFormatOptions( + string contentSerializationFormat, + CreateCustomNavigator createCustomNavigator, CreateCustomWriter createCustomWriter) { + if (contentSerializationFormat == null) + { + throw new ArgumentNullException(nameof(contentSerializationFormat)); + } + + if (createCustomNavigator == null) + { + throw new ArgumentNullException(nameof(createCustomNavigator)); + } + if (createCustomWriter == null) { throw new ArgumentNullException(nameof(createCustomWriter)); } + this.ContentSerializationFormat = contentSerializationFormat; + this.CreateCustomNavigatorCallback = createCustomNavigator; this.CreateCustomWriterCallback = createCustomWriter; } } -} +} \ No newline at end of file diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Performance.Tests/Query/EndToEnd.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Performance.Tests/Query/EndToEnd.cs index 7e64560a5c..24cb907be8 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Performance.Tests/Query/EndToEnd.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Performance.Tests/Query/EndToEnd.cs @@ -164,6 +164,7 @@ private static async Task QueryWithTextStream( MaxBufferedItemCount = -1, MaxConcurrency = -1, }; + SetSerializationFormat(queryRequestOptions, jsonSerializationFormat); FeedIterator feedIterator = container.GetItemQueryStreamIterator( queryText: query, @@ -189,6 +190,7 @@ private static async Task QueryWithCosmosElements( MaxBufferedItemCount = -1, MaxConcurrency = -1, }; + SetSerializationFormat(queryRequestOptions, jsonSerializationFormat); FeedIterator feedIterator = container.GetItemQueryStreamIterator( queryText: query, @@ -203,6 +205,26 @@ private static async Task QueryWithCosmosElements( } } + private static void SetSerializationFormat( + QueryRequestOptions queryRequestOptions, + JsonSerializationFormat jsonSerializationFormat) + { + string contentSerializationFormat = jsonSerializationFormat switch + { + JsonSerializationFormat.Text => "JsonText", + JsonSerializationFormat.Binary => "CosmosBinary", + JsonSerializationFormat.HybridRow => "HybridRow", + _ => throw new Exception(), + }; + + CosmosSerializationFormatOptions formatOptions = new CosmosSerializationFormatOptions( + contentSerializationFormat, + (content) => JsonNavigator.Create(content), + () => JsonWriter.Create(JsonSerializationFormat.Text)); + + queryRequestOptions.CosmosSerializationFormatOptions = formatOptions; + } + public IEnumerable Data() { foreach (FieldInfo fieldInfo in typeof(Queries).GetFields(BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic)) diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/BinaryEncodingOverTheWireTests.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/BinaryEncodingOverTheWireTests.cs index dc62511dab..dc9e77ceb4 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/BinaryEncodingOverTheWireTests.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/BinaryEncodingOverTheWireTests.cs @@ -245,12 +245,26 @@ async Task AssertQueryDrainsCorrectlyAsync(FeedIterator feedIterator) } FeedIterator textFeedIterator = container.GetItemQueryIterator( - queryDefinition: new QueryDefinition("SELECT * FROM c ORDER BY c._ts")); + queryDefinition: new QueryDefinition("SELECT * FROM c ORDER BY c._ts"), + requestOptions: new QueryRequestOptions() + { + CosmosSerializationFormatOptions = new CosmosSerializationFormatOptions( + "JsonText", + (content) => JsonNavigator.Create(content), + () => Cosmos.Json.JsonWriter.Create(JsonSerializationFormat.Text)), + }); await AssertQueryDrainsCorrectlyAsync(textFeedIterator); FeedIterator binaryFeedIterator = container.GetItemQueryIterator( - queryDefinition: new QueryDefinition("SELECT * FROM c ORDER BY c._ts")); + queryDefinition: new QueryDefinition("SELECT * FROM c ORDER BY c._ts"), + requestOptions: new QueryRequestOptions() + { + CosmosSerializationFormatOptions = new CosmosSerializationFormatOptions( + "CosmosBinary", + (content) => JsonNavigator.Create(content), + () => Cosmos.Json.JsonWriter.Create(JsonSerializationFormat.Text)), + }); await AssertQueryDrainsCorrectlyAsync(binaryFeedIterator); } From b90cd4fd9e3bd0cb505bbf85355d3be9468e4cf6 Mon Sep 17 00:00:00 2001 From: Maya-Painter Date: Thu, 15 Jun 2023 13:10:37 -0700 Subject: [PATCH 28/32] revert --- .../Microsoft.Azure.Cosmos.EmulatorTests/CosmosItemTests.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/CosmosItemTests.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/CosmosItemTests.cs index cdf0bb9853..b237c68c2a 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/CosmosItemTests.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/CosmosItemTests.cs @@ -1630,6 +1630,8 @@ public async Task ItemQueryStreamSerializationSetting() QueryDefinition sql = new QueryDefinition("SELECT * FROM toDoActivity t ORDER BY t.taskNum"); CosmosSerializationFormatOptions options = new CosmosSerializationFormatOptions( + ContentSerializationFormat.CosmosBinary.ToString(), + (content) => JsonNavigator.Create(content), () => JsonWriter.Create(JsonSerializationFormat.Binary)); QueryRequestOptions requestOptions = new QueryRequestOptions() From 59cce85218042a5724d8cf473464c6796344fbf7 Mon Sep 17 00:00:00 2001 From: Maya-Painter Date: Thu, 15 Jun 2023 13:55:30 -0700 Subject: [PATCH 29/32] test update --- .../Microsoft.Azure.Cosmos.Tests/Query/FeedOptionTests.cs | 3 --- 1 file changed, 3 deletions(-) diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Query/FeedOptionTests.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Query/FeedOptionTests.cs index ea22b3ef26..703636ca81 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Query/FeedOptionTests.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Query/FeedOptionTests.cs @@ -73,9 +73,6 @@ public async Task TestSupportedSerializationFormats() feedOptions.SupportedSerializationFormats = SupportedSerializationFormats.CosmosBinary | SupportedSerializationFormats.HybridRow; headers = await testQueryExecutionContext.CreateCommonHeadersAsync(feedOptions); Assert.AreEqual("CosmosBinary, HybridRow", headers[HttpConstants.HttpHeaders.SupportedSerializationFormats]); - - headers = await testQueryExecutionContext.CreateCommonHeadersAsync(feedOptions); - Assert.AreEqual("CosmosBinary", headers[HttpConstants.HttpHeaders.ContentSerializationFormat]); } internal class TestQueryExecutionContext : DocumentQueryExecutionContextBase From 7de7e99115175956c693154a7c74a805ba45e37c Mon Sep 17 00:00:00 2001 From: Maya-Painter Date: Mon, 19 Jun 2023 10:33:48 -0700 Subject: [PATCH 30/32] PR comments --- .../src/Query/v2Query/DocumentQueryExecutionContextBase.cs | 4 +--- .../src/RequestOptions/QueryRequestOptions.cs | 4 +--- .../HeadersValidationTests.cs | 2 +- 3 files changed, 3 insertions(+), 7 deletions(-) diff --git a/Microsoft.Azure.Cosmos/src/Query/v2Query/DocumentQueryExecutionContextBase.cs b/Microsoft.Azure.Cosmos/src/Query/v2Query/DocumentQueryExecutionContextBase.cs index 824d992734..053c951f6c 100644 --- a/Microsoft.Azure.Cosmos/src/Query/v2Query/DocumentQueryExecutionContextBase.cs +++ b/Microsoft.Azure.Cosmos/src/Query/v2Query/DocumentQueryExecutionContextBase.cs @@ -329,9 +329,7 @@ await this.Client.EnsureValidOverwriteAsync( requestHeaders.Set(HttpConstants.HttpHeaders.MergeStaticId, this.feedOptions.MergeStaticId); } - requestHeaders[HttpConstants.HttpHeaders.SupportedSerializationFormats] = this.feedOptions.SupportedSerializationFormats != null - ? this.feedOptions.SupportedSerializationFormats.Value.ToString() - : DefaultSupportedSerializationFormats; + requestHeaders[HttpConstants.HttpHeaders.SupportedSerializationFormats] = this.feedOptions.SupportedSerializationFormats?.ToString() ?? DefaultSupportedSerializationFormats; return requestHeaders; } diff --git a/Microsoft.Azure.Cosmos/src/RequestOptions/QueryRequestOptions.cs b/Microsoft.Azure.Cosmos/src/RequestOptions/QueryRequestOptions.cs index 01154096eb..f723107ede 100644 --- a/Microsoft.Azure.Cosmos/src/RequestOptions/QueryRequestOptions.cs +++ b/Microsoft.Azure.Cosmos/src/RequestOptions/QueryRequestOptions.cs @@ -245,9 +245,7 @@ internal override void PopulateRequestOptions(RequestMessage request) request.Headers.Add(HttpConstants.HttpHeaders.ResponseContinuationTokenLimitInKB, this.ResponseContinuationTokenLimitInKb.ToString()); } - request.Headers.CosmosMessageHeaders.SupportedSerializationFormats = this.SupportedSerializationFormats != null - ? this.SupportedSerializationFormats.ToString() - : DocumentQueryExecutionContextBase.DefaultSupportedSerializationFormats; + request.Headers.CosmosMessageHeaders.SupportedSerializationFormats = this.SupportedSerializationFormats?.ToString() ?? DocumentQueryExecutionContextBase.DefaultSupportedSerializationFormats; if (this.StartId != null) { diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/HeadersValidationTests.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/HeadersValidationTests.cs index ae66d2ad8b..36f2a5b371 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/HeadersValidationTests.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/HeadersValidationTests.cs @@ -308,7 +308,7 @@ private void ValidateJsonSerializationFormatQuery(DocumentClient client, Documen } [TestMethod] - [Owner("hdetroja")] + [Owner("maya-painter")] public void ValidateSupportedSerializationFormatsGateway() { DocumentClient client = TestCommon.CreateClient(true); From 5a3f53c5be8fca8e99b4f8e4a4a3073d235d9476 Mon Sep 17 00:00:00 2001 From: Maya-Painter <130110800+Maya-Painter@users.noreply.github.com> Date: Tue, 20 Jun 2023 14:58:30 -0700 Subject: [PATCH 31/32] remove test owner headers HeadersValidationTests.cs --- .../HeadersValidationTests.cs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/HeadersValidationTests.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/HeadersValidationTests.cs index 36f2a5b371..87118606aa 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/HeadersValidationTests.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/HeadersValidationTests.cs @@ -204,7 +204,6 @@ private async Task ValidateConsistencyLevel(DocumentClient client) } [TestMethod] - [Owner("brchon")] public void ValidateJsonSerializationFormatGateway() { var client = TestCommon.CreateClient(true); @@ -308,7 +307,6 @@ private void ValidateJsonSerializationFormatQuery(DocumentClient client, Documen } [TestMethod] - [Owner("maya-painter")] public void ValidateSupportedSerializationFormatsGateway() { DocumentClient client = TestCommon.CreateClient(true); @@ -1292,4 +1290,4 @@ internal override string BaseUserAgent } } } -} \ No newline at end of file +} From 9b396f780eb2bd1fadbb8d682e6b883240271248 Mon Sep 17 00:00:00 2001 From: Maya-Painter Date: Thu, 22 Jun 2023 11:26:52 -0700 Subject: [PATCH 32/32] PR comments - remove unsupported tests and scope client --- .../HeadersValidationTests.cs | 15 ++++----------- .../BinaryEncodingOverTheWireTests.cs | 6 +----- 2 files changed, 5 insertions(+), 16 deletions(-) diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/HeadersValidationTests.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/HeadersValidationTests.cs index 87118606aa..f9ca3f8ecc 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/HeadersValidationTests.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/HeadersValidationTests.cs @@ -206,14 +206,14 @@ private async Task ValidateConsistencyLevel(DocumentClient client) [TestMethod] public void ValidateJsonSerializationFormatGateway() { - var client = TestCommon.CreateClient(true); + using var client = TestCommon.CreateClient(true); ValidateJsonSerializationFormat(client); } [TestMethod] public void ValidateJsonSerializationFormatRntbd() { - var client = TestCommon.CreateClient(false, Protocol.Tcp); + using var client = TestCommon.CreateClient(false, Protocol.Tcp); ValidateJsonSerializationFormat(client); } @@ -309,24 +309,17 @@ private void ValidateJsonSerializationFormatQuery(DocumentClient client, Documen [TestMethod] public void ValidateSupportedSerializationFormatsGateway() { - DocumentClient client = TestCommon.CreateClient(true); + using var client = TestCommon.CreateClient(true); this.ValidateSupportedSerializationFormats(client, true); } [TestMethod] public void ValidateSupportedSerializationFormatsRntbd() { - DocumentClient client = TestCommon.CreateClient(false, Protocol.Tcp); + using var client = TestCommon.CreateClient(false, Protocol.Tcp); this.ValidateSupportedSerializationFormats(client, false); } - [TestMethod] - public void ValidateSupportedSerializationFormatsHttps() - { - DocumentClient client = TestCommon.CreateClient(false, Protocol.Https); - this.ValidateSupportedSerializationFormats(client, true); - } - private void ValidateSupportedSerializationFormats(DocumentClient client, bool isHttps) { DocumentCollection collection = TestCommon.CreateOrGetDocumentCollection(client); diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/BinaryEncodingOverTheWireTests.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/BinaryEncodingOverTheWireTests.cs index dc9e77ceb4..7d570d65d0 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/BinaryEncodingOverTheWireTests.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/BinaryEncodingOverTheWireTests.cs @@ -28,15 +28,11 @@ public class BinaryEncodingOverTheWireTests ConfigurationManager.AppSettings["GatewayEndpoint"], ConfigurationManager.AppSettings["MasterKey"], new CosmosClientOptions() { ConnectionMode = ConnectionMode.Gateway }); - private static readonly CosmosClient DirectHttpsClient = new CosmosClient( - ConfigurationManager.AppSettings["GatewayEndpoint"], - ConfigurationManager.AppSettings["MasterKey"], - new CosmosClientOptions() { ConnectionMode = ConnectionMode.Direct, ConnectionProtocol = Documents.Client.Protocol.Https }); private static readonly CosmosClient RntbdClient = new CosmosClient( ConfigurationManager.AppSettings["GatewayEndpoint"], ConfigurationManager.AppSettings["MasterKey"], new CosmosClientOptions() { ConnectionMode = ConnectionMode.Direct, ConnectionProtocol = Documents.Client.Protocol.Tcp }); - private static readonly CosmosClient[] Clients = new CosmosClient[] { GatewayClient, DirectHttpsClient, RntbdClient }; + private static readonly CosmosClient[] Clients = new CosmosClient[] { GatewayClient, RntbdClient }; private static readonly CosmosClient Client = RntbdClient; private static readonly AsyncLazy Database = new AsyncLazy(async () => {