Skip to content

Commit

Permalink
Rename methods in DoubleLatch to be more verbose and explicit
Browse files Browse the repository at this point in the history
o Also: Address warnings reported by IntelliJ IDEA
  • Loading branch information
boggle authored and systay committed Sep 6, 2016
1 parent a5aac0b commit b5675b7
Show file tree
Hide file tree
Showing 19 changed files with 193 additions and 244 deletions.
Expand Up @@ -50,7 +50,7 @@ public class SchemaIndexWaitingAcceptanceTest
protected void configure( GraphDatabaseFactory databaseFactory ) protected void configure( GraphDatabaseFactory databaseFactory )
{ {
List<KernelExtensionFactory<?>> extensions; List<KernelExtensionFactory<?>> extensions;
extensions = Collections.<KernelExtensionFactory<?>>singletonList( singleInstanceSchemaIndexProviderFactory( "test", provider ) ); extensions = Collections.singletonList( singleInstanceSchemaIndexProviderFactory( "test", provider ) );
((TestGraphDatabaseFactory) databaseFactory).addKernelExtensions( extensions ); ((TestGraphDatabaseFactory) databaseFactory).addKernelExtensions( extensions );
} }
}; };
Expand All @@ -69,7 +69,7 @@ public void shouldTimeoutWatingForIndexToComeOnline() throws Exception
tx.success(); tx.success();
} }


latch.awaitStart(); latch.waitForAllToStart();


// when // when
try ( Transaction tx = db.beginTx() ) try ( Transaction tx = db.beginTx() )
Expand Down Expand Up @@ -103,7 +103,7 @@ public void shouldTimeoutWatingForAllIndexesToComeOnline() throws Exception
tx.success(); tx.success();
} }


latch.awaitStart(); latch.waitForAllToStart();


// when // when
try ( Transaction tx = db.beginTx() ) try ( Transaction tx = db.beginTx() )
Expand Down
Expand Up @@ -73,7 +73,7 @@
@RunWith( Parameterized.class ) @RunWith( Parameterized.class )
public class KernelTransactionImplementationTest extends KernelTransactionTestBase public class KernelTransactionImplementationTest extends KernelTransactionTestBase
{ {
@Parameterized.Parameter( 0 ) @Parameterized.Parameter()
public Consumer<KernelTransaction> transactionInitializer; public Consumer<KernelTransaction> transactionInitializer;


@Parameterized.Parameter( 1 ) @Parameterized.Parameter( 1 )
Expand Down Expand Up @@ -329,14 +329,14 @@ public void shouldAllowTerminatingFromADifferentThread() throws Exception


Future<?> terminationFuture = Executors.newSingleThreadExecutor().submit( () -> Future<?> terminationFuture = Executors.newSingleThreadExecutor().submit( () ->
{ {
latch.awaitStart(); latch.waitForAllToStart();
transaction.markForTermination( Status.General.UnknownError ); transaction.markForTermination( Status.General.UnknownError );
latch.finish(); latch.finish();
} ); } );


// WHEN // WHEN
transaction.success(); transaction.success();
latch.startAndAwaitFinish(); latch.startAndWaitForAllToStartAndFinish();


assertNull( terminationFuture.get( 1, TimeUnit.MINUTES ) ); assertNull( terminationFuture.get( 1, TimeUnit.MINUTES ) );


Expand All @@ -356,6 +356,7 @@ public void shouldAllowTerminatingFromADifferentThread() throws Exception
verifyExtraInteractionWithTheMonitor( transactionMonitor, isWriteTx ); verifyExtraInteractionWithTheMonitor( transactionMonitor, isWriteTx );
} }


