From 24ec5db3d9154ffa093d3fdb9463329ad2b19528 Mon Sep 17 00:00:00 2001 From: Marius Date: Thu, 14 May 2026 13:54:00 +0300 Subject: [PATCH 1/5] Fix container tests --- compose-local-deps.yml | 4 ++-- .../java/uk/ac/cam/cl/dtg/isaac/api/IsaacIntegrationTest.java | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/compose-local-deps.yml b/compose-local-deps.yml index d126100761..8ed3ee7413 100644 --- a/compose-local-deps.yml +++ b/compose-local-deps.yml @@ -14,7 +14,7 @@ services: elasticsearch: network_mode: bridge container_name: elasticsearch - image: docker.elastic.co/elasticsearch/elasticsearch:7.17.6 + image: docker.elastic.co/elasticsearch/elasticsearch:8.13.0 environment: - cluster.name=isaac - "network.host=0.0.0.0" @@ -32,7 +32,7 @@ services: cs-elasticsearch: network_mode: bridge container_name: cs-elasticsearch - image: docker.elastic.co/elasticsearch/elasticsearch:7.17.6 + image: docker.elastic.co/elasticsearch/elasticsearch:8.13.0 environment: - cluster.name=cs-isaac - "network.host=0.0.0.0" diff --git a/src/test/java/uk/ac/cam/cl/dtg/isaac/api/IsaacIntegrationTest.java b/src/test/java/uk/ac/cam/cl/dtg/isaac/api/IsaacIntegrationTest.java index e96b55b9eb..3064a00485 100644 --- a/src/test/java/uk/ac/cam/cl/dtg/isaac/api/IsaacIntegrationTest.java +++ b/src/test/java/uk/ac/cam/cl/dtg/isaac/api/IsaacIntegrationTest.java @@ -195,7 +195,7 @@ public static void setUpClass() { ); elasticsearch = new ElasticsearchContainer( - DockerImageName.parse("docker.elastic.co/elasticsearch/elasticsearch:7.17.6")) + DockerImageName.parse("docker.elastic.co/elasticsearch/elasticsearch:8.13.0")) .withCopyFileToContainer( MountableFile.forClasspathResource("isaac-test-es-data.tar.gz"), "/usr/share/elasticsearch/isaac-test-es-data.tar.gz" @@ -211,6 +211,7 @@ public static void setUpClass() { .withEnv("xpack.security.enabled", "true") .withEnv("ELASTIC_PASSWORD", "elastic") .withEnv("ingest.geoip.downloader.enabled", "false") + .withEnv("ES_JAVA_OPTS", "-Dcom.sun.management.jmxremote=false -XX:+IgnoreUnrecognizedVMOptions") .withStartupTimeout(Duration.ofSeconds(120)); postgres.start(); From f2922ef0ad6ec4a797cb7c126f85bcfceb593926 Mon Sep 17 00:00:00 2001 From: Marius Date: Thu, 14 May 2026 14:58:47 +0300 Subject: [PATCH 2/5] Fix container tests --- compose-local-deps.yml | 4 ++-- .../uk/ac/cam/cl/dtg/isaac/api/IsaacIntegrationTest.java | 5 +++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/compose-local-deps.yml b/compose-local-deps.yml index 8ed3ee7413..d126100761 100644 --- a/compose-local-deps.yml +++ b/compose-local-deps.yml @@ -14,7 +14,7 @@ services: elasticsearch: network_mode: bridge container_name: elasticsearch - image: docker.elastic.co/elasticsearch/elasticsearch:8.13.0 + image: docker.elastic.co/elasticsearch/elasticsearch:7.17.6 environment: - cluster.name=isaac - "network.host=0.0.0.0" @@ -32,7 +32,7 @@ services: cs-elasticsearch: network_mode: bridge container_name: cs-elasticsearch - image: docker.elastic.co/elasticsearch/elasticsearch:8.13.0 + image: docker.elastic.co/elasticsearch/elasticsearch:7.17.6 environment: - cluster.name=cs-isaac - "network.host=0.0.0.0" diff --git a/src/test/java/uk/ac/cam/cl/dtg/isaac/api/IsaacIntegrationTest.java b/src/test/java/uk/ac/cam/cl/dtg/isaac/api/IsaacIntegrationTest.java index 3064a00485..f762e70fd9 100644 --- a/src/test/java/uk/ac/cam/cl/dtg/isaac/api/IsaacIntegrationTest.java +++ b/src/test/java/uk/ac/cam/cl/dtg/isaac/api/IsaacIntegrationTest.java @@ -195,7 +195,7 @@ public static void setUpClass() { ); elasticsearch = new ElasticsearchContainer( - DockerImageName.parse("docker.elastic.co/elasticsearch/elasticsearch:8.13.0")) + DockerImageName.parse("docker.elastic.co/elasticsearch/elasticsearch:7.17.6")) .withCopyFileToContainer( MountableFile.forClasspathResource("isaac-test-es-data.tar.gz"), "/usr/share/elasticsearch/isaac-test-es-data.tar.gz" @@ -211,7 +211,8 @@ public static void setUpClass() { .withEnv("xpack.security.enabled", "true") .withEnv("ELASTIC_PASSWORD", "elastic") .withEnv("ingest.geoip.downloader.enabled", "false") - .withEnv("ES_JAVA_OPTS", "-Dcom.sun.management.jmxremote=false -XX:+IgnoreUnrecognizedVMOptions") + .withEnv("ES_JAVA_OPTS", "-XX:+IgnoreUnrecognizedVMOptions -XX:-UseCGroupMemoryLimitForHeap -Djdk.internal.platform.cgroups.enabled=false") + .withEnv("JAVA_TOOL_OPTIONS", "-Dcom.sun.management.jmxremote=false") .withStartupTimeout(Duration.ofSeconds(120)); postgres.start(); From 357fed54ee1cdb7df3beef9cd8769b6782741c8f Mon Sep 17 00:00:00 2001 From: Marius Date: Fri, 15 May 2026 09:50:31 +0300 Subject: [PATCH 3/5] Revert IsaacIntegrationTest to use withFileSystemBind instead of withCopyFileToContainer Restores the original approach used before commit faac45a3c0 which changed PostgreSQL database script mounting from withFileSystemBind to withCopyFileToContainer. This reverts to the simpler file system binding approach. --- .../dtg/isaac/api/IsaacIntegrationTest.java | 69 ++++++++----------- 1 file changed, 29 insertions(+), 40 deletions(-) diff --git a/src/test/java/uk/ac/cam/cl/dtg/isaac/api/IsaacIntegrationTest.java b/src/test/java/uk/ac/cam/cl/dtg/isaac/api/IsaacIntegrationTest.java index f762e70fd9..03be5b6c84 100644 --- a/src/test/java/uk/ac/cam/cl/dtg/isaac/api/IsaacIntegrationTest.java +++ b/src/test/java/uk/ac/cam/cl/dtg/isaac/api/IsaacIntegrationTest.java @@ -56,7 +56,6 @@ import uk.ac.cam.cl.dtg.isaac.api.managers.QuizQuestionManager; import uk.ac.cam.cl.dtg.isaac.api.managers.URIManager; import uk.ac.cam.cl.dtg.isaac.api.services.AssignmentService; -import uk.ac.cam.cl.dtg.isaac.api.services.CompetitionEntryService; import uk.ac.cam.cl.dtg.isaac.api.services.ContentSummarizerService; import uk.ac.cam.cl.dtg.isaac.api.services.EmailService; import uk.ac.cam.cl.dtg.isaac.dao.EventBookingPersistenceManager; @@ -167,8 +166,6 @@ public abstract class IsaacIntegrationTest { protected static PgAnonymousUsers pgAnonymousUsers; protected static ContentMapperUtils contentMapperUtils; - protected static CompetitionEntryService competitionEntryService; - // Services protected static AssignmentService assignmentService; @@ -177,43 +174,35 @@ public static void setUpClass() { postgres = new PostgreSQLContainer<>("postgres:14-alpine") .withEnv("POSTGRES_HOST_AUTH_METHOD", "trust") .withUsername("rutherford") - .withCopyFileToContainer( - MountableFile.forClasspathResource("db_scripts/postgres-rutherford-create-script.sql"), - "/docker-entrypoint-initdb.d/00-isaac-create.sql" - ) - .withCopyFileToContainer( - MountableFile.forClasspathResource("db_scripts/postgres-rutherford-functions.sql"), - "/docker-entrypoint-initdb.d/01-isaac-functions.sql" - ) - .withCopyFileToContainer( - MountableFile.forClasspathResource("db_scripts/quartz_scheduler_create_script.sql"), - "/docker-entrypoint-initdb.d/02-isaac-quartz.sql" - ) - .withCopyFileToContainer( - MountableFile.forClasspathResource("test-postgres-rutherford-data-dump.sql"), - "/docker-entrypoint-initdb.d/03-data-dump.sql" - ); - - elasticsearch = new ElasticsearchContainer( - DockerImageName.parse("docker.elastic.co/elasticsearch/elasticsearch:7.17.6")) - .withCopyFileToContainer( - MountableFile.forClasspathResource("isaac-test-es-data.tar.gz"), - "/usr/share/elasticsearch/isaac-test-es-data.tar.gz" - ) - .withCopyFileToContainer( - MountableFile.forClasspathResource("isaac-test-es-docker-entrypoint.sh", 0100775), - "/usr/local/bin/docker-entrypoint.sh" - ) - .withExposedPorts(9200, 9300) - .withEnv("cluster.name", "isaac") - .withEnv("node.name", "localhost") - .withEnv("http.max_content_length", "512mb") - .withEnv("xpack.security.enabled", "true") - .withEnv("ELASTIC_PASSWORD", "elastic") - .withEnv("ingest.geoip.downloader.enabled", "false") - .withEnv("ES_JAVA_OPTS", "-XX:+IgnoreUnrecognizedVMOptions -XX:-UseCGroupMemoryLimitForHeap -Djdk.internal.platform.cgroups.enabled=false") - .withEnv("JAVA_TOOL_OPTIONS", "-Dcom.sun.management.jmxremote=false") - .withStartupTimeout(Duration.ofSeconds(120)); + .withFileSystemBind( + IsaacIntegrationTest.class.getClassLoader().getResource("db_scripts/postgres-rutherford-create-script.sql") + .getPath(), "/docker-entrypoint-initdb.d/00-isaac-create.sql") + .withFileSystemBind( + IsaacIntegrationTest.class.getClassLoader().getResource("db_scripts/postgres-rutherford-functions.sql") + .getPath(), "/docker-entrypoint-initdb.d/01-isaac-functions.sql") + .withFileSystemBind( + IsaacIntegrationTest.class.getClassLoader().getResource("db_scripts/quartz_scheduler_create_script.sql") + .getPath(), "/docker-entrypoint-initdb.d/02-isaac-quartz.sql") + .withFileSystemBind( + IsaacIntegrationTest.class.getClassLoader().getResource("test-postgres-rutherford-data-dump.sql").getPath(), + "/docker-entrypoint-initdb.d/03-data-dump.sql") + ; + + // TODO It would be nice if we could pull the version from pom.xml + elasticsearch = + new ElasticsearchContainer(DockerImageName.parse("docker.elastic.co/elasticsearch/elasticsearch:7.17.6")) + .withCopyFileToContainer(MountableFile.forClasspathResource("isaac-test-es-data.tar.gz"), + "/usr/share/elasticsearch/isaac-test-es-data.tar.gz") + .withCopyFileToContainer(MountableFile.forClasspathResource("isaac-test-es-docker-entrypoint.sh", 0100775), + "/usr/local/bin/docker-entrypoint.sh") + .withExposedPorts(9200, 9300) + .withEnv("cluster.name", "isaac") + .withEnv("node.name", "localhost") + .withEnv("http.max_content_length", "512mb") + .withEnv("xpack.security.enabled", "true") + .withEnv("ELASTIC_PASSWORD", "elastic") + .withEnv("ingest.geoip.downloader.enabled", "false") + .withStartupTimeout(Duration.ofSeconds(120)); postgres.start(); elasticsearch.start(); From c775a6064ba2cba48bbb14538c06695b5497c022 Mon Sep 17 00:00:00 2001 From: Marius Date: Fri, 15 May 2026 16:08:49 +0300 Subject: [PATCH 4/5] Fix container tests --- .github/workflows/test.yml | 14 +++++ .../dtg/isaac/api/IsaacIntegrationTest.java | 55 ++----------------- 2 files changed, 18 insertions(+), 51 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 1a9238ef2d..a4a7af360b 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -25,6 +25,20 @@ jobs: ${{ runner.os }}-maven- - name: Fetch ES data run: wget -O src/test/resources/isaac-test-es-data.tar.gz https://cdn.isaaccomputerscience.org/isaac/test/isaac-test-es-data.tar.gz + - name: Start test containers + run: docker compose -f compose-test-deps.yml up -d + - name: Wait for PostgreSQL to be ready + run: | + until docker compose -f compose-test-deps.yml exec -T postgres pg_isready -U rutherford; do + echo "Waiting for PostgreSQL..." + sleep 2 + done + - name: Wait for Elasticsearch to be ready + run: | + until curl -s -u elastic:elastic http://localhost:9200/_cluster/health | grep -q '"status"'; do + echo "Waiting for Elasticsearch..." + sleep 2 + done - name: Build with Maven run: mvn -B package -DskipTests --file pom.xml - name: Test with Maven diff --git a/src/test/java/uk/ac/cam/cl/dtg/isaac/api/IsaacIntegrationTest.java b/src/test/java/uk/ac/cam/cl/dtg/isaac/api/IsaacIntegrationTest.java index 03be5b6c84..a6ccb1f833 100644 --- a/src/test/java/uk/ac/cam/cl/dtg/isaac/api/IsaacIntegrationTest.java +++ b/src/test/java/uk/ac/cam/cl/dtg/isaac/api/IsaacIntegrationTest.java @@ -33,7 +33,6 @@ import java.net.UnknownHostException; import java.security.NoSuchAlgorithmException; import java.security.spec.InvalidKeySpecException; -import java.time.Duration; import java.time.Instant; import java.time.format.DateTimeFormatter; import java.util.HashMap; @@ -41,12 +40,7 @@ import org.apache.commons.lang3.SystemUtils; import org.easymock.Capture; import org.eclipse.jgit.api.Git; -import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; -import org.testcontainers.containers.PostgreSQLContainer; -import org.testcontainers.elasticsearch.ElasticsearchContainer; -import org.testcontainers.utility.DockerImageName; -import org.testcontainers.utility.MountableFile; import uk.ac.cam.cl.dtg.isaac.api.managers.AssignmentManager; import uk.ac.cam.cl.dtg.isaac.api.managers.EventBookingManager; import uk.ac.cam.cl.dtg.isaac.api.managers.GameManager; @@ -56,6 +50,7 @@ import uk.ac.cam.cl.dtg.isaac.api.managers.QuizQuestionManager; import uk.ac.cam.cl.dtg.isaac.api.managers.URIManager; import uk.ac.cam.cl.dtg.isaac.api.services.AssignmentService; +import uk.ac.cam.cl.dtg.isaac.api.services.CompetitionEntryService; import uk.ac.cam.cl.dtg.isaac.api.services.ContentSummarizerService; import uk.ac.cam.cl.dtg.isaac.api.services.EmailService; import uk.ac.cam.cl.dtg.isaac.dao.EventBookingPersistenceManager; @@ -126,8 +121,6 @@ public abstract class IsaacIntegrationTest { protected static HttpSession httpSession; - protected static PostgreSQLContainer postgres; - protected static ElasticsearchContainer elasticsearch; protected static PropertiesLoader properties; protected static Map globalTokens; protected static PostgresSqlDb postgresSqlDb; @@ -151,6 +144,7 @@ public abstract class IsaacIntegrationTest { protected static GitContentManager contentManager; protected static UserBadgeManager userBadgeManager; protected static UserAssociationManager userAssociationManager; + protected static CompetitionEntryService competitionEntryService; protected static AssignmentManager assignmentManager; protected static QuestionManager questionManager; protected static QuizManager quizManager; @@ -171,44 +165,8 @@ public abstract class IsaacIntegrationTest { @BeforeAll public static void setUpClass() { - postgres = new PostgreSQLContainer<>("postgres:14-alpine") - .withEnv("POSTGRES_HOST_AUTH_METHOD", "trust") - .withUsername("rutherford") - .withFileSystemBind( - IsaacIntegrationTest.class.getClassLoader().getResource("db_scripts/postgres-rutherford-create-script.sql") - .getPath(), "/docker-entrypoint-initdb.d/00-isaac-create.sql") - .withFileSystemBind( - IsaacIntegrationTest.class.getClassLoader().getResource("db_scripts/postgres-rutherford-functions.sql") - .getPath(), "/docker-entrypoint-initdb.d/01-isaac-functions.sql") - .withFileSystemBind( - IsaacIntegrationTest.class.getClassLoader().getResource("db_scripts/quartz_scheduler_create_script.sql") - .getPath(), "/docker-entrypoint-initdb.d/02-isaac-quartz.sql") - .withFileSystemBind( - IsaacIntegrationTest.class.getClassLoader().getResource("test-postgres-rutherford-data-dump.sql").getPath(), - "/docker-entrypoint-initdb.d/03-data-dump.sql") - ; - - // TODO It would be nice if we could pull the version from pom.xml - elasticsearch = - new ElasticsearchContainer(DockerImageName.parse("docker.elastic.co/elasticsearch/elasticsearch:7.17.6")) - .withCopyFileToContainer(MountableFile.forClasspathResource("isaac-test-es-data.tar.gz"), - "/usr/share/elasticsearch/isaac-test-es-data.tar.gz") - .withCopyFileToContainer(MountableFile.forClasspathResource("isaac-test-es-docker-entrypoint.sh", 0100775), - "/usr/local/bin/docker-entrypoint.sh") - .withExposedPorts(9200, 9300) - .withEnv("cluster.name", "isaac") - .withEnv("node.name", "localhost") - .withEnv("http.max_content_length", "512mb") - .withEnv("xpack.security.enabled", "true") - .withEnv("ELASTIC_PASSWORD", "elastic") - .withEnv("ingest.geoip.downloader.enabled", "false") - .withStartupTimeout(Duration.ofSeconds(120)); - - postgres.start(); - elasticsearch.start(); - postgresSqlDb = new PostgresSqlDb( - postgres.getJdbcUrl(), + "jdbc:postgresql://localhost:5432/rutherford", "rutherford", "somerandompassword" ); // user/pass are irrelevant because POSTGRES_HOST_AUTH_METHOD is set to "trust" @@ -217,7 +175,7 @@ public static void setUpClass() { elasticSearchProvider = new ElasticSearchProvider(ElasticSearchProvider.getClient( "localhost", - elasticsearch.getMappedPort(9200), + 9200, "elastic", "elastic" ) @@ -369,11 +327,6 @@ public static void setUpClass() { */ } - @AfterAll - static void tearDownClass() { - postgres.stop(); - elasticsearch.stop(); - } protected LoginResult loginAs(final HttpSession httpSession, final String username, final String password) throws NoCredentialsAvailableException, SegueDatabaseException, AuthenticationProviderMappingException, From a63de1f20d66d7b8d0023886fb9b64dad7a708f8 Mon Sep 17 00:00:00 2001 From: Marius Date: Mon, 18 May 2026 13:26:42 +0300 Subject: [PATCH 5/5] Fix container tests --- compose-test-deps.yml | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 compose-test-deps.yml diff --git a/compose-test-deps.yml b/compose-test-deps.yml new file mode 100644 index 0000000000..949cf08c73 --- /dev/null +++ b/compose-test-deps.yml @@ -0,0 +1,34 @@ +version: '2' + +services: + postgres: + image: postgres:14-alpine + environment: + POSTGRES_HOST_AUTH_METHOD: trust + POSTGRES_USER: rutherford + ports: + - "5432:5432" + volumes: + - ./src/test/resources/db_scripts/postgres-rutherford-create-script.sql:/docker-entrypoint-initdb.d/00-isaac-create.sql + - ./src/test/resources/db_scripts/postgres-rutherford-functions.sql:/docker-entrypoint-initdb.d/01-isaac-functions.sql + - ./src/test/resources/db_scripts/quartz_scheduler_create_script.sql:/docker-entrypoint-initdb.d/02-isaac-quartz.sql + - ./src/test/resources/test-postgres-rutherford-data-dump.sql:/docker-entrypoint-initdb.d/03-data-dump.sql + + elasticsearch: + image: docker.elastic.co/elasticsearch/elasticsearch:7.17.6 + environment: + - cluster.name=isaac + - node.name=localhost + - http.max_content_length=512mb + - xpack.security.enabled=true + - ELASTIC_PASSWORD=elastic + - ingest.geoip.downloader.enabled=false + - ES_JAVA_OPTS=-XX:+IgnoreUnrecognizedVMOptions -XX:-UseCGroupMemoryLimitForHeap -Djdk.internal.platform.cgroups.enabled=false + - JAVA_TOOL_OPTIONS=-Dcom.sun.management.jmxremote=false + ports: + - "9200:9200" + - "9300:9300" + entrypoint: /usr/local/bin/docker-entrypoint.sh + volumes: + - ./src/test/resources/isaac-test-es-docker-entrypoint.sh:/usr/local/bin/docker-entrypoint.sh:ro + - ./src/test/resources/isaac-test-es-data.tar.gz:/usr/share/elasticsearch/isaac-test-es-data.tar.gz