use of org.redisson.api.RedissonClient in project redisson by redisson.
the class RedissonTopicTest method testStatus.
@Test
public void testStatus() throws InterruptedException {
RedissonClient redisson = BaseTest.createInstance();
final RTopic<Message> topic1 = redisson.getTopic("topic1");
final CountDownLatch l = new CountDownLatch(1);
int listenerId = topic1.addListener(new BaseStatusListener() {
@Override
public void onSubscribe(String channel) {
Assert.assertEquals("topic1", channel);
l.countDown();
}
});
Thread.sleep(500);
int listenerId2 = topic1.addListener(new BaseStatusListener() {
@Override
public void onUnsubscribe(String channel) {
Assert.assertEquals("topic1", channel);
l.countDown();
}
});
topic1.removeListener(listenerId);
topic1.removeListener(listenerId2);
Assert.assertTrue(l.await(5, TimeUnit.SECONDS));
}
use of org.redisson.api.RedissonClient in project redisson by redisson.
the class RedissonRemoteServiceTest method testTimeout.
@Test(expected = RemoteServiceTimeoutException.class)
public void testTimeout() throws InterruptedException {
RedissonClient r1 = createInstance();
r1.getRemoteService().register(RemoteInterface.class, new RemoteImpl());
RedissonClient r2 = createInstance();
RemoteInterface ri = r2.getRemoteService().get(RemoteInterface.class, 1, TimeUnit.SECONDS);
try {
ri.timeoutMethod();
} finally {
r1.shutdown();
r2.shutdown();
}
}
use of org.redisson.api.RedissonClient in project redisson by redisson.
the class RedissonRemoteServiceTest method testNoAckWithResultInvocationsAsync.
@Test
public void testNoAckWithResultInvocationsAsync() throws InterruptedException, ExecutionException {
RedissonClient server = createInstance();
RedissonClient client = createInstance();
try {
server.getRemoteService().register(RemoteInterface.class, new RemoteImpl());
// no ack but an execution timeout of 1 second
RemoteInvocationOptions options = RemoteInvocationOptions.defaults().noAck().expectResultWithin(1, TimeUnit.SECONDS);
RemoteInterfaceAsync service = client.getRemoteService().get(RemoteInterfaceAsync.class, options);
service.voidMethod("noAck", 100L).get();
assertThat(service.resultMethod(21L).get()).isEqualTo(42);
try {
service.errorMethod().get();
Assert.fail();
} catch (Exception e) {
assertThat(e.getCause().getMessage()).isEqualTo("Checking error throw");
}
try {
service.errorMethodWithCause().get();
Assert.fail();
} catch (Exception e) {
assertThat(e.getCause().getCause()).isInstanceOf(ArithmeticException.class);
assertThat(e.getCause().getCause().getMessage()).isEqualTo("/ by zero");
}
try {
service.timeoutMethod().get();
Assert.fail("noAck option should still wait for the server to return a response and throw if the execution timeout is exceeded");
} catch (Exception e) {
assertThat(e.getCause()).isInstanceOf(RemoteServiceTimeoutException.class);
}
} finally {
client.shutdown();
server.shutdown();
}
}
use of org.redisson.api.RedissonClient in project redisson by redisson.
the class RedissonRemoteServiceTest method testMethodOverload.
@Test
public void testMethodOverload() {
RedissonClient r1 = createInstance();
r1.getRemoteService().register(RemoteInterface.class, new RemoteImpl());
RedissonClient r2 = createInstance();
RemoteInterface ri = r2.getRemoteService().get(RemoteInterface.class);
assertThat(ri.methodOverload()).isEqualTo("methodOverload()");
assertThat(ri.methodOverload(1l)).isEqualTo("methodOverload(Long lng)");
assertThat(ri.methodOverload("")).isEqualTo("methodOverload(String str)");
assertThat(ri.methodOverload("", 1l)).isEqualTo("methodOverload(String str, Long lng)");
r1.shutdown();
r2.shutdown();
}
use of org.redisson.api.RedissonClient in project redisson by redisson.
the class RedissonRemoteServiceTest method testAckWithoutResultInvocations.
@Test
public void testAckWithoutResultInvocations() throws InterruptedException {
RedissonClient server = createInstance();
RedissonClient client = createInstance();
try {
server.getRemoteService().register(RemoteInterface.class, new RemoteImpl());
// fire and forget with an ack timeout of 1 sec
RemoteInvocationOptions options = RemoteInvocationOptions.defaults().expectAckWithin(1, TimeUnit.SECONDS).noResult();
RemoteInterface service = client.getRemoteService().get(RemoteInterface.class, options);
service.voidMethod("noResult", 100L);
try {
service.resultMethod(100L);
Assert.fail();
} catch (Exception e) {
assertThat(e).isInstanceOf(IllegalArgumentException.class);
}
try {
service.errorMethod();
} catch (IOException e) {
Assert.fail("noResult option should not throw server side exception");
}
try {
service.errorMethodWithCause();
} catch (Exception e) {
Assert.fail("noResult option should not throw server side exception");
}
long time = System.currentTimeMillis();
service.timeoutMethod();
time = System.currentTimeMillis() - time;
assertThat(time).describedAs("noResult option should not wait for the server to return a response").isLessThan(2000);
try {
service.timeoutMethod();
Assert.fail("noResult option should still wait for the server to ack the request and throw if the ack timeout is exceeded");
} catch (Exception e) {
assertThat(e).isInstanceOf(RemoteServiceAckTimeoutException.class);
}
} finally {
client.shutdown();
server.shutdown();
}
}
Aggregations