Skip to content

Commit 7523b8e

Browse files
author
jruaux
committed
test: Added example tests
1 parent f71d785 commit 7523b8e

File tree

2 files changed

+58
-0
lines changed

2 files changed

+58
-0
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package com.redis.testcontainers;
2+
3+
import org.junit.jupiter.api.Assertions;
4+
import org.junit.jupiter.api.Test;
5+
import org.testcontainers.junit.jupiter.Container;
6+
import org.testcontainers.junit.jupiter.Testcontainers;
7+
8+
import io.lettuce.core.RedisClient;
9+
import io.lettuce.core.api.StatefulRedisConnection;
10+
import io.lettuce.core.api.sync.RedisCommands;
11+
12+
@Testcontainers
13+
public class RedisExampleTest {
14+
15+
@Container
16+
private static RedisContainer redisContainer = new RedisContainer(
17+
RedisContainer.DEFAULT_IMAGE_NAME.withTag(RedisContainer.DEFAULT_TAG));
18+
19+
@Test
20+
void testSomethingUsingLettuce() {
21+
// Retrieve the Redis URI from the container
22+
String redisURI = redisContainer.getRedisURI();
23+
RedisClient client = RedisClient.create(redisURI);
24+
try (StatefulRedisConnection<String, String> connection = client.connect()) {
25+
RedisCommands<String, String> commands = connection.sync();
26+
Assertions.assertEquals("PONG", commands.ping());
27+
}
28+
}
29+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package com.redis.testcontainers;
2+
3+
import org.junit.jupiter.api.Assertions;
4+
import org.junit.jupiter.api.Test;
5+
import org.testcontainers.junit.jupiter.Container;
6+
import org.testcontainers.junit.jupiter.Testcontainers;
7+
8+
import com.redis.lettucemod.RedisModulesClient;
9+
import com.redis.lettucemod.api.StatefulRedisModulesConnection;
10+
import com.redis.lettucemod.api.sync.RedisModulesCommands;
11+
12+
@Testcontainers
13+
public class RedisStackExampleTest {
14+
15+
@Container
16+
private static RedisStackContainer redisContainer = new RedisStackContainer(
17+
RedisStackContainer.DEFAULT_IMAGE_NAME.withTag(RedisStackContainer.DEFAULT_TAG));
18+
19+
@Test
20+
void testSomethingUsingLettuce() {
21+
// Retrieve the Redis URI from the container
22+
String redisURI = redisContainer.getRedisURI();
23+
RedisModulesClient client = RedisModulesClient.create(redisURI);
24+
try (StatefulRedisModulesConnection<String, String> connection = client.connect()) {
25+
RedisModulesCommands<String, String> commands = connection.sync();
26+
Assertions.assertEquals("PONG", commands.ping());
27+
}
28+
}
29+
}

0 commit comments

Comments
 (0)