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).untilTrue(executed);
redisson.shutdown();
runner.stop();
}
use of org.redisson.RedisRunner.RedisProcess in project redisson by redisson.
the class RedissonBucketTest method testMigrate.
@Test
public void testMigrate() throws FailedToStartRedisException, IOException, InterruptedException {
RedisProcess runner = new RedisRunner().appendonly(true).randomDir().randomPort().run();
RBucket<String> bucket = redisson.getBucket("test");
bucket.set("someValue");
bucket.migrate(runner.getRedisServerBindAddress(), runner.getRedisServerPort(), 0, 5000);
Config config = new Config();
config.useSingleServer().setAddress(runner.getRedisServerAddressAndPort());
RedissonClient r = Redisson.create(config);
RBucket<String> bucket2 = r.getBucket("test");
assertThat(bucket2.get()).isEqualTo("someValue");
assertThat(bucket.isExists()).isFalse();
runner.stop();
}
use of org.redisson.RedisRunner.RedisProcess in project redisson by redisson.
the class RedissonBucketTest method testExpiredListener.
@Test
public void testExpiredListener() throws FailedToStartRedisException, IOException, InterruptedException {
RedisProcess instance = new RedisRunner().nosave().randomPort().randomDir().notifyKeyspaceEvents(KEYSPACE_EVENTS_OPTIONS.E, KEYSPACE_EVENTS_OPTIONS.x).run();
Config config = new Config();
config.useSingleServer().setAddress(instance.getRedisServerAddressAndPort());
RedissonClient redisson = Redisson.create(config);
RBucket<Integer> al = redisson.getBucket("test");
al.set(1, 3, TimeUnit.SECONDS);
CountDownLatch latch = new CountDownLatch(1);
al.addListener(new ExpiredObjectListener() {
@Override
public void onExpired(String name) {
latch.countDown();
}
});
assertThat(latch.await(4, TimeUnit.SECONDS)).isTrue();
redisson.shutdown();
instance.stop();
}
use of org.redisson.RedisRunner.RedisProcess in project redisson by redisson.
the class RedissonBucketTest method testCopy.
@Test
public void testCopy() throws FailedToStartRedisException, IOException, InterruptedException {
RedisProcess runner = new RedisRunner().appendonly(true).randomDir().randomPort().run();
RBucket<String> bucket = redisson.getBucket("test");
bucket.set("someValue");
bucket.copy(runner.getRedisServerBindAddress(), runner.getRedisServerPort(), 0, 5000);
Config config = new Config();
config.useSingleServer().setAddress(runner.getRedisServerAddressAndPort());
RedissonClient r = Redisson.create(config);
RBucket<String> bucket2 = r.getBucket("test");
assertThat(bucket2.get()).isEqualTo("someValue");
assertThat(bucket.get()).isEqualTo("someValue");
runner.stop();
}
use of org.redisson.RedisRunner.RedisProcess in project redisson by redisson.
the class RedissonTopicPatternTest method testReattach.
@Test
public void testReattach() 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();
RPatternTopic topic = redisson.getPatternTopic("topic*");
topic.addListener(Integer.class, new PatternMessageListener<Integer>() {
@Override
public void onMessage(CharSequence pattern, CharSequence channel, Integer msg) {
if (msg == 1) {
executed.set(true);
}
}
});
runner.stop();
runner = new RedisRunner().port(runner.getRedisServerPort()).nosave().randomDir().run();
Thread.sleep(1000);
redisson.getTopic("topic1").publish(1);
await().atMost(5, TimeUnit.SECONDS).untilTrue(executed);
redisson.shutdown();
runner.stop();
}
Aggregations