Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removed cartridge-java from dependencies #71

Merged
merged 1 commit into from
Jun 16, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
  • Loading branch information
iDneprov committed Jun 16, 2023
commit 0701bf97cd7a8a5e52ff6df94ec183fb600f780d
1 change: 1 addition & 0 deletions .github/workflows/ubuntu-master.yml
Original file line number Diff line number Diff line change
@@ -37,4 +37,5 @@ jobs:
TARANTOOL_SERVER_USER: root
TARANTOOL_SERVER_GROUP: root
DOWNLOAD_SDK_URI: ${{ secrets.DOWNLOAD_SDK_URI }}
SDK_VERSION: tarantool-enterprise-sdk-nogc64-2.10.7-0-r563.linux.x86_64
run: mvn -B test -P enterprise --file pom.xml
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -5,6 +5,13 @@
- Bump testcontainers to 1.18.0
- Move rocks building in build phase
- Use "addExposedPorts" instead of "withExposedPorts"
- **[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;
@@ -13,7 +12,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;
@@ -83,6 +81,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> {
@@ -120,6 +121,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
@@ -344,6 +346,11 @@ public String getInstanceDir() {
return instanceDir;
}

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

/**
* Get Cartridge router HTTP API hostname
*
@@ -491,7 +498,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");
@@ -505,7 +512,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
@@ -517,10 +524,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);
@@ -546,7 +549,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);
@@ -594,10 +597,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;
@@ -606,23 +609,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