/** * Tests that SystemProcessingTimeService#scheduleAtFixedRate is actually triggered multiple * times. */ @Test(timeout = 10000) public void testScheduleAtFixedRate() throws Exception { final Object lock = new Object(); final AtomicReference<Throwable> errorRef = new AtomicReference<>(); final long period = 10L; final int countDown = 3; final SystemProcessingTimeService timer = new SystemProcessingTimeService( new ReferenceSettingExceptionHandler(errorRef), lock); final CountDownLatch countDownLatch = new CountDownLatch(countDown); try { timer.scheduleAtFixedRate(new ProcessingTimeCallback() { @Override public void onProcessingTime(long timestamp) throws Exception { countDownLatch.countDown(); } }, 0L, period); countDownLatch.await(); if (errorRef.get() != null) { throw new Exception(errorRef.get()); } } finally { timer.shutdownService(); } }
@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()); }
@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()); }
@Test public void testTriggerHoldsLock() 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(), new ProcessingTimeCallback() { @Override public void onProcessingTime(long timestamp) { assertTrue(Thread.holdsLock(lock)); } }); // wait until the execution is over future.get(); assertEquals(0, timer.getNumTasksScheduled()); // check that no asynchronous error was reported if (errorRef.get() != null) { throw new Exception(errorRef.get()); } } finally { timer.shutdownService(); } }
final AtomicReference<Throwable> errorRef = new AtomicReference<>(); final SystemProcessingTimeService timer = new SystemProcessingTimeService( new ReferenceSettingExceptionHandler(errorRef), lock);
final AtomicReference<Throwable> errorRef = new AtomicReference<>(); final SystemProcessingTimeService timer = new SystemProcessingTimeService( new ReferenceSettingExceptionHandler(errorRef), lock);
final SystemProcessingTimeService timeService = new SystemProcessingTimeService( (message, exception) -> { },
final long period = 10L; final SystemProcessingTimeService timer = new SystemProcessingTimeService( new ReferenceSettingExceptionHandler(errorRef), lock);
final AtomicReference<Throwable> errorRef = new AtomicReference<>(); final SystemProcessingTimeService timer = new SystemProcessingTimeService( new ReferenceSettingExceptionHandler(errorRef), lock);
final AtomicReference<Throwable> errorRef = new AtomicReference<>(); final SystemProcessingTimeService timer = new SystemProcessingTimeService( new ReferenceSettingExceptionHandler(errorRef), lock);
"Time Trigger for " + getName(), getUserCodeClassLoader()); timerService = new SystemProcessingTimeService(this, getCheckpointLock(), timerThreadFactory);
new DispatcherThreadFactory(TRIGGER_THREAD_GROUP, "Time Trigger for " + getName()); timerService = new SystemProcessingTimeService(this, getCheckpointLock(), timerThreadFactory);
"Time Trigger for " + getName(), getUserCodeClassLoader()); timerService = new SystemProcessingTimeService(this, getCheckpointLock(), timerThreadFactory);
"Time Trigger for " + getName(), getUserCodeClassLoader()); timerService = new SystemProcessingTimeService(this, getCheckpointLock(), timerThreadFactory);