99package org .elasticsearch .transport ;
1010
1111import org .apache .logging .log4j .Level ;
12+ import org .apache .lucene .store .AlreadyClosedException ;
1213import org .elasticsearch .TransportVersion ;
1314import org .elasticsearch .action .ActionListener ;
1415import org .elasticsearch .action .LatchedActionListener ;
@@ -1097,22 +1098,20 @@ public void testCollectNodesConcurrentWithSettingsChanges() throws IOException {
10971098 taskLatch .countDown ();
10981099 boolean isLinked = true ;
10991100 while (taskLatch .getCount () != 0 ) {
1100- final var latch = new CountDownLatch (1 );
1101- service .updateRemoteCluster (
1102- "cluster_1" ,
1103- createSettings ("cluster_1" , isLinked ? Collections .emptyList () : seedList ),
1104- new LatchedActionListener <>(ActionListener .noop (), latch )
1105- );
1106- safeAwait (latch );
1101+ final var future = new PlainActionFuture <RemoteClusterService .RemoteClusterConnectionStatus >();
1102+ final var settings = createSettings ("cluster_1" , isLinked ? Collections .emptyList () : seedList );
1103+ service .updateRemoteCluster ("cluster_1" , settings , future );
1104+ safeGet (future );
11071105 isLinked = isLinked == false ;
11081106 }
11091107 return ;
11101108 }
11111109
11121110 // Verify collectNodes() always invokes the listener, even if the node is concurrently being unlinked.
11131111 try {
1114- for (int i = 0 ; i < 1000 ; ++i ) {
1112+ for (int i = 0 ; i < 10 ; ++i ) {
11151113 final var latch = new CountDownLatch (1 );
1114+ final var exRef = new AtomicReference <Exception >();
11161115 service .collectNodes (Set .of ("cluster_1" ), new LatchedActionListener <>(new ActionListener <>() {
11171116 @ Override
11181117 public void onResponse (BiFunction <String , String , DiscoveryNode > func ) {
@@ -1121,10 +1120,18 @@ public void onResponse(BiFunction<String, String, DiscoveryNode> func) {
11211120
11221121 @ Override
11231122 public void onFailure (Exception e ) {
1124- assertNotNull (e );
1123+ exRef . set (e );
11251124 }
11261125 }, latch ));
11271126 safeAwait (latch );
1127+ if (exRef .get () != null ) {
1128+ assertThat (
1129+ exRef .get (),
1130+ either (instanceOf (TransportException .class )).or (instanceOf (NoSuchRemoteClusterException .class ))
1131+ .or (instanceOf (AlreadyClosedException .class ))
1132+ .or (instanceOf (NoSeedNodeLeftException .class ))
1133+ );
1134+ }
11281135 }
11291136 } finally {
11301137 taskLatch .countDown ();
0 commit comments