Search in sources :

Example 21 with RLiveObjectService

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()));
}
Also used : LinkedBlockingDeque(java.util.concurrent.LinkedBlockingDeque) HashMap(java.util.HashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) RQueue(org.redisson.api.RQueue) ArrayList(java.util.ArrayList) RMap(org.redisson.api.RMap) RBlockingQueue(org.redisson.api.RBlockingQueue) RLiveObjectService(org.redisson.api.RLiveObjectService) RBlockingDeque(org.redisson.api.RBlockingDeque) ArrayBlockingQueue(java.util.concurrent.ArrayBlockingQueue) RSet(org.redisson.api.RSet) TreeSet(java.util.TreeSet) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashSet(java.util.HashSet) LinkedList(java.util.LinkedList) RDeque(org.redisson.api.RDeque) RList(org.redisson.api.RList) RSortedSet(org.redisson.api.RSortedSet) ConcurrentLinkedQueue(java.util.concurrent.ConcurrentLinkedQueue) Test(org.junit.Test)

Example 22 with RLiveObjectService

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"));
}
Also used : HashMap(java.util.HashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) RLiveObjectService(org.redisson.api.RLiveObjectService) Test(org.junit.Test)

Example 23 with RLiveObjectService

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());
}
Also used : UUID(java.util.UUID) RLiveObjectService(org.redisson.api.RLiveObjectService) Test(org.junit.Test)

Example 24 with RLiveObjectService

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());
    }
}
Also used : RedisException(org.redisson.client.RedisException) RLiveObjectService(org.redisson.api.RLiveObjectService) Test(org.junit.Test)

Example 25 with RLiveObjectService

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);
}
Also used : RLiveObjectService(org.redisson.api.RLiveObjectService) Test(org.junit.Test)

Aggregations

RLiveObjectService (org.redisson.api.RLiveObjectService)30 Test (org.junit.Test)29 RedisException (org.redisson.client.RedisException)8 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 LinkedList (java.util.LinkedList)3 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)3 RList (org.redisson.api.RList)3 RLiveObject (org.redisson.api.RLiveObject)3 RObject (org.redisson.api.RObject)3 HashSet (java.util.HashSet)2 TreeSet (java.util.TreeSet)2 ArrayBlockingQueue (java.util.concurrent.ArrayBlockingQueue)2 ConcurrentLinkedQueue (java.util.concurrent.ConcurrentLinkedQueue)2 LinkedBlockingDeque (java.util.concurrent.LinkedBlockingDeque)2 RBlockingDeque (org.redisson.api.RBlockingDeque)2 RBlockingQueue (org.redisson.api.RBlockingQueue)2 RDeque (org.redisson.api.RDeque)2 RMap (org.redisson.api.RMap)2 RQueue (org.redisson.api.RQueue)2