-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
203 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,14 @@ | ||
FROM eclipse-temurin:21-jre-jammy | ||
COPY target/dependency /lib | ||
COPY target/classes /app | ||
WORKDIR /app | ||
ARG USERNAME=hazeuser | ||
ARG USER_UID=1000 | ||
ARG USER_GID=$USER_UID | ||
RUN groupadd --gid $USER_GID $USERNAME && \ | ||
useradd --uid $USER_UID --gid $USER_GID -m $USERNAME | ||
ADD https://repo1.maven.org/maven2/org/apache/logging/log4j/log4j-core/2.20.0/log4j-core-2.20.0.jar ./lib/ | ||
ADD https://repo1.maven.org/maven2/org/apache/logging/log4j/log4j-api/2.20.0/log4j-api-2.20.0.jar ./lib/ | ||
COPY target/classes . | ||
RUN chown --recursive $USERNAME:$USERNAME . | ||
USER $USERNAME | ||
EXPOSE 6379 | ||
ENTRYPOINT ["java","-cp" , "/app:/lib/*", "--enable-preview", "org.fungover.haze.Main"] | ||
ENTRYPOINT ["java","-cp","/app:/app/lib/*","org.fungover.haze.Main"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
src/test/java/org/fungover/haze/integration/HazeExtension.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package org.fungover.haze.integration; | ||
|
||
import org.junit.jupiter.api.extension.AfterAllCallback; | ||
import org.junit.jupiter.api.extension.BeforeAllCallback; | ||
import org.junit.jupiter.api.extension.BeforeEachCallback; | ||
import org.junit.jupiter.api.extension.ExtensionContext; | ||
import org.testcontainers.containers.GenericContainer; | ||
import org.testcontainers.images.builder.ImageFromDockerfile; | ||
import redis.clients.jedis.JedisPooled; | ||
|
||
import java.lang.reflect.Field; | ||
import java.nio.file.Path; | ||
import java.util.List; | ||
|
||
public class HazeExtension implements BeforeAllCallback, AfterAllCallback, BeforeEachCallback { | ||
|
||
private GenericContainer<?> haze; | ||
private JedisPooled pool; | ||
|
||
@Override | ||
public void beforeAll(ExtensionContext extensionContext) throws Exception { | ||
haze = new GenericContainer<>(new ImageFromDockerfile() | ||
.withDockerfile(Path.of("./Dockerfile"))) | ||
.withExposedPorts(6379); | ||
haze.start(); | ||
pool = new JedisPooled(haze.getHost(), haze.getFirstMappedPort()); | ||
} | ||
|
||
@Override | ||
public void afterAll(ExtensionContext context) { | ||
// do nothing, Testcontainers handles container shutdown | ||
if (pool != null) | ||
pool.close(); | ||
} | ||
|
||
@Override | ||
public void beforeEach(ExtensionContext extensionContext) throws Exception { | ||
|
||
// Get the list of test instances (instances of test classes) | ||
final List<Object> testInstances = | ||
extensionContext.getRequiredTestInstances().getAllInstances(); | ||
|
||
testInstances.forEach((ti) -> { | ||
for (Field field : ti.getClass().getDeclaredFields()) { | ||
if (field.isAnnotationPresent(Pool.class)) { | ||
try { | ||
field.set(ti, pool); | ||
} catch (IllegalAccessException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
} | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
package org.fungover.haze.integration; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import redis.clients.jedis.JedisPooled; | ||
import redis.clients.jedis.Protocol; | ||
import redis.clients.jedis.util.SafeEncoder; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
@ExtendWith(HazeExtension.class) | ||
class HazeIT { | ||
|
||
@Pool | ||
JedisPooled pool; | ||
|
||
@Test | ||
void pingPong() { | ||
//Simple PING command with no message should return PONG as simple string | ||
var result = pool.sendCommand(Protocol.Command.PING); | ||
assertThat(SafeEncoder.encode((byte[]) result)).isEqualTo("PONG"); | ||
//PING with message argument should return bulk string with the argument | ||
result = pool.sendCommand(Protocol.Command.PING, "HELLO"); | ||
assertThat(SafeEncoder.encode((byte[]) result)).isEqualTo("HELLO"); | ||
//PING with message argument containing space should return bulk string with the argument | ||
// result = pool.sendCommand(Protocol.Command.PING, "HELLO\r\n There"); | ||
// assertThat(SafeEncoder.encode((byte[]) result)).isEqualTo("HELLO\r\n There"); | ||
} | ||
|
||
@Test | ||
void setNx() { | ||
pool.del("test"); | ||
pool.del("test1"); | ||
assertThat(pool.setnx("test", "test")).isEqualTo(1); | ||
assertThat(pool.setnx("test1", "test")).isEqualTo(1); | ||
//Key test already exists so should not be set | ||
assertThat(pool.setnx("test", "test1")).isZero(); | ||
pool.del("test"); | ||
pool.del("test1"); | ||
} | ||
|
||
@Test | ||
void setGet() { | ||
assertThat(pool.set("test", "test")).isEqualTo("OK"); | ||
assertThat(pool.get("test")).isEqualTo("test"); | ||
pool.del("test"); | ||
} | ||
|
||
@Test | ||
void exists() { | ||
assertThat(pool.set("test", "test")).isEqualTo("OK"); | ||
assertThat(pool.exists("test")).isTrue(); | ||
pool.del("notused"); | ||
assertThat(pool.exists("notused")).isFalse(); | ||
} | ||
|
||
@Test | ||
void listLPushLPop() { | ||
assertThat(pool.lpush("left", "first")).isEqualTo(1); | ||
assertThat(pool.llen("left")).isEqualTo(1); | ||
assertThat(pool.lpop("left")).isEqualTo("first"); | ||
assertThat(pool.llen("left")).isZero(); | ||
pool.del("left"); | ||
assertThat(pool.exists("left")).isFalse(); | ||
} | ||
|
||
@Test | ||
void listRPushRPop() { | ||
assertThat(pool.rpush("right", "first")).isEqualTo(1); | ||
assertThat(pool.llen("right")).isEqualTo(1); | ||
assertThat(pool.rpop("right")).isEqualTo("first"); | ||
assertThat(pool.llen("right")).isZero(); | ||
pool.del("right"); | ||
assertThat(pool.exists("right")).isFalse(); | ||
} | ||
|
||
@Test | ||
void listKeyWithMultipleValues() { | ||
assertThat(pool.lpush("test", "first")).isEqualTo(1); | ||
assertThat(pool.lpush("test", "second")).isEqualTo(2); | ||
assertThat(pool.llen("test")).isEqualTo(2); | ||
assertThat(pool.lpush("test", "third", "fourth")).isEqualTo(4); | ||
assertThat(pool.llen("test")).isEqualTo(4); | ||
assertThat(pool.rpush("test", "fifth", "sixth")).isEqualTo(6); | ||
assertThat(pool.llen("test")).isEqualTo(6); | ||
|
||
pool.del("test"); | ||
assertThat(pool.exists("right")).isFalse(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package org.fungover.haze.integration; | ||
|
||
import java.lang.annotation.*; | ||
|
||
@Documented | ||
@Target(ElementType.FIELD) | ||
@Retention(RetentionPolicy.RUNTIME) | ||
public @interface Pool { | ||
} |