@SuppressWarnings( "unchecked" )
@Test @Test
public void shouldUseStartTimeAndTxIdFromWhenStartingTxAsHeader() throws Exception public void shouldUseStartTimeAndTxIdFromWhenStartingTxAsHeader() throws Exception
{ {
Expand All @@ -364,6 +365,7 @@ public void shouldUseStartTimeAndTxIdFromWhenStartingTxAsHeader() throws Excepti
when( legacyIndexState.hasChanges() ).thenReturn( true ); when( legacyIndexState.hasChanges() ).thenReturn( true );
doAnswer( invocation -> doAnswer( invocation ->
{ {
@SuppressWarnings( "unchecked" )
Collection<StorageCommand> commands = invocation.getArgumentAt( 0, Collection.class ); Collection<StorageCommand> commands = invocation.getArgumentAt( 0, Collection.class );
commands.add( mock( Command.class ) ); commands.add( mock( Command.class ) );
return null; return null;
Expand Down
Expand Up @@ -171,24 +171,17 @@ public void shouldNotCloseWhileCreating() throws IOException
@Override @Override
public void start() public void start()
{ {
latch.startAndAwaitFinish(); latch.startAndWaitForAllToStartAndFinish();
} }
}; };
final IndexProxy outer = newContractCheckingIndexProxy( inner ); final IndexProxy outer = newContractCheckingIndexProxy( inner );


// WHEN // WHEN
runInSeparateThread( new ThrowingRunnable() runInSeparateThread( () -> outer.start() );
{
@Override
public void run() throws IOException
{
outer.start();
}
} );


try try
{ {
latch.awaitStart(); latch.waitForAllToStart();
outer.close(); outer.close();
} }
finally finally
Expand All @@ -207,24 +200,17 @@ public void shouldNotDropWhileCreating() throws IOException
@Override @Override
public void start() public void start()
{ {
latch.startAndAwaitFinish(); latch.startAndWaitForAllToStartAndFinish();
} }
}; };
final IndexProxy outer = newContractCheckingIndexProxy( inner ); final IndexProxy outer = newContractCheckingIndexProxy( inner );


// WHEN // WHEN
runInSeparateThread( new ThrowingRunnable() runInSeparateThread( () -> outer.start() );
{
@Override
public void run() throws IOException
{
outer.start();
}
} );


try try
{ {
latch.awaitStart(); latch.waitForAllToStart();
outer.drop(); outer.drop();
} }
finally finally
Expand All @@ -250,26 +236,22 @@ public IndexUpdater newUpdater( IndexUpdateMode mode )
outer.start(); outer.start();


// WHEN // WHEN
runInSeparateThread( new ThrowingRunnable() runInSeparateThread( () ->
{ {
@Override try (IndexUpdater updater = outer.newUpdater( IndexUpdateMode.ONLINE ))
public void run() throws IOException
{ {
try (IndexUpdater updater = outer.newUpdater( IndexUpdateMode.ONLINE )) updater.process( null );
{ latch.startAndWaitForAllToStartAndFinish();
updater.process( null ); }
latch.startAndAwaitFinish(); catch ( IndexEntryConflictException e )
} {
catch ( IndexEntryConflictException e ) throw new RuntimeException( e );
{
throw new RuntimeException( e );
}
} }
} ); } );


try try
{ {
latch.awaitStart(); latch.waitForAllToStart();
outer.close(); outer.close();
} }
finally finally
Expand All @@ -288,25 +270,18 @@ public void shouldNotCloseWhileForcing() throws IOException
@Override @Override
public void force() public void force()
{ {
latch.startAndAwaitFinish(); latch.startAndWaitForAllToStartAndFinish();
} }
}; };
final IndexProxy outer = newContractCheckingIndexProxy( inner ); final IndexProxy outer = newContractCheckingIndexProxy( inner );
outer.start(); outer.start();


// WHEN // WHEN
runInSeparateThread( new ThrowingRunnable() runInSeparateThread( () -> outer.force() );
{
@Override
public void run() throws IOException
{
outer.force();
}
} );


try try
{ {
latch.awaitStart(); latch.waitForAllToStart();
outer.close(); outer.close();
} }
finally finally
Expand All @@ -322,19 +297,15 @@ private interface ThrowingRunnable


private void runInSeparateThread( final ThrowingRunnable action ) private void runInSeparateThread( final ThrowingRunnable action )
{ {
new Thread( new Runnable() new Thread( () ->
{ {
@Override try
public void run() {
action.run();
}
catch ( IOException e )
{ {
try throw new RuntimeException( e );
{
action.run();
}
catch ( IOException e )
{
throw new RuntimeException( e );
}
} }
} ).start(); } ).start();
} }
Expand Down
Expand Up @@ -49,8 +49,8 @@ public class ControlledPopulationSchemaIndexProvider extends SchemaIndexProvider
private final IndexAccessor mockedWriter = mock( IndexAccessor.class ); private final IndexAccessor mockedWriter = mock( IndexAccessor.class );
private final CountDownLatch writerLatch = new CountDownLatch( 1 ); private final CountDownLatch writerLatch = new CountDownLatch( 1 );
private InternalIndexState initialIndexState = POPULATING; private InternalIndexState initialIndexState = POPULATING;
public final AtomicInteger populatorCallCount = new AtomicInteger(); final AtomicInteger populatorCallCount = new AtomicInteger();
public final AtomicInteger writerCallCount = new AtomicInteger(); final AtomicInteger writerCallCount = new AtomicInteger();


public static final SchemaIndexProvider.Descriptor PROVIDER_DESCRIPTOR = new SchemaIndexProvider.Descriptor( public static final SchemaIndexProvider.Descriptor PROVIDER_DESCRIPTOR = new SchemaIndexProvider.Descriptor(
"controlled-population", "1.0" ); "controlled-population", "1.0" );
Expand All @@ -70,7 +70,7 @@ public DoubleLatch installPopulationJobCompletionLatch()
@Override @Override
public void create() throws IOException public void create() throws IOException
{ {
populationCompletionLatch.startAndAwaitFinish(); populationCompletionLatch.startAndWaitForAllToStartAndFinish();
super.create(); super.create();
} }


