Skip to content

Commit

Permalink
Fix review comments by reshuffle filters, checking file name
Browse files Browse the repository at this point in the history
start instead of contains.
  • Loading branch information
MishaDemianenko committed Jul 3, 2017
1 parent c1e9d0c commit a96540f
Showing 1 changed file with 11 additions and 14 deletions.
Expand Up @@ -20,6 +20,7 @@
package org.neo4j.index.backup; package org.neo4j.index.backup;


import org.apache.commons.io.FilenameUtils; import org.apache.commons.io.FilenameUtils;
import org.apache.lucene.index.IndexFileNames;
import org.junit.Before; import org.junit.Before;
import org.junit.Rule; import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
Expand Down Expand Up @@ -145,24 +146,18 @@ public void snapshotFilesDeletedWhenSnapshotReleased() throws IOException
private void compareSnapshotFiles( Set<String> firstSnapshotFileNames, Set<String> secondSnapshotFileNames, private void compareSnapshotFiles( Set<String> firstSnapshotFileNames, Set<String> secondSnapshotFileNames,
FileSystemAbstraction fileSystem ) FileSystemAbstraction fileSystem )
{ {
Set<String> firstSnapshotIndexesSegments = firstSnapshotFileNames.stream()
.filter( this::segmentsFilePredicate )
.collect( Collectors.toSet() );
Set<String> secondSnapshotIndexesSegments = secondSnapshotFileNames.stream()
.filter( this::segmentsFilePredicate )
.collect( Collectors.toSet() );
assertThat( format( "Should have %d modified index segment files. Snapshot segment files are: %s", assertThat( format( "Should have %d modified index segment files. Snapshot segment files are: %s",
NUMBER_OF_INDEXES, firstSnapshotIndexesSegments ), firstSnapshotIndexesSegments, NUMBER_OF_INDEXES, firstSnapshotFileNames ), firstSnapshotFileNames,
hasSize( NUMBER_OF_INDEXES ) ); hasSize( NUMBER_OF_INDEXES ) );
for ( String fileName : firstSnapshotIndexesSegments ) for ( String fileName : firstSnapshotFileNames )
{ {
assertFalse( "Snapshot segments fileset should not have files from another snapshot set." + assertFalse( "Snapshot segments fileset should not have files from another snapshot set." +
describeFileSets( firstSnapshotIndexesSegments, secondSnapshotIndexesSegments ), describeFileSets( firstSnapshotFileNames, secondSnapshotFileNames ),
secondSnapshotIndexesSegments.contains( fileName ) ); secondSnapshotFileNames.contains( fileName ) );
String path = FilenameUtils.getFullPath( fileName ); String path = FilenameUtils.getFullPath( fileName );
assertTrue( "Snapshot should contain files for index in path: " + path + "." + assertTrue( "Snapshot should contain files for index in path: " + path + "." +
describeFileSets( firstSnapshotIndexesSegments, secondSnapshotIndexesSegments ), describeFileSets( firstSnapshotFileNames, secondSnapshotFileNames ),
secondSnapshotIndexesSegments.stream().anyMatch( name -> name.startsWith( path ) ) ); secondSnapshotFileNames.stream().anyMatch( name -> name.startsWith( path ) ) );
assertTrue( format( "Snapshot segment file '%s' should exist.", fileName ), assertTrue( format( "Snapshot segment file '%s' should exist.", fileName ),
fileSystem.fileExists( new File( fileName ) ) ); fileSystem.fileExists( new File( fileName ) ) );
} }
Expand Down Expand Up @@ -199,7 +194,9 @@ private String describeFileSets( Set<String> firstFileSet, Set<String> secondFil


private Set<String> getFileNames( ResourceIterator<File> files ) private Set<String> getFileNames( ResourceIterator<File> files )
{ {
return files.stream().map( File::getAbsolutePath ).collect( Collectors.toSet() ); return files.stream().map( File::getAbsolutePath )
.filter( this::segmentsFilePredicate )
.collect( Collectors.toSet() );
} }


private void forceCheckpoint( CheckPointer checkPointer ) throws IOException private void forceCheckpoint( CheckPointer checkPointer ) throws IOException
Expand Down Expand Up @@ -256,6 +253,6 @@ private DependencyResolver getDatabaseResolver()


private boolean segmentsFilePredicate( String fileName ) private boolean segmentsFilePredicate( String fileName )
{ {
return fileName.contains( "segments_" ); return FilenameUtils.getName( fileName ).startsWith( IndexFileNames.SEGMENTS );
} }
} }

0 comments on commit a96540f

Please sign in to comment.