Skip to content

Commit 7e6d389

Browse files
committed
Remove cartridge-java from dependencies
- [breaking change] Remove io.tarantool.cartridge-driver dependency - [breaking change] Update executeScript and executeCommand methods to execute code viva execInContainer (now it returns yaml string in Container.ExecResult not CompletableFuture) - Add executeScriptDecoded and executeCommandDecoded methods to return parsed yaml not string. - Add SslContext class - Add withSslContext method to TarantoolContainer and TarantoolCartridgeContainer. - Update org.yaml.snakeyaml to 2.0 version. Closes #69
1 parent 046335e commit 7e6d389

29 files changed

+732
-209
lines changed

.github/workflows/ubuntu-master.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,5 @@ jobs:
3737
TARANTOOL_SERVER_USER: root
3838
TARANTOOL_SERVER_GROUP: root
3939
DOWNLOAD_SDK_URI: ${{ secrets.DOWNLOAD_SDK_URI }}
40+
SDK_VERSION: tarantool-enterprise-sdk-nogc64-2.10.7-0-r563.linux.x86_64
4041
run: mvn -B test -P enterprise --file pom.xml

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,13 @@
55
- Bump testcontainers to 1.18.0
66
- Move rocks building in build phase
77
- Use "addExposedPorts" instead of "withExposedPorts"
8+
- **[breaking change]** Remove io.tarantool.cartridge-driver dependency
9+
- **[breaking change]** Update executeScript and executeCommand methods to execute code via execInContainer
10+
(now it returns **yaml** string in Container.ExecResult instead of CompletableFuture)
11+
- Add executeScriptDecoded and executeCommandDecoded methods to return parsed yaml not string.
12+
- Add SslContext class
13+
- Add withSslContext method to TarantoolContainer and TarantoolCartridgeContainer.
14+
- Update org.yaml.snakeyaml to 2.0 version.
815

916
## [0.5.4] - 2023-03-31
1017
- 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: 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>
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package org.testcontainers.containers;
2+
3+
public class SslContext {
4+
private String keyFile;
5+
private String certFile;
6+
7+
private SslContext() {
8+
}
9+
10+
private SslContext(String keyFile, String certFile) {
11+
this.keyFile = keyFile;
12+
this.certFile = certFile;
13+
}
14+
15+
public static SslContext getSslContext(){
16+
return new SslContext();
17+
}
18+
19+
public static SslContext getSslContext(String keyFile, String certFile){
20+
return new SslContext(keyFile, certFile);
21+
}
22+
23+
String getKeyFile() {
24+
return this.keyFile;
25+
}
26+
27+
String getCertFile() {
28+
return this.certFile;
29+
}
30+
}

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

