Search in sources :

Example 46 with RedisProcess

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();
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) RedissonClient(org.redisson.api.RedissonClient) RedisProcess(org.redisson.RedisRunner.RedisProcess) Config(org.redisson.config.Config) Test(org.junit.jupiter.api.Test)

Example 47 with RedisProcess

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();
}
Also used : RedissonClient(org.redisson.api.RedissonClient) RedisProcess(org.redisson.RedisRunner.RedisProcess) Config(org.redisson.config.Config) Test(org.junit.jupiter.api.Test)

Example 48 with RedisProcess

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();
}
Also used : RedissonClient(org.redisson.api.RedissonClient) RedisProcess(org.redisson.RedisRunner.RedisProcess) Config(org.redisson.config.Config) ExpiredObjectListener(org.redisson.api.ExpiredObjectListener) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.jupiter.api.Test)

Example 49 with RedisProcess

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();
}
Also used : RedissonClient(org.redisson.api.RedissonClient) RedisProcess(org.redisson.RedisRunner.RedisProcess) Config(org.redisson.config.Config) Test(org.junit.jupiter.api.Test)

Example 50 with RedisProcess

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();
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) RPatternTopic(org.redisson.api.RPatternTopic) RedissonClient(org.redisson.api.RedissonClient) RedisProcess(org.redisson.RedisRunner.RedisProcess) Config(org.redisson.config.Config) Test(org.junit.jupiter.api.Test)

Aggregations

RedisProcess (org.redisson.RedisRunner.RedisProcess)55 Test (org.junit.jupiter.api.Test)49 Config (org.redisson.config.Config)41 RedissonClient (org.redisson.api.RedissonClient)30 BaseTest (org.redisson.BaseTest)16 RedisRunner (org.redisson.RedisRunner)16 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)13 RLock (org.redisson.api.RLock)12 URL (java.net.URL)11 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)9 CountDownLatch (java.util.concurrent.CountDownLatch)8 IOException (java.io.IOException)6 TimeoutException (java.util.concurrent.TimeoutException)6 MutableConfiguration (javax.cache.configuration.MutableConfiguration)6 URI (java.net.URI)5 ExecutionException (java.util.concurrent.ExecutionException)5 MutableCacheEntryListenerConfiguration (javax.cache.configuration.MutableCacheEntryListenerConfiguration)5 HashMap (java.util.HashMap)4 ExecutorService (java.util.concurrent.ExecutorService)4 ClusterProcesses (org.redisson.ClusterRunner.ClusterProcesses)4