Search in sources :

Example 6 with WriteOptions

use of com.datastax.driver.mapping.option.WriteOptions in project cassandra-driver-mapping by valchkou.

the class MappingSessionAsyncTest method appendWithOptionsTest.

@Test
public void appendWithOptionsTest() throws Exception {
    WriteOptions wo = new WriteOptions().setTtl(3);
    UUID id = UUID.randomUUID();
    EntityWithCollections obj = new EntityWithCollections();
    obj.setId(id);
    Set<String> refs = new HashSet<String>();
    refs.add("100");
    refs.add("abc");
    obj.setRefs(refs);
    ResultSetFuture f = target.saveAsync(obj);
    f.getUninterruptibly();
    EntityWithCollections loaded = target.get(EntityWithCollections.class, id);
    assertEquals(2, loaded.getRefs().size());
    f = target.appendAsync(id, EntityWithCollections.class, "refs", "56545sd4", wo);
    f.getUninterruptibly();
    loaded = target.get(EntityWithCollections.class, id);
    assertTrue(loaded.getRefs().contains("56545sd4"));
    assertEquals(3, loaded.getRefs().size());
    sleep(3000);
    loaded = target.get(EntityWithCollections.class, id);
    assertEquals(2, loaded.getRefs().size());
    assertFalse(loaded.getRefs().contains("56545sd4"));
}
Also used : WriteOptions(com.datastax.driver.mapping.option.WriteOptions) ResultSetFuture(com.datastax.driver.core.ResultSetFuture) EntityWithCollections(com.datastax.driver.mapping.entity.EntityWithCollections) UUID(java.util.UUID) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 7 with WriteOptions

use of com.datastax.driver.mapping.option.WriteOptions 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)

Aggregations

WriteOptions (com.datastax.driver.mapping.option.WriteOptions)7 ResultSetFuture (com.datastax.driver.core.ResultSetFuture)4 UUID (java.util.UUID)4 Test (org.junit.Test)4 Date (java.util.Date)3 EntityWithTtl (com.datastax.driver.mapping.entity.EntityWithTtl)2 Simple (com.datastax.driver.mapping.entity.Simple)2 EntityWithCollections (com.datastax.driver.mapping.entity.EntityWithCollections)1 HashSet (java.util.HashSet)1