1010package org .elasticsearch .indices .cluster ;
1111
1212import org .elasticsearch .ElasticsearchTimeoutException ;
13+ import org .elasticsearch .ExceptionsHelper ;
1314import org .elasticsearch .action .fieldcaps .FieldCapabilitiesRequest ;
1415import org .elasticsearch .action .fieldcaps .TransportFieldCapabilitiesAction ;
1516import org .elasticsearch .common .settings .Setting ;
2930
3031import static org .elasticsearch .test .hamcrest .ElasticsearchAssertions .assertAcked ;
3132
32- public class RemoteFieldCapsForceConnectTimeoutIT extends AbstractMultiClustersTestCase {
33- private static final String REMOTE_CLUSTER_1 = "cluster-a" ;
34- private static final String REMOTE_CLUSTER_2 = "cluster-b" ;
33+ public class FieldCapsForceConnectTimeoutIT extends AbstractMultiClustersTestCase {
34+ private static final String LINKED_CLUSTER_1 = "cluster-a" ;
35+ private static final String LINKED_CLUSTER_2 = "cluster-b" ;
3536
3637 public static class ForceConnectTimeoutPlugin extends Plugin implements ClusterPlugin {
3738 @ Override
@@ -47,7 +48,7 @@ public List<Setting<?>> getSettings() {
4748
4849 @ Override
4950 protected List <String > remoteClusterAlias () {
50- return List .of (REMOTE_CLUSTER_1 , REMOTE_CLUSTER_2 );
51+ return List .of (LINKED_CLUSTER_1 , LINKED_CLUSTER_2 );
5152 }
5253
5354 @ Override
@@ -67,7 +68,7 @@ protected Settings nodeSettings() {
6768
6869 @ Override
6970 protected Map <String , Boolean > skipUnavailableForRemoteClusters () {
70- return Map .of (REMOTE_CLUSTER_1 , true , REMOTE_CLUSTER_2 , true );
71+ return Map .of (LINKED_CLUSTER_1 , true , LINKED_CLUSTER_2 , true );
7172 }
7273
7374 public void testTimeoutSetting () {
@@ -76,7 +77,7 @@ public void testTimeoutSetting() {
7677 MockTransportService mts = (MockTransportService ) cluster (LOCAL_CLUSTER ).getInstance (TransportService .class , nodeName );
7778
7879 mts .addConnectBehavior (
79- cluster (REMOTE_CLUSTER_1 ).getInstance (TransportService .class , (String ) null ),
80+ cluster (LINKED_CLUSTER_1 ).getInstance (TransportService .class , (String ) null ),
8081 ((transport , discoveryNode , profile , listener ) -> {
8182 try {
8283 latch .await ();
@@ -90,27 +91,27 @@ public void testTimeoutSetting() {
9091 }
9192
9293 // Add some dummy data to prove we are communicating fine with the remote.
93- assertAcked (client (REMOTE_CLUSTER_1 ).admin ().indices ().prepareCreate ("test-index" ));
94- client (REMOTE_CLUSTER_1 ).prepareIndex ("test-index" ).setSource ("sample-field" , "sample-value" ).get ();
95- client (REMOTE_CLUSTER_1 ).admin ().indices ().prepareRefresh ("test-index" ).get ();
94+ assertAcked (client (LINKED_CLUSTER_1 ).admin ().indices ().prepareCreate ("test-index" ));
95+ client (LINKED_CLUSTER_1 ).prepareIndex ("test-index" ).setSource ("sample-field" , "sample-value" ).get ();
96+ client (LINKED_CLUSTER_1 ).admin ().indices ().prepareRefresh ("test-index" ).get ();
9697
9798 /*
9899 * Do a full restart so that our custom connect behaviour takes effect since it does not apply to
99100 * pre-existing connections -- they're already established by the time this test runs.
100101 */
101102 try {
102- cluster (REMOTE_CLUSTER_1 ).fullRestart ();
103+ cluster (LINKED_CLUSTER_1 ).fullRestart ();
103104 } catch (Exception e ) {
104105 throw new AssertionError (e );
105106 } finally {
106107 var fieldCapsRequest = new FieldCapabilitiesRequest ();
107108 /*
108- * We have a local and 2 remote clusters but will target only the remote that we stalled.
109- * This is because when the timeout kicks in, and we move on from the stalled remote , we do not want
109+ * We have an origin and 2 linked clusters but will target only the one that we stalled.
110+ * This is because when the timeout kicks in, and we move on from the stalled cluster , we do not want
110111 * the error to be a top-level error. Rather, it must be present in the response object under "failures".
111112 * All other errors are free to be top-level errors though.
112113 */
113- fieldCapsRequest .indices (REMOTE_CLUSTER_1 + ":*" );
114+ fieldCapsRequest .indices (LINKED_CLUSTER_1 + ":*" );
114115 fieldCapsRequest .fields ("foo" , "bar" , "baz" );
115116 var result = safeGet (client ().execute (TransportFieldCapabilitiesAction .TYPE , fieldCapsRequest ));
116117
@@ -126,8 +127,9 @@ public void testTimeoutSetting() {
126127 Matchers .containsString ("java.lang.IllegalStateException: Unable to open any connections" )
127128 );
128129
129- // The actual error that is thrown by the subscribable listener when a remote could not be talked to.
130+ // The actual error that is thrown by the subscribable listener when a linked cluster could not be talked to.
130131 assertThat (failure .getException ().getCause (), Matchers .instanceOf (ElasticsearchTimeoutException .class ));
132+ assertThat (ExceptionsHelper .isRemoteUnavailableException (failure .getException ()), Matchers .is (true ));
131133
132134 latch .countDown ();
133135 result .decRef ();
0 commit comments