use of com.datastax.driver.mapping.option.WriteOptions in project cassandra-driver-mapping by valchkou.
the class MappingSessionTest 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);
target.withBatch().save(obj1).save(obj2).save(obj3, new WriteOptions().setTtl(10)).execute();
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.option.WriteOptions in project cassandra-driver-mapping by valchkou.
the class MappingSessionTest method saveAndGetWithOptionsTest.
@Test
public void saveAndGetWithOptionsTest() throws Exception {
UUID uuid = UUID.randomUUID();
Simple obj = new Simple();
obj.setTimestamp(new Date());
obj.setAge(55).setId(uuid);
Simple loaded = target.get(Simple.class, uuid);
assertNull(loaded);
WriteOptions so = new WriteOptions().setTtl(3).setTimestamp(42).setConsistencyLevel(ConsistencyLevel.ANY).setRetryPolicy(DefaultRetryPolicy.INSTANCE);
target.save(obj, so);
loaded = target.get(Simple.class, uuid);
assertEquals(obj, loaded);
Thread.sleep(3000);
loaded = target.get(Simple.class, uuid);
assertNull(loaded);
}
use of com.datastax.driver.mapping.option.WriteOptions in project cassandra-driver-mapping by valchkou.
the class MappingSessionTest method appendWithOptionsTest.
@Test
public void appendWithOptionsTest() throws Exception {
WriteOptions wo = new WriteOptions().setTtl(3);
UUID id = UUID.randomUUID();
EntityWithCollections obj = new EntityWithCollections();
obj.setId(id);
Set<String> refs = new HashSet<String>();
refs.add("100");
refs.add("abc");
obj.setRefs(refs);
target.save(obj);
EntityWithCollections loaded = target.get(EntityWithCollections.class, id);
assertEquals(2, loaded.getRefs().size());
target.append(id, EntityWithCollections.class, "refs", "56545sd4", wo);
loaded = target.get(EntityWithCollections.class, id);
assertTrue(loaded.getRefs().contains("56545sd4"));
assertEquals(3, loaded.getRefs().size());
sleep(3000);
loaded = target.get(EntityWithCollections.class, id);
assertEquals(2, loaded.getRefs().size());
assertFalse(loaded.getRefs().contains("56545sd4"));
}
use of com.datastax.driver.mapping.option.WriteOptions 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);
}
use of com.datastax.driver.mapping.option.WriteOptions in project cassandra-driver-mapping by valchkou.
the class MappingSessionAsyncTest method saveAndGetWithOptionsTest.
@Test
public void saveAndGetWithOptionsTest() throws Exception {
UUID uuid = UUID.randomUUID();
Simple obj = new Simple();
obj.setTimestamp(new Date());
obj.setAge(55).setId(uuid);
Simple loaded = target.get(Simple.class, uuid);
assertNull(loaded);
WriteOptions so = new WriteOptions().setTtl(3).setTimestamp(42).setConsistencyLevel(ConsistencyLevel.ANY).setRetryPolicy(DefaultRetryPolicy.INSTANCE);
ResultSetFuture f = target.saveAsync(obj, so);
f.getUninterruptibly();
loaded = target.get(Simple.class, uuid);
assertEquals(obj, loaded);
Thread.sleep(3000);
loaded = target.get(Simple.class, uuid);
assertNull(loaded);
}
Aggregations