@@ -131,7 +131,7 @@ public void testConnectAndDisconnect() throws Exception {
131
131
service .connectToNodes (nodes , () -> future .onResponse (null ));
132
132
future .actionGet ();
133
133
if (isDisrupting == false ) {
134
- assertConnected (nodes );
134
+ assertConnected (transportService , nodes );
135
135
}
136
136
service .disconnectFromNodesExcept (nodes );
137
137
@@ -169,6 +169,11 @@ public void testPeriodicReconnection() {
169
169
final DeterministicTaskQueue deterministicTaskQueue
170
170
= new DeterministicTaskQueue (builder ().put (NODE_NAME_SETTING .getKey (), "node" ).build (), random ());
171
171
172
+ MockTransport transport = new MockTransport (deterministicTaskQueue .getThreadPool ());
173
+ TestTransportService transportService = new TestTransportService (transport , deterministicTaskQueue .getThreadPool ());
174
+ transportService .start ();
175
+ transportService .acceptIncomingRequests ();
176
+
172
177
final NodeConnectionsService service
173
178
= new NodeConnectionsService (settings .build (), deterministicTaskQueue .getThreadPool (), transportService );
174
179
service .start ();
@@ -211,7 +216,7 @@ public String toString() {
211
216
transport .randomConnectionExceptions = false ;
212
217
logger .info ("renewing connections" );
213
218
runTasksUntil (deterministicTaskQueue , maxDisconnectionTime + reconnectIntervalMillis );
214
- assertConnectedExactlyToNodes (targetNodes );
219
+ assertConnectedExactlyToNodes (transportService , targetNodes );
215
220
}
216
221
217
222
public void testOnlyBlocksOnConnectionsToNewNodes () throws Exception {
@@ -314,11 +319,15 @@ private void ensureConnections(NodeConnectionsService service) {
314
319
}
315
320
316
321
private void assertConnectedExactlyToNodes (DiscoveryNodes discoveryNodes ) {
317
- assertConnected (discoveryNodes );
322
+ assertConnectedExactlyToNodes (transportService , discoveryNodes );
323
+ }
324
+
325
+ private void assertConnectedExactlyToNodes (TransportService transportService , DiscoveryNodes discoveryNodes ) {
326
+ assertConnected (transportService , discoveryNodes );
318
327
assertThat (transportService .getConnectionManager ().size (), equalTo (discoveryNodes .getSize ()));
319
328
}
320
329
321
- private void assertConnected (Iterable <DiscoveryNode > nodes ) {
330
+ private void assertConnected (TransportService transportService , Iterable <DiscoveryNode > nodes ) {
322
331
for (DiscoveryNode node : nodes ) {
323
332
assertTrue ("not connected to " + node , transportService .nodeConnected (node ));
324
333
}
@@ -328,8 +337,9 @@ private void assertConnected(Iterable<DiscoveryNode> nodes) {
328
337
@ Before
329
338
public void setUp () throws Exception {
330
339
super .setUp ();
331
- this .threadPool = new TestThreadPool (getClass ().getName ());
332
- this .transport = new MockTransport ();
340
+ ThreadPool threadPool = new TestThreadPool (getClass ().getName ());
341
+ this .threadPool = threadPool ;
342
+ this .transport = new MockTransport (threadPool );
333
343
nodeConnectionBlocks = newConcurrentMap ();
334
344
transportService = new TestTransportService (transport , threadPool );
335
345
transportService .start ();
@@ -361,21 +371,35 @@ public void handshake(Transport.Connection connection, long timeout, Predicate<C
361
371
362
372
@ Override
363
373
public void connectToNode (DiscoveryNode node ) throws ConnectTransportException {
374
+ throw new AssertionError ("no blocking connect" );
375
+ }
376
+
377
+ @ Override
378
+ public void connectToNode (DiscoveryNode node , ActionListener <Void > listener ) throws ConnectTransportException {
364
379
final CheckedRunnable <Exception > connectionBlock = nodeConnectionBlocks .get (node );
365
380
if (connectionBlock != null ) {
366
- try {
367
- connectionBlock .run ();
368
- } catch (Exception e ) {
369
- throw new AssertionError (e );
370
- }
381
+ getThreadPool ().generic ().execute (() -> {
382
+ try {
383
+ connectionBlock .run ();
384
+ super .connectToNode (node , listener );
385
+ } catch (Exception e ) {
386
+ throw new AssertionError (e );
387
+ }
388
+ });
389
+ } else {
390
+ super .connectToNode (node , listener );
371
391
}
372
- super .connectToNode (node );
373
392
}
374
393
}
375
394
376
395
private final class MockTransport implements Transport {
377
396
private ResponseHandlers responseHandlers = new ResponseHandlers ();
378
397
private volatile boolean randomConnectionExceptions = false ;
398
+ private final ThreadPool threadPool ;
399
+
400
+ MockTransport (ThreadPool threadPool ) {
401
+ this .threadPool = threadPool ;
402
+ }
379
403
380
404
@ Override
381
405
public <Request extends TransportRequest > void registerRequestHandler (RequestHandlerRegistry <Request > reg ) {
0 commit comments