@@ -217,19 +217,27 @@ public void run() {
217
217
218
218
/**
219
219
* Test concurrent operations, reconnects and close.
220
+ *
220
221
* Expected situation is nothing gets stuck.
222
+ *
223
+ * The test sets SO_LINGER to 0 for outgoing connections to avoid producing
224
+ * many TIME_WAIT sockets, because an available port range can be
225
+ * exhausted.
221
226
*/
222
227
@ Test
223
228
public void testLongParallelCloseReconnects () {
224
229
int numThreads = 4 ;
225
230
int numClients = 4 ;
226
231
int timeBudget = 30 *1000 ;
227
232
233
+ SocketChannelProvider provider = new TestSocketChannelProvider (host ,
234
+ port , RESTART_TIMEOUT ).setSoLinger (0 );
235
+
228
236
final AtomicReferenceArray <TarantoolClient > clients =
229
237
new AtomicReferenceArray <TarantoolClient >(numClients );
230
238
231
239
for (int idx = 0 ; idx < clients .length (); idx ++) {
232
- clients .set (idx , makeClient ());
240
+ clients .set (idx , makeClient (provider ));
233
241
}
234
242
235
243
final Random rnd = new Random ();
@@ -258,7 +266,7 @@ public void run() {
258
266
259
267
cli .close ();
260
268
261
- TarantoolClient next = makeClient ();
269
+ TarantoolClient next = makeClient (provider );
262
270
if (!clients .compareAndSet (idx , cli , next )) {
263
271
next .close ();
264
272
}
@@ -306,14 +314,17 @@ public void run() {
306
314
}
307
315
308
316
/**
309
- * Verify that we don't exhaust a file descriptor limit (and so likely
310
- * don't leak file descriptors) when trying to connect to a non existing
311
- * node.
317
+ * Verify that we don't exceed a file descriptor limit (and so likely don't
318
+ * leak file descriptors) when trying to connect to a non existing node.
319
+ *
320
+ * The test sets SO_LINGER to 0 for outgoing connections to avoid producing
321
+ * many TIME_WAIT sockets, because an available port range can be
322
+ * exhausted.
312
323
*/
313
324
@ Test
314
325
public void testReconnectNonExist () throws Exception {
315
326
SocketChannelProvider provider = new TestSocketChannelProvider (host ,
316
- NON_EXIST_PORT , RESTART_TIMEOUT );
327
+ NON_EXIST_PORT , RESTART_TIMEOUT ). setSoLinger ( 0 ) ;
317
328
TarantoolClientConfig config = makeClientConfig ();
318
329
config .initTimeoutMillis = 100 ;
319
330
TarantoolClientImpl client = null ;
@@ -330,19 +341,25 @@ public void testReconnectNonExist() throws Exception {
330
341
}
331
342
332
343
/**
333
- * Verify that we don't exhaust a file descriptor limit (and so likely
334
- * don't leak file descriptors) when trying to connect to an existing node
335
- * with wrong authentification credentials.
344
+ * Verify that we don't exceed a file descriptor limit (and so likely don't
345
+ * leak file descriptors) when trying to connect to an existing node with
346
+ * wrong authentification credentials.
347
+ *
348
+ * The test sets SO_LINGER to 0 for outgoing connections to avoid producing
349
+ * many TIME_WAIT sockets, because an available port range can be
350
+ * exhausted.
336
351
*/
337
352
@ Test
338
353
public void testReconnectWrongAuth () throws Exception {
354
+ SocketChannelProvider provider = new TestSocketChannelProvider (host ,
355
+ port , RESTART_TIMEOUT ).setSoLinger (0 );
339
356
TarantoolClientConfig config = makeClientConfig ();
340
357
config .initTimeoutMillis = 100 ;
341
358
config .password = config .password + 'x' ;
342
359
TarantoolClientImpl client = null ;
343
360
for (int i = 0 ; i < 100 ; ++i ) {
344
361
try {
345
- client = new TarantoolClientImpl (socketChannelProvider , config );
362
+ client = new TarantoolClientImpl (provider , config );
346
363
} catch (Exception ignored ) {
347
364
}
348
365
assertNull (client );
0 commit comments