@@ -2708,15 +2708,22 @@ public void onConnectionClosed(Transport.Connection connection) {
27082708 }
27092709 }
27102710
2711+ public void testFailToSendTransportException () throws InterruptedException {
2712+ TransportException exception = doFailToSend (new TransportException ("fail to send" ));
2713+ assertThat (exception .getMessage (), equalTo ("fail to send" ));
2714+ assertThat (exception .getCause (), nullValue ());
2715+ }
2716+
2717+ public void testFailToSendIllegalStateException () throws InterruptedException {
2718+ TransportException exception = doFailToSend (new IllegalStateException ("fail to send" ));
2719+ assertThat (exception , instanceOf (SendRequestTransportException .class ));
2720+ assertThat (exception .getMessage (), containsString ("fail-to-send-action" ));
2721+ assertThat (exception .getCause (), instanceOf (IllegalStateException .class ));
2722+ assertThat (exception .getCause ().getMessage (), equalTo ("fail to send" ));
2723+ }
2724+
27112725 // test that the response handler is invoked on a failure to send
2712- @ AwaitsFix (bugUrl = "https://github.com/elastic/elasticsearch/issues/75209" )
2713- public void testFailToSend () throws InterruptedException {
2714- final RuntimeException failToSendException ;
2715- if (randomBoolean ()) {
2716- failToSendException = new IllegalStateException ("fail to send" );
2717- } else {
2718- failToSendException = new TransportException ("fail to send" );
2719- }
2726+ private TransportException doFailToSend (RuntimeException failToSendException ) throws InterruptedException {
27202727 final TransportInterceptor interceptor = new TransportInterceptor () {
27212728 @ Override
27222729 public AsyncSender interceptSender (final AsyncSender sender ) {
@@ -2752,7 +2759,7 @@ public void onResponse(final Void v) {
27522759 public void onFailure (final Exception e ) {
27532760 fail (e .getMessage ());
27542761 }
2755- });
2762+ });
27562763 latch .await ();
27572764 final AtomicReference <TransportException > te = new AtomicReference <>();
27582765 final Transport .Connection connection = serviceC .getConnection (nodeA );
@@ -2773,17 +2780,8 @@ public void handleException(final TransportException exp) {
27732780 }
27742781 });
27752782 assertThat (te .get (), not (nullValue ()));
2776-
2777- if (failToSendException instanceof IllegalStateException ) {
2778- assertThat (te .get ().getMessage (), equalTo ("failure to send" ));
2779- assertThat (te .get ().getCause (), instanceOf (IllegalStateException .class ));
2780- assertThat (te .get ().getCause ().getMessage (), equalTo ("fail to send" ));
2781- } else {
2782- assertThat (te .get ().getMessage (), equalTo ("fail to send" ));
2783- assertThat (te .get ().getCause (), nullValue ());
2784- }
2783+ return te .get ();
27852784 }
2786-
27872785 }
27882786
27892787 private void closeConnectionChannel (Transport .Connection connection ) {
0 commit comments