Skip to content

Commit

Permalink
PageCacheTest cleanups
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisvest committed Sep 28, 2016
1 parent ad7c1d2 commit b2fe975
Showing 1 changed file with 9 additions and 10 deletions.
Expand Up @@ -4808,7 +4808,7 @@ public void streamFilesRecursiveMustNotListSubDirectories() throws Exception
File sub2 = existingDirectory( "sub2" ); File sub2 = existingDirectory( "sub2" );
File sub2sub1 = new File( sub2, "sub1"); File sub2sub1 = new File( sub2, "sub1");
ensureDirectoryExists( sub2sub1 ); ensureDirectoryExists( sub2sub1 );
File sub3 = existingDirectory( "sub3" ); existingDirectory( "sub3" ); // must not be observed in the stream
File a = existingFile( "a" ); File a = existingFile( "a" );
File b = new File( sub1, "b" ); File b = new File( sub1, "b" );
File c = new File( sub2, "c" ); File c = new File( sub2, "c" );
Expand Down Expand Up @@ -4839,8 +4839,8 @@ public void streamFilesRecursiveFilePathsMustBeCanonical() throws Exception
public void streamFilesRecursiveMustListSingleFileGivenAsBase() throws Exception public void streamFilesRecursiveMustListSingleFileGivenAsBase() throws Exception
{ {
configureStandardPageCache(); configureStandardPageCache();
File sub = existingDirectory( "sub" ); existingDirectory( "sub" ); // must not be observed
File x = existingFile( "sub/x" ); existingFile( "sub/x" ); // must not be observed
File a = file( "a" ); File a = file( "a" );


Stream<FileHandle> stream = pageCache.streamFilesRecursive( a ); Stream<FileHandle> stream = pageCache.streamFilesRecursive( a );
Expand All @@ -4853,7 +4853,7 @@ public void streamFilesRecursiveListedSingleFileMustHaveCanonicalPath() throws E
{ {
configureStandardPageCache(); configureStandardPageCache();
File sub = existingDirectory( "sub" ); File sub = existingDirectory( "sub" );
File x = existingFile( "sub/x" ); existingFile( "sub/x" ); // we query specifically for 'a', so this must not be listed
File a = file( "a" ); File a = file( "a" );
File queryForA = new File( new File( sub, ".." ), "a" ); File queryForA = new File( new File( sub, ".." ), "a" );


Expand Down Expand Up @@ -4916,7 +4916,7 @@ public void streamFilesRecursiveMustThrowWhenRenamingMappedSourceFile() throws E
configureStandardPageCache(); configureStandardPageCache();
File a = file( "a" ); File a = file( "a" );
File b = file( "b" ); File b = file( "b" );
try ( PagedFile pf = pageCache.map( a, filePageSize ) ) try ( PagedFile ignore = pageCache.map( a, filePageSize ) )
{ {
Iterable<FileHandle> handles = pageCache.streamFilesRecursive( a.getParentFile() )::iterator; Iterable<FileHandle> handles = pageCache.streamFilesRecursive( a.getParentFile() )::iterator;
for ( FileHandle handle : handles ) for ( FileHandle handle : handles )
Expand All @@ -4933,7 +4933,7 @@ public void streamFilesRecursiveMustThrowWhenRenamingMappedTargetFile() throws E
configureStandardPageCache(); configureStandardPageCache();
File a = file( "a" ); File a = file( "a" );
File b = existingFile( "b" ); File b = existingFile( "b" );
try ( PagedFile pf = pageCache.map( b, filePageSize ) ) try ( PagedFile ignore = pageCache.map( b, filePageSize ) )
{ {
Stream<FileHandle> streamOfA = Stream<FileHandle> streamOfA =
pageCache.streamFilesRecursive( a.getParentFile() ).filter( hasFile( a ) ); pageCache.streamFilesRecursive( a.getParentFile() ).filter( hasFile( a ) );
Expand All @@ -4956,15 +4956,14 @@ public void streamFilesRecursiveMustThrowWhenDeletingMappedFile() throws Excepti
{ {
configureStandardPageCache(); configureStandardPageCache();
File a = file( "a" ); File a = file( "a" );
try ( PagedFile pf = pageCache.map( a, filePageSize ) ) try ( PagedFile ignore = pageCache.map( a, filePageSize ) )
{ {
FileHandle handle = pageCache.streamFilesRecursive( a ).findAny().get(); FileHandle handle = pageCache.streamFilesRecursive( a ).findAny().get();
expectedException.expect( FileIsMappedException.class ); expectedException.expect( FileIsMappedException.class );
handle.delete(); handle.delete();
} }
} }


@SuppressWarnings( "OptionalGetWithoutIsPresent" )
@Test @Test
public void streamFilesRecursiveMustThrowWhenDeletingNonExistingFile() throws Exception public void streamFilesRecursiveMustThrowWhenDeletingNonExistingFile() throws Exception
{ {
Expand Down Expand Up @@ -5067,7 +5066,6 @@ public void streamFilesRecursiveMustDeleteMultipleLayersOfSubDirectoriesIfTheyBe
ensureDirectoryExists( subsub ); ensureDirectoryExists( subsub );
File x = new File( subsub, "x" ); File x = new File( subsub, "x" );
ensureExists( x ); ensureExists( x );
File target = file( "target" );


Iterable<FileHandle> handles = pageCache.streamFilesRecursive( sub )::iterator; Iterable<FileHandle> handles = pageCache.streamFilesRecursive( sub )::iterator;
for ( FileHandle handle : handles ) for ( FileHandle handle : handles )
Expand Down Expand Up @@ -5188,14 +5186,15 @@ public void streamFilesRecursiveRenameTargetFileMustBeMappable() throws Exceptio
pageCache.map( b, filePageSize ).close(); pageCache.map( b, filePageSize ).close();
} }


@Test( expected = NoSuchFileException.class ) @Test
public void streamFilesRecursiveSourceFileMustNotBeMappableAfterRename() throws Exception public void streamFilesRecursiveSourceFileMustNotBeMappableAfterRename() throws Exception
{ {
configureStandardPageCache(); configureStandardPageCache();
File a = file( "a" ); File a = file( "a" );
File b = file( "b" ); File b = file( "b" );
FileHandle handle = pageCache.streamFilesRecursive( a ).findAny().get(); FileHandle handle = pageCache.streamFilesRecursive( a ).findAny().get();
handle.rename( b ); handle.rename( b );
expectedException.expect( NoSuchFileException.class );
pageCache.map( a, filePageSize ); pageCache.map( a, filePageSize );
fail( "pageCache.map should have thrown" ); fail( "pageCache.map should have thrown" );
} }
Expand Down

0 comments on commit b2fe975

Please sign in to comment.