Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove cartridge-java from dependencies
Browse files Browse the repository at this point in the history
- [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
iDneprov committed Jun 14, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent d6f21a6 commit 4e9d764
Showing 28 changed files with 732 additions and 210 deletions.
9 changes: 8 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -3,7 +3,14 @@
## [Unreleased]
- Fix problem if topology isn't applied correctly
- Bump testcontainers to 1.18.0
- Move rocks building in build phase
- Move rocks building to the build phase
- **[breaking change]** Remove io.tarantool.cartridge-driver dependency
- **[breaking change]** Update executeScript and executeCommand methods to execute code via execInContainer
(now it returns **yaml** string in Container.ExecResult instead of 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.

## [0.5.4] - 2023-03-31
- Use tarantool image as base instead of centos in cartridge container
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -52,9 +52,9 @@ public class SomeTest {
@BeforeAll
public void setUp() {
// Run some setup commands
container.executeCommand("return 1, 2").get();
container.executeCommand("return 1, 2");
// Or execute a script
container.executeScript("org/testcontainers/containers/test.lua").get();
container.executeScript("org/testcontainers/containers/test.lua");
}

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

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

// Instantiate a client connected to the router node
TarantoolCredentials credentials = new SimpleTarantoolCredentials(getRouterUsername(), getRouterPassword());
7 changes: 1 addition & 6 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -81,15 +81,10 @@
<artifactId>testcontainers</artifactId>
<version>${testcontainers.version}</version>
</dependency>
<dependency>
<groupId>io.tarantool</groupId>
<artifactId>cartridge-driver</artifactId>
<version>0.9.1</version>
</dependency>
<dependency>
<groupId>org.yaml</groupId>
<artifactId>snakeyaml</artifactId>
<version>1.33</version>
<version>2.0</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
30 changes: 30 additions & 0 deletions src/main/java/org/testcontainers/containers/SslContext.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package org.testcontainers.containers;

public class SslContext {
private String keyFile;
private String certFile;

private SslContext() {
}

private SslContext(String keyFile, String certFile) {
this.keyFile = keyFile;
this.certFile = certFile;
}

public static SslContext getSslContext(){
return new SslContext();
}

public static SslContext getSslContext(String keyFile, String certFile){
return new SslContext(keyFile, certFile);
}

String getKeyFile() {
return this.keyFile;
}

String getCertFile() {
return this.certFile;
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package org.testcontainers.containers;

import com.github.dockerjava.api.command.InspectContainerResponse;
import io.tarantool.driver.exceptions.TarantoolConnectionException;

import org.testcontainers.containers.exceptions.CartridgeTopologyException;
import org.testcontainers.images.builder.ImageFromDockerfile;
@@ -12,7 +11,6 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeoutException;
import java.util.function.Supplier;
@@ -82,6 +80,9 @@
* specified in the http_port options, will be exposed.
*
* @author Alexey Kuzin
* @author Artyom Dubinin
* @author Ivan Dneprov
*
*/
public class TarantoolCartridgeContainer extends GenericContainer<TarantoolCartridgeContainer>
implements TarantoolContainerOperations<TarantoolCartridgeContainer> {
@@ -119,6 +120,7 @@ public class TarantoolCartridgeContainer extends GenericContainer<TarantoolCartr
private String directoryResourcePath = SCRIPT_RESOURCE_DIRECTORY;
private String instanceDir = INSTANCE_DIR;
private String topologyConfigurationFile;
private SslContext sslContext;

/**
* Create a container with default image and specified instances file from the classpath resources. Assumes that
@@ -333,6 +335,11 @@ public String getInstanceDir() {
return instanceDir;
}

@Override
public int getInternalPort() {
return routerPort;
}

/**
* Get Cartridge router HTTP API hostname
*
@@ -480,7 +487,7 @@ private boolean setupTopology() {
.substring(topologyConfigurationFile.lastIndexOf('/') + 1);

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

} else {
try {
List<?> res = executeScript(topologyConfigurationFile).get();
List<?> res = executeScriptDecoded(topologyConfigurationFile);
if (res.size() >= 2 && res.get(1) != null && res.get(1) instanceof Map) {
HashMap<?, ?> error = ((HashMap<?, ?>) res.get(1));
// that means topology already exists
@@ -506,10 +513,6 @@ private boolean setupTopology() {
if (e.getCause() instanceof TimeoutException) {
return true;
// Do nothing, the cluster is reloading
} else if (e.getCause() instanceof TarantoolConnectionException) {
// Probably cluster is not ready
logger().error("Failed to setup topology: {}", e.getMessage());
return false;
}
} else {
throw new CartridgeTopologyException(e);
@@ -535,7 +538,7 @@ private void retryingSetupTopology() {

private void bootstrapVshard() {
try {
executeCommand(VSHARD_BOOTSTRAP_COMMAND).get();
executeCommand(VSHARD_BOOTSTRAP_COMMAND);
} catch (Exception e) {
logger().error("Failed to bootstrap vshard cluster", e);
throw new RuntimeException(e);
@@ -583,10 +586,10 @@ private void waitUntilTrue(int secondsToWait, Supplier<Boolean> waitFunc) {

private boolean routerIsUp() {
String healthyCmd = " local cartridge = package.loaded['cartridge']" +
" return assert(cartridge ~= nil)";
" return cartridge ~= nil";
try {
List<?> result = executeCommand(healthyCmd).get();
return (Boolean) result.get(0);
List<?> result = executeCommandDecoded(healthyCmd);
return result.get(0).getClass() == Boolean.class && (Boolean) result.get(0);
} catch (Exception e) {
logger().warn("Error while waiting for router instance to be up: " + e.getMessage());
return false;
@@ -595,23 +598,33 @@ private boolean routerIsUp() {

private boolean isCartridgeHealthy() {
String healthyCmd = " local cartridge = package.loaded['cartridge']" +
" return assert(cartridge) and assert(cartridge.is_healthy())";
" return cartridge ~= nil and cartridge.is_healthy()";
try {
List<?> result = executeCommand(healthyCmd).get();
return (Boolean) result.get(0);
List<?> result = executeCommandDecoded(healthyCmd);
return result.get(0).getClass() == Boolean.class && (Boolean) result.get(0);
} catch (Exception e) {
logger().warn("Error while waiting for cartridge healthy state: " + e.getMessage());
return false;
}
}

@Override
public CompletableFuture<List<?>> executeScript(String scriptResourcePath) throws Exception {
return clientHelper.executeScript(scriptResourcePath);
public ExecResult executeScript(String scriptResourcePath) throws Exception {
return clientHelper.executeScript(scriptResourcePath, this.sslContext);
}

@Override
public <T> T executeScriptDecoded(String scriptResourcePath) throws Exception {
return clientHelper.executeScriptDecoded(scriptResourcePath, this.sslContext);
}

@Override
public ExecResult executeCommand(String command) throws Exception {
return clientHelper.executeCommand(command, this.sslContext);
}

@Override
public CompletableFuture<List<?>> executeCommand(String command, Object... arguments) throws Exception {
return clientHelper.executeCommand(command, arguments);
public <T> T executeCommandDecoded(String command) throws Exception {
return clientHelper.executeCommandDecoded(command, this.sslContext);
}
}
Loading

0 comments on commit 4e9d764

Please sign in to comment.