Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix FileMoveAction inconsistency/windows issue WIP
This is to fix a revert for commit d94dfd0.
- Loading branch information
Showing
4 changed files
with
152 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
126 changes: 126 additions & 0 deletions
126
enterprise/com/src/test/java/org/neo4j/com/storecopy/FileMoveActionTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,126 @@ | |||
/* | |||
* Copyright (c) 2002-2018 "Neo4j," | |||
* Neo4j Sweden AB [http://neo4j.com] | |||
* | |||
* This file is part of Neo4j Enterprise Edition. The included source | |||
* code can be redistributed and/or modified under the terms of the | |||
* GNU AFFERO GENERAL PUBLIC LICENSE Version 3 | |||
* (http://www.fsf.org/licensing/licenses/agpl-3.0.html) with the | |||
* Commons Clause, as found in the associated LICENSE.txt file. | |||
* | |||
* This program is distributed in the hope that it will be useful, | |||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
* GNU Affero General Public License for more details. | |||
* | |||
* Neo4j object code can be licensed independently from the source | |||
* under separate terms from the AGPL. Inquiries can be directed to: | |||
* licensing@neo4j.com | |||
* | |||
* More information is also available at: | |||
* https://neo4j.com/licensing/ | |||
*/ | |||
package org.neo4j.com.storecopy; | |||
|
|||
import org.junit.Rule; | |||
import org.junit.Test; | |||
|
|||
import java.io.File; | |||
import java.io.IOException; | |||
import java.nio.file.StandardOpenOption; | |||
|
|||
import org.neo4j.io.fs.DefaultFileSystemAbstraction; | |||
import org.neo4j.io.fs.FileSystemAbstraction; | |||
import org.neo4j.io.pagecache.PageCache; | |||
import org.neo4j.io.pagecache.PagedFile; | |||
import org.neo4j.kernel.configuration.Config; | |||
import org.neo4j.kernel.impl.pagecache.ConfigurableStandalonePageCacheFactory; | |||
import org.neo4j.test.rule.TestDirectory; | |||
|
|||
import static org.junit.Assert.assertFalse; | |||
import static org.junit.Assert.assertTrue; | |||
|
|||
public class FileMoveActionTest | |||
{ | |||
@Rule | |||
public final TestDirectory testDirectory = TestDirectory.testDirectory(); | |||
|
|||
private FileSystemAbstraction fileSystemAbstraction = new DefaultFileSystemAbstraction(); | |||
private Config config = Config.defaults(); | |||
|
|||
@Test | |||
public void pageCacheFilesMovedDoNotLeaveOriginal() throws IOException | |||
{ | |||
// given | |||
PageCache pageCache = aPageCache(); | |||
|
|||
// and | |||
File pageCacheFile = testDirectory.file( "page-cache-file" ); | |||
PagedFile pagedFile = pageCache.map( pageCacheFile, 100, StandardOpenOption.CREATE ); | |||
|
|||
// when | |||
File targetRename = testDirectory.file( "destination" ); | |||
FileMoveAction action = FileMoveAction.moveViaPageCache( pageCacheFile, pageCache ); | |||
pagedFile.close(); | |||
action.move( targetRename ); | |||
|
|||
// then | |||
assertFalse( pageCacheFile.exists() ); | |||
assertTrue( targetRename.exists() ); | |||
} | |||
|
|||
@Test | |||
public void nonPageCacheFilesMovedDoNotLeaveOriginal() throws IOException | |||
{ | |||
// given | |||
File baseDirectory = testDirectory.directory(); | |||
File sourceDirectory = new File( baseDirectory, "source" ); | |||
File targetDirectory = new File( baseDirectory, "destination" ); | |||
File sourceFile = new File( sourceDirectory, "theFileName" ); | |||
File targetFile = new File( targetDirectory, "theFileName" ); | |||
sourceFile.getParentFile().mkdirs(); | |||
targetDirectory.mkdirs(); | |||
|
|||
// and sanity check | |||
assertTrue( sourceFile.createNewFile() ); | |||
assertTrue( sourceFile.exists() ); | |||
assertFalse( targetFile.exists() ); | |||
|
|||
// when | |||
FileMoveAction.moveViaFileSystem( sourceFile, sourceDirectory ).move( targetDirectory ); | |||
|
|||
// then | |||
assertTrue( targetFile.exists() ); | |||
assertFalse( sourceFile.exists() ); | |||
} | |||
|
|||
@Test | |||
public void nonPageCacheFilesCopiedLeaveOriginal() throws IOException | |||
{ | |||
// given | |||
File baseDirectory = testDirectory.directory(); | |||
File sourceDirectory = new File( baseDirectory, "source" ); | |||
File targetDirectory = new File( baseDirectory, "destination" ); | |||
File sourceFile = new File( sourceDirectory, "theFileName" ); | |||
File targetFile = new File( targetDirectory, "theFileName" ); | |||
sourceFile.getParentFile().mkdirs(); | |||
targetDirectory.mkdirs(); | |||
|
|||
// and sanity check | |||
assertTrue( sourceFile.createNewFile() ); | |||
assertTrue( sourceFile.exists() ); | |||
assertFalse( targetFile.exists() ); | |||
|
|||
// when | |||
FileMoveAction.copyViaFileSystem( sourceFile, sourceDirectory ).move( targetDirectory ); | |||
|
|||
// then | |||
assertTrue( targetFile.exists() ); | |||
assertTrue( sourceFile.exists() ); | |||
} | |||
|
|||
private PageCache aPageCache() | |||
{ | |||
return ConfigurableStandalonePageCacheFactory.createPageCache( fileSystemAbstraction, config ); | |||
} | |||
} |