Search in sources :

Example 1 with RLiveObjectService

use of org.redisson.api.RLiveObjectService in project redisson by redisson.

the class RedissonLiveObjectServiceTest method testNoTransformation.

@Test
public void testNoTransformation() {
    RLiveObjectService service = redisson.getLiveObjectService();
    TestClassNoTransformation ts = new TestClassNoTransformation();
    ts = service.persist(ts);
    HashMap<String, String> m = new HashMap<>();
    ts.setContent(m);
    assertTrue(HashMap.class.isAssignableFrom(ts.getContent().getClass()));
    assertFalse(RMap.class.isAssignableFrom(ts.getContent().getClass()));
    HashSet<String> s = new HashSet<>();
    ts.setContent(s);
    assertTrue(HashSet.class.isAssignableFrom(ts.getContent().getClass()));
    assertFalse(RSet.class.isAssignableFrom(ts.getContent().getClass()));
    TreeSet<String> ss = new TreeSet<>();
    ts.setContent(ss);
    assertTrue(TreeSet.class.isAssignableFrom(ts.getContent().getClass()));
    assertFalse(RSortedSet.class.isAssignableFrom(ts.getContent().getClass()));
    ArrayList<String> al = new ArrayList<>();
    ts.setContent(al);
    assertTrue(ArrayList.class.isAssignableFrom(ts.getContent().getClass()));
    assertFalse(RList.class.isAssignableFrom(ts.getContent().getClass()));
    ConcurrentHashMap<String, String> chm = new ConcurrentHashMap<>();
    ts.setContent(chm);
    assertTrue(ConcurrentHashMap.class.isAssignableFrom(ts.getContent().getClass()));
    assertFalse(RMap.class.isAssignableFrom(ts.getContent().getClass()));
    ArrayBlockingQueue<String> abq = new ArrayBlockingQueue<>(10);
    abq.add("111");
    ts.setContent(abq);
    assertTrue(ArrayBlockingQueue.class.isAssignableFrom(ts.getContent().getClass()));
    assertFalse(RBlockingQueue.class.isAssignableFrom(ts.getContent().getClass()));
    ConcurrentLinkedQueue<String> clq = new ConcurrentLinkedQueue<>();
    ts.setContent(clq);
    assertTrue(ConcurrentLinkedQueue.class.isAssignableFrom(ts.getContent().getClass()));
    assertFalse(RQueue.class.isAssignableFrom(ts.getContent().getClass()));
    LinkedBlockingDeque<String> lbdq = new LinkedBlockingDeque<>();
    ts.setContent(lbdq);
    assertTrue(LinkedBlockingDeque.class.isAssignableFrom(ts.getContent().getClass()));
    assertFalse(RBlockingDeque.class.isAssignableFrom(ts.getContent().getClass()));
    LinkedList<String> ll = new LinkedList<>();
    ts.setContent(ll);
    assertTrue(LinkedList.class.isAssignableFrom(ts.getContent().getClass()));
    assertFalse(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 2 with RLiveObjectService

use of org.redisson.api.RLiveObjectService in project redisson by redisson.

the class RedissonLiveObjectServiceTest method testFieldWithoutIdSetter.

@Test
public void testFieldWithoutIdSetter() {
    RLiveObjectService service = redisson.getLiveObjectService();
    SimpleObject so = new SimpleObject();
    so = service.persist(so);
    so.setValue(10L);
    so = redisson.getLiveObjectService().detach(so);
    assertThat(so.getId()).isNotNull();
    assertThat(so.getValue()).isEqualTo(10L);
    so = redisson.getLiveObjectService().get(SimpleObject.class, so.getId());
    assertThat(so.getId()).isNotNull();
    assertThat(so.getValue()).isEqualTo(10L);
}
Also used : RLiveObjectService(org.redisson.api.RLiveObjectService) Test(org.junit.Test)

Example 3 with RLiveObjectService

use of org.redisson.api.RLiveObjectService in project redisson by redisson.

the class RedissonLiveObjectServiceTest method test.

@Test
public void test() {
    RLiveObjectService service = redisson.getLiveObjectService();
    MyObject object = new MyObject(20L);
    try {
        service.attach(object);
    } catch (Exception e) {
        assertEquals("Non-null value is required for the field with RId annotation.", e.getMessage());
    }
}
Also used : RedisException(org.redisson.client.RedisException) RLiveObjectService(org.redisson.api.RLiveObjectService) Test(org.junit.Test)

Example 4 with RLiveObjectService

use of org.redisson.api.RLiveObjectService in project redisson by redisson.

the class RedissonLiveObjectServiceTest method testClassRegistration.

@Test
public void testClassRegistration() {
    RLiveObjectService service = redisson.getLiveObjectService();
    service.registerClass(TestClass.class);
    assertTrue(service.isClassRegistered(TestClass.class));
    RLiveObjectService newService = redisson.getLiveObjectService();
    assertTrue(newService.isClassRegistered(TestClass.class));
    RedissonClient newRedisson = Redisson.create(redisson.getConfig());
    assertFalse(newRedisson.getLiveObjectService().isClassRegistered(TestClass.class));
    newRedisson.shutdown(1, 5, TimeUnit.SECONDS);
}
Also used : RedissonClient(org.redisson.api.RedissonClient) RLiveObjectService(org.redisson.api.RLiveObjectService) Test(org.junit.Test)

Example 5 with RLiveObjectService

use of org.redisson.api.RLiveObjectService in project redisson by redisson.

the class RedissonLiveObjectServiceTest method testCreateObjectsInRuntime.

@Test
public void testCreateObjectsInRuntime() {
    RLiveObjectService service = redisson.getLiveObjectService();
    TestREntityWithMap so = new TestREntityWithMap();
    so = service.persist(so);
    so.getValue().put("1", "2");
    so = redisson.getLiveObjectService().detach(so);
    assertThat(so.getName()).isNotNull();
    assertThat(so.getValue()).containsKey("1");
    assertThat(so.getValue()).containsValue("2");
    so = redisson.getLiveObjectService().get(TestREntityWithMap.class, so.getName());
    assertThat(so.getName()).isNotNull();
    assertThat(so.getValue()).containsKey("1");
    assertThat(so.getValue()).containsValue("2");
}
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