Skip to content

Commit fa8e02e

Browse files
committed
Remove cartridge-java from dependencies
- Update executeScript and executeCommand methods to execute code viva execInContainer. - Add executeScriptDecoded and executeCommandDecoded methods to return parsed yaml not string. - Remove cartridge-java client from TarantoolContainerClientHelper and tests. - Rewrite tests and add new cases to support new API - Remove io.tarantool.cartridge-driver dependency. - Update org.yaml.snakeyaml to 2.0 version. Closes #69
1 parent dda7e9c commit fa8e02e

11 files changed

+156
-167
lines changed

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>

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

Lines changed: 25 additions & 16 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> {
@@ -326,6 +324,11 @@ public String getInstanceDir() {
326324
return instanceDir;
327325
}
328326

327+
@Override
328+
public int getInternalPort() {
329+
return routerPort;
330+
}
331+
329332
/**
330333
* Get Cartridge router HTTP API hostname
331334
*
@@ -487,17 +490,13 @@ private boolean setupTopology() {
487490

488491
} else {
489492
try {
490-
executeScript(topologyConfigurationFile).get();
493+
executeScript(topologyConfigurationFile);
491494
// The client connection will be closed after that command
492495
} catch (Exception e) {
493496
if (e instanceof ExecutionException) {
494497
if (e.getCause() instanceof TimeoutException) {
495498
return true;
496499
// 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;
501500
}
502501
} else {
503502
throw new RuntimeException("Failed to change the app topology", e);
@@ -523,7 +522,7 @@ private void retryingSetupTopology() {
523522

524523
private void bootstrapVshard() {
525524
try {
526-
executeCommand(VSHARD_BOOTSTRAP_COMMAND).get();
525+
executeCommand(VSHARD_BOOTSTRAP_COMMAND);
527526
} catch (Exception e) {
528527
logger().error("Failed to bootstrap vshard cluster", e);
529528
throw new RuntimeException(e);
@@ -573,8 +572,8 @@ private boolean routerIsUp() {
573572
String healthyCmd = " local cartridge = package.loaded['cartridge']" +
574573
" return assert(cartridge ~= nil)";
575574
try {
576-
List<?> result = executeCommand(healthyCmd).get();
577-
return (Boolean) result.get(0);
575+
Container.ExecResult result = executeCommand(healthyCmd);
576+
return result.getStdout().equals("---\n- true\n...\n\n");
578577
} catch (Exception e) {
579578
logger().warn("Error while waiting for router instance to be up: " + e.getMessage());
580579
return false;
@@ -585,21 +584,31 @@ private boolean isCartridgeHealthy() {
585584
String healthyCmd = " local cartridge = package.loaded['cartridge']" +
586585
" return assert(cartridge) and assert(cartridge.is_healthy())";
587586
try {
588-
List<?> result = executeCommand(healthyCmd).get();
589-
return (Boolean) result.get(0);
587+
Container.ExecResult result = executeCommand(healthyCmd);
588+
return result.getStdout().equals("---\n- true\n...\n\n");
590589
} catch (Exception e) {
591590
logger().warn("Error while waiting for cartridge healthy state: " + e.getMessage());
592591
return false;
593592
}
594593
}
595594

596595
@Override
597-
public CompletableFuture<List<?>> executeScript(String scriptResourcePath) throws Exception {
596+
public Container.ExecResult executeScript(String scriptResourcePath) throws Exception {
598597
return clientHelper.executeScript(scriptResourcePath);
599598
}
600599

601600
@Override
602-
public CompletableFuture<List<?>> executeCommand(String command, Object... arguments) throws Exception {
603-
return clientHelper.executeCommand(command, arguments);
601+
public <T> T executeScriptDecoded(String scriptResourcePath) throws Exception {
602+
return clientHelper.executeScriptDecoded(scriptResourcePath);
603+
}
604+
605+
@Override
606+
public Container.ExecResult executeCommand(String command) throws Exception {
607+
return clientHelper.executeCommand(command);
608+
}
609+
610+
@Override
611+
public <T> T executeCommandDecoded(String command) throws Exception {
612+
return clientHelper.executeCommandDecoded(command);
604613
}
605614
}

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

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

33
import com.github.dockerjava.api.command.InspectContainerResponse;
4-
import io.tarantool.driver.api.TarantoolClientBuilder;
54
import org.testcontainers.containers.wait.strategy.Wait;
65

76
import java.net.URL;
87
import java.nio.file.Paths;
9-
import java.util.List;
10-
import java.util.concurrent.CompletableFuture;
118
import java.util.concurrent.Future;
129

1310
import static org.testcontainers.containers.PathUtils.normalizePath;
@@ -16,6 +13,7 @@
1613
* Sets up a Tarantool instance and provides API for configuring it.
1714
*
1815
* @author Alexey Kuzin
16+
* @author Ivan Dneprov
1917
*/
2018
public class TarantoolContainer extends GenericContainer<TarantoolContainer>
2119
implements TarantoolContainerOperations<TarantoolContainer> {
@@ -55,15 +53,6 @@ public TarantoolContainer() {
5553
this(String.format("%s:%s", TARANTOOL_IMAGE, DEFAULT_IMAGE_VERSION));
5654
}
5755

58-
/**
59-
* Constructor for {@link TarantoolContainer}
60-
*
61-
* @param clientBuilder client builder with custom client settings for setting up container
62-
*/
63-
public TarantoolContainer(TarantoolClientBuilder clientBuilder) {
64-
this(String.format("%s:%s", TARANTOOL_IMAGE, DEFAULT_IMAGE_VERSION), clientBuilder);
65-
}
66-
6756
/**
6857
* Constructor for {@link TarantoolContainer}
6958
*
@@ -74,38 +63,14 @@ public TarantoolContainer(String dockerImageName) {
7463
clientHelper = new TarantoolContainerClientHelper(this);
7564
}
7665

77-
/**
78-
* Constructor for {@link TarantoolContainer}
79-
*
80-
* @param dockerImageName docker image name for container creating
81-
* @param clientBuilder client builder with custom client settings for setting up container
82-
*/
83-
public TarantoolContainer(String dockerImageName,
84-
TarantoolClientBuilder clientBuilder) {
85-
super(dockerImageName);
86-
clientHelper = new TarantoolContainerClientHelper(this, clientBuilder);
87-
}
88-
8966
/**
9067
* Constructor for {@link TarantoolContainer}
9168
*
9269
* @param tarantoolImageParams params for cached image creating
9370
*/
9471
public TarantoolContainer(TarantoolImageParams tarantoolImageParams) {
9572
super(TarantoolContainerImageHelper.getImage(tarantoolImageParams));
96-
clientHelper = new TarantoolContainerClientHelper(this);
97-
}
98-
99-
/**
100-
* Constructor for {@link TarantoolContainer}
101-
*
102-
* @param tarantoolImageParams params for cached image creating
103-
* @param clientBuilder client builder with custom client settings for setting up container
104-
*/
105-
public TarantoolContainer(TarantoolImageParams tarantoolImageParams,
106-
TarantoolClientBuilder clientBuilder) {
107-
super(TarantoolContainerImageHelper.getImage(tarantoolImageParams));
108-
clientHelper = new TarantoolContainerClientHelper(this, clientBuilder);
73+
clientHelper = new TarantoolContainerClientHelper(this, "/sdk/tarantoolctl");
10974
}
11075

11176
/**
@@ -118,18 +83,6 @@ public TarantoolContainer(Future<String> image) {
11883
clientHelper = new TarantoolContainerClientHelper(this);
11984
}
12085

121-
/**
122-
* Constructor for {@link TarantoolContainer}
123-
*
124-
* @param image future with image name
125-
* @param clientBuilder client builder with custom client settings for setting up container
126-
*/
127-
public TarantoolContainer(Future<String> image,
128-
TarantoolClientBuilder clientBuilder) {
129-
super(image);
130-
clientHelper = new TarantoolContainerClientHelper(this, clientBuilder);
131-
}
132-
13386
/**
13487
* Use fixed ports binding.
13588
* Defaults to false.
@@ -223,7 +176,7 @@ public TarantoolContainer withLogLevel(TarantoolLogLevel logLevel) {
223176
this.logLevel = logLevel;
224177
if (isRunning()) {
225178
try {
226-
executeCommand(logLevel.toCommand()).get();
179+
executeCommand(logLevel.toCommand());
227180
} catch (Exception e) {
228181
logger().error(String.format("Failed to set log_level to %s", logLevel.toString()), e);
229182
throw new RuntimeException(e);
@@ -246,7 +199,7 @@ public TarantoolContainer withMemtxMemory(Integer memtxMemory) {
246199
this.memtxMemory = memtxMemory;
247200
if (isRunning()) {
248201
try {
249-
executeCommand(String.format("box.cfg{memtx_memory=%d}", memtxMemory)).get();
202+
executeCommand(String.format("box.cfg{memtx_memory=%d}", memtxMemory));
250203
} catch (Exception e) {
251204
logger().error(String.format("Failed to set memtx_memory to %d", memtxMemory), e);
252205
throw new RuntimeException(e);
@@ -290,6 +243,11 @@ public String getInstanceDir() {
290243
return instanceDir;
291244
}
292245

246+
@Override
247+
public int getInternalPort() {
248+
return port;
249+
}
250+
293251
/**
294252
* Specify the server init script file name
295253
*
@@ -380,12 +338,22 @@ protected void containerIsStopping(InspectContainerResponse containerInfo) {
380338
}
381339

382340
@Override
383-
public CompletableFuture<List<?>> executeScript(String scriptResourcePath) throws Exception {
341+
public Container.ExecResult executeScript(String scriptResourcePath) throws Exception {
384342
return clientHelper.executeScript(scriptResourcePath);
385343
}
386344

387345
@Override
388-
public CompletableFuture<List<?>> executeCommand(String command, Object... arguments) throws Exception {
389-
return clientHelper.executeCommand(command, arguments);
346+
public <T> T executeScriptDecoded(String scriptResourcePath) throws Exception {
347+
return clientHelper.executeScriptDecoded(scriptResourcePath);
348+
}
349+
350+
@Override
351+
public Container.ExecResult executeCommand(String command) throws Exception {
352+
return clientHelper.executeCommand(command);
353+
}
354+
355+
@Override
356+
public <T> T executeCommandDecoded(String command) throws Exception {
357+
return clientHelper.executeCommandDecoded(command);
390358
}
391359
}

0 commit comments

Comments
 (0)