Search in sources :

Example 41 with RedisProcess

use of org.redisson.RedisRunner.RedisProcess in project redisson by redisson.

the class RedissonBlockingQueueTest method testPollReattach.

@Test
public void testPollReattach() throws InterruptedException, IOException {
    RedisProcess runner = new RedisRunner().nosave().randomDir().randomPort().requirepass("1234").run();
    Config config = new Config();
    config.useSingleServer().setAddress(runner.getRedisServerAddressAndPort()).setPassword("1234");
    RedissonClient redisson = Redisson.create(config);
    final AtomicBoolean executed = new AtomicBoolean();
    Thread t = new Thread() {

        public void run() {
            try {
                RBlockingQueue<Integer> queue1 = getQueue(redisson);
                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().requirepass("1234").run();
    Thread.sleep(1000);
    RBlockingQueue<Integer> queue1 = getQueue(redisson);
    queue1.put(123);
    t.join();
    await().atMost(7, TimeUnit.SECONDS).untilTrue(executed);
    redisson.shutdown();
    runner.stop();
}
Also used : 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 42 with RedisProcess

use of org.redisson.RedisRunner.RedisProcess in project redisson by redisson.

the class RedissonBlockingQueueTest 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) {
        e.printStackTrace();
    }
    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);
    }
    assertThat(queue1.size()).isEqualTo(10);
    Integer result = f.get(1, TimeUnit.SECONDS);
    assertThat(result).isEqualTo(123);
    runner.stop();
    redisson.shutdown();
}
Also used : RedissonClient(org.redisson.api.RedissonClient) RedisProcess(org.redisson.RedisRunner.RedisProcess) Config(org.redisson.config.Config) ExecutionException(java.util.concurrent.ExecutionException) TimeoutException(java.util.concurrent.TimeoutException) Test(org.junit.jupiter.api.Test)

Example 43 with RedisProcess

use of org.redisson.RedisRunner.RedisProcess in project redisson by redisson.

the class RedissonBlockingQueueTest 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);
    RBlockingQueue<Integer> queue1 = getQueue(redisson);
    RFuture<Integer> f = queue1.pollAsync(10, TimeUnit.SECONDS);
    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);
    }
    assertThat(queue1.size()).isEqualTo(10);
    Integer result = f.get(1, TimeUnit.SECONDS);
    assertThat(result).isEqualTo(123);
    redisson.shutdown();
    runner.stop();
}
Also used : RedissonClient(org.redisson.api.RedissonClient) RedisProcess(org.redisson.RedisRunner.RedisProcess) Config(org.redisson.config.Config) ExecutionException(java.util.concurrent.ExecutionException) TimeoutException(java.util.concurrent.TimeoutException) Test(org.junit.jupiter.api.Test)

Example 44 with RedisProcess

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

Example 45 with RedisProcess

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);
    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);
    redisson.shutdown();
    runner.stop();
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) 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