use of org.redisson.RedisRunner.RedisProcess in project redisson by redisson.
the class RedissonBlockingQueueTest method testPollReattach.
@Test
public void testPollReattach() 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);
final AtomicBoolean executed = new AtomicBoolean();
Thread t = new Thread() {
public void run() {
try {
RBlockingQueue<Integer> queue1 = redisson.getBlockingQueue("queue:pollany");
long start = System.currentTimeMillis();
Integer res = queue1.poll(10, TimeUnit.SECONDS);
assertThat(System.currentTimeMillis() - start).isGreaterThan(2000);
assertThat(res).isEqualTo(123);
executed.set(true);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
;
};
t.start();
t.join(1000);
runner.stop();
runner = new RedisRunner().port(runner.getRedisServerPort()).nosave().randomDir().run();
Thread.sleep(1000);
RBlockingQueue<Integer> queue1 = redisson.getBlockingQueue("queue:pollany");
queue1.put(123);
t.join();
await().atMost(5, TimeUnit.SECONDS).until(() -> assertThat(executed.get()).isTrue());
redisson.shutdown();
runner.stop();
}
use of org.redisson.RedisRunner.RedisProcess in project redisson by redisson.
the class RedissonBlockingQueueTest 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 RBlockingQueue<Integer> queue1 = redisson.getBlockingQueue("queue:pollTimeout");
RFuture<Integer> f = queue1.pollAsync(5, TimeUnit.SECONDS);
Assert.assertFalse(f.await(1, TimeUnit.SECONDS));
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 RedissonBlockingQueueTest 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);
RBlockingQueue<Integer> queue1 = redisson.getBlockingQueue("testTakeReattach");
RFuture<Integer> f = queue1.takeAsync();
f.await(1, TimeUnit.SECONDS);
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);
}
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 testPollReattach.
@Test
public void testPollReattach() 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();
final AtomicBoolean executed = new AtomicBoolean();
Thread t = new Thread() {
public void run() {
try {
RBoundedBlockingQueue<Integer> queue1 = redisson.getBoundedBlockingQueue("queue:pollany");
assertThat(queue1.trySetCapacity(10)).isTrue();
long start = System.currentTimeMillis();
Integer res = queue1.poll(10, TimeUnit.SECONDS);
assertThat(System.currentTimeMillis() - start).isGreaterThan(2000);
assertThat(res).isEqualTo(123);
executed.set(true);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
;
};
t.start();
t.join(1000);
runner.stop();
runner = new RedisRunner().port(runner.getRedisServerPort()).nosave().randomDir().run();
Thread.sleep(1000);
RBoundedBlockingQueue<Integer> queue1 = redisson.getBoundedBlockingQueue("queue:pollany");
assertThat(queue1.trySetCapacity(10)).isTrue();
queue1.put(123);
t.join();
await().atMost(5, TimeUnit.SECONDS).until(() -> assertThat(executed.get()).isTrue());
redisson.shutdown();
runner.stop();
}
use of org.redisson.RedisRunner.RedisProcess in project redisson by redisson.
the class RedissonBoundedBlockingQueueTest method testPollAsyncReattach.
@Test
public void testPollAsyncReattach() 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);
RBoundedBlockingQueue<Integer> queue1 = redisson.getBoundedBlockingQueue("queue:pollany");
RFuture<Integer> f = queue1.pollAsync(10, TimeUnit.SECONDS);
f.await(1, TimeUnit.SECONDS);
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);
redisson.shutdown();
runner.stop();
}
Aggregations