Search in sources :

Example 6 with RLiveObjectService

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

the class RedissonLiveObjectServiceTest method testExpirable.

@Test
public void testExpirable() throws InterruptedException {
    RLiveObjectService service = redisson.getLiveObjectService();
    TestClass myObject = new TestClass();
    myObject = service.persist(myObject);
    myObject.setValue("123345");
    assertTrue(service.asLiveObject(myObject).isExists());
    service.asRExpirable(myObject).expire(1, TimeUnit.SECONDS);
    Thread.sleep(2000);
    assertFalse(service.asLiveObject(myObject).isExists());
}
Also used : RLiveObjectService(org.redisson.api.RLiveObjectService) Test(org.junit.Test)

Example 7 with RLiveObjectService

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

the class RedissonLiveObjectServiceTest method testRObject.

@Test
public void testRObject() {
    RLiveObjectService service = redisson.getLiveObjectService();
    TestClass myObject = new TestClass();
    myObject = service.persist(myObject);
    try {
        ((RObject) myObject).isExists();
    } catch (Exception e) {
        assertEquals("Please use RLiveObjectService instance for this type of functions", e.getMessage());
    }
}
Also used : RObject(org.redisson.api.RObject) RedisException(org.redisson.client.RedisException) RLiveObjectService(org.redisson.api.RLiveObjectService) Test(org.junit.Test)

Example 8 with RLiveObjectService

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

the class RedissonLiveObjectServiceTest method testStoreInnerObject.

@Test
public void testStoreInnerObject() {
    RLiveObjectService service = redisson.getLiveObjectService();
    ObjectWithList so = new ObjectWithList();
    so = service.persist(so);
    SimpleObject s = new SimpleObject();
    s = service.persist(s);
    so.setSo(s);
    assertThat(s.getId()).isNotNull();
    so.getObjects().add(s);
    so = redisson.getLiveObjectService().detach(so);
    assertThat(so.getSo().getId()).isEqualTo(s.getId());
    assertThat(so.getObjects().get(0).getId()).isEqualTo(so.getSo().getId());
}
Also used : RLiveObjectService(org.redisson.api.RLiveObjectService) Test(org.junit.Test)

Example 9 with RLiveObjectService

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

the class RedissonLiveObjectServiceTest method testAsLiveObject.

@Test
public void testAsLiveObject() {
    RLiveObjectService service = redisson.getLiveObjectService();
    TestClass instance = new TestClass(new ObjectId(100));
    instance = service.persist(instance);
    RLiveObject liveObject = service.asLiveObject(instance);
    assertEquals(new ObjectId(100), liveObject.getLiveObjectId());
    try {
        service.asLiveObject(new Object());
        fail("Should not be here");
    } catch (Exception e) {
        assertTrue(e instanceof ClassCastException);
    }
}
Also used : RLiveObject(org.redisson.api.RLiveObject) RObject(org.redisson.api.RObject) RLiveObject(org.redisson.api.RLiveObject) RedisException(org.redisson.client.RedisException) RLiveObjectService(org.redisson.api.RLiveObjectService) Test(org.junit.Test)

Example 10 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)

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