use of org.redisson.api.RRemoteService in project redisson by redisson.
the class RedissonRemoteServiceTest method testFreeWorkers.
@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);
}
use of org.redisson.api.RRemoteService in project redisson by redisson.
the class RedissonRemoteServiceTest method testOptional.
@Test
public void testOptional() {
RRemoteService remoteService = redisson.getRemoteService();
remoteService.register(RemoteInterface.class, new RemoteImpl());
RemoteInterface service = redisson.getRemoteService().get(RemoteInterface.class);
Optional<Integer> r1 = service.optionalResult(null);
assertThat(r1.isPresent()).isFalse();
Optional<Integer> r2 = service.optionalResult(2);
assertThat(r2.get()).isEqualTo(2);
remoteService.deregister(RemoteInterface.class);
}
use of org.redisson.api.RRemoteService in project redisson by redisson.
the class RedissonRemoteServiceTest method testConcurrentInvocations.
@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);
}
use of org.redisson.api.RRemoteService in project redisson by redisson.
the class RedissonRemoteServiceTest method testPendingInvocations.
@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);
}
Aggregations