Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ba5524b
commit bb2b341
Showing
5 changed files
with
232 additions
and
9 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
46 changes: 46 additions & 0 deletions
46
community/io/src/test/java/org/neo4j/graphdb/mockfs/CloseTrackingFileSystem.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 | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* | ||
* Copyright (c) 2002-2016 "Neo Technology," | ||
* Network Engine for Objects in Lund AB [http://neotechnology.com] | ||
* | ||
* This file is part of Neo4j. | ||
* | ||
* Neo4j is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* 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 General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
package org.neo4j.graphdb.mockfs; | ||
|
||
import java.io.IOException; | ||
import java.util.zip.ZipOutputStream; | ||
|
||
import org.neo4j.io.fs.FileSystemAbstraction; | ||
|
||
public class CloseTrackingFileSystem implements FileSystemAbstraction.ThirdPartyFileSystem | ||
{ | ||
private boolean closed = false; | ||
|
||
@Override | ||
public void close() | ||
{ | ||
closed = true; | ||
} | ||
|
||
@Override | ||
public void dumpToZip( ZipOutputStream zip, byte[] scratchPad ) throws IOException | ||
{ | ||
} | ||
|
||
public boolean isClosed() | ||
{ | ||
return closed; | ||
} | ||
} |
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
135 changes: 135 additions & 0 deletions
135
community/io/src/test/java/org/neo4j/io/fs/DelegateFileSystemAbstractionTest.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 | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
/* | ||
* Copyright (c) 2002-2016 "Neo Technology," | ||
* Network Engine for Objects in Lund AB [http://neotechnology.com] | ||
* | ||
* This file is part of Neo4j. | ||
* | ||
* Neo4j is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* 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 General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
package org.neo4j.io.fs; | ||
|
||
import org.junit.Test; | ||
|
||
import java.io.IOException; | ||
import java.nio.file.FileStore; | ||
import java.nio.file.FileSystem; | ||
import java.nio.file.Path; | ||
import java.nio.file.PathMatcher; | ||
import java.nio.file.WatchService; | ||
import java.nio.file.attribute.UserPrincipalLookupService; | ||
import java.nio.file.spi.FileSystemProvider; | ||
import java.util.Set; | ||
|
||
import org.neo4j.graphdb.mockfs.CloseTrackingFileSystem; | ||
|
||
import static org.junit.Assert.assertFalse; | ||
import static org.junit.Assert.assertTrue; | ||
|
||
public class DelegateFileSystemAbstractionTest | ||
{ | ||
|
||
@Test | ||
public void closeAllResourcesOnClose() throws Exception | ||
{ | ||
TrackableFileSystem fileSystem = new TrackableFileSystem(); | ||
CloseTrackingFileSystem closeTrackingFileSystem = new CloseTrackingFileSystem(); | ||
|
||
DelegateFileSystemAbstraction fileSystemAbstraction = new DelegateFileSystemAbstraction( fileSystem ); | ||
fileSystemAbstraction.getOrCreateThirdPartyFileSystem( CloseTrackingFileSystem.class, | ||
closeTrackingFileSystemClass -> closeTrackingFileSystem ); | ||
|
||
fileSystemAbstraction.close(); | ||
|
||
assertFalse( fileSystem.isOpen() ); | ||
assertTrue( closeTrackingFileSystem.isClosed() ); | ||
} | ||
|
||
private class TrackableFileSystem extends FileSystem | ||
{ | ||
|
||
private boolean closed; | ||
|
||
@Override | ||
public FileSystemProvider provider() | ||
{ | ||
return null; | ||
} | ||
|
||
@Override | ||
public void close() throws IOException | ||
{ | ||
closed = true; | ||
} | ||
|
||
@Override | ||
public boolean isOpen() | ||
{ | ||
return !closed; | ||
} | ||
|
||
@Override | ||
public boolean isReadOnly() | ||
{ | ||
return false; | ||
} | ||
|
||
@Override | ||
public String getSeparator() | ||
{ | ||
return null; | ||
} | ||
|
||
@Override | ||
public Iterable<Path> getRootDirectories() | ||
{ | ||
return null; | ||
} | ||
|
||
@Override | ||
public Iterable<FileStore> getFileStores() | ||
{ | ||
return null; | ||
} | ||
|
||
@Override | ||
public Set<String> supportedFileAttributeViews() | ||
{ | ||
return null; | ||
} | ||
|
||
@Override | ||
public Path getPath( String first, String... more ) | ||
{ | ||
return null; | ||
} | ||
|
||
@Override | ||
public PathMatcher getPathMatcher( String syntaxAndPattern ) | ||
{ | ||
return null; | ||
} | ||
|
||
@Override | ||
public UserPrincipalLookupService getUserPrincipalLookupService() | ||
{ | ||
return null; | ||
} | ||
|
||
@Override | ||
public WatchService newWatchService() throws IOException | ||
{ | ||
return null; | ||
} | ||
} | ||
} |