refactoring

pull/5676/head
Nikita Koksharov 1 year ago
parent 8acd3380aa
commit 2ed5c1226c

@ -117,10 +117,12 @@ public class RedisExecutor<V, R> {
return;
}
connectionManager.getServiceManager().addFuture(mainPromise);
mainPromise.whenComplete((r, e) -> {
connectionManager.getServiceManager().removeFuture(mainPromise);
});
if (getClass() == RedisExecutor.class) {
connectionManager.getServiceManager().addFuture(mainPromise);
mainPromise.whenComplete((r, e) -> {
connectionManager.getServiceManager().removeFuture(mainPromise);
});
}
if (connectionManager.getServiceManager().isShuttingDown()) {
free();

@ -490,7 +490,7 @@ public class MasterSlaveConnectionManager implements ConnectionManager {
@Override
public void shutdown() {
shutdown(2, 15, TimeUnit.SECONDS); //default netty value
shutdown(2, 10, TimeUnit.SECONDS); //default netty value
}
@Override
@ -505,7 +505,7 @@ public class MasterSlaveConnectionManager implements ConnectionManager {
serviceManager.getResolverGroup().close();
long startTime = System.nanoTime();
serviceManager.shutdownFutures(timeoutInNanos, TimeUnit.NANOSECONDS);
serviceManager.shutdownFutures(quietPeriod, unit);
timeoutInNanos = Math.max(0, timeoutInNanos - System.nanoTime() - startTime);
if (isInitialized()) {

@ -347,11 +347,10 @@ public final class ServiceManager {
CompletableFuture<Void> future = CompletableFuture.allOf(futures.toArray(new CompletableFuture[0]));
try {
future.get(timeout, unit);
} catch (InterruptedException | ExecutionException e) {
} catch (Exception e) {
// skip
} catch (TimeoutException e) {
futures.forEach(f -> f.completeExceptionally(new RedissonShutdownException("Redisson is shutdown")));
}
futures.forEach(f -> f.completeExceptionally(new RedissonShutdownException("Redisson is shutdown")));
futures.clear();
}

@ -16,7 +16,7 @@ public abstract class BaseReactiveTest extends RedisDockerTest {
protected static RedissonReactiveClient redisson;
@BeforeAll
public static void beforeClass() throws IOException, InterruptedException {
public static void beforeClass() {
redisson = RedisDockerTest.redisson.reactive();
}

@ -8,6 +8,7 @@ import org.junit.jupiter.api.BeforeEach;
import org.redisson.api.RedissonClient;
import org.redisson.config.Config;
@Deprecated
public abstract class BaseTest {
protected static RedissonClient redisson;

@ -18,6 +18,7 @@ import org.redisson.misc.BiHashMap;
*
* @author Rui Gu (https://github.com/jackygurui)
*/
@Deprecated
public class ClusterRunner {
private final LinkedHashMap<RedisRunner, String> nodes = new LinkedHashMap<>();

@ -58,26 +58,23 @@ public class RedisDockerTest {
.withExposedPorts(6379);
}
@BeforeAll
public static void beforeAll() {
if (redisson == null) {
REDIS.start();
Config config = createConfig();
redisson = Redisson.create(config);
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
redisson.shutdown();
REDIS.stop();
if (redissonCluster != null) {
redissonCluster.shutdown();
redissonCluster = null;
}
if (REDIS_CLUSTER != null) {
REDIS_CLUSTER.stop();
REDIS_CLUSTER = null;
}
}));
}
static {
REDIS.start();
Config config = createConfig();
redisson = Redisson.create(config);
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
redisson.shutdown();
REDIS.stop();
if (redissonCluster != null) {
redissonCluster.shutdown();
redissonCluster = null;
}
if (REDIS_CLUSTER != null) {
REDIS_CLUSTER.stop();
REDIS_CLUSTER = null;
}
}));
}
protected static Config createConfig() {
@ -92,7 +89,7 @@ public class RedisDockerTest {
return config;
}
protected static RedissonClient createInstance() {
public static RedissonClient createInstance() {
Config config = createConfig();
return Redisson.create(config);
}
@ -289,7 +286,152 @@ public class RedisDockerTest {
Map<String, ContainerNetwork> ss = node.getContainerInfo().getNetworkSettings().getNetworks();
ContainerNetwork s = ss.values().iterator().next();
if (uri.getPort() == 6379 && node.getNetworkAliases().contains("slave0")) {
if (uri.getPort() == 6379
&& !uri.getHost().equals("redis")
&& RedisDockerTest.this.getClass() == RedissonTopicTest.class
&& node.getNetworkAliases().contains("slave0")) {
return new RedisURI(uri.getScheme(), "127.0.0.1", Integer.valueOf(mappedPort[0].getHostPortSpec()));
}
if (mappedPort != null
&& s.getIpAddress().equals(uri.getHost())) {
return new RedisURI(uri.getScheme(), "127.0.0.1", Integer.valueOf(mappedPort[0].getHostPortSpec()));
}
}
return uri;
}
})
.addSentinelAddress("redis://127.0.0.1:" + sentinel1.getFirstMappedPort())
.setMasterName("mymaster");
callback.accept(nodes, config);
nodes.forEach(n -> n.stop());
network.close();
}
protected void withSentinel(BiConsumer<List<GenericContainer<?>>, Config> callback, int slaves, String password) throws InterruptedException {
Network network = Network.newNetwork();
List<GenericContainer<? extends GenericContainer<?>>> nodes = new ArrayList<>();
GenericContainer<?> master =
new GenericContainer<>("bitnami/redis:7.2.4")
.withNetwork(network)
.withEnv("REDIS_REPLICATION_MODE", "master")
.withEnv("REDIS_PASSWORD", password)
.withNetworkAliases("redis")
.withExposedPorts(6379);
master.start();
assert master.getNetwork() == network;
int masterPort = master.getFirstMappedPort();
master.withCreateContainerCmdModifier(cmd -> {
cmd.getHostConfig().withPortBindings(
new PortBinding(Ports.Binding.bindPort(Integer.valueOf(masterPort)),
cmd.getExposedPorts()[0]));
});
nodes.add(master);
for (int i = 0; i < slaves; i++) {
GenericContainer<?> slave =
new GenericContainer<>("bitnami/redis:7.2.4")
.withNetwork(network)
.withEnv("REDIS_REPLICATION_MODE", "slave")
.withEnv("REDIS_MASTER_HOST", "redis")
.withEnv("REDIS_PASSWORD", password)
.withEnv("REDIS_MASTER_PASSWORD", password)
.withNetworkAliases("slave" + i)
.withExposedPorts(6379);
slave.start();
int slavePort = slave.getFirstMappedPort();
slave.withCreateContainerCmdModifier(cmd -> {
cmd.getHostConfig().withPortBindings(
new PortBinding(Ports.Binding.bindPort(Integer.valueOf(slavePort)),
cmd.getExposedPorts()[0]));
});
nodes.add(slave);
}
GenericContainer<?> sentinel1 =
new GenericContainer<>("bitnami/redis-sentinel:7.2.4")
.withNetwork(network)
.withEnv("REDIS_SENTINEL_DOWN_AFTER_MILLISECONDS", "5000")
.withEnv("REDIS_SENTINEL_FAILOVER_TIMEOUT", "10000")
.withEnv("REDIS_SENTINEL_PASSWORD", password)
.withEnv("REDIS_MASTER_PASSWORD", password)
.withNetworkAliases("sentinel1")
.withExposedPorts(26379);
sentinel1.start();
int sentinel1Port = sentinel1.getFirstMappedPort();
sentinel1.withCreateContainerCmdModifier(cmd -> {
cmd.getHostConfig().withPortBindings(
new PortBinding(Ports.Binding.bindPort(Integer.valueOf(sentinel1Port)),
cmd.getExposedPorts()[0]));
});
nodes.add(sentinel1);
GenericContainer<?> sentinel2 =
new GenericContainer<>("bitnami/redis-sentinel:7.2.4")
.withNetwork(network)
.withEnv("REDIS_SENTINEL_DOWN_AFTER_MILLISECONDS", "5000")
.withEnv("REDIS_SENTINEL_FAILOVER_TIMEOUT", "10000")
.withEnv("REDIS_SENTINEL_PASSWORD", password)
.withEnv("REDIS_MASTER_PASSWORD", password)
.withNetworkAliases("sentinel2")
.withExposedPorts(26379);
sentinel2.start();
int sentinel2Port = sentinel2.getFirstMappedPort();
sentinel2.withCreateContainerCmdModifier(cmd -> {
cmd.getHostConfig().withPortBindings(
new PortBinding(Ports.Binding.bindPort(Integer.valueOf(sentinel2Port)),
cmd.getExposedPorts()[0]));
});
nodes.add(sentinel2);
GenericContainer<?> sentinel3 =
new GenericContainer<>("bitnami/redis-sentinel:7.2.4")
.withNetwork(network)
.withEnv("REDIS_SENTINEL_DOWN_AFTER_MILLISECONDS", "5000")
.withEnv("REDIS_SENTINEL_FAILOVER_TIMEOUT", "10000")
.withEnv("REDIS_SENTINEL_PASSWORD", password)
.withEnv("REDIS_MASTER_PASSWORD", password)
.withNetworkAliases("sentinel3")
.withExposedPorts(26379);
sentinel3.start();
int sentinel3Port = sentinel3.getFirstMappedPort();
sentinel3.withCreateContainerCmdModifier(cmd -> {
cmd.getHostConfig().withPortBindings(
new PortBinding(Ports.Binding.bindPort(Integer.valueOf(sentinel3Port)),
cmd.getExposedPorts()[0]));
});
nodes.add(sentinel3);
Thread.sleep(5000);
Config config = new Config();
config.setProtocol(protocol);
config.useSentinelServers()
.setPassword(password)
.setNatMapper(new NatMapper() {
@Override
public RedisURI map(RedisURI uri) {
for (GenericContainer<? extends GenericContainer<?>> node : nodes) {
if (node.getContainerInfo() == null) {
continue;
}
Ports.Binding[] mappedPort = node.getContainerInfo().getNetworkSettings()
.getPorts().getBindings().get(new ExposedPort(uri.getPort()));
Map<String, ContainerNetwork> ss = node.getContainerInfo().getNetworkSettings().getNetworks();
ContainerNetwork s = ss.values().iterator().next();
if (uri.getPort() == 6379
&& !uri.getHost().equals("redis")
&& RedisDockerTest.this.getClass() == RedissonTopicTest.class
&& node.getNetworkAliases().contains("slave0")) {
return new RedisURI(uri.getScheme(), "127.0.0.1", Integer.valueOf(mappedPort[0].getHostPortSpec()));
}
@ -310,8 +452,8 @@ public class RedisDockerTest {
network.close();
}
List<ContainerState> nodes = new ArrayList<>();
protected void withNewCluster(Consumer<RedissonClient> callback) {
List<InspectContainerResponse> nodes = new ArrayList<>();
LogMessageWaitStrategy wait2 = new LogMessageWaitStrategy().withRegEx(".*REPLICA\ssync\\:\sFinished\swith\ssuccess.*");
@ -334,18 +476,26 @@ public class RedisDockerTest {
for (int i = 0; i < 6; i++) {
Optional<ContainerState> cc = environment.getContainerByServiceName("redis-node-" + i);
nodes.add(cc.get().getContainerInfo());
nodes.add(cc.get());
}
Optional<ContainerState> cc2 = environment.getContainerByServiceName("redis-node-0");
Ports.Binding[] mp = cc2.get().getContainerInfo().getNetworkSettings()
.getPorts().getBindings().get(new ExposedPort(cc2.get().getExposedPorts().get(0)));
Config config = new Config();
config.useClusterServers()
.setPingConnectionInterval(0)
.setNatMapper(new NatMapper() {
@Override
public RedisURI map(RedisURI uri) {
for (InspectContainerResponse node : nodes) {
for (ContainerState state : nodes) {
if (state.getContainerInfo() == null) {
continue;
}
InspectContainerResponse node = state.getContainerInfo();
Ports.Binding[] mappedPort = node.getNetworkSettings()
.getPorts().getBindings().get(new ExposedPort(uri.getPort()));
@ -360,13 +510,16 @@ public class RedisDockerTest {
return uri;
}
})
.addNodeAddress("redis://127.0.0.1:" + cc2.get().getFirstMappedPort());
.addNodeAddress("redis://127.0.0.1:" + mp[0].getHostPortSpec());
RedissonClient redisson = Redisson.create(config);
callback.accept(redisson);
redisson.shutdown();
environment.stop();
try {
callback.accept(redisson);
} finally {
redisson.shutdown();
environment.stop();
}
}
protected void restart(GenericContainer<?> redis) {

@ -32,6 +32,7 @@ import org.redisson.client.protocol.convertor.VoidReplayConvertor;
*
* @author Rui Gu (https://github.com/jackygurui)
*/
@Deprecated
public class RedisRunner {
public enum REDIS_OPTIONS {

@ -15,7 +15,6 @@ import org.redisson.client.RedisClient;
import org.redisson.client.RedisClientConfig;
import org.redisson.client.protocol.RedisCommands;
import org.redisson.config.Config;
import org.redisson.connection.balancer.RandomLoadBalancer;
import org.testcontainers.containers.GenericContainer;
import java.io.IOException;
@ -210,84 +209,52 @@ public class RedissonBlockingQueueTest extends RedissonQueueTest {
}
@Test
public void testTakeReattachSentinel() throws IOException, InterruptedException, TimeoutException, ExecutionException {
RedisRunner.RedisProcess master = new RedisRunner()
.nosave()
.randomDir()
.run();
RedisRunner.RedisProcess slave1 = new RedisRunner()
.port(6380)
.nosave()
.randomDir()
.slaveof("127.0.0.1", 6379)
.run();
RedisRunner.RedisProcess slave2 = new RedisRunner()
.port(6381)
.nosave()
.randomDir()
.slaveof("127.0.0.1", 6379)
.run();
RedisRunner.RedisProcess sentinel1 = new RedisRunner()
.nosave()
.randomDir()
.port(26379)
.sentinel()
.sentinelMonitor("myMaster", "127.0.0.1", 6379, 2)
.run();
RedisRunner.RedisProcess sentinel2 = new RedisRunner()
.nosave()
.randomDir()
.port(26380)
.sentinel()
.sentinelMonitor("myMaster", "127.0.0.1", 6379, 2)
.run();
RedisRunner.RedisProcess sentinel3 = new RedisRunner()
.nosave()
.randomDir()
.port(26381)
.sentinel()
.sentinelMonitor("myMaster", "127.0.0.1", 6379, 2)
.run();
public void testTakeReattachSentinel() throws InterruptedException {
withSentinel((nodes, config) -> {
RedissonClient redisson = Redisson.create(config);
Thread.sleep(1000);
Config config = new Config();
config.useSentinelServers()
.setLoadBalancer(new RandomLoadBalancer())
.addSentinelAddress(sentinel3.getRedisServerAddressAndPort()).setMasterName("myMaster");
RedissonClient redisson = Redisson.create(config);
RBlockingQueue<Integer> queue1 = getQueue(redisson);
RFuture<Integer> f = queue1.takeAsync();
try {
f.toCompletableFuture().get(1, TimeUnit.SECONDS);
} catch (ExecutionException | TimeoutException e) {
// skip
}
master.stop();
RBlockingQueue<Integer> queue1 = getQueue(redisson);
RFuture<Integer> f = queue1.takeAsync();
try {
f.toCompletableFuture().get(1, TimeUnit.SECONDS);
} catch (ExecutionException | TimeoutException | InterruptedException e) {
// skip
}
Thread.sleep(TimeUnit.SECONDS.toMillis(60));
nodes.get(0).stop();
queue1.put(123);
try {
Thread.sleep(TimeUnit.SECONDS.toMillis(30));
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
// check connection rotation
for (int i = 0; i < 10; i++) {
queue1.put(i + 10000);
}
assertThat(queue1.size()).isEqualTo(10);
try {
queue1.put(123);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
Integer result = f.get(80, TimeUnit.SECONDS);
assertThat(result).isEqualTo(123);
// check connection rotation
for (int i = 0; i < 10; i++) {
try {
queue1.put(i + 10000);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}
assertThat(queue1.size()).isEqualTo(10);
redisson.shutdown();
sentinel1.stop();
sentinel2.stop();
sentinel3.stop();
master.stop();
slave1.stop();
slave2.stop();
Integer result = null;
try {
result = f.get(80, TimeUnit.SECONDS);
} catch (Exception e) {
throw new RuntimeException(e);
}
assertThat(result).isEqualTo(123);
redisson.shutdown();
}, 2);
}
@Test
@ -473,8 +440,6 @@ public class RedissonBlockingQueueTest extends RedissonQueueTest {
@Test
public void testPollFirstFromAny() throws InterruptedException {
// Assumptions.assumeTrue(RedisRunner.getDefaultRedisServerInstance().getRedisVersion().compareTo("7.0.0") > 0);
RBlockingQueue<Integer> queue1 = redisson.getBlockingQueue("queue:pollany");
RBlockingQueue<Integer> queue2 = redisson.getBlockingQueue("queue:pollany1");
RBlockingQueue<Integer> queue3 = redisson.getBlockingQueue("queue:pollany2");
@ -696,7 +661,7 @@ public class RedissonBlockingQueueTest extends RedissonQueueTest {
}
@Test
public void testSubscribeOnElements() throws InterruptedException {
public void testSubscribeOnElements() {
RBlockingQueue<Integer> q = redisson.getBlockingQueue("test");
Set<Integer> values = new HashSet<>();
int listnerId = q.subscribeOnElements(v -> {
@ -707,7 +672,7 @@ public class RedissonBlockingQueueTest extends RedissonQueueTest {
q.add(i);
}
Awaitility.await().atMost(Duration.ofSeconds(1)).until(() -> {
Awaitility.await().atMost(Duration.ofSeconds(2)).until(() -> {
return values.size() == 10;
});
@ -716,8 +681,6 @@ public class RedissonBlockingQueueTest extends RedissonQueueTest {
q.add(11);
q.add(12);
Thread.sleep(1000);
assertThat(values).hasSize(10);
}

@ -10,45 +10,16 @@ import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
public class RedissonCountDownLatchConcurrentTest {
public class RedissonCountDownLatchConcurrentTest extends RedisDockerTest {
@BeforeAll
public static void beforeClass() throws IOException, InterruptedException {
if (!RedissonRuntimeEnvironment.isTravis) {
RedisRunner.startDefaultRedisServerInstance();
}
}
@AfterAll
public static void afterClass() throws IOException, InterruptedException {
if (!RedissonRuntimeEnvironment.isTravis) {
RedisRunner.shutDownDefaultRedisServerInstance();
}
}
@BeforeEach
public void before() throws IOException, InterruptedException {
if (RedissonRuntimeEnvironment.isTravis) {
RedisRunner.startDefaultRedisServerInstance();
}
}
@AfterEach
public void after() throws InterruptedException {
if (RedissonRuntimeEnvironment.isTravis) {
RedisRunner.shutDownDefaultRedisServerInstance();
}
}
@Test
public void testSingleCountDownAwait_SingleInstance() throws InterruptedException {
final int iterations = Runtime.getRuntime().availableProcessors()*3;
int iterations = Runtime.getRuntime().availableProcessors()*3;
RedissonClient redisson = BaseTest.createInstance();
final RCountDownLatch latch = redisson.getCountDownLatch("latch");
RCountDownLatch latch = redisson.getCountDownLatch("latch");
latch.trySetCount(iterations);
final AtomicInteger counter = new AtomicInteger();
AtomicInteger counter = new AtomicInteger();
ExecutorService executor = Executors.newScheduledThreadPool(iterations);
for (int i = 0; i < iterations; i++) {
executor.execute(() -> {
@ -72,8 +43,6 @@ public class RedissonCountDownLatchConcurrentTest {
executor.shutdown();
Assertions.assertTrue(executor.awaitTermination(10, TimeUnit.SECONDS));
redisson.shutdown();
}
}

@ -47,16 +47,6 @@ public class RedissonListReactiveTest extends BaseReactiveTest {
}
}
@Test
public void testHashCode() {
RListReactive<String> list = redisson.getList("list");
sync(list.add("a"));
sync(list.add("b"));
sync(list.add("c"));
Assertions.assertEquals(1625097607, list.hashCode());
}
@Test
public void testAddByIndex() {
RListReactive<String> test2 = redisson.getList("test2");

@ -306,7 +306,7 @@ public class RedissonRateLimiterTest extends RedisDockerTest {
for (Long value : queue) {
if (count % 10 == 0) {
if (start > 0) {
assertThat(value - start).isGreaterThan(980);
assertThat(value - start).isGreaterThan(940);
}
start = value;
}

@ -646,19 +646,15 @@ public class RedissonRemoteServiceTest extends RedisDockerTest {
assertThat(serviceRemoteInterface.resultMethod(21L)).isEqualTo(42L);
try {
// Invoking a service in an unregistered custom services namespace should throw
Assertions.assertThrows(RemoteServiceAckTimeoutException.class, () -> {
otherServiceRemoteInterface.resultMethod(21L);
Assertions.fail("Invoking a service in an unregistered custom services namespace should throw");
} catch (Exception e) {
assertThat(e).isInstanceOf(RemoteServiceAckTimeoutException.class);
}
});
try {
// Invoking a service in the unregistered default services namespace should throw
Assertions.assertThrows(RemoteServiceAckTimeoutException.class, () -> {
defaultServiceRemoteInterface.resultMethod(21L);
Assertions.fail("Invoking a service in the unregistered default services namespace should throw");
} catch (Exception e) {
assertThat(e).isInstanceOf(RemoteServiceAckTimeoutException.class);
}
});
client.shutdown();
server.shutdown();

@ -124,7 +124,7 @@ public class RedissonSemaphoreTest extends BaseConcurrentTest {
}
@Test
@Timeout(120)
@Timeout(5)
public void testBlockingNAcquire() throws InterruptedException {
RSemaphore s = redisson.getSemaphore("test");
s.trySetPermits(5);

@ -147,14 +147,15 @@ public class RedissonTest extends RedisDockerTest {
RAtomicLong s = inst.getAtomicLong("counter");
ExecutorService ex = Executors.newFixedThreadPool(16);
for (int i = 0; i < 500_000; i++) {
for (int i = 0; i < 200_000; i++) {
ex.execute(() -> {
long t = s.incrementAndGet();
s.incrementAndGet();
});
}
ex.shutdown();
assertThat(ex.awaitTermination(20, TimeUnit.SECONDS)).isTrue();
assertThat(ex.awaitTermination(10, TimeUnit.SECONDS)).isTrue();
assertThat(s.get()).isEqualTo(200_000L);
inst.shutdown();
}
@ -197,9 +198,9 @@ public class RedissonTest extends RedisDockerTest {
}
executor1.shutdown();
assertThat(executor1.awaitTermination(5, TimeUnit.SECONDS)).isTrue();
assertThat(executor1.awaitTermination(10, TimeUnit.SECONDS)).isTrue();
executor2.shutdown();
assertThat(executor2.awaitTermination(5, TimeUnit.SECONDS)).isTrue();
assertThat(executor2.awaitTermination(10, TimeUnit.SECONDS)).isTrue();
assertThat(hasError).isFalse();
redisson.shutdown();
@ -209,7 +210,7 @@ public class RedissonTest extends RedisDockerTest {
@Test
public void testResponseHandling() throws InterruptedException {
List<Integer> list = new ArrayList<>();
for (int i = 0; i < 10000; i++) {
for (int i = 0; i < 1000; i++) {
list.add(i);
}
@ -219,15 +220,15 @@ public class RedissonTest extends RedisDockerTest {
AtomicInteger counter = new AtomicInteger();
for (int i = 0; i < 100; i++) {
e.submit(() -> {
for (int k = 0; k < 10000; k++) {
for (int k = 0; k < list.size(); k++) {
assertThat(l.get(k)).isEqualTo(k);
counter.incrementAndGet();
}
});
}
e.shutdown();
assertThat(e.awaitTermination(70, TimeUnit.SECONDS)).isTrue();
assertThat(counter.get()).isEqualTo(10000 * 100);
assertThat(e.awaitTermination(12, TimeUnit.SECONDS)).isTrue();
assertThat(counter.get()).isEqualTo(list.size() * 100);
}
@Test
@ -606,74 +607,12 @@ public class RedissonTest extends RedisDockerTest {
@Test
public void testSentinelStartupWithPassword() throws Exception {
RedisRunner.RedisProcess master = new RedisRunner()
.nosave()
.randomDir()
.requirepass("123")
.run();
RedisRunner.RedisProcess slave1 = new RedisRunner()
.port(6380)
.nosave()
.randomDir()
.slaveof("127.0.0.1", 6379)
.requirepass("123")
.masterauth("123")
.run();
RedisRunner.RedisProcess slave2 = new RedisRunner()
.port(6381)
.nosave()
.randomDir()
.slaveof("127.0.0.1", 6379)
.requirepass("123")
.masterauth("123")
.run();
RedisRunner.RedisProcess sentinel1 = new RedisRunner()
.nosave()
.randomDir()
.port(26379)
.sentinel()
.sentinelMonitor("myMaster", "127.0.0.1", 6379, 2)
.sentinelAuthPass("myMaster", "123")
.requirepass("123")
.run();
RedisRunner.RedisProcess sentinel2 = new RedisRunner()
.nosave()
.randomDir()
.port(26380)
.sentinel()
.sentinelMonitor("myMaster", "127.0.0.1", 6379, 2)
.sentinelAuthPass("myMaster", "123")
.requirepass("123")
.run();
RedisRunner.RedisProcess sentinel3 = new RedisRunner()
.nosave()
.randomDir()
.port(26381)
.sentinel()
.sentinelMonitor("myMaster", "127.0.0.1", 6379, 2)
.sentinelAuthPass("myMaster", "123")
.requirepass("123")
.run();
Thread.sleep(5000);
Config config = new Config();
config.useSentinelServers()
.setLoadBalancer(new RandomLoadBalancer())
.setPassword("123")
.addSentinelAddress(sentinel3.getRedisServerAddressAndPort()).setMasterName("myMaster");
long t = System.currentTimeMillis();
RedissonClient redisson = Redisson.create(config);
assertThat(System.currentTimeMillis() - t).isLessThan(2000L);
redisson.shutdown();
sentinel1.stop();
sentinel2.stop();
sentinel3.stop();
master.stop();
slave1.stop();
slave2.stop();
withSentinel((nodes, config) -> {
long t = System.currentTimeMillis();
RedissonClient redisson = Redisson.create(config);
assertThat(System.currentTimeMillis() - t).isLessThan(2000L);
redisson.shutdown();
}, 2, "123");
}
@Test

@ -882,7 +882,7 @@ public class RedissonTopicTest extends RedisDockerTest {
new GenericContainer<>("bitnami/redis:7.2.4")
.withNetwork(nodes.get(1).getNetwork())
.withEnv("REDIS_REPLICATION_MODE", "slave")
.withEnv("REDIS_MASTER_HOST", "slave0")
.withEnv("REDIS_MASTER_HOST", nodes.get(1).getIpAddress())
.withEnv("ALLOW_EMPTY_PASSWORD", "yes")
.withNetworkAliases("slave2")
.withExposedPorts(6379);
@ -1109,7 +1109,7 @@ public class RedissonTopicTest extends RedisDockerTest {
redisson.getTopic("topic").publish(1);
await().atMost(20, TimeUnit.SECONDS).until(() -> subscriptions.get() == 2);
await().atMost(30, TimeUnit.SECONDS).until(() -> subscriptions.get() == 2);
assertThat(executed.get()).isTrue();
redisson.shutdown();

@ -208,7 +208,10 @@ public class RedissonTransferQueueTest extends RedisDockerTest {
f.get();
queue.clear();
assertThat(redisson.getKeys().count()).isZero();
Awaitility.waitAtMost(Duration.ofSeconds(1)).untilAsserted(() -> {
assertThat(redisson.getKeys().count()).isZero();
});
}
@Test

@ -1,26 +1,19 @@
package org.redisson.codec;
import static org.assertj.core.api.Assertions.assertThat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufAllocator;
import io.netty.util.CharsetUtil;
import org.junit.jupiter.api.Test;
import org.redisson.BaseTest;
import org.redisson.RedisDockerTest;
import org.redisson.api.RBucket;
import org.redisson.api.RMap;
import org.redisson.client.handler.State;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.util.*;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufAllocator;
import io.netty.util.CharsetUtil;
import static org.assertj.core.api.Assertions.assertThat;
public class TypedJsonJacksonCodecTest extends RedisDockerTest {

@ -1,16 +1,8 @@
package org.redisson.executor;
import static org.assertj.core.api.Assertions.assertThat;
import java.io.IOException;
import java.io.Serializable;
import java.util.Collections;
import java.util.concurrent.Callable;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.redisson.BaseTest;
import org.redisson.RedisDockerTest;
import org.redisson.RedisRunner.FailedToStartRedisException;
import org.redisson.RedissonNode;
@ -27,6 +19,12 @@ import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Service;
import java.io.Serializable;
import java.util.Collections;
import java.util.concurrent.Callable;
import static org.assertj.core.api.Assertions.assertThat;
public class RedissonExecutorServiceSpringTest extends RedisDockerTest {
public static class SampleRunnable implements Runnable, Serializable {
@ -94,7 +92,7 @@ public class RedissonExecutorServiceSpringTest extends RedisDockerTest {
private static AnnotationConfigApplicationContext context;
@BeforeAll
public static void beforeTest() throws FailedToStartRedisException, IOException, InterruptedException {
public static void beforeTest() throws FailedToStartRedisException {
context = new AnnotationConfigApplicationContext(Application.class);
}

@ -173,6 +173,7 @@ public class RedissonScheduledExecutorServiceTest extends RedisDockerTest {
@Test
@Disabled("Doesn't work with JDK 11+")
public void testDelay() throws ExecutionException, InterruptedException, TimeoutException {
RScheduledExecutorService executor = redisson.getExecutorService("test", ExecutorOptions.defaults().taskRetryInterval(5, TimeUnit.SECONDS));
long start = System.currentTimeMillis();
@ -363,6 +364,7 @@ public class RedissonScheduledExecutorServiceTest extends RedisDockerTest {
assertThat(executor.getTaskIds().contains(future.getTaskId())).isTrue();
Thread.sleep(1200);
assertThat(executor.getTaskIds().isEmpty()).isTrue();
executor.delete();
}
@Test

@ -14,6 +14,7 @@ import org.redisson.api.*;
import org.redisson.api.BatchOptions.ExecutionMode;
import org.redisson.api.RScript.Mode;
import org.redisson.client.RedisException;
import org.redisson.client.RedisTimeoutException;
import org.redisson.client.codec.StringCodec;
import org.redisson.config.Config;
@ -101,7 +102,7 @@ public class RedissonBatchRxTest extends BaseRxTest {
}
@Test
@Timeout(20)
@Timeout(4)
public void testConnectionLeakAfterError() {
Config config = createConfig();
config.useSingleServer()
@ -113,24 +114,21 @@ public class RedissonBatchRxTest extends BaseRxTest {
BatchOptions batchOptions = BatchOptions.defaults().executionMode(ExecutionMode.REDIS_WRITE_ATOMIC);
RBatchRx batch = redisson.createBatch(batchOptions);
for (int i = 0; i < 130000; i++) {
for (int i = 0; i < 60000; i++) {
batch.getBucket("test").set(123);
}
try {
Assertions.assertThrows(RedisTimeoutException.class, () -> {
sync(batch.execute());
Assertions.fail();
} catch (Exception e) {
// skip
}
});
sync(redisson.getBucket("test3").set(4));
assertThat(sync(redisson.getBucket("test3").get())).isEqualTo(4);
batch = redisson.createBatch(batchOptions);
batch.getBucket("test1").set(1);
batch.getBucket("test2").set(2);
sync(batch.execute());
RBatchRx nbatch = redisson.createBatch(batchOptions);
nbatch.getBucket("test1").set(1);
nbatch.getBucket("test2").set(2);
sync(nbatch.execute());
assertThat(sync(redisson.getBucket("test1").get())).isEqualTo(1);
assertThat(sync(redisson.getBucket("test2").get())).isEqualTo(2);

@ -4,9 +4,7 @@ import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
import org.redisson.BaseTest;
import org.redisson.RedisRunner;
import org.redisson.RedisRunner.FailedToStartRedisException;
import org.redisson.RedisDockerTest;
import org.redisson.api.RedissonClient;
import org.springframework.cache.CacheManager;
import org.springframework.cache.annotation.CacheEvict;
@ -29,7 +27,7 @@ import java.util.stream.Collectors;
import static org.assertj.core.api.Assertions.assertThat;
public class RedissonSpringCacheShortTTLTest {
public class RedissonSpringCacheShortTTLTest extends RedisDockerTest {
public static class SampleObject implements Serializable {
@ -96,7 +94,7 @@ public class RedissonSpringCacheShortTTLTest {
@Bean(destroyMethod = "shutdown")
RedissonClient redisson() {
return BaseTest.createInstance();
return createInstance();
}
@Bean
@ -115,11 +113,11 @@ public class RedissonSpringCacheShortTTLTest {
@Bean(destroyMethod = "shutdown")
RedissonClient redisson() {
return BaseTest.createInstance();
return createInstance();
}
@Bean
CacheManager cacheManager(RedissonClient redissonClient) throws IOException {
CacheManager cacheManager(RedissonClient redissonClient) {
return new RedissonSpringCacheManager(redissonClient, "classpath:/org/redisson/spring/cache/cache-config-shortTTL.json");
}
@ -132,8 +130,7 @@ public class RedissonSpringCacheShortTTLTest {
}
@BeforeAll
public static void before() throws FailedToStartRedisException, IOException, InterruptedException {
RedisRunner.startDefaultRedisServerInstance();
public static void before() {
contexts = data().stream().collect(Collectors.toMap(e -> e, e -> new AnnotationConfigApplicationContext(e)));
}

@ -1,22 +1,11 @@
package org.redisson.spring.cache;
import static org.assertj.core.api.Assertions.assertThat;
import java.io.IOException;
import java.io.Serializable;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import java.util.stream.StreamSupport;
import org.junit.jupiter.api.*;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
import org.redisson.BaseTest;
import org.redisson.RedisRunner;
import org.redisson.RedisRunner.FailedToStartRedisException;
import org.redisson.RedisDockerTest;
import org.redisson.api.RedissonClient;
import org.springframework.cache.CacheManager;
import org.springframework.cache.annotation.CacheEvict;
@ -30,8 +19,18 @@ import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Service;
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
import java.io.IOException;
import java.io.Serializable;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import static org.assertj.core.api.Assertions.assertThat;
@SpringJUnitConfig
public class RedissonSpringCacheTest {
public class RedissonSpringCacheTest extends RedisDockerTest {
public static class SampleObject implements Serializable {
@ -93,7 +92,7 @@ public class RedissonSpringCacheTest {
@Bean(destroyMethod = "shutdown")
RedissonClient redisson() {
return BaseTest.createInstance();
return createInstance();
}
@Bean
@ -112,7 +111,7 @@ public class RedissonSpringCacheTest {
@Bean(destroyMethod = "shutdown")
RedissonClient redisson() {
return BaseTest.createInstance();
return createInstance();
}
@Bean
@ -129,15 +128,13 @@ public class RedissonSpringCacheTest {
}
@BeforeAll
public static void before() throws FailedToStartRedisException, IOException, InterruptedException {
RedisRunner.startDefaultRedisServerInstance();
public static void before() {
contexts = data().stream().collect(Collectors.toMap(e -> e, e -> new AnnotationConfigApplicationContext(e)));
}
@AfterAll
public static void after() throws InterruptedException {
public static void after() {
contexts.values().forEach(e -> e.close());
RedisRunner.shutDownDefaultRedisServerInstance();
}
@ParameterizedTest

@ -1,16 +1,10 @@
package org.redisson.spring.transaction;
import org.redisson.BaseTest;
import org.redisson.Redisson;
import org.redisson.RedissonReactive;
import org.redisson.api.RedissonClient;
import org.redisson.RedisDockerTest;
import org.redisson.api.RedissonReactiveClient;
import org.redisson.transaction.operation.TransactionalOperation;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.transaction.ReactiveTransactionManager;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import org.springframework.transaction.reactive.TransactionalOperator;
import javax.annotation.PreDestroy;
@ -35,7 +29,7 @@ public class RedissonReactiveTransactionContextConfig {
@Bean
public RedissonReactiveClient redisson() {
return Redisson.create(BaseTest.createConfig()).reactive();
return RedisDockerTest.createInstance().reactive();
}
@PreDestroy

@ -1,18 +1,13 @@
package org.redisson.spring.transaction;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.redisson.RedisRunner;
import org.redisson.api.RMapReactive;
import org.redisson.api.RedissonReactiveClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
import java.io.IOException;
import static org.assertj.core.api.Assertions.assertThat;
@SpringJUnitConfig
@ -25,16 +20,6 @@ public class RedissonReactiveTransactionManagerTest {
@Autowired
private ReactiveTransactionalBean transactionalBean;
@BeforeAll
public static void beforeClass() throws IOException, InterruptedException {
RedisRunner.startDefaultRedisServerInstance();
}
@AfterAll
public static void afterClass() throws IOException, InterruptedException {
RedisRunner.shutDownDefaultRedisServerInstance();
}
@Test
public void test() {
transactionalBean.testTransactionIsNotNull().block();

@ -1,13 +1,13 @@
package org.redisson.spring.transaction;
import javax.annotation.PreDestroy;
import org.redisson.BaseTest;
import org.redisson.RedisDockerTest;
import org.redisson.api.RedissonClient;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import javax.annotation.PreDestroy;
@Configuration
@EnableTransactionManagement
public class RedissonTransactionContextConfig {
@ -29,7 +29,7 @@ public class RedissonTransactionContextConfig {
@Bean
public RedissonClient redisson() {
return BaseTest.createInstance();
return RedisDockerTest.createInstance();
}
@PreDestroy

@ -1,18 +1,13 @@
package org.redisson.spring.transaction;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.redisson.RedisRunner;
import org.redisson.api.RMap;
import org.redisson.api.RedissonClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
import java.io.IOException;
import static org.assertj.core.api.Assertions.assertThat;
@SpringJUnitConfig
@ -25,16 +20,6 @@ public class RedissonTransactionManagerTest {
@Autowired
private TransactionalBean transactionalBean;
@BeforeAll
public static void beforeClass() throws IOException, InterruptedException {
RedisRunner.startDefaultRedisServerInstance();
}
@AfterAll
public static void afterClass() throws IOException, InterruptedException {
RedisRunner.shutDownDefaultRedisServerInstance();
}
@Test
public void test() {
transactionalBean.testTransactionIsNotNull();

@ -1,7 +1,6 @@
package org.redisson.transaction;
import org.junit.jupiter.api.Test;
import org.redisson.BaseTest;
import org.redisson.RedisDockerTest;
import org.redisson.api.RBucket;
import org.redisson.api.RBuckets;

@ -1,7 +1,6 @@
package org.redisson.transaction;
import org.junit.jupiter.api.Test;
import org.redisson.BaseTest;
import org.redisson.RedisDockerTest;
import org.redisson.api.RSet;
import org.redisson.api.RTransaction;

Loading…
Cancel
Save