use of com.datastax.driver.mapping.entity.EntityWithCollections 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.entity.EntityWithCollections in project cassandra-driver-mapping by valchkou.
the class MappingSessionAsyncTest method addToSetTest.
@Test
public void addToSetTest() throws Exception {
UUID id = UUID.randomUUID();
EntityWithCollections obj = new EntityWithCollections();
obj.setId(id);
ResultSetFuture f = target.saveAsync(obj);
f.getUninterruptibly();
EntityWithCollections loaded = target.get(EntityWithCollections.class, id);
assertEquals(0, loaded.getRefs().size());
loaded.addRef("200");
f = target.saveAsync(loaded);
f.getUninterruptibly();
loaded = target.get(EntityWithCollections.class, id);
assertTrue(loaded.getRefs().contains("200"));
assertEquals(1, loaded.getRefs().size());
loaded.addRef("300");
f = target.saveAsync(loaded);
f.getUninterruptibly();
loaded = target.get(EntityWithCollections.class, id);
assertTrue(loaded.getRefs().contains("300"));
assertEquals(2, loaded.getRefs().size());
}
use of com.datastax.driver.mapping.entity.EntityWithCollections in project cassandra-driver-mapping by valchkou.
the class MappingSessionAsyncTest method appendToSetTest.
@Test
public void appendToSetTest() throws Exception {
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");
f.getUninterruptibly();
loaded = target.get(EntityWithCollections.class, id);
assertTrue(loaded.getRefs().contains("56545sd4"));
assertEquals(3, loaded.getRefs().size());
}
Aggregations