|
21 | 21 | import org.elasticsearch.action.ActionListenerResponseHandler;
|
22 | 22 | import org.elasticsearch.action.support.PlainActionFuture;
|
23 | 23 | import org.elasticsearch.cluster.node.DiscoveryNode;
|
| 24 | +import org.elasticsearch.common.component.Lifecycle; |
24 | 25 | import org.elasticsearch.common.io.stream.BytesStreamOutput;
|
25 | 26 | import org.elasticsearch.common.io.stream.StreamInput;
|
26 | 27 | import org.elasticsearch.common.io.stream.StreamOutput;
|
@@ -850,6 +851,31 @@ public void handleException(TransportException exp) {
|
850 | 851 | }
|
851 | 852 | }
|
852 | 853 |
|
| 854 | + public void testExceptionOnConnect() { |
| 855 | + final Transport transportA = serviceA.getOriginalTransport(); |
| 856 | + |
| 857 | + final PlainActionFuture<Transport.Connection> nullProfileFuture = new PlainActionFuture<>(); |
| 858 | + transportA.openConnection(nodeB, null, nullProfileFuture); |
| 859 | + assertTrue(nullProfileFuture.isDone()); |
| 860 | + expectThrows(ExecutionException.class, NullPointerException.class, nullProfileFuture::get); |
| 861 | + |
| 862 | + final ConnectionProfile profile = ConnectionProfile.buildDefaultConnectionProfile(Settings.EMPTY); |
| 863 | + final PlainActionFuture<Transport.Connection> nullNodeFuture = new PlainActionFuture<>(); |
| 864 | + transportA.openConnection(null, profile, nullNodeFuture); |
| 865 | + assertTrue(nullNodeFuture.isDone()); |
| 866 | + expectThrows(ExecutionException.class, ConnectTransportException.class, nullNodeFuture::get); |
| 867 | + |
| 868 | + serviceA.stop(); |
| 869 | + assertEquals(Lifecycle.State.STOPPED, transportA.lifecycleState()); |
| 870 | + serviceA.close(); |
| 871 | + assertEquals(Lifecycle.State.CLOSED, transportA.lifecycleState()); |
| 872 | + |
| 873 | + final PlainActionFuture<Transport.Connection> closedTransportFuture = new PlainActionFuture<>(); |
| 874 | + transportA.openConnection(nodeB, profile, closedTransportFuture); |
| 875 | + assertTrue(closedTransportFuture.isDone()); |
| 876 | + expectThrows(ExecutionException.class, IllegalStateException.class, closedTransportFuture::get); |
| 877 | + } |
| 878 | + |
853 | 879 | public void testDisconnectListener() throws Exception {
|
854 | 880 | final CountDownLatch latch = new CountDownLatch(1);
|
855 | 881 | TransportConnectionListener disconnectListener = new TransportConnectionListener() {
|
|
0 commit comments