Closed fasilmarshooq closed 2 months ago
Which version (tag) did you use exactly? I tested community-7.6.2
and latest
, and I did not run into any issues. I think latest
refers to the enterprise version, which is not specifically supported or tested.
The current unit test doesnt point to any version , so i think its pointing to latest.
i face the same issue even with the community edition
private readonly CouchbaseContainer _couchbaseContainer = new CouchbaseBuilder()
.WithImage("couchbase:community-7.6.2")
.Build();
Working with default testContainers but not with CoucheBase module
using Couchbase;
using Couchbase.Management.Buckets;
using DotNet.Testcontainers.Builders;
using DotNet.Testcontainers.Containers;
namespace testCoucheBase
{
public class Tests
{
private IContainer _couchbaseContainer;
private const string Username = "Administrator";
private const string Password = "password";
private const string BucketName = "YCS";
[OneTimeSetUp]
public async Task SetupAsync()
{
// Configure the Couchbase container
_couchbaseContainer = new ContainerBuilder()
.WithImage("couchbase:community-7.6.2")
.WithEnvironment("CB_USERNAME", Username)
.WithEnvironment("CB_PASSWORD", Password)
.WithPortBinding(8091, 8091)
.WithPortBinding(8093, 8093)
.WithPortBinding(11210, 11210)
.WithWaitStrategy(Wait.ForUnixContainer().UntilPortIsAvailable(8091))
.Build();
// Start the container
await _couchbaseContainer.StartAsync();
// Initialize the cluster
await _couchbaseContainer.ExecAsync(new[] {
"couchbase-cli", "cluster-init",
"--cluster-username", Username,
"--cluster-password", Password,
"--services", "data,index,query",
"--cluster-ramsize", "512",
"--cluster-index-ramsize", "256"
});
}
[OneTimeTearDown]
public async Task TearDown()
{
await _couchbaseContainer.StopAsync();
await _couchbaseContainer.DisposeAsync();
}
[Test]
public async Task Test1()
{
var clusterOptions = new ClusterOptions
{
UserName = Username,
Password = Password,
ConnectionString = "couchbase://127.0.0.1" // For some reason not able to connect via localHost since docker is running in wsl and i can access management ui from browser using localHost
};
var cluster = await Cluster.ConnectAsync(clusterOptions);
IBucketManager manager = cluster.Buckets;
await CreateBucket(manager);
// Open the default bucket
var bucket = await manager.GetBucketAsync(BucketName);
// Perform operations with the bucket...
Assert.IsNotNull(bucket);
}
private static async Task CreateBucket(IBucketManager manager)
{
// create a bucket
var bucketSettings = new BucketSettings();
bucketSettings.Name = BucketName;
bucketSettings.BucketType = BucketType.Couchbase;
bucketSettings.RamQuotaMB = 100;
await manager.CreateBucketAsync(bucketSettings);
}
}
}
May be the issue is because the docker is running in wsl and the module is not able to resolve the ports properly ?
May be the issue is because the docker is running in wsl and the module is not able to resolve the ports properly ?
Hmm, that is unlikely. I am using WSL as well and tested three different versions, running the tests for a while (on two different devices). None of them encountered a null reference.
// For some reason not able to connect via localHost since docker is running in wsl and i can access management ui from browser using localHost
This is likely due to https://github.com/testcontainers/testcontainers-dotnet/issues/825, but using the provided connection string, we ensure it resolves the correct host and port.
Could you please set a breakpoint at PingAsync()
, share the connection string, the container logs, and check if the container is still running? The console should also include a log message that contains the URL to the web interface. Check if you can access it. The log message should look like:
Couchbase container is ready! UI available at http://127.0.0.1:60745/.
connection string is couchbase://localhost at the point and yes the container was still running
connection string is couchbase://localhost at the point and yes the container was still running
localhost
is very likely not correct. According to your environment, it should be 127.0.0.1
.
Hi, PTAL at this PR in tc-java
tried on one of my colleagues laptop the connection string is properly resolved as 127.0.0.1
, some thing wrong with my machine when bridges to wsl i guess.
Thanks for the help mate! , we at Agoda really love your work.
Testcontainers version
3.9.0
Using the latest Testcontainers version?
Yes
Host OS
Windows
Host arch
x64
.NET version
8.0
Docker version
Docker info
What happened?
Object reference not set to an instance of an object
on https://github.com/testcontainers/testcontainers-dotnet/blob/develop/tests/Testcontainers.Couchbase.Tests/CouchbaseContainerTest.cs#L31at Couchbase.Diagnostics.DiagnosticsReportProvider.CreatePingReportAsync(ClusterContext context, BucketConfig config, PingOptions options)
Relevant log output
Additional information
docker run -d --name couchbase -p 8091-8094:8091-8094 -p 11210:11210 couchbase
and run the same test against it.