2323import java .util .ArrayList ;
2424import java .util .Map ;
2525import java .util .concurrent .atomic .AtomicBoolean ;
26+ import java .util .function .Function ;
2627
2728import static org .hamcrest .Matchers .anyOf ;
2829import static org .hamcrest .Matchers .containsString ;
@@ -108,32 +109,34 @@ private void esqlEnrichWithRandomSkipUnavailable() throws Exception {
108109 Map <?, ?> localClusterDetails = (Map <?, ?>) clusterDetails .get ("(local)" );
109110 Map <?, ?> remoteClusterDetails = (Map <?, ?>) clusterDetails .get ("my_remote_cluster" );
110111
112+ Function <String , String > info = (msg ) -> "test: esqlEnrichWithRandomSkipUnavailable: " + msg ;
113+
111114 assertOK (response );
112- assertThat ((int ) map .get ("took" ), greaterThan (0 ));
113- assertThat (values .size (), is (6 ));
115+ assertThat (info . apply ( "overall took" ), (int ) map .get ("took" ), greaterThan (0 ));
116+ assertThat (info . apply ( "overall num values" ), values .size (), is (6 ));
114117 for (int i = 0 ; i < 6 ; i ++) {
115118 ArrayList <?> value = (ArrayList <?>) values .get (i );
116119 // Size is 3: ID, Email, Designation.
117- assertThat (value .size (), is (3 ));
120+ assertThat (info . apply ( "should be id, email, designation, so size 3" ), value .size (), is (3 ));
118121 // Email
119- assertThat ((String ) value .get (0 ), endsWith ("@corp.co" ));
122+ assertThat (info . apply ( "email was: " + value . get ( 0 )), (String ) value .get (0 ), endsWith ("@corp.co" ));
120123 // ID
121- assertThat (value .get (1 ), is (i + 1 ));
124+ assertThat (info . apply ( "id" ), value .get (1 ), is (i + 1 ));
122125 }
123126
124- assertThat ((int ) clusters .get ("total" ), is (2 ));
125- assertThat ((int ) clusters .get ("successful" ), is (2 ));
126- assertThat ((int ) clusters .get ("running" ), is (0 ));
127- assertThat ((int ) clusters .get ("skipped" ), is (0 ));
128- assertThat ((int ) clusters .get ("partial" ), is (0 ));
129- assertThat ((int ) clusters .get ("failed" ), is (0 ));
127+ assertThat (info . apply ( "total clusters" ), (int ) clusters .get ("total" ), is (2 ));
128+ assertThat (info . apply ( "successful clusters" ), (int ) clusters .get ("successful" ), is (2 ));
129+ assertThat (info . apply ( "running clusters" ), (int ) clusters .get ("running" ), is (0 ));
130+ assertThat (info . apply ( "skipped clusters" ), (int ) clusters .get ("skipped" ), is (0 ));
131+ assertThat (info . apply ( "partial clusters" ), (int ) clusters .get ("partial" ), is (0 ));
132+ assertThat (info . apply ( "failed clusters" ), (int ) clusters .get ("failed" ), is (0 ));
130133
131134 assertThat (clusterDetails .size (), is (2 ));
132- assertThat ((int ) localClusterDetails .get ("took" ), greaterThan (0 ));
133- assertThat (localClusterDetails .get ("status" ), is ("successful" ));
135+ assertThat (info . apply ( "local cluster took" ), (int ) localClusterDetails .get ("took" ), greaterThan (0 ));
136+ assertThat (info . apply ( "local cluster status" ), localClusterDetails .get ("status" ), is ("successful" ));
134137
135- assertThat ((int ) remoteClusterDetails .get ("took" ), greaterThan (0 ));
136- assertThat (remoteClusterDetails .get ("status" ), is ("successful" ));
138+ assertThat (info . apply ( "remote cluster took" ), (int ) remoteClusterDetails .get ("took" ), greaterThan (0 ));
139+ assertThat (info . apply ( "remote cluster status" ), remoteClusterDetails .get ("status" ), is ("successful" ));
137140 }
138141
139142 @ SuppressWarnings ("unchecked" )
@@ -153,44 +156,48 @@ private void esqlEnrichWithSkipUnavailableTrue() throws Exception {
153156 Map <?, ?> localClusterDetails = (Map <?, ?>) clusterDetails .get ("(local)" );
154157 Map <?, ?> remoteClusterDetails = (Map <?, ?>) clusterDetails .get ("my_remote_cluster" );
155158
159+ Function <String , String > info = (msg ) -> "test: esqlEnrichWithSkipUnavailableTrue: " + msg ;
160+
156161 assertOK (response );
157- assertThat ((int ) map .get ("took" ), greaterThan (0 ));
158- assertThat (values .size (), is (3 ));
162+ assertThat (info . apply ( "overall took" ), (int ) map .get ("took" ), greaterThan (0 ));
163+ assertThat (info . apply ( "overall values.size" ), values .size (), is (3 ));
159164
160165 // We only have 3 values since the remote cluster is turned off.
161166 for (int i = 0 ; i < 3 ; i ++) {
162167 ArrayList <?> value = (ArrayList <?>) values .get (i );
163168 // Size is 3: ID, Email, Designation.
164- assertThat (value .size (), is (3 ));
169+ assertThat (info . apply ( "should be id, email, designation but had size: " ), value .size (), is (3 ));
165170 // Email
166- assertThat ((String ) value .get (0 ), endsWith ("@corp.co" ));
171+ assertThat (info . apply ( "email was: " + value . get ( 0 )), (String ) value .get (0 ), endsWith ("@corp.co" ));
167172 // ID
168- assertThat (value .get (1 ), is (i + 1 ));
173+ assertThat (info . apply ( "id" ), value .get (1 ), is (i + 1 ));
169174 }
170175
171- assertThat ((int ) clusters .get ("total" ), is (2 ));
172- assertThat ((int ) clusters .get ("successful" ), is (1 ));
173- assertThat ((int ) clusters .get ("running" ), is (0 ));
174- assertThat ((int ) clusters .get ("skipped" ), is (1 ));
175- assertThat ((int ) clusters .get ("partial" ), is (0 ));
176- assertThat ((int ) clusters .get ("failed" ), is (0 ));
176+ assertThat (info . apply ( "total clusters" ), (int ) clusters .get ("total" ), is (2 ));
177+ assertThat (info . apply ( "successful clusters" ), (int ) clusters .get ("successful" ), is (1 ));
178+ assertThat (info . apply ( "running clusters" ), (int ) clusters .get ("running" ), is (0 ));
179+ assertThat (info . apply ( "skipped clusters" ), (int ) clusters .get ("skipped" ), is (1 ));
180+ assertThat (info . apply ( "partial clusters" ), (int ) clusters .get ("partial" ), is (0 ));
181+ assertThat (info . apply ( "failed clusters" ), (int ) clusters .get ("failed" ), is (0 ));
177182
178- assertThat (clusterDetails .size (), is (2 ));
179- assertThat ((int ) localClusterDetails .get ("took" ), greaterThan (0 ));
180- assertThat (localClusterDetails .get ("status" ), is ("successful" ));
183+ assertThat (info . apply ( "cluster details size" ), clusterDetails .size (), is (2 ));
184+ assertThat (info . apply ( "local cluster took" ), (int ) localClusterDetails .get ("took" ), greaterThan (0 ));
185+ assertThat (info . apply ( "local cluster status" ), localClusterDetails .get ("status" ), is ("successful" ));
181186
182- assertThat ((int ) remoteClusterDetails .get ("took" ), greaterThan (0 ));
183- assertThat (remoteClusterDetails .get ("status" ), is ("skipped" ));
187+ assertThat (info . apply ( "remote cluster took" ), (int ) remoteClusterDetails .get ("took" ), greaterThan (0 ));
188+ assertThat (info . apply ( "remote cluster status" ), remoteClusterDetails .get ("status" ), is ("skipped" ));
184189
185190 ArrayList <?> remoteClusterFailures = (ArrayList <?>) remoteClusterDetails .get ("failures" );
186- assertThat (remoteClusterFailures .size (), equalTo (1 ));
191+ assertThat (info . apply ( "remote cluster failure count" ), remoteClusterFailures .size (), equalTo (1 ));
187192 Map <String , ?> failuresMap = (Map <String , ?>) remoteClusterFailures .get (0 );
188193
189194 Map <String , ?> reason = (Map <String , ?>) failuresMap .get ("reason" );
190195 assertThat (
196+ info .apply ("unexpected failure reason: " + reason ),
191197 reason .get ("type" ).toString (),
192198 oneOf ("node_disconnected_exception" , "connect_transport_exception" , "node_not_connected_exception" )
193199 );
200+
194201 } finally {
195202 fulfillingCluster .start ();
196203 closeFulfillingClusterClient ();
@@ -208,6 +215,7 @@ private void esqlEnrichWithSkipUnavailableFalse() throws Exception {
208215 ResponseException ex = expectThrows (ResponseException .class , () -> client ().performRequest (esqlRequest (query )));
209216
210217 assertThat (
218+ "esqlEnrichWithSkipUnavailableFalse failure" ,
211219 ex .getMessage (),
212220 anyOf (
213221 containsString ("connect_transport_exception" ),
0 commit comments