Search in sources :

Example 31 with ResultSetFuture

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

Example 32 with ResultSetFuture

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

Example 33 with ResultSetFuture

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

Example 34 with ResultSetFuture

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());
}
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)

Example 35 with ResultSetFuture

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