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));
}
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());
}
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"));
}
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());
}
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));
}
Aggregations