use of org.redisson.RedisRunner.RedisProcess in project redisson by redisson.
the class RedissonBlockingQueueTest method testTakeReattachCluster.
@Test
public void testTakeReattachCluster() throws IOException, InterruptedException {
RedisRunner master1 = new RedisRunner().port(6890).randomDir().nosave();
RedisRunner master2 = new RedisRunner().port(6891).randomDir().nosave();
RedisRunner master3 = new RedisRunner().port(6892).randomDir().nosave();
RedisRunner slave1 = new RedisRunner().port(6900).randomDir().nosave();
RedisRunner slave2 = new RedisRunner().port(6901).randomDir().nosave();
RedisRunner slave3 = new RedisRunner().port(6902).randomDir().nosave();
ClusterRunner clusterRunner = new ClusterRunner().addNode(master1, slave1).addNode(master2, slave2).addNode(master3, slave3);
ClusterProcesses process = clusterRunner.run();
Thread.sleep(1000);
Config config = new Config();
config.useClusterServers().setLoadBalancer(new RandomLoadBalancer()).addNodeAddress(process.getNodes().stream().findAny().get().getRedisServerAddressAndPort());
RedissonClient redisson = Redisson.create(config);
RedisProcess master = process.getNodes().stream().filter(x -> x.getRedisServerPort() == master1.getPort()).findFirst().get();
List<RFuture<Integer>> futures = new ArrayList<>();
for (int i = 0; i < 10; i++) {
RBlockingQueue<Integer> queue = redisson.getBlockingQueue("queue" + i);
RFuture<Integer> f = queue.takeAsync();
try {
f.toCompletableFuture().get(1, TimeUnit.SECONDS);
} catch (ExecutionException | TimeoutException e) {
// skip
}
futures.add(f);
}
master.stop();
Thread.sleep(TimeUnit.SECONDS.toMillis(80));
for (int i = 0; i < 10; i++) {
RBlockingQueue<Integer> queue = redisson.getBlockingQueue("queue" + i);
queue.put(i * 100);
}
for (int i = 0; i < 10; i++) {
RFuture<Integer> f = futures.get(i);
try {
f.toCompletableFuture().get(20, TimeUnit.SECONDS);
} catch (ExecutionException | TimeoutException e) {
// skip
}
if (f.cause() != null) {
f.cause().printStackTrace();
}
Integer result = f.toCompletableFuture().getNow(null);
assertThat(result).isEqualTo(i * 100);
}
redisson.shutdown();
process.shutdown();
}
use of org.redisson.RedisRunner.RedisProcess in project redisson by redisson.
the class RedissonBoundedBlockingQueueTest method testTakeReattach.
@Test
public void testTakeReattach() throws InterruptedException, IOException, ExecutionException, TimeoutException {
RedisProcess runner = new RedisRunner().nosave().randomDir().randomPort().run();
Config config = new Config();
config.useSingleServer().setAddress(runner.getRedisServerAddressAndPort());
RedissonClient redisson = Redisson.create(config);
redisson.getKeys().flushall();
RBoundedBlockingQueue<Integer> queue1 = redisson.getBoundedBlockingQueue("testTakeReattach");
assertThat(queue1.trySetCapacity(15)).isTrue();
RFuture<Integer> f = queue1.takeAsync();
try {
f.toCompletableFuture().get(1, TimeUnit.SECONDS);
} catch (ExecutionException | TimeoutException e) {
// skip
}
runner.stop();
runner = new RedisRunner().port(runner.getRedisServerPort()).nosave().randomDir().run();
assertThat(queue1.trySetCapacity(15)).isTrue();
queue1.put(123);
// check connection rotation
for (int i = 0; i < 10; i++) {
queue1.put(i);
}
assertThat(queue1.size()).isEqualTo(10);
Integer result = f.get(1, TimeUnit.SECONDS);
assertThat(result).isEqualTo(123);
runner.stop();
redisson.shutdown();
}
use of org.redisson.RedisRunner.RedisProcess in project redisson by redisson.
the class RedissonBoundedBlockingQueueTest method testPollWithBrokenConnection.
@Test
public void testPollWithBrokenConnection() throws IOException, InterruptedException, ExecutionException {
RedisProcess runner = new RedisRunner().nosave().randomDir().randomPort().run();
Config config = new Config();
config.useSingleServer().setAddress(runner.getRedisServerAddressAndPort());
RedissonClient redisson = Redisson.create(config);
final RBoundedBlockingQueue<Integer> queue1 = redisson.getBoundedBlockingQueue("bounded-queue:pollTimeout");
assertThat(queue1.trySetCapacity(5)).isTrue();
RFuture<Integer> f = queue1.pollAsync(5, TimeUnit.SECONDS);
try {
f.toCompletableFuture().get(1, TimeUnit.SECONDS);
Assertions.fail();
} catch (TimeoutException e) {
// skip
}
runner.stop();
long start = System.currentTimeMillis();
assertThat(f.get()).isNull();
assertThat(System.currentTimeMillis() - start).isGreaterThan(3800);
redisson.shutdown();
}
use of org.redisson.RedisRunner.RedisProcess in project redisson by redisson.
the class RedissonPriorityBlockingQueueTest method testTakeReattach.
@Test
public void testTakeReattach() throws Exception {
RedisProcess runner = new RedisRunner().nosave().randomDir().randomPort().run();
Config config = new Config();
config.useSingleServer().setAddress(runner.getRedisServerAddressAndPort());
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
}
runner.stop();
runner = new RedisRunner().port(runner.getRedisServerPort()).nosave().randomDir().run();
queue1.put(123);
// check connection rotation
for (int i = 0; i < 10; i++) {
queue1.put(i + 10000);
}
Integer result = f.get();
assertThat(result).isEqualTo(123);
assertThat(queue1.size()).isEqualTo(10);
runner.stop();
redisson.shutdown();
}
use of org.redisson.RedisRunner.RedisProcess in project redisson by redisson.
the class RedissonBucketTest method testSetListener.
@Test
public void testSetListener() throws FailedToStartRedisException, IOException, InterruptedException {
RedisProcess instance = new RedisRunner().nosave().randomPort().randomDir().notifyKeyspaceEvents(KEYSPACE_EVENTS_OPTIONS.E, KEYSPACE_EVENTS_OPTIONS.$).run();
Config config = new Config();
config.useSingleServer().setAddress(instance.getRedisServerAddressAndPort());
RedissonClient redisson = Redisson.create(config);
RBucket<Integer> al = redisson.getBucket("test");
CountDownLatch latch = new CountDownLatch(1);
al.addListener(new SetObjectListener() {
@Override
public void onSet(String name) {
latch.countDown();
}
});
al.set(1);
assertThat(latch.await(1, TimeUnit.SECONDS)).isTrue();
redisson.shutdown();
instance.stop();
}
Aggregations