Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>io.tarantool</groupId>
Expand Down Expand Up @@ -42,11 +43,11 @@
<connection>scm:git:git@github.com:tarantool/cartridge-java-testcontainers.git</connection>
<developerConnection>scm:git:git@github.com:tarantool/cartridge-java-testcontainers.git</developerConnection>
<url>http://github.com/tarantool/cartridge-java-testcontainers/tree/master</url>
<tag>v0.4.6</tag>
</scm>
<tag>v0.4.6</tag>
</scm>

<properties>
<driver.version>0.6.0</driver.version>
<driver.version>0.7.0</driver.version>
<testcontainers.version>1.16.2</testcontainers.version>
<snakeyaml.version>1.26</snakeyaml.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
Expand Down Expand Up @@ -192,7 +193,8 @@
<manifestEntries>
<Bundle-ManifestVersion>2</Bundle-ManifestVersion>
<Bundle-Name>${project.name}</Bundle-Name>
<Bundle-SymbolicName>${project.groupId}.${project.artifactId}.source</Bundle-SymbolicName>
<Bundle-SymbolicName>${project.groupId}.${project.artifactId}.source
</Bundle-SymbolicName>
<Bundle-Vendor>${project.organization.name}</Bundle-Vendor>
</manifestEntries>
</archive>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ public class TarantoolCartridgeContainer extends GenericContainer<TarantoolCartr
private static final String ENV_TARANTOOL_WORKDIR = "TARANTOOL_WORKDIR";
private static final String ENV_TARANTOOL_RUNDIR = "TARANTOOL_RUNDIR";
private static final String ENV_TARANTOOL_DATADIR = "TARANTOOL_DATADIR";
private static final String ENV_TARANTOOL_INSTANCES_FILE = "TARANTOOL_INSTANCES_FILE";
private boolean useFixedPorts = false;

private String routerHost = ROUTER_HOST;
Expand All @@ -125,6 +126,20 @@ public TarantoolCartridgeContainer(String instancesFile, String topologyConfigur
this(DOCKERFILE, instancesFile, topologyConfigurationFile);
}

/**
* Create a container with default image and specified instances file from the classpath resources. Assumes that
* there is a file named Dockerfile in the project resources classpath.
*
* @param instancesFile path to instances.yml, relative to the classpath resources
* @param topologyConfigurationFile path to a topology bootstrap script, relative to the classpath resources
* @param buildArgs a map of arguments that will be passed to docker ARG commands on image build.
* This values can be overridden by environment.
*/
public TarantoolCartridgeContainer(String instancesFile, String topologyConfigurationFile,
Map<String, String> buildArgs) {
this(DOCKERFILE, "", instancesFile, topologyConfigurationFile, buildArgs);
}

