Skip to content

Commit 17383e0

Browse files
Make Testcontainers tests conditional via Maven profile
Disabled for Windows Server (CI) cause its windows containers are not supported by Testcontainers.
1 parent 85493e4 commit 17383e0

3 files changed

Lines changed: 37 additions & 14 deletions

File tree

.github/workflows/maven.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,4 @@ jobs:
3030
cache: 'maven'
3131

3232
- name: Build and test
33-
run: mvn clean verify -U
33+
run: mvn clean verify -U ${{ matrix.os != 'windows-latest' && '-Pdocker' || '' }}

jjava-distro/src/test/java/org/dflib/jjava/distro/ContainerizedKernelCase.java

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package org.dflib.jjava.distro;
22

3+
import org.junit.jupiter.api.Assumptions;
34
import org.junit.jupiter.api.BeforeAll;
45
import org.slf4j.Logger;
56
import 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",

pom.xml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,11 @@
227227
</goals>
228228
</execution>
229229
</executions>
230+
<configuration>
231+
<systemPropertyVariables>
232+
<docker.tests.enabled>${docker.tests.enabled}</docker.tests.enabled>
233+
</systemPropertyVariables>
234+
</configuration>
230235
</plugin>
231236
<plugin>
232237
<groupId>org.apache.maven.plugins</groupId>
@@ -309,5 +314,11 @@
309314
</plugins>
310315
</build>
311316
</profile>
317+
<profile>
318+
<id>docker</id>
319+
<properties>
320+
<docker.tests.enabled>true</docker.tests.enabled>
321+
</properties>
322+
</profile>
312323
</profiles>
313324
</project>

0 commit comments

Comments
 (0)