use of org.opensearch.common.util.concurrent.BaseFuture in project OpenSearch by opensearch-project.
the class MasterServiceTests 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<>();
try (MasterService clusterManagerService = createClusterManagerService(true)) {
clusterManagerService.submitStateUpdateTask("testBlockingCallInClusterStateTaskListenerFails", new Object(), ClusterStateTaskConfig.build(Priority.NORMAL), (currentState, tasks) -> {
ClusterState newClusterState = ClusterState.builder(currentState).build();
return ClusterStateTaskExecutor.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("Reason: [Blocking operation]"));
}
}
use of org.opensearch.common.util.concurrent.BaseFuture in project OpenSearch by opensearch-project.
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());
}
Aggregations