2222import org .elasticsearch .common .transport .TransportAddress ;
2323import org .elasticsearch .core .TimeValue ;
2424import org .elasticsearch .transport .client .PreBuiltTransportClient ;
25- import org .junit .AfterClass ;
26- import org .junit .Assume ;
27- import org .junit .BeforeClass ;
25+ import org .junit .jupiter . api . AfterAll ;
26+ import org .junit .jupiter . api . Assumptions ;
27+ import org .junit .jupiter . api . BeforeAll ;
2828import org .testcontainers .containers .GenericContainer ;
29+ import org .testcontainers .junit .jupiter .Container ;
30+ import org .testcontainers .junit .jupiter .Testcontainers ;
2931import org .testcontainers .utility .DockerImageName ;
3032
33+ @ Testcontainers (disabledWithoutDocker = true )
3134public abstract class AbstractElasticsearchTest {
3235
3336 protected static final String CLUSTER_NAME = "test" ;
3437
38+ @ Container
3539 public static final GenericContainer <?> elasticsearch = new GenericContainer <>(dockerImageName ())
3640 .withEnv ("discovery.type" , "single-node" )
3741 .withEnv ("cluster.name" , CLUSTER_NAME )
@@ -45,22 +49,15 @@ public abstract class AbstractElasticsearchTest {
4549
4650 protected static TransportClient client ;
4751
48- @ BeforeClass
52+ @ BeforeAll
4953 public static void setUpCluster () throws Exception {
5054 System .out .println ("Setting up elasticsearch cluster" );
5155 if (client != null ) {
5256 return ;
5357 }
5458
55- try {
56- elasticsearch .start ();
57- } catch (IllegalStateException e ) {
58- Assume .assumeTrue ("Docker is required to run Elasticsearch compliance tests:\n " + safeLogs (), false );
59- }
60-
61- if (!elasticsearch .isRunning ()) {
62- Assume .assumeTrue ("Elasticsearch test container failed to stay running:\n " + safeLogs (), false );
63- }
59+ Assumptions .assumeTrue (elasticsearch .isRunning (),
60+ "Elasticsearch test container failed to start:\n " + safeLogs ());
6461
6562 Settings settings = Settings .builder ().put ("cluster.name" , CLUSTER_NAME ).build ();
6663
@@ -75,15 +72,12 @@ public static void setUpCluster() throws Exception {
7572 client = transportClient ;
7673 }
7774
78- @ AfterClass
75+ @ AfterAll
7976 public static void tearDownCluster () {
8077 if (client != null ) {
8178 client .close ();
8279 client = null ;
8380 }
84- if (elasticsearch != null && elasticsearch .isRunning ()) {
85- elasticsearch .stop ();
86- }
8781 }
8882
8983 private static DockerImageName dockerImageName () {
0 commit comments