use of org.apache.flink.core.testutils.OneShotLatch in project flink by apache.
the class StreamTaskTest method testCancellationNotBlockedOnLock.
@Test
public void testCancellationNotBlockedOnLock() throws Exception {
SYNC_LATCH = new OneShotLatch();
StreamConfig cfg = new StreamConfig(new Configuration());
Task task = createTask(CancelLockingTask.class, cfg, new Configuration());
// start the task and wait until it runs
// execution state RUNNING is not enough, we need to wait until the stream task's run() method
// is entered
task.startTaskThread();
SYNC_LATCH.await();
// cancel the execution - this should lead to smooth shutdown
task.cancelExecution();
task.getExecutingThread().join();
assertEquals(ExecutionState.CANCELED, task.getExecutionState());
}
use of org.apache.flink.core.testutils.OneShotLatch in project flink by apache.
the class StreamTaskTest method testCancellationFailsWithBlockingLock.
@Test
public void testCancellationFailsWithBlockingLock() throws Exception {
SYNC_LATCH = new OneShotLatch();
StreamConfig cfg = new StreamConfig(new Configuration());
Task task = createTask(CancelFailingTask.class, cfg, new Configuration());
// start the task and wait until it runs
// execution state RUNNING is not enough, we need to wait until the stream task's run() method
// is entered
task.startTaskThread();
SYNC_LATCH.await();
// cancel the execution - this should lead to smooth shutdown
task.cancelExecution();
task.getExecutingThread().join();
assertEquals(ExecutionState.CANCELED, task.getExecutionState());
}
use of org.apache.flink.core.testutils.OneShotLatch in project flink by apache.
the class SystemProcessingTimeServiceTest method testExceptionReportingScheduleAtFixedRate.
@Test
public void testExceptionReportingScheduleAtFixedRate() throws InterruptedException {
final AtomicBoolean exceptionWasThrown = new AtomicBoolean(false);
final OneShotLatch latch = new OneShotLatch();
final Object lock = new Object();
ProcessingTimeService timeServiceProvider = new SystemProcessingTimeService(new AsyncExceptionHandler() {
@Override
public void handleAsyncException(String message, Throwable exception) {
exceptionWasThrown.set(true);
latch.trigger();
}
}, lock);
timeServiceProvider.scheduleAtFixedRate(new ProcessingTimeCallback() {
@Override
public void onProcessingTime(long timestamp) throws Exception {
throw new Exception("Exception in Timer");
}
}, 0L, 100L);
latch.await();
assertTrue(exceptionWasThrown.get());
}
use of org.apache.flink.core.testutils.OneShotLatch in project flink by apache.
the class SystemProcessingTimeServiceTest method testExceptionReporting.
@Test
public void testExceptionReporting() throws InterruptedException {
final AtomicBoolean exceptionWasThrown = new AtomicBoolean(false);
final OneShotLatch latch = new OneShotLatch();
final Object lock = new Object();
ProcessingTimeService timeServiceProvider = new SystemProcessingTimeService(new AsyncExceptionHandler() {
@Override
public void handleAsyncException(String message, Throwable exception) {
exceptionWasThrown.set(true);
latch.trigger();
}
}, lock);
timeServiceProvider.registerTimer(System.currentTimeMillis(), new ProcessingTimeCallback() {
@Override
public void onProcessingTime(long timestamp) throws Exception {
throw new Exception("Exception in Timer");
}
});
latch.await();
assertTrue(exceptionWasThrown.get());
}
use of org.apache.flink.core.testutils.OneShotLatch in project flink by apache.
the class SystemProcessingTimeServiceTest method testScheduleAtFixedRateHoldsLock.
/**
* Tests that the schedule at fixed rate callback is called under the given lock
*/
@Test
public void testScheduleAtFixedRateHoldsLock() throws Exception {
final Object lock = new Object();
final AtomicReference<Throwable> errorRef = new AtomicReference<>();
final SystemProcessingTimeService timer = new SystemProcessingTimeService(new ReferenceSettingExceptionHandler(errorRef), lock);
final OneShotLatch awaitCallback = new OneShotLatch();
try {
assertEquals(0, timer.getNumTasksScheduled());
// schedule something
ScheduledFuture<?> future = timer.scheduleAtFixedRate(new ProcessingTimeCallback() {
@Override
public void onProcessingTime(long timestamp) {
assertTrue(Thread.holdsLock(lock));
awaitCallback.trigger();
}
}, 0L, 100L);
// wait until the first execution is active
awaitCallback.await();
// cancel periodic callback
future.cancel(true);
// check that no asynchronous error was reported
if (errorRef.get() != null) {
throw new Exception(errorRef.get());
}
} finally {
timer.shutdownService();
}
}
Aggregations