Skip to content

Commit 362b438

Browse files
committed
Remove cartridge-java from dependencies
- Update executeScript and executeCommand methods to execute code viva execInContainer (now it returns yaml string in Container.ExecResult not CompletableFuture). - Remove TarantoolContainer containers with TarantoolClientBuilder parameter. - Remove getClient method from TarantoolContainerClientHelper. - Remove io.tarantool.cartridge-driver dependency. because cartridge-java client was also removed. - Add executeScriptDecoded and executeCommandDecoded methods to return parsed yaml not string. - Add withSsl and withKeyAndCertFiles methods to TarantoolContainer and TarantoolCartridgeContainer. - Rewrite tests and add new cases to support new API. - Update org.yaml.snakeyaml to 2.0 version. Closes #69
1 parent a8c8404 commit 362b438

31 files changed

+810
-244
lines changed

CHANGELOG.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,18 @@
22

33
## [Unreleased]
44
- Fix problem if topology isn't applied correctly
5+
- Bump testcontainers to 1.18.0
6+
- Move rocks building in build phase
7+
- **[breaking change]** Update executeScript and executeCommand methods to execute code viva execInContainer
8+
(now it returns yaml string in Container.ExecResult not CompletableFuture).
9+
- **[breaking change]** Remove TarantoolContainer containers with TarantoolClientBuilder parameter.
10+
- **[breaking change]** Remove getClient method from TarantoolContainerClientHelper.
11+
- **[breaking change]** Remove io.tarantool.cartridge-driver dependency.
12+
because cartridge-java client was also removed.
13+
- Add executeScriptDecoded and executeCommandDecoded methods to return parsed yaml not string.
14+
- Add withSsl and withKeyAndCertFiles methods to TarantoolContainer and TarantoolCartridgeContainer.
15+
- Rewrite tests and add new cases to support new API.
16+
- Update org.yaml.snakeyaml to 2.0 version.
517

