Skip to content
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.testcontainers.containers;

import com.github.dockerjava.api.command.InspectContainerResponse;
import io.tarantool.driver.exceptions.TarantoolConnectionException;
import org.testcontainers.images.builder.ImageFromDockerfile;

import java.net.URL;
Expand Down Expand Up @@ -431,29 +432,56 @@ protected void containerIsStarting(InspectContainerResponse containerInfo) {
logger().info("Tarantool Cartridge cluster is starting");
}

@Override
protected void containerIsStarted(InspectContainerResponse containerInfo, boolean reused) {
super.containerIsStarted(containerInfo, reused);

private boolean setupTopology() {
try {
executeScript(topologyConfigurationFile).get();
// The client connection will be closed after that command
} catch (Exception e) {
if (e instanceof ExecutionException && e.getCause() instanceof TimeoutException) {
// Do nothing, the cluster is reloading
if (e instanceof ExecutionException) {
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 {
logger().error("Failed to change the app topology", e);
throw new RuntimeException("Failed to change the app topology", e);
}
}
return true;
}

private void retryingSetupTopology() {
if (!setupTopology()) {
try {
logger().info("Retrying setup topology in 10 seconds");
Thread.sleep(10000);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
if (!setupTopology()) {
throw new RuntimeException("Failed to change the app topology after retry");
}
}
}

// The client must reconnect automatically
private void bootstrapVshard() {
try {
executeCommand(VSHARD_BOOTSTRAP_COMMAND).get();
} catch (Exception e) {
logger().error("Failed to bootstrap vshard cluster", e);
throw new RuntimeException(e);
}
}

@Override
protected void containerIsStarted(InspectContainerResponse containerInfo, boolean reused) {
super.containerIsStarted(containerInfo, reused);

retryingSetupTopology();
bootstrapVshard();

logger().info("Tarantool Cartridge cluster is started");
logger().info("Tarantool Cartridge router is listening at {}:{}", getRouterHost(), getRouterPort());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,28 +39,43 @@ public void test_ClusterContainer_StartsSuccessfully_ifFilesAreCopiedUnderRoot()

container.start();
CartridgeContainerTestUtils.executeProfileReplaceSmokeTest(container);
if(container.isRunning())
container.stop();
}

@Test
public void test_ClusterContainer_StartsSuccessfully_ifFixedPortsAreConfigured() throws Exception {
Map<String, String> buildArgs = new HashMap<String, String>() {
{
put("TARANTOOL_SERVER_USER", "root");
put("TARANTOOL_SERVER_UID", "0");
put("TARANTOOL_SERVER_GROUP", "root");
put("TARANTOOL_SERVER_GID", "0");
}
};

TarantoolCartridgeContainer container =
new TarantoolCartridgeContainer(
"Dockerfile",
"testcontainers-java-tarantool:test",
"testcontainers-java-tarantool-fixport:test",
"cartridge/instances_fixedport.yml",
"cartridge/topology_fixedport.lua")
.withDirectoryBinding("cartridge")
"cartridge/topology_fixedport.lua",
buildArgs)
.withCopyFileToContainer(MountableFile.forClasspathResource("cartridge"), "/app")
.withCopyFileToContainer(MountableFile.forClasspathResource("cartridge/instances_fixedport.yml"),"/app/instances.yml")
.withStartupTimeout(Duration.ofSeconds(300))
.withUseFixedPorts(true)
.withAPIPort(18081)
.withRouterPort(13301)
.waitingFor(
Wait.forLogMessage(".*Listening HTTP on.*", 1)
Wait.forLogMessage(".*Listening HTTP on.*", 2)
)
.withLogConsumer(new Slf4jLogConsumer(
LoggerFactory.getLogger(TarantoolCartridgeContainerTest.class)));

container.start();
CartridgeContainerTestUtils.executeProfileReplaceSmokeTest(container);
if(container.isRunning())
container.stop();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ public class TarantoolCartridgeStaticContainerTest {
private static final TarantoolCartridgeContainer container =
new TarantoolCartridgeContainer(
"Dockerfile",
"testcontainers-java-tarantool:test",
"cartridge/instances.yml",
"cartridge/topology.lua")
.withDirectoryBinding("cartridge")
Expand All @@ -27,7 +26,7 @@ public class TarantoolCartridgeStaticContainerTest {
LoggerFactory.getLogger(TarantoolCartridgeStaticContainerTest.class)));

@Test
public void testContainerWithParameters() throws Exception {
public void test_StaticClusterContainer_StartsSuccessfully_ifDirectoryBinndingIsUsed() throws Exception {
CartridgeContainerTestUtils.executeProfileReplaceSmokeTest(container);
}
}
16 changes: 6 additions & 10 deletions src/test/resources/cartridge/instances.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,38 +2,34 @@ testapp.router:
workdir: ./tmp/db_dev/3301
advertise_uri: localhost:3301
http_port: 8081
memtx_memory: 60000000

testapp.s1-master:
workdir: ./tmp/db_dev/3302
advertise_uri: localhost:3302
http_port: 8082
memtx_memory: 60000000

testapp.s1-replica:
workdir: ./tmp/db_dev/3303
advertise_uri: localhost:3303
http_port: 8083
memtx_memory: 60000000

testapp.s2-master:
workdir: ./tmp/db_dev/3304
advertise_uri: localhost:3304
http_port: 8084
memtx_memory: 60000000

testapp.s2-replica:
workdir: ./tmp/db_dev/3305
advertise_uri: localhost:3305
http_port: 8085
memtx_memory: 60000000

testapp-stateboard:
workdir: ./tmp/db_dev/3310
listen: localhost:3310
password: passwd

testapp.router-fixedport:
workdir: ./tmp/db_dev/13301
advertise_uri: localhost:13301
http_port: 18081

testapp.storage-fixedport:
workdir: ./tmp/db_dev/13302
advertise_uri: localhost:13302
http_port: 18082
memtx_memory: 60000000
2 changes: 2 additions & 0 deletions src/test/resources/cartridge/instances_fixedport.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ testapp.router-fixedport:
workdir: ./tmp/db_dev/13301
advertise_uri: localhost:13301
http_port: 18081
memtx_memory: 60000000

testapp.storage-fixedport:
workdir: ./tmp/db_dev/13302
advertise_uri: localhost:13302
http_port: 18082
memtx_memory: 60000000