use of org.redisson.api.RLiveObjectService in project redisson by redisson.
the class RedissonLiveObjectServiceTest method testBasics.
@Test
public void testBasics() {
RLiveObjectService s = redisson.getLiveObjectService();
TestREntity t = new TestREntity("1");
t = s.persist(t);
assertEquals("1", t.getName());
assertTrue(redisson.getMap(DefaultNamingScheme.INSTANCE.getName(TestREntity.class, String.class, "name", "1")).isExists());
t.setName("3333");
assertEquals("3333", t.getName());
assertTrue(redisson.getMap(DefaultNamingScheme.INSTANCE.getName(TestREntity.class, String.class, "name", "3333")).isExists());
t.setValue("111");
assertEquals("111", t.getValue());
assertTrue(redisson.getMap(DefaultNamingScheme.INSTANCE.getName(TestREntity.class, String.class, "name", "3333")).isExists());
assertTrue(!redisson.getMap(DefaultNamingScheme.INSTANCE.getName(TestREntity.class, String.class, "name", "1")).isExists());
assertEquals("111", redisson.getMap(DefaultNamingScheme.INSTANCE.getName(TestREntity.class, String.class, "name", "3333")).get("value"));
// ((RLiveObject) t).getLiveObjectLiveMap().put("value", "555");
// assertEquals("555", redisson.getMap(REntity.DefaultNamingScheme.INSTANCE.getName(TestREntity.class, "name", "3333")).get("value"));
// assertEquals("3333", ((RObject) t).getName());//field access takes priority over the implemented interface.
}
use of org.redisson.api.RLiveObjectService in project redisson by redisson.
the class RedissonLiveObjectServiceTest method testFieldAccessor.
@Test
public void testFieldAccessor() {
RLiveObjectService service = redisson.getLiveObjectService();
TestClass myObject = new TestClass();
myObject = service.persist(myObject);
myObject.setValue("123345");
assertEquals("123345", myObject.get("value"));
myObject.set("value", "9999");
assertEquals("9999", myObject.get("value"));
assertEquals("9999", myObject.getValue());
try {
myObject.get("555555");
} catch (Exception e) {
assertTrue(e instanceof NoSuchFieldException);
}
try {
myObject.set("555555", "999");
} catch (Exception e) {
assertTrue(e instanceof NoSuchFieldException);
}
}
use of org.redisson.api.RLiveObjectService in project redisson by redisson.
the class RedissonLiveObjectServiceTest method testSerializerable.
@Test
public void testSerializerable() {
RLiveObjectService service = redisson.getLiveObjectService();
TestClass t = new TestClass("55555");
t = service.persist(t);
assertTrue(Objects.equals("55555", t.getId()));
t = new TestClass(90909l);
t = service.persist(t);
assertTrue(Objects.equals(90909l, t.getId()));
t = new TestClass(90909);
t = service.persist(t);
assertTrue(Objects.equals(90909, t.getId()));
t = new TestClass(new ObjectId(9090909));
t = service.persist(t);
assertTrue(Objects.equals(new ObjectId(9090909), t.getId()));
t = new TestClass(new Byte("0"));
t = service.persist(t);
assertEquals(new Byte("0"), Byte.valueOf(t.getId().toString()));
t = new TestClass((byte) 90);
assertEquals((byte) 90, Byte.parseByte(t.getId().toString()));
t = new TestClass((Serializable) Arrays.asList(1, 2, 3, 4));
t = service.persist(t);
List<Integer> l = new ArrayList();
l.addAll(Arrays.asList(1, 2, 3, 4));
assertTrue(l.removeAll((List) t.getId()));
assertTrue(l.isEmpty());
try {
t = new TestClass(new int[] { 1, 2, 3, 4, 5 });
t = service.persist(t);
fail("Should not be here");
} catch (Exception e) {
assertEquals("RId value cannot be an array.", e.getMessage());
}
try {
t = new TestClass(new byte[] { 1, 2, 3, 4, 5 });
t = service.persist(t);
fail("Should not be here");
} catch (Exception e) {
assertEquals("RId value cannot be an array.", e.getMessage());
}
}
use of org.redisson.api.RLiveObjectService in project redisson by redisson.
the class RedissonLiveObjectServiceTest method testGet.
@Test
public void testGet() {
RLiveObjectService service = redisson.getLiveObjectService();
assertNull(service.get(TestClass.class, new ObjectId(100)));
TestClass ts = new TestClass(new ObjectId(100));
TestClass persisted = service.persist(ts);
assertNotNull(service.get(TestClass.class, new ObjectId(100)));
persisted.setCode("CODE");
assertNotNull(service.get(TestClass.class, new ObjectId(100)));
}
use of org.redisson.api.RLiveObjectService in project redisson by redisson.
the class RedissonLiveObjectServiceTest method testLiveObjectWithNestedLiveObjectAsId.
@Test
public void testLiveObjectWithNestedLiveObjectAsId() {
RLiveObjectService s = redisson.getLiveObjectService();
TestREntity t1 = new TestREntity("1");
t1 = s.persist(t1);
try {
s.persist(new TestREntityIdNested(t1));
fail("Should not be here");
} catch (Exception e) {
assertEquals("Field with RId annotation cannot be a type of which class is annotated with REntity.", e.getMessage());
}
}
Aggregations