use of com.datastax.driver.mapping.entity.EntityWithTtl in project cassandra-driver-mapping by valchkou.
the class MappingSessionAsyncTest method batchTtlTest.
@Test
public void batchTtlTest() throws Exception {
UUID uuid1 = UUID.randomUUID();
Simple obj1 = new Simple();
obj1.setTimestamp(new Date());
obj1.setId(uuid1);
UUID uuid2 = UUID.randomUUID();
EntityWithTtl obj2 = new EntityWithTtl();
obj2.setTimestamp(new Date());
obj2.setId(uuid2);
UUID uuid3 = UUID.randomUUID();
EntityWithTtl obj3 = new EntityWithTtl();
obj3.setTimestamp(new Date());
obj3.setId(uuid3);
ResultSetFuture f = target.withBatch().save(obj1).save(obj2).save(obj3, new WriteOptions().setTtl(10)).executeAsync();
f.getUninterruptibly();
Simple loaded1 = target.get(Simple.class, uuid1);
EntityWithTtl loaded2 = target.get(EntityWithTtl.class, uuid2);
EntityWithTtl loaded3 = target.get(EntityWithTtl.class, uuid3);
assertNotNull(loaded1);
assertNotNull(loaded2);
assertNotNull(loaded3);
Thread.sleep(5000);
loaded1 = target.get(Simple.class, uuid1);
loaded2 = target.get(EntityWithTtl.class, uuid2);
loaded3 = target.get(EntityWithTtl.class, uuid3);
assertNotNull(loaded1);
assertNull(loaded2);
assertNotNull(loaded3);
Thread.sleep(5000);
loaded1 = target.get(Simple.class, uuid1);
loaded2 = target.get(EntityWithTtl.class, uuid2);
loaded3 = target.get(EntityWithTtl.class, uuid3);
assertNotNull(loaded1);
assertNull(loaded2);
assertNull(loaded3);
target.delete(loaded1);
}
use of com.datastax.driver.mapping.entity.EntityWithTtl in project cassandra-driver-mapping by valchkou.
the class MappingSessionAsyncTest method saveAndGetWithDefaultTtlTest.
@Test
public void saveAndGetWithDefaultTtlTest() throws Exception {
UUID uuid = UUID.randomUUID();
EntityWithTtl obj = new EntityWithTtl();
obj.setTimestamp(new Date());
obj.setId(uuid);
EntityWithTtl loaded = target.get(EntityWithTtl.class, uuid);
assertNull(loaded);
ResultSetFuture f = target.saveAsync(obj);
f.getUninterruptibly();
loaded = target.get(EntityWithTtl.class, uuid);
assertNotNull(loaded);
Thread.sleep(4000);
loaded = target.get(EntityWithTtl.class, uuid);
assertNull(loaded);
}
use of com.datastax.driver.mapping.entity.EntityWithTtl in project cassandra-driver-mapping by valchkou.
the class MappingSessionAsyncTest method saveAndGetWithOverrideTtlTest.
@Test
public void saveAndGetWithOverrideTtlTest() throws Exception {
UUID uuid = UUID.randomUUID();
EntityWithTtl obj = new EntityWithTtl();
obj.setTimestamp(new Date());
obj.setId(uuid);
EntityWithTtl loaded = target.get(EntityWithTtl.class, uuid);
assertNull(loaded);
ResultSetFuture f = target.saveAsync(obj, new WriteOptions().setTtl(10));
f.getUninterruptibly();
// ttl is 10 sec. obj still should be alive
Thread.sleep(5000);
loaded = target.get(EntityWithTtl.class, uuid);
assertNotNull(loaded);
// 10 sec passed, obj should expire
Thread.sleep(5000);
loaded = target.get(EntityWithTtl.class, uuid);
assertNull(loaded);
}
Aggregations