Search in sources :

Example 1 with CacheValueHolder

use of com.alicp.jetcache.CacheValueHolder in project jetcache by alibaba.

the class AbstractEncoderTest method baseTest.

protected void baseTest() {
    Assert.assertEquals("123", decoder.apply(encoder.apply("123")));
    Assert.assertEquals(123, decoder.apply(encoder.apply(123)));
    Date date = new Date();
    Assert.assertEquals(date, decoder.apply(encoder.apply(date)));
    Assert.assertArrayEquals(new byte[] { 1, 2, 3, -1 }, (byte[]) decoder.apply(encoder.apply(new byte[] { 1, 2, 3, -1 })));
    Assert.assertNull(decoder.apply(encoder.apply(null)));
    testMap(new HashMap());
    testMap(new Hashtable());
    testMap(new ConcurrentHashMap());
    //        testMap(Collections.synchronizedMap(new HashMap()));
    testList(new ArrayList());
    testList(new Vector());
    testList(new LinkedList());
    testSet(new HashSet());
    testQueue(new LinkedBlockingQueue<>());
    //        testQueue(new ArrayBlockingQueue(10));
    testDeque(new LinkedBlockingDeque());
    TestObject q = new TestObject();
    q.setId(100);
    q.setEmail("aaa");
    q.setName("bbb");
    q.setData(new byte[] { 1, 2, 3 });
    Map<String, BigDecimal> m = new HashMap();
    m.put("12345", new BigDecimal(12345));
    byte[] bs = encoder.apply(q);
    TestObject q2 = (TestObject) decoder.apply(bs);
    compareTestObject(q, q2);
    bs = encoder.apply(new Object[] { q, 123 });
    Object[] o = (Object[]) decoder.apply(bs);
    q2 = (TestObject) o[0];
    Assert.assertEquals(123, o[1]);
    compareTestObject(q, q2);
    A a = new A();
    a.setList(new ArrayList<>());
    a.getList().add(q);
    CacheValueHolder<CacheValueHolder<A>> h = new CacheValueHolder(new CacheValueHolder(a, 1000), 1000);
    bs = encoder.apply(h);
    CacheValueHolder<CacheValueHolder<A>> h2 = (CacheValueHolder<CacheValueHolder<A>>) decoder.apply(bs);
    compareTestObject(h.getValue().getValue().getList().get(0), h2.getValue().getValue().getList().get(0));
}
Also used : LinkedBlockingDeque(java.util.concurrent.LinkedBlockingDeque) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) CacheValueHolder(com.alicp.jetcache.CacheValueHolder) BigDecimal(java.math.BigDecimal) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Aggregations

CacheValueHolder (com.alicp.jetcache.CacheValueHolder)1 BigDecimal (java.math.BigDecimal)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 LinkedBlockingDeque (java.util.concurrent.LinkedBlockingDeque)1