@Override public void stop() { if ( monitorJobHandle != null ) { monitorJobHandle.cancel( true ); } } }
@Override public void stop() { jobHandle.cancel( false ); }
@Override public void stop() { if ( featureDecayJob != null ) { featureDecayJob.cancel( false ); } }
public void stop() { if ( backgroundSamplingHandle != null ) { backgroundSamplingHandle.cancel( true ); } jobTracker.stopAndAwaitAllJobs(); } }
@Override public void stop() { stopped = true; if ( handle != null ) { handle.cancel( false ); } waitOngoingCheckpointCompletion(); }
public void stop() { log.debug( "Stopping VM pause monitor" ); checkState( job != null, "VM pause monitor is not started" ); job.cancel( true ); job = null; }
@Override public void cancel( boolean mayInterruptIfRunning ) { set( FAILED ); JobHandle handle = latestHandle; if ( handle != null ) { handle.cancel( mayInterruptIfRunning ); } for ( CancelListener cancelListener : cancelListeners ) { cancelListener.cancelled( mayInterruptIfRunning ); } // Release the handle to allow waitTermination() to observe the cancellation. handleRelease.release(); }
@Test public void testRestart() { monitor.start(); monitor.stop(); monitor.start(); verify( jobScheduler, times( 2 ) ).schedule( any( Group.class ), any( Runnable.class ) ); verify( jobHandle ).cancel( eq( true ) ); }
@Test public void testStartAndStop() { monitor.start(); monitor.stop(); verify( jobScheduler ).schedule( any( Group.class ), any( Runnable.class ) ); verify( jobHandle ).cancel( eq( true ) ); }
@Test void startJobTransactionMonitor() { JobHandle jobHandle = Mockito.mock( JobHandle.class ); when( jobScheduler.scheduleRecurring( eq(Group.TRANSACTION_TIMEOUT_MONITOR ), eq( transactionMonitor), anyLong(), any(TimeUnit.class) )).thenReturn( jobHandle ); KernelTransactionMonitorScheduler monitorScheduler = new KernelTransactionMonitorScheduler( transactionMonitor, jobScheduler, 7 ); monitorScheduler.start(); verify(jobScheduler).scheduleRecurring( Group.TRANSACTION_TIMEOUT_MONITOR, transactionMonitor, 7, TimeUnit.MILLISECONDS ); monitorScheduler.stop(); verify( jobHandle ).cancel( true ); } }
for ( JobHandle handle : handles ) handle.cancel( false );
@Test public void shouldNotifyCancelListeners() { // GIVEN CentralJobScheduler centralJobScheduler = new CentralJobScheduler(); centralJobScheduler.init(); // WHEN AtomicBoolean halted = new AtomicBoolean(); Runnable job = () -> { while ( !halted.get() ) { LockSupport.parkNanos( MILLISECONDS.toNanos( 10 ) ); } }; JobHandle handle = centralJobScheduler.schedule( Group.INDEX_POPULATION, job ); handle.registerCancelListener( mayBeInterrupted -> halted.set( true ) ); handle.cancel( false ); // THEN assertTrue( halted.get() ); centralJobScheduler.shutdown(); }
handle.cancel( false );
@Test public void delayedTasksMustNotRunIfCancelledFirst() throws Exception { List<Boolean> cancelListener = new ArrayList<>(); JobHandle handle = scheduler.submit( Group.STORAGE_MAINTENANCE, counter::incrementAndGet, 100, 0 ); handle.registerCancelListener( cancelListener::add ); clock.forward( 90, TimeUnit.NANOSECONDS ); scheduler.tick(); handle.cancel( false ); clock.forward( 10, TimeUnit.NANOSECONDS ); scheduler.tick(); pools.getThreadPool( Group.STORAGE_MAINTENANCE ).shutDown(); assertThat( counter.get(), is( 0 ) ); assertThat( cancelListener, contains( Boolean.FALSE ) ); try { handle.waitTermination(); fail( "waitTermination should have thrown a CancellationException." ); } catch ( CancellationException ignore ) { // Good stuff. } }
@Test public void recurringTasksMustStopWhenCancelled() throws InterruptedException { List<Boolean> cancelListener = new ArrayList<>(); Runnable recurring = () -> { counter.incrementAndGet(); semaphore.release(); }; JobHandle handle = scheduler.submit( Group.STORAGE_MAINTENANCE, recurring, 100, 100 ); handle.registerCancelListener( cancelListener::add ); clock.forward( 100, TimeUnit.NANOSECONDS ); scheduler.tick(); assertSemaphoreAcquire(); clock.forward( 100, TimeUnit.NANOSECONDS ); scheduler.tick(); assertSemaphoreAcquire(); handle.cancel( true ); clock.forward( 100, TimeUnit.NANOSECONDS ); scheduler.tick(); clock.forward( 100, TimeUnit.NANOSECONDS ); scheduler.tick(); pools.getThreadPool( Group.STORAGE_MAINTENANCE ).shutDown(); assertThat( counter.get(), is( 2 ) ); assertThat( cancelListener, contains( Boolean.TRUE ) ); }
@Test public void shouldCancelRecurringJob() throws Exception { // Given long period = 2; life.start(); JobHandle jobHandle = scheduler.scheduleRecurring( Group.INDEX_POPULATION, countInvocationsJob, period, MILLISECONDS ); awaitFirstInvocation(); // When jobHandle.cancel( false ); try { jobHandle.waitTermination(); fail( "Task should be terminated" ); } catch ( CancellationException ignored ) { // task should be canceled } // Then int recorded = invocations.get(); sleep( period * 100 ); // we can have task that is already running during cancellation so lets count it as well assertThat( invocations.get(), both( greaterThanOrEqualTo( recorded ) ).and( lessThanOrEqualTo( recorded + 1 ) ) ); }
@Override public void stop() { jobHandle.cancel( false ); }
@Override public void stop() { stopped = true; if ( handle != null ) { handle.cancel( false ); } waitOngoingCheckpointCompletion(); }
public void stop() { if ( backgroundSamplingHandle != null ) { backgroundSamplingHandle.cancel( true ); } jobTracker.stopAndAwaitAllJobs(); } }
public void stop() { log.debug( "Stopping VM pause monitor" ); checkState( job != null, "VM pause monitor is not started" ); job.cancel( true ); job = null; }