Skip to content

Commit

Permalink
Socat sidecar proxy for Couchbase container to support random ports (#…
Browse files Browse the repository at this point in the history
…815)

* Use Socat sidecar container in Couchbase to randomize the ports

* add dynamic couchbase port mappings:
- updated couchbase sdk to support 5.5.0
- added all client ports to port mappings
- configuring couchbase through static_config file

* restructured couchbase tests to support multiple couchbase versions

* - added memcached_ssl_port
- added @ClassRule for the couchbase container tests instead of
  static variables to prevent race conditions
- configured socat to expose the bootstrap ports as target.
  These bootstrap ports are not added to the couchbase config file.

* moved shouldUseCorrectDockerImage to its own test class

* - increased kvTimeout for busy ci systems
- tool pleasing

* - couchbase sdk update
- minor code style and naming improvements
  • Loading branch information
klara-l authored and bsideup committed Aug 7, 2018
1 parent d2ff073 commit 7e99051
Show file tree
Hide file tree
Showing 9 changed files with 287 additions and 88 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,8 @@ private void tryStart(Profiler profiler) {
containerId = createCommand.exec().getId();
copyToFileContainerPathMap.forEach(this::copyFileToContainer);

containerIsCreated(containerId);

logger().info("Starting container with ID: {}", containerId);
profiler.start("Start container");
dockerClient.startContainerCmd(containerId).exec();
Expand Down Expand Up @@ -356,6 +358,10 @@ protected void configure() {

}

@SuppressWarnings({"EmptyMethod", "UnusedParameters"})
protected void containerIsCreated(String containerId) {
}

@SuppressWarnings({"EmptyMethod", "UnusedParameters"})
protected void containerIsStarting(InspectContainerResponse containerInfo) {
}
Expand Down Expand Up @@ -556,7 +562,10 @@ public void setWaitStrategy(org.testcontainers.containers.wait.strategy.WaitStra
* @see #waitingFor(org.testcontainers.containers.wait.strategy.WaitStrategy)
*/
protected void waitUntilContainerStarted() {
getWaitStrategy().waitUntilReady(this);
org.testcontainers.containers.wait.strategy.WaitStrategy waitStrategy = getWaitStrategy();
if (waitStrategy != null) {
waitStrategy.waitUntilReady(this);
}
}

/**
Expand Down Expand Up @@ -1028,8 +1037,8 @@ public void copyFileToContainer(MountableFile mountableLocalFile, String contain
@Override
public void copyFileFromContainer(String containerPath, String destinationPath) throws IOException {

if (!isRunning()) {
throw new IllegalStateException("copyFileToContainer can only be used while the Container is running");
if (!isCreated()) {
throw new IllegalStateException("copyFileFromContainer can only be used when the Container is created.");
}

try (final TarArchiveInputStream tarInputStream = new TarArchiveInputStream(this.dockerClient
Expand Down
2 changes: 1 addition & 1 deletion modules/couchbase/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ description = "Testcontainers :: Couchbase"

dependencies {
compile project(':testcontainers')
compile 'com.couchbase.client:java-client:2.5.7'
compile 'com.couchbase.client:java-client:2.6.1'
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,18 @@
import com.couchbase.client.java.query.N1qlParams;
import com.couchbase.client.java.query.N1qlQuery;
import com.couchbase.client.java.query.consistency.ScanConsistency;
import lombok.Getter;
import org.junit.After;

/**
* @author ctayeb
* Basic class that can be used for couchbase tests. It will clear the database after every test.
*/
public abstract class AbstractCouchbaseTest {

public static final String TEST_BUCKET = "test";

public static final String DEFAULT_PASSWORD = "password";

@Getter(lazy = true)
private final static CouchbaseContainer couchbaseContainer = initCouchbaseContainer();

@Getter(lazy = true)
private final static Bucket bucket = openBucket(TEST_BUCKET, DEFAULT_PASSWORD);
private Bucket bucket;

@After
public void clear() {
Expand All @@ -36,24 +31,31 @@ public void clear() {
}
}

private static CouchbaseContainer initCouchbaseContainer() {
CouchbaseContainer couchbaseContainer = new CouchbaseContainer()
.withNewBucket(DefaultBucketSettings.builder()
.enableFlush(true)
.name(TEST_BUCKET)
.password(DEFAULT_PASSWORD)
.quota(100)
.replicas(0)
.type(BucketType.COUCHBASE)
.build());
protected abstract CouchbaseContainer getCouchbaseContainer();

protected static CouchbaseContainer initCouchbaseContainer(String imageName) {
CouchbaseContainer couchbaseContainer = (imageName == null) ? new CouchbaseContainer() : new CouchbaseContainer(imageName);
couchbaseContainer.withNewBucket(DefaultBucketSettings.builder()
.enableFlush(true)
.name(TEST_BUCKET)
.password(DEFAULT_PASSWORD)
.quota(100)
.replicas(0)
.type(BucketType.COUCHBASE)
.build());
couchbaseContainer.start();
return couchbaseContainer;
}

private static Bucket openBucket(String bucketName, String password) {
CouchbaseCluster cluster = getCouchbaseContainer().getCouchbaseCluster();
Bucket bucket = cluster.openBucket(bucketName, password);
Runtime.getRuntime().addShutdownHook(new Thread(bucket::close));
protected synchronized Bucket getBucket() {
if (bucket == null) {
bucket = openBucket(TEST_BUCKET, DEFAULT_PASSWORD);
}
return bucket;
}

private Bucket openBucket(String bucketName, String password) {
CouchbaseCluster cluster = getCouchbaseContainer().getCouchbaseCluster();
return cluster.openBucket(bucketName, password);
}
}
Loading

0 comments on commit 7e99051

Please sign in to comment.