Skip to content

Commit

Permalink
testcontainers for engine tests #131
Browse files Browse the repository at this point in the history
  • Loading branch information
isuru89 committed Apr 21, 2024
1 parent a3eae2a commit fb35c67
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 4 deletions.
20 changes: 20 additions & 0 deletions engine/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,26 @@
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>testcontainers</artifactId>
<version>${testcontainers.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.redis.testcontainers</groupId>
<artifactId>testcontainers-redis</artifactId>
<version>1.6.4</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>junit-jupiter</artifactId>
<version>${testcontainers.version}</version>
<scope>test</scope>
</dependency>


<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
Expand Down
13 changes: 12 additions & 1 deletion engine/src/test/java/io/github/oasis/engine/MultiEngineTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
package io.github.oasis.engine;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.redis.testcontainers.RedisContainer;
import io.github.oasis.core.configs.OasisConfigs;
import io.github.oasis.core.exception.OasisException;
import io.github.oasis.core.external.Db;
Expand All @@ -38,15 +39,23 @@
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.testcontainers.junit.jupiter.Container;
import org.testcontainers.junit.jupiter.Testcontainers;
import org.testcontainers.utility.DockerImageName;

import java.io.IOException;
import java.util.Map;
import java.util.concurrent.ExecutionException;

/**
* @author Isuru Weerarathna
*/
@Testcontainers
public class MultiEngineTest {

@Container
protected static final RedisContainer REDIS_CONTAINER = new RedisContainer(DockerImageName.parse("redis:5"));

protected final ObjectMapper mapper = new ObjectMapper();

protected Db dbPool;
Expand All @@ -59,7 +68,9 @@ public void beforeEach() {

@Test
public void testMultipleEngines() throws OasisException, IOException, ExecutionException, InterruptedException {
OasisConfigs oasisConfigs = new OasisConfigs.Builder().buildFromYamlResource("test-defaults.yml");
OasisConfigs oasisConfigs = new OasisConfigs.Builder()
.withCustomEnvOverrides(Map.of("O_OASIS_REDIS_URL", REDIS_CONTAINER.getRedisURI()))
.buildFromYamlResource("test-defaults.yml");
dbPool = RedisDb.create(oasisConfigs, "oasis.redis");
dbPool.init();

Expand Down
13 changes: 12 additions & 1 deletion engine/src/test/java/io/github/oasis/engine/OasisEngineTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
import com.redis.testcontainers.RedisContainer;
import io.github.oasis.core.configs.OasisConfigs;
import io.github.oasis.core.elements.AbstractRule;
import io.github.oasis.core.elements.ElementDef;
Expand Down Expand Up @@ -55,6 +56,9 @@
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.testcontainers.junit.jupiter.Container;
import org.testcontainers.junit.jupiter.Testcontainers;
import org.testcontainers.utility.DockerImageName;

import java.io.IOException;
import java.nio.charset.StandardCharsets;
Expand All @@ -63,12 +67,17 @@
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
* @author Isuru Weerarathna
*/
@Testcontainers
public class OasisEngineTest {

@Container
protected static final RedisContainer REDIS_CONTAINER = new RedisContainer(DockerImageName.parse("redis:5"));

static final DateTimeFormatter FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm");

protected final ObjectMapper mapper = new ObjectMapper();
Expand Down Expand Up @@ -101,7 +110,9 @@ public void setup() throws IOException, OasisException {
var jsonSerializer = new JsonSerializer(mapper);

EngineContext.Builder builder = EngineContext.builder();
OasisConfigs oasisConfigs = new OasisConfigs.Builder().buildFromYamlResource("test-defaults.yml");
OasisConfigs oasisConfigs = new OasisConfigs.Builder()
.withCustomEnvOverrides(Map.of("O_OASIS_REDIS_URL", REDIS_CONTAINER.getRedisURI()))
.buildFromYamlResource("test-defaults.yml");
dbPool = RedisDb.create(oasisConfigs, "oasis.redis");
dbPool.init();

Expand Down
3 changes: 1 addition & 2 deletions engine/src/test/resources/test-defaults.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ oasis:
impl: "io.github.oasis.engine.TestEventStreamFactory"

redis:
host: localhost
port: 6379
url: redis://localhost:6379

pool:
max: 128
Expand Down

0 comments on commit fb35c67

Please sign in to comment.