Skip to content

Commit a4b81d9

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 a4b81d9

28 files changed

+742
-212
lines changed

CHANGELOG.md

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

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

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

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: 59 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,12 @@
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;
87

98
import java.net.URL;
10-
import java.util.Arrays;
11-
import java.util.Collections;
12-
import java.util.HashMap;
13-
import java.util.List;
14-
import java.util.Map;
15-
import java.util.concurrent.CompletableFuture;
9+
import java.util.*;
1610
import java.util.concurrent.ExecutionException;
1711
import java.util.concurrent.TimeoutException;
1812
import java.util.function.Supplier;
@@ -82,6 +76,9 @@
8276
* specified in the http_port options, will be exposed.
8377
*
8478
* @author Alexey Kuzin
79+
* @authorm Artyom Dubinin
80+
* @author Ivan Dneprov
81+
*
8582
*/
8683
public class TarantoolCartridgeContainer extends GenericContainer<TarantoolCartridgeContainer>
8784
implements TarantoolContainerOperations<TarantoolCartridgeContainer> {
@@ -119,6 +116,9 @@ public class TarantoolCartridgeContainer extends GenericContainer<TarantoolCartr
119116
private String directoryResourcePath = SCRIPT_RESOURCE_DIRECTORY;
120117
private String instanceDir = INSTANCE_DIR;
121118
private String topologyConfigurationFile;
119+
private Boolean sslIsActive = false;
120+
private String keyFile = "";
121+
private String certFile = "";
122122

123123
/**
124124
* Create a container with default image and specified instances file from the classpath resources. Assumes that
@@ -246,6 +246,33 @@ private static ImageFromDockerfile buildImage(String dockerFile, String buildIma
246246
return new ImageFromDockerfile().withFileFromClasspath("Dockerfile", dockerFile);
247247
}
248248

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

358+
@Override
359+
public int getInternalPort() {
360+
return routerPort;
361+
}
362+
331363
/**
332364
* Get Cartridge router HTTP API hostname
333365
*
@@ -489,7 +521,7 @@ private boolean setupTopology() {
489521

490522
} else {
491523
try {
492-
List<?> res = executeScript(topologyConfigurationFile).get();
524+
ArrayList<?> res = executeScriptDecoded(topologyConfigurationFile);
493525
if (res.size() >= 2 && res.get(1) != null && res.get(1) instanceof Map) {
494526
HashMap<?, ?> error = ((HashMap<?, ?>) res.get(1));
495527
// that means topology already exists
@@ -501,10 +533,6 @@ private boolean setupTopology() {
501533
if (e.getCause() instanceof TimeoutException) {
502534
return true;
503535
// 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;
508536
}
509537
} else {
510538
throw new CartridgeTopologyException(e);
@@ -530,7 +558,7 @@ private void retryingSetupTopology() {
530558

531559
private void bootstrapVshard() {
532560
try {
533-
executeCommand(VSHARD_BOOTSTRAP_COMMAND).get();
561+
executeCommand(VSHARD_BOOTSTRAP_COMMAND);
534562
} catch (Exception e) {
535563
logger().error("Failed to bootstrap vshard cluster", e);
536564
throw new RuntimeException(e);
@@ -580,8 +608,8 @@ private boolean routerIsUp() {
580608
String healthyCmd = " local cartridge = package.loaded['cartridge']" +
581609
" return assert(cartridge ~= nil)";
582610
try {
583-
List<?> result = executeCommand(healthyCmd).get();
584-
return (Boolean) result.get(0);
611+
Container.ExecResult result = executeCommand(healthyCmd);
612+
return result.getStdout().equals("---\n- true\n...\n\n");
585613
} catch (Exception e) {
586614
logger().warn("Error while waiting for router instance to be up: " + e.getMessage());
587615
return false;
@@ -592,21 +620,31 @@ private boolean isCartridgeHealthy() {
592620
String healthyCmd = " local cartridge = package.loaded['cartridge']" +
593621
" return assert(cartridge) and assert(cartridge.is_healthy())";
594622
try {
595-
List<?> result = executeCommand(healthyCmd).get();
596-
return (Boolean) result.get(0);
623+
Container.ExecResult result = executeCommand(healthyCmd);
624+
return result.getStdout().equals("---\n- true\n...\n\n");
597625
} catch (Exception e) {
598626
logger().warn("Error while waiting for cartridge healthy state: " + e.getMessage());
599627
return false;
600628
}
601629
}
602630

603631
@Override
604-
public CompletableFuture<List<?>> executeScript(String scriptResourcePath) throws Exception {
605-
return clientHelper.executeScript(scriptResourcePath);
632+
public Container.ExecResult executeScript(String scriptResourcePath) throws Exception {
633+
return clientHelper.executeScript(scriptResourcePath, this.sslIsActive, this.keyFile, this.certFile);
634+
}
635+
636+
@Override
637+
public <T> T executeScriptDecoded(String scriptResourcePath) throws Exception {
638+
return clientHelper.executeScriptDecoded(scriptResourcePath, this.sslIsActive, this.keyFile, this.certFile);
639+
}
640+
641+
@Override
642+
public Container.ExecResult executeCommand(String command) throws Exception {
643+
return clientHelper.executeCommand(command, this.sslIsActive, this.keyFile, this.certFile);
606644
}
607645

608646
@Override
609-
public CompletableFuture<List<?>> executeCommand(String command, Object... arguments) throws Exception {
610-
return clientHelper.executeCommand(command, arguments);
647+
public <T> T executeCommandDecoded(String command) throws Exception {
648+
return clientHelper.executeCommandDecoded(command, this.sslIsActive, this.keyFile, this.certFile);
611649
}
612650
}

0 commit comments

Comments
 (0)