Skip to content

Commit 3420575

Browse files
nicktorwaldTotktonada
authored andcommitted
Improve awaiting Tarantool start/stop processes
Add await-versions of start/stop commands for TarantoolControl class. Improve the waiting process with an extra monitoring PID of a running Tarantool-instance using terminal kill -0 command Fixes: #164
1 parent aaa404a commit 3420575

7 files changed

+200
-93
lines changed

src/test/java/org/tarantool/AbstractTarantoolConnectorIT.java

-2
Original file line numberDiff line numberDiff line change
@@ -235,12 +235,10 @@ protected List<?> consoleDelete(String spaceName, Object key) {
235235

236236
protected static void stopTarantool(String instance) {
237237
control.stop(instance);
238-
control.waitStopped("jdk-testing");
239238
}
240239

241240
protected static void startTarantool(String instance) {
242241
control.start(instance);
243-
control.waitStarted("jdk-testing");
244242
}
245243

246244
/**

src/test/java/org/tarantool/AbstractTarantoolSQLConnectorIT.java

-2
Original file line numberDiff line numberDiff line change
@@ -131,12 +131,10 @@ protected static TarantoolConsole openConsole(String instance) {
131131

132132
protected static void stopTarantool(String instance) {
133133
control.stop(instance);
134-
control.waitStopped("jdk-testing");
135134
}
136135

137136
protected static void startTarantool(String instance) {
138137
control.start(instance);
139-
control.waitStarted("jdk-testing");
140138
}
141139

142140
}

src/test/java/org/tarantool/ClientReconnectClusterIT.java

+3-6
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ public class ClientReconnectClusterIT {
3636
private static final String SRV1 = "replica1";
3737
private static final String SRV2 = "replica2";
3838
private static final String SRV3 = "replica3";
39-
private static final int[] PORTS = { 3302, 3303, 3304 };
40-
private static final int[] CONSOLE_PORTS = { 3312, 3313, 3314 };
39+
private static final int[] PORTS = { 3401, 3402, 3403 };
40+
private static final int[] CONSOLE_PORTS = { 3501, 3502, 3503 };
4141
private static TarantoolControl control;
4242

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

411411
private void startInstancesAndAwait(String... instances) {
412412
for (String instance : instances) {
413-
control.start(instance);
413+
control.start(instance, false);
414414
}
415415
for (String instance : instances) {
416416
control.waitStarted(instance);
@@ -421,9 +421,6 @@ private void stopInstancesAndAwait(String... instances) {
421421
for (String instance : instances) {
422422
control.stop(instance);
423423
}
424-
for (String instance : instances) {
425-
control.waitStopped(instance);
426-
}
427424
}
428425

429426
private void expectConnected(TarantoolClientImpl client, int spaceId, int pkId) {

src/test/java/org/tarantool/ClientReconnectIT.java

+49-4
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import java.util.concurrent.locks.LockSupport;
2727

2828
public class ClientReconnectIT extends AbstractTarantoolConnectorIT {
29+
2930
private static final String INSTANCE_NAME = "jdk-testing";
3031
private TarantoolClient client;
3132

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

101102
// The park() will return inside connector thread.
102-
LockSupport.unpark(((TarantoolClientImpl)client).connector);
103+
LockSupport.unpark(((TarantoolClientImpl) client).connector);
103104

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

217+
// DO NOT REMOVE THIS TEST
218+
// Motivation: this test checks start/stop correctness
219+
// of TarantoolControl class which is used by other tests.
220+
// This test is commented out because the class is used
221+
// for internal purposes only and isn't related to
222+
// the connector testing.
223+
// @Test
224+
// @DisplayName("follow up the issue #164")
225+
// void testStartStopTarantoolInstance() throws InterruptedException {
226+
// int numberOfParallelInstances = 4;
227+
// CountDownLatch finished = new CountDownLatch(numberOfParallelInstances);
228+
// List<String> instancesNames = new ArrayList<>(numberOfParallelInstances);
229+
//
230+
// for (int i = 0; i < numberOfParallelInstances; i++) {
231+
// String instance = "startStop" + (i + 1);
232+
// instancesNames.add(instance);
233+
// control.createInstance(
234+
// instancesNames.get(i),
235+
// LUA_FILE,
236+
// makeInstanceEnv(3401 + i + 1, 3501 + i + 1)
237+
// );
238+
// startTarantool(instancesNames.get(i));
239+
// new Thread(() -> {
240+
// for (int j = 0; j < 100; j++) {
241+
// stopTarantool(instance);
242+
// startTarantool(instance);
243+
// if (j % 10 == 0) {
244+
// System.out.println(
245+
// Thread.currentThread().getName() + ": " + j + "% completed"
246+
// );
247+
// }
248+
// }
249+
// finished.countDown();
250+
// }, "Thread" + (i + 1)).start();
251+
// }
252+
//
253+
// assertTrue(finished.await(2, TimeUnit.MINUTES));
254+
//
255+
// for (int i = 0; i < numberOfParallelInstances; i++) {
256+
// stopTarantool(instancesNames.get(i));
257+
// }
258+
// }
259+
216260
/**
217261
* Test concurrent operations, reconnects and close.
218-
*
262+
* <p>
219263
* Expected situation is nothing gets stuck.
220-
*
264+
* <p>
221265
* The test sets SO_LINGER to 0 for outgoing connections to avoid producing
222266
* many TIME_WAIT sockets, because an available port range can be
223267
* exhausted.
@@ -316,7 +360,7 @@ public void run() {
316360
* Verify that we don't exceed a file descriptor limit (and so likely don't
317361
* leak file descriptors) when trying to connect to an existing node with
318362
* wrong authentification credentials.
319-
*
363+
* <p>
320364
* The test sets SO_LINGER to 0 for outgoing connections to avoid producing
321365
* many TIME_WAIT sockets, because an available port range can be
322366
* exhausted.
@@ -354,4 +398,5 @@ public void execute() throws Throwable {
354398
client.syncOps().ping();
355399
client.close();
356400
}
401+
357402
}

0 commit comments

Comments
 (0)