Search in sources :

Example 1 with JsonJacksonCodec

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

the class RedissonMapCacheTest method testDeserializationErrorReturnsErrorImmediately.

@Test(timeout = 5000)
public void testDeserializationErrorReturnsErrorImmediately() throws Exception {
    redisson.getConfig().setCodec(new JsonJacksonCodec());
    RMapCache<String, SimpleObjectWithoutDefaultConstructor> map = redisson.getMapCache("deserializationFailure");
    SimpleObjectWithoutDefaultConstructor object = new SimpleObjectWithoutDefaultConstructor("test-val");
    Assert.assertEquals("test-val", object.getTestField());
    map.put("test-key", object);
    try {
        map.get("test-key");
        Assert.fail("Expected exception from map.get() call");
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : JsonJacksonCodec(org.redisson.codec.JsonJacksonCodec) ExecutionException(java.util.concurrent.ExecutionException) Test(org.junit.Test)

Example 2 with JsonJacksonCodec

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

the class RedissonMapTest method testDeserializationErrorReturnsErrorImmediately.

@Test(timeout = 5000)
public void testDeserializationErrorReturnsErrorImmediately() throws Exception {
    redisson.getConfig().setCodec(new JsonJacksonCodec());
    RMap<String, SimpleObjectWithoutDefaultConstructor> map = redisson.getMap("deserializationFailure");
    SimpleObjectWithoutDefaultConstructor object = new SimpleObjectWithoutDefaultConstructor("test-val");
    Assert.assertEquals("test-val", object.getTestField());
    map.put("test-key", object);
    try {
        map.get("test-key");
        Assert.fail("Expected exception from map.get() call");
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : JsonJacksonCodec(org.redisson.codec.JsonJacksonCodec) ExecutionException(java.util.concurrent.ExecutionException) Test(org.junit.Test)

Example 3 with JsonJacksonCodec

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

the class RedissonCodecTest method testListOfStrings.

@Test
public void testListOfStrings() {
    Config config = createConfig();
    config.setCodec(new JsonJacksonCodec());
    RedissonClient redisson = Redisson.create(config);
    RMap<String, List<String>> map = redisson.getMap("list of strings", jsonListOfStringCodec);
    map.put("foo", new ArrayList<String>(Arrays.asList("bar")));
    RMap<String, List<String>> map2 = redisson.getMap("list of strings", jsonListOfStringCodec);
    assertThat(map2).isEqualTo(map);
    redisson.shutdown();
}
Also used : JsonJacksonCodec(org.redisson.codec.JsonJacksonCodec) RedissonClient(org.redisson.api.RedissonClient) Config(org.redisson.config.Config) ArrayList(java.util.ArrayList) List(java.util.List) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)3 JsonJacksonCodec (org.redisson.codec.JsonJacksonCodec)3 ExecutionException (java.util.concurrent.ExecutionException)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 RedissonClient (org.redisson.api.RedissonClient)1 Config (org.redisson.config.Config)1