5454import static org .hamcrest .MatcherAssert .assertThat ;
5555import static org .hamcrest .Matchers .*;
5656import static org .junit .Assume .assumeNoException ;
57- import static org .junit .Assume .assumeThat ;
5857
5958public class BeyonderRestIT extends AbstractBeyonderTest {
6059
@@ -81,39 +80,44 @@ private static void startRestClient() throws IOException {
8180 if (client == null ) {
8281 client = buildClient (testCluster , testClusterUser , null );
8382 try {
84- if (!testClusterRunning ()) {
85- Properties props = new Properties ();
86- props .load (TestContainerHelper .class .getResourceAsStream ("/beyonder-tests.properties" ));
87- String version = props .getProperty ("elasticsearch.version" );
88-
89- TestContainerHelper containerHelper = new TestContainerHelper ();
90- String url = containerHelper .startElasticsearch (version , testClusterPass );
91- Path clusterCaCrtPath = null ;
92- if (containerHelper .getCertAsBytes () != null ) {
93- clusterCaCrtPath = rootTmpDir .resolve ("cluster-ca.crt" );
94- Files .write (clusterCaCrtPath , containerHelper .getCertAsBytes ());
83+ ConnectException connectException = testClusterRunning ();
84+ if (connectException != null ) {
85+ if (testCluster .equals (DEFAULT_TEST_CLUSTER )) {
86+ Properties props = new Properties ();
87+ props .load (TestContainerHelper .class .getResourceAsStream ("/beyonder-tests.properties" ));
88+ String version = props .getProperty ("elasticsearch.version" );
89+
90+ TestContainerHelper containerHelper = new TestContainerHelper ();
91+ String url = containerHelper .startElasticsearch (version , testClusterPass );
92+ Path clusterCaCrtPath = null ;
93+ if (containerHelper .getCertAsBytes () != null ) {
94+ clusterCaCrtPath = rootTmpDir .resolve ("cluster-ca.crt" );
95+ Files .write (clusterCaCrtPath , containerHelper .getCertAsBytes ());
96+ }
97+ client = buildClient (url , DEFAULT_TEST_USER , clusterCaCrtPath );
98+ connectException = testClusterRunning ();
99+ if (connectException != null ) {
100+ throw new IOException (connectException );
101+ }
102+ } else {
103+ throw new IOException (connectException );
95104 }
96- client = buildClient (url , DEFAULT_TEST_USER , clusterCaCrtPath );
97105 }
98- } catch (ConnectException e ) {
99- // If we have an exception here, let's ignore the test
100- logger .warn ("Integration tests are skipped: [{}]" , e .getMessage ());
101- assumeThat ("Integration tests are skipped" , e .getMessage (), not (containsString ("Connection refused" )));
102106 } catch (IOException e ) {
103- logger .error ("Full error is " , e );
107+ logger .error ("Can not connect to [{}]: {} " , testCluster , e . getMessage () );
104108 throw e ;
105109 }
106110 }
107111 }
108112
109- private static boolean testClusterRunning () throws IOException {
113+ private static ConnectException testClusterRunning () throws IOException {
110114 try {
111115 Response response = client .performRequest (new Request ("GET" , "/" ));
112116 Map <String , Object > asMap = (Map <String , Object >) JsonUtil .asMap (response ).get ("version" );
113117 logger .info ("Starting integration tests against an external cluster running elasticsearch [{}]" , asMap .get ("number" ));
114- return true ;
118+ return null ;
115119 } catch (ConnectException e ) {
116- return false ;
120+ return e ;
117121 }
118122 }
119123
@@ -598,7 +602,7 @@ public void testDateMathIndices() throws Exception {
598602 @ Test
599603 public void testDateMathIndicesWithExistingDailyIndex () throws Exception {
600604 // Manually create an index named <my-index-{now/d}>
601- client .performRequest (new Request ("PUT" , "%3Cmy-index-%7Bnow%2Fd%7D%3E" ));
605+ client .performRequest (new Request ("PUT" , "/ %3Cmy-index-%7Bnow%2Fd%7D%3E" ));
602606
603607 testBeyonder ("models/date-math-indices" ,
604608 singletonList ("my-index-*" ),
@@ -616,7 +620,7 @@ public void testDateMathIndicesWithExistingDailyIndex() throws Exception {
616620 @ Test
617621 public void testDateMathIndicesWithExistingOlderIndex () throws Exception {
618622 // Manually create an index named <my-index-{now/d-1d}>
619- client .performRequest (new Request ("PUT" , "%3Cmy-index-%7Bnow%2Fd-1d%7D%3E" ));
623+ client .performRequest (new Request ("PUT" , "/ %3Cmy-index-%7Bnow%2Fd-1d%7D%3E" ));
620624
621625 testBeyonder ("models/date-math-indices" ,
622626 singletonList ("my-index-*" ),
@@ -747,7 +751,7 @@ public void testRolloverWithDateMaths() throws Exception {
747751 }
748752
749753 private String getMapping (String indexName ) throws IOException {
750- HttpEntity response = client .performRequest (new Request ("GET" , indexName + "/_mapping" )).getEntity ();
754+ HttpEntity response = client .performRequest (new Request ("GET" , "/" + indexName + "/_mapping" )).getEntity ();
751755 ByteArrayOutputStream out = new ByteArrayOutputStream (Math .toIntExact (response .getContentLength () > 0 ? response .getContentLength () : 4000L ));
752756 IOUtils .copy (response .getContent (), out );
753757 return out .toString ();
0 commit comments