Skip to content

Instantly share code, notes, and snippets.

@ldoguin
Last active July 18, 2016 10:23
Show Gist options
  • Save ldoguin/3599ca3388aac6794156919271763fb8 to your computer and use it in GitHub Desktop.
Save ldoguin/3599ca3388aac6794156919271763fb8 to your computer and use it in GitHub Desktop.
This gist is using testcontainers(http://testcontainers.viewdocs.io/testcontainers-java/) and a custom Couchbase docker image.
package com.couchbase.fullstack;
import com.couchbase.client.core.CouchbaseCore;
import com.couchbase.client.java.Bucket;
import com.couchbase.client.java.CouchbaseCluster;
import com.couchbase.client.java.env.CouchbaseEnvironment;
import com.couchbase.client.java.env.DefaultCouchbaseEnvironment;
import org.junit.ClassRule;
import org.junit.Test;
import org.springframework.boot.autoconfigure.couchbase.CouchbaseProperties;
import org.springframework.util.Assert;
import org.testcontainers.containers.GenericContainer;
import org.testcontainers.containers.startupcheck.StartupCheckStrategy;
import org.testcontainers.containers.wait.HostPortWaitStrategy;
import org.testcontainers.containers.wait.HttpWaitStrategy;
import org.testcontainers.containers.wait.Wait;
import org.testcontainers.containers.wait.WaitStrategy;
/**
* Created by ldoguin on 15/07/16.
*/
public class FullTest {
@ClassRule
public static GenericContainer couchbase =
new GenericContainer("couchbase:unittest").withExposedPorts(8091, 8092, 8093, 8094, 11207, 11210, 11211, 18091, 18092, 18093)
.waitingFor(Wait.forHttp("/ui/index.html"));
@Test
public void cruding() throws InterruptedException {
Thread.sleep(1000);
CouchbaseEnvironment env = DefaultCouchbaseEnvironment.builder()
.bootstrapCarrierDirectPort(couchbase.getMappedPort(11210))
.bootstrapCarrierSslPort(couchbase.getMappedPort(11207))
.bootstrapHttpDirectPort(couchbase.getMappedPort(8091))
.bootstrapHttpSslPort(couchbase.getMappedPort(18091))
.queryPort(couchbase.getMappedPort(8093))
.build();
CouchbaseCluster cc = CouchbaseCluster.create(env);
Bucket bucket = cc.openBucket("beer-sample");
Assert.isTrue(bucket.exists("21st_amendment_brewery_cafe"));
bucket.close();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment