-
-
Notifications
You must be signed in to change notification settings - Fork 275
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Andre Hofmeister <9199345+HofmeisterAn@users.noreply.github.com>
- Loading branch information
1 parent
2131fbd
commit 8aed123
Showing
12 changed files
with
313 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
root = true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
namespace Testcontainers.Milvus; | ||
|
||
/// <inheritdoc cref="ContainerBuilder{TBuilderEntity, TContainerEntity, TConfigurationEntity}" /> | ||
[PublicAPI] | ||
public sealed class MilvusBuilder : ContainerBuilder<MilvusBuilder, MilvusContainer, MilvusConfiguration> | ||
{ | ||
public const string MilvusEtcdConfigFilePath = "/milvus/configs/embedEtcd.yaml"; | ||
|
||
public const string MilvusImage = "milvusdb/milvus:v2.3.10"; | ||
|
||
public const ushort MilvusManagementPort = 9091; | ||
|
||
public const ushort MilvusGrpcPort = 19530; | ||
|
||
private static readonly byte[] EtcdConfig = Encoding.Default.GetBytes(string.Join("\n", "advertise-client-urls: http://0.0.0.0:2379", "listen-client-urls: http://0.0.0.0:2379")); | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="MilvusBuilder" /> class. | ||
/// </summary> | ||
public MilvusBuilder() | ||
: this(new MilvusConfiguration()) | ||
{ | ||
DockerResourceConfiguration = Init().DockerResourceConfiguration; | ||
} | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="MilvusBuilder" /> class. | ||
/// </summary> | ||
/// <param name="resourceConfiguration">The Docker resource configuration.</param> | ||
private MilvusBuilder(MilvusConfiguration resourceConfiguration) | ||
: base(resourceConfiguration) | ||
{ | ||
DockerResourceConfiguration = resourceConfiguration; | ||
} | ||
|
||
/// <inheritdoc /> | ||
protected override MilvusConfiguration DockerResourceConfiguration { get; } | ||
|
||
/// <summary> | ||
/// Sets the etcd endpoint. | ||
/// </summary> | ||
/// <param name="etcdEndpoint">The etcd endpoint.</param> | ||
/// <returns>A configured instance of <see cref="MilvusBuilder" />.</returns> | ||
public MilvusBuilder WithEtcdEndpoint(string etcdEndpoint) | ||
{ | ||
return WithEnvironment("ETCD_USE_EMBED", "false") | ||
.WithEnvironment("ETCD_CONFIG_PATH", string.Empty) | ||
.WithEnvironment("ETCD_DATA_DIR", string.Empty) | ||
.WithEnvironment("ETCD_ENDPOINTS", etcdEndpoint); | ||
} | ||
|
||
/// <inheritdoc /> | ||
public override MilvusContainer Build() | ||
{ | ||
Validate(); | ||
return new MilvusContainer(DockerResourceConfiguration, TestcontainersSettings.Logger); | ||
} | ||
|
||
/// <inheritdoc /> | ||
protected override MilvusBuilder Init() | ||
{ | ||
return base.Init() | ||
.WithImage(MilvusImage) | ||
.WithPortBinding(MilvusManagementPort, true) | ||
.WithPortBinding(MilvusGrpcPort, true) | ||
.WithCommand("milvus", "run", "standalone") | ||
.WithEnvironment("COMMON_STORAGETYPE", "local") | ||
// For embedded etcd only; see WithEtcdEndpoint(string) for using an external etcd. | ||
.WithEnvironment("ETCD_USE_EMBED", "true") | ||
.WithEnvironment("ETCD_CONFIG_PATH", MilvusEtcdConfigFilePath) | ||
.WithEnvironment("ETCD_DATA_DIR", "/var/lib/milvus/etcd") | ||
.WithResourceMapping(EtcdConfig, MilvusEtcdConfigFilePath) | ||
.WithWaitStrategy(Wait.ForUnixContainer().UntilHttpRequestIsSucceeded(request => | ||
request.ForPort(MilvusManagementPort).ForPath("/healthz"))); | ||
} | ||
|
||
/// <inheritdoc /> | ||
protected override MilvusBuilder Clone(IResourceConfiguration<CreateContainerParameters> resourceConfiguration) | ||
{ | ||
return Merge(DockerResourceConfiguration, new MilvusConfiguration(resourceConfiguration)); | ||
} | ||
|
||
/// <inheritdoc /> | ||
protected override MilvusBuilder Clone(IContainerConfiguration resourceConfiguration) | ||
{ | ||
return Merge(DockerResourceConfiguration, new MilvusConfiguration(resourceConfiguration)); | ||
} | ||
|
||
/// <inheritdoc /> | ||
protected override MilvusBuilder Merge(MilvusConfiguration oldValue, MilvusConfiguration newValue) | ||
{ | ||
return new MilvusBuilder(new MilvusConfiguration(oldValue, newValue)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
namespace Testcontainers.Milvus; | ||
|
||
/// <inheritdoc cref="ContainerConfiguration" /> | ||
[PublicAPI] | ||
public sealed class MilvusConfiguration : ContainerConfiguration | ||
{ | ||
/// <summary> | ||
/// Initializes a new instance of the <see cref="MilvusConfiguration" /> class. | ||
/// </summary> | ||
public MilvusConfiguration() | ||
{ | ||
} | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="MilvusConfiguration" /> class. | ||
/// </summary> | ||
/// <param name="resourceConfiguration">The Docker resource configuration.</param> | ||
public MilvusConfiguration(IResourceConfiguration<CreateContainerParameters> resourceConfiguration) | ||
: base(resourceConfiguration) | ||
{ | ||
// Passes the configuration upwards to the base implementations to create an updated immutable copy. | ||
} | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="MilvusConfiguration" /> class. | ||
/// </summary> | ||
/// <param name="resourceConfiguration">The Docker resource configuration.</param> | ||
public MilvusConfiguration(IContainerConfiguration resourceConfiguration) | ||
: base(resourceConfiguration) | ||
{ | ||
// Passes the configuration upwards to the base implementations to create an updated immutable copy. | ||
} | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="MilvusConfiguration" /> class. | ||
/// </summary> | ||
/// <param name="resourceConfiguration">The Docker resource configuration.</param> | ||
public MilvusConfiguration(MilvusConfiguration resourceConfiguration) | ||
: this(new MilvusConfiguration(), resourceConfiguration) | ||
{ | ||
// Passes the configuration upwards to the base implementations to create an updated immutable copy. | ||
} | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="MilvusConfiguration" /> class. | ||
/// </summary> | ||
/// <param name="oldValue">The old Docker resource configuration.</param> | ||
/// <param name="newValue">The new Docker resource configuration.</param> | ||
public MilvusConfiguration(MilvusConfiguration oldValue, MilvusConfiguration newValue) | ||
: base(oldValue, newValue) | ||
{ | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
namespace Testcontainers.Milvus; | ||
|
||
/// <inheritdoc cref="DockerContainer" /> | ||
[PublicAPI] | ||
public sealed class MilvusContainer : DockerContainer | ||
{ | ||
/// <summary> | ||
/// Initializes a new instance of the <see cref="MilvusContainer" /> class. | ||
/// </summary> | ||
/// <param name="configuration">The container configuration.</param> | ||
/// <param name="logger">The logger.</param> | ||
public MilvusContainer(MilvusConfiguration configuration, ILogger logger) | ||
: base(configuration, logger) | ||
{ | ||
} | ||
|
||
/// <summary> | ||
/// Gets the Milvus endpoint. | ||
/// </summary> | ||
/// <returns>The Milvus endpoint.</returns> | ||
public Uri GetEndpoint() | ||
{ | ||
return new UriBuilder(Uri.UriSchemeHttp, Hostname, GetMappedPublicPort(MilvusBuilder.MilvusGrpcPort)).Uri; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<TargetFrameworks>net6.0;net8.0;netstandard2.0;netstandard2.1;net462</TargetFrameworks> | ||
<LangVersion>latest</LangVersion> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<PackageReference Include="JetBrains.Annotations" VersionOverride="2023.3.0" PrivateAssets="All"/> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<ProjectReference Include="../Testcontainers/Testcontainers.csproj"/> | ||
</ItemGroup> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
global using System; | ||
global using System.Text; | ||
global using Docker.DotNet.Models; | ||
global using DotNet.Testcontainers.Builders; | ||
global using DotNet.Testcontainers.Configurations; | ||
global using DotNet.Testcontainers.Containers; | ||
global using JetBrains.Annotations; | ||
global using Microsoft.Extensions.Logging; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
root = true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
namespace Testcontainers.Milvus; | ||
|
||
public abstract class MilvusContainerTest : IAsyncLifetime | ||
{ | ||
private const string MilvusVersion = "v2.3.10"; | ||
|
||
private readonly MilvusContainer _milvusContainer; | ||
|
||
private MilvusContainerTest(MilvusContainer milvusContainer) | ||
{ | ||
_milvusContainer = milvusContainer; | ||
} | ||
|
||
public Task InitializeAsync() | ||
{ | ||
return _milvusContainer.StartAsync(); | ||
} | ||
|
||
public Task DisposeAsync() | ||
{ | ||
return _milvusContainer.DisposeAsync().AsTask(); | ||
} | ||
|
||
[Fact] | ||
[Trait(nameof(DockerCli.DockerPlatform), nameof(DockerCli.DockerPlatform.Linux))] | ||
public async Task GetVersionReturnsExpectedVersion() | ||
{ | ||
// Given | ||
using var client = new MilvusClient(_milvusContainer.GetEndpoint()); | ||
|
||
// When | ||
var version = await client.GetVersionAsync() | ||
.ConfigureAwait(true); | ||
|
||
// Then | ||
Assert.Equal(MilvusVersion, version); | ||
} | ||
|
||
[UsedImplicitly] | ||
public sealed class MilvusDefaultConfiguration : MilvusContainerTest | ||
{ | ||
public MilvusDefaultConfiguration() | ||
: base(new MilvusBuilder().WithImage("milvusdb/milvus:" + MilvusVersion).Build()) | ||
{ | ||
} | ||
} | ||
|
||
[UsedImplicitly] | ||
public sealed class MilvusSidecarConfiguration : MilvusContainerTest | ||
{ | ||
public MilvusSidecarConfiguration() | ||
: this(new NetworkBuilder().Build()) | ||
{ | ||
} | ||
|
||
private MilvusSidecarConfiguration(INetwork network) | ||
: base(new MilvusBuilder() | ||
.WithImage("milvusdb/milvus:" + MilvusVersion) | ||
.WithEtcdEndpoint("etcd:2379") | ||
.DependsOn(new ContainerBuilder() | ||
.WithImage("quay.io/coreos/etcd:v3.5.5") | ||
.WithNetworkAliases("etcd") | ||
.WithCommand("etcd") | ||
.WithCommand("-advertise-client-urls=http://127.0.0.1:2379") | ||
.WithCommand("-listen-client-urls=http://0.0.0.0:2379") | ||
.WithCommand("-data-dir=/etcd") | ||
.WithEnvironment("ETCD_AUTO_COMPACTION_MODE", "periodic") | ||
.WithEnvironment("ETCD_AUTO_COMPACTION_RETENTION", "0") | ||
.WithEnvironment("ETCD_QUOTA_BACKEND_BYTES", "0") | ||
.WithEnvironment("ETCD_SNAPSHOT_COUNT", "100000") | ||
.WithWaitStrategy(Wait.ForUnixContainer().UntilMessageIsLogged("ready to serve client requests")) | ||
.DependsOn(network) | ||
.Build()) | ||
.DependsOn(network) | ||
.Build()) | ||
{ | ||
} | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
tests/Testcontainers.Milvus.Tests/Testcontainers.Milvus.Tests.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<TargetFrameworks>net8.0</TargetFrameworks> | ||
<IsPackable>false</IsPackable> | ||
<IsPublishable>false</IsPublishable> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk"/> | ||
<PackageReference Include="coverlet.collector"/> | ||
<PackageReference Include="xunit.runner.visualstudio"/> | ||
<PackageReference Include="xunit"/> | ||
<PackageReference Include="Milvus.Client"/> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<ProjectReference Include="../../src/Testcontainers.Milvus/Testcontainers.Milvus.csproj"/> | ||
<ProjectReference Include="../Testcontainers.Commons/Testcontainers.Commons.csproj"/> | ||
</ItemGroup> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
global using System.Threading.Tasks; | ||
global using DotNet.Testcontainers.Builders; | ||
global using DotNet.Testcontainers.Commons; | ||
global using DotNet.Testcontainers.Networks; | ||
global using JetBrains.Annotations; | ||
global using Milvus.Client; | ||
global using Xunit; |