/**
* Create a container with default image and specified instances file from the classpath resources
*
Expand Down Expand Up @@ -163,11 +178,11 @@ public TarantoolCartridgeContainer(String dockerFile, String buildImageName,
* @param instancesFile URL resource path to instances.yml relative in the classpath
* @param topologyConfigurationFile URL resource path to a topology bootstrap script in the classpath
* @param buildArgs a map of arguments that will be passed to docker ARG commands on image build.
* This values can be overriden by environment.
* This values can be overridden by environment.
*/
public TarantoolCartridgeContainer(String dockerFile, String buildImageName, String instancesFile,
String topologyConfigurationFile, final Map<String, String> buildArgs) {
this(withArguments(buildImage(dockerFile, buildImageName), buildArgs),
this(withArguments(buildImage(dockerFile, buildImageName), instancesFile, buildArgs),
instancesFile, topologyConfigurationFile);
}

Expand All @@ -181,10 +196,12 @@ private TarantoolCartridgeContainer(Future<String> image, String instancesFile,
this.clientHelper = new TarantoolContainerClientHelper(this);
}

private static Future<String> withArguments(ImageFromDockerfile image, final Map<String, String> buildArgs) {
private static Future<String> withArguments(ImageFromDockerfile image, String instancesFile,
final Map<String, String> buildArgs) {
if (!buildArgs.isEmpty()) {
image.withBuildArgs(buildArgs);
}

for (String envVariable : Arrays.asList(
ENV_TARANTOOL_VERSION,
ENV_TARANTOOL_SERVER_USER,
Expand All @@ -193,7 +210,8 @@ private static Future<String> withArguments(ImageFromDockerfile image, final Map
ENV_TARANTOOL_SERVER_GID,
ENV_TARANTOOL_WORKDIR,
ENV_TARANTOOL_RUNDIR,
ENV_TARANTOOL_DATADIR
ENV_TARANTOOL_DATADIR,
ENV_TARANTOOL_INSTANCES_FILE
)) {
String variableValue = System.getenv(envVariable);
if (variableValue != null) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
package org.testcontainers.containers;

import io.tarantool.driver.api.TarantoolClient;
import io.tarantool.driver.api.TarantoolClientConfig;
import io.tarantool.driver.api.TarantoolClientFactory;
import io.tarantool.driver.api.TarantoolResult;
import io.tarantool.driver.api.TarantoolServerAddress;
import io.tarantool.driver.api.retry.TarantoolRequestRetryPolicies;
import io.tarantool.driver.api.tuple.TarantoolTuple;
import io.tarantool.driver.auth.SimpleTarantoolCredentials;
import io.tarantool.driver.auth.TarantoolCredentials;
import io.tarantool.driver.core.ClusterTarantoolTupleClient;
import org.testcontainers.utility.MountableFile;

import java.nio.file.Paths;
Expand Down Expand Up @@ -35,25 +32,28 @@ public final class TarantoolContainerClientHelper {
this.container = container;
}

private TarantoolClient<TarantoolTuple, TarantoolResult<TarantoolTuple>>
createClient(TarantoolClientConfig config, TarantoolServerAddress address) {
return new ClusterTarantoolTupleClient(config, address);
private TarantoolClient<TarantoolTuple, TarantoolResult<TarantoolTuple>> createClient() {
return TarantoolClientFactory.createClient()
.withCredentials(container.getUsername(), container.getPassword())
.withAddress(container.getHost(), container.getPort())
.withRequestTimeout(5000)
.withRetryingByNumberOfAttempts(10,
TarantoolRequestRetryPolicies.retryNetworkErrors()
.or(TarantoolRequestRetryPolicies.retryNetworkErrors()), b -> b.withDelay(100))
.build();
}

/**
* Configure or return an already configured client connected to a Cartridge router
*
* @param config router instance client config
* @param address router host address
* @return a configured client
*/
public TarantoolClient<TarantoolTuple, TarantoolResult<TarantoolTuple>>
getClient(TarantoolClientConfig config, TarantoolServerAddress address) {
public TarantoolClient<TarantoolTuple, TarantoolResult<TarantoolTuple>> getClient() {
if (!container.isRunning()) {
throw new IllegalStateException("Cannot connect to Tarantool instance in a stopped container");
}
if (clientHolder.get() == null) {
clientHolder.compareAndSet(null, createClient(config, address));
clientHolder.compareAndSet(null, createClient());
}
return clientHolder.get();
}
Expand All @@ -74,10 +74,6 @@ public CompletableFuture<List<?>> executeCommand(String command, Object... argum
throw new IllegalStateException("Cannot execute commands in stopped container");
}

TarantoolCredentials credentials = new SimpleTarantoolCredentials(
container.getUsername(), container.getPassword());
TarantoolServerAddress address = new TarantoolServerAddress(container.getHost(), container.getPort());
TarantoolClientConfig config = TarantoolClientConfig.builder().withCredentials(credentials).build();
return getClient(config, address).eval(command, Arrays.asList(arguments));
return getClient().eval(command, Arrays.asList(arguments));
}
}
4 changes: 3 additions & 1 deletion src/main/resources/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ ARG TARANTOOL_SERVER_GID=1000
ARG TARANTOOL_WORKDIR="/app"
ARG TARANTOOL_RUNDIR="/tmp/run"
ARG TARANTOOL_DATADIR="/tmp/data"
ARG TARANTOOL_INSTANCES_FILE="./instances.yml"
ENV TARANTOOL_WORKDIR=$TARANTOOL_WORKDIR
ENV TARANTOOL_RUNDIR=$TARANTOOL_RUNDIR
ENV TARANTOOL_DATADIR=$TARANTOOL_DATADIR
ENV TARANTOOL_INSTANCES_FILE=$TARANTOOL_INSTANCES_FILE
RUN curl -L https://tarantool.io/installer.sh | VER=$TARANTOOL_VERSION /bin/bash -s -- --repo-only && \
yum -y install cmake make gcc gcc-c++ git unzip tarantool tarantool-devel cartridge-cli && \
yum clean all
Expand All @@ -21,4 +23,4 @@ RUN cartridge version

FROM tarantool-base AS cartridge-base
WORKDIR $TARANTOOL_WORKDIR
CMD cartridge build && cartridge start --run-dir=$TARANTOOL_RUNDIR --data-dir=$TARANTOOL_DATADIR
CMD cartridge build && cartridge start --run-dir=$TARANTOOL_RUNDIR --data-dir=$TARANTOOL_DATADIR --cfg=$TARANTOOL_INSTANCES_FILE