Skip to content

Commit

Permalink
Don't call IndexPopulator.close twice from test code
Browse files Browse the repository at this point in the history
  • Loading branch information
sherfert committed Apr 9, 2018
1 parent 0fe85a8 commit b31c6d2
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,9 @@ public void shouldProvidePopulatorThatAcceptsDuplicateEntries() throws Exception
{
// when
IndexSamplingConfig indexSamplingConfig = new IndexSamplingConfig( Config.defaults() );
withPopulator( indexProvider.getPopulator( 17, descriptor, indexSamplingConfig ), p ->
{
p.create();
p.add( Arrays.asList(
add( 1, descriptor.schema(), "v1", "v2" ),
add( 2, descriptor.schema(), "v1", "v2" ) ) );
p.close( true );
} );
withPopulator( indexProvider.getPopulator( 17, descriptor, indexSamplingConfig ), p -> p.add( Arrays.asList(
add( 1, descriptor.schema(), "v1", "v2" ),
add( 2, descriptor.schema(), "v1", "v2" ) ) ) );

// then
try ( IndexAccessor accessor = indexProvider.getOnlineAccessor( 17, descriptor, indexSamplingConfig ) )
Expand Down Expand Up @@ -110,7 +105,6 @@ public void shouldEnforceUniqueConstraintsDirectly() throws Exception
IndexSamplingConfig indexSamplingConfig = new IndexSamplingConfig( Config.defaults() );
withPopulator( indexProvider.getPopulator( 17, descriptor, indexSamplingConfig ), p ->
{
p.create();
p.add( Arrays.asList(
IndexEntryUpdate.add( nodeId1, descriptor.schema(), value1, value2 ),
IndexEntryUpdate.add( nodeId2, descriptor.schema(), value1, value2 ) ) );
Expand Down Expand Up @@ -140,8 +134,6 @@ public void shouldNotRestrictUpdatesDifferingOnSecondProperty() throws Exception
IndexSamplingConfig indexSamplingConfig = new IndexSamplingConfig( Config.defaults() );
withPopulator( indexProvider.getPopulator( 17, descriptor, indexSamplingConfig ), p ->
{
p.create();

// when
p.add( Arrays.asList(
IndexEntryUpdate.add( nodeId1, descriptor.schema(), value1, value2 ),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ void withPopulator( IndexPopulator populator, ThrowingConsumer<IndexPopulator,Ex
{
try
{
populator.create();
runWithPopulator.accept( populator );
}
finally
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,19 +76,12 @@ public SimpleIndexPopulatorCompatibility(
public void shouldStorePopulationFailedForRetrievalFromProviderLater() throws Exception
{
// GIVEN
String failure = "The contrived failure";
IndexSamplingConfig indexSamplingConfig = new IndexSamplingConfig( Config.defaults() );
withPopulator( indexProvider.getPopulator( 17, descriptor, indexSamplingConfig ), p ->
{
String failure = "The contrived failure";
p.create();

// WHEN
p.markAsFailed( failure );
p.close( false );

// THEN
assertThat( indexProvider.getPopulationFailure( 17, descriptor ), containsString( failure ) );
} );
// WHEN (this will attempt to call close)
withPopulator( indexProvider.getPopulator( 17, descriptor, indexSamplingConfig ), p -> p.markAsFailed( failure ) );
// THEN
assertThat( indexProvider.getPopulationFailure( 17, descriptor ), containsString( failure ) );
}

@Test
Expand All @@ -99,7 +92,6 @@ public void shouldReportInitialStateAsFailedIfPopulationFailed() throws Exceptio
withPopulator( indexProvider.getPopulator( 17, descriptor, indexSamplingConfig ), p ->
{
String failure = "The contrived failure";
p.create();

// WHEN
p.markAsFailed( failure );
Expand All @@ -114,15 +106,13 @@ public void shouldBeAbleToDropAClosedIndexPopulator() throws Exception
{
// GIVEN
IndexSamplingConfig indexSamplingConfig = new IndexSamplingConfig( Config.defaults() );
withPopulator( indexProvider.getPopulator( 17, descriptor, indexSamplingConfig ), p ->
{
p.close( false );
final IndexPopulator p = indexProvider.getPopulator( 17, descriptor, indexSamplingConfig );
p.close( false );

// WHEN
p.drop();
// WHEN
p.drop();

// THEN - no exception should be thrown (it's been known to!)
} );
// THEN - no exception should be thrown (it's been known to!)
}

@Test
Expand All @@ -133,7 +123,6 @@ public void shouldApplyUpdatesIdempotently() throws Exception
final Value propertyValue = Values.of( "value1" );
withPopulator( indexProvider.getPopulator( 17, descriptor, indexSamplingConfig ), p ->
{
p.create();
long nodeId = 1;

// update using populator...
Expand All @@ -144,8 +133,6 @@ public void shouldApplyUpdatesIdempotently() throws Exception
{
updater.process( update );
}

p.close( true );
} );

// THEN
Expand All @@ -165,11 +152,7 @@ public void shouldApplyUpdatesIdempotently() throws Exception
public void shouldPopulateWithAllValues() throws Exception
{
// GIVEN
withPopulator( indexProvider.getPopulator( 17, descriptor, indexSamplingConfig ), p ->
{
p.create();
p.add( updates( valueSet1 ) );
} );
withPopulator( indexProvider.getPopulator( 17, descriptor, indexSamplingConfig ), p -> p.add( updates( valueSet1 ) ) );

// THEN
assertHasAllValues( valueSet1 );
Expand All @@ -181,8 +164,6 @@ public void shouldUpdateWithAllValuesDuringPopulation() throws Exception
// GIVEN
withPopulator( indexProvider.getPopulator( 17, descriptor, indexSamplingConfig ), p ->
{
p.create();

try ( IndexUpdater updater = p.newPopulatingUpdater( this::valueSet1Lookup ) )
{
for ( NodeAndValue entry : valueSet1 )
Expand All @@ -200,11 +181,7 @@ public void shouldUpdateWithAllValuesDuringPopulation() throws Exception
public void shouldPopulateAndUpdate() throws Exception
{
// GIVEN
withPopulator( indexProvider.getPopulator( 17, descriptor, indexSamplingConfig ), p ->
{
p.create();
p.add( updates( valueSet1 ) );
} );
withPopulator( indexProvider.getPopulator( 17, descriptor, indexSamplingConfig ), p -> p.add( updates( valueSet1 ) ) );

try ( IndexAccessor accessor = indexProvider.getOnlineAccessor( 17, descriptor, indexSamplingConfig ) )
{
Expand Down Expand Up @@ -278,7 +255,6 @@ public void shouldProvidePopulatorThatAcceptsDuplicateEntries() throws Exception
long offset = valueSet1.size();
withPopulator( indexProvider.getPopulator( 17, descriptor, indexSamplingConfig ), p ->
{
p.create();
p.add( updates( valueSet1, 0 ) );
p.add( updates( valueSet1, offset ) );
} );
Expand Down Expand Up @@ -322,7 +298,6 @@ public void shouldProvidePopulatorThatEnforcesUniqueConstraints() throws Excepti

withPopulator( indexProvider.getPopulator( 17, descriptor, indexSamplingConfig ), p ->
{
p.create();
try
{
p.add( Arrays.asList(
Expand Down

0 comments on commit b31c6d2

Please sign in to comment.