Search in sources :

Example 66 with ResultSetFuture

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

Example 67 with ResultSetFuture

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);
}
Also used : WriteOptions(com.datastax.driver.mapping.option.WriteOptions) 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 68 with ResultSetFuture

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);
}
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) Test(org.junit.Test)

Example 69 with ResultSetFuture

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

Example 70 with ResultSetFuture

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