Skip to content

Commit

Permalink
Merge pull request #34 from thehyve/distribution-integration-test
Browse files Browse the repository at this point in the history
Distribution integration test
  • Loading branch information
janblom authored Oct 26, 2023
2 parents d591898 + b9f9344 commit f26d572
Show file tree
Hide file tree
Showing 3 changed files with 115 additions and 14 deletions.
28 changes: 26 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,10 @@
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.release>1.8</maven.compiler.release>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

<skipTests>false</skipTests>
<skipUnitTests>${skipTests}</skipUnitTests>
<skipIntegrationTests>${skipTests}</skipIntegrationTests>
<org.ohdsi.whiterabbit.maxjdkversion>1.8</org.ohdsi.whiterabbit.maxjdkversion>
</properties>

Expand Down Expand Up @@ -120,8 +124,10 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<!-- JUnit 5 requires Surefire version 2.22.0 or higher -->
<version>3.0.0-M8</version>
<version>3.1.2</version>
<configuration>
<skipTests>${skipUnitTests}</skipTests>
</configuration>
<dependencies>
<dependency>
<groupId>org.junit.jupiter</groupId>
Expand All @@ -130,6 +136,24 @@
</dependency>
</dependencies>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<configuration>
<includes>
<include>**/*IT.java</include>
</includes>
<skipTests>${skipIntegrationTests}</skipTests>
</configuration>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.honton.chas</groupId>
<artifactId>license-maven-plugin</artifactId>
Expand Down
42 changes: 30 additions & 12 deletions whiterabbit/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<!-- JUnit 5 requires Surefire version 2.22.0 or higher -->
<version>3.0.0-M8</version>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.1.2</version>
<configuration>
<skipTests>${skipUnitTests}</skipTests>
<argLine>
-Doracle.jdbc.timezoneAsRegion=false
<!-- Line(s) below are needed to keep TestSourceDataScan.updateEnv() working in java 17+
Expand All @@ -47,14 +47,32 @@
--add-opens=java.base/java.util=ALL-UNNAMED
</argLine>
</configuration>
<dependencies>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>5.8.2</version>
</dependency>
</dependencies>
</plugin>
<dependencies>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>5.8.2</version>
</dependency>
</dependencies>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<configuration>
<includes>
<include>**/*IT.java</include>
</includes>
<skipTests>${skipIntegrationTests}</skipTests>
</configuration>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<!-- The maven-shade-plugin takes care of building the fat jar for distribution -->
<groupId>org.apache.maven.plugins</groupId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package org.ohdsi.whiterabbit.scan;

import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.rnorth.ducttape.TimeoutException;
import org.testcontainers.junit.jupiter.Container;
import org.testcontainers.containers.ContainerLaunchException;
import org.testcontainers.containers.GenericContainer;
import org.testcontainers.containers.Container.ExecResult;
import org.testcontainers.junit.jupiter.Testcontainers;
import org.testcontainers.utility.DockerImageName;

import java.io.IOException;
import java.nio.file.Paths;

import static org.junit.jupiter.api.Assertions.*;

/**
* Intent: "deploy" the distributed application in a docker container containing a Java 8 runtime,
* and run a set of tests that aim to verify that the distribution is complete, i.e. no dependencies
* are missing. Typical tests are those that connect to a database of brand X and connect to it, so that the
* distribution is known to have all dependencies present required to connect to a database of brand X.
*/
@Testcontainers(disabledWithoutDocker = true)
public class VerifyDistributionIT {

@Container
static GenericContainer<?> java8Container = new GenericContainer<>(
DockerImageName.parse("eclipse-temurin:8"))
.withCommand("sh", "-c", "tail -f /dev/null")
.withFileSystemBind(Paths.get("../dist").toAbsolutePath().toString(), "/app");

@BeforeAll
public static void beforeAll() {
try {
java8Container.start();
} catch (ContainerLaunchException | TimeoutException e) {
String logs = java8Container.getLogs();
System.out.println(logs);
}
}

@AfterAll
public static void afterAll() {
java8Container.stop();
}

@Test
public void testContainerSetup() throws IOException, InterruptedException {
ExecResult execResult = java8Container.execInContainer("sh", "-c", "java -version");
assertNotNull(execResult);
assertTrue(execResult.getStderr().startsWith("openjdk version \"1.8.0_"));
execResult = java8Container.execInContainer("sh", "-c", "ls /app");
// please note: the test below verifies that the distribution had been generated
// this works
assertTrue(execResult.getStdout().contains("repo"));
}
}

0 comments on commit f26d572

Please sign in to comment.