Java Code Examples for org.redisson.api.RRemoteService#register()

The following examples show how to use org.redisson.api.RRemoteService#register() . 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 testPendingInvocations() throws InterruptedException, ExecutionException {
    ExecutorService executor = Executors.newSingleThreadExecutor();
    RRemoteService rs = redisson.getRemoteService();
    rs.register(RemoteInterface.class, new RemoteImpl(), 1, executor);
    
    assertThat(rs.getPendingInvocations(RemoteInterface.class)).isEqualTo(0);
    
    RemoteInterfaceAsync ri = redisson.getRemoteService().get(RemoteInterfaceAsync.class);
    
    for (int i = 0; i < 5; i++) {
        ri.timeoutMethod();
    }
    Thread.sleep(1000);
    assertThat(rs.getPendingInvocations(RemoteInterface.class)).isEqualTo(4);
    Thread.sleep(9000);
    assertThat(rs.getPendingInvocations(RemoteInterface.class)).isEqualTo(0);

    executor.shutdown();
    executor.awaitTermination(1, TimeUnit.MINUTES);
    
    rs.deregister(RemoteInterface.class);
}
 
Example 2
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 3
Source File: RedissonRemoteServiceTest.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Test
public void testConcurrentInvocations() {
    ExecutorService executorService = Executors.newFixedThreadPool(2);
    RRemoteService remoteService = redisson.getRemoteService();
    remoteService.register(RemoteInterface.class, new RemoteImpl());
    RemoteInterface service = redisson.getRemoteService().get(RemoteInterface.class);

    List<Future<?>> futures = new ArrayList<>();

    int iterations = 1000;
    AtomicBoolean bool = new AtomicBoolean();
    for (int i = 0; i < iterations; i++) {
        futures.add(executorService.submit(() -> {
            try {
                if (ThreadLocalRandom.current().nextBoolean()) {
                    service.resultMethod(1L);
                } else {
                    service.methodOverload();
                }
            } catch (Exception e) {
                e.printStackTrace();
                bool.set(true);
            }
        }));
    }

    while (!futures.stream().allMatch(Future::isDone)) {}

    assertThat(bool.get()).isFalse();
    remoteService.deregister(RemoteInterface.class);
}