use of com.datastax.driver.core.ResultSetFuture in project cassandra-driver-mapping by valchkou.
the class MappingSessionAsyncTest method testCollectionsOverride.
@Test
public void testCollectionsOverride() throws Exception {
EntityWithCollectionsOverride obj = new EntityWithCollectionsOverride();
UUID uuid = UUID.randomUUID();
obj.setId(uuid);
ResultSetFuture f = target.saveAsync(obj);
f.getUninterruptibly();
EntityWithCollectionsOverride loaded = target.get(EntityWithCollectionsOverride.class, uuid);
Map<String, BigDecimal> map = new HashMap<String, BigDecimal>();
map.put("key1", new BigDecimal(100.55));
map.put("key1", new BigDecimal(100.55555));
map.put("key1", new BigDecimal(101.5500000333));
obj.setRates(map);
List<Integer> list = new ArrayList<Integer>();
list.add(100);
list.add(200);
list.add(300);
obj.setTrades(list);
Set<String> set = new HashSet<String>();
set.add("100");
set.add("200");
set.add("300");
obj.setRefs(set);
f = target.saveAsync(obj);
f.getUninterruptibly();
loaded = target.get(EntityWithCollectionsOverride.class, uuid);
assertTrue(loaded.getRates() instanceof TreeMap);
assertTrue(loaded.getRefs() instanceof TreeSet);
assertTrue(loaded.getTrades() instanceof LinkedList);
}
use of com.datastax.driver.core.ResultSetFuture in project cassandra-driver-mapping by valchkou.
the class MappingSessionAsyncTest method saveAndGetAndDeleteWithCompoundCompositeKeyTest.
@Test
public void saveAndGetAndDeleteWithCompoundCompositeKeyTest() throws Exception {
SimpleKey partition = new SimpleKey();
partition.setName("name");
partition.setRank(10);
partition.setT1(UUIDs.timeBased());
partition.setT2(UUIDs.timeBased());
CompositeKey key = new CompositeKey();
key.setKey(partition);
Date created = new Date();
key.setCreated(created);
key.setEmail("email@at");
EntityWithCompositeKey obj = new EntityWithCompositeKey();
obj.setKey(key);
obj.setTimestamp(1000);
obj.setAsof(created);
EntityWithCompositeKey loaded = target.get(EntityWithCompositeKey.class, key);
assertNull(loaded);
ResultSetFuture f = target.saveAsync(obj);
f.getUninterruptibly();
loaded = target.get(EntityWithCompositeKey.class, key);
assertEquals(obj, loaded);
f = target.deleteAsync(loaded);
f.getUninterruptibly();
loaded = target.get(EntityWithCompositeKey.class, key);
assertNull(loaded);
}
use of com.datastax.driver.core.ResultSetFuture 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);
}
use of com.datastax.driver.core.ResultSetFuture in project cassandra-driver-mapping by valchkou.
the class MappingSessionAsyncTest method saveAndGetWithDefaultTtlTest.
@Test
public void saveAndGetWithDefaultTtlTest() 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);
f.getUninterruptibly();
loaded = target.get(EntityWithTtl.class, uuid);
assertNotNull(loaded);
Thread.sleep(4000);
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 prependTest.
@Test
public void prependTest() throws Exception {
UUID id = UUID.randomUUID();
EntityWithCollections obj = new EntityWithCollections();
obj.setId(id);
List<Integer> trades = new ArrayList<Integer>();
trades.add(1);
trades.add(2);
obj.setTrades(trades);
ResultSetFuture f = target.saveAsync(obj);
f.getUninterruptibly();
EntityWithCollections loaded = target.get(EntityWithCollections.class, id);
assertEquals(2, loaded.getTrades().size());
List<Integer> adds = new ArrayList<Integer>();
adds.add(5);
adds.add(6);
f = target.prependAsync(id, EntityWithCollections.class, "trades", adds);
f.getUninterruptibly();
loaded = target.get(EntityWithCollections.class, id);
assertEquals(new Integer(6), loaded.getTrades().get(0));
assertEquals(new Integer(5), loaded.getTrades().get(1));
assertEquals(new Integer(1), loaded.getTrades().get(2));
assertEquals(new Integer(2), loaded.getTrades().get(3));
f = target.prependAsync(id, EntityWithCollections.class, "trades", 10);
f.getUninterruptibly();
loaded = target.get(EntityWithCollections.class, id);
assertEquals(new Integer(10), loaded.getTrades().get(0));
}
Aggregations