RedissonShardedTopicTest should use docker container

pull/4773/head
Nikita Koksharov 2 years ago
parent 4c8c792ccb
commit 4f0258f2b6

@ -172,6 +172,13 @@
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>testcontainers-bom</artifactId>
<version>1.17.6</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-bom</artifactId>

@ -126,6 +126,11 @@
<artifactId>logback-classic</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>junit-jupiter</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>

@ -7,6 +7,10 @@ import org.redisson.api.RTopic;
import org.redisson.api.RedissonClient;
import org.redisson.config.Config;
import org.redisson.connection.balancer.RandomLoadBalancer;
import org.testcontainers.containers.FixedHostPortGenericContainer;
import org.testcontainers.containers.startupcheck.MinimumDurationRunningStartupCheckStrategy;
import org.testcontainers.junit.jupiter.Container;
import org.testcontainers.junit.jupiter.Testcontainers;
import java.time.Duration;
import java.util.HashMap;
@ -15,19 +19,34 @@ import java.util.concurrent.atomic.AtomicInteger;
import static org.assertj.core.api.Assertions.assertThat;
@Testcontainers
public class RedissonShardedTopicTest {
@Container
private final FixedHostPortGenericContainer<?> redisClusterContainer =
new FixedHostPortGenericContainer<>("vishnunair/docker-redis-cluster")
.withFixedExposedPort(5000, 6379)
.withFixedExposedPort(5001, 6380)
.withFixedExposedPort(5002, 6381)
.withFixedExposedPort(5003, 6382)
.withFixedExposedPort(5004, 6383)
.withFixedExposedPort(5005, 6384)
.withStartupCheckStrategy(
new MinimumDurationRunningStartupCheckStrategy(Duration.ofSeconds(6))
);
@Test
public void testClusterSharding() {
Config config = new Config();
HostPortNatMapper m = new HostPortNatMapper();
Map<String, String> mm = new HashMap<>();
mm.put("172.17.0.2:6380", "127.0.0.1:5001");
mm.put("172.17.0.2:6382", "127.0.0.1:5003");
mm.put("172.17.0.2:6379", "127.0.0.1:5000");
mm.put("172.17.0.2:6383", "127.0.0.1:5004");
mm.put("172.17.0.2:6384", "127.0.0.1:5005");
mm.put("172.17.0.2:6381", "127.0.0.1:5002");
String ip = redisClusterContainer.getCurrentContainerInfo().getNetworkSettings().getIpAddress();
mm.put(ip + ":6380", "127.0.0.1:5001");
mm.put(ip + ":6382", "127.0.0.1:5003");
mm.put(ip + ":6379", "127.0.0.1:5000");
mm.put(ip + ":6383", "127.0.0.1:5004");
mm.put(ip + ":6384", "127.0.0.1:5005");
mm.put(ip + ":6381", "127.0.0.1:5002");
m.setHostsPortMap(mm);
config.useClusterServers()
.setPingConnectionInterval(0)
@ -60,6 +79,7 @@ public class RedissonShardedTopicTest {
}
redisson.shutdown();
}

Loading…
Cancel
Save