use of org.neo4j.io.fs.DelegatingFileSystemAbstraction in project neo4j by neo4j.
the class FileLockerTest method shouldNotObtainLockWhenDirCannotBeCreated.
@ParameterizedTest
@MethodSource("lockerFactories")
void shouldNotObtainLockWhenDirCannotBeCreated(LockerFactory lockerFactory) {
FileSystemAbstraction fileSystemAbstraction = new DelegatingFileSystemAbstraction(fileSystem) {
@Override
public void mkdirs(Path fileName) throws IOException {
throw new IOException("store dir could not be created");
}
@Override
public boolean fileExists(Path file) {
return false;
}
};
FileLockException fileLockException = assertThrows(FileLockException.class, () -> {
try (Locker storeLocker = lockerFactory.createLocker(fileSystemAbstraction, testDirectory)) {
storeLocker.checkLock();
}
});
assertThat(fileLockException.getMessage()).startsWith("Unable to create path for dir: ");
}
use of org.neo4j.io.fs.DelegatingFileSystemAbstraction in project neo4j by neo4j.
the class FileLockerTest method shouldObtainLockWhenFileNotLocked.
@ParameterizedTest
@MethodSource("lockerFactories")
void shouldObtainLockWhenFileNotLocked(LockerFactory lockerFactory) {
FileSystemAbstraction fileSystemAbstraction = new DelegatingFileSystemAbstraction(fileSystem) {
@Override
public boolean fileExists(Path file) {
return fileSystem.fileExists(file);
}
};
assertDoesNotThrow(() -> {
try (Locker locker = lockerFactory.createLocker(fileSystemAbstraction, testDirectory)) {
locker.checkLock();
}
});
}
use of org.neo4j.io.fs.DelegatingFileSystemAbstraction in project neo4j by neo4j.
the class FileLockerTest method shouldNotObtainLockWhenUnableToOpenLockFile.
@ParameterizedTest
@MethodSource("lockerFactories")
void shouldNotObtainLockWhenUnableToOpenLockFile(LockerFactory lockerFactory) {
FileSystemAbstraction fileSystemAbstraction = new DelegatingFileSystemAbstraction(fileSystem) {
@Override
public StoreChannel write(Path fileName) throws IOException {
throw new IOException("cannot open lock file");
}
@Override
public boolean fileExists(Path file) {
return false;
}
};
FileLockException fileLockException = assertThrows(FileLockException.class, () -> {
try (Locker storeLocker = lockerFactory.createLocker(fileSystemAbstraction, testDirectory)) {
storeLocker.checkLock();
}
});
assertThat(fileLockException.getMessage()).startsWith("Unable to obtain lock on file:");
}
use of org.neo4j.io.fs.DelegatingFileSystemAbstraction in project neo4j by neo4j.
the class SingleFilePageSwapperTest method mustCloseFilesIfTakingFileLockThrows.
@Test
@DisabledOnOs(OS.WINDOWS)
void mustCloseFilesIfTakingFileLockThrows() throws Exception {
final AtomicInteger openFilesCounter = new AtomicInteger();
PageSwapperFactory factory = createSwapperFactory(new DelegatingFileSystemAbstraction(fileSystem) {
@Override
public StoreChannel open(Path fileName, Set<OpenOption> options) throws IOException {
openFilesCounter.getAndIncrement();
return new DelegatingStoreChannel(super.open(fileName, options)) {
@Override
public void close() throws IOException {
openFilesCounter.getAndDecrement();
super.close();
}
};
}
});
Path file = testDir.file("file");
try (StoreChannel ch = fileSystem.write(file);
FileLock ignore = ch.tryLock()) {
createSwapper(factory, file, 4, NO_CALLBACK, false).close();
fail("Creating a page swapper for a locked channel should have thrown");
} catch (FileLockException e) {
// As expected.
}
assertThat(openFilesCounter.get()).isEqualTo(0);
}
Aggregations