Expand Down
Expand Up @@ -295,7 +295,7 @@ public void shouldBeAbleToCancelPopulationJob() throws Exception
IndexStoreView storeView = mock( IndexStoreView.class ); IndexStoreView storeView = mock( IndexStoreView.class );
ControlledStoreScan storeScan = new ControlledStoreScan(); ControlledStoreScan storeScan = new ControlledStoreScan();
when( storeView.visitNodes( any( IntPredicate.class ), any( IntPredicate.class ), when( storeView.visitNodes( any( IntPredicate.class ), any( IntPredicate.class ),
Matchers.<Visitor<NodePropertyUpdates,RuntimeException>>any(), Matchers.any(),
Matchers.<Visitor<NodeLabelUpdate,RuntimeException>>any()) ) Matchers.<Visitor<NodeLabelUpdate,RuntimeException>>any()) )
.thenReturn(storeScan ); .thenReturn(storeScan );


Expand All @@ -305,21 +305,21 @@ public void shouldBeAbleToCancelPopulationJob() throws Exception
OtherThreadExecutor<Void> populationJobRunner = cleanup.add( new OtherThreadExecutor<Void>( OtherThreadExecutor<Void> populationJobRunner = cleanup.add( new OtherThreadExecutor<Void>(
"Population job test runner", null ) ); "Population job test runner", null ) );
Future<Void> runFuture = populationJobRunner Future<Void> runFuture = populationJobRunner
.executeDontWait( (WorkerCommand<Void,Void>) state -> { .executeDontWait( state -> {
job.run(); job.run();
return null; return null;
} ); } );


storeScan.latch.awaitStart(); storeScan.latch.waitForAllToStart();
job.cancel().get(); job.cancel().get();
storeScan.latch.awaitFinish(); storeScan.latch.waitForAllToFinish();


// WHEN // WHEN
runFuture.get(); runFuture.get();


// THEN // THEN
verify( populator, times( 1 ) ).close( false ); verify( populator, times( 1 ) ).close( false );
verify( index, times( 0 ) ).flip( Matchers.<Callable<Void>>any(), Matchers.<FailedIndexProxyFactory>any() ); verify( index, times( 0 ) ).flip( Matchers.any(), Matchers.any() );


// AND ALSO // AND ALSO
assertDoubleLongEquals( 0, 0, indexUpdatesAndSize( FIRST, name ) ); assertDoubleLongEquals( 0, 0, indexUpdatesAndSize( FIRST, name ) );
Expand Down Expand Up @@ -456,7 +456,7 @@ private static class ControlledStoreScan implements StoreScan<RuntimeException>
@Override @Override
public void run() public void run()
{ {
latch.startAndAwaitFinish(); latch.startAndWaitForAllToStartAndFinish();
} }


@Override @Override
Expand All @@ -481,8 +481,7 @@ private class NodeChangingWriter extends IndexPopulator.Adapter
private final Object previousValue; private final Object previousValue;
private final int label, propertyKeyId; private final int label, propertyKeyId;


public NodeChangingWriter( long nodeToChange, int propertyKeyId, Object previousValue, Object newValue, NodeChangingWriter( long nodeToChange, int propertyKeyId, Object previousValue, Object newValue, int label )
int label )
{ {
this.nodeToChange = nodeToChange; this.nodeToChange = nodeToChange;
this.propertyKeyId = propertyKeyId; this.propertyKeyId = propertyKeyId;
Expand Down Expand Up @@ -553,7 +552,7 @@ private class NodeDeletingWriter extends IndexPopulator.Adapter
private final Object valueToDelete; private final Object valueToDelete;
private final int label; private final int label;


public NodeDeletingWriter( long nodeToDelete, int propertyKeyId, Object valueToDelete, int label ) NodeDeletingWriter( long nodeToDelete, int propertyKeyId, Object valueToDelete, int label )
{ {
this.nodeToDelete = nodeToDelete; this.nodeToDelete = nodeToDelete;
this.propertyKeyId = propertyKeyId; this.propertyKeyId = propertyKeyId;
Expand Down
Expand Up @@ -67,8 +67,9 @@ public void before() throws Exception
{ {
factory = new TestGraphDatabaseFactory(); factory = new TestGraphDatabaseFactory();
factory.setFileSystem( fs.get() ); factory.setFileSystem( fs.get() );
factory.addKernelExtensions( Collections.<KernelExtensionFactory<?>>singletonList( factory.addKernelExtensions( Collections.singletonList(
singleInstanceSchemaIndexProviderFactory( "test", provider ) ) ); singleInstanceSchemaIndexProviderFactory( "test", provider )
) );
} }


@After @After
Expand All @@ -88,7 +89,7 @@ public void shouldBeAbleToDropIndexWhileItIsPopulating() throws Exception
startDb(); startDb();
DoubleLatch populationCompletionLatch = provider.installPopulationJobCompletionLatch(); DoubleLatch populationCompletionLatch = provider.installPopulationJobCompletionLatch();
IndexDefinition index = createIndex(); IndexDefinition index = createIndex();
populationCompletionLatch.awaitStart(); // await population job to start populationCompletionLatch.waitForAllToStart(); // await population job to start


// WHEN // WHEN
dropIndex( index, populationCompletionLatch ); dropIndex( index, populationCompletionLatch );
Expand Down

0 comments on commit b5675b7

Please sign in to comment.