Search in sources :

Example 11 with EntityWithCollections

use of com.datastax.driver.mapping.entity.EntityWithCollections 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 12 with EntityWithCollections

use of com.datastax.driver.mapping.entity.EntityWithCollections in project cassandra-driver-mapping by valchkou.

the class MappingSessionAsyncTest method addToSetTest.

@Test
public void addToSetTest() 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.getRefs().size());
    loaded.addRef("200");
    f = target.saveAsync(loaded);
    f.getUninterruptibly();
    loaded = target.get(EntityWithCollections.class, id);
    assertTrue(loaded.getRefs().contains("200"));
    assertEquals(1, loaded.getRefs().size());
    loaded.addRef("300");
    f = target.saveAsync(loaded);
    f.getUninterruptibly();
    loaded = target.get(EntityWithCollections.class, id);
    assertTrue(loaded.getRefs().contains("300"));
    assertEquals(2, loaded.getRefs().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 13 with EntityWithCollections

use of com.datastax.driver.mapping.entity.EntityWithCollections in project cassandra-driver-mapping by valchkou.

the class MappingSessionAsyncTest method appendToSetTest.

@Test
public void appendToSetTest() throws Exception {
    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");
    f.getUninterruptibly();
    loaded = target.get(EntityWithCollections.class, id);
    assertTrue(loaded.getRefs().contains("56545sd4"));
    assertEquals(3, loaded.getRefs().size());
}
Also used : 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)

Aggregations

ResultSetFuture (com.datastax.driver.core.ResultSetFuture)13 EntityWithCollections (com.datastax.driver.mapping.entity.EntityWithCollections)13 UUID (java.util.UUID)13 Test (org.junit.Test)13 ArrayList (java.util.ArrayList)5 BigDecimal (java.math.BigDecimal)4 HashSet (java.util.HashSet)4 HashMap (java.util.HashMap)3 WriteOptions (com.datastax.driver.mapping.option.WriteOptions)1