-
-
Notifications
You must be signed in to change notification settings - Fork 302
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Update CosmosDb image to vnext-preview version #1324
base: develop
Are you sure you want to change the base?
Changes from 4 commits
ddcbe02
4827b45
b991265
53f35d8
01bc2f9
87e978e
b620a7d
370afa2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
using Microsoft.Azure.Cosmos; | ||
|
||
namespace Testcontainers.CosmosDb; | ||
|
||
/// <inheritdoc cref="DockerContainer" /> | ||
|
@@ -20,11 +22,23 @@ public CosmosDbContainer(CosmosDbConfiguration configuration) | |
public string GetConnectionString() | ||
{ | ||
var properties = new Dictionary<string, string>(); | ||
properties.Add("AccountEndpoint", new UriBuilder(Uri.UriSchemeHttps, Hostname, GetMappedPublicPort(CosmosDbBuilder.CosmosDbPort)).ToString()); | ||
properties.Add("AccountEndpoint", new UriBuilder(Uri.UriSchemeHttp, Hostname, GetMappedPublicPort(CosmosDbBuilder.CosmosDbPort)).ToString()); | ||
properties.Add("AccountKey", CosmosDbBuilder.DefaultAccountKey); | ||
return string.Join(";", properties.Select(property => string.Join("=", property.Key, property.Value))); | ||
} | ||
|
||
/// <summary> | ||
/// Gets a configured cosmos client with connection mode set to Gateway. | ||
/// </summary> | ||
public CosmosClient CosmosClient | ||
=> new CosmosClient( | ||
GetConnectionString(), | ||
new() | ||
{ | ||
ConnectionMode = ConnectionMode.Gateway, | ||
HttpClientFactory = () => new(new UriRewriter(Hostname, GetMappedPublicPort(CosmosDbBuilder.CosmosDbPort))) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can use this.HttpClient here. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. According to the discussion here, it was agreed that it would be better to remove the dependency on the Cosmos Client and delegate the responsibility of creating the client to the consumer. |
||
}); | ||
|
||
/// <summary> | ||
/// Gets a configured HTTP message handler that automatically trusts the CosmosDb Emulator's certificate. | ||
/// </summary> | ||
|
@@ -50,7 +64,7 @@ private sealed class UriRewriter : DelegatingHandler | |
/// <param name="hostname">The target hostname.</param> | ||
/// <param name="port">The target port.</param> | ||
public UriRewriter(string hostname, ushort port) | ||
: base(new HttpClientHandler { ServerCertificateCustomValidationCallback = (_, _, _, _) => true }) | ||
: base(new HttpClientHandler()) | ||
{ | ||
_hostname = hostname; | ||
_port = port; | ||
|
@@ -59,8 +73,8 @@ public UriRewriter(string hostname, ushort port) | |
/// <inheritdoc /> | ||
protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) | ||
{ | ||
request.RequestUri = new UriBuilder(Uri.UriSchemeHttps, _hostname, _port, request.RequestUri.PathAndQuery).Uri; | ||
request.RequestUri = new UriBuilder(Uri.UriSchemeHttp, _hostname, _port, request.RequestUri.PathAndQuery).Uri; | ||
return base.SendAsync(request, cancellationToken); | ||
} | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it necessary to use the preview version as a default? I know that this image is quite new but users can always:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The advantage of this PR is the use of this image as default, as it delivers significantly better results compared to the current :latest. Additionally, some configurations made in this PR are not compatible between the :latest and :vnext-preview versions. Currently, the :vnext-preview version shows considerably better results than :latest.