use of org.neo4j.io.fs.DelegatingFileSystemAbstraction in project neo4j by neo4j.
the class FileUserRepositoryTest method shouldRecoverIfCrashedDuringMove.
@Test
void shouldRecoverIfCrashedDuringMove() throws Throwable {
// Given
final IOException exception = new IOException("simulated IO Exception on create");
FileSystemAbstraction crashingFileSystem = new DelegatingFileSystemAbstraction(fs) {
@Override
public void renameFile(Path oldLocation, Path newLocation, CopyOption... copyOptions) throws IOException {
if (authFile.getFileName().equals(newLocation.getFileName())) {
throw exception;
}
super.renameFile(oldLocation, newLocation, copyOptions);
}
};
FileUserRepository users = new FileUserRepository(crashingFileSystem, authFile, logProvider);
users.start();
User user = new User.Builder("jake", LegacyCredential.INACCESSIBLE).withRequiredPasswordChange(true).build();
// When
var e = assertThrows(IOException.class, () -> users.create(user));
assertSame(exception, e);
// Then
assertFalse(crashingFileSystem.fileExists(authFile));
assertThat(crashingFileSystem.listFiles(authFile.getParent()).length).isEqualTo(0);
}
use of org.neo4j.io.fs.DelegatingFileSystemAbstraction in project neo4j by neo4j.
the class MuninnPageCacheTest method mustUnblockPageFaultersWhenEvictionGetsException.
@Test
void mustUnblockPageFaultersWhenEvictionGetsException() {
assertTimeoutPreemptively(ofMillis(SEMI_LONG_TIMEOUT_MILLIS), () -> {
writeInitialDataTo(file("a"));
MutableBoolean throwException = new MutableBoolean(true);
FileSystemAbstraction fs = new DelegatingFileSystemAbstraction(this.fs) {
@Override
public StoreChannel open(Path fileName, Set<OpenOption> options) throws IOException {
return new DelegatingStoreChannel(super.open(fileName, options)) {
@Override
public void writeAll(ByteBuffer src, long position) throws IOException {
if (throwException.booleanValue()) {
throw new IOException("uh-oh...");
} else {
super.writeAll(src, position);
}
}
};
}
};
try (MuninnPageCache pageCache = createPageCache(fs, 2, PageCacheTracer.NULL);
PagedFile pagedFile = map(pageCache, file("a"), 8)) {
// exceptions on all writes.
try (PageCursor cursor = pagedFile.io(0, PF_SHARED_WRITE_LOCK, NULL)) {
for (int i = 0; i < 1000; i++) {
assertTrue(cursor.next());
}
fail("Expected an exception at this point");
} catch (IOException ignore) {
// Good.
}
throwException.setFalse();
}
});
}
use of org.neo4j.io.fs.DelegatingFileSystemAbstraction in project neo4j by neo4j.
the class PageCacheTest method flushingDuringPagedFileCloseMustRetryUntilItSucceeds.
@RepeatedTest(100)
void flushingDuringPagedFileCloseMustRetryUntilItSucceeds() {
assertTimeoutPreemptively(ofMillis(SHORT_TIMEOUT_MILLIS), () -> {
FileSystemAbstraction fs = new DelegatingFileSystemAbstraction(this.fs) {
@Override
public StoreChannel open(Path fileName, Set<OpenOption> options) throws IOException {
return new DelegatingStoreChannel(super.open(fileName, options)) {
private int writeCount;
@Override
public void writeAll(ByteBuffer src, long position) throws IOException {
if (writeCount++ < 10) {
throw new IOException("This is a benign exception that we expect to be thrown " + "during a flush of a PagedFile.");
}
super.writeAll(src, position);
}
};
}
};
getPageCache(fs, maxPages, PageCacheTracer.NULL);
PrintStream oldSystemErr = System.err;
try (PagedFile pf = map(file("a"), filePageSize);
PageCursor cursor = pf.io(0, PF_SHARED_WRITE_LOCK, NULL)) {
assertTrue(cursor.next());
writeRecords(cursor);
// Silence any stack traces the failed flushes might print.
System.setErr(new PrintStream(new ByteArrayOutputStream()));
} finally {
System.setErr(oldSystemErr);
}
verifyRecordsInFile(file("a"), recordsPerFilePage);
});
}
use of org.neo4j.io.fs.DelegatingFileSystemAbstraction in project neo4j by neo4j.
the class MuninnPageCacheTest method pageCacheFlushAndForceMustClearBackgroundEvictionException.
@Test
void pageCacheFlushAndForceMustClearBackgroundEvictionException() {
assertTimeoutPreemptively(ofMillis(SEMI_LONG_TIMEOUT_MILLIS), () -> {
MutableBoolean throwException = new MutableBoolean(true);
FileSystemAbstraction fs = new DelegatingFileSystemAbstraction(this.fs) {
@Override
public StoreChannel open(Path fileName, Set<OpenOption> options) throws IOException {
return new DelegatingStoreChannel(super.open(fileName, options)) {
@Override
public void writeAll(ByteBuffer src, long position) throws IOException {
if (throwException.booleanValue()) {
throw new IOException("uh-oh...");
} else {
super.writeAll(src, position);
}
}
};
}
};
try (MuninnPageCache pageCache = createPageCache(fs, 2, PageCacheTracer.NULL);
PagedFile pagedFile = map(pageCache, file("a"), 8)) {
try (PageCursor cursor = pagedFile.io(0, PF_SHARED_WRITE_LOCK, NULL)) {
// Page 0 is now dirty, but flushing it will throw an exception.
assertTrue(cursor.next());
}
// This will run into that exception, in background eviction:
pageCache.evictPages(1, 0, EvictionRunEvent.NULL);
// We now have a background eviction exception. A successful flushAndForce should clear it, though.
throwException.setFalse();
pageCache.flushAndForce();
// And with a cleared exception, we should be able to work with the page cache without worry.
try (PageCursor cursor = pagedFile.io(0, PF_SHARED_WRITE_LOCK, NULL)) {
for (int i = 0; i < maxPages * 20; i++) {
assertTrue(cursor.next());
}
}
}
});
}
use of org.neo4j.io.fs.DelegatingFileSystemAbstraction in project neo4j by neo4j.
the class FileLockerTest method shouldNotObtainLockWhenAlreadyInUse.
@ParameterizedTest
@MethodSource("lockerFactories")
void shouldNotObtainLockWhenAlreadyInUse(LockerFactory lockerFactory) {
FileSystemAbstraction fileSystemAbstraction = new DelegatingFileSystemAbstraction(fileSystem) {
@Override
public boolean fileExists(Path file) {
return false;
}
@Override
public StoreChannel write(Path fileName) throws IOException {
return new DelegatingStoreChannel(super.write(fileName)) {
@Override
public FileLock tryLock() {
// 'null' implies that the file has been externally locked
return null;
}
};
}
};
FileLockException fileLockException = assertThrows(FileLockException.class, () -> {
try (Locker storeLocker = lockerFactory.createLocker(fileSystemAbstraction, testDirectory)) {
storeLocker.checkLock();
}
});
assertThat(fileLockException.getMessage()).contains("Lock file has been locked by another process");
}
Aggregations