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