Skip to content

Commit

Permalink
feat: Add Milvus module (#1131)
Browse files Browse the repository at this point in the history
Co-authored-by: Andre Hofmeister <9199345+HofmeisterAn@users.noreply.github.com>
  • Loading branch information
roji and HofmeisterAn authored Feb 29, 2024
1 parent 2131fbd commit 8aed123
Show file tree
Hide file tree
Showing 12 changed files with 313 additions and 0 deletions.
1 change: 1 addition & 0 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
<PackageVersion Include="Microsoft.Azure.Cosmos" Version="3.32.1"/>
<PackageVersion Include="Microsoft.Azure.Kusto.Data" Version="11.3.3"/>
<PackageVersion Include="Microsoft.Data.SqlClient" Version="5.1.3"/>
<PackageVersion Include="Milvus.Client" Version="2.2.2-preview.6"/>
<PackageVersion Include="MongoDB.Driver" Version="2.19.0"/>
<PackageVersion Include="MyCouch" Version="7.6.0"/>
<PackageVersion Include="MySqlConnector" Version="2.2.5"/>
Expand Down
14 changes: 14 additions & 0 deletions Testcontainers.sln
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Testcontainers.LocalStack",
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Testcontainers.MariaDb", "src\Testcontainers.MariaDb\Testcontainers.MariaDb.csproj", "{4B204EB3-C478-422E-9B6F-62DF3871291A}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Testcontainers.Milvus", "src\Testcontainers.Milvus\Testcontainers.Milvus.csproj", "{B024E315-831F-429D-92AA-44B839AC10F4}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Testcontainers.Minio", "src\Testcontainers.Minio\Testcontainers.Minio.csproj", "{1266E1E6-5CEF-4161-8B45-83282455746E}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Testcontainers.MongoDb", "src\Testcontainers.MongoDb\Testcontainers.MongoDb.csproj", "{2613F146-6C66-4059-9D37-D48BA6B61515}"
Expand Down Expand Up @@ -151,6 +153,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Testcontainers.LocalStack.T
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Testcontainers.MariaDb.Tests", "tests\Testcontainers.MariaDb.Tests\Testcontainers.MariaDb.Tests.csproj", "{7F0AE083-9DB8-4BD4-91F7-C199DCC7301D}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Testcontainers.Milvus.Tests", "tests\Testcontainers.Milvus.Tests\Testcontainers.Milvus.Tests.csproj", "{5247DF94-32F3-4ED6-AE71-6AB4F4078E6D}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Testcontainers.Minio.Tests", "tests\Testcontainers.Minio.Tests\Testcontainers.Minio.Tests.csproj", "{5DB1F35F-B714-4B62-84BE-16A33084D3E1}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Testcontainers.MongoDb.Tests", "tests\Testcontainers.MongoDb.Tests\Testcontainers.MongoDb.Tests.csproj", "{82A7E7B8-3187-4CAE-845B-0BF43409B38A}"
Expand Down Expand Up @@ -300,6 +304,10 @@ Global
{4B204EB3-C478-422E-9B6F-62DF3871291A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4B204EB3-C478-422E-9B6F-62DF3871291A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4B204EB3-C478-422E-9B6F-62DF3871291A}.Release|Any CPU.Build.0 = Release|Any CPU
{B024E315-831F-429D-92AA-44B839AC10F4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B024E315-831F-429D-92AA-44B839AC10F4}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B024E315-831F-429D-92AA-44B839AC10F4}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B024E315-831F-429D-92AA-44B839AC10F4}.Release|Any CPU.Build.0 = Release|Any CPU
{1266E1E6-5CEF-4161-8B45-83282455746E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{1266E1E6-5CEF-4161-8B45-83282455746E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1266E1E6-5CEF-4161-8B45-83282455746E}.Release|Any CPU.ActiveCfg = Release|Any CPU
Expand Down Expand Up @@ -476,6 +484,10 @@ Global
{7F0AE083-9DB8-4BD4-91F7-C199DCC7301D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7F0AE083-9DB8-4BD4-91F7-C199DCC7301D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7F0AE083-9DB8-4BD4-91F7-C199DCC7301D}.Release|Any CPU.Build.0 = Release|Any CPU
{5247DF94-32F3-4ED6-AE71-6AB4F4078E6D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{5247DF94-32F3-4ED6-AE71-6AB4F4078E6D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5247DF94-32F3-4ED6-AE71-6AB4F4078E6D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{5247DF94-32F3-4ED6-AE71-6AB4F4078E6D}.Release|Any CPU.Build.0 = Release|Any CPU
{5DB1F35F-B714-4B62-84BE-16A33084D3E1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{5DB1F35F-B714-4B62-84BE-16A33084D3E1}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5DB1F35F-B714-4B62-84BE-16A33084D3E1}.Release|Any CPU.ActiveCfg = Release|Any CPU
Expand Down Expand Up @@ -583,6 +595,7 @@ Global
{FCF59758-2403-4EC9-9EAE-4EC69A3F27AF} = {673F23AE-7694-4BB9-ABD4-136D6C13634E}
{3792268A-EF08-4569-8118-991E08FD61C4} = {673F23AE-7694-4BB9-ABD4-136D6C13634E}
{4B204EB3-C478-422E-9B6F-62DF3871291A} = {673F23AE-7694-4BB9-ABD4-136D6C13634E}
{B024E315-831F-429D-92AA-44B839AC10F4} = {673F23AE-7694-4BB9-ABD4-136D6C13634E}
{1266E1E6-5CEF-4161-8B45-83282455746E} = {673F23AE-7694-4BB9-ABD4-136D6C13634E}
{2613F146-6C66-4059-9D37-D48BA6B61515} = {673F23AE-7694-4BB9-ABD4-136D6C13634E}
{121FB123-40D9-44D4-9AB7-AD57ED34F466} = {673F23AE-7694-4BB9-ABD4-136D6C13634E}
Expand Down Expand Up @@ -627,6 +640,7 @@ Global
{FA59D75A-8D3A-412C-92E6-4A56033162DD} = {7164F1FB-7F24-444A-ACD2-2C329C2B3CCF}
{728CBE16-1D52-4F84-AF01-7229E6013512} = {7164F1FB-7F24-444A-ACD2-2C329C2B3CCF}
{7F0AE083-9DB8-4BD4-91F7-C199DCC7301D} = {7164F1FB-7F24-444A-ACD2-2C329C2B3CCF}
{5247DF94-32F3-4ED6-AE71-6AB4F4078E6D} = {7164F1FB-7F24-444A-ACD2-2C329C2B3CCF}
{5DB1F35F-B714-4B62-84BE-16A33084D3E1} = {7164F1FB-7F24-444A-ACD2-2C329C2B3CCF}
{82A7E7B8-3187-4CAE-845B-0BF43409B38A} = {7164F1FB-7F24-444A-ACD2-2C329C2B3CCF}
{25DBED78-99F4-433F-BBF5-1B4E9DEAE437} = {7164F1FB-7F24-444A-ACD2-2C329C2B3CCF}
Expand Down
1 change: 1 addition & 0 deletions src/Testcontainers.Milvus/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
root = true
94 changes: 94 additions & 0 deletions src/Testcontainers.Milvus/MilvusBuilder.cs
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));
}
}
53 changes: 53 additions & 0 deletions src/Testcontainers.Milvus/MilvusConfiguration.cs
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)
{
}
}
25 changes: 25 additions & 0 deletions src/Testcontainers.Milvus/MilvusContainer.cs
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;
}
}
12 changes: 12 additions & 0 deletions src/Testcontainers.Milvus/Testcontainers.Milvus.csproj
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>
8 changes: 8 additions & 0 deletions src/Testcontainers.Milvus/Usings.cs
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;
1 change: 1 addition & 0 deletions tests/Testcontainers.Milvus.Tests/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
root = true
79 changes: 79 additions & 0 deletions tests/Testcontainers.Milvus.Tests/MilvusContainerTest.cs
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())
{
}
}
}
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>
7 changes: 7 additions & 0 deletions tests/Testcontainers.Milvus.Tests/Usings.cs
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;

0 comments on commit 8aed123

Please sign in to comment.