use of org.apache.flink.streaming.runtime.operators.TestProcessingTimeServiceTest.ReferenceSettingExceptionHandler in project flink by apache.
the class SystemProcessingTimeServiceTest method testQuiesceAndAwaitingCancelsScheduledAtFixRateFuture.
/**
* Tests that shutting down the SystemProcessingTimeService will also cancel the scheduled at
* fix rate future.
*/
@Test
public void testQuiesceAndAwaitingCancelsScheduledAtFixRateFuture() throws Exception {
final Object lock = new Object();
final AtomicReference<Throwable> errorRef = new AtomicReference<>();
final long period = 10L;
final SystemProcessingTimeService timer = new SystemProcessingTimeService(new ReferenceSettingExceptionHandler(errorRef), lock);
try {
ScheduledFuture<?> scheduledFuture = timer.scheduleAtFixedRate(new ProcessingTimeCallback() {
@Override
public void onProcessingTime(long timestamp) throws Exception {
}
}, 0L, period);
assertFalse(scheduledFuture.isDone());
// this should cancel our future
timer.quiesceAndAwaitPending();
assertTrue(scheduledFuture.isCancelled());
scheduledFuture = timer.scheduleAtFixedRate(new ProcessingTimeCallback() {
@Override
public void onProcessingTime(long timestamp) throws Exception {
throw new Exception("Test exception.");
}
}, 0L, 100L);
assertNotNull(scheduledFuture);
assertEquals(0, timer.getNumTasksScheduled());
if (errorRef.get() != null) {
throw new Exception(errorRef.get());
}
} finally {
timer.shutdownService();
}
}
use of org.apache.flink.streaming.runtime.operators.TestProcessingTimeServiceTest.ReferenceSettingExceptionHandler in project flink by apache.
the class SystemProcessingTimeServiceTest method testFutureCancellation.
@Test
public void testFutureCancellation() throws Exception {
final Object lock = new Object();
final AtomicReference<Throwable> errorRef = new AtomicReference<>();
final SystemProcessingTimeService timer = new SystemProcessingTimeService(new ReferenceSettingExceptionHandler(errorRef), lock);
try {
assertEquals(0, timer.getNumTasksScheduled());
// schedule something
ScheduledFuture<?> future = timer.registerTimer(System.currentTimeMillis() + 100000000, new ProcessingTimeCallback() {
@Override
public void onProcessingTime(long timestamp) {
}
});
assertEquals(1, timer.getNumTasksScheduled());
future.cancel(false);
assertEquals(0, timer.getNumTasksScheduled());
future = timer.scheduleAtFixedRate(new ProcessingTimeCallback() {
@Override
public void onProcessingTime(long timestamp) throws Exception {
}
}, 10000000000L, 50L);
assertEquals(1, timer.getNumTasksScheduled());
future.cancel(false);
assertEquals(0, timer.getNumTasksScheduled());
// check that no asynchronous error was reported
if (errorRef.get() != null) {
throw new Exception(errorRef.get());
}
} finally {
timer.shutdownService();
}
}
Aggregations