Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 1 addition & 13 deletions Microsoft.Azure.Cosmos/src/DocumentClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,6 @@ internal partial class DocumentClient : IDisposable, IAuthorizationTokenProvider
private IStoreClientFactory storeClientFactory;
internal CosmosHttpClient httpClient { get; private set; }

internal CosmosHttpClient thinClientModeHttpClient { get; private set; }
// Flag that indicates whether store client factory must be disposed whenever client is disposed.
// Setting this flag to false will result in store client factory not being disposed when client is disposed.
// This flag is used to allow shared store client factory survive disposition of a document client while other clients continue using it.
Expand Down Expand Up @@ -974,17 +973,6 @@ internal virtual void Initialize(Uri serviceEndpoint,
this.receivedResponse,
this.chaosInterceptor);

if (enableThinClientMode)
{
this.thinClientModeHttpClient = CosmosHttpClientCore.CreateWithConnectionPolicy(
this.ApiType,
DocumentClientEventSource.Instance,
this.ConnectionPolicy,
null,
this.sendingRequest,
this.receivedResponse);
}

// Loading VM Information (non blocking call and initialization won't fail if this call fails)
VmMetadataApiHandler.TryInitialize(this.httpClient);

Expand Down Expand Up @@ -1109,7 +1097,7 @@ private async Task<bool> GetInitializationTaskAsync(IStoreClientFactory storeCli
(Cosmos.ConsistencyLevel)this.accountServiceConfiguration.DefaultConsistencyLevel,
this.eventSource,
this.serializerSettings,
this.thinClientModeHttpClient);
this.httpClient);

thinClientStoreModel.SetCaches(this.partitionKeyRangeCache, this.collectionCache);

Expand Down
3 changes: 1 addition & 2 deletions Microsoft.Azure.Cosmos/src/ThinClientTransportSerializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,7 @@ public static async Task<Stream> SerializeProxyRequestAsync(
{
await serializedRequest.CopyToStreamAsync(new MemoryStream(buffer, 0, length, true, true));

MemoryStream stream = new MemoryStream(buffer, 0, length, writable: false, publiclyVisible: false);
return stream;
return new MemoryStream(buffer, 0, length, writable: false, publiclyVisible: false);
}
catch
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -668,8 +668,94 @@ public async Task NonPartitionKeyLookupCacheTest(bool binaryEncodingEnabledInCli
{
Environment.SetEnvironmentVariable(ConfigurationManager.BinaryEncodingEnabled, null);
}
}

}

[TestMethod]
public async Task HttpRequestVersionIsOnePointOneWhenUsingGatewayMode()
{
Version httpVersionOnePointOne = new Version(1, 1);
int hitCount = 0;

using CosmosClient client = TestCommon.CreateCosmosClient(builder =>
{
builder.WithConnectionModeGateway();
builder.WithSendingRequestEventArgs((sender, e) =>
{
if (e.IsHttpRequest())
{
Assert.AreEqual(httpVersionOnePointOne, e.HttpRequest.Version);
hitCount++;
}
});
});

Cosmos.Database database = await client.CreateDatabaseIfNotExistsAsync("HttpVersionTestDb");
Container container = await database.CreateContainerIfNotExistsAsync("HttpVersionTestContainer", "/pk");

ToDoActivity testItem = ToDoActivity.CreateRandomToDoActivity();
ItemResponse<ToDoActivity> response = await container.CreateItemAsync<ToDoActivity>(testItem, new Cosmos.PartitionKey(testItem.pk));

Assert.IsNotNull(response);
Assert.AreEqual(HttpStatusCode.Created, response.StatusCode);
Assert.IsNotNull(response.Resource);
Assert.IsNotNull(response.Diagnostics);
Assert.IsTrue(hitCount > 0, "HTTP request event handler was not triggered");

await database.DeleteAsync();
}

[TestMethod]
public async Task HttpRequestVersionIsTwoPointZeroWhenUsingThinClientMode()
{
try
{
Environment.SetEnvironmentVariable(ConfigurationManager.ThinClientModeEnabled, "True");

Version expectedGatewayVersion = new(1, 1);
Version expectedThinClientVersion = new(2, 0);

List<Version> postRequestVersions = new();

using CosmosClient client = TestCommon.CreateCosmosClient(builder =>
{
builder.WithConnectionModeGateway();
builder.WithSendingRequestEventArgs((sender, e) =>
{
if (e.HttpRequest.Method == HttpMethod.Post)
{
postRequestVersions.Add(e.HttpRequest.Version);
}
});
});

Cosmos.Database database = await client.CreateDatabaseIfNotExistsAsync("HttpVersionTestDb");
Container container = await database.CreateContainerIfNotExistsAsync("HttpVersionTestContainer", "/pk");

ToDoActivity testItem = ToDoActivity.CreateRandomToDoActivity();

try
{
await container.CreateItemAsync(testItem, new Cosmos.PartitionKey(testItem.pk));
}
catch (CosmosException)
Comment thread
aavasthy marked this conversation as resolved.
Outdated
{
// Expected as thinclient is not supported in emulator.
}

Assert.AreEqual(3, postRequestVersions.Count, "Expected exactly 3 POST requests (DB, Container, Item).");

Assert.AreEqual(expectedGatewayVersion, postRequestVersions[0], "Expected HTTP/1.1 for CreateDatabaseAsync.");
Assert.AreEqual(expectedGatewayVersion, postRequestVersions[1], "Expected HTTP/1.1 for CreateContainerAsync.");
Assert.AreEqual(expectedThinClientVersion, postRequestVersions[2], "Expected HTTP/2.0 for CreateItemAsync.");

await database.DeleteAsync();
}
finally
{
Environment.SetEnvironmentVariable(ConfigurationManager.ThinClientModeEnabled, null);
}
}

[TestMethod]
[DataRow(true, true, DisplayName = "Test scenario when binary encoding is enabled at client level and expected stream response type is binary.")]
[DataRow(true, false, DisplayName = "Test scenario when binary encoding is enabled at client level and expected stream response type is text.")]
Expand Down
Loading