Merge branch 'master' of github.com:mrniko/redisson
commit
6bde9d2509
@ -0,0 +1,31 @@
|
||||
/**
|
||||
* Copyright 2014 Nikita Koksharov, Nickolay Borbit
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.redisson.codec;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.dataformat.cbor.CBORFactory;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Faye Li
|
||||
* @date 2015-10-16
|
||||
*/
|
||||
public class CborJacksonCodec extends JsonJacksonCodec {
|
||||
@Override
|
||||
protected ObjectMapper initObjectMapper() {
|
||||
return new ObjectMapper(new CBORFactory());
|
||||
}
|
||||
}
|
@ -0,0 +1,88 @@
|
||||
package org.redisson;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.redisson.client.codec.Codec;
|
||||
import org.redisson.codec.CborJacksonCodec;
|
||||
import org.redisson.codec.JsonJacksonCodec;
|
||||
import org.redisson.codec.KryoCodec;
|
||||
import org.redisson.codec.SerializationCodec;
|
||||
import org.redisson.core.RMap;
|
||||
|
||||
public class RedissonCodecTest extends BaseTest {
|
||||
private Codec codec = new SerializationCodec();
|
||||
private Codec kryoCodec = new KryoCodec();
|
||||
private Codec jsonCodec = new JsonJacksonCodec();
|
||||
private Codec cborCodec = new CborJacksonCodec();
|
||||
|
||||
@Test
|
||||
public void testJdk() {
|
||||
Config config = createConfig();
|
||||
config.setCodec(codec);
|
||||
redisson = Redisson.create(config);
|
||||
|
||||
test();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testJson() {
|
||||
Config config = createConfig();
|
||||
config.setCodec(jsonCodec);
|
||||
redisson = Redisson.create(config);
|
||||
|
||||
test();
|
||||
}
|
||||
|
||||
public void test() {
|
||||
RMap<Integer, Map<String, Object>> map = redisson.getMap("getAll");
|
||||
Map<String, Object> a = new HashMap<String, Object>();
|
||||
a.put("double", new Double(100000.0));
|
||||
a.put("float", 100.0f);
|
||||
a.put("int", 100);
|
||||
a.put("long", 10000000000L);
|
||||
a.put("boolt", true);
|
||||
a.put("boolf", false);
|
||||
a.put("string", "testString");
|
||||
a.put("array", Arrays.asList(1, 2.0, "adsfasdfsdf"));
|
||||
|
||||
map.fastPut(1, a);
|
||||
Map<String, Object> resa = map.get(1);
|
||||
Assert.assertEquals(a, resa);
|
||||
|
||||
Set<TestObject> set = redisson.getSet("set");
|
||||
|
||||
set.add(new TestObject("1", "2"));
|
||||
set.add(new TestObject("1", "2"));
|
||||
set.add(new TestObject("2", "3"));
|
||||
set.add(new TestObject("3", "4"));
|
||||
set.add(new TestObject("5", "6"));
|
||||
|
||||
Assert.assertTrue(set.contains(new TestObject("2", "3")));
|
||||
Assert.assertTrue(set.contains(new TestObject("1", "2")));
|
||||
Assert.assertFalse(set.contains(new TestObject("1", "9")));
|
||||
}
|
||||
|
||||
// @Test
|
||||
public void testKryo() {
|
||||
Config config = createConfig();
|
||||
config.setCodec(kryoCodec);
|
||||
redisson = Redisson.create(config);
|
||||
|
||||
test();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCbor() {
|
||||
Config config = createConfig();
|
||||
config.setCodec(cborCodec);
|
||||
redisson = Redisson.create(config);
|
||||
|
||||
test();
|
||||
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue