use of org.redisson.api.RLiveObjectService in project redisson by redisson.
the class RedissonLiveObjectServiceTest method testTransformation.
@Test
public void testTransformation() {
RLiveObjectService service = redisson.getLiveObjectService();
TestClass ts = new TestClass();
ts = service.persist(ts);
HashMap<String, String> m = new HashMap<>();
ts.setContent(m);
assertFalse(HashMap.class.isAssignableFrom(ts.getContent().getClass()));
assertTrue(RMap.class.isAssignableFrom(ts.getContent().getClass()));
HashSet<String> s = new HashSet<>();
ts.setContent(s);
assertFalse(HashSet.class.isAssignableFrom(ts.getContent().getClass()));
assertTrue(RSet.class.isAssignableFrom(ts.getContent().getClass()));
TreeSet<String> ss = new TreeSet<>();
ts.setContent(ss);
assertFalse(TreeSet.class.isAssignableFrom(ts.getContent().getClass()));
assertTrue(RSortedSet.class.isAssignableFrom(ts.getContent().getClass()));
ArrayList<String> al = new ArrayList<>();
ts.setContent(al);
assertFalse(ArrayList.class.isAssignableFrom(ts.getContent().getClass()));
assertTrue(RList.class.isAssignableFrom(ts.getContent().getClass()));
ConcurrentHashMap<String, String> chm = new ConcurrentHashMap<>();
ts.setContent(chm);
assertFalse(ConcurrentHashMap.class.isAssignableFrom(ts.getContent().getClass()));
assertTrue(RMap.class.isAssignableFrom(ts.getContent().getClass()));
ArrayBlockingQueue<String> abq = new ArrayBlockingQueue<>(10);
ts.setContent(abq);
assertFalse(ArrayBlockingQueue.class.isAssignableFrom(ts.getContent().getClass()));
assertTrue(RBlockingQueue.class.isAssignableFrom(ts.getContent().getClass()));
ConcurrentLinkedQueue<String> clq = new ConcurrentLinkedQueue<>();
ts.setContent(clq);
assertFalse(ConcurrentLinkedQueue.class.isAssignableFrom(ts.getContent().getClass()));
assertTrue(RQueue.class.isAssignableFrom(ts.getContent().getClass()));
LinkedBlockingDeque<String> lbdq = new LinkedBlockingDeque<>();
ts.setContent(lbdq);
assertFalse(LinkedBlockingDeque.class.isAssignableFrom(ts.getContent().getClass()));
assertTrue(RBlockingDeque.class.isAssignableFrom(ts.getContent().getClass()));
LinkedList<String> ll = new LinkedList<>();
ts.setContent(ll);
assertFalse(LinkedList.class.isAssignableFrom(ts.getContent().getClass()));
assertTrue(RDeque.class.isAssignableFrom(ts.getContent().getClass()));
}
use of org.redisson.api.RLiveObjectService in project redisson by redisson.
the class RedissonLiveObjectServiceTest method testLiveObjectWithCollection.
@Test
public void testLiveObjectWithCollection() {
RLiveObjectService s = redisson.getLiveObjectService();
TestREntityWithMap t = new TestREntityWithMap("2");
t = s.persist(t);
RMap<String, String> map = redisson.<String, String>getMap("testMap");
t.setValue(map);
map.put("field", "123");
TestREntityWithMap t2 = s.get(TestREntityWithMap.class, "2");
assertEquals("123", t2.getValue().get("field"));
TestREntityWithMap t3 = s.get(TestREntityWithMap.class, "2");
t3.getValue().put("field", "333");
t3 = s.get(TestREntityWithMap.class, "2");
assertEquals("333", t3.getValue().get("field"));
HashMap<String, String> map2 = new HashMap<>();
map2.put("field", "hello");
t.setValue(map2);
t3 = s.get(TestREntityWithMap.class, "2");
assertEquals("hello", t3.getValue().get("field"));
}
use of org.redisson.api.RLiveObjectService in project redisson by redisson.
the class RedissonLiveObjectServiceTest method testCreate.
@Test
public void testCreate() {
RLiveObjectService service = redisson.getLiveObjectService();
TestClass ts = new TestClass();
ts = service.persist(ts);
UUID uuid = UUID.fromString(ts.getId().toString());
assertEquals(4, uuid.version());
TestClassID1 tc1 = new TestClassID1();
tc1 = service.persist(tc1);
assertEquals(new Long(1), tc1.getName());
TestClassID2 tc2 = new TestClassID2();
tc2 = service.persist(tc2);
assertEquals(new Long(1), tc2.getName());
}
use of org.redisson.api.RLiveObjectService in project redisson by redisson.
the class RedissonLiveObjectServiceTest method testPersist.
@Test
public void testPersist() {
RLiveObjectService service = redisson.getLiveObjectService();
TestClass ts = new TestClass(new ObjectId(100));
ts.setValue("VALUE");
ts.setContent(new TestREntity("123"));
TestClass persisted = service.persist(ts);
assertEquals(2, redisson.getKeys().count());
assertEquals("123", ((TestREntity) persisted.getContent()).getName());
assertEquals(new ObjectId(100), persisted.getId());
assertEquals("VALUE", persisted.getValue());
try {
service.persist(ts);
fail("Should not be here");
} catch (Exception e) {
assertEquals("This REntity already exists.", e.getMessage());
}
}
use of org.redisson.api.RLiveObjectService in project redisson by redisson.
the class RedissonLiveObjectServiceTest method testDetach.
@Test
public void testDetach() {
RLiveObjectService service = redisson.getLiveObjectService();
TestClass ts = new TestClass(new ObjectId(100));
ts.setValue("VALUE");
ts.setCode("CODE");
TestClass merged = service.merge(ts);
assertEquals("VALUE", merged.getValue());
assertEquals("CODE", merged.getCode());
TestClass detach = service.detach(merged);
assertEquals(ts, detach);
}
Aggregations