Search in sources :

Example 61 with ResultSetFuture

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);
}
Also used : ResultSetFuture(com.datastax.driver.core.ResultSetFuture) HashMap(java.util.HashMap) EntityWithCollectionsOverride(com.datastax.driver.mapping.entity.EntityWithCollectionsOverride) ArrayList(java.util.ArrayList) TreeMap(java.util.TreeMap) BigDecimal(java.math.BigDecimal) LinkedList(java.util.LinkedList) TreeSet(java.util.TreeSet) UUID(java.util.UUID) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 62 with ResultSetFuture

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);
}
Also used : CompositeKey(com.datastax.driver.mapping.entity.CompositeKey) EntityWithCompositeKey(com.datastax.driver.mapping.entity.EntityWithCompositeKey) ResultSetFuture(com.datastax.driver.core.ResultSetFuture) EntityWithCompositeKey(com.datastax.driver.mapping.entity.EntityWithCompositeKey) Date(java.util.Date) SimpleKey(com.datastax.driver.mapping.entity.SimpleKey) Test(org.junit.Test)

Example 63 with ResultSetFuture

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);
}
Also used : WriteOptions(com.datastax.driver.mapping.option.WriteOptions) ResultSetFuture(com.datastax.driver.core.ResultSetFuture) EntityWithTtl(com.datastax.driver.mapping.entity.EntityWithTtl) UUID(java.util.UUID) Date(java.util.Date) Simple(com.datastax.driver.mapping.entity.Simple) Test(org.junit.Test)

Example 64 with ResultSetFuture

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);
}
Also used : ResultSetFuture(com.datastax.driver.core.ResultSetFuture) EntityWithTtl(com.datastax.driver.mapping.entity.EntityWithTtl) UUID(java.util.UUID) Date(java.util.Date) Test(org.junit.Test)

Example 65 with ResultSetFuture

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));
}
Also used : ResultSetFuture(com.datastax.driver.core.ResultSetFuture) ArrayList(java.util.ArrayList) EntityWithCollections(com.datastax.driver.mapping.entity.EntityWithCollections) UUID(java.util.UUID) Test(org.junit.Test)

Aggregations

ResultSetFuture (com.datastax.driver.core.ResultSetFuture)78 Test (org.junit.Test)35 UUID (java.util.UUID)26 ResultSet (com.datastax.driver.core.ResultSet)20 EntityWithCollections (com.datastax.driver.mapping.entity.EntityWithCollections)13 BoundStatement (com.datastax.driver.core.BoundStatement)12 PreparedStatement (com.datastax.driver.core.PreparedStatement)10 ArrayList (java.util.ArrayList)8 Date (java.util.Date)8 Row (com.datastax.driver.core.Row)7 Statement (com.datastax.driver.core.Statement)7 List (java.util.List)6 Session (com.datastax.driver.core.Session)5 Simple (com.datastax.driver.mapping.entity.Simple)5 Cell (com.palantir.atlasdb.keyvalue.api.Cell)5 BigDecimal (java.math.BigDecimal)5 HashSet (java.util.HashSet)5 Result (com.datastax.driver.mapping.Result)4 WriteOptions (com.datastax.driver.mapping.option.WriteOptions)4 Nullable (javax.annotation.Nullable)4