Lines changed: 32 additions & 19 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;
@@ -13,7 +12,6 @@
1312
import java.util.HashMap;
1413
import java.util.List;
1514
import java.util.Map;
16-
import java.util.concurrent.CompletableFuture;
1715
import java.util.concurrent.ExecutionException;
1816
import java.util.concurrent.TimeoutException;
1917
import java.util.function.Supplier;
@@ -83,6 +81,9 @@
8381
* specified in the http_port options, will be exposed.
8482
*
8583
* @author Alexey Kuzin
84+
* @author Artyom Dubinin
85+
* @author Ivan Dneprov
86+
*
8687
*/
8788
public class TarantoolCartridgeContainer extends GenericContainer<TarantoolCartridgeContainer>
8889
implements TarantoolContainerOperations<TarantoolCartridgeContainer> {
@@ -120,6 +121,7 @@ public class TarantoolCartridgeContainer extends GenericContainer<TarantoolCartr
120121
private String directoryResourcePath = SCRIPT_RESOURCE_DIRECTORY;
121122
private String instanceDir = INSTANCE_DIR;
122123
private String topologyConfigurationFile;
124+
private SslContext sslContext;
123125

124126
/**
125127
* Create a container with default image and specified instances file from the classpath resources. Assumes that
@@ -344,6 +346,11 @@ public String getInstanceDir() {
344346
return instanceDir;
345347
}
346348

349+
@Override
350+
public int getInternalPort() {
351+
return routerPort;
352+
}
353+
347354
/**
348355
* Get Cartridge router HTTP API hostname
349356
*
@@ -491,7 +498,7 @@ private boolean setupTopology() {
491498
.substring(topologyConfigurationFile.lastIndexOf('/') + 1);
492499

493500
try {
494-
Container.ExecResult result = execInContainer("cartridge",
501+
ExecResult result = execInContainer("cartridge",
495502
"replicasets",
496503
"--run-dir=" + TARANTOOL_RUN_DIR,
497504
"--file=" + replicasetsFileName, "setup", "--bootstrap-vshard");
@@ -505,7 +512,7 @@ private boolean setupTopology() {
505512

506513
} else {
507514
try {
508-
List<?> res = executeScript(topologyConfigurationFile).get();
515+
List<?> res = executeScriptDecoded(topologyConfigurationFile);
509516
if (res.size() >= 2 && res.get(1) != null && res.get(1) instanceof Map) {
510517
HashMap<?, ?> error = ((HashMap<?, ?>) res.get(1));
511518
// that means topology already exists
@@ -517,10 +524,6 @@ private boolean setupTopology() {
517524
if (e.getCause() instanceof TimeoutException) {
518525
return true;
519526
// Do nothing, the cluster is reloading
520-
} else if (e.getCause() instanceof TarantoolConnectionException) {
521-
// Probably cluster is not ready
522-
logger().error("Failed to setup topology: {}", e.getMessage());
523-
return false;
524527
}
525528
} else {
526529
throw new CartridgeTopologyException(e);
@@ -546,7 +549,7 @@ private void retryingSetupTopology() {
546549

547550
private void bootstrapVshard() {
548551
try {
549-
executeCommand(VSHARD_BOOTSTRAP_COMMAND).get();
552+
executeCommand(VSHARD_BOOTSTRAP_COMMAND);
550553
} catch (Exception e) {
551554
logger().error("Failed to bootstrap vshard cluster", e);
552555
throw new RuntimeException(e);
@@ -594,10 +597,10 @@ private void waitUntilTrue(int secondsToWait, Supplier<Boolean> waitFunc) {
594597

595598
private boolean routerIsUp() {
596599
String healthyCmd = " local cartridge = package.loaded['cartridge']" +
597-
" return assert(cartridge ~= nil)";
600+
" return cartridge ~= nil";
598601
try {
599-
List<?> result = executeCommand(healthyCmd).get();
600-
return (Boolean) result.get(0);
602+
List<?> result = executeCommandDecoded(healthyCmd);
603+
return result.get(0).getClass() == Boolean.class && (Boolean) result.get(0);
601604
} catch (Exception e) {
602605
logger().warn("Error while waiting for router instance to be up: " + e.getMessage());
603606
return false;
@@ -606,23 +609,33 @@ private boolean routerIsUp() {
606609

607610
private boolean isCartridgeHealthy() {
608611
String healthyCmd = " local cartridge = package.loaded['cartridge']" +
609-
" return assert(cartridge) and assert(cartridge.is_healthy())";
612+
" return cartridge ~= nil and cartridge.is_healthy()";
610613
try {
611-
List<?> result = executeCommand(healthyCmd).get();
612-
return (Boolean) result.get(0);
614+
List<?> result = executeCommandDecoded(healthyCmd);
615+
return result.get(0).getClass() == Boolean.class && (Boolean) result.get(0);
613616
} catch (Exception e) {
614617
logger().warn("Error while waiting for cartridge healthy state: " + e.getMessage());
615618
return false;
616619
}
617620
}
618621

619622
@Override
620-
public CompletableFuture<List<?>> executeScript(String scriptResourcePath) throws Exception {
621-
return clientHelper.executeScript(scriptResourcePath);
623+
public ExecResult executeScript(String scriptResourcePath) throws Exception {
624+
return clientHelper.executeScript(scriptResourcePath, this.sslContext);
625+
}
626+
627+
@Override
628+
public <T> T executeScriptDecoded(String scriptResourcePath) throws Exception {
629+
return clientHelper.executeScriptDecoded(scriptResourcePath, this.sslContext);
630+
}
631+
632+
@Override
633+
public ExecResult executeCommand(String command) throws Exception {
634+
return clientHelper.executeCommand(command, this.sslContext);
622635
}
623636

624637
@Override
625-
public CompletableFuture<List<?>> executeCommand(String command, Object... arguments) throws Exception {
626-
return clientHelper.executeCommand(command, arguments);
638+
public <T> T executeCommandDecoded(String command) throws Exception {
639+
return clientHelper.executeCommandDecoded(command, this.sslContext);
627640
}
628641
}

0 commit comments

Comments
 (0)