Skip to content

Commit c82d407

Browse files
committed
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 ps-command. Fixes: #164
1 parent 7cdb58c commit c82d407

6 files changed

+192
-93
lines changed

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

+1-3
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) {
242-
control.start(instance);
243-
control.waitStarted("jdk-testing");
241+
control.start(instance, true);
244242
}
245243

246244
/**

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

+1-3
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) {
138-
control.start(instance);
139-
control.waitStarted("jdk-testing");
137+
control.start(instance, true);
140138
}
141139

142140
}

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

+6-4
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ public class ClientReconnectClusterIT {
2929
AbstractTarantoolConnectorIT.password,
3030
"localhost:" + PORTS[0],
3131
"localhost:" + PORTS[1],
32-
"localhost:" + PORTS[2]);
32+
"localhost:" + PORTS[2]
33+
);
3334

3435
// Resume replication faster in case of temporary failure to fit TIMEOUT.
3536
private static double REPLICATION_TIMEOUT = 0.1;
@@ -59,9 +60,10 @@ public static void tearDownEnv() {
5960

6061
@Test
6162
public void testRoundRobinReconnect() {
62-
control.start(SRV1);
63-
control.start(SRV2);
64-
control.start(SRV3);
63+
// start instances simultaneously to sync up them
64+
control.start(SRV1, false);
65+
control.start(SRV2, false);
66+
control.start(SRV3, false);
6567

6668
control.waitStarted(SRV1);
6769
control.waitStarted(SRV2);

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(3301 + i + 1, 3321 + 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).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.
@@ -317,7 +361,7 @@ public void run() {
317361
* Verify that we don't exceed a file descriptor limit (and so likely don't
318362
* leak file descriptors) when trying to connect to an existing node with
319363
* wrong authentification credentials.
320-
*
364+
* <p>
321365
* The test sets SO_LINGER to 0 for outgoing connections to avoid producing
322366
* many TIME_WAIT sockets, because an available port range can be
323367
* exhausted.
@@ -355,4 +399,5 @@ public void execute() throws Throwable {
355399
client.syncOps().ping();
356400
client.close();
357401
}
402+
358403
}

0 commit comments

Comments
 (0)