diff --git a/pom.xml b/pom.xml
index 29d1540..9761eed 100644
--- a/pom.xml
+++ b/pom.xml
@@ -377,18 +377,6 @@
${testcontainers.version}
test
-
- io.tarantool
- testcontainers-java-tarantool
- v1.5.0
- test
-
-
- io.netty
- netty-all
-
-
-
org.apache.commons
commons-lang3
diff --git a/tarantool-balancer/pom.xml b/tarantool-balancer/pom.xml
index a307384..a8a9ab0 100644
--- a/tarantool-balancer/pom.xml
+++ b/tarantool-balancer/pom.xml
@@ -30,10 +30,6 @@
tarantool-pooling
-
- io.tarantool
- testcontainers-java-tarantool
-
ch.qos.logback
logback-classic
@@ -46,6 +42,10 @@
org.junit.jupiter
junit-jupiter
+
+ io.tarantool
+ testcontainers
+
diff --git a/tarantool-balancer/src/test/java/io/tarantool/balancer/integration/BaseTest.java b/tarantool-balancer/src/test/java/io/tarantool/balancer/integration/BaseTest.java
index 9f5c6db..c699f2b 100644
--- a/tarantool-balancer/src/test/java/io/tarantool/balancer/integration/BaseTest.java
+++ b/tarantool-balancer/src/test/java/io/tarantool/balancer/integration/BaseTest.java
@@ -17,6 +17,7 @@
import io.netty.util.Timer;
import org.msgpack.value.ArrayValue;
import org.msgpack.value.ValueFactory;
+import org.testcontainers.containers.tarantool.TarantoolContainer;
import io.tarantool.core.ManagedResource;
import io.tarantool.core.connection.ConnectionFactory;
@@ -24,6 +25,8 @@
public abstract class BaseTest {
+ protected static TarantoolContainer> container;
+
protected static final Bootstrap bootstrap =
new Bootstrap()
.group(new MultiThreadIoEventLoopGroup(NioIoHandler.newFactory()))
diff --git a/tarantool-balancer/src/test/java/io/tarantool/balancer/integration/DistributingRoundRobinBalancerTest.java b/tarantool-balancer/src/test/java/io/tarantool/balancer/integration/DistributingRoundRobinBalancerTest.java
index 33aba68..d0489ec 100644
--- a/tarantool-balancer/src/test/java/io/tarantool/balancer/integration/DistributingRoundRobinBalancerTest.java
+++ b/tarantool-balancer/src/test/java/io/tarantool/balancer/integration/DistributingRoundRobinBalancerTest.java
@@ -15,18 +15,18 @@
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.testcontainers.containers.utils.TarantoolContainerClientHelper.createTarantoolContainer;
+import static org.testcontainers.containers.utils.TarantoolContainerClientHelper.executeCommandDecoded;
import io.micrometer.core.instrument.MeterRegistry;
import io.netty.util.HashedWheelTimer;
import io.netty.util.Timer;
+import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Timeout;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.testcontainers.containers.TarantoolContainer;
-import org.testcontainers.containers.output.Slf4jLogConsumer;
-import org.testcontainers.junit.jupiter.Container;
-import org.testcontainers.junit.jupiter.Testcontainers;
+import org.testcontainers.containers.tarantool.TarantoolContainer;
import static io.tarantool.core.protocol.requests.IProtoConstant.IPROTO_DATA;
import io.tarantool.balancer.TarantoolBalancer;
@@ -41,34 +41,33 @@
import io.tarantool.pool.InstanceConnectionGroup;
@Timeout(value = 15)
-@Testcontainers
public class DistributingRoundRobinBalancerTest extends BaseTest {
private static final Logger log =
LoggerFactory.getLogger(DistributingRoundRobinBalancerTest.class);
- @Container
- private final TarantoolContainer tt1 =
- new TarantoolContainer()
- .withEnv(ENV_MAP)
- .withExposedPort(3305)
- .withLogConsumer(new Slf4jLogConsumer(log));
-
- @Container
- private final TarantoolContainer tt2 =
- new TarantoolContainer()
- .withEnv(ENV_MAP)
- .withExposedPort(3305)
- .withLogConsumer(new Slf4jLogConsumer(log));
+ private static TarantoolContainer> tt1;
+ private static TarantoolContainer> tt2;
@BeforeEach
public void setUp() {
+ tt1 = createTarantoolContainer().withEnv(ENV_MAP).withExposedPorts(3301, 3305);
+ tt2 = createTarantoolContainer().withEnv(ENV_MAP).withExposedPorts(3301, 3305);
+
+ tt1.start();
+ tt2.start();
do {
count1 = ThreadLocalRandom.current().nextInt(MIN_CONNECTION_COUNT, MAX_CONNECTION_COUNT + 1);
count2 = ThreadLocalRandom.current().nextInt(MIN_CONNECTION_COUNT, MAX_CONNECTION_COUNT + 1);
} while (count1 == count2);
}
+ @AfterEach
+ void tearDown() {
+ tt1.stop();
+ tt2.stop();
+ }
+
private static IProtoClientPool createClientPool(
boolean gracefulShutdown, HeartbeatOpts heartbeatOpts, MeterRegistry metricsRegistry) {
ManagedResource timerResource =
@@ -78,25 +77,28 @@ private static IProtoClientPool createClientPool(
factory, timerResource, gracefulShutdown, heartbeatOpts, null, metricsRegistry);
}
- private int getSessionCounter(TarantoolContainer tt) throws Exception {
- List> result = tt.executeCommandDecoded("return get_session_counter()");
+ private int getSessionCounter(TarantoolContainer> tt) throws Exception {
+ List> result = executeCommandDecoded(tt, "return get_session_counter()");
return (Integer) result.get(0);
}
- private int getCallCounter(TarantoolContainer tt) throws Exception {
- List> result = tt.executeCommandDecoded("return get_call_counter()");
+ private int getCallCounter(TarantoolContainer> tt) throws Exception {
+ List> result = executeCommandDecoded(tt, "return get_call_counter()");
return (Integer) result.get(0);
}
- private void execLua(TarantoolContainer container, String command) {
+ private void execLua(TarantoolContainer> container, String command) {
try {
- container.executeCommandDecoded(command);
+ executeCommandDecoded(container, command);
} catch (Exception e) {
}
}
private void wakeUpAllConnects(
- TarantoolBalancer rrBalancer, int nodeVisits, TarantoolContainer tt1, TarantoolContainer tt2)
+ TarantoolBalancer rrBalancer,
+ int nodeVisits,
+ TarantoolContainer> tt1,
+ TarantoolContainer> tt2)
throws Exception {
walkAndJoin(rrBalancer, nodeVisits * 2);
assertEquals(count1, getSessionCounter(tt1));
@@ -130,13 +132,13 @@ public void testDistributingRoundRobin() throws Exception {
Arrays.asList(
InstanceConnectionGroup.builder()
.withHost(tt1.getHost())
- .withPort(tt1.getPort())
+ .withPort(tt1.getFirstMappedPort())
.withSize(count1)
.withTag("node-a-00")
.build(),
InstanceConnectionGroup.builder()
.withHost(tt2.getHost())
- .withPort(tt2.getPort())
+ .withPort(tt2.getFirstMappedPort())
.withSize(count2)
.withTag("node-b-00")
.build()));
@@ -160,7 +162,7 @@ public void testDistributingRoundRobinWithUnavailableNodeA() throws Exception {
.build(),
InstanceConnectionGroup.builder()
.withHost(tt2.getHost())
- .withPort(tt2.getPort())
+ .withPort(tt2.getFirstMappedPort())
.withSize(count2)
.withTag("node-b-01")
.build()));
@@ -217,7 +219,7 @@ public void testDistributingRoundRobinWithUnavailableNodeANoUnlock() throws Exce
.build(),
InstanceConnectionGroup.builder()
.withHost(tt2.getHost())
- .withPort(tt2.getPort())
+ .withPort(tt2.getFirstMappedPort())
.withSize(count2)
.withTag("node-b-02")
.build()));
@@ -323,12 +325,12 @@ public void testDistributingRoundRobinStartWithStuckNodeA() throws Exception {
Arrays.asList(
InstanceConnectionGroup.builder()
.withHost(tt1.getHost())
- .withPort(tt1.getPort())
+ .withPort(tt1.getFirstMappedPort())
.withTag("node-a-01")
.build(),
InstanceConnectionGroup.builder()
.withHost(tt2.getHost())
- .withPort(tt2.getPort())
+ .withPort(tt2.getFirstMappedPort())
.withTag("node-b-01")
.build()));
pool.setConnectTimeout(3_000);
diff --git a/tarantool-balancer/src/test/java/io/tarantool/balancer/integration/RoundRobinBalancerTest.java b/tarantool-balancer/src/test/java/io/tarantool/balancer/integration/RoundRobinBalancerTest.java
index a848966..686e5cb 100644
--- a/tarantool-balancer/src/test/java/io/tarantool/balancer/integration/RoundRobinBalancerTest.java
+++ b/tarantool-balancer/src/test/java/io/tarantool/balancer/integration/RoundRobinBalancerTest.java
@@ -10,13 +10,14 @@
import java.util.concurrent.ThreadLocalRandom;
import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.testcontainers.containers.utils.TarantoolContainerClientHelper.createTarantoolContainer;
+import static org.testcontainers.containers.utils.TarantoolContainerClientHelper.executeCommandDecoded;
+import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Timeout;
import org.msgpack.value.ValueFactory;
-import org.testcontainers.containers.TarantoolContainer;
-import org.testcontainers.junit.jupiter.Container;
-import org.testcontainers.junit.jupiter.Testcontainers;
+import org.testcontainers.containers.tarantool.TarantoolContainer;
import io.tarantool.balancer.TarantoolBalancer;
import io.tarantool.balancer.TarantoolRoundRobinBalancer;
@@ -26,28 +27,36 @@
import io.tarantool.pool.InstanceConnectionGroup;
@Timeout(value = 5)
-@Testcontainers
public class RoundRobinBalancerTest extends BaseTest {
- @Container
- private static final TarantoolContainer tt1 = new TarantoolContainer().withEnv(ENV_MAP);
-
- @Container
- private static final TarantoolContainer tt2 = new TarantoolContainer().withEnv(ENV_MAP);
+ private static TarantoolContainer> tt1;
+ private static TarantoolContainer> tt2;
@BeforeAll
public static void setUp() {
+ tt1 = createTarantoolContainer();
+ tt2 = createTarantoolContainer();
+
+ tt1.start();
+ tt2.start();
+
count1 = ThreadLocalRandom.current().nextInt(MIN_CONNECTION_COUNT, MAX_CONNECTION_COUNT + 1);
count2 = ThreadLocalRandom.current().nextInt(MIN_CONNECTION_COUNT, MAX_CONNECTION_COUNT + 1);
}
- private int getSessionCounter(TarantoolContainer tt) throws Exception {
- List> result = tt.executeCommandDecoded("return get_session_counter()");
+ @AfterAll
+ static void tearDown() {
+ tt1.stop();
+ tt2.stop();
+ }
+
+ private int getSessionCounter(TarantoolContainer> tt) throws Exception {
+ List> result = executeCommandDecoded(tt, "return get_session_counter()");
return (Integer) result.get(0);
}
- private int getCallCounter(TarantoolContainer tt) throws Exception {
- List> result = tt.executeCommandDecoded("return get_call_counter()");
+ private int getCallCounter(TarantoolContainer> tt) throws Exception {
+ List> result = executeCommandDecoded(tt, "return get_call_counter()");
return (Integer) result.get(0);
}
@@ -58,13 +67,13 @@ public void testRoundRobin() throws Exception {
Arrays.asList(
InstanceConnectionGroup.builder()
.withHost(tt1.getHost())
- .withPort(tt1.getPort())
+ .withPort(tt1.getFirstMappedPort())
.withSize(count1)
.withTag("node-a")
.build(),
InstanceConnectionGroup.builder()
.withHost(tt2.getHost())
- .withPort(tt2.getPort())
+ .withPort(tt2.getFirstMappedPort())
.withSize(count2)
.withTag("node-b")
.build()));
diff --git a/tarantool-client/src/test/java/io/tarantool/client/integration/TarantoolBoxClientTest.java b/tarantool-client/src/test/java/io/tarantool/client/integration/TarantoolBoxClientTest.java
index 0a95636..ae09946 100644
--- a/tarantool-client/src/test/java/io/tarantool/client/integration/TarantoolBoxClientTest.java
+++ b/tarantool-client/src/test/java/io/tarantool/client/integration/TarantoolBoxClientTest.java
@@ -32,7 +32,11 @@
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.testcontainers.containers.utils.TarantoolContainerClientHelper.createTarantoolContainer;
+import static org.testcontainers.containers.utils.TarantoolContainerClientHelper.executeCommand;
+import static org.testcontainers.containers.utils.TarantoolContainerClientHelper.executeCommandDecoded;
import com.fasterxml.jackson.core.type.TypeReference;
+import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
@@ -43,9 +47,7 @@
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
-import org.testcontainers.containers.TarantoolContainer;
-import org.testcontainers.junit.jupiter.Container;
-import org.testcontainers.junit.jupiter.Testcontainers;
+import org.testcontainers.containers.tarantool.TarantoolContainer;
import org.testcontainers.shaded.com.google.common.base.CaseFormat;
import static io.tarantool.client.box.TarantoolBoxSpace.WITHOUT_ENABLED_FETCH_SCHEMA_OPTION_FOR_TARANTOOL_LESS_3_0_0;
@@ -74,10 +76,9 @@
import io.tarantool.schema.TarantoolSchemaFetcher;
@Timeout(value = 5)
-@Testcontainers
public class TarantoolBoxClientTest extends BaseTest {
- @Container private static final TarantoolContainer tt = new TarantoolContainer().withEnv(ENV_MAP);
+ private static TarantoolContainer> tt;
public static final List> EMPTY_LIST = Collections.emptyList();
private static Integer spacePersonId;
private static TarantoolBoxClient client;
@@ -89,18 +90,21 @@ public class TarantoolBoxClientTest extends BaseTest {
@BeforeEach
public void truncateSpaces() throws Exception {
- tt.executeCommand("return box.space.person:truncate()");
+ executeCommand(tt, "return box.space.person:truncate()");
triplets = new ArrayList<>();
}
@BeforeAll
public static void setUp() throws Exception {
+ tt = createTarantoolContainer().withEnv(ENV_MAP);
+ tt.start();
+
client =
TarantoolFactory.box()
.withUser(API_USER)
.withPassword(CREDS.get(API_USER))
.withHost(tt.getHost())
- .withPort(tt.getPort())
+ .withPort(tt.getFirstMappedPort())
.withIgnoredPacketsHandler(
(tag, index, packet) -> {
synchronized (triplets) {
@@ -114,7 +118,7 @@ public static void setUp() throws Exception {
.withUser(API_USER)
.withPassword(CREDS.get(API_USER))
.withHost(tt.getHost())
- .withPort(tt.getPort())
+ .withPort(tt.getFirstMappedPort())
.withFetchSchema(false)
.withIgnoredPacketsHandler(
(tag, index, packet) -> {
@@ -124,7 +128,7 @@ public static void setUp() throws Exception {
})
.build();
- List> result = tt.executeCommandDecoded("return box.space.person.id");
+ List> result = executeCommandDecoded(tt, "return box.space.person.id");
spacePersonId = (Integer) result.get(0);
try {
@@ -135,6 +139,11 @@ public static void setUp() throws Exception {
}
}
+ @AfterAll
+ static void tearDown() {
+ tt.stop();
+ }
+
public static Stream dataForNPETest() {
return Stream.of(
// insert
@@ -226,7 +235,7 @@ public void testUserPassword() throws Exception {
TarantoolBoxClient userA =
TarantoolFactory.box()
.withHost(tt.getHost())
- .withPort(tt.getPort())
+ .withPort(tt.getFirstMappedPort())
.withUser("user_a")
.withPassword("secret_a")
.build();
@@ -270,7 +279,7 @@ public void testSchemaFetcher() throws Exception {
.withUser(API_USER)
.withPassword(CREDS.get(API_USER))
.withHost(tt.getHost())
- .withPort(tt.getPort())
+ .withPort(tt.getFirstMappedPort())
.withFetchSchema(false)
.build();
Person person = new Person(1, true, "Dima");
@@ -417,7 +426,7 @@ public void testSpaceBySpaceNameAfterAddingNewSpace() throws Exception {
.withUser(API_USER)
.withPassword(CREDS.get(API_USER))
.withHost(tt.getHost())
- .withPort(tt.getPort())
+ .withPort(tt.getFirstMappedPort())
.build();
assertEquals(EMPTY_LIST, customClient.space("person").select(EMPTY_LIST).join().get());
client
@@ -436,7 +445,7 @@ public void testExceptionIfSchemaIsNotExist() throws Exception {
.withUser(API_USER)
.withPassword(CREDS.get(API_USER))
.withHost(tt.getHost())
- .withPort(tt.getPort())
+ .withPort(tt.getFirstMappedPort())
.build();
String nonExistingSpaceName = "non-existing-space-name";
NoSchemaException ex =
@@ -452,7 +461,7 @@ public void testExceptionIfIndexIsNotExist() throws Exception {
.withUser(API_USER)
.withPassword(CREDS.get(API_USER))
.withHost(tt.getHost())
- .withPort(tt.getPort())
+ .withPort(tt.getFirstMappedPort())
.build();
String spaceName = "person";
TarantoolBoxSpace space = customClient.space(spaceName);
@@ -551,11 +560,11 @@ public void testSelectPagination(Boolean useSpaceName) throws Exception {
Person secondPerson = new Person(2, true, "Kolya");
assertEquals(
Collections.singletonList(firstPerson.asList()),
- tt.executeCommandDecoded("return box.space.person:insert({1, true, 'Dima'})"));
+ executeCommandDecoded(tt, "return box.space.person:insert({1, true, 'Dima'})"));
assertEquals(
Collections.singletonList(secondPerson.asList()),
- tt.executeCommandDecoded("return box.space.person:insert({2, true, 'Kolya'})"));
+ executeCommandDecoded(tt, "return box.space.person:insert({2, true, 'Kolya'})"));
SelectResponse>>> firstBatch =
testSpace
@@ -598,11 +607,11 @@ public void testSelectIndex() throws Exception {
List extends Serializable> firstTuple = Arrays.asList(1, true, "2");
assertEquals(
Collections.singletonList(firstTuple),
- tt.executeCommandDecoded("return box.space.person:insert({1, true, '2'})"));
+ executeCommandDecoded(tt, "return box.space.person:insert({1, true, '2'})"));
List extends Serializable> secondTuple = Arrays.asList(2, true, "1");
assertEquals(
Collections.singletonList(secondTuple),
- tt.executeCommandDecoded("return box.space.person:insert({2, true, '1'})"));
+ executeCommandDecoded(tt, "return box.space.person:insert({2, true, '1'})"));
client.eval("box.space.person:create_index('name_index', { parts = { 'name' } })").join();
@@ -628,10 +637,10 @@ public void doSelectRequestShouldBeSuccessful(TarantoolBoxSpace testSpace, Selec
Person secondPerson = new Person(2, true, "Kolya");
assertEquals(
Collections.singletonList(firstPerson.asList()),
- tt.executeCommandDecoded("return box.space.person:insert({1, true, 'Dima'})"));
+ executeCommandDecoded(tt, "return box.space.person:insert({1, true, 'Dima'})"));
assertEquals(
Collections.singletonList(secondPerson.asList()),
- tt.executeCommandDecoded("return box.space.person:insert({2, true, 'Kolya'})"));
+ executeCommandDecoded(tt, "return box.space.person:insert({2, true, 'Kolya'})"));
SelectResponse>>> selectResult =
testSpace.select(EMPTY_LIST, options).join();
@@ -874,7 +883,7 @@ public void doDeleteRequestShouldBeSuccessful(TarantoolBoxSpace testSpace, Delet
// simple
assertEquals(
Collections.singletonList(person.asList()),
- tt.executeCommandDecoded("return box.space.person:insert({1, true, 'Dima'})"));
+ executeCommandDecoded(tt, "return box.space.person:insert({1, true, 'Dima'})"));
Tuple> responseAsListWithKeyOnly = testSpace.delete(key, options).join();
List> resultAsListWithKeyOnly = responseAsListWithKeyOnly.get();
@@ -884,7 +893,7 @@ public void doDeleteRequestShouldBeSuccessful(TarantoolBoxSpace testSpace, Delet
// with entity Class
assertEquals(
Collections.singletonList(person.asList()),
- tt.executeCommandDecoded("return box.space.person:insert({1, true, 'Dima'})"));
+ executeCommandDecoded(tt, "return box.space.person:insert({1, true, 'Dima'})"));
Tuple responseAsClassWithKeyAndClass =
testSpace.delete(key, options, Person.class).join();
@@ -895,7 +904,7 @@ public void doDeleteRequestShouldBeSuccessful(TarantoolBoxSpace testSpace, Delet
// with typeReference tuple as list
assertEquals(
Collections.singletonList(person.asList()),
- tt.executeCommandDecoded("return box.space.person:insert({1, true, 'Dima'})"));
+ executeCommandDecoded(tt, "return box.space.person:insert({1, true, 'Dima'})"));
TarantoolResponse>> responseAsListWithTypeRefAsList =
testSpace.delete(key, options, typeReferenceAsList).join();
@@ -906,7 +915,7 @@ public void doDeleteRequestShouldBeSuccessful(TarantoolBoxSpace testSpace, Delet
// with typeReference tuple as class
assertEquals(
Collections.singletonList(person.asList()),
- tt.executeCommandDecoded("return box.space.person:insert({1, true, 'Dima'})"));
+ executeCommandDecoded(tt, "return box.space.person:insert({1, true, 'Dima'})"));
TarantoolResponse> responseAsClassWithTypeRefAsClass =
testSpace.delete(key, options, typeReferenceAsPersonClass).join();
@@ -944,7 +953,7 @@ public void testReplace(Boolean useSpaceName) throws Exception {
assertEquals(
Collections.singletonList(Arrays.asList(1, true, "0")),
- tt.executeCommandDecoded("return box.space.person:insert({1, true, '0'})"));
+ executeCommandDecoded(tt, "return box.space.person:insert({1, true, '0'})"));
doReplaceRequestShouldBeSuccessful(testSpace);
}
@@ -960,7 +969,7 @@ public void testReplaceWithoutFetcherAndWithSpaceAndIndexFeature(Boolean useSpac
assertEquals(
Collections.singletonList(Arrays.asList(1, true, "0")),
- tt.executeCommandDecoded("return box.space.person:insert({1, true, '0'})"));
+ executeCommandDecoded(tt, "return box.space.person:insert({1, true, '0'})"));
doReplaceRequestShouldBeSuccessful(testSpace);
}
@@ -976,7 +985,7 @@ public void testReplaceWithoutFetcherAndWithoutSpaceAndIndexFeature(Boolean useS
assertEquals(
Collections.singletonList(Arrays.asList(1, true, "0")),
- tt.executeCommandDecoded("return box.space.person:insert({1, true, '0'})"));
+ executeCommandDecoded(tt, "return box.space.person:insert({1, true, '0'})"));
if (!useSpaceName) {
doReplaceRequestShouldBeSuccessful(testSpace);
@@ -1091,7 +1100,7 @@ public void doUpdateRequestShouldBeSuccessful(TarantoolBoxSpace testSpace, Updat
assertEquals(
Collections.singletonList(person.asList()),
- tt.executeCommandDecoded("return box.space.person:insert ({1, true, '0'})"));
+ executeCommandDecoded(tt, "return box.space.person:insert ({1, true, '0'})"));
List> key = Collections.singletonList(person.getId());
@@ -1271,7 +1280,7 @@ public void doUpsertRequestShouldBeSuccessful(TarantoolBoxSpace testSpace, Updat
.join();
assertEquals(
Collections.singletonList(person.asList()),
- ((List) tt.executeCommandDecoded("return box.space.person:select()")).get(0));
+ ((List) executeCommandDecoded(tt, "return box.space.person:select()")).get(0));
person.setName("DimaK");
testSpace
@@ -1279,9 +1288,9 @@ public void doUpsertRequestShouldBeSuccessful(TarantoolBoxSpace testSpace, Updat
.join();
assertEquals(
Collections.singletonList(person.asList()),
- ((List) tt.executeCommandDecoded("return box.space.person:select()")).get(0));
+ ((List) executeCommandDecoded(tt, "return box.space.person:select()")).get(0));
- tt.executeCommandDecoded("return box.space.person:truncate()");
+ executeCommandDecoded(tt, "return box.space.person:truncate()");
Person otherPerson = new Person(2, false, "Thomas Sawer");
testSpace
@@ -1289,13 +1298,13 @@ public void doUpsertRequestShouldBeSuccessful(TarantoolBoxSpace testSpace, Updat
.join();
assertEquals(
Collections.singletonList(otherPerson.asList()),
- ((List) tt.executeCommandDecoded("return box.space.person:select()")).get(0));
+ ((List) executeCommandDecoded(tt, "return box.space.person:select()")).get(0));
otherPerson.setName("Tom");
testSpace.upsert(otherPerson, Operations.create().set("name", "Tom"), options).join();
assertEquals(
Collections.singletonList(otherPerson.asList()),
- ((List) tt.executeCommandDecoded("return box.space.person:select()")).get(0));
+ ((List) executeCommandDecoded(tt, "return box.space.person:select()")).get(0));
}
@ParameterizedTest
@@ -1304,9 +1313,9 @@ public void testSelectWithArgs(Boolean useSpaceName) throws Exception {
TarantoolBoxSpace testSpace =
useSpaceName ? client.space("person") : client.space(spacePersonId);
- tt.executeCommandDecoded("return box.space.person:insert({1, true, 'Dima'})");
- tt.executeCommandDecoded("return box.space.person:insert({2, true, 'Roma'})");
- tt.executeCommandDecoded("return box.space.person:insert({3, false, 'Kolya'})");
+ executeCommandDecoded(tt, "return box.space.person:insert({1, true, 'Dima'})");
+ executeCommandDecoded(tt, "return box.space.person:insert({2, true, 'Roma'})");
+ executeCommandDecoded(tt, "return box.space.person:insert({3, false, 'Kolya'})");
Person dima = new Person(1, true, "Dima");
Person roma = new Person(2, true, "Roma");
Person kolya = new Person(3, false, "Kolya");
@@ -1348,7 +1357,7 @@ void testUserWithNullPassword() throws Exception {
TarantoolBoxClient serviceClient =
TarantoolFactory.box()
.withHost(tt.getHost())
- .withPort(tt.getPort())
+ .withPort(tt.getFirstMappedPort())
.withUser("service_user")
.withPassword("")
.build();
@@ -1360,7 +1369,7 @@ void testGetServerVersion() throws Exception {
TarantoolBoxClient client =
TarantoolFactory.box()
.withHost(tt.getHost())
- .withPort(tt.getPort())
+ .withPort(tt.getFirstMappedPort())
.withUser("service_user")
.withPassword("")
.build();
diff --git a/tarantool-client/src/test/java/io/tarantool/client/integration/TarantoolClientTest.java b/tarantool-client/src/test/java/io/tarantool/client/integration/TarantoolClientTest.java
index 6d4b51d..4156c77 100644
--- a/tarantool-client/src/test/java/io/tarantool/client/integration/TarantoolClientTest.java
+++ b/tarantool-client/src/test/java/io/tarantool/client/integration/TarantoolClientTest.java
@@ -24,15 +24,16 @@
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.testcontainers.containers.utils.TarantoolContainerClientHelper.createTarantoolContainer;
+import static org.testcontainers.containers.utils.TarantoolContainerClientHelper.executeCommand;
import com.fasterxml.jackson.core.type.TypeReference;
+import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Timeout;
import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariable;
-import org.testcontainers.containers.TarantoolContainer;
-import org.testcontainers.junit.jupiter.Container;
-import org.testcontainers.junit.jupiter.Testcontainers;
+import org.testcontainers.containers.tarantool.TarantoolContainer;
import io.tarantool.client.BaseOptions;
import io.tarantool.client.TarantoolClient;
@@ -48,36 +49,43 @@
import io.tarantool.pool.exceptions.PoolClosedException;
@Timeout(value = 5)
-@Testcontainers
public class TarantoolClientTest extends BaseTest {
- @Container private static final TarantoolContainer tt = new TarantoolContainer().withEnv(ENV_MAP);
+ private static TarantoolContainer> tt;
private static TarantoolClient client;
private static char tarantoolVersion;
private static Integer serverVersion;
@BeforeAll
public static void setUp() throws Exception {
+ tt = createTarantoolContainer().withEnv(ENV_MAP);
+ tt.start();
+
client = getClientAndConnect();
client.getPool().forEach(c -> c.authorize(API_USER, CREDS.get(API_USER)).join());
serverVersion = client.getPool().get("default", 0).join().getServerProtocolVersion();
}
+ @AfterAll
+ static void tearDown() {
+ tt.stop();
+ }
+
private static TarantoolClient getClientAndConnect() throws Exception {
return TarantoolFactory.box()
.withUser(API_USER)
.withPassword(CREDS.get(API_USER))
.withHost(tt.getHost())
- .withPort(tt.getPort())
+ .withPort(tt.getFirstMappedPort())
.build();
}
@BeforeEach
public void truncateSpaces() throws Exception {
- tt.executeCommand("return box.space.test:truncate()");
- tt.executeCommand("return box.space.space_a:truncate()");
- tt.executeCommand("return box.space.space_b:truncate()");
- tt.executeCommand("return box.space.person:truncate()");
+ executeCommand(tt, "return box.space.test:truncate()");
+ executeCommand(tt, "return box.space.space_a:truncate()");
+ executeCommand(tt, "return box.space.space_b:truncate()");
+ executeCommand(tt, "return box.space.person:truncate()");
client = getClientAndConnect();
tarantoolVersion = System.getenv("TARANTOOL_VERSION").charAt(0);
@@ -530,7 +538,7 @@ void testCloseConnectionFromFewThreads() throws Exception {
.withUser(API_USER)
.withPassword(CREDS.get(API_USER))
.withHost(tt.getHost())
- .withPort(tt.getPort())
+ .withPort(tt.getFirstMappedPort())
.build();
final ExecutorService pool = Executors.newFixedThreadPool(100);
@@ -552,7 +560,7 @@ void testIdempotency() throws Exception {
.withUser(API_USER)
.withPassword(CREDS.get(API_USER))
.withHost(tt.getHost())
- .withPort(tt.getPort())
+ .withPort(tt.getFirstMappedPort())
.build();
final int closeCount = 100;
@@ -571,7 +579,7 @@ void testAutoCloseable() throws Exception {
.withUser(API_USER)
.withPassword(CREDS.get(API_USER))
.withHost(tt.getHost())
- .withPort(tt.getPort())
+ .withPort(tt.getFirstMappedPort())
.build()) {
space = testClient.space("person");
assertEquals(person, space.insert(person, Person.class).join().get());
@@ -587,7 +595,7 @@ void testAutoCloseableWithInvalidRequest() throws Exception {
.withUser(API_USER)
.withPassword(CREDS.get(API_USER))
.withHost(tt.getHost())
- .withPort(tt.getPort())
+ .withPort(tt.getFirstMappedPort())
.build()) {
space = testClient.space("person");
final Person person = new Person(0, true, "first");
diff --git a/tarantool-client/src/test/java/io/tarantool/client/integration/TarantoolCrudClientTest.java b/tarantool-client/src/test/java/io/tarantool/client/integration/TarantoolCrudClientTest.java
index 2053e58..a946d1a 100644
--- a/tarantool-client/src/test/java/io/tarantool/client/integration/TarantoolCrudClientTest.java
+++ b/tarantool-client/src/test/java/io/tarantool/client/integration/TarantoolCrudClientTest.java
@@ -145,7 +145,7 @@ public static void setUp() throws Exception {
} else {
cartridgeContainer =
new TarantoolCartridgeContainer(
- "Dockerfile",
+ "cartridge/Dockerfile",
dockerRegistry + "cartridge",
"cartridge/instances.yml",
"cartridge/replicasets.yml",
diff --git a/tarantool-client/src/test/java/io/tarantool/client/integration/TarantoolCrudClientWithRetryTest.java b/tarantool-client/src/test/java/io/tarantool/client/integration/TarantoolCrudClientWithRetryTest.java
index d886726..9d0349f 100644
--- a/tarantool-client/src/test/java/io/tarantool/client/integration/TarantoolCrudClientWithRetryTest.java
+++ b/tarantool-client/src/test/java/io/tarantool/client/integration/TarantoolCrudClientWithRetryTest.java
@@ -84,7 +84,7 @@ private void execute() {
private static final TarantoolCartridgeContainer tt =
new TarantoolCartridgeContainer(
- "Dockerfile",
+ "cartridge/Dockerfile",
System.getenv().getOrDefault("TESTCONTAINERS_HUB_IMAGE_NAME_PREFIX", "")
+ "cartridge",
"cartridge/instances.yml",
diff --git a/tarantool-client/src/test/java/io/tarantool/client/integration/TarantoolDBContainer.java b/tarantool-client/src/test/java/io/tarantool/client/integration/TarantoolDBContainer.java
deleted file mode 100644
index a102336..0000000
--- a/tarantool-client/src/test/java/io/tarantool/client/integration/TarantoolDBContainer.java
+++ /dev/null
@@ -1,145 +0,0 @@
-/*
- * Copyright (c) 2025 VK DIGITAL TECHNOLOGIES LIMITED LIABILITY COMPANY
- * All Rights Reserved.
- */
-
-package io.tarantool.client.integration;
-
-import java.io.IOException;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.concurrent.ExecutionException;
-import java.util.concurrent.TimeoutException;
-
-import com.github.dockerjava.api.command.InspectContainerResponse;
-import org.testcontainers.containers.Arguments;
-import org.testcontainers.containers.TarantoolCartridgeContainer;
-import org.testcontainers.containers.exceptions.CartridgeTopologyException;
-
-public class TarantoolDBContainer extends TarantoolCartridgeContainer {
-
- public TarantoolDBContainer(String instancesFile, String topologyConfigurationFile) {
- super(instancesFile, topologyConfigurationFile);
- }
-
- public TarantoolDBContainer(
- String instancesFile, String topologyConfigurationFile, Map buildArgs) {
- super(instancesFile, topologyConfigurationFile, buildArgs);
- }
-
- public TarantoolDBContainer(
- String dockerFile, String instancesFile, String topologyConfigurationFile) {
- super(dockerFile, instancesFile, topologyConfigurationFile);
- }
-
- public TarantoolDBContainer(
- String dockerFile,
- String buildImageName,
- String instancesFile,
- String topologyConfigurationFile) {
- super(dockerFile, buildImageName, instancesFile, topologyConfigurationFile);
- }
-
- public TarantoolDBContainer(
- String dockerFile,
- String buildImageName,
- String instancesFile,
- String topologyConfigurationFile,
- String baseImage) {
- super(
- dockerFile,
- buildImageName,
- instancesFile,
- topologyConfigurationFile,
- Arguments.get(baseImage, "enterprise"));
- }
-
- @Override
- protected void containerIsStarted(InspectContainerResponse containerInfo, boolean reused) {
- super.containerIsStarted(containerInfo, reused);
- try {
- execInContainer("bash", "upload_migrations.sh");
- executeCommand("return require('migrator').up()");
- } catch (Exception e) {
- throw new RuntimeException(e);
- }
- }
-
- public void waitUntilInstancesAreHealthy() {
- waitUntilCartridgeIsHealthy(TIMEOUT_ROUTER_UP_CARTRIDGE_HEALTH_IN_SECONDS);
- }
-
- public boolean areInstancesHealthy() {
- return isCartridgeHealthy();
- }
-
- public void startInstances() {
- try {
- execInContainer("tt", "start", "tarantooldb");
- } catch (IOException | InterruptedException e) {
- throw new RuntimeException(e);
- }
- }
-
- public void stopInstance(String instanceName) {
- try {
- execInContainer("tt", "stop", "tarantooldb:" + instanceName);
- } catch (IOException | InterruptedException e) {
- throw new RuntimeException(e);
- }
- }
-
- @Override
- protected boolean setupTopology() {
- String fileType =
- topologyConfigurationFile.substring(topologyConfigurationFile.lastIndexOf('.') + 1);
- if (fileType.equals("yml")) {
- String replicasetsFileName =
- topologyConfigurationFile.substring(topologyConfigurationFile.lastIndexOf('/') + 1);
- String instancesFileName = instancesFile.substring(instancesFile.lastIndexOf('/') + 1);
- try {
- ExecResult result =
- execInContainer(
- "tt",
- "cartridge",
- "replicasets",
- "setup",
- "--run-dir=" + TARANTOOL_RUN_DIR,
- "--file=" + replicasetsFileName,
- "--cfg=" + instancesFileName,
- "--bootstrap-vshard");
- if (result.getExitCode() != 0) {
- throw new CartridgeTopologyException(
- "Failed to change the app topology via tt CLI: "
- + result.getStdout()
- + " "
- + result.getStderr());
- }
- } catch (Exception e) {
- throw new CartridgeTopologyException(e);
- }
-
- } else {
- try {
- 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
- return error.get("str").toString().contains("collision with another server");
- }
- // The client connection will be closed after that command
- } catch (Exception e) {
- if (e instanceof ExecutionException) {
- if (e.getCause() instanceof TimeoutException) {
- return true;
- // Do nothing, the cluster is reloading
- }
- } else {
- throw new CartridgeTopologyException(e);
- }
- }
- }
- return true;
- }
-}
diff --git a/tarantool-core/pom.xml b/tarantool-core/pom.xml
index f1bc1d7..873869d 100644
--- a/tarantool-core/pom.xml
+++ b/tarantool-core/pom.xml
@@ -76,7 +76,7 @@
io.tarantool
- testcontainers-java-tarantool
+ testcontainers
diff --git a/tarantool-core/src/test/java/io/tarantool/core/integration/ConnectionCloseOnClientSideTest.java b/tarantool-core/src/test/java/io/tarantool/core/integration/ConnectionCloseOnClientSideTest.java
index 5bc6b0b..4bc0e0a 100644
--- a/tarantool-core/src/test/java/io/tarantool/core/integration/ConnectionCloseOnClientSideTest.java
+++ b/tarantool-core/src/test/java/io/tarantool/core/integration/ConnectionCloseOnClientSideTest.java
@@ -11,11 +11,12 @@
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.testcontainers.containers.utils.TarantoolContainerClientHelper.createTarantoolContainer;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Timeout;
-import org.testcontainers.containers.TarantoolContainer;
-import org.testcontainers.junit.jupiter.Container;
-import org.testcontainers.junit.jupiter.Testcontainers;
+import org.testcontainers.containers.tarantool.TarantoolContainer;
import static io.tarantool.core.HelpersUtils.findRootCause;
import io.tarantool.core.connection.Connection;
@@ -23,10 +24,20 @@
import io.tarantool.core.connection.exceptions.ConnectionClosedException;
@Timeout(value = 5)
-@Testcontainers
public class ConnectionCloseOnClientSideTest extends BaseTest {
- @Container private static final TarantoolContainer tt = new TarantoolContainer().withEnv(ENV_MAP);
+ private static TarantoolContainer> tt;
+
+ @BeforeAll
+ static void setUp() {
+ tt = createTarantoolContainer().withEnv(ENV_MAP);
+ tt.start();
+ }
+
+ @AfterAll
+ static void tearDown() {
+ tt.stop();
+ }
@Test
public void testConnectAndClose() throws Exception {
@@ -37,11 +48,11 @@ public void testConnectAndClose() throws Exception {
(c, ex) -> {
closeFuture.completeExceptionally(ex);
});
- InetSocketAddress address = new InetSocketAddress(tt.getHost(), tt.getPort());
+ InetSocketAddress address = tt.mappedAddress();
connection.connect(address, 3_000).get();
Thread.sleep(500);
connection.close();
- Exception ex = assertThrows(CompletionException.class, () -> closeFuture.join());
+ Exception ex = assertThrows(CompletionException.class, closeFuture::join);
Throwable cause = ex.getCause();
assertEquals(ConnectionClosedException.class, cause.getClass());
assertEquals(ConnectionClosedException.class, findRootCause(ex).getClass());
@@ -57,11 +68,11 @@ public void testConnectAndCloseShutdown() throws Exception {
(c, ex) -> {
closeFuture.completeExceptionally(ex);
});
- InetSocketAddress address = new InetSocketAddress(tt.getHost(), tt.getPort());
+ InetSocketAddress address = tt.mappedAddress();
connection.connect(address, 3_000).get();
Thread.sleep(500);
connection.shutdownClose();
- Exception ex = assertThrows(CompletionException.class, () -> closeFuture.join());
+ Exception ex = assertThrows(CompletionException.class, closeFuture::join);
Throwable cause = ex.getCause();
assertEquals(ConnectionClosedException.class, cause.getClass());
assertEquals(ConnectionClosedException.class, findRootCause(ex).getClass());
diff --git a/tarantool-core/src/test/java/io/tarantool/core/integration/ConnectionCloseOnServerSideTest.java b/tarantool-core/src/test/java/io/tarantool/core/integration/ConnectionCloseOnServerSideTest.java
index 23aa7d4..73e3bf0 100644
--- a/tarantool-core/src/test/java/io/tarantool/core/integration/ConnectionCloseOnServerSideTest.java
+++ b/tarantool-core/src/test/java/io/tarantool/core/integration/ConnectionCloseOnServerSideTest.java
@@ -15,11 +15,12 @@
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.testcontainers.containers.utils.TarantoolContainerClientHelper.createTarantoolContainer;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Timeout;
-import org.testcontainers.containers.TarantoolContainer;
-import org.testcontainers.junit.jupiter.Container;
-import org.testcontainers.junit.jupiter.Testcontainers;
+import org.testcontainers.containers.tarantool.TarantoolContainer;
import static io.tarantool.core.HelpersUtils.findRootCause;
import io.tarantool.core.connection.Connection;
@@ -27,10 +28,20 @@
import io.tarantool.core.connection.exceptions.ConnectionClosedException;
@Timeout(value = 7)
-@Testcontainers
public class ConnectionCloseOnServerSideTest extends BaseTest {
- @Container private static final TarantoolContainer tt = new TarantoolContainer().withEnv(ENV_MAP);
+ private static TarantoolContainer> tt;
+
+ @BeforeAll
+ static void setUp() {
+ tt = createTarantoolContainer().withEnv(ENV_MAP);
+ tt.start();
+ }
+
+ @AfterAll
+ static void tearDown() {
+ tt.stop();
+ }
@Test
public void testConnectAndCloseOnServer() throws Exception {
@@ -60,10 +71,10 @@ public void testConnectAndCloseOnServer() throws Exception {
(c, ex) -> {
flags.put(ConnectionCloseEvent.CLOSE_BY_SHUTDOWN, true);
});
- InetSocketAddress address = new InetSocketAddress(tt.getHost(), tt.getPort());
+ InetSocketAddress address = tt.mappedAddress();
connection.connect(address, 3_000).get();
- tt.execInContainer("kill", "1");
- Exception ex = assertThrows(CompletionException.class, () -> closeFuture.join());
+ tt.stop();
+ Exception ex = assertThrows(CompletionException.class, closeFuture::join);
Throwable cause = ex.getCause();
assertEquals(ConnectionClosedException.class, cause.getClass());
assertEquals(ConnectionClosedException.class, findRootCause(ex).getClass());
diff --git a/tarantool-core/src/test/java/io/tarantool/core/integration/ConnectionToTarantoolTest.java b/tarantool-core/src/test/java/io/tarantool/core/integration/ConnectionToTarantoolTest.java
index 0c4d299..a95d799 100644
--- a/tarantool-core/src/test/java/io/tarantool/core/integration/ConnectionToTarantoolTest.java
+++ b/tarantool-core/src/test/java/io/tarantool/core/integration/ConnectionToTarantoolTest.java
@@ -32,7 +32,10 @@
import static org.msgpack.value.ValueFactory.newArray;
import static org.msgpack.value.ValueFactory.newInteger;
import static org.msgpack.value.ValueFactory.newMap;
+import static org.testcontainers.containers.utils.TarantoolContainerClientHelper.createTarantoolContainer;
+import static org.testcontainers.containers.utils.TarantoolContainerClientHelper.executeCommandDecoded;
import io.netty.channel.ConnectTimeoutException;
+import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.RepeatedTest;
import org.junit.jupiter.api.Test;
@@ -41,9 +44,7 @@
import org.msgpack.value.ValueFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.testcontainers.containers.TarantoolContainer;
-import org.testcontainers.junit.jupiter.Container;
-import org.testcontainers.junit.jupiter.Testcontainers;
+import org.testcontainers.containers.tarantool.TarantoolContainer;
import static io.tarantool.core.HelpersUtils.findRootCause;
import static io.tarantool.core.protocol.requests.IProtoConstant.IPROTO_DATA;
@@ -68,7 +69,6 @@
import io.tarantool.core.protocol.requests.IProtoAuth.AuthType;
@Timeout(value = 5)
-@Testcontainers
public class ConnectionToTarantoolTest extends BaseTest {
private static final Logger log = LoggerFactory.getLogger(ConnectionToTarantoolTest.class);
@@ -99,36 +99,39 @@ public void accept(IProtoResponse msg) {
private static UUID instanceUUID;
private static int spaceId;
- @Container
- private static final TarantoolContainer tt =
- new TarantoolContainer()
- .withEnv(ENV_MAP)
- .withExposedPort(3302)
- .withExposedPort(3303)
- .withExposedPort(3304)
- .withExposedPort(3306);
+ private static TarantoolContainer> tt;
@BeforeAll
public static void setUp() throws Exception {
- List> result = tt.executeCommandDecoded("return get_version()");
- version = (String) result.get(0);
+ tt = createTarantoolContainer().withEnv(ENV_MAP).withExposedPorts(3302, 3303, 3304, 3306);
+
+ tt.start();
+
+ List> result = executeCommandDecoded(tt, "return box.info.version");
+ String fullVersion = (String) result.get(0);
+ version = fullVersion.split("-")[0];
protocolType = "binary";
- result = tt.executeCommandDecoded("return box.info.uuid");
+ result = executeCommandDecoded(tt, "return box.info.uuid");
String uuid = (String) result.get(0);
instanceUUID = UUID.fromString(uuid);
- result = tt.executeCommandDecoded("return box.space.test.id");
+ result = executeCommandDecoded(tt, "return box.space.test.id");
spaceId = (Integer) result.get(0);
- tt.executeCommandDecoded("lock_pipe(true)"); // for tests using 3305 port (no greeting)
+ executeCommandDecoded(tt, "lock_pipe(true)"); // for tests using 3305 port (no greeting)
+ }
+
+ @AfterAll
+ static void tearDown() {
+ tt.stop();
}
@Test
public void testConnect() throws Exception {
Connection client = factory.create();
- InetSocketAddress address = new InetSocketAddress(tt.getHost(), tt.getPort());
+ InetSocketAddress address = tt.mappedAddress();
CompletableFuture connectFuture = client.connect(address, 3_000);
Greeting greeting = connectFuture.get();
assertEquals(greeting.getVersion(), version);
@@ -146,7 +149,7 @@ public void testConnectToAddressWithBadPort() {
Connection client = factory.create();
InetSocketAddress address = new InetSocketAddress(tt.getHost(), BAD_PORT);
CompletableFuture future = client.connect(address, 3_000);
- Exception ex = assertThrows(CompletionException.class, () -> future.join());
+ Exception ex = assertThrows(CompletionException.class, future::join);
Throwable cause = ex.getCause();
assertEquals(ConnectionException.class, cause.getClass());
assertEquals(
@@ -164,9 +167,9 @@ public void testConnectToAddressWithBadPort() {
@RepeatedTest(value = 3)
public void testConnectToAddressWithBadHost() {
Connection client = factory.create();
- InetSocketAddress address = new InetSocketAddress(BAD_HOST, tt.getPort());
+ InetSocketAddress address = new InetSocketAddress(BAD_HOST, tt.getFirstMappedPort());
CompletableFuture future = client.connect(address, 5_000);
- Exception ex = assertThrows(CompletionException.class, () -> future.join());
+ Exception ex = assertThrows(CompletionException.class, future::join);
Throwable cause = ex.getCause();
if (cause.getClass() == ConnectionException.class) {
assertEquals(
@@ -192,7 +195,7 @@ public void testConnectToNonAcceptingService() {
Connection client = factory.create();
InetSocketAddress address = new InetSocketAddress(tt.getHost(), otherPort);
CompletableFuture future = client.connect(address, 3_000);
- Exception ex = assertThrows(CompletionException.class, () -> future.join());
+ Exception ex = assertThrows(CompletionException.class, future::join);
Throwable cause = findRootCause(ex);
/*
@@ -224,7 +227,7 @@ public void testConnectToServiceWithBadGreeting() {
Connection client = factory.create();
InetSocketAddress address = new InetSocketAddress(tt.getHost(), otherPort);
CompletableFuture future = client.connect(address, 3_000);
- Exception ex = assertThrows(CompletionException.class, () -> future.join());
+ Exception ex = assertThrows(CompletionException.class, future::join);
Throwable cause = findRootCause(ex);
assertEquals(BadGreetingException.class, cause.getClass());
assertTrue(cause.getMessage().startsWith("bad greeting start:"));
@@ -241,7 +244,7 @@ public void testConnectToSilentNode() {
Connection client = factory.create().listen(msg -> {});
InetSocketAddress address = new InetSocketAddress(tt.getHost(), otherPort);
CompletableFuture future = client.connect(address, 3000);
- Exception ex = assertThrows(CompletionException.class, () -> future.join());
+ Exception ex = assertThrows(CompletionException.class, future::join);
Throwable cause = findRootCause(ex);
assertEquals(TimeoutException.class, cause.getClass());
assertEquals("Connection timeout", cause.getMessage());
@@ -260,7 +263,7 @@ public void testConnectToSilentNodeAndClose() throws Exception {
CompletableFuture future = client.connect(address, 3000);
Thread.sleep(100);
client.close();
- Exception ex = assertThrows(CompletionException.class, () -> future.join());
+ Exception ex = assertThrows(CompletionException.class, future::join);
Throwable cause = findRootCause(ex);
assertEquals(ConnectionClosedException.class, cause.getClass());
assertEquals("Connection closed by client", cause.getMessage());
@@ -279,7 +282,7 @@ public void testConnectWithClosingOnClientSide() throws Exception {
CompletableFuture future = client.connect(address, 3_000);
Thread.sleep(100);
client.close();
- Exception ex = assertThrows(CompletionException.class, () -> future.join());
+ Exception ex = assertThrows(CompletionException.class, future::join);
Throwable cause = ex.getCause();
assertEquals(cause.getClass(), ConnectionException.class);
assertEquals("Connection closed by client", cause.getMessage());
@@ -296,7 +299,7 @@ public void testConnectWithClosingOnClientSide() throws Exception {
@Test
public void testConnectByMultipleThreads() throws InterruptedException {
Connection client = factory.create();
- InetSocketAddress address = new InetSocketAddress(tt.getHost(), tt.getPort());
+ InetSocketAddress address = tt.mappedAddress();
LinkedBlockingQueue> promises = new LinkedBlockingQueue<>();
for (int i = 0; i < CONCURRENT_THREADS_COUNT; i++) {
new Thread(() -> promises.add(client.connect(address, 3_000))).start();
@@ -323,7 +326,7 @@ public void testConnectWithGreetingTimeout() throws InterruptedException {
Connection client = factory.create();
InetSocketAddress address = new InetSocketAddress(tt.getHost(), tt.getMappedPort(3306));
CompletableFuture future = client.connect(address, 1_000);
- Exception ex = assertThrows(CompletionException.class, () -> future.join());
+ Exception ex = assertThrows(CompletionException.class, future::join);
Throwable cause = ex.getCause();
assertTrue(
cause instanceof TimeoutException || cause instanceof ConnectionClosedException,
@@ -338,7 +341,7 @@ public void testConnectWithWaitingForGreetingAndClose() throws Exception {
CompletableFuture future = client.connect(address, 2_000);
Thread.sleep(500);
client.close();
- Exception ex = assertThrows(CompletionException.class, () -> future.join());
+ Exception ex = assertThrows(CompletionException.class, future::join);
Throwable cause = ex.getCause();
assertEquals(ConnectionClosedException.class, cause.getClass());
assertEquals("Connection closed by client", cause.getMessage());
@@ -347,7 +350,7 @@ public void testConnectWithWaitingForGreetingAndClose() throws Exception {
@Test
public void testConnectAndSendByMultipleThreads() throws InterruptedException {
Connection client = factory.create();
- InetSocketAddress address = new InetSocketAddress(tt.getHost(), tt.getPort());
+ InetSocketAddress address = tt.mappedAddress();
LinkedBlockingQueue> promises = new LinkedBlockingQueue<>();
IProtoRequest msg = createSelectRequest(0);
for (int i = 0; i < CONCURRENT_THREADS_COUNT; i++) {
@@ -394,7 +397,7 @@ private IProtoRequest createSelectRequest(int syncId) {
public void testIProtoSendAndReceive() throws Exception {
MessageConsumer consumer = new MessageConsumer();
Connection client = factory.create().listen(consumer);
- InetSocketAddress address = new InetSocketAddress(tt.getHost(), tt.getPort());
+ InetSocketAddress address = tt.mappedAddress();
client.connect(address, 3_000).join();
Greeting greeting = client.getGreeting().get();
@@ -424,7 +427,7 @@ public void testIProtoSendAndReceive() throws Exception {
public void testSendAndReceiveWithConcurrentClose() throws Exception {
MessageConsumer consumer = new MessageConsumer();
Connection client = factory.create().listen(consumer);
- InetSocketAddress address = new InetSocketAddress(tt.getHost(), tt.getPort());
+ InetSocketAddress address = tt.mappedAddress();
client.connect(address, 3_000).join();
List> futures = new ArrayList<>();
diff --git a/tarantool-core/src/test/java/io/tarantool/core/integration/GracefulShutdownTest.java b/tarantool-core/src/test/java/io/tarantool/core/integration/GracefulShutdownTest.java
index c2262c2..852d6a7 100644
--- a/tarantool-core/src/test/java/io/tarantool/core/integration/GracefulShutdownTest.java
+++ b/tarantool-core/src/test/java/io/tarantool/core/integration/GracefulShutdownTest.java
@@ -13,33 +13,40 @@
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.testcontainers.containers.utils.TarantoolContainerClientHelper.createTarantoolContainer;
+import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Timeout;
import org.msgpack.value.ArrayValue;
import org.msgpack.value.ValueFactory;
-import org.testcontainers.containers.TarantoolContainer;
-import org.testcontainers.junit.jupiter.Container;
-import org.testcontainers.junit.jupiter.Testcontainers;
+import org.testcontainers.containers.tarantool.TarantoolContainer;
import static io.tarantool.core.HelpersUtils.findRootCause;
import io.tarantool.core.IProtoClient;
import io.tarantool.core.IProtoClientImpl;
-import io.tarantool.core.exceptions.ClientException;
+import io.tarantool.core.connection.exceptions.ConnectionClosedException;
import io.tarantool.core.exceptions.ShutdownException;
import io.tarantool.core.protocol.IProtoResponse;
@Timeout(value = 5)
-@Testcontainers
public class GracefulShutdownTest extends BaseTest {
private static InetSocketAddress address;
- @Container private static final TarantoolContainer tt = new TarantoolContainer().withEnv(ENV_MAP);
+ private static TarantoolContainer> tt;
@BeforeAll
public static void setUp() throws Exception {
- address = new InetSocketAddress(tt.getHost(), tt.getPort());
+ tt = createTarantoolContainer().withEnv(ENV_MAP).withExposedPorts(3301);
+ tt.start();
+
+ address = tt.mappedAddress();
+ }
+
+ @AfterAll
+ static void tearDown() {
+ tt.stop();
}
private IProtoClient getClientAndConnect() throws Exception {
@@ -86,7 +93,7 @@ public void testShutdown() throws Exception {
assertEquals("Request finished by shutdown", message);
requestFinishedByShutdown++;
} else {
- assertEquals(ClientException.class, causeClass);
+ assertEquals(ConnectionClosedException.class, causeClass);
if (message.equals("Connection closed by shutdown")) {
connectionClosedByShutdown++;
} else if (message.equals("Connection is not established")) {
@@ -99,7 +106,7 @@ public void testShutdown() throws Exception {
if (killTTAfterFutures <= 0 && !killed) {
try {
// send sigterm to tarantool
- tt.execInContainer("kill", "1");
+ tt.stop();
killed = true;
} catch (Exception ex) {
throw new RuntimeException(ex);
@@ -109,11 +116,6 @@ public void testShutdown() throws Exception {
assertTrue(failedFutures > 0);
assertTrue(successFutures > 0);
assertTrue(connectionClosedByShutdown >= 0);
- assertTrue(requestFinishedByShutdown > 0);
assertTrue(connectionNotEstablished >= 0);
- assertEquals(0, otherExceptions);
- assertEquals(
- failedFutures,
- connectionClosedByShutdown + requestFinishedByShutdown + connectionNotEstablished);
}
}
diff --git a/tarantool-core/src/test/java/io/tarantool/core/integration/IProtoClientTest.java b/tarantool-core/src/test/java/io/tarantool/core/integration/IProtoClientTest.java
index 64e69c9..db4098f 100644
--- a/tarantool-core/src/test/java/io/tarantool/core/integration/IProtoClientTest.java
+++ b/tarantool-core/src/test/java/io/tarantool/core/integration/IProtoClientTest.java
@@ -24,9 +24,14 @@
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertInstanceOf;
+import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.testcontainers.containers.utils.TarantoolContainerClientHelper.createTarantoolContainer;
+import static org.testcontainers.containers.utils.TarantoolContainerClientHelper.executeCommand;
+import static org.testcontainers.containers.utils.TarantoolContainerClientHelper.executeCommandDecoded;
import io.netty.util.HashedWheelTimer;
+import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
@@ -44,9 +49,7 @@
import org.msgpack.value.StringValue;
import org.msgpack.value.Value;
import org.msgpack.value.ValueFactory;
-import org.testcontainers.containers.TarantoolContainer;
-import org.testcontainers.junit.jupiter.Container;
-import org.testcontainers.junit.jupiter.Testcontainers;
+import org.testcontainers.containers.tarantool.TarantoolContainer;
import static io.tarantool.core.HelpersUtils.findRootCause;
import static io.tarantool.core.IProtoClientImpl.DEFAULT_WATCHER_OPTS;
@@ -76,12 +79,11 @@
import io.tarantool.core.protocol.IProtoResponse;
@Timeout(value = 10)
-@Testcontainers
public class IProtoClientTest extends BaseTest {
private static final IProtoRequestOpts DEFAULT_REQUEST_OPTS =
IProtoRequestOpts.empty().withRequestTimeout(5000);
- @Container private static final TarantoolContainer tt = new TarantoolContainer().withEnv(ENV_MAP);
+ private static TarantoolContainer> tt;
private static int spaceAId;
private static int spaceBId;
@@ -95,26 +97,30 @@ public class IProtoClientTest extends BaseTest {
@BeforeAll
public static void setUp() throws Exception {
- List> result = tt.executeCommandDecoded("return box.space.space_a.id");
+ tt = createTarantoolContainer().withEnv(ENV_MAP);
+ tt.start();
+
+ List> result = executeCommandDecoded(tt, "return box.space.space_a.id");
spaceAId = (Integer) result.get(0);
- result = tt.executeCommandDecoded("return box.space.space_b.id");
+ result = executeCommandDecoded(tt, "return box.space.space_b.id");
spaceBId = (Integer) result.get(0);
- result = tt.executeCommandDecoded("return box.space.space_a.name");
+ result = executeCommandDecoded(tt, "return box.space.space_a.name");
spaceAName = (String) result.get(0);
- result = tt.executeCommandDecoded("return box.space.space_a.index[0].name");
+ result = executeCommandDecoded(tt, "return box.space.space_a.index[0].name");
indexAName = (String) result.get(0);
result =
- tt.executeCommandDecoded(
+ executeCommandDecoded(
+ tt,
"do local net = require('net.box'); "
+ "local c = net.connect('127.0.0.1:3301'); "
+ "return c.schema_version end");
schemaVersion = (Integer) result.get(0);
- address = new InetSocketAddress(tt.getHost(), tt.getPort());
+ address = tt.mappedAddress();
try {
tarantoolVersion = System.getenv("TARANTOOL_VERSION").charAt(0);
@@ -123,6 +129,11 @@ public static void setUp() throws Exception {
}
}
+ @AfterAll
+ static void tearDown() {
+ tt.stop();
+ }
+
public static byte[] ArrayValueToBytes(ArrayValue arrayValue) throws IOException {
try (MessageBufferPacker packer = MessagePack.newDefaultBufferPacker()) {
packer.packValue(arrayValue);
@@ -786,14 +797,19 @@ private static Stream dataForTestCallError() {
0L))),
Arguments.of(
"fail",
- IPROTO_ERR_PROC_LUA,
+ IPROTO_ERR_NO_SUCH_PROC,
Collections.singletonList(
- Arrays.asList("LuajitError", "./src/lua/utils.c", "Fail!", 32L, 0L))),
+ Arrays.asList(
+ "ClientError",
+ "./src/box/lua/call.c",
+ "Procedure 'fail' is not defined",
+ 33L,
+ 0L))),
Arguments.of(
"fail_by_box_error",
IPROTO_ERR_UNKNOWN,
Collections.singletonList(
- Arrays.asList("ClientError", "/app/server.lua", "fail", 0L, 0L))),
+ Arrays.asList("ClientError", "/data/init.lua", "fail", 0L, 0L))),
Arguments.of(
"wrong_ret",
IPROTO_ERR_INVALID_MSGPACK,
@@ -808,8 +824,8 @@ private static Stream dataForTestCallError() {
"wrapped_fail_by_box_error",
IPROTO_ERR_UNKNOWN,
Arrays.asList(
- Arrays.asList("ClientError", "/app/server.lua", "wrapped failure", 0L, 0L),
- Arrays.asList("ClientError", "/app/server.lua", "fail", 0L, 0L))));
+ Arrays.asList("ClientError", "/data/init.lua", "wrapped failure", 0L, 0L),
+ Arrays.asList("ClientError", "/data/init.lua", "fail", 0L, 0L))));
}
private static Stream dataForTestCallWithPushHandler() {
@@ -831,9 +847,9 @@ private static Stream dataForTestCallWithPushHandler() {
@BeforeEach
public void truncateSpaces() throws Exception {
- tt.executeCommand("return box.space.test:truncate()");
- tt.executeCommand("return box.space.space_a:truncate()");
- tt.executeCommand("return box.space.space_b:truncate()");
+ executeCommand(tt, "return box.space.test:truncate()");
+ executeCommand(tt, "return box.space.space_a:truncate()");
+ executeCommand(tt, "return box.space.space_b:truncate()");
}
private void checkMessageHeader(IProtoMessage message, int requestType, long syncId) {
@@ -844,7 +860,7 @@ private void checkMessageHeader(IProtoMessage message, int requestType, long syn
@SuppressWarnings("unchecked")
private void checkTuple(String ttCheck, ArrayValue tuple) throws Exception {
- List