use of org.elasticsearch.common.util.concurrent.BaseFuture in project elasticsearch by elastic.
the class ScheduleWithFixedDelayTests method testBlockingCallOnSchedulerThreadFails.
public void testBlockingCallOnSchedulerThreadFails() throws Exception {
final BaseFuture<Object> future = new BaseFuture<Object>() {
};
final TestFuture resultsFuture = new TestFuture();
final boolean getWithTimeout = randomBoolean();
final Runnable runnable = () -> {
try {
Object obj;
if (getWithTimeout) {
obj = future.get(1L, TimeUnit.SECONDS);
} else {
obj = future.get();
}
resultsFuture.futureDone(obj);
} catch (Throwable t) {
resultsFuture.futureDone(t);
}
};
Cancellable cancellable = threadPool.scheduleWithFixedDelay(runnable, TimeValue.timeValueMillis(10L), Names.SAME);
Object resultingObject = resultsFuture.get();
assertNotNull(resultingObject);
assertThat(resultingObject, instanceOf(Throwable.class));
Throwable t = (Throwable) resultingObject;
assertThat(t, instanceOf(AssertionError.class));
assertThat(t.getMessage(), containsString("Blocking"));
assertFalse(cancellable.isCancelled());
}
use of org.elasticsearch.common.util.concurrent.BaseFuture in project elasticsearch by elastic.
the class ClusterServiceTests method testBlockingCallInClusterStateTaskListenerFails.
public void testBlockingCallInClusterStateTaskListenerFails() throws InterruptedException {
assumeTrue("assertions must be enabled for this test to work", BaseFuture.class.desiredAssertionStatus());
final CountDownLatch latch = new CountDownLatch(1);
final AtomicReference<AssertionError> assertionRef = new AtomicReference<>();
clusterService.submitStateUpdateTask("testBlockingCallInClusterStateTaskListenerFails", new Object(), ClusterStateTaskConfig.build(Priority.NORMAL), new ClusterStateTaskExecutor<Object>() {
@Override
public ClusterTasksResult<Object> execute(ClusterState currentState, List<Object> tasks) throws Exception {
ClusterState newClusterState = ClusterState.builder(currentState).build();
return ClusterTasksResult.builder().successes(tasks).build(newClusterState);
}
}, new ClusterStateTaskListener() {
@Override
public void clusterStateProcessed(String source, ClusterState oldState, ClusterState newState) {
BaseFuture<Void> future = new BaseFuture<Void>() {
};
try {
if (randomBoolean()) {
future.get(1L, TimeUnit.SECONDS);
} else {
future.get();
}
} catch (Exception e) {
throw new RuntimeException(e);
} catch (AssertionError e) {
assertionRef.set(e);
latch.countDown();
}
}
@Override
public void onFailure(String source, Exception e) {
}
});
latch.await();
assertNotNull(assertionRef.get());
assertThat(assertionRef.get().getMessage(), containsString("not be the cluster state update thread. Reason: [Blocking operation]"));
}
Aggregations