@Override public void add( Collection<? extends IndexEntryUpdate<?>> updates ) { latch.waitForAllToStart(); }
@Override public void run() { latch.waitForAllToStart(); } } );
public void startAndWaitForAllToStart() { start(); waitForAllToStart(); }
@Override public void run() { count.incrementAndGet(); latch.waitForAllToStart(); latch.finish(); }
} ); storeScan.latch.waitForAllToStart(); job.cancel().get(); storeScan.latch.waitForAllToFinish();
jobLatch.waitForAllToStart(); testLatch.startAndWaitForAllToStart(); jobLatch.waitForAllToFinish(); testLatch.waitForAllToStart();
jobLatch.waitForAllToStart(); testLatch.startAndWaitForAllToStart(); jobLatch.waitForAllToFinish(); testLatch.waitForAllToStart();
} ).start(); latch.waitForAllToStart();
latch.waitForAllToStart(); transaction.markForTermination( Status.General.UnknownError ); latch.finish();
latch.waitForAllToStart(); } ).start(); waitingLatch.waitForAllToStart();
task1.latch.waitForAllToStart(); task2.latch.waitForAllToStart(); executor.submit( task3 ); executor.submit( task4 ); task1.latch.finish(); task2.latch.finish(); task3.latch.waitForAllToStart(); Thread.sleep( 200 ); // gosh, a Thread.sleep... assertEquals( 0, task4.executed );
@Test public void shouldShutDownOnTaskFailureEvenIfOtherTasksArePending() throws Exception { // GIVEN TaskExecutor<Void> executor = new DynamicTaskExecutor<>( 2, 0, 10, PARK, getClass().getSimpleName() ); IOException exception = new IOException( "Test message" ); ControlledTask firstBlockingTask = new ControlledTask(); ControlledTask secondBlockingTask = new ControlledTask(); executor.submit( firstBlockingTask ); executor.submit( secondBlockingTask ); firstBlockingTask.latch.waitForAllToStart(); secondBlockingTask.latch.waitForAllToStart(); FailingTask failingTask = new FailingTask( exception ); executor.submit( failingTask ); ControlledTask thirdBlockingTask = new ControlledTask(); executor.submit( thirdBlockingTask ); // WHEN firstBlockingTask.latch.finish(); failingTask.latch.await(); failingTask.latch.release(); // THEN assertExceptionOnSubmit( executor, exception ); executor.close(); // call would block if the shutdown as part of failure doesn't complete properly secondBlockingTask.latch.finish(); }
@Test public void shouldExecuteTasksInParallel() { // GIVEN TaskExecutor<Void> executor = new DynamicTaskExecutor<>( 2, 0, 5, PARK, getClass().getSimpleName() ); ControlledTask task1 = new ControlledTask(); TestTask task2 = new TestTask(); // WHEN executor.submit( task1 ); task1.latch.waitForAllToStart(); executor.submit( task2 ); //noinspection StatementWithEmptyBody while ( task2.executed == 0 ) { // Busy loop } task1.latch.finish(); //noinspection StatementWithEmptyBody while ( task1.executed == 0 ) { // Busy loop } executor.close(); // THEN assertEquals( 1, task1.executed ); assertEquals( 1, task2.executed ); }
@Test( expected = /* THEN */ IllegalStateException.class ) public void shouldNotDropWhileCreating() throws IOException { // GIVEN final DoubleLatch latch = new DoubleLatch(); final IndexProxy inner = new IndexProxyAdapter() { @Override public void start() { latch.startAndWaitForAllToStartAndFinish(); } }; final IndexProxy outer = newContractCheckingIndexProxy( inner ); // WHEN runInSeparateThread( outer::start ); try { latch.waitForAllToStart(); outer.drop(); } finally { latch.finish(); } }
@Test public void shouldIncrementNumberOfProcessorsWhenRunning() { // GIVEN TaskExecutor<Void> executor = new DynamicTaskExecutor<>( 1, 0, 5, PARK, getClass().getSimpleName() ); ControlledTask task1 = new ControlledTask(); TestTask task2 = new TestTask(); // WHEN executor.submit( task1 ); task1.latch.waitForAllToStart(); executor.submit( task2 ); executor.processors( 1 ); // now at 2 //noinspection StatementWithEmptyBody while ( task2.executed == 0 ) { // With one additional worker, the second task can execute even if task one is still executing } task1.latch.finish(); //noinspection StatementWithEmptyBody while ( task1.executed == 0 ) { // Busy loop } executor.close(); // THEN assertEquals( 1, task1.executed ); assertEquals( 1, task2.executed ); }
@Test( expected = /* THEN */ IllegalStateException.class ) public void shouldNotCloseWhileCreating() throws IOException { // GIVEN final DoubleLatch latch = new DoubleLatch(); final IndexProxy inner = new IndexProxyAdapter() { @Override public void start() { latch.startAndWaitForAllToStartAndFinish(); } }; final IndexProxy outer = newContractCheckingIndexProxy( inner ); // WHEN runInSeparateThread( outer::start ); try { latch.waitForAllToStart(); outer.close(); } finally { latch.finish(); } }
latch.waitForAllToStart(); try ( Transaction tx = kernel.beginTransaction( Transaction.Type.implicit, LoginContext.AUTH_DISABLED ) )
latch.waitForAllToStart();
@Test public void shouldBeAbleToDropIndexWhileItIsPopulating() { // GIVEN startDb(); DoubleLatch populationCompletionLatch = provider.installPopulationJobCompletionLatch(); IndexDefinition index = createIndex(); populationCompletionLatch.waitForAllToStart(); // await population job to start // WHEN dropIndex( index, populationCompletionLatch ); // THEN assertThat( getIndexes( db, myLabel ), inTx( db, hasSize( 0 ) ) ); try { getIndexState( db, index ); fail( "This index should have been deleted" ); } catch ( NotFoundException e ) { assertThat( e.getMessage(), CoreMatchers.containsString( myLabel.name() ) ); } }
@Test public void shouldTimeoutWaitingForIndexToComeOnline() { // given GraphDatabaseService db = rule.getGraphDatabaseAPI(); DoubleLatch latch = provider.installPopulationJobCompletionLatch(); IndexDefinition index; try ( Transaction tx = db.beginTx() ) { index = db.schema().indexFor( Label.label( "Person" ) ).on( "name" ).create(); tx.success(); } latch.waitForAllToStart(); // when try ( Transaction tx = db.beginTx() ) { // then db.schema().awaitIndexOnline( index, 1, TimeUnit.MILLISECONDS ); fail( "Expected IllegalStateException to be thrown" ); } catch ( IllegalStateException e ) { // good assertThat( e.getMessage(), containsString( "come online" ) ); } finally { latch.finish(); } }