Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
34 changes: 34 additions & 0 deletions compose-test-deps.yml
Original file line number Diff line number Diff line change
@@ -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
62 changes: 3 additions & 59 deletions src/test/java/uk/ac/cam/cl/dtg/isaac/api/IsaacIntegrationTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,20 +33,14 @@
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;
import java.util.Map;
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;
Expand Down Expand Up @@ -127,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<String, String> globalTokens;
protected static PostgresSqlDb postgresSqlDb;
Expand All @@ -152,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;
Expand All @@ -167,57 +160,13 @@ public abstract class IsaacIntegrationTest {
protected static PgAnonymousUsers pgAnonymousUsers;
protected static ContentMapperUtils contentMapperUtils;

protected static CompetitionEntryService competitionEntryService;

// Services
protected static AssignmentService assignmentService;

@BeforeAll
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")
.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"
Expand All @@ -226,7 +175,7 @@ public static void setUpClass() {
elasticSearchProvider =
new ElasticSearchProvider(ElasticSearchProvider.getClient(
"localhost",
elasticsearch.getMappedPort(9200),
9200,
"elastic",
"elastic"
)
Expand Down Expand Up @@ -378,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,
Expand Down
Loading