use of org.redisson.api.RedissonClient in project redisson by redisson.
the class RedissonRemoteServiceTest method testNoAckWithoutResultInvocations.
@Test
public void testNoAckWithoutResultInvocations() throws InterruptedException {
RedissonClient server = createInstance();
RedissonClient client = createInstance();
try {
server.getRemoteService().register(RemoteInterface.class, new RemoteImpl());
// no ack fire and forget
RemoteInvocationOptions options = RemoteInvocationOptions.defaults().noAck().noResult();
RemoteInterface service = client.getRemoteService().get(RemoteInterface.class, options);
RemoteInterface invalidService = client.getRemoteService("Invalid").get(RemoteInterface.class, options);
service.voidMethod("noAck/noResult", 100L);
try {
service.resultMethod(100L);
Assert.fail();
} catch (Exception e) {
assertThat(e).isInstanceOf(IllegalArgumentException.class);
}
try {
service.errorMethod();
} catch (IOException e) {
Assert.fail("noAck with noResult options should not throw server side exception");
}
try {
service.errorMethodWithCause();
} catch (Exception e) {
Assert.fail("noAck with noResult options should not throw server side exception");
}
long time = System.currentTimeMillis();
service.timeoutMethod();
time = System.currentTimeMillis() - time;
assertThat(time).describedAs("noAck with noResult options should not wait for the server to return a response").isLessThan(2000);
try {
invalidService.voidMethod("noAck/noResult", 21L);
} catch (Exception e) {
Assert.fail("noAck with noResult options should not throw any exception even while invoking a service in an unregistered services namespace");
}
} finally {
client.shutdown();
server.shutdown();
}
}
use of org.redisson.api.RedissonClient in project redisson by redisson.
the class RedissonRemoteServiceTest method testInvocations.
@Test
public void testInvocations() {
RedissonClient r1 = createInstance();
r1.getRemoteService().register(RemoteInterface.class, new RemoteImpl());
RedissonClient r2 = createInstance();
RemoteInterface ri = r2.getRemoteService().get(RemoteInterface.class);
ri.voidMethod("someName", 100L);
assertThat(ri.resultMethod(100L)).isEqualTo(200);
try {
ri.errorMethod();
Assert.fail();
} catch (IOException e) {
assertThat(e.getMessage()).isEqualTo("Checking error throw");
}
try {
ri.errorMethodWithCause();
Assert.fail();
} catch (Exception e) {
assertThat(e.getCause()).isInstanceOf(ArithmeticException.class);
assertThat(e.getCause().getMessage()).isEqualTo("/ by zero");
}
r1.shutdown();
r2.shutdown();
}
use of org.redisson.api.RedissonClient in project redisson by redisson.
the class RedissonRemoteServiceTest method testInvocationWithFstCodec.
@Test
public void testInvocationWithFstCodec() {
RedissonClient server = Redisson.create(createConfig().setCodec(new FstCodec()));
RedissonClient client = Redisson.create(createConfig().setCodec(new FstCodec()));
try {
server.getRemoteService().register(RemoteInterface.class, new RemoteImpl());
RemoteInterface service = client.getRemoteService().get(RemoteInterface.class);
assertThat(service.resultMethod(21L)).as("Should be compatible with FstCodec").isEqualTo(42L);
try {
assertThat(service.doSomethingWithSerializablePojo(new SerializablePojo("test")).getStringField()).isEqualTo("test");
} catch (Exception e) {
Assert.fail("Should be compatible with FstCodec");
}
try {
assertThat(service.doSomethingWithPojo(new Pojo("test")).getStringField()).isEqualTo("test");
Assert.fail("FstCodec should not be able to serialize a not serializable class");
} catch (Exception e) {
assertThat(e.getCause()).isInstanceOf(RuntimeException.class);
assertThat(e.getCause().getMessage()).contains("Pojo does not implement Serializable");
}
} finally {
client.shutdown();
server.shutdown();
}
}
use of org.redisson.api.RedissonClient in project redisson by redisson.
the class RedissonRemoteServiceTest method testAsync.
@Test
public void testAsync() throws InterruptedException {
RedissonClient r1 = createInstance();
r1.getRemoteService().register(RemoteInterface.class, new RemoteImpl());
RedissonClient r2 = createInstance();
RemoteInterfaceAsync ri = r2.getRemoteService().get(RemoteInterfaceAsync.class);
RFuture<Void> f = ri.voidMethod("someName", 100L);
f.sync();
RFuture<Long> resFuture = ri.resultMethod(100L);
resFuture.sync();
assertThat(resFuture.getNow()).isEqualTo(200);
r1.shutdown();
r2.shutdown();
}
use of org.redisson.api.RedissonClient in project redisson by redisson.
the class RedissonTopicPatternTest method testListenerRemove.
@Test
public void testListenerRemove() throws InterruptedException {
RedissonClient redisson1 = BaseTest.createInstance();
RPatternTopic<Message> topic1 = redisson1.getPatternTopic("topic.*");
final CountDownLatch l = new CountDownLatch(1);
topic1.addListener(new BasePatternStatusListener() {
@Override
public void onPUnsubscribe(String pattern) {
Assert.assertEquals("topic.*", pattern);
l.countDown();
}
});
int id = topic1.addListener((pattern, channel, msg) -> {
Assert.fail();
});
RedissonClient redisson2 = BaseTest.createInstance();
RTopic<Message> topic2 = redisson2.getTopic("topic.t1");
topic1.removeListener(id);
topic2.publish(new Message("123"));
redisson1.shutdown();
redisson2.shutdown();
}
Aggregations