Search in sources :

Example 16 with RLiveObjectService

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

Example 17 with RLiveObjectService

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

Example 18 with RLiveObjectService

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());
    }
}
Also used : Serializable(java.io.Serializable) ArrayList(java.util.ArrayList) RList(org.redisson.api.RList) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List) RedisException(org.redisson.client.RedisException) RLiveObjectService(org.redisson.api.RLiveObjectService) Test(org.junit.Test)

Example 19 with RLiveObjectService

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

Example 20 with RLiveObjectService

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