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();
}
}
use of org.redisson.api.RedissonClient in project redisson by redisson.
the class RedissonRemoteServiceTest method testInvocationWithSerializationCodec.
@Test
public void testInvocationWithSerializationCodec() {
RedissonClient server = Redisson.create(createConfig().setCodec(new SerializationCodec()));
RedissonClient client = Redisson.create(createConfig().setCodec(new SerializationCodec()));
try {
server.getRemoteService().register(RemoteInterface.class, new RemoteImpl());
RemoteInterface service = client.getRemoteService().get(RemoteInterface.class);
try {
assertThat(service.resultMethod(21L)).isEqualTo(42L);
} catch (Exception e) {
Assert.fail("Should be compatible with SerializationCodec");
}
try {
assertThat(service.doSomethingWithSerializablePojo(new SerializablePojo("test")).getStringField()).isEqualTo("test");
} catch (Exception e) {
e.printStackTrace();
Assert.fail("Should be compatible with SerializationCodec");
}
try {
assertThat(service.doSomethingWithPojo(new Pojo("test")).getStringField()).isEqualTo("test");
Assert.fail("SerializationCodec should not be able to serialize a not serializable class");
} catch (Exception e) {
e.printStackTrace();
assertThat(e.getCause()).isInstanceOf(NotSerializableException.class);
assertThat(e.getCause().getMessage()).contains("Pojo");
}
} finally {
client.shutdown();
server.shutdown();
}
}
Aggregations