Skip to content

Commit

Permalink
Fix test failures exposed by new assert
Browse files Browse the repository at this point in the history
  • Loading branch information
fickludd committed Mar 16, 2017
1 parent 3e86629 commit 570d884
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 28 deletions.
Expand Up @@ -100,8 +100,7 @@ public void partitionedIndexPopulation() throws Exception
assertEquals( 0, uniqueIndex.allDocumentsReader().maxCount() );
assertFalse( uniqueIndex.exists() );

try ( LuceneIndexAccessor indexAccessor = new LuceneIndexAccessor( uniqueIndex,
NewIndexDescriptorFactory.forLabel( 1, 1 ) ) )
try ( LuceneIndexAccessor indexAccessor = new LuceneIndexAccessor( uniqueIndex, descriptor ) )
{
generateUpdates( indexAccessor, affectedNodes );
indexAccessor.force();
Expand Down
Expand Up @@ -137,7 +137,7 @@ private LuceneIndexAccessor createAccessor( PartitionedIndexStorage indexStorage
.withIndexStorage( indexStorage )
.build();
luceneIndex.open();
return new LuceneIndexAccessor( luceneIndex, NewIndexDescriptorFactory.forLabel( 1, 1 ) );
return new LuceneIndexAccessor( luceneIndex, index );
}

private PartitionedIndexStorage getIndexStorage() throws IOException
Expand Down
Expand Up @@ -67,31 +67,31 @@
public class DatabaseIndexAccessorTest
{
public static final int PROP_ID = 1;
private static final NewIndexDescriptor SOME_INDEX_DESCRIPTOR = NewIndexDescriptorFactory.forLabel( 1, PROP_ID );

@Rule
public final ThreadingRule threading = new ThreadingRule();
@ClassRule
public static final EphemeralFileSystemRule fileSystemRule = new EphemeralFileSystemRule();

@Parameterized.Parameter
@Parameterized.Parameter(0)
public NewIndexDescriptor index;
@Parameterized.Parameter(1)
public IOFunction<DirectoryFactory,LuceneIndexAccessor> accessorFactory;

private LuceneIndexAccessor accessor;
private final long nodeId = 1, nodeId2 = 2;
private final Object value = "value", value2 = 40;
private DirectoryFactory.InMemoryDirectoryFactory dirFactory;
private static final NewIndexDescriptor indexDescriptor = NewIndexDescriptorFactory.forLabel( 0, PROP_ID );
private static final NewIndexDescriptor uniqueIndexDescriptor = NewIndexDescriptorFactory
.uniqueForLabel( 1, PROP_ID );
private static final NewIndexDescriptor GENERAL_INDEX = NewIndexDescriptorFactory.forLabel( 0, PROP_ID );
private static final NewIndexDescriptor UNIQUE_INDEX = NewIndexDescriptorFactory.uniqueForLabel( 1, PROP_ID );

@Parameterized.Parameters( name = "{0}" )
public static Collection<IOFunction<DirectoryFactory,LuceneIndexAccessor>[]> implementations()
public static Collection<Object[]> implementations()
{
final File dir = new File( "dir" );
return Arrays.asList(
arg( dirFactory1 -> {
SchemaIndex index = LuceneSchemaIndexBuilder.create( indexDescriptor )
arg( GENERAL_INDEX, dirFactory1 -> {
SchemaIndex index = LuceneSchemaIndexBuilder.create( GENERAL_INDEX )
.withFileSystem( fileSystemRule.get() )
.withDirectoryFactory( dirFactory1 )
.withIndexRootFolder( dir )
Expand All @@ -100,10 +100,10 @@ public static Collection<IOFunction<DirectoryFactory,LuceneIndexAccessor>[]> imp

index.create();
index.open();
return new LuceneIndexAccessor( index, SOME_INDEX_DESCRIPTOR );
return new LuceneIndexAccessor( index, GENERAL_INDEX );
} ),
arg( dirFactory1 -> {
SchemaIndex index = LuceneSchemaIndexBuilder.create( uniqueIndexDescriptor )
arg( UNIQUE_INDEX, dirFactory1 -> {
SchemaIndex index = LuceneSchemaIndexBuilder.create( UNIQUE_INDEX )
.withFileSystem( fileSystemRule.get() )
.withDirectoryFactory( dirFactory1 )
.withIndexRootFolder( dir )
Expand All @@ -112,15 +112,16 @@ public static Collection<IOFunction<DirectoryFactory,LuceneIndexAccessor>[]> imp

index.create();
index.open();
return new LuceneIndexAccessor( index, SOME_INDEX_DESCRIPTOR );
return new LuceneIndexAccessor( index, UNIQUE_INDEX );
} )
);
}

private static IOFunction<DirectoryFactory,LuceneIndexAccessor>[] arg(
private static Object[] arg(
NewIndexDescriptor index,
IOFunction<DirectoryFactory,LuceneIndexAccessor> foo )
{
return new IOFunction[]{foo};
return new Object[]{index, foo};
}

@Before
Expand Down Expand Up @@ -324,17 +325,17 @@ public void shouldStopSamplingWhenIndexIsDropped() throws Exception

private IndexEntryUpdate add( long nodeId, Object value )
{
return IndexEntryUpdate.add( nodeId, indexDescriptor.schema(), value );
return IndexEntryUpdate.add( nodeId, index.schema(), value );
}

private IndexEntryUpdate remove( long nodeId, Object value )
{
return IndexEntryUpdate.remove( nodeId, indexDescriptor.schema(), value );
return IndexEntryUpdate.remove( nodeId, index.schema(), value );
}

private IndexEntryUpdate change( long nodeId, Object valueBefore, Object valueAfter )
{
return IndexEntryUpdate.change( nodeId, indexDescriptor.schema(), valueBefore, valueAfter );
return IndexEntryUpdate.change( nodeId, index.schema(), valueBefore, valueAfter );
}

private void updateAndCommit( List<IndexEntryUpdate> nodePropertyUpdates )
Expand Down
Expand Up @@ -257,7 +257,7 @@ private LuceneIndexAccessor createDefaultIndexAccessor() throws IOException
.build();
index.create();
index.open();
return new LuceneIndexAccessor( index, NewIndexDescriptorFactory.forLabel( 1, 1 ) );
return new LuceneIndexAccessor( index, descriptor );
}

private Map<String,Integer> countTemplateMatches( List<String> nameTemplates, List<String> fileNames )
Expand Down
Expand Up @@ -284,7 +284,7 @@ public void removalsDeliveredToIndexWriter() throws Exception
updater.process( remove( 3, SCHEMA_DESCRIPTOR, "baz" ) );
verify( writer ).deleteDocuments( newTermForChangeOrRemove( 3 ) );

updater.process( remove( 4, SCHEMA_DESCRIPTOR, "bit", "baz" ) );
updater.process( remove( 4, COMPOSITE_SCHEMA_DESCRIPTOR, "bit", "baz" ) );
verify( writer ).deleteDocuments( newTermForChangeOrRemove( 4 ) );
}

Expand Down
Expand Up @@ -530,13 +530,12 @@ public void sampleIncludedUpdates() throws Exception
@Test
public void addUpdates() throws Exception
{
LabelSchemaDescriptor schemaDescriptor = SchemaDescriptorFactory.forLabel( 1, 1 );
populator = newPopulator();

List<IndexEntryUpdate> updates = Arrays.asList(
IndexEntryUpdate.add( 1, schemaDescriptor, "aaa" ),
IndexEntryUpdate.add( 2, schemaDescriptor, "bbb" ),
IndexEntryUpdate.add( 3, schemaDescriptor, "ccc" ) );
IndexEntryUpdate.add( 1, descriptor.schema(), "aaa" ),
IndexEntryUpdate.add( 2, descriptor.schema(), "bbb" ),
IndexEntryUpdate.add( 3, descriptor.schema(), "ccc" ) );

populator.add( updates );

Expand All @@ -558,8 +557,7 @@ private UniqueLuceneIndexPopulator newPopulator() throws IOException
private static void addUpdate( UniqueLuceneIndexPopulator populator, long nodeId, Object value )
throws IOException, IndexEntryConflictException
{
NewIndexDescriptor indexDescriptor = NewIndexDescriptorFactory.forLabel( 0, 0 );
IndexEntryUpdate update = IndexEntryUpdate.add( nodeId, indexDescriptor.schema(), value );
IndexEntryUpdate update = IndexEntryUpdate.add( nodeId, descriptor.schema(), value );
populator.add( Collections.singletonList( update ) );
}
}

0 comments on commit 570d884

Please sign in to comment.