use of com.datastax.driver.core.ResultSetFuture in project cassandra-driver-mapping by valchkou.
the class MappingSessionAsyncTest method batchTest.
@Test
public void batchTest() throws Exception {
UUID uuid1 = UUID.randomUUID();
Simple obj1 = new Simple();
obj1.setTimestamp(new Date());
obj1.setId(uuid1);
UUID uuid2 = UUID.randomUUID();
Simple obj2 = new Simple();
obj2.setTimestamp(new Date());
obj2.setId(uuid2);
ResultSetFuture f = target.saveAsync(obj2);
f.getUninterruptibly();
f = target.withBatch().save(obj1).delete(obj2).executeAsync();
f.getUninterruptibly();
Simple loaded1 = target.get(Simple.class, uuid1);
Simple loaded2 = target.get(Simple.class, uuid2);
assertNull(loaded2);
assertNotNull(loaded1);
}
use of com.datastax.driver.core.ResultSetFuture in project cassandra-driver-mapping by valchkou.
the class MappingSessionAsyncTest method appendToMapTest.
@Test
public void appendToMapTest() throws Exception {
UUID id = UUID.randomUUID();
EntityWithCollections obj = new EntityWithCollections();
obj.setId(id);
Map<String, BigDecimal> rates = new HashMap<String, BigDecimal>();
rates.put("abc", new BigDecimal(100));
rates.put("cde", new BigDecimal(10000.554154));
obj.setRates(rates);
ResultSetFuture f = target.saveAsync(obj);
f.getUninterruptibly();
EntityWithCollections loaded = target.get(EntityWithCollections.class, id);
assertEquals(2, loaded.getRates().size());
Map<String, BigDecimal> add = new HashMap<String, BigDecimal>();
add.put("bcd", new BigDecimal(0.000005555));
f = target.appendAsync(id, EntityWithCollections.class, "rates", add);
f.getUninterruptibly();
loaded = target.get(EntityWithCollections.class, id);
assertTrue(loaded.getRates().containsKey("bcd"));
assertEquals(new BigDecimal(0.000005555), loaded.getRates().get("bcd"));
assertEquals(3, loaded.getRates().size());
}
use of com.datastax.driver.core.ResultSetFuture in project cassandra-driver-mapping by valchkou.
the class MappingSessionAsyncTest method deleteTest.
@Test
public void deleteTest() throws Exception {
UUID id = UUID.randomUUID();
EntityWithCollections obj = new EntityWithCollections();
obj.setId(id);
Map<String, BigDecimal> rates = new HashMap<String, BigDecimal>();
rates.put("abc", new BigDecimal(100));
rates.put("cde", new BigDecimal(10000.554154));
obj.setRates(rates);
ResultSetFuture f = target.saveAsync(obj);
f.getUninterruptibly();
EntityWithCollections loaded = target.get(EntityWithCollections.class, id);
assertEquals(2, loaded.getRates().size());
f = target.deleteValueAsync(id, EntityWithCollections.class, "rates");
f.getUninterruptibly();
loaded = target.get(EntityWithCollections.class, id);
assertEquals(0, loaded.getRates().size());
}
use of com.datastax.driver.core.ResultSetFuture in project cassandra-driver-mapping by valchkou.
the class MappingSessionAsyncTest method appendAtTest.
@Test
public void appendAtTest() throws Exception {
UUID id = UUID.randomUUID();
EntityWithCollections obj = new EntityWithCollections();
obj.setId(id);
List<Integer> trades = new ArrayList<Integer>();
trades.add(100);
trades.add(200);
trades.add(300);
obj.setTrades(trades);
ResultSetFuture f = target.saveAsync(obj);
f.getUninterruptibly();
EntityWithCollections loaded = target.get(EntityWithCollections.class, id);
assertEquals(3, loaded.getTrades().size());
f = target.replaceAtAsync(id, EntityWithCollections.class, "trades", 3, 0);
f.getUninterruptibly();
loaded = target.get(EntityWithCollections.class, id);
assertEquals(new Integer(3), loaded.getTrades().get(0));
assertEquals(3, loaded.getTrades().size());
f = target.replaceAtAsync(id, EntityWithCollections.class, "trades", 33, 2);
f.getUninterruptibly();
loaded = target.get(EntityWithCollections.class, id);
assertEquals(new Integer(33), loaded.getTrades().get(2));
assertEquals(3, loaded.getTrades().size());
f = target.replaceAtAsync(id, EntityWithCollections.class, "trades", 22, 1);
f.getUninterruptibly();
loaded = target.get(EntityWithCollections.class, id);
assertEquals(new Integer(22), loaded.getTrades().get(1));
assertEquals(3, loaded.getTrades().size());
}
use of com.datastax.driver.core.ResultSetFuture in project cassandra-driver-mapping by valchkou.
the class MappingSessionAsyncTest method saveAndGetAndDeleteTest.
@Test
public void saveAndGetAndDeleteTest() throws Exception {
UUID uuid = UUID.randomUUID();
EntityWithIndexes obj = new EntityWithIndexes();
obj.setCount(100);
obj.setEmail("email@at");
obj.setName("test");
obj.setTimeStamp(new Date());
obj.setUuid(uuid);
EntityWithIndexes loaded = target.get(EntityWithIndexes.class, uuid);
assertNull(loaded);
ResultSetFuture f = target.saveAsync(obj);
f.getUninterruptibly();
loaded = target.get(EntityWithIndexes.class, uuid);
assertEquals(obj, loaded);
f = target.deleteAsync(loaded);
f.getUninterruptibly();
loaded = target.get(EntityWithIndexes.class, uuid);
assertNull(loaded);
}
Aggregations