From 9e310eca390ba05d8b4d553772d6b783e6e72436 Mon Sep 17 00:00:00 2001 From: Gavin deKock Date: Sun, 15 Sep 2024 01:11:51 +0100 Subject: [PATCH 01/11] Added support for Cassandra 5.0 TestConainer --- Testcontainers.sln | 14 ++++ src/Testcontainers.Cassandra/.editorconfig | 1 + .../CassandraBuilder.cs | 77 +++++++++++++++++++ .../CassandraConfiguration.cs | 54 +++++++++++++ .../CassandraContainer.cs | 39 ++++++++++ .../Testcontainers.Cassandra.csproj | 16 ++++ src/Testcontainers.Cassandra/Usings.cs | 10 +++ .../CassandraContainerTest.cs | 52 +++++++++++++ .../Testcontainers.Cassandra.Tests.csproj | 21 +++++ .../Testcontainers.Cassandra.Tests/Usings.cs | 5 ++ 10 files changed, 289 insertions(+) create mode 100644 src/Testcontainers.Cassandra/.editorconfig create mode 100644 src/Testcontainers.Cassandra/CassandraBuilder.cs create mode 100644 src/Testcontainers.Cassandra/CassandraConfiguration.cs create mode 100644 src/Testcontainers.Cassandra/CassandraContainer.cs create mode 100644 src/Testcontainers.Cassandra/Testcontainers.Cassandra.csproj create mode 100644 src/Testcontainers.Cassandra/Usings.cs create mode 100644 tests/Testcontainers.Cassandra.Tests/CassandraContainerTest.cs create mode 100644 tests/Testcontainers.Cassandra.Tests/Testcontainers.Cassandra.Tests.csproj create mode 100644 tests/Testcontainers.Cassandra.Tests/Usings.cs diff --git a/Testcontainers.sln b/Testcontainers.sln index e8c10a811..9976e9323 100644 --- a/Testcontainers.sln +++ b/Testcontainers.sln @@ -199,6 +199,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Testcontainers.Tests", "tes EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Testcontainers.WebDriver.Tests", "tests\Testcontainers.WebDriver.Tests\Testcontainers.WebDriver.Tests.csproj", "{EBA72C3B-57D5-43FF-A5B4-3D55B3B6D4C2}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Testcontainers.Cassandra.Tests", "tests\Testcontainers.Cassandra.Tests\Testcontainers.Cassandra.Tests.csproj", "{817CA7E2-7BFE-47CB-927F-B92D63C7E43F}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Testcontainers.Cassandra", "src\Testcontainers.Cassandra\Testcontainers.Cassandra.csproj", "{A434D20C-C518-446C-A8C3-FF907D25E045}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -580,6 +584,14 @@ Global {EBA72C3B-57D5-43FF-A5B4-3D55B3B6D4C2}.Debug|Any CPU.Build.0 = Debug|Any CPU {EBA72C3B-57D5-43FF-A5B4-3D55B3B6D4C2}.Release|Any CPU.ActiveCfg = Release|Any CPU {EBA72C3B-57D5-43FF-A5B4-3D55B3B6D4C2}.Release|Any CPU.Build.0 = Release|Any CPU + {817CA7E2-7BFE-47CB-927F-B92D63C7E43F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {817CA7E2-7BFE-47CB-927F-B92D63C7E43F}.Debug|Any CPU.Build.0 = Debug|Any CPU + {817CA7E2-7BFE-47CB-927F-B92D63C7E43F}.Release|Any CPU.ActiveCfg = Release|Any CPU + {817CA7E2-7BFE-47CB-927F-B92D63C7E43F}.Release|Any CPU.Build.0 = Release|Any CPU + {A434D20C-C518-446C-A8C3-FF907D25E045}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {A434D20C-C518-446C-A8C3-FF907D25E045}.Debug|Any CPU.Build.0 = Debug|Any CPU + {A434D20C-C518-446C-A8C3-FF907D25E045}.Release|Any CPU.ActiveCfg = Release|Any CPU + {A434D20C-C518-446C-A8C3-FF907D25E045}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(NestedProjects) = preSolution {5365F780-0E6C-41F0-B1B9-7DC34368F80C} = {673F23AE-7694-4BB9-ABD4-136D6C13634E} @@ -675,5 +687,7 @@ Global {1A1983E6-5297-435F-B467-E8E1F11277D6} = {7164F1FB-7F24-444A-ACD2-2C329C2B3CCF} {27CDB869-A150-4593-958F-6F26E5391E7C} = {7164F1FB-7F24-444A-ACD2-2C329C2B3CCF} {EBA72C3B-57D5-43FF-A5B4-3D55B3B6D4C2} = {7164F1FB-7F24-444A-ACD2-2C329C2B3CCF} + {817CA7E2-7BFE-47CB-927F-B92D63C7E43F} = {7164F1FB-7F24-444A-ACD2-2C329C2B3CCF} + {A434D20C-C518-446C-A8C3-FF907D25E045} = {673F23AE-7694-4BB9-ABD4-136D6C13634E} EndGlobalSection EndGlobal diff --git a/src/Testcontainers.Cassandra/.editorconfig b/src/Testcontainers.Cassandra/.editorconfig new file mode 100644 index 000000000..6f066619d --- /dev/null +++ b/src/Testcontainers.Cassandra/.editorconfig @@ -0,0 +1 @@ +root = true \ No newline at end of file diff --git a/src/Testcontainers.Cassandra/CassandraBuilder.cs b/src/Testcontainers.Cassandra/CassandraBuilder.cs new file mode 100644 index 000000000..31068f30a --- /dev/null +++ b/src/Testcontainers.Cassandra/CassandraBuilder.cs @@ -0,0 +1,77 @@ +namespace Testcontainers.Cassandra +{ + /// + [PublicAPI] + public sealed class CassandraBuilder : ContainerBuilder + { + public const string CassandraImage = "library/cassandra:5.0.0"; + + public const ushort CqlPort = 9042; + + public const string DefaultLocalDataCentre = "datacentre1"; + + /// + /// Initializes a new instance of the class. + /// + public CassandraBuilder() + : this(new CassandraConfiguration()) + { + DockerResourceConfiguration = Init().DockerResourceConfiguration; + } + + /// + /// Initializes a new instance of the class. + /// + /// The Docker resource configuration. + private CassandraBuilder(CassandraConfiguration resourceConfiguration) + : base(resourceConfiguration) + { + DockerResourceConfiguration = resourceConfiguration; + } + + /// + protected override CassandraConfiguration DockerResourceConfiguration { get; } + + /// + public override CassandraContainer Build() + { + return new CassandraContainer(DockerResourceConfiguration); + } + + /// + protected override CassandraBuilder Init() + { + return base.Init() + .WithImage(CassandraImage) + .WithPortBinding(CqlPort, true) + .WithEnvironment("CASSANDRA_SNITCH", "GossipingPropertyFileSnitch") + .WithEnvironment("JVM_OPTS", "-Dcassandra.skip_wait_for_gossip_to_settle=0 -Dcassandra.initial_token=0") + .WithEnvironment("HEAP_NEWSIZE", "128M") + .WithEnvironment("MAX_HEAP_SIZE", "1024M") + .WithEnvironment("CASSANDRA_ENDPOINT_SNITCH", "GossipingPropertyFileSnitch") + .WithEnvironment("CASSANDRA_DC", DefaultLocalDataCentre) + .WithWaitStrategy( + Wait.ForUnixContainer() + .UntilPortIsAvailable(CqlPort) + .UntilMessageIsLogged("Startup complete")); + } + + /// + protected override CassandraBuilder Clone(IResourceConfiguration resourceConfiguration) + { + return Merge(DockerResourceConfiguration, new CassandraConfiguration(resourceConfiguration)); + } + + /// + protected override CassandraBuilder Clone(IContainerConfiguration resourceConfiguration) + { + return Merge(DockerResourceConfiguration, new CassandraConfiguration(resourceConfiguration)); + } + + /// + protected override CassandraBuilder Merge(CassandraConfiguration oldValue, CassandraConfiguration newValue) + { + return new CassandraBuilder(new CassandraConfiguration(oldValue, newValue)); + } + } +} \ No newline at end of file diff --git a/src/Testcontainers.Cassandra/CassandraConfiguration.cs b/src/Testcontainers.Cassandra/CassandraConfiguration.cs new file mode 100644 index 000000000..88b569519 --- /dev/null +++ b/src/Testcontainers.Cassandra/CassandraConfiguration.cs @@ -0,0 +1,54 @@ +namespace Testcontainers.Cassandra +{ + /// + [PublicAPI] + public sealed class CassandraConfiguration : ContainerConfiguration + { + /// + /// Initializes a new instance of the class. + /// + public CassandraConfiguration() + { + } + + /// + /// Initializes a new instance of the class. + /// + /// The Docker resource configuration. + public CassandraConfiguration(IResourceConfiguration resourceConfiguration) + : base(resourceConfiguration) + { + // Passes the configuration upwards to the base implementations to create an updated immutable copy. + } + + /// + /// Initializes a new instance of the class. + /// + /// The Docker resource configuration. + public CassandraConfiguration(IContainerConfiguration resourceConfiguration) + : base(resourceConfiguration) + { + // Passes the configuration upwards to the base implementations to create an updated immutable copy. + } + + /// + /// Initializes a new instance of the class. + /// + /// The Docker resource configuration. + public CassandraConfiguration(CassandraConfiguration resourceConfiguration) + : this(new CassandraConfiguration(), resourceConfiguration) + { + // Passes the configuration upwards to the base implementations to create an updated immutable copy. + } + + /// + /// Initializes a new instance of the class. + /// + /// The old Docker resource configuration. + /// The new Docker resource configuration. + public CassandraConfiguration(CassandraConfiguration oldValue, CassandraConfiguration newValue) + : base(oldValue, newValue) + { + } + } +} \ No newline at end of file diff --git a/src/Testcontainers.Cassandra/CassandraContainer.cs b/src/Testcontainers.Cassandra/CassandraContainer.cs new file mode 100644 index 000000000..97e61f74f --- /dev/null +++ b/src/Testcontainers.Cassandra/CassandraContainer.cs @@ -0,0 +1,39 @@ +using System.Net; + +namespace Testcontainers.Cassandra +{ + /// + [PublicAPI] + public class CassandraContainer : DockerContainer + { + private readonly CassandraConfiguration _configuration; + + /// + public CassandraContainer(CassandraConfiguration configuration) : base(configuration) + { + _configuration = configuration; + } + + public IPEndPoint GetEndPoint() + { + return new IPEndPoint(IPAddress.Loopback, GetMappedPublicPort(CassandraBuilder.CqlPort)); + } + + /// + /// Executes the SQL script in the Cassandra container. + /// + /// The content of the CQL script to execute. + /// Cancellation token. + /// Task that completes when the CQL script has been executed. + public async Task ExecScriptAsync(string scriptContent, CancellationToken ct = default) + { + var scriptFilePath = string.Join("/", string.Empty, "tmp", Guid.NewGuid().ToString("D"), Path.GetRandomFileName()); + + await CopyAsync(Encoding.Default.GetBytes(scriptContent), scriptFilePath, Unix.FileMode644, ct) + .ConfigureAwait(false); + + return await ExecAsync(new[] { "cqlsh", "-f", scriptFilePath }, ct) + .ConfigureAwait(false); + } + } +} diff --git a/src/Testcontainers.Cassandra/Testcontainers.Cassandra.csproj b/src/Testcontainers.Cassandra/Testcontainers.Cassandra.csproj new file mode 100644 index 000000000..c0d904ddf --- /dev/null +++ b/src/Testcontainers.Cassandra/Testcontainers.Cassandra.csproj @@ -0,0 +1,16 @@ + + + + net6.0;net8.0;netstandard2.0;netstandard2.1 + latest + + + + + + + + + + + diff --git a/src/Testcontainers.Cassandra/Usings.cs b/src/Testcontainers.Cassandra/Usings.cs new file mode 100644 index 000000000..3c22a4545 --- /dev/null +++ b/src/Testcontainers.Cassandra/Usings.cs @@ -0,0 +1,10 @@ +global using System; +global using System.IO; +global using System.Text; +global using System.Threading; +global using System.Threading.Tasks; +global using Docker.DotNet.Models; +global using DotNet.Testcontainers.Builders; +global using DotNet.Testcontainers.Configurations; +global using DotNet.Testcontainers.Containers; +global using JetBrains.Annotations; \ No newline at end of file diff --git a/tests/Testcontainers.Cassandra.Tests/CassandraContainerTest.cs b/tests/Testcontainers.Cassandra.Tests/CassandraContainerTest.cs new file mode 100644 index 000000000..6b1ab7d31 --- /dev/null +++ b/tests/Testcontainers.Cassandra.Tests/CassandraContainerTest.cs @@ -0,0 +1,52 @@ +using System.Net; +using Cassandra; + +namespace Testcontainers.Cassandra.Tests +{ + public class CassandraContainerTest : IAsyncLifetime + { + private readonly CassandraContainer _cassandraContainer = new CassandraBuilder().Build(); + + public Task InitializeAsync() + { + return _cassandraContainer.StartAsync(); + } + + public Task DisposeAsync() + { + return _cassandraContainer.DisposeAsync().AsTask(); + } + + [Fact] + [Trait(nameof(DockerCli.DockerPlatform), nameof(DockerCli.DockerPlatform.Linux))] + public void ConnectionStateReturnsOpen() + { + // Given + var cluster = Cluster.Builder() + .AddContactPoint(_cassandraContainer.GetEndPoint()) + .Build(); + + // When + var session = cluster.Connect(); + + // Then + Assert.True(session.GetState().GetConnectedHosts().First().IsUp); + } + + [Fact] + [Trait(nameof(DockerCli.DockerPlatform), nameof(DockerCli.DockerPlatform.Linux))] + public async Task ExecScriptReturnsSuccessful() + { + // Given + const string scriptContent = "SELECT * FROM system.local;"; + + // When + var execResult = await _cassandraContainer.ExecScriptAsync(scriptContent) + .ConfigureAwait(true); + + // Then + Assert.True(0L.Equals(execResult.ExitCode), execResult.Stderr); + Assert.Empty(execResult.Stderr); + } + } +} diff --git a/tests/Testcontainers.Cassandra.Tests/Testcontainers.Cassandra.Tests.csproj b/tests/Testcontainers.Cassandra.Tests/Testcontainers.Cassandra.Tests.csproj new file mode 100644 index 000000000..88ecbb9e1 --- /dev/null +++ b/tests/Testcontainers.Cassandra.Tests/Testcontainers.Cassandra.Tests.csproj @@ -0,0 +1,21 @@ + + + + net8.0 + enable + enable + + + + + + + + + + + + + + + diff --git a/tests/Testcontainers.Cassandra.Tests/Usings.cs b/tests/Testcontainers.Cassandra.Tests/Usings.cs new file mode 100644 index 000000000..5b11f0abb --- /dev/null +++ b/tests/Testcontainers.Cassandra.Tests/Usings.cs @@ -0,0 +1,5 @@ +global using System.Data; +global using System.Data.Common; +global using System.Threading.Tasks; +global using DotNet.Testcontainers.Commons; +global using Xunit; From c728c883d9bb01236021dbf0adca257fa529bcf4 Mon Sep 17 00:00:00 2001 From: Gavin deKock Date: Sun, 15 Sep 2024 12:28:26 +0100 Subject: [PATCH 02/11] Added support for Cassandra 5.0 TestConainer --- Directory.Packages.props | 1 + docs/modules/index.md | 1 + .../Testcontainers.Cassandra.csproj | 10 +++----- .../Testcontainers.Cassandra.Tests.csproj | 23 ++++++++----------- 4 files changed, 15 insertions(+), 20 deletions(-) diff --git a/Directory.Packages.props b/Directory.Packages.props index bae22338e..9e012d84c 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -14,6 +14,7 @@ + diff --git a/docs/modules/index.md b/docs/modules/index.md index 38e925ce5..5b10fefd1 100644 --- a/docs/modules/index.md +++ b/docs/modules/index.md @@ -28,6 +28,7 @@ await moduleNameContainer.StartAsync(); | Azurite | `mcr.microsoft.com/azure-storage/azurite:3.24.0` | [NuGet](https://www.nuget.org/packages/Testcontainers.Azurite) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.Azurite) | | BigQuery | `ghcr.io/goccy/bigquery-emulator:0.4` | [NuGet](https://www.nuget.org/packages/Testcontainers.BigQuery) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.BigQuery) | | Bigtable | `gcr.io/google.com/cloudsdktool/google-cloud-cli:446.0.1-emulators` | [NuGet](https://www.nuget.org/packages/Testcontainers.Bigtable) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.Bigtable) | +| Cassandra | `library/cassandra:5.0.0` | [NuGet](https://www.nuget.org/packages/Testcontainers.Cassandra) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.Cassandra) | | ClickHouse | `clickhouse/clickhouse-server:23.6-alpine` | [NuGet](https://www.nuget.org/packages/Testcontainers.ClickHouse) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.ClickHouse) | | CockroachDB | `cockroachdb:23.1.13` | [NuGet](https://www.nuget.org/packages/Testcontainers.CockroachDb) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.CockroachDb) | | Consul | `consul:1.15` | [NuGet](https://www.nuget.org/packages/Testcontainers.Consul) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.Consul) | diff --git a/src/Testcontainers.Cassandra/Testcontainers.Cassandra.csproj b/src/Testcontainers.Cassandra/Testcontainers.Cassandra.csproj index c0d904ddf..0bc118e7c 100644 --- a/src/Testcontainers.Cassandra/Testcontainers.Cassandra.csproj +++ b/src/Testcontainers.Cassandra/Testcontainers.Cassandra.csproj @@ -1,16 +1,12 @@  - net6.0;net8.0;netstandard2.0;netstandard2.1 latest - - + - - + - - + \ No newline at end of file diff --git a/tests/Testcontainers.Cassandra.Tests/Testcontainers.Cassandra.Tests.csproj b/tests/Testcontainers.Cassandra.Tests/Testcontainers.Cassandra.Tests.csproj index 88ecbb9e1..8861a27e7 100644 --- a/tests/Testcontainers.Cassandra.Tests/Testcontainers.Cassandra.Tests.csproj +++ b/tests/Testcontainers.Cassandra.Tests/Testcontainers.Cassandra.Tests.csproj @@ -1,21 +1,18 @@  - - net8.0 - enable - enable + net8.0 + false + false - - - - + + + + + - - - - + + - From 704ef08a3d3264e2e6ebc2175709bb6953baf862 Mon Sep 17 00:00:00 2001 From: Gavin deKock Date: Sun, 15 Sep 2024 12:39:45 +0100 Subject: [PATCH 03/11] Added support for Cassandra 5.0 TestConainer --- .../Testcontainers.Cassandra.Tests/CassandraContainerTest.cs | 5 +---- tests/Testcontainers.Cassandra.Tests/Usings.cs | 4 ++-- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/tests/Testcontainers.Cassandra.Tests/CassandraContainerTest.cs b/tests/Testcontainers.Cassandra.Tests/CassandraContainerTest.cs index 6b1ab7d31..639ac6019 100644 --- a/tests/Testcontainers.Cassandra.Tests/CassandraContainerTest.cs +++ b/tests/Testcontainers.Cassandra.Tests/CassandraContainerTest.cs @@ -1,7 +1,4 @@ -using System.Net; -using Cassandra; - -namespace Testcontainers.Cassandra.Tests +namespace Testcontainers.Cassandra.Tests { public class CassandraContainerTest : IAsyncLifetime { diff --git a/tests/Testcontainers.Cassandra.Tests/Usings.cs b/tests/Testcontainers.Cassandra.Tests/Usings.cs index 5b11f0abb..25e8a9661 100644 --- a/tests/Testcontainers.Cassandra.Tests/Usings.cs +++ b/tests/Testcontainers.Cassandra.Tests/Usings.cs @@ -1,5 +1,5 @@ -global using System.Data; -global using System.Data.Common; +global using System.Linq; global using System.Threading.Tasks; +global using Cassandra; global using DotNet.Testcontainers.Commons; global using Xunit; From 10401bc586164fc3da092d3ff54478fbe7b19c1a Mon Sep 17 00:00:00 2001 From: Gavin de Kock Date: Sat, 12 Oct 2024 16:48:31 +0100 Subject: [PATCH 04/11] bump cassandra to 5.0.1 and fix usings --- src/Testcontainers.Cassandra/CassandraBuilder.cs | 2 +- src/Testcontainers.Cassandra/CassandraContainer.cs | 4 +--- src/Testcontainers.Cassandra/Usings.cs | 3 ++- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/Testcontainers.Cassandra/CassandraBuilder.cs b/src/Testcontainers.Cassandra/CassandraBuilder.cs index 31068f30a..f66323578 100644 --- a/src/Testcontainers.Cassandra/CassandraBuilder.cs +++ b/src/Testcontainers.Cassandra/CassandraBuilder.cs @@ -4,7 +4,7 @@ [PublicAPI] public sealed class CassandraBuilder : ContainerBuilder { - public const string CassandraImage = "library/cassandra:5.0.0"; + public const string CassandraImage = "library/cassandra:5.0.1"; public const ushort CqlPort = 9042; diff --git a/src/Testcontainers.Cassandra/CassandraContainer.cs b/src/Testcontainers.Cassandra/CassandraContainer.cs index 97e61f74f..182c22903 100644 --- a/src/Testcontainers.Cassandra/CassandraContainer.cs +++ b/src/Testcontainers.Cassandra/CassandraContainer.cs @@ -1,6 +1,4 @@ -using System.Net; - -namespace Testcontainers.Cassandra +namespace Testcontainers.Cassandra { /// [PublicAPI] diff --git a/src/Testcontainers.Cassandra/Usings.cs b/src/Testcontainers.Cassandra/Usings.cs index 3c22a4545..3b1dcb627 100644 --- a/src/Testcontainers.Cassandra/Usings.cs +++ b/src/Testcontainers.Cassandra/Usings.cs @@ -1,5 +1,6 @@ global using System; global using System.IO; +global using System.Net; global using System.Text; global using System.Threading; global using System.Threading.Tasks; @@ -7,4 +8,4 @@ global using DotNet.Testcontainers.Builders; global using DotNet.Testcontainers.Configurations; global using DotNet.Testcontainers.Containers; -global using JetBrains.Annotations; \ No newline at end of file +global using JetBrains.Annotations; From 29f1c403eb111c7b5028acf01a2ffbdba4ec32a7 Mon Sep 17 00:00:00 2001 From: Gavin de Kock Date: Sat, 12 Oct 2024 17:45:09 +0100 Subject: [PATCH 05/11] added test to confirm running cql using driver --- .../CassandraContainerTest.cs | 30 +++++++++++++++++-- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/tests/Testcontainers.Cassandra.Tests/CassandraContainerTest.cs b/tests/Testcontainers.Cassandra.Tests/CassandraContainerTest.cs index 639ac6019..16a0af368 100644 --- a/tests/Testcontainers.Cassandra.Tests/CassandraContainerTest.cs +++ b/tests/Testcontainers.Cassandra.Tests/CassandraContainerTest.cs @@ -32,17 +32,41 @@ public void ConnectionStateReturnsOpen() [Fact] [Trait(nameof(DockerCli.DockerPlatform), nameof(DockerCli.DockerPlatform.Linux))] - public async Task ExecScriptReturnsSuccessful() + public async Task DriverExecutesCqlStatementAndReturnResult() { // Given - const string scriptContent = "SELECT * FROM system.local;"; + const string selectFromSystemLocalStatement = "SELECT * FROM system.local WHERE key = ?;"; + var cluster = Cluster.Builder() + .AddContactPoint(_cassandraContainer.GetEndPoint()) + .Build(); + + // When + var session = await cluster.ConnectAsync(); + var preparedStatement = await session.PrepareAsync(selectFromSystemLocalStatement); + var boundStatement = preparedStatement.Bind("local"); + var result = await session.ExecuteAsync(boundStatement); + + // Then + Assert.True(result.IsFullyFetched); + var resultRows = result.GetRows().ToList(); + Assert.Single(resultRows); + Assert.Equal("COMPLETED", resultRows.First()["bootstrapped"]); + } + + [Fact] + [Trait(nameof(DockerCli.DockerPlatform), nameof(DockerCli.DockerPlatform.Linux))] + public async Task ExecScriptAsyncReturnsSuccess() + { + // Given + const string selectFromSystemLocalStatement = "SELECT * FROM system.local;"; // When - var execResult = await _cassandraContainer.ExecScriptAsync(scriptContent) + var execResult = await _cassandraContainer.ExecScriptAsync(selectFromSystemLocalStatement) .ConfigureAwait(true); // Then Assert.True(0L.Equals(execResult.ExitCode), execResult.Stderr); + Assert.NotEmpty(execResult.Stdout); Assert.Empty(execResult.Stderr); } } From c08c8dcffe1b2bba3006183595a7fa34df58a0ea Mon Sep 17 00:00:00 2001 From: Gavin de Kock Date: Sat, 12 Oct 2024 18:32:16 +0100 Subject: [PATCH 06/11] adding IDatabaseContainer --- src/Testcontainers.Cassandra/CassandraContainer.cs | 8 +++++++- .../CassandraContainerTest.cs | 2 +- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/Testcontainers.Cassandra/CassandraContainer.cs b/src/Testcontainers.Cassandra/CassandraContainer.cs index 182c22903..141424147 100644 --- a/src/Testcontainers.Cassandra/CassandraContainer.cs +++ b/src/Testcontainers.Cassandra/CassandraContainer.cs @@ -2,7 +2,7 @@ { /// [PublicAPI] - public class CassandraContainer : DockerContainer + public class CassandraContainer : DockerContainer, IDatabaseContainer { private readonly CassandraConfiguration _configuration; @@ -17,6 +17,11 @@ public IPEndPoint GetEndPoint() return new IPEndPoint(IPAddress.Loopback, GetMappedPublicPort(CassandraBuilder.CqlPort)); } + public string GetConnectionString() + { + throw new NotImplementedException(); + } + /// /// Executes the SQL script in the Cassandra container. /// @@ -33,5 +38,6 @@ await CopyAsync(Encoding.Default.GetBytes(scriptContent), scriptFilePath, Unix.F return await ExecAsync(new[] { "cqlsh", "-f", scriptFilePath }, ct) .ConfigureAwait(false); } + } } diff --git a/tests/Testcontainers.Cassandra.Tests/CassandraContainerTest.cs b/tests/Testcontainers.Cassandra.Tests/CassandraContainerTest.cs index 16a0af368..b53f9ef1e 100644 --- a/tests/Testcontainers.Cassandra.Tests/CassandraContainerTest.cs +++ b/tests/Testcontainers.Cassandra.Tests/CassandraContainerTest.cs @@ -1,6 +1,6 @@ namespace Testcontainers.Cassandra.Tests { - public class CassandraContainerTest : IAsyncLifetime + public sealed class CassandraContainerTest : IAsyncLifetime { private readonly CassandraContainer _cassandraContainer = new CassandraBuilder().Build(); From be0c952c3b03f100a8a4d8e5a54b529b4ee4c4f5 Mon Sep 17 00:00:00 2001 From: Gavin de Kock Date: Sat, 8 Feb 2025 20:18:30 +0000 Subject: [PATCH 07/11] Upgrade to C* 5.0.3 --- src/Testcontainers.Cassandra/CassandraBuilder.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Testcontainers.Cassandra/CassandraBuilder.cs b/src/Testcontainers.Cassandra/CassandraBuilder.cs index f66323578..90a5336bd 100644 --- a/src/Testcontainers.Cassandra/CassandraBuilder.cs +++ b/src/Testcontainers.Cassandra/CassandraBuilder.cs @@ -4,7 +4,7 @@ [PublicAPI] public sealed class CassandraBuilder : ContainerBuilder { - public const string CassandraImage = "library/cassandra:5.0.1"; + public const string CassandraImage = "library/cassandra:5.0.3"; public const ushort CqlPort = 9042; @@ -74,4 +74,4 @@ protected override CassandraBuilder Merge(CassandraConfiguration oldValue, Cassa return new CassandraBuilder(new CassandraConfiguration(oldValue, newValue)); } } -} \ No newline at end of file +} From 401c18a3690761e10d2c95d0f88714544a093a97 Mon Sep 17 00:00:00 2001 From: Gavin de Kock Date: Sat, 8 Feb 2025 20:18:52 +0000 Subject: [PATCH 08/11] Added net9.0 removed net6.0 --- src/Testcontainers.Cassandra/Testcontainers.Cassandra.csproj | 2 +- .../Testcontainers.Cassandra.Tests.csproj | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Testcontainers.Cassandra/Testcontainers.Cassandra.csproj b/src/Testcontainers.Cassandra/Testcontainers.Cassandra.csproj index 0bc118e7c..906f34018 100644 --- a/src/Testcontainers.Cassandra/Testcontainers.Cassandra.csproj +++ b/src/Testcontainers.Cassandra/Testcontainers.Cassandra.csproj @@ -1,6 +1,6 @@  - net6.0;net8.0;netstandard2.0;netstandard2.1 + net8.0;net9.0;netstandard2.0;netstandard2.1 latest diff --git a/tests/Testcontainers.Cassandra.Tests/Testcontainers.Cassandra.Tests.csproj b/tests/Testcontainers.Cassandra.Tests/Testcontainers.Cassandra.Tests.csproj index 8861a27e7..268dc4deb 100644 --- a/tests/Testcontainers.Cassandra.Tests/Testcontainers.Cassandra.Tests.csproj +++ b/tests/Testcontainers.Cassandra.Tests/Testcontainers.Cassandra.Tests.csproj @@ -1,6 +1,6 @@  - net8.0 + net9.0 false false From 5551ee3137aa82159ab77fefd6decbecf160bdc1 Mon Sep 17 00:00:00 2001 From: Gavin de Kock Date: Sat, 8 Feb 2025 20:19:29 +0000 Subject: [PATCH 09/11] Readded Testcontainers.C* and Testcontainers.Cassandra.Tests to the sln --- Testcontainers.sln | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/Testcontainers.sln b/Testcontainers.sln index 444bdb1c3..2c69556e3 100644 --- a/Testcontainers.sln +++ b/Testcontainers.sln @@ -209,6 +209,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Testcontainers.WebDriver.Te EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Testcontainers.Xunit.Tests", "tests\Testcontainers.Xunit.Tests\Testcontainers.Xunit.Tests.csproj", "{E901DF14-6F05-4FC2-825A-3055FAD33561}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Testcontainers.Cassandra", "src\Testcontainers.Cassandra\Testcontainers.Cassandra.csproj", "{8495D757-5FD7-491C-B941-9D43B3DCF3C0}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Testcontainers.Cassandra.Tests", "tests\Testcontainers.Cassandra.Tests\Testcontainers.Cassandra.Tests.csproj", "{C6A2B99E-BFD5-4510-83D7-A8844142F27D}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -610,6 +614,14 @@ Global {E901DF14-6F05-4FC2-825A-3055FAD33561}.Debug|Any CPU.Build.0 = Debug|Any CPU {E901DF14-6F05-4FC2-825A-3055FAD33561}.Release|Any CPU.ActiveCfg = Release|Any CPU {E901DF14-6F05-4FC2-825A-3055FAD33561}.Release|Any CPU.Build.0 = Release|Any CPU + {8495D757-5FD7-491C-B941-9D43B3DCF3C0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {8495D757-5FD7-491C-B941-9D43B3DCF3C0}.Debug|Any CPU.Build.0 = Debug|Any CPU + {8495D757-5FD7-491C-B941-9D43B3DCF3C0}.Release|Any CPU.ActiveCfg = Release|Any CPU + {8495D757-5FD7-491C-B941-9D43B3DCF3C0}.Release|Any CPU.Build.0 = Release|Any CPU + {C6A2B99E-BFD5-4510-83D7-A8844142F27D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {C6A2B99E-BFD5-4510-83D7-A8844142F27D}.Debug|Any CPU.Build.0 = Debug|Any CPU + {C6A2B99E-BFD5-4510-83D7-A8844142F27D}.Release|Any CPU.ActiveCfg = Release|Any CPU + {C6A2B99E-BFD5-4510-83D7-A8844142F27D}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(NestedProjects) = preSolution {5365F780-0E6C-41F0-B1B9-7DC34368F80C} = {673F23AE-7694-4BB9-ABD4-136D6C13634E} @@ -710,5 +722,7 @@ Global {DDB41BC8-5826-4D97-9C5F-001151E3FFD6} = {7164F1FB-7F24-444A-ACD2-2C329C2B3CCF} {EBA72C3B-57D5-43FF-A5B4-3D55B3B6D4C2} = {7164F1FB-7F24-444A-ACD2-2C329C2B3CCF} {E901DF14-6F05-4FC2-825A-3055FAD33561} = {7164F1FB-7F24-444A-ACD2-2C329C2B3CCF} + {8495D757-5FD7-491C-B941-9D43B3DCF3C0} = {673F23AE-7694-4BB9-ABD4-136D6C13634E} + {C6A2B99E-BFD5-4510-83D7-A8844142F27D} = {7164F1FB-7F24-444A-ACD2-2C329C2B3CCF} EndGlobalSection EndGlobal From fa910946c01148c880f05aed4892d7caf55c0a82 Mon Sep 17 00:00:00 2001 From: Gavin de Kock Date: Sat, 8 Feb 2025 22:44:39 +0000 Subject: [PATCH 10/11] Update Cassandra version in index.md --- docs/modules/index.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/modules/index.md b/docs/modules/index.md index 40386dde1..2d83a2b83 100644 --- a/docs/modules/index.md +++ b/docs/modules/index.md @@ -28,7 +28,7 @@ await moduleNameContainer.StartAsync(); | Azurite | `mcr.microsoft.com/azure-storage/azurite:3.24.0` | [NuGet](https://www.nuget.org/packages/Testcontainers.Azurite) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.Azurite) | | BigQuery | `ghcr.io/goccy/bigquery-emulator:0.4` | [NuGet](https://www.nuget.org/packages/Testcontainers.BigQuery) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.BigQuery) | | Bigtable | `gcr.io/google.com/cloudsdktool/google-cloud-cli:446.0.1-emulators` | [NuGet](https://www.nuget.org/packages/Testcontainers.Bigtable) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.Bigtable) | -| Cassandra | `library/cassandra:5.0.0` | [NuGet](https://www.nuget.org/packages/Testcontainers.Cassandra) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.Cassandra) | +| Cassandra | `library/cassandra:5.0.3` | [NuGet](https://www.nuget.org/packages/Testcontainers.Cassandra) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.Cassandra) | | ClickHouse | `clickhouse/clickhouse-server:23.6-alpine` | [NuGet](https://www.nuget.org/packages/Testcontainers.ClickHouse) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.ClickHouse) | | CockroachDB | `cockroachdb:23.1.13` | [NuGet](https://www.nuget.org/packages/Testcontainers.CockroachDb) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.CockroachDb) | | Consul | `consul:1.15` | [NuGet](https://www.nuget.org/packages/Testcontainers.Consul) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.Consul) | From 544b999446e9a88e79a02a551b6b35068d1cad0e Mon Sep 17 00:00:00 2001 From: Gavin de Kock Date: Sat, 8 Feb 2025 23:06:54 +0000 Subject: [PATCH 11/11] Added Testcontainers.Cassandra to cicd.yml --- .github/workflows/cicd.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/cicd.yml b/.github/workflows/cicd.yml index 642ce1a33..ad937c5df 100644 --- a/.github/workflows/cicd.yml +++ b/.github/workflows/cicd.yml @@ -42,6 +42,7 @@ jobs: { name: "Testcontainers.Azurite", runs-on: "ubuntu-22.04" }, { name: "Testcontainers.BigQuery", runs-on: "ubuntu-22.04" }, { name: "Testcontainers.Bigtable", runs-on: "ubuntu-22.04" }, + { name: "Testcontainers.Cassandra", runs-on: "ubuntu-22.04" }, { name: "Testcontainers.ClickHouse", runs-on: "ubuntu-22.04" }, { name: "Testcontainers.CockroachDb", runs-on: "ubuntu-22.04" }, { name: "Testcontainers.Consul", runs-on: "ubuntu-22.04" },