use of java.util.concurrent.ScheduledFuture in project camel by apache.
the class AmazonSQSClientMock method deleteMessage.
@Override
public DeleteMessageResult deleteMessage(DeleteMessageRequest deleteMessageRequest) throws AmazonClientException {
String receiptHandle = deleteMessageRequest.getReceiptHandle();
if (inFlight.containsKey(receiptHandle)) {
ScheduledFuture inFlightTask = inFlight.get(receiptHandle);
inFlightTask.cancel(true);
}
return new DeleteMessageResult();
}
use of java.util.concurrent.ScheduledFuture in project flink by apache.
the class TimerServiceTest method testUnregisterAllTimeouts.
/**
* Test all timeouts registered can be unregistered
* @throws Exception
*/
@Test
@SuppressWarnings("unchecked")
public void testUnregisterAllTimeouts() throws Exception {
// Prepare all instances.
ScheduledExecutorService scheduledExecutorService = mock(ScheduledExecutorService.class);
ScheduledFuture scheduledFuture = mock(ScheduledFuture.class);
when(scheduledExecutorService.schedule(any(Runnable.class), anyLong(), any(TimeUnit.class))).thenReturn(scheduledFuture);
TimerService<AllocationID> timerService = new TimerService<>(scheduledExecutorService, 100L);
TimeoutListener<AllocationID> listener = mock(TimeoutListener.class);
timerService.start(listener);
// Invoke register and unregister.
timerService.registerTimeout(new AllocationID(), 10, TimeUnit.SECONDS);
timerService.registerTimeout(new AllocationID(), 10, TimeUnit.SECONDS);
timerService.unregisterAllTimeouts();
// Verify.
Map<?, ?> timeouts = (Map<?, ?>) Whitebox.getInternalState(timerService, "timeouts");
assertTrue(timeouts.isEmpty());
verify(scheduledFuture, times(2)).cancel(true);
}
use of java.util.concurrent.ScheduledFuture in project hbase by apache.
the class JmxCacheBuster method stop.
/**
* Stops the clearing of JMX metrics and restarting the Hadoop metrics system. This is needed for
* some test environments where we manually inject sources or sinks dynamically.
*/
@VisibleForTesting
public static void stop() {
stopped.set(true);
ScheduledFuture future = fut.get();
future.cancel(false);
}
use of java.util.concurrent.ScheduledFuture in project spring-boot-admin by codecentric.
the class StatusUpdateApplicationListenerTest method test_start_stop.
@SuppressWarnings({ "unchecked", "rawtypes" })
@Test
public void test_start_stop() throws Exception {
StatusUpdater statusUpdater = mock(StatusUpdater.class);
ThreadPoolTaskScheduler scheduler = mock(ThreadPoolTaskScheduler.class);
StatusUpdateApplicationListener listener = new StatusUpdateApplicationListener(statusUpdater, scheduler);
ScheduledFuture task = mock(ScheduledFuture.class);
when(scheduler.scheduleAtFixedRate(isA(Runnable.class), eq(10_000L))).thenReturn(task);
listener.onApplicationReady(new ApplicationReadyEvent(mock(SpringApplication.class), null, mock(ConfigurableWebApplicationContext.class)));
verify(scheduler).scheduleAtFixedRate(isA(Runnable.class), eq(10_000L));
listener.onContextClosed(new ContextClosedEvent(mock(EmbeddedWebApplicationContext.class)));
verify(task).cancel(true);
}
use of java.util.concurrent.ScheduledFuture in project elasticsearch by elastic.
the class AsyncBulkByScrollActionTests method testScrollDelay.
public void testScrollDelay() throws Exception {
/*
* Replace the thread pool with one that will save the delay sent for the command. We'll use that to check that we used a proper
* delay for throttling.
*/
AtomicReference<TimeValue> capturedDelay = new AtomicReference<>();
AtomicReference<Runnable> capturedCommand = new AtomicReference<>();
setupClient(new TestThreadPool(getTestName()) {
@Override
public ScheduledFuture<?> schedule(TimeValue delay, String name, Runnable command) {
capturedDelay.set(delay);
capturedCommand.set(command);
return null;
}
});
DummyAsyncBulkByScrollAction action = new DummyAsyncBulkByScrollAction();
action.setScroll(scrollId());
// Set the base for the scroll to wait - this is added to the figure we calculate below
firstSearchRequest.scroll(timeValueSeconds(10));
// Set throttle to 1 request per second to make the math simpler
testTask.rethrottle(1f);
// Make the last batch look nearly instant but have 100 documents
action.startNextScroll(timeValueNanos(System.nanoTime()), 100);
// So the next request is going to have to wait an extra 100 seconds or so (base was 10 seconds, so 110ish)
assertThat(client.lastScroll.get().request.scroll().keepAlive().seconds(), either(equalTo(110L)).or(equalTo(109L)));
// Now we can simulate a response and check the delay that we used for the task
SearchHit hit = new SearchHit(0, "id", new Text("type"), emptyMap());
SearchHits hits = new SearchHits(new SearchHit[] { hit }, 0, 0);
InternalSearchResponse internalResponse = new InternalSearchResponse(hits, null, null, null, false, false, 1);
SearchResponse searchResponse = new SearchResponse(internalResponse, scrollId(), 5, 4, randomLong(), null);
if (randomBoolean()) {
client.lastScroll.get().listener.onResponse(searchResponse);
// The delay is still 100ish seconds because there hasn't been much time between when we requested the bulk and when we got it.
assertThat(capturedDelay.get().seconds(), either(equalTo(100L)).or(equalTo(99L)));
} else {
// Let's rethrottle between the starting the scroll and getting the response
testTask.rethrottle(10f);
client.lastScroll.get().listener.onResponse(searchResponse);
// The delay uses the new throttle
assertThat(capturedDelay.get().seconds(), either(equalTo(10L)).or(equalTo(9L)));
}
// Running the command ought to increment the delay counter on the task.
capturedCommand.get().run();
assertEquals(capturedDelay.get(), testTask.getStatus().getThrottled());
}
Aggregations