Skip to content

Commit cbdf777

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 dda7e9c commit cbdf777

27 files changed

+736
-203
lines changed

CHANGELOG.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,17 @@
11
# Changelog
22

3+
## [0.6.0] - 2023-05-29
4+
- **[breaking change]** Update executeScript and executeCommand methods to execute code viva execInContainer
5+
(now it returns yaml string in Container.ExecResult not CompletableFuture).
6+
- **[breaking change]** Remove TarantoolContainer containers with TarantoolClientBuilder parameter.
7+
- **[breaking change]** Remove getClient method from TarantoolContainerClientHelper.
8+
- **[breaking change]** Remove io.tarantool.cartridge-driver dependency.
9+
because cartridge-java client was also removed.
10+
- Add executeScriptDecoded and executeCommandDecoded methods to return parsed yaml not string.
11+
- Add withSsl and withKeyAndCertFiles methods to TarantoolContainer and TarantoolCartridgeContainer.
12+
- Rewrite tests and add new cases to support new API.
13+
- Update org.yaml.snakeyaml to 2.0 version.
14+
315
## [0.5.4] - 2023-03-31
416
- Use tarantool image as base instead of centos in cartridge container
517

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Add the Maven dependency:
1414
<dependency>
1515
<groupId>io.tarantool</groupId>
1616
<artifactId>testcontainers-java-tarantool</artifactId>
17-
<version>0.5.4</version>
17+
<version>0.6.0</version>
1818
</dependency>
1919
```
2020

@@ -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: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -81,15 +81,10 @@
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>

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

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

33
import com.github.dockerjava.api.command.InspectContainerResponse;
4-
import io.tarantool.driver.exceptions.TarantoolConnectionException;
54
import org.testcontainers.images.builder.ImageFromDockerfile;
65

76
import java.net.URL;
87
import java.util.Arrays;
98
import java.util.Collections;
109
import java.util.HashMap;
11-
import java.util.List;
1210
import java.util.Map;
13-
import java.util.concurrent.CompletableFuture;
1411
import java.util.concurrent.ExecutionException;
1512
import java.util.concurrent.TimeoutException;
1613
import java.util.function.Supplier;
@@ -80,6 +77,7 @@
8077
* specified in the http_port options, will be exposed.
8178
*
8279
* @author Alexey Kuzin
80+
* @author Ivan Dneprov
8381
*/
8482
public class TarantoolCartridgeContainer extends GenericContainer<TarantoolCartridgeContainer>
8583
implements TarantoolContainerOperations<TarantoolCartridgeContainer> {
@@ -117,6 +115,9 @@ public class TarantoolCartridgeContainer extends GenericContainer<TarantoolCartr
117115
private String directoryResourcePath = SCRIPT_RESOURCE_DIRECTORY;
118116
private String instanceDir = INSTANCE_DIR;
119117
private String topologyConfigurationFile;
118+
private Boolean sslIsActive = false;
119+
private String keyFile = "";
120+
private String certFile = "";
120121

121122
/**
122123
* Create a container with default image and specified instances file from the classpath resources. Assumes that
@@ -244,6 +245,33 @@ private static ImageFromDockerfile buildImage(String dockerFile, String buildIma
244245
return new ImageFromDockerfile().withFileFromClasspath("Dockerfile", dockerFile);
245246
}
246247

248+
/**
249+
* Specify SSL as connection transport.
250+
* Warning! SSL must be set as default transport on your tarantool cluster.
251+
* Supported only in Tarantool Enterprise
252+
*
253+
* @return this container instance
254+
*/
255+
public TarantoolCartridgeContainer withSsl() {
256+
checkNotRunning();
257+
this.sslIsActive = true;
258+
return this;
259+
}
260+
261+
/**
262+
* Specify path to key and cert files inside your container for SSL connection.
263+
* Warning! SSL must be set as default transport on your tarantool cluster.
264+
* Supported only in Tarantool Enterprise
265+
*
266+
* @return this container instance
267+
*/
268+
public TarantoolCartridgeContainer withKeyAndCertFiles(String keyFile, String certFile) {
269+
checkNotRunning();
270+
this.keyFile = keyFile;
271+
this.certFile = certFile;
272+
return this;
273+
}
274+
247275
/**
248276
* Get the router host
249277
*
@@ -326,6 +354,11 @@ public String getInstanceDir() {
326354
return instanceDir;
327355
}
328356

357+
@Override
358+
public int getInternalPort() {
359+
return routerPort;
360+
}
361+
329362
/**
330363
* Get Cartridge router HTTP API hostname
331364
*
@@ -487,17 +520,13 @@ private boolean setupTopology() {
487520

488521
} else {
489522
try {
490-
executeScript(topologyConfigurationFile).get();
523+
executeScript(topologyConfigurationFile);
491524
// The client connection will be closed after that command
492525
} catch (Exception e) {
493526
if (e instanceof ExecutionException) {
494527
if (e.getCause() instanceof TimeoutException) {
495528
return true;
496529
// Do nothing, the cluster is reloading
497-
} else if (e.getCause() instanceof TarantoolConnectionException) {
498-
// Probably cluster is not ready
499-
logger().error("Failed to setup topology: {}", e.getMessage());
500-
return false;
501530
}
502531
} else {
503532
throw new RuntimeException("Failed to change the app topology", e);
@@ -523,7 +552,7 @@ private void retryingSetupTopology() {
523552

524553
private void bootstrapVshard() {
525554
try {
526-
executeCommand(VSHARD_BOOTSTRAP_COMMAND).get();
555+
executeCommand(VSHARD_BOOTSTRAP_COMMAND);
527556
} catch (Exception e) {
528557
logger().error("Failed to bootstrap vshard cluster", e);
529558
throw new RuntimeException(e);
@@ -573,8 +602,8 @@ private boolean routerIsUp() {
573602
String healthyCmd = " local cartridge = package.loaded['cartridge']" +
574603
" return assert(cartridge ~= nil)";
575604
try {
576-
List<?> result = executeCommand(healthyCmd).get();
577-
return (Boolean) result.get(0);
605+
Container.ExecResult result = executeCommand(healthyCmd);
606+
return result.getStdout().equals("---\n- true\n...\n\n");
578607
} catch (Exception e) {
579608
logger().warn("Error while waiting for router instance to be up: " + e.getMessage());
580609
return false;
@@ -585,21 +614,31 @@ private boolean isCartridgeHealthy() {
585614
String healthyCmd = " local cartridge = package.loaded['cartridge']" +
586615
" return assert(cartridge) and assert(cartridge.is_healthy())";
587616
try {
588-
List<?> result = executeCommand(healthyCmd).get();
589-
return (Boolean) result.get(0);
617+
Container.ExecResult result = executeCommand(healthyCmd);
618+
return result.getStdout().equals("---\n- true\n...\n\n");
590619
} catch (Exception e) {
591620
logger().warn("Error while waiting for cartridge healthy state: " + e.getMessage());
592621
return false;
593622
}
594623
}
595624

596625
@Override
597-
public CompletableFuture<List<?>> executeScript(String scriptResourcePath) throws Exception {
598-
return clientHelper.executeScript(scriptResourcePath);
626+
public Container.ExecResult executeScript(String scriptResourcePath) throws Exception {
627+
return clientHelper.executeScript(scriptResourcePath, this.sslIsActive, this.keyFile, this.certFile);
628+
}
629+
630+
@Override
631+
public <T> T executeScriptDecoded(String scriptResourcePath) throws Exception {
632+
return clientHelper.executeScriptDecoded(scriptResourcePath, this.sslIsActive, this.keyFile, this.certFile);
633+
}
634+
635+
@Override
636+
public Container.ExecResult executeCommand(String command) throws Exception {
637+
return clientHelper.executeCommand(command, this.sslIsActive, this.keyFile, this.certFile);
599638
}
600639

601640
@Override
602-
public CompletableFuture<List<?>> executeCommand(String command, Object... arguments) throws Exception {
603-
return clientHelper.executeCommand(command, arguments);
641+
public <T> T executeCommandDecoded(String command) throws Exception {
642+
return clientHelper.executeCommandDecoded(command, this.sslIsActive, this.keyFile, this.certFile);
604643
}
605644
}

0 commit comments

Comments
 (0)