use of java.util.concurrent.ScheduledFuture in project elasticsearch by elastic.
the class AsyncBulkByScrollActionTests method testCancelWhileDelayedAfterScrollResponse.
/**
* Tests that we can cancel the request during its throttling delay. This can't use {@link #cancelTaskCase(Consumer)} because it needs
* to send the request un-canceled and cancel it at a specific time.
*/
public void testCancelWhileDelayedAfterScrollResponse() throws Exception {
String reason = randomSimpleString(random());
/*
* Replace the thread pool with one that will cancel the task as soon as anything is scheduled, which reindex tries to do when there
* is a delay.
*/
setupClient(new TestThreadPool(getTestName()) {
@Override
public ScheduledFuture<?> schedule(TimeValue delay, String name, Runnable command) {
/*
* This is called twice:
* 1. To schedule the throttling. When that happens we immediately cancel the task.
* 2. After the task is canceled.
* Both times we use delegate to the standard behavior so the task is scheduled as expected so it can be cancelled and all
* that good stuff.
*/
if (delay.nanos() > 0) {
generic().execute(() -> taskManager.cancel(testTask, reason, () -> {
}));
}
return super.schedule(delay, name, command);
}
});
// Send the scroll response which will trigger the custom thread pool above, canceling the request before running the response
DummyAsyncBulkByScrollAction action = new DummyAsyncBulkByScrollAction();
boolean previousScrollSet = usually();
if (previousScrollSet) {
action.setScroll(scrollId());
}
long total = randomIntBetween(0, Integer.MAX_VALUE);
ScrollableHitSource.Response response = new ScrollableHitSource.Response(false, emptyList(), total, emptyList(), null);
// Use a long delay here so the test will time out if the cancellation doesn't reschedule the throttled task
testTask.rethrottle(1);
simulateScrollResponse(action, timeValueNanos(System.nanoTime()), 1000, response);
// Now that we've got our cancel we'll just verify that it all came through all right
assertEquals(reason, listener.get(10, TimeUnit.SECONDS).getReasonCancelled());
if (previousScrollSet) {
// Canceled tasks always start to clear the scroll before they die.
assertThat(client.scrollsCleared, contains(scrollId));
}
}
use of java.util.concurrent.ScheduledFuture in project elasticsearch by elastic.
the class RemoteScrollableHitSourceTests method setUp.
@Before
@Override
public void setUp() throws Exception {
super.setUp();
final ExecutorService directExecutor = EsExecutors.newDirectExecutorService();
threadPool = new TestThreadPool(getTestName()) {
@Override
public ExecutorService executor(String name) {
return directExecutor;
}
@Override
public ScheduledFuture<?> schedule(TimeValue delay, String name, Runnable command) {
command.run();
return null;
}
};
retries = 0;
searchRequest = new SearchRequest();
searchRequest.scroll(timeValueMinutes(5));
searchRequest.source(new SearchSourceBuilder().size(10).version(true).sort("_doc").size(123));
retriesAllowed = 0;
}
use of java.util.concurrent.ScheduledFuture in project druid by druid-io.
the class RemoteTaskRunner method cancelWorkerCleanup.
private boolean cancelWorkerCleanup(String workerHost) {
ScheduledFuture previousCleanup = removedWorkerCleanups.remove(workerHost);
if (previousCleanup != null) {
log.info("Cancelling Worker[%s] scheduled task cleanup", workerHost);
previousCleanup.cancel(false);
}
return previousCleanup != null;
}
use of java.util.concurrent.ScheduledFuture in project elasticsearch by elastic.
the class ScheduleWithFixedDelayTests method testOnRejectionCausesCancellation.
public void testOnRejectionCausesCancellation() throws Exception {
final TimeValue delay = TimeValue.timeValueMillis(10L);
terminate(threadPool);
threadPool = new ThreadPool(Settings.builder().put(Node.NODE_NAME_SETTING.getKey(), "fixed delay tests").build()) {
@Override
public ScheduledFuture<?> schedule(TimeValue delay, String executor, Runnable command) {
if (command instanceof ReschedulingRunnable) {
((ReschedulingRunnable) command).onRejection(new EsRejectedExecutionException());
} else {
fail("this should only be called with a rescheduling runnable in this test");
}
return null;
}
};
Runnable runnable = () -> {
};
ReschedulingRunnable reschedulingRunnable = new ReschedulingRunnable(runnable, delay, Names.GENERIC, threadPool);
assertTrue(reschedulingRunnable.isCancelled());
}
use of java.util.concurrent.ScheduledFuture in project hazelcast by hazelcast.
the class DefaultPublisherContext method startRemovalTask.
private void startRemovalTask(final Collection<PartitionAccumulatorRegistry> removalCandidates, String uuid) {
QueryCacheScheduler queryCacheScheduler = context.getQueryCacheScheduler();
ScheduledFuture scheduledFuture = queryCacheScheduler.scheduleWithRepetition(new Runnable() {
@Override
public void run() {
for (PartitionAccumulatorRegistry registry : removalCandidates) {
removePartitionAccumulatorRegistry(registry);
}
}
}, ORPHANED_QUERY_CACHE_REMOVAL_DELAY_SECONDS);
ScheduledFuture prevFuture = removalCandidateFutures.put(uuid, scheduledFuture);
if (prevFuture != null) {
prevFuture.cancel(false);
}
}
Aggregations