11package org .dflib .jjava .distro ;
22
3+ import org .junit .jupiter .api .Assumptions ;
34import org .junit .jupiter .api .BeforeAll ;
45import org .slf4j .Logger ;
56import org .slf4j .LoggerFactory ;
@@ -24,7 +25,7 @@ public abstract class ContainerizedKernelCase {
2425
2526 private static final Logger LOGGER = LoggerFactory .getLogger (ContainerizedKernelCase .class );
2627
27- protected static final GenericContainer <?> container ;
28+ protected static GenericContainer <?> container ;
2829 protected static final String WORKING_DIRECTORY = "/test" ;
2930 protected static final String CONTAINER_KERNELSPEC = "/usr/share/jupyter/kernels/java" ;
3031 protected static final String CONTAINER_RESOURCES = WORKING_DIRECTORY + "/resources" ;
@@ -34,20 +35,15 @@ public abstract class ContainerizedKernelCase {
3435 private static final String FS_KERNELSPEC = "../kernelspec/java" ;
3536 private static final String FS_RESOURCES = "src/test/resources" ;
3637
37- static {
38- container = new GenericContainer <>(BASE_IMAGE )
39- .withWorkingDirectory (WORKING_DIRECTORY )
40- .withCopyToContainer (MountableFile .forHostPath (FS_KERNELSPEC ), CONTAINER_KERNELSPEC )
41- .withCopyToContainer (MountableFile .forHostPath (FS_RESOURCES ), CONTAINER_RESOURCES )
42- .withCommand ("bash" , "-c" , getStartupCommand ())
43- .withLogConsumer (new Slf4jLogConsumer (LOGGER ))
44- .waitingFor (Wait .forSuccessfulCommand (getSuccessfulCommand ()))
45- .withStartupTimeout (Duration .ofMinutes (1 ));
46- container .start ();
47- }
38+ private static final String TESTS_ENABLED_PROPERTY = "docker.tests.enabled" ;
4839
4940 @ BeforeAll
50- static void compileSources () throws IOException , InterruptedException {
41+ static void setUp () throws IOException , InterruptedException {
42+ System .out .println ("ContainerizedKernelCase.setUp" );
43+ initializeContainer ();
44+ Assumptions .assumeTrue (container != null , "Docker tests are disabled. Enable with -Pdocker" );
45+ System .out .println ("container = " + container );
46+
5147 String source = "$(find " + CONTAINER_RESOURCES + "/src -name '*.java')" ;
5248 Container .ExecResult compileResult = executeInContainer ("javac -d " + TEST_CLASSPATH + " " + source );
5349
@@ -85,6 +81,22 @@ protected static Container.ExecResult executeInKernel(String snippet, Map<String
8581 return execResult ;
8682 }
8783
84+ private static void initializeContainer () {
85+ if (container != null || !"true" .equals (System .getProperty (TESTS_ENABLED_PROPERTY ))) {
86+ return ;
87+ }
88+
89+ container = new GenericContainer <>(BASE_IMAGE )
90+ .withWorkingDirectory (WORKING_DIRECTORY )
91+ .withCopyToContainer (MountableFile .forHostPath (FS_KERNELSPEC ), CONTAINER_KERNELSPEC )
92+ .withCopyToContainer (MountableFile .forHostPath (FS_RESOURCES ), CONTAINER_RESOURCES )
93+ .withCommand ("bash" , "-c" , getStartupCommand ())
94+ .withLogConsumer (new Slf4jLogConsumer (LOGGER ))
95+ .waitingFor (Wait .forSuccessfulCommand (getSuccessfulCommand ()))
96+ .withStartupTimeout (Duration .ofMinutes (1 ));
97+ container .start ();
98+ }
99+
88100 private static String getStartupCommand () {
89101 return String .join (" && " ,
90102 "apt-get update" ,
0 commit comments