Search in sources :

Example 71 with ResultSetFuture

use of com.datastax.driver.core.ResultSetFuture 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 72 with ResultSetFuture

use of com.datastax.driver.core.ResultSetFuture 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 73 with ResultSetFuture

use of com.datastax.driver.core.ResultSetFuture 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)

Example 74 with ResultSetFuture

use of com.datastax.driver.core.ResultSetFuture in project flink by apache.

the class CassandraOutputFormatBase method writeRecord.

@Override
public void writeRecord(OUT record) throws IOException {
    if (exception != null) {
        throw new IOException("write record failed", exception);
    }
    Object[] fields = extractFields(record);
    ResultSetFuture result = session.executeAsync(prepared.bind(fields));
    Futures.addCallback(result, callback);
}
Also used : ResultSetFuture(com.datastax.driver.core.ResultSetFuture) IOException(java.io.IOException)

Example 75 with ResultSetFuture

use of com.datastax.driver.core.ResultSetFuture in project newts by OpenNMS.

the class CassandraIndexerStressITCase method canIndexManyResources.

@Test
public void canIndexManyResources() {
    final int numResources = 20000;
    final int numSamplesPerResource = 3;
    // Setup the indexer
    ResultSetFuture future = mock(ResultSetFuture.class);
    CassandraSession session = mock(CassandraSession.class);
    when(session.executeAsync(any(Statement.class))).thenReturn(future);
    PreparedStatement preparedStatement = mock(PreparedStatement.class);
    BoundStatement boundStatement = mock(BoundStatement.class);
    when(session.prepare(any(RegularStatement.class))).thenReturn(preparedStatement);
    when(preparedStatement.bind()).thenReturn(boundStatement);
    when(boundStatement.setString(any(String.class), any(String.class))).thenReturn(boundStatement);
    ContextConfigurations contexts = new ContextConfigurations();
    MetricRegistry metrics = new MetricRegistry();
    CassandraIndexingOptions options = new CassandraIndexingOptions.Builder().withHierarchicalIndexing(true).build();
    ResourceIdSplitter resourceIdSplitter = new EscapableResourceIdSplitter();
    GuavaResourceMetadataCache cache = new GuavaResourceMetadataCache(numResources * 2, metrics);
    CassandraIndexer indexer = new CassandraIndexer(session, 0, cache, metrics, options, resourceIdSplitter, contexts);
    // Generate the resources and sample sets
    Resource[] resources = new Resource[numResources];
    List<List<Sample>> sampleSets = Lists.newArrayListWithCapacity(numResources);
    System.out.println("Building sample sets...");
    for (int i = 0; i < numResources; i++) {
        resources[i] = new Resource(String.format("snmp:%d:eth0-x:ifHcInOctets", i));
        List<Sample> samples = Lists.newArrayListWithCapacity(numSamplesPerResource);
        for (int j = 0; j < numSamplesPerResource; j++) {
            samples.add(new Sample(Timestamp.now(), resources[i], "y" + j, MetricType.COUNTER, new Counter(i * j)));
        }
        sampleSets.add(samples);
    }
    ;
    System.out.println("Done building sample sets.");
    // Index the resources and associated samples several times over
    for (int k = 0; k < 3; k++) {
        System.out.println("Indexing samples sets...");
        long start = System.currentTimeMillis();
        for (List<Sample> sampleSet : sampleSets) {
            indexer.update(sampleSet);
        }
        long elapsed = System.currentTimeMillis() - start;
        System.out.println("Done indexing samples in : " + elapsed + " ms");
    }
}
Also used : ResultSetFuture(com.datastax.driver.core.ResultSetFuture) RegularStatement(com.datastax.driver.core.RegularStatement) PreparedStatement(com.datastax.driver.core.PreparedStatement) BoundStatement(com.datastax.driver.core.BoundStatement) Statement(com.datastax.driver.core.Statement) Sample(org.opennms.newts.api.Sample) MetricRegistry(com.codahale.metrics.MetricRegistry) Resource(org.opennms.newts.api.Resource) CassandraSession(org.opennms.newts.cassandra.CassandraSession) PreparedStatement(com.datastax.driver.core.PreparedStatement) RegularStatement(com.datastax.driver.core.RegularStatement) Counter(org.opennms.newts.api.Counter) List(java.util.List) ContextConfigurations(org.opennms.newts.cassandra.ContextConfigurations) BoundStatement(com.datastax.driver.core.BoundStatement) 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