Search in sources :

Example 1 with SerializationCodec

use of org.redisson.codec.SerializationCodec 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)

Example 2 with SerializationCodec

use of org.redisson.codec.SerializationCodec in project redisson by redisson.

the class RedissonLocalCachedMapSerializationCodecTest method createConfig.

public static Config createConfig() {
    Config config = RedissonLocalCachedMapTest.createConfig();
    config.setCodec(new SerializationCodec());
    return config;
}
Also used : Config(org.redisson.config.Config) SerializationCodec(org.redisson.codec.SerializationCodec)

Example 3 with SerializationCodec

use of org.redisson.codec.SerializationCodec in project redisson by redisson.

the class RedissonTest method testSer.

@Test(expected = RedisException.class)
public void testSer() {
    Config config = new Config();
    config.useSingleServer().setAddress(RedisRunner.getDefaultRedisServerBindAddressAndPort());
    config.setCodec(new SerializationCodec());
    RedissonClient r = Redisson.create(config);
    r.getMap("test").put("1", new Dummy());
}
Also used : RedissonClient(org.redisson.api.RedissonClient) Config(org.redisson.config.Config) SerializationCodec(org.redisson.codec.SerializationCodec) Test(org.junit.Test)

Aggregations

SerializationCodec (org.redisson.codec.SerializationCodec)3 Test (org.junit.Test)2 RedissonClient (org.redisson.api.RedissonClient)2 Config (org.redisson.config.Config)2 IOException (java.io.IOException)1 NotSerializableException (java.io.NotSerializableException)1 ExecutionException (java.util.concurrent.ExecutionException)1 RemoteServiceAckTimeoutException (org.redisson.remote.RemoteServiceAckTimeoutException)1 RemoteServiceTimeoutException (org.redisson.remote.RemoteServiceTimeoutException)1