Skip to content

CouchbaseContainer does not correctly support .withReuse(true) #2794

@aaronjwhiteside

Description

@aaronjwhiteside

After the container has been started the second time around the health checks fail ,because now certain apis require authentication.

The culprit lies in containerIsStarting():

https://github.com/testcontainers/testcontainers-java/blob/master/modules/couchbase/src/main/java/org/testcontainers/couchbase/CouchbaseContainer.java#L188-L199

waitUntilNodeIsOnline() fails the second time around because configureAdminUser() has already been called which now protects the api used in waitUntilNodeIsOnline().

Our current work around looks something like this:

        final CouchbaseContainer couchbase = new CouchbaseContainer("couchbase:enterprise-6.5.0") {
            @Override
            protected void configure() {
                super.configure();
                // needed because a random network alias is assigned in addition to anything we try to set withNetworkAliases("couchbase") which causes the hash comparision to fail.
                setNetworkAliases(Collections.singletonList("couchbase"));
            }

            @Override
            protected void containerIsStarting(final InspectContainerResponse containerInfo, final boolean reused) {
                if (!reused) {
                    super.containerIsStarting(containerInfo, reused);
                }
            }

            @Override
            protected void containerIsStarted(final InspectContainerResponse containerInfo, final boolean reused) {
                if (!reused) {
                    super.containerIsStarted(containerInfo, reused);
                } else {
                    this.logger().info("Couchbase container is ready! UI available at http://{}:{}", this.getHost(), this.getMappedPort(8091));
                }
            }
        }

It would be good if the correct fix was applied upstream, so that others may take advantage of CouchbaseContainer and .withReuse(true).

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions