Skip to content

Commit

Permalink
Use simpler method nemes in the PageCache.streamFilesRecursive area o…
Browse files Browse the repository at this point in the history
…f the code
  • Loading branch information
chrisvest committed Sep 27, 2016
1 parent e021968 commit 0733687
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 24 deletions.
Expand Up @@ -62,7 +62,7 @@ public interface FileHandle
* {@link java.nio.file.StandardCopyOption#REPLACE_EXISTING} open option was not specified.
* @throws IOException if an I/O error occurs, for instance when canonicalising the {@code to} path.
*/
void renameFile( File to, CopyOption... options ) throws IOException;
void rename( File to, CopyOption... options ) throws IOException;

/**
* Delete the file that this file handle represents.
Expand Down
Expand Up @@ -156,7 +156,7 @@ public File getFile()
}

@Override
public void renameFile( File to, CopyOption... options ) throws IOException
public void rename( File to, CopyOption... options ) throws IOException
{
File parentFile = file.getParentFile();
fs.mkdirs( to.getParentFile() );
Expand Down
Expand Up @@ -418,16 +418,16 @@ public File getFile()
}

@Override
public void renameFile( File targetFile, CopyOption... options ) throws IOException
public void rename( File targetFile, CopyOption... options ) throws IOException
{
synchronized ( MuninnPageCache.this )
{
File sourceFile = getFile();
sourceFile = sourceFile.getCanonicalFile();
targetFile = targetFile.getCanonicalFile();
throwIfMapped( sourceFile, FileIsMappedException.Operation.RENAME );
throwIfMapped( targetFile, FileIsMappedException.Operation.RENAME );
fileHandle.renameFile( targetFile, options );
assertNotMapped( sourceFile, FileIsMappedException.Operation.RENAME );
assertNotMapped( targetFile, FileIsMappedException.Operation.RENAME );
fileHandle.rename( targetFile, options );
}
}

Expand All @@ -436,14 +436,14 @@ public void delete() throws IOException
{
synchronized ( MuninnPageCache.this )
{
throwIfMapped( getFile(), FileIsMappedException.Operation.DELETE );
assertNotMapped( getFile(), FileIsMappedException.Operation.DELETE );
fileHandle.delete();
}
}
};
}

private void throwIfMapped( File file, FileIsMappedException.Operation operation ) throws IOException
private void assertNotMapped( File file, FileIsMappedException.Operation operation ) throws IOException
{
if ( tryGetMappingOrNull( file ) != null )
{
Expand Down
Expand Up @@ -4848,7 +4848,7 @@ public void streamFilesRecursiveMustRenameFiles() throws Exception
Iterable<FileHandle> handles = pageCache.streamFilesRecursive( base )::iterator;
for ( FileHandle fh : handles )
{
fh.renameFile( b );
fh.rename( b );
}
List<File> filepaths = pageCache.streamFilesRecursive( base ).map( FileHandle::getFile ).collect( toList() );
assertThat( filepaths, containsInAnyOrder( b.getCanonicalFile() ) );
Expand Down Expand Up @@ -4888,7 +4888,7 @@ public void streamFilesRecursiveMustThrowWhenRenamingMappedSourceFile() throws E
Iterable<FileHandle> handles = pageCache.streamFilesRecursive( a.getParentFile() )::iterator;
for ( FileHandle handle : handles )
{
handle.renameFile( b );
handle.rename( b );
}
}
}
Expand All @@ -4906,7 +4906,7 @@ public void streamFilesRecursiveMustThrowWhenRenamingMappedTargetFile() throws E
Iterable<FileHandle> handles = streamOfA::iterator;
for ( FileHandle handle : handles )
{
handle.renameFile( b );
handle.rename( b );
}
}
}
Expand Down Expand Up @@ -4946,7 +4946,7 @@ public void streamFilesRecursiveMustThrowWhenTargetFileOfRenameAlreadyExists() t
File a = file( "a" );
File b = existingFile( "b" );
FileHandle handle = pageCache.streamFilesRecursive( a ).findAny().get();
handle.renameFile( b );
handle.rename( b );
}

@Test
Expand All @@ -4957,7 +4957,7 @@ public void streamFilesRecursiveMustNotThrowWhenTargetFileOfRenameAlreadyExistsA
File a = file( "a" );
File b = existingFile( "b" );
FileHandle handle = pageCache.streamFilesRecursive( a ).findAny().get();
handle.renameFile( b, StandardCopyOption.REPLACE_EXISTING );
handle.rename( b, StandardCopyOption.REPLACE_EXISTING );
}

@Test
Expand All @@ -4972,7 +4972,7 @@ public void streamFilesRecursiveMustDeleteSubDirectoriesEmptiedByFileRename() th
Iterable<FileHandle> handles = pageCache.streamFilesRecursive( sub )::iterator;
for ( FileHandle handle : handles )
{
handle.renameFile( target );
handle.rename( target );
}

assertFalse( fs.isDirectory( sub ) );
Expand Down Expand Up @@ -5008,7 +5008,7 @@ public void streamFilesRecursiveMustCreateMissingPathDirectoriesImpliedByFileRen
File target = new File( sub, "b" );

FileHandle handle = pageCache.streamFilesRecursive( a ).findAny().get();
handle.renameFile( target );
handle.rename( target );

assertTrue( fs.isDirectory( sub ) );
assertTrue( fs.fileExists( target ) );
Expand Down Expand Up @@ -5043,7 +5043,7 @@ public void streamFilesRecursiveMustNotSeeFilesRenamedIntoBaseDirectory() throws
observedFiles.add( file );
if ( file.equals( x ) )
{
handle.renameFile( target );
handle.rename( target );
}
}
assertThat( observedFiles, containsInAnyOrder( a, x ) );
Expand All @@ -5064,7 +5064,7 @@ public void streamFilesRecursiveMustNotSeeFilesRenamedIntoSubDirectory() throws
observedFiles.add( file );
if ( file.equals( a ) )
{
handle.renameFile( target );
handle.rename( target );
}
}
assertThat( observedFiles, containsInAnyOrder( a ) );
Expand All @@ -5080,7 +5080,7 @@ public void streamFilesRecursiveRenameMustCanonicaliseSourceFile() throws Except
File b = file( "b" );

FileHandle handle = pageCache.streamFilesRecursive( a ).findAny().get();
handle.renameFile( b ); // must not throw
handle.rename( b ); // must not throw
}

@Test
Expand All @@ -5092,7 +5092,7 @@ public void streamFilesRecursiveRenameMustCanonicaliseTargetFile() throws Except
File a = file( "a" );
File b = new File( new File( file( "b" ), "poke" ), ".." );
FileHandle handle = pageCache.streamFilesRecursive( a ).findAny().get();
handle.renameFile( b );
handle.rename( b );
}

@Test
Expand All @@ -5102,7 +5102,7 @@ public void streamFilesRecursiveRenameTargetFileMustBeMappable() throws Exceptio
File a = file( "a" );
File b = file( "b" );
FileHandle handle = pageCache.streamFilesRecursive( a ).findAny().get();
handle.renameFile( b );
handle.rename( b );
pageCache.map( b, filePageSize ).close();
}

Expand All @@ -5113,7 +5113,7 @@ public void streamFilesRecursiveSourceFileMustNotBeMappableAfterRename() throws
File a = file( "a" );
File b = file( "b" );
FileHandle handle = pageCache.streamFilesRecursive( a ).findAny().get();
handle.renameFile( b );
handle.rename( b );
pageCache.map( a, filePageSize );
fail( "pageCache.map should have thrown" );
}
Expand All @@ -5126,7 +5126,7 @@ public void streamFilesRecursiveRenameMustNotChangeSourceFileContents() throws E
File b = file( "b" );
generateFileWithRecords( a, recordCount, recordSize );
FileHandle handle = pageCache.streamFilesRecursive( a ).findAny().get();
handle.renameFile( b );
handle.rename( b );
verifyRecordsInFile( b, recordCount );
}

Expand Down Expand Up @@ -5156,7 +5156,7 @@ public void streamFilesRecursiveRenameMustNotChangeSourceFileContentsWithReplace

// Do the rename
FileHandle handle = pageCache.streamFilesRecursive( a ).findAny().get();
handle.renameFile( b, REPLACE_EXISTING );
handle.rename( b, REPLACE_EXISTING );

// Then verify that the old random data we put in 'b' has been replaced with the contents of 'a'
verifyRecordsInFile( b, recordCount );
Expand Down
Expand Up @@ -104,7 +104,7 @@ private void addPageCacheMoveAction( File file )
Optional<FileHandle> handle = pageCache.streamFilesRecursive( file ).findAny();
if ( handle.isPresent() )
{
handle.get().renameFile( new File( toDir, file.getName() ), copyOptions );
handle.get().rename( new File( toDir, file.getName() ), copyOptions );
}
} );
}
Expand Down

0 comments on commit 0733687

Please sign in to comment.