use of com.datastax.driver.core.utils.MoreFutures.SuccessCallback in project java-driver by datastax.
the class MapperAsyncTest method should_get_query_async_without_blocking.
/**
* Validates that when using save, get and deleteAsync using the same executor as the caller that the driver
* does not block indefinitely in a netty worker thread.
*
* @jira_ticket JAVA-1070
* @test_category queries:async
* @test_category object_mapper
*/
@Test(groups = "short")
public void should_get_query_async_without_blocking() {
final CountDownLatch latch = new CountDownLatch(1);
// create a second cluster to perform everything asynchronously,
// including session initialization
Cluster cluster2 = register(createClusterBuilder().addContactPoints(getContactPoints()).withPort(ccm().getBinaryPort()).build());
ListenableFuture<MappingManager> mappingManagerFuture = Futures.transform(cluster2.connectAsync(), new Function<Session, MappingManager>() {
@Override
public MappingManager apply(Session session) {
return new MappingManager(session);
}
});
Futures.addCallback(mappingManagerFuture, new SuccessCallback<MappingManager>() {
@Override
public void onSuccess(MappingManager manager) {
final Mapper<User> mapper = manager.mapper(User.class);
ListenableFuture<Void> saveFuture = mapper.saveAsync(paul);
Futures.addCallback(saveFuture, new SuccessCallback<Void>() {
@Override
public void onSuccess(Void result) {
ListenableFuture<User> getFuture = mapper.getAsync(paul.getUserId());
Futures.addCallback(getFuture, new SuccessCallback<User>() {
@Override
public void onSuccess(User paul) {
Futures.addCallback(mapper.deleteAsync(paul), new SuccessCallback<Void>() {
@Override
public void onSuccess(Void result) {
latch.countDown();
}
});
}
});
}
});
}
});
try {
Uninterruptibles.awaitUninterruptibly(latch, 5, MINUTES);
} catch (Exception e) {
fail("Operation did not complete normally within 5 minutes");
}
}
Aggregations