Skip to content

Commit

Permalink
Fix dependencies between tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ArtDu committed Apr 27, 2023
1 parent 87468f9 commit 4ea0205
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 22 deletions.
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
package io.tarantool.driver.integration;

import java.time.Duration;
import java.util.HashMap;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.testcontainers.containers.TarantoolCartridgeContainer;
import org.testcontainers.containers.output.Slf4jLogConsumer;
import org.testcontainers.containers.wait.strategy.Wait;

import java.time.Duration;
import java.util.HashMap;

abstract class CartridgeMixedInstancesContainer {

private static final Logger logger = LoggerFactory.getLogger(CartridgeMixedInstancesContainer.class);

protected static final TarantoolCartridgeContainer container;

static {
final HashMap<String, String> buildArgs = new HashMap<>();
buildArgs.put("TARANTOOL_INSTANCES_FILE", "./instances_mixed.yml");
container = new TarantoolCartridgeContainer(
"cartridge/instances_mixed.yml",
"cartridge/topology_mixed.lua", buildArgs)
.withDirectoryBinding("cartridge")
.withLogConsumer(new Slf4jLogConsumer(logger))
.waitingFor(Wait.forLogMessage(".*Listening HTTP on.*", 3))
.withStartupTimeout(Duration.ofMinutes(2));
final HashMap<String, String> env = new HashMap<>();
env.put("TARANTOOL_INSTANCES_FILE", "./instances_mixed.yml");
container = new TarantoolCartridgeContainer("cartridge/instances_mixed.yml",
"cartridge/topology_mixed.lua")
.withDirectoryBinding("cartridge")
.withLogConsumer(new Slf4jLogConsumer(logger))
.waitingFor(Wait.forLogMessage(".*Listening HTTP on.*", 3))
.withStartupTimeout(Duration.ofMinutes(2))
.withEnv(env);
}

protected static void startCluster() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,7 @@ void test_roundRobin_shouldWorkCorrectly_withDiscoveryAndConnections()
Object routerCallCounterPerConnection = getCallCountersPerConnection(getAllConnectionCalls, routerClient4);
assertEquals(Arrays.asList(2, 2), routerCallCounterPerConnection);

String pid = container.execInContainer("pgrep", "-f", "testapp@fourth-router")
.getStdout().replace("\n", "");
container.execInContainer("kill", "-9", pid);
stopInstance("fourth-router");
// wait until discovery get topology
Thread.sleep(5_000);

Expand All @@ -156,11 +154,11 @@ void test_roundRobin_shouldWorkCorrectly_withDiscoveryAndConnections()
}
Thread.sleep(5_000);
for (TarantoolClient router :
Arrays.asList(routerClient1, routerClient3)) {
Arrays.asList(routerClient1, routerClient2, routerClient3)) {
assertEquals(Arrays.asList(6, 7), getCallCountersPerConnection(getAllConnectionCalls, router));
}
routerCallCounterPerConnection = getCallCountersPerConnection(getAllConnectionCalls, routerClient4);
assertEquals(Arrays.asList(4, 4), routerCallCounterPerConnection);

startCartridge();
}

private static TarantoolClient<TarantoolTuple, TarantoolResult<TarantoolTuple>> getSimpleClient(Integer port) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public void httpClusterDiscovererTest() throws TarantoolClientException {
HTTPDiscoveryClusterAddressProvider addressProvider = getHttpProvider();
Collection<TarantoolServerAddress> nodes = addressProvider.getAddresses();

assertEquals(nodes.size(), 3);
assertEquals(nodes.size(), 4);
Set<TarantoolServerAddress> nodeSet = new HashSet<>(nodes);
assertTrue(nodeSet.contains(new TarantoolServerAddress(TEST_ROUTER1_URI)));
assertTrue(nodeSet.contains(new TarantoolServerAddress(TEST_ROUTER2_URI)));
Expand All @@ -70,7 +70,7 @@ public void binaryClusterDiscovererTest() {
TarantoolClusterAddressProvider addressProvider = getBinaryProvider();

Collection<TarantoolServerAddress> nodes = addressProvider.getAddresses();
assertEquals(nodes.size(), 3);
assertEquals(nodes.size(), 4);
Set<TarantoolServerAddress> nodeSet = new HashSet<>(nodes);
assertTrue(nodeSet.contains(new TarantoolServerAddress(TEST_ROUTER1_URI)));
assertTrue(nodeSet.contains(new TarantoolServerAddress(TEST_ROUTER2_URI)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.testcontainers.junit.jupiter.Testcontainers;
import org.testcontainers.shaded.org.apache.commons.lang3.StringUtils;

import java.util.Arrays;
import java.util.Collection;
Expand Down Expand Up @@ -245,6 +246,8 @@ void test_should_closeConnections_ifAddressProviderReturnsNewAddresses() throws
// restart routers for resetting connections
stopInstances(Arrays.asList("router", "second-router"));
startCartridge();
String status = container.execInContainer("cartridge", "status", "--run-dir=/tmp/run").getStderr();
assertEquals(6, StringUtils.countMatches(status, "RUNNING"));

final TarantoolServerAddress firstAddress =
new TarantoolServerAddress(container.getRouterHost(), container.getMappedPort(3301));
Expand Down Expand Up @@ -298,7 +301,7 @@ public void setRefreshCallback(Runnable runnable) {
numberOfSwitching.incrementAndGet();
runnable.run();
}
}, 500, 100, TimeUnit.MILLISECONDS);
}, 0, 100, TimeUnit.MILLISECONDS);
}
}).build();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,6 @@ protected static void startInstance(String instanceName) throws IOException, Int
}

protected static void stopInstance(String instanceName) throws IOException, InterruptedException {
container.execInContainer("cartridge", "stop", "--run-dir=/tmp/run", "--data-dir=/tmp/data", instanceName);
container.execInContainer("cartridge", "stop", "--run-dir=/tmp/run", instanceName);
}
}

0 comments on commit 4ea0205

Please sign in to comment.