|
39 | 39 | import org.elasticsearch.common.util.BigArrays; |
40 | 40 | import org.elasticsearch.common.util.concurrent.AbstractRunnable; |
41 | 41 | import org.elasticsearch.common.util.concurrent.ConcurrentCollections; |
42 | | -import org.elasticsearch.indices.breaker.CircuitBreakerService; |
43 | 42 | import org.elasticsearch.indices.breaker.NoneCircuitBreakerService; |
44 | 43 | import org.elasticsearch.node.Node; |
45 | 44 | import org.elasticsearch.plugins.Plugin; |
@@ -263,10 +262,17 @@ public void connectToNode(DiscoveryNode node, ConnectionProfile connectionProfil |
263 | 262 | } |
264 | 263 | } |
265 | 264 |
|
| 265 | + @Override |
| 266 | + public Connection openConnection(DiscoveryNode node, ConnectionProfile profile) throws IOException { |
| 267 | + throw new ConnectTransportException(node, "DISCONNECT: simulated"); |
| 268 | + } |
| 269 | + |
266 | 270 | @Override |
267 | 271 | protected void sendRequest(Connection connection, long requestId, String action, TransportRequest request, |
268 | 272 | TransportRequestOptions options) throws IOException { |
269 | | - simulateDisconnect(connection, original, "DISCONNECT: simulated"); |
| 273 | + connection.close(); |
| 274 | + // send the request, which will blow up |
| 275 | + connection.sendRequest(requestId, action, request, options); |
270 | 276 | } |
271 | 277 | }); |
272 | 278 | } |
@@ -301,19 +307,12 @@ public void addFailToSendNoConnectRule(TransportAddress transportAddress, final |
301 | 307 |
|
302 | 308 | addDelegate(transportAddress, new DelegateTransport(original) { |
303 | 309 |
|
304 | | - @Override |
305 | | - public void connectToNode(DiscoveryNode node, ConnectionProfile connectionProfile, |
306 | | - CheckedBiConsumer<Connection, ConnectionProfile, IOException> connectionValidator) |
307 | | - throws ConnectTransportException { |
308 | | - original.connectToNode(node, connectionProfile, connectionValidator); |
309 | | - } |
310 | | - |
311 | 310 | @Override |
312 | 311 | protected void sendRequest(Connection connection, long requestId, String action, TransportRequest request, |
313 | 312 | TransportRequestOptions options) throws IOException { |
314 | 313 | if (blockedActions.contains(action)) { |
315 | 314 | logger.info("--> preventing {} request", action); |
316 | | - simulateDisconnect(connection, original, "DISCONNECT: prevented " + action + " request"); |
| 315 | + connection.close(); |
317 | 316 | } |
318 | 317 | connection.sendRequest(requestId, action, request, options); |
319 | 318 | } |
@@ -347,6 +346,11 @@ public void connectToNode(DiscoveryNode node, ConnectionProfile connectionProfil |
347 | 346 | } |
348 | 347 | } |
349 | 348 |
|
| 349 | + @Override |
| 350 | + public Connection openConnection(DiscoveryNode node, ConnectionProfile profile) throws IOException { |
| 351 | + throw new ConnectTransportException(node, "UNRESPONSIVE: simulated"); |
| 352 | + } |
| 353 | + |
350 | 354 | @Override |
351 | 355 | protected void sendRequest(Connection connection, long requestId, String action, TransportRequest request, |
352 | 356 | TransportRequestOptions options) throws IOException { |
@@ -413,6 +417,28 @@ public void connectToNode(DiscoveryNode node, ConnectionProfile connectionProfil |
413 | 417 | } |
414 | 418 | } |
415 | 419 |
|
| 420 | + @Override |
| 421 | + public Connection openConnection(DiscoveryNode node, ConnectionProfile profile) throws IOException { |
| 422 | + TimeValue delay = getDelay(); |
| 423 | + if (delay.millis() <= 0) { |
| 424 | + return original.openConnection(node, profile); |
| 425 | + } |
| 426 | + |
| 427 | + // TODO: Replace with proper setting |
| 428 | + TimeValue connectingTimeout = NetworkService.TcpSettings.TCP_CONNECT_TIMEOUT.getDefault(Settings.EMPTY); |
| 429 | + try { |
| 430 | + if (delay.millis() < connectingTimeout.millis()) { |
| 431 | + Thread.sleep(delay.millis()); |
| 432 | + return original.openConnection(node, profile); |
| 433 | + } else { |
| 434 | + Thread.sleep(connectingTimeout.millis()); |
| 435 | + throw new ConnectTransportException(node, "UNRESPONSIVE: simulated"); |
| 436 | + } |
| 437 | + } catch (InterruptedException e) { |
| 438 | + throw new ConnectTransportException(node, "UNRESPONSIVE: simulated"); |
| 439 | + } |
| 440 | + } |
| 441 | + |
416 | 442 | @Override |
417 | 443 | protected void sendRequest(Connection connection, long requestId, String action, TransportRequest request, |
418 | 444 | TransportRequestOptions options) throws IOException { |
@@ -494,37 +520,6 @@ private LookupTestTransport transport() { |
494 | 520 | return (LookupTestTransport) transport; |
495 | 521 | } |
496 | 522 |
|
497 | | - /** |
498 | | - * simulates a disconnect by disconnecting from the underlying transport and throwing a |
499 | | - * {@link ConnectTransportException} |
500 | | - */ |
501 | | - private void simulateDisconnect(DiscoveryNode node, Transport transport, String reason) { |
502 | | - simulateDisconnect(node, transport, reason, null); |
503 | | - } |
504 | | - |
505 | | - /** |
506 | | - * simulates a disconnect by disconnecting from the underlying transport and throwing a |
507 | | - * {@link ConnectTransportException}, due to a specific cause exception |
508 | | - */ |
509 | | - private void simulateDisconnect(DiscoveryNode node, Transport transport, String reason, @Nullable Throwable e) { |
510 | | - if (transport.nodeConnected(node)) { |
511 | | - // this a connected node, disconnecting from it will be up the exception |
512 | | - transport.disconnectFromNode(node); |
513 | | - } else { |
514 | | - throw new ConnectTransportException(node, reason, e); |
515 | | - } |
516 | | - } |
517 | | - |
518 | | - /** |
519 | | - * simulates a disconnect by closing the connection and throwing a |
520 | | - * {@link ConnectTransportException} |
521 | | - */ |
522 | | - private void simulateDisconnect(Transport.Connection connection, Transport transport, String reason) throws IOException { |
523 | | - connection.close(); |
524 | | - simulateDisconnect(connection.getNode(), transport, reason); |
525 | | - } |
526 | | - |
527 | | - |
528 | 523 | /** |
529 | 524 | * A lookup transport that has a list of potential Transport implementations to delegate to for node operations, |
530 | 525 | * if none is registered, then the default one is used. |
|
0 commit comments