use of com.datastax.driver.mapping.option.WriteOptions in project cassandra-driver-mapping by valchkou.
the class MappingSessionAsyncTest 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);
ResultSetFuture f = target.saveAsync(obj);
f.getUninterruptibly();
EntityWithCollections loaded = target.get(EntityWithCollections.class, id);
assertEquals(2, loaded.getRefs().size());
f = target.appendAsync(id, EntityWithCollections.class, "refs", "56545sd4", wo);
f.getUninterruptibly();
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 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);
}
Aggregations