Search in sources :

Example 11 with RLiveObjectService

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

the class RedissonLiveObjectServiceTest method testRemoveByInstance.

@Test
public void testRemoveByInstance() {
    RLiveObjectService service = redisson.getLiveObjectService();
    TestClass ts = new TestClass(new ObjectId(100));
    ts.setCode("CODE");
    TestClass persisted = service.persist(ts);
    assertTrue(service.isExists(persisted));
    service.delete(persisted);
    assertFalse(service.isExists(persisted));
}
Also used : RLiveObjectService(org.redisson.api.RLiveObjectService) Test(org.junit.Test)

Example 12 with RLiveObjectService

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

the class RedissonLiveObjectServiceTest method testMerge.

@Test
public void testMerge() {
    RLiveObjectService service = redisson.getLiveObjectService();
    TestClass ts = new TestClass(new ObjectId(100));
    ts.setValue("VALUE");
    TestClass merged = service.merge(ts);
    assertEquals(new ObjectId(100), merged.getId());
    assertEquals("VALUE", merged.getValue());
    try {
        service.persist(ts);
        fail("Should not be here");
    } catch (Exception e) {
        assertEquals("This REntity already exists.", e.getMessage());
    }
    ts = new TestClass(new ObjectId(100));
    ts.setCode("CODE");
    merged = service.merge(ts);
    assertNull(ts.getValue());
    assertEquals("VALUE", merged.getValue());
    assertEquals("CODE", merged.getCode());
}
Also used : RedisException(org.redisson.client.RedisException) RLiveObjectService(org.redisson.api.RLiveObjectService) Test(org.junit.Test)

Example 13 with RLiveObjectService

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

the class RedissonLiveObjectServiceTest method testLiveObjectWithNestedLiveObjectAsValue.

@Test
public void testLiveObjectWithNestedLiveObjectAsValue() throws Exception {
    RLiveObjectService s = redisson.getLiveObjectService();
    TestREntityWithRMap t1 = new TestREntityWithRMap("111");
    t1 = s.persist(t1);
    TestREntityValueNested t2 = new TestREntityValueNested("122");
    t2 = s.persist(t2);
    RMap<String, String> map = redisson.<String, String>getMap("32123");
    t2.setValue(t1);
    t2.getValue().setValue(map);
    map.put("field", "123");
    assertEquals("123", s.get(TestREntityWithRMap.class, "111").getValue().get("field"));
    assertEquals("123", s.get(TestREntityValueNested.class, "122").getValue().getValue().get("field"));
}
Also used : RLiveObjectService(org.redisson.api.RLiveObjectService) Test(org.junit.Test)

Example 14 with RLiveObjectService

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

the class RedissonReferenceTest method testBasic.

@Test
public void testBasic() {
    RBucket<Object> b1 = redisson.getBucket("b1");
    RBucket<Object> b2 = redisson.getBucket("b2");
    RBucket<Object> b3 = redisson.getBucket("b3");
    b2.set(b3);
    b1.set(redisson.getBucket("b2"));
    assertTrue(b1.get().getClass().equals(RedissonBucket.class));
    assertEquals("b3", ((RBucket) ((RBucket) b1.get()).get()).getName());
    RBucket<Object> b4 = redisson.getBucket("b4");
    b4.set(redisson.getMapCache("testCache"));
    assertTrue(b4.get() instanceof RedissonMapCache);
    ((RedissonMapCache) b4.get()).fastPut(b1, b2, 1, TimeUnit.MINUTES);
    assertEquals("b2", ((RBucket) ((RedissonMapCache) b4.get()).get(b1)).getName());
    RBucket<Object> b5 = redisson.getBucket("b5");
    RLiveObjectService service = redisson.getLiveObjectService();
    RedissonLiveObjectServiceTest.TestREntity rlo = new RedissonLiveObjectServiceTest.TestREntity("123");
    rlo = service.persist(rlo);
    rlo.setName("t1");
    rlo.setValue("t2");
    b5.set(rlo);
    assertTrue(redisson.getBucket("b5").get() instanceof RLiveObject);
    assertEquals("t1", ((RedissonLiveObjectServiceTest.TestREntity) redisson.getBucket("b5").get()).getName());
    assertEquals("t2", ((RedissonLiveObjectServiceTest.TestREntity) redisson.getBucket("b5").get()).getValue());
}
Also used : RBucket(org.redisson.api.RBucket) RLiveObject(org.redisson.api.RLiveObject) RLiveObject(org.redisson.api.RLiveObject) RLiveObjectService(org.redisson.api.RLiveObjectService) Test(org.junit.Test)

Example 15 with RLiveObjectService

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

the class RedissonLiveObjectServiceTest method testIsPhantom.

@Test
public void testIsPhantom() {
    RLiveObjectService service = redisson.getLiveObjectService();
    assertFalse(service.isExists(new Object()));
    TestClass ts = new TestClass(new ObjectId(100));
    assertFalse(service.isExists(service.get(TestClass.class, new ObjectId(100))));
    assertFalse(service.isExists(ts));
    ts.setValue("VALUE");
    ts.setCode("CODE");
    TestClass persisted = service.persist(ts);
    assertTrue(service.isExists(service.get(TestClass.class, new ObjectId(100))));
    assertFalse(service.isExists(ts));
    assertTrue(service.isExists(persisted));
}
Also used : RObject(org.redisson.api.RObject) RLiveObject(org.redisson.api.RLiveObject) 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