Skip to content

Improve awaiting Tarantool start/stop processes #165

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

Merged
merged 1 commit into from
Apr 20, 2019
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
2 changes: 0 additions & 2 deletions src/test/java/org/tarantool/AbstractTarantoolConnectorIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -235,12 +235,10 @@ protected List<?> consoleDelete(String spaceName, Object key) {

protected static void stopTarantool(String instance) {
control.stop(instance);
control.waitStopped("jdk-testing");
}

protected static void startTarantool(String instance) {
control.start(instance);
control.waitStarted("jdk-testing");
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,12 +131,10 @@ protected static TarantoolConsole openConsole(String instance) {

protected static void stopTarantool(String instance) {
control.stop(instance);
control.waitStopped("jdk-testing");
}

protected static void startTarantool(String instance) {
control.start(instance);
control.waitStarted("jdk-testing");
}

}
9 changes: 3 additions & 6 deletions src/test/java/org/tarantool/ClientReconnectClusterIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ public class ClientReconnectClusterIT {
private static final String SRV1 = "replica1";
private static final String SRV2 = "replica2";
private static final String SRV3 = "replica3";
private static final int[] PORTS = { 3302, 3303, 3304 };
private static final int[] CONSOLE_PORTS = { 3312, 3313, 3314 };
private static final int[] PORTS = { 3401, 3402, 3403 };
private static final int[] CONSOLE_PORTS = { 3501, 3502, 3503 };
private static TarantoolControl control;

private static String REPLICATION_CONFIG = TestUtils.makeReplicationString(
Expand Down Expand Up @@ -410,7 +410,7 @@ private void tryAwait(CyclicBarrier barrier) {

private void startInstancesAndAwait(String... instances) {
for (String instance : instances) {
control.start(instance);
control.start(instance, false);
}
for (String instance : instances) {
control.waitStarted(instance);
Expand All @@ -421,9 +421,6 @@ private void stopInstancesAndAwait(String... instances) {
for (String instance : instances) {
control.stop(instance);
}
for (String instance : instances) {
control.waitStopped(instance);
}
}

private void expectConnected(TarantoolClientImpl client, int spaceId, int pkId) {
Expand Down
53 changes: 49 additions & 4 deletions src/test/java/org/tarantool/ClientReconnectIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import java.util.concurrent.locks.LockSupport;

public class ClientReconnectIT extends AbstractTarantoolConnectorIT {

private static final String INSTANCE_NAME = "jdk-testing";
private TarantoolClient client;

Expand Down Expand Up @@ -99,7 +100,7 @@ public SocketChannel get(int retryNumber, Throwable lastError) {
client.syncOps().ping();

// The park() will return inside connector thread.
LockSupport.unpark(((TarantoolClientImpl)client).connector);
LockSupport.unpark(((TarantoolClientImpl) client).connector);

// Wait on latch as a proof that reconnect did not happen.
// In case of a failure, latch will reach 0 before timeout occurs.
Expand Down Expand Up @@ -213,11 +214,54 @@ public void run() {
});
}

// DO NOT REMOVE THIS TEST
// Motivation: this test checks start/stop correctness
// of TarantoolControl class which is used by other tests.
// This test is commented out because the class is used
// for internal purposes only and isn't related to
// the connector testing.
// @Test
// @DisplayName("follow up the issue #164")
// void testStartStopTarantoolInstance() throws InterruptedException {
// int numberOfParallelInstances = 4;
// CountDownLatch finished = new CountDownLatch(numberOfParallelInstances);
// List<String> instancesNames = new ArrayList<>(numberOfParallelInstances);
//
// for (int i = 0; i < numberOfParallelInstances; i++) {
// String instance = "startStop" + (i + 1);
// instancesNames.add(instance);
// control.createInstance(
// instancesNames.get(i),
// LUA_FILE,
// makeInstanceEnv(3401 + i + 1, 3501 + i + 1)
// );
// startTarantool(instancesNames.get(i));
// new Thread(() -> {
// for (int j = 0; j < 100; j++) {
// stopTarantool(instance);
// startTarantool(instance);
// if (j % 10 == 0) {
// System.out.println(
// Thread.currentThread().getName() + ": " + j + "% completed"
// );
// }
// }
// finished.countDown();
// }, "Thread" + (i + 1)).start();
// }
//
// assertTrue(finished.await(2, TimeUnit.MINUTES));
//
// for (int i = 0; i < numberOfParallelInstances; i++) {
// stopTarantool(instancesNames.get(i));
// }
// }

/**
* Test concurrent operations, reconnects and close.
*
* <p>
* Expected situation is nothing gets stuck.
*
* <p>
* The test sets SO_LINGER to 0 for outgoing connections to avoid producing
* many TIME_WAIT sockets, because an available port range can be
* exhausted.
Expand Down Expand Up @@ -316,7 +360,7 @@ public void run() {
* Verify that we don't exceed a file descriptor limit (and so likely don't
* leak file descriptors) when trying to connect to an existing node with
* wrong authentification credentials.
*
* <p>
* The test sets SO_LINGER to 0 for outgoing connections to avoid producing
* many TIME_WAIT sockets, because an available port range can be
* exhausted.
Expand Down Expand Up @@ -354,4 +398,5 @@ public void execute() throws Throwable {
client.syncOps().ping();
client.close();
}

}
Loading