Skip to content

Commit

Permalink
Fix deprecation warnings in Testcontainers wait strategies
Browse files Browse the repository at this point in the history
  • Loading branch information
wilkinsona committed Apr 24, 2018
1 parent dc9254c commit 6c504a5
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import org.rnorth.ducttape.TimeoutException;
import org.rnorth.ducttape.unreliables.Unreliables;
import org.testcontainers.containers.GenericContainer;
import org.testcontainers.containers.wait.HostPortWaitStrategy;
import org.testcontainers.containers.wait.strategy.HostPortWaitStrategy;

/**
* A {@link GenericContainer} for Cassandra.
Expand All @@ -37,14 +37,22 @@ public class CassandraContainer extends Container {
private static final int PORT = 9042;

public CassandraContainer() {
super("cassandra:3.11.1", PORT, (container) -> container
.waitingFor(new WaitStrategy()).withStartupAttempts(3));
super("cassandra:3.11.1", PORT,
(container) -> container
.waitingFor(new WaitStrategy(container.getMappedPort(PORT)))
.withStartupAttempts(3));
}

private static class WaitStrategy extends HostPortWaitStrategy {

private final int port;

private WaitStrategy(int port) {
this.port = port;
}

@Override
public void waitUntilReady(GenericContainer container) {
public void waitUntilReady() {
super.waitUntilReady();

try {
Expand All @@ -58,8 +66,7 @@ public void waitUntilReady(GenericContainer container) {

private Callable<Boolean> checkConnection() {
return () -> {
try (Cluster cluster = Cluster.builder()
.withPort(container.getMappedPort(PORT))
try (Cluster cluster = Cluster.builder().withPort(this.port)
.addContactPoint("localhost").build()) {
cluster.connect();
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import org.rnorth.ducttape.TimeoutException;
import org.rnorth.ducttape.unreliables.Unreliables;
import org.testcontainers.containers.GenericContainer;
import org.testcontainers.containers.wait.HostPortWaitStrategy;
import org.testcontainers.containers.wait.strategy.HostPortWaitStrategy;

/**
* A {@link GenericContainer} for Neo4J.
Expand All @@ -34,19 +34,28 @@
*/
public class Neo4jContainer extends Container {

private static final int PORT = 7687;

public Neo4jContainer() {
super("neo4j:3.3.1", 7687, (container) -> container.waitingFor(new WaitStrategy())
.withEnv("NEO4J_AUTH", "none"));
super("neo4j:3.3.1", PORT,
(container) -> container
.waitingFor(new WaitStrategy(container.getMappedPort(PORT)))
.withEnv("NEO4J_AUTH", "none"));
}

private static class WaitStrategy extends HostPortWaitStrategy {

private final int port;

private WaitStrategy(int port) {
this.port = port;
}

@Override
public void waitUntilReady(GenericContainer container) {
public void waitUntilReady() {
super.waitUntilReady();
Configuration configuration = new Configuration.Builder()
.uri("bolt://localhost:" + container.getMappedPort(7687))
.build();
.uri("bolt://localhost:" + this.port).build();
SessionFactory sessionFactory = new SessionFactory(configuration,
"org.springframework.boot.test.autoconfigure.data.neo4j");
try {
Expand Down

0 comments on commit 6c504a5

Please sign in to comment.