618
## [0.5.4] - 2023-03-31
719
- Use tarantool image as base instead of centos in cartridge container

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,9 @@ public class SomeTest {
5252
@BeforeAll
5353
public void setUp() {
5454
// Run some setup commands
55-
container.executeCommand("return 1, 2").get();
55+
container.executeCommand("return 1, 2");
5656
// Or execute a script
57-
container.executeScript("org/testcontainers/containers/test.lua").get();
57+
container.executeScript("org/testcontainers/containers/test.lua");
5858
}
5959

6060
@Test
@@ -72,7 +72,7 @@ public class SomeTest {
7272
...
7373

7474
// Execute some commands in Tarantool instance for verification
75-
List<Object> result = container.executeCommand("return 1, 2").get();
75+
List<Object> result = container.executeCommand("return 1, 2");
7676
...
7777
}
7878
...
@@ -181,7 +181,7 @@ public class SomeOtherTest {
181181
// Use the created container in tests
182182
public void testFoo() {
183183
// Execute Lua commands in the router instance
184-
List<Object> result = container.executeCommand("return profile_get(...)", 1).get();
184+
List<Object> result = container.executeCommand("return profile_get(1)");
185185

186186
// Instantiate a client connected to the router node
187187
TarantoolCredentials credentials = new SimpleTarantoolCredentials(getRouterUsername(), getRouterPassword());

pom.xml

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
</scm>
5454

5555
<properties>
56-
<testcontainers.version>1.17.4</testcontainers.version>
56+
<testcontainers.version>1.18.0</testcontainers.version>
5757
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
5858
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
5959
<logging.config>${project.basedir}/src/test/resources/logback-test.xml</logging.config>
@@ -81,20 +81,21 @@
8181
<artifactId>testcontainers</artifactId>
8282
<version>${testcontainers.version}</version>
8383
</dependency>
84-
<dependency>
85-
<groupId>io.tarantool</groupId>
86-
<artifactId>cartridge-driver</artifactId>
87-
<version>0.9.1</version>
88-
</dependency>
8984
<dependency>
9085
<groupId>org.yaml</groupId>
9186
<artifactId>snakeyaml</artifactId>
92-
<version>1.33</version>
87+
<version>2.0</version>
9388
</dependency>
9489
<dependency>
9590
<groupId>org.slf4j</groupId>
9691
<artifactId>slf4j-api</artifactId>
9792
</dependency>
93+
<dependency>
94+
<groupId>org.projectlombok</groupId>
95+
<artifactId>lombok</artifactId>
96+
<version>1.18.28</version>
97+
<scope>provided</scope>
98+
</dependency>
9899

99100
<!-- Test dependencies -->
100101
<dependency>
@@ -103,6 +104,12 @@
103104
<version>1.3.4</version>
104105
<scope>test</scope>
105106
</dependency>
107+
<dependency>
108+
<groupId>org.junit.jupiter</groupId>
109+
<artifactId>junit-jupiter</artifactId>
110+
<version>5.8.1</version>
111+
<scope>test</scope>
112+
</dependency>
106113
<dependency>
107114
<groupId>org.testcontainers</groupId>
108115
<artifactId>junit-jupiter</artifactId>
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package org.testcontainers.containers;
2+
3+
import lombok.AllArgsConstructor;
4+
import lombok.EqualsAndHashCode;
5+
import lombok.Getter;
6+
import lombok.NoArgsConstructor;
7+
import lombok.NonNull;
8+
import lombok.ToString;
9+
10+
@Getter
11+
@NoArgsConstructor(staticName = "getSslContext")
12+
@AllArgsConstructor(staticName = "getSslContext")
13+
@ToString(includeFieldNames=true)
14+
@EqualsAndHashCode
15+
public class SslContext {
16+
@NonNull
17+
private String keyFile;
18+
@NonNull
19+
private String certFile;
20+
}

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

Lines changed: 72 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package org.testcontainers.containers;
22

33
import com.github.dockerjava.api.command.InspectContainerResponse;
4-
import io.tarantool.driver.exceptions.TarantoolConnectionException;
54

65
import org.testcontainers.containers.exceptions.CartridgeTopologyException;
76
import org.testcontainers.images.builder.ImageFromDockerfile;
@@ -12,7 +11,6 @@
1211
import java.util.HashMap;
1312
import java.util.List;
1413
import java.util.Map;
15-
import java.util.concurrent.CompletableFuture;
1614
import java.util.concurrent.ExecutionException;
1715
import java.util.concurrent.TimeoutException;
1816
import java.util.function.Supplier;
@@ -82,6 +80,9 @@
8280
* specified in the http_port options, will be exposed.
8381
*
8482
* @author Alexey Kuzin
83+
* @authorm Artyom Dubinin
84+
* @author Ivan Dneprov
85+
*
8586
*/
8687
public class TarantoolCartridgeContainer extends GenericContainer<TarantoolCartridgeContainer>
8788
implements TarantoolContainerOperations<TarantoolCartridgeContainer> {
@@ -119,6 +120,7 @@ public class TarantoolCartridgeContainer extends GenericContainer<TarantoolCartr
119120
private String directoryResourcePath = SCRIPT_RESOURCE_DIRECTORY;
120121
private String instanceDir = INSTANCE_DIR;
121122
private String topologyConfigurationFile;
123+
private SslContext sslContext ;
122124

123125
/**
124126
* Create a container with default image and specified instances file from the classpath resources. Assumes that
@@ -186,8 +188,24 @@ public TarantoolCartridgeContainer(String dockerFile, String buildImageName,
186188
*/
187189
public TarantoolCartridgeContainer(String dockerFile, String buildImageName, String instancesFile,
188190
String topologyConfigurationFile, final Map<String, String> buildArgs) {
189-
this(buildImage(dockerFile, buildImageName), instancesFile, topologyConfigurationFile, buildArgs);
190-
}
191+
this(buildImage(dockerFile, buildImageName, buildArgs), instancesFile, topologyConfigurationFile, buildArgs);
192+
}
193+
194+
// todo add SSL and mTLS cartridge test
195+
// /**
196+
// * Create a container with specified image and specified instances file from the classpath resources. By providing
197+
// * the result Cartridge container image name, you can cache the image and avoid rebuilding on each test run (the
198+
// * image is tagged with the provided name and not deleted after tests finishing).
199+
// *
200+
// * @param tarantoolImageParams params for cached image creating
201+
// * @param instancesFile URL resource path to instances.yml relative in the classpath
202+
// * @param topologyConfigurationFile URL resource path to a topology bootstrap script in the classpath
203+
// */
204+
// public TarantoolCartridgeContainer(TarantoolImageParams tarantoolImageParams, String instancesFile,
205+
// String topologyConfigurationFile) {
206+
// this(new ImageFromDockerfile(TarantoolContainerImageHelper.getImage(tarantoolImageParams)), instancesFile,
207+
// topologyConfigurationFile, tarantoolImageParams.getBuildArgs());
208+
// }
191209

192210
private TarantoolCartridgeContainer(ImageFromDockerfile image, String instancesFile, String topologyConfigurationFile,
193211
Map<String, String> buildArgs) {
@@ -238,13 +256,32 @@ private static Map<String, String> mergeBuildArguments(Map<String, String> build
238256
return args;
239257
}
240258

241-
private static ImageFromDockerfile buildImage(String dockerFile, String buildImageName) {
259+
private static ImageFromDockerfile buildImage(String dockerFile, String buildImageName,
260+
final Map<String, String> buildArgs) {
261+
ImageFromDockerfile image;
242262
if (buildImageName != null && !buildImageName.isEmpty()) {
243-
return new ImageFromDockerfile(buildImageName, false)
244-
.withFileFromClasspath("Dockerfile", dockerFile);
263+
image = new ImageFromDockerfile(buildImageName, false);
264+
} else {
265+
image = new ImageFromDockerfile();
245266
}
246-
return new ImageFromDockerfile().withFileFromClasspath("Dockerfile", dockerFile);
247-
}
267+
return image.withFileFromClasspath("Dockerfile", dockerFile)
268+
.withFileFromClasspath("cartridge", buildArgs.get("CARTRIDGE_SRC_DIR") == null ?
269+
"cartridge" : buildArgs.get("CARTRIDGE_SRC_DIR"));
270+
}
271+
272+
// todo add SSL and mTLS cartridge test
273+
// /**
274+
// * Specify SSL as connection transport. And path to key and cert files inside your container for mTLS connection
275+
// * Warning! SSL must be set as default transport on your tarantool cluster.
276+
// * Supported only in Tarantool Enterprise
277+
// *
278+
// * @return this container instance
279+
// */
280+
// public TarantoolCartridgeContainer withSslContext(SslContext sslContext) {
281+
// checkNotRunning();
282+
// this.sslContext = sslContext;
283+
// return this;
284+
// }
248285

249286
/**
250287
* Get the router host
@@ -328,6 +365,11 @@ public String getInstanceDir() {
328365
return instanceDir;
329366
}
330367

368+
@Override
369+
public int getInternalPort() {
370+
return routerPort;
371+
}
372+
331373
/**
332374
* Get Cartridge router HTTP API hostname
333375
*
@@ -475,7 +517,7 @@ private boolean setupTopology() {
475517
.substring(topologyConfigurationFile.lastIndexOf('/') + 1);
476518

477519
try {
478-
Container.ExecResult result = execInContainer("cartridge",
520+
ExecResult result = execInContainer("cartridge",
479521
"replicasets",
480522
"--run-dir=" + TARANTOOL_RUN_DIR,
481523
"--file=" + replicasetsFileName, "setup", "--bootstrap-vshard");
@@ -489,7 +531,7 @@ private boolean setupTopology() {
489531

490532
} else {
491533
try {
492-
List<?> res = executeScript(topologyConfigurationFile).get();
534+
List<?> res = executeScriptDecoded(topologyConfigurationFile);
493535
if (res.size() >= 2 && res.get(1) != null && res.get(1) instanceof Map) {
494536
HashMap<?, ?> error = ((HashMap<?, ?>) res.get(1));
495537
// that means topology already exists
@@ -501,10 +543,6 @@ private boolean setupTopology() {
501543
if (e.getCause() instanceof TimeoutException) {
502544
return true;
503545
// Do nothing, the cluster is reloading
504-
} else if (e.getCause() instanceof TarantoolConnectionException) {
505-
// Probably cluster is not ready
506-
logger().error("Failed to setup topology: {}", e.getMessage());
507-
return false;
508546
}
509547
} else {
510548
throw new CartridgeTopologyException(e);
@@ -530,7 +568,7 @@ private void retryingSetupTopology() {
530568

531569
private void bootstrapVshard() {
532570
try {
533-
executeCommand(VSHARD_BOOTSTRAP_COMMAND).get();
571+
executeCommand(VSHARD_BOOTSTRAP_COMMAND);
534572
} catch (Exception e) {
535573
logger().error("Failed to bootstrap vshard cluster", e);
536574
throw new RuntimeException(e);
@@ -580,8 +618,8 @@ private boolean routerIsUp() {
580618
String healthyCmd = " local cartridge = package.loaded['cartridge']" +
581619
" return assert(cartridge ~= nil)";
582620
try {
583-
List<?> result = executeCommand(healthyCmd).get();
584-
return (Boolean) result.get(0);
621+
ExecResult result = executeCommand(healthyCmd);
622+
return result.getStdout().equals("---\n- true\n...\n\n");
585623
} catch (Exception e) {
586624
logger().warn("Error while waiting for router instance to be up: " + e.getMessage());
587625
return false;
@@ -592,21 +630,31 @@ private boolean isCartridgeHealthy() {
592630
String healthyCmd = " local cartridge = package.loaded['cartridge']" +
593631
" return assert(cartridge) and assert(cartridge.is_healthy())";
594632
try {
595-
List<?> result = executeCommand(healthyCmd).get();
596-
return (Boolean) result.get(0);
633+
ExecResult result = executeCommand(healthyCmd);
634+
return result.getStdout().equals("---\n- true\n...\n\n");
597635
} catch (Exception e) {
598636
logger().warn("Error while waiting for cartridge healthy state: " + e.getMessage());
599637
return false;
600638
}
601639
}
602640

603641
@Override
604-
public CompletableFuture<List<?>> executeScript(String scriptResourcePath) throws Exception {
605-
return clientHelper.executeScript(scriptResourcePath);
642+
public ExecResult executeScript(String scriptResourcePath) throws Exception {
643+
return clientHelper.executeScript(scriptResourcePath, this.sslContext);
644+
}
645+
646+
@Override
647+
public <T> T executeScriptDecoded(String scriptResourcePath) throws Exception {
648+
return clientHelper.executeScriptDecoded(scriptResourcePath, this.sslContext);
649+
}
650+
651+
@Override
652+
public ExecResult executeCommand(String command) throws Exception {
653+
return clientHelper.executeCommand(command, this.sslContext);
606654
}
607655

608656
@Override
609-
public CompletableFuture<List<?>> executeCommand(String command, Object... arguments) throws Exception {
610-
return clientHelper.executeCommand(command, arguments);
657+
public <T> T executeCommandDecoded(String command) throws Exception {
658+
return clientHelper.executeCommandDecoded(command, this.sslContext);
611659
}
612660
}

0 commit comments

Comments
 (0)