Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extends dynalite container from GenericContainer - for JUnit5 support #1114

Merged
merged 1 commit into from Jan 9, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -6,28 +6,23 @@
import com.amazonaws.client.builder.AwsClientBuilder;
import com.amazonaws.services.dynamodbv2.AmazonDynamoDB;
import com.amazonaws.services.dynamodbv2.AmazonDynamoDBClientBuilder;
import org.junit.rules.ExternalResource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.testcontainers.containers.GenericContainer;
import org.testcontainers.containers.output.Slf4jLogConsumer;

/**
* Container for Dynalite, a DynamoDB clone.
*/
public class DynaliteContainer extends ExternalResource {
public class DynaliteContainer extends GenericContainer<DynaliteContainer> {

private static final Logger LOGGER = LoggerFactory.getLogger(DynaliteContainer.class);
private final GenericContainer delegate;
private static final String IMAGE_NAME = "quay.io/testcontainers/dynalite:v1.2.1-1";
private static final int MAPPED_PORT = 4567;

public DynaliteContainer() {
this("quay.io/testcontainers/dynalite:v1.2.1-1");
this(IMAGE_NAME);
withExposedPorts(MAPPED_PORT);
}

public DynaliteContainer(String imageName) {
this.delegate = new GenericContainer(imageName)
.withExposedPorts(4567)
.withLogConsumer(new Slf4jLogConsumer(LOGGER));
super(imageName);
}

/**
Expand All @@ -51,8 +46,8 @@ public AmazonDynamoDB getClient() {
*/
public AwsClientBuilder.EndpointConfiguration getEndpointConfiguration() {
return new AwsClientBuilder.EndpointConfiguration("http://" +
this.delegate.getContainerIpAddress() + ":" +
this.delegate.getMappedPort(4567), null);
this.getContainerIpAddress() + ":" +
this.getMappedPort(MAPPED_PORT), null);
}

/**
Expand All @@ -64,13 +59,5 @@ public AWSCredentialsProvider getCredentials() {
return new AWSStaticCredentialsProvider(new BasicAWSCredentials("dummy", "dummy"));
}

@Override
protected void before() throws Throwable {
delegate.start();
}

@Override
protected void after() {
delegate.stop();
}
}