Skip to content

Commit

Permalink
Adress comments and added file listing test for index.db file
Browse files Browse the repository at this point in the history
  • Loading branch information
burqen committed Sep 9, 2016
1 parent 6c27532 commit dcb0d64
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 11 deletions.
Expand Up @@ -23,6 +23,7 @@
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.Objects;
import java.util.Optional; import java.util.Optional;
import java.util.function.Function; import java.util.function.Function;
import java.util.stream.Collectors; import java.util.stream.Collectors;
Expand Down Expand Up @@ -77,7 +78,7 @@ public ResourceIterator<StoreFileMetadata> listStoreFiles( boolean includeLogs )


private void gatherNonRecordStores( Collection<StoreFileMetadata> files, boolean includeLogs ) private void gatherNonRecordStores( Collection<StoreFileMetadata> files, boolean includeLogs )
{ {
for ( File file : storeDir.listFiles() ) for ( File file : Objects.requireNonNull( storeDir.listFiles()) )
{ {
if ( file.getName().equals( IndexConfigStore.INDEX_DB_FILE_NAME ) ) if ( file.getName().equals( IndexConfigStore.INDEX_DB_FILE_NAME ) )
{ {
Expand Down
Expand Up @@ -37,6 +37,7 @@
import org.neo4j.kernel.api.labelscan.LabelScanStore; import org.neo4j.kernel.api.labelscan.LabelScanStore;
import org.neo4j.kernel.impl.api.LegacyIndexProviderLookup; import org.neo4j.kernel.impl.api.LegacyIndexProviderLookup;
import org.neo4j.kernel.impl.api.index.IndexingService; import org.neo4j.kernel.impl.api.index.IndexingService;
import org.neo4j.kernel.impl.index.IndexConfigStore;
import org.neo4j.kernel.impl.store.StoreType; import org.neo4j.kernel.impl.store.StoreType;
import org.neo4j.kernel.impl.storemigration.StoreFile; import org.neo4j.kernel.impl.storemigration.StoreFile;
import org.neo4j.kernel.impl.storemigration.StoreFileType; import org.neo4j.kernel.impl.storemigration.StoreFileType;
Expand All @@ -58,23 +59,70 @@ public class NeoStoreFileListingTest
@Rule @Rule
public EmbeddedDatabaseRule db = new EmbeddedDatabaseRule( getClass() ); public EmbeddedDatabaseRule db = new EmbeddedDatabaseRule( getClass() );
private NeoStoreDataSource neoStoreDataSource; private NeoStoreDataSource neoStoreDataSource;
private static final String[] STANDARD_STORE_DIR_FILES = new String[]{
"lock",
"debug.log",
"neostore",
"neostore.id",
"neostore.counts.db.a",
"neostore.counts.db.b",
"neostore.labeltokenstore.db",
"neostore.labeltokenstore.db.id",
"neostore.labeltokenstore.db.names",
"neostore.labeltokenstore.db.names.id",
"neostore.nodestore.db",
"neostore.nodestore.db.id",
"neostore.nodestore.db.labels",
"neostore.nodestore.db.labels.id",
"neostore.propertystore.db",
"neostore.propertystore.db.arrays",
"neostore.propertystore.db.arrays.id",
"neostore.propertystore.db.id",
"neostore.propertystore.db.index",
"neostore.propertystore.db.index.id",
"neostore.propertystore.db.index.keys",
"neostore.propertystore.db.index.keys.id",
"neostore.propertystore.db.strings",
"neostore.propertystore.db.strings.id",
"neostore.relationshipstore.db",
"neostore.relationshipstore.db.id",
"neostore.relationshiptypestore.db",
"neostore.relationshiptypestore.db.id",
"neostore.relationshiptypestore.db.names",
"neostore.relationshiptypestore.db.names.id",
"neostore.schemastore.db",
"neostore.schemastore.db.id",
PhysicalLogFile.DEFAULT_NAME + ".active",
PhysicalLogFile.DEFAULT_NAME + PhysicalLogFile.DEFAULT_VERSION_SUFFIX + "0",
PhysicalLogFile.DEFAULT_NAME + PhysicalLogFile.DEFAULT_VERSION_SUFFIX + "1",
PhysicalLogFile.DEFAULT_NAME + PhysicalLogFile.DEFAULT_VERSION_SUFFIX + "2",
"store_lock"};

private static final String[] STANDARD_STORE_DIR_DIRECTORIES = new String[]{"schema", "index", "branched"};


@Before @Before
public void setUp() throws IOException public void setUp() throws IOException
{ {
createIndexDbFile();
neoStoreDataSource = db.getDependencyResolver().resolveDependency( NeoStoreDataSource.class ); neoStoreDataSource = db.getDependencyResolver().resolveDependency( NeoStoreDataSource.class );
} }


private void createIndexDbFile() throws IOException
{
File storeDir = new File( db.getStoreDir() );
final File indexFile = new File( storeDir, "index.db" );
if ( !indexFile.exists() )
{
assertTrue( indexFile.createNewFile() );
}
}

private Set<String> expectedStoreFiles( boolean includeLogFiles ) private Set<String> expectedStoreFiles( boolean includeLogFiles )
{ {
Set<String> storeFileNames = new HashSet<>(); Set<String> storeFileNames = new HashSet<>();
for ( StoreType type : StoreType.values() ) for ( StoreType type : StoreType.values() )
{ {
if ( type.equals( StoreType.COUNTS ) ) if ( !type.equals( StoreType.COUNTS ) )
{
// Skip
}
else
{ {
storeFileNames.add( type.getStoreFile().fileName( StoreFileType.STORE ) ); storeFileNames.add( type.getStoreFile().fileName( StoreFileType.STORE ) );
} }
Expand All @@ -83,6 +131,7 @@ private Set<String> expectedStoreFiles( boolean includeLogFiles )
{ {
storeFileNames.add( PhysicalLogFile.DEFAULT_NAME + ".0" ); storeFileNames.add( PhysicalLogFile.DEFAULT_NAME + ".0" );
} }
storeFileNames.add( IndexConfigStore.INDEX_DB_FILE_NAME );
return storeFileNames; return storeFileNames;
} }


Expand All @@ -101,7 +150,7 @@ public void shouldNotIncludeTransactionLogFile() throws Exception
final Set<String> actual = asSetOfPaths( storeFiles ); final Set<String> actual = asSetOfPaths( storeFiles );
final Set<String> expectedStoreFiles = expectedStoreFiles( false ); final Set<String> expectedStoreFiles = expectedStoreFiles( false );
final List<String> countStoreFiles = countStoreFiles(); final List<String> countStoreFiles = countStoreFiles();
assertTrue( actual.containsAll( expectedStoreFiles ) ); assertTrue( diffSet( actual, expectedStoreFiles ), actual.containsAll( expectedStoreFiles ) );
assertFalse( Collections.disjoint( actual, countStoreFiles ) ); assertFalse( Collections.disjoint( actual, countStoreFiles ) );
} }


Expand All @@ -112,7 +161,7 @@ public void shouldIncludeTransactionLogFile() throws Exception
final Set<String> actual = asSetOfPaths( storeFiles ); final Set<String> actual = asSetOfPaths( storeFiles );
final Set<String> expectedStoreFiles = expectedStoreFiles( true ); final Set<String> expectedStoreFiles = expectedStoreFiles( true );
final List<String> countStoreFiles = countStoreFiles(); final List<String> countStoreFiles = countStoreFiles();
assertTrue( actual.containsAll( expectedStoreFiles ) ); assertTrue( diffSet( actual, expectedStoreFiles ), actual.containsAll( expectedStoreFiles ) );
assertFalse( Collections.disjoint( actual, countStoreFiles ) ); assertFalse( Collections.disjoint( actual, countStoreFiles ) );
} }


Expand All @@ -125,6 +174,7 @@ public void shouldCloseIndexAndLabelScanSnapshots() throws Exception
LegacyIndexProviderLookup legacyIndexes = mock( LegacyIndexProviderLookup.class ); LegacyIndexProviderLookup legacyIndexes = mock( LegacyIndexProviderLookup.class );
when( legacyIndexes.all() ).thenReturn( Collections.emptyList() ); when( legacyIndexes.all() ).thenReturn( Collections.emptyList() );
File storeDir = mock( File.class ); File storeDir = mock( File.class );
filesInStoreDirAre( storeDir, STANDARD_STORE_DIR_FILES, STANDARD_STORE_DIR_DIRECTORIES );
StorageEngine storageEngine = mock( StorageEngine.class ); StorageEngine storageEngine = mock( StorageEngine.class );
NeoStoreFileListing fileListing = new NeoStoreFileListing( NeoStoreFileListing fileListing = new NeoStoreFileListing(
storeDir, labelScanStore, indexingService, legacyIndexes, storageEngine ); storeDir, labelScanStore, indexingService, legacyIndexes, storageEngine );
Expand All @@ -143,6 +193,14 @@ public void shouldCloseIndexAndLabelScanSnapshots() throws Exception
verify( indexSnapshot ).close(); verify( indexSnapshot ).close();
} }


private void filesInStoreDirAre( File storeDir, String[] filenames, String[] dirs )
{
ArrayList<File> files = new ArrayList<>();
mockFiles( filenames, files, false );
mockFiles( dirs, files, true );
when( storeDir.listFiles() ).thenReturn( files.toArray( new File[files.size()] ) );
}

private String diffSet( Set<String> actual, Set<String> expected ) private String diffSet( Set<String> actual, Set<String> expected )
{ {
Set<String> extra = new HashSet<>( actual ); Set<String> extra = new HashSet<>( actual );
Expand All @@ -154,12 +212,12 @@ private String diffSet( Set<String> actual, Set<String> expected )


private Set<String> asSetOfPaths( ResourceIterator<StoreFileMetadata> result ) private Set<String> asSetOfPaths( ResourceIterator<StoreFileMetadata> result )
{ {
List<String> fnames = new ArrayList<>(); List<String> names = new ArrayList<>();
while ( result.hasNext() ) while ( result.hasNext() )
{ {
fnames.add( result.next().file().getName() ); names.add( result.next().file().getName() );
} }
return Iterables.asUniqueSet( fnames ); return Iterables.asUniqueSet( names );
} }


private ResourceIterator<File> scanStoreFilesAre( LabelScanStore labelScanStore, String[] fileNames ) private ResourceIterator<File> scanStoreFilesAre( LabelScanStore labelScanStore, String[] fileNames )
Expand Down

0 comments on commit dcb0d64

Please sign in to comment.