Search in sources :

Example 1 with RedissonClient

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();
    }
}
Also used : RedissonClient(org.redisson.api.RedissonClient) Test(org.junit.Test)

Example 2 with RedissonClient

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();
    }
}
Also used : RedissonClient(org.redisson.api.RedissonClient) RemoteServiceTimeoutException(org.redisson.remote.RemoteServiceTimeoutException) RemoteServiceTimeoutException(org.redisson.remote.RemoteServiceTimeoutException) IOException(java.io.IOException) NotSerializableException(java.io.NotSerializableException) ExecutionException(java.util.concurrent.ExecutionException) RemoteServiceAckTimeoutException(org.redisson.remote.RemoteServiceAckTimeoutException) RemoteInvocationOptions(org.redisson.api.RemoteInvocationOptions) Test(org.junit.Test)

Example 3 with RedissonClient

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();
}
Also used : RedissonClient(org.redisson.api.RedissonClient) Test(org.junit.Test)

Example 4 with RedissonClient

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();
    }
}
Also used : RedissonClient(org.redisson.api.RedissonClient) RemoteServiceAckTimeoutException(org.redisson.remote.RemoteServiceAckTimeoutException) IOException(java.io.IOException) RemoteServiceTimeoutException(org.redisson.remote.RemoteServiceTimeoutException) IOException(java.io.IOException) NotSerializableException(java.io.NotSerializableException) ExecutionException(java.util.concurrent.ExecutionException) RemoteServiceAckTimeoutException(org.redisson.remote.RemoteServiceAckTimeoutException) RemoteInvocationOptions(org.redisson.api.RemoteInvocationOptions) Test(org.junit.Test)

Example 5 with RedissonClient

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();
    }
}
Also used : NotSerializableException(java.io.NotSerializableException) RedissonClient(org.redisson.api.RedissonClient) SerializationCodec(org.redisson.codec.SerializationCodec) RemoteServiceTimeoutException(org.redisson.remote.RemoteServiceTimeoutException) IOException(java.io.IOException) NotSerializableException(java.io.NotSerializableException) ExecutionException(java.util.concurrent.ExecutionException) RemoteServiceAckTimeoutException(org.redisson.remote.RemoteServiceAckTimeoutException) Test(org.junit.Test)

Aggregations

RedissonClient (org.redisson.api.RedissonClient)94 Test (org.junit.Test)87 Config (org.redisson.config.Config)44 RedisProcess (org.redisson.RedisRunner.RedisProcess)23 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)22 CountDownLatch (java.util.concurrent.CountDownLatch)15 ExecutorService (java.util.concurrent.ExecutorService)12 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)10 RLock (org.redisson.api.RLock)10 IOException (java.io.IOException)9 ExecutionException (java.util.concurrent.ExecutionException)9 NotSerializableException (java.io.NotSerializableException)8 RemoteServiceAckTimeoutException (org.redisson.remote.RemoteServiceAckTimeoutException)8 RemoteServiceTimeoutException (org.redisson.remote.RemoteServiceTimeoutException)8 ArrayList (java.util.ArrayList)4 HashMap (java.util.HashMap)4 RemoteInvocationOptions (org.redisson.api.RemoteInvocationOptions)4 NioEventLoopGroup (io.netty.channel.nio.NioEventLoopGroup)3 BasePatternStatusListener (org.redisson.api.listener.BasePatternStatusListener)3 SerializationCodec (org.redisson.codec.SerializationCodec)3