Skip to content

Commit a9f9593

Browse files
authored
Bump driver, added instances file environment argument (#36)
* Bump driver, added instances file environment argument
1 parent c70ea40 commit a9f9593

File tree

4 files changed

+46
-28
lines changed

4 files changed

+46
-28
lines changed

pom.xml

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<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">
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
34
<modelVersion>4.0.0</modelVersion>
45

56
<groupId>io.tarantool</groupId>
@@ -42,11 +43,11 @@
4243
<connection>scm:git:git@github.com:tarantool/cartridge-java-testcontainers.git</connection>
4344
<developerConnection>scm:git:git@github.com:tarantool/cartridge-java-testcontainers.git</developerConnection>
4445
<url>http://github.com/tarantool/cartridge-java-testcontainers/tree/master</url>
45-
<tag>v0.4.6</tag>
46-
</scm>
46+
<tag>v0.4.6</tag>
47+
</scm>
4748

4849
<properties>
49-
<driver.version>0.6.0</driver.version>
50+
<driver.version>0.7.0</driver.version>
5051
<testcontainers.version>1.16.2</testcontainers.version>
5152
<snakeyaml.version>1.26</snakeyaml.version>
5253
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
@@ -192,7 +193,8 @@
192193
<manifestEntries>
193194
<Bundle-ManifestVersion>2</Bundle-ManifestVersion>
194195
<Bundle-Name>${project.name}</Bundle-Name>
195-
<Bundle-SymbolicName>${project.groupId}.${project.artifactId}.source</Bundle-SymbolicName>
196+
<Bundle-SymbolicName>${project.groupId}.${project.artifactId}.source
197+
</Bundle-SymbolicName>
196198
<Bundle-Vendor>${project.organization.name}</Bundle-Vendor>
197199
</manifestEntries>
198200
</archive>

src/main/java/org/testcontainers/containers/TarantoolCartridgeContainer.java

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ public class TarantoolCartridgeContainer extends GenericContainer<TarantoolCartr
101101
private static final String ENV_TARANTOOL_WORKDIR = "TARANTOOL_WORKDIR";
102102
private static final String ENV_TARANTOOL_RUNDIR = "TARANTOOL_RUNDIR";
103103
private static final String ENV_TARANTOOL_DATADIR = "TARANTOOL_DATADIR";
104+
private static final String ENV_TARANTOOL_INSTANCES_FILE = "TARANTOOL_INSTANCES_FILE";
104105
private boolean useFixedPorts = false;
105106

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

129+
/**
130+
* Create a container with default image and specified instances file from the classpath resources. Assumes that
131+
* there is a file named Dockerfile in the project resources classpath.
132+
*
133+
* @param instancesFile path to instances.yml, relative to the classpath resources
134+
* @param topologyConfigurationFile path to a topology bootstrap script, relative to the classpath resources
135+
* @param buildArgs a map of arguments that will be passed to docker ARG commands on image build.
136+
* This values can be overridden by environment.
137+
*/
138+
public TarantoolCartridgeContainer(String instancesFile, String topologyConfigurationFile,
139+
Map<String, String> buildArgs) {
140+
this(DOCKERFILE, "", instancesFile, topologyConfigurationFile, buildArgs);
141+
}
142+
128143
/**
129144
* Create a container with default image and specified instances file from the classpath resources
130145
*
@@ -163,11 +178,11 @@ public TarantoolCartridgeContainer(String dockerFile, String buildImageName,
163178
* @param instancesFile URL resource path to instances.yml relative in the classpath
164179
* @param topologyConfigurationFile URL resource path to a topology bootstrap script in the classpath
165180
* @param buildArgs a map of arguments that will be passed to docker ARG commands on image build.
166-
* This values can be overriden by environment.
181+
* This values can be overridden by environment.
167182
*/
168183
public TarantoolCartridgeContainer(String dockerFile, String buildImageName, String instancesFile,
169184
String topologyConfigurationFile, final Map<String, String> buildArgs) {
170-
this(withArguments(buildImage(dockerFile, buildImageName), buildArgs),
185+
this(withArguments(buildImage(dockerFile, buildImageName), instancesFile, buildArgs),
171186
instancesFile, topologyConfigurationFile);
172187
}
173188

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

184-
private static Future<String> withArguments(ImageFromDockerfile image, final Map<String, String> buildArgs) {
199+
private static Future<String> withArguments(ImageFromDockerfile image, String instancesFile,
200+
final Map<String, String> buildArgs) {
185201
if (!buildArgs.isEmpty()) {
186202
image.withBuildArgs(buildArgs);
187203
}
204+
188205
for (String envVariable : Arrays.asList(
189206
ENV_TARANTOOL_VERSION,
190207
ENV_TARANTOOL_SERVER_USER,
@@ -193,7 +210,8 @@ private static Future<String> withArguments(ImageFromDockerfile image, final Map
193210
ENV_TARANTOOL_SERVER_GID,
194211
ENV_TARANTOOL_WORKDIR,
195212
ENV_TARANTOOL_RUNDIR,
196-
ENV_TARANTOOL_DATADIR
213+
ENV_TARANTOOL_DATADIR,
214+
ENV_TARANTOOL_INSTANCES_FILE
197215
)) {
198216
String variableValue = System.getenv(envVariable);
199217
if (variableValue != null) {

src/main/java/org/testcontainers/containers/TarantoolContainerClientHelper.java

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
package org.testcontainers.containers;
22

33
import io.tarantool.driver.api.TarantoolClient;
4-
import io.tarantool.driver.api.TarantoolClientConfig;
4+
import io.tarantool.driver.api.TarantoolClientFactory;
55
import io.tarantool.driver.api.TarantoolResult;
6-
import io.tarantool.driver.api.TarantoolServerAddress;
6+
import io.tarantool.driver.api.retry.TarantoolRequestRetryPolicies;
77
import io.tarantool.driver.api.tuple.TarantoolTuple;
8-
import io.tarantool.driver.auth.SimpleTarantoolCredentials;
9-
import io.tarantool.driver.auth.TarantoolCredentials;
10-
import io.tarantool.driver.core.ClusterTarantoolTupleClient;
118
import org.testcontainers.utility.MountableFile;
129

1310
import java.nio.file.Paths;
@@ -35,25 +32,28 @@ public final class TarantoolContainerClientHelper {
3532
this.container = container;
3633
}
3734

38-
private TarantoolClient<TarantoolTuple, TarantoolResult<TarantoolTuple>>
39-
createClient(TarantoolClientConfig config, TarantoolServerAddress address) {
40-
return new ClusterTarantoolTupleClient(config, address);
35+
private TarantoolClient<TarantoolTuple, TarantoolResult<TarantoolTuple>> createClient() {
36+
return TarantoolClientFactory.createClient()
37+
.withCredentials(container.getUsername(), container.getPassword())
38+
.withAddress(container.getHost(), container.getPort())
39+
.withRequestTimeout(5000)
40+
.withRetryingByNumberOfAttempts(10,
41+
TarantoolRequestRetryPolicies.retryNetworkErrors()
42+
.or(TarantoolRequestRetryPolicies.retryNetworkErrors()), b -> b.withDelay(100))
43+
.build();
4144
}
4245

4346
/**
4447
* Configure or return an already configured client connected to a Cartridge router
4548
*
46-
* @param config router instance client config
47-
* @param address router host address
4849
* @return a configured client
4950
*/
50-
public TarantoolClient<TarantoolTuple, TarantoolResult<TarantoolTuple>>
51-
getClient(TarantoolClientConfig config, TarantoolServerAddress address) {
51+
public TarantoolClient<TarantoolTuple, TarantoolResult<TarantoolTuple>> getClient() {
5252
if (!container.isRunning()) {
5353
throw new IllegalStateException("Cannot connect to Tarantool instance in a stopped container");
5454
}
5555
if (clientHolder.get() == null) {
56-
clientHolder.compareAndSet(null, createClient(config, address));
56+
clientHolder.compareAndSet(null, createClient());
5757
}
5858
return clientHolder.get();
5959
}
@@ -74,10 +74,6 @@ public CompletableFuture<List<?>> executeCommand(String command, Object... argum
7474
throw new IllegalStateException("Cannot execute commands in stopped container");
7575
}
7676

77-
TarantoolCredentials credentials = new SimpleTarantoolCredentials(
78-
container.getUsername(), container.getPassword());
79-
TarantoolServerAddress address = new TarantoolServerAddress(container.getHost(), container.getPort());
80-
TarantoolClientConfig config = TarantoolClientConfig.builder().withCredentials(credentials).build();
81-
return getClient(config, address).eval(command, Arrays.asList(arguments));
77+
return getClient().eval(command, Arrays.asList(arguments));
8278
}
8379
}

src/main/resources/Dockerfile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,11 @@ ARG TARANTOOL_SERVER_GID=1000
77
ARG TARANTOOL_WORKDIR="/app"
88
ARG TARANTOOL_RUNDIR="/tmp/run"
99
ARG TARANTOOL_DATADIR="/tmp/data"
10+
ARG TARANTOOL_INSTANCES_FILE="./instances.yml"
1011
ENV TARANTOOL_WORKDIR=$TARANTOOL_WORKDIR
1112
ENV TARANTOOL_RUNDIR=$TARANTOOL_RUNDIR
1213
ENV TARANTOOL_DATADIR=$TARANTOOL_DATADIR
14+
ENV TARANTOOL_INSTANCES_FILE=$TARANTOOL_INSTANCES_FILE
1315
RUN curl -L https://tarantool.io/installer.sh | VER=$TARANTOOL_VERSION /bin/bash -s -- --repo-only && \
1416
yum -y install cmake make gcc gcc-c++ git unzip tarantool tarantool-devel cartridge-cli && \
1517
yum clean all
@@ -21,4 +23,4 @@ RUN cartridge version
2123

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

0 commit comments

Comments
 (0)