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() ); assertEquals( 0, uniqueIndex.allDocumentsReader().maxCount() );
assertFalse( uniqueIndex.exists() ); assertFalse( uniqueIndex.exists() );


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


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


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


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


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


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


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


index.create(); index.create();
index.open(); 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 ) IOFunction<DirectoryFactory,LuceneIndexAccessor> foo )
{ {
return new IOFunction[]{foo}; return new Object[]{index, foo};
} }


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


private IndexEntryUpdate add( long nodeId, Object value ) 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 ) 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 ) 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 ) private void updateAndCommit( List<IndexEntryUpdate> nodePropertyUpdates )
Expand Down
Expand Up @@ -257,7 +257,7 @@ private LuceneIndexAccessor createDefaultIndexAccessor() throws IOException
.build(); .build();
index.create(); index.create();
index.open(); 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 ) 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" ) ); updater.process( remove( 3, SCHEMA_DESCRIPTOR, "baz" ) );
verify( writer ).deleteDocuments( newTermForChangeOrRemove( 3 ) ); 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 ) ); verify( writer ).deleteDocuments( newTermForChangeOrRemove( 4 ) );
} }


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


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


populator.add( updates ); populator.add( updates );


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

0 comments on commit 570d884

Please sign in to comment.