use of com.datastax.driver.core.ResultSetFuture in project cassandra-driver-mapping by valchkou.
the class MappingSessionAsyncTest method addToListTest.
@Test
public void addToListTest() 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.getTrades().size());
loaded.addTrade(200);
f = target.saveAsync(loaded);
f.getUninterruptibly();
loaded = target.get(EntityWithCollections.class, id);
assertTrue(loaded.getTrades().contains(200));
assertEquals(1, loaded.getTrades().size());
loaded.addTrade(300);
f = target.saveAsync(loaded);
f.getUninterruptibly();
loaded = target.get(EntityWithCollections.class, id);
assertTrue(loaded.getTrades().contains(300));
assertEquals(2, loaded.getTrades().size());
}
use of com.datastax.driver.core.ResultSetFuture 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);
}
use of com.datastax.driver.core.ResultSetFuture 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.core.ResultSetFuture in project cassandra-driver-mapping by valchkou.
the class MappingSessionAsyncTest method saveAndGetAndDeleteWithSimpleCompositeKeyTest.
@Test
public void saveAndGetAndDeleteWithSimpleCompositeKeyTest() throws Exception {
SimpleKey key = new SimpleKey();
key.setName("name");
key.setRank(10);
key.setT1(UUIDs.timeBased());
key.setT2(UUIDs.timeBased());
Date created = new Date();
EntityWithKey obj = new EntityWithKey();
obj.setKey(key);
obj.setTimestamp(1000);
obj.setAsof(created);
EntityWithKey loaded = target.get(EntityWithKey.class, key);
assertNull(loaded);
ResultSetFuture f = target.saveAsync(obj);
f.getUninterruptibly();
loaded = target.get(EntityWithKey.class, key);
assertEquals(obj, loaded);
f = target.deleteAsync(loaded);
f.getUninterruptibly();
loaded = target.get(EntityWithKey.class, key);
assertNull(loaded);
}
use of com.datastax.driver.core.ResultSetFuture in project cassandra-driver-mapping by valchkou.
the class MappingSessionAsyncTest method addToMapTest.
@Test
public void addToMapTest() 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.getRates().size());
loaded.addRate("200", new BigDecimal("100"));
f = target.saveAsync(loaded);
f.getUninterruptibly();
loaded = target.get(EntityWithCollections.class, id);
assertTrue(loaded.getRates().containsKey("200"));
assertEquals(1, loaded.getRates().size());
loaded.addRate("300", new BigDecimal("300"));
f = target.saveAsync(loaded);
f.getUninterruptibly();
loaded = target.get(EntityWithCollections.class, id);
assertTrue(loaded.getRates().containsKey("300"));
assertEquals(2, loaded.getRates().size());
}
Aggregations