Java Code Examples for org.redisson.api.RFuture#get()

The following examples show how to use org.redisson.api.RFuture#get() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RedissonRemoteServiceTest.java    From redisson with Apache License 2.0 6 votes vote down vote up
@Test
public void testFreeWorkers() throws InterruptedException, ExecutionException {
    RedissonClient r1 = createInstance();
    ExecutorService executor = Executors.newSingleThreadExecutor();
    RRemoteService rs = r1.getRemoteService();
    rs.register(RemoteInterface.class, new RemoteImpl(), 1, executor);
    assertThat(rs.getFreeWorkers(RemoteInterface.class)).isEqualTo(1);
    
    RedissonClient r2 = createInstance();
    RemoteInterfaceAsync ri = r2.getRemoteService().get(RemoteInterfaceAsync.class);
    
    RFuture<Void> f = ri.timeoutMethod();
    Thread.sleep(100);
    assertThat(rs.getFreeWorkers(RemoteInterface.class)).isEqualTo(0);
    f.get();
    assertThat(rs.getFreeWorkers(RemoteInterface.class)).isEqualTo(1);

    r1.shutdown();
    r2.shutdown();
    
    executor.shutdown();
    executor.awaitTermination(1, TimeUnit.MINUTES);
}
 
Example 2
Source File: RedissonPriorityBlockingQueueTest.java    From redisson with Apache License 2.0 5 votes vote down vote up
@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);
    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 + 1000);
    }
    Integer result = f.get();
    assertThat(queue1.size()).isEqualTo(10);
    
    assertThat(result).isEqualTo(123);
    
    redisson.shutdown();
    runner.stop();
}
 
Example 3
Source File: RedissonPriorityBlockingQueueTest.java    From redisson with Apache License 2.0 5 votes vote down vote up
@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();
    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 + 10000);
    }

    Integer result = f.get();
    assertThat(result).isEqualTo(123);
    assertThat(queue1.size()).isEqualTo(10);
    runner.stop();
    
    redisson.shutdown();
}
 
Example 4
Source File: RedissonBlockingQueueTest.java    From redisson with Apache License 2.0 5 votes vote down vote up
@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);
    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);
    
    redisson.shutdown();
    runner.stop();
}
 
Example 5
Source File: RedissonBlockingQueueTest.java    From redisson with Apache License 2.0 5 votes vote down vote up
@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();
    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 + 10000);
    }
    assertThat(queue1.size()).isEqualTo(10);
    
    Integer result = f.get(1, TimeUnit.SECONDS);
    assertThat(result).isEqualTo(123);
    runner.stop();
    
    redisson.shutdown();
}
 
Example 6
Source File: RedissonBoundedBlockingQueueTest.java    From redisson with Apache License 2.0 5 votes vote down vote up
@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();
}
 
Example 7
Source File: RedissonBoundedBlockingQueueTest.java    From redisson with Apache License 2.0 5 votes vote down vote up
@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();
    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);
    runner.stop();
    
    redisson.shutdown();
}
 
Example 8
Source File: RedissonBlockingQueueTest.java    From redisson with Apache License 2.0 4 votes vote down vote up
@Test
public void testTakeReattachSentinel() throws IOException, InterruptedException, TimeoutException, ExecutionException {
    RedisRunner.RedisProcess master = new RedisRunner()
            .nosave()
            .randomDir()
            .run();
    RedisRunner.RedisProcess slave1 = new RedisRunner()
            .port(6380)
            .nosave()
            .randomDir()
            .slaveof("127.0.0.1", 6379)
            .run();
    RedisRunner.RedisProcess slave2 = new RedisRunner()
            .port(6381)
            .nosave()
            .randomDir()
            .slaveof("127.0.0.1", 6379)
            .run();
    RedisRunner.RedisProcess sentinel1 = new RedisRunner()
            .nosave()
            .randomDir()
            .port(26379)
            .sentinel()
            .sentinelMonitor("myMaster", "127.0.0.1", 6379, 2)
            .run();
    RedisRunner.RedisProcess sentinel2 = new RedisRunner()
            .nosave()
            .randomDir()
            .port(26380)
            .sentinel()
            .sentinelMonitor("myMaster", "127.0.0.1", 6379, 2)
            .run();
    RedisRunner.RedisProcess sentinel3 = new RedisRunner()
            .nosave()
            .randomDir()
            .port(26381)
            .sentinel()
            .sentinelMonitor("myMaster", "127.0.0.1", 6379, 2)
            .run();

    Thread.sleep(1000);

    Config config = new Config();
    config.useSentinelServers()
        .setLoadBalancer(new RandomLoadBalancer())
        .addSentinelAddress(sentinel3.getRedisServerAddressAndPort()).setMasterName("myMaster");
    RedissonClient redisson = Redisson.create(config);

    RBlockingQueue<Integer> queue1 = getQueue(redisson);
    RFuture<Integer> f = queue1.takeAsync();
    f.await(1, TimeUnit.SECONDS);

    master.stop();

    Thread.sleep(TimeUnit.SECONDS.toMillis(60));

    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(80, TimeUnit.SECONDS);
    assertThat(result).isEqualTo(123);

    redisson.shutdown();
    sentinel1.stop();
    sentinel2.stop();
    sentinel3.stop();
    master.stop();
    slave1.stop();
    slave2.stop();

}