use of org.neo4j.graphdb.mockfs.DelegatingStoreChannel in project neo4j by neo4j.
the class NodeStoreTest method shouldCloseStoreFileOnFailureToOpen.
@Test
public void shouldCloseStoreFileOnFailureToOpen() throws Exception {
// GIVEN
final AtomicBoolean fired = new AtomicBoolean();
FileSystemAbstraction fs = new DelegatingFileSystemAbstraction(efs.get()) {
@Override
public StoreChannel open(File fileName, String mode) throws IOException {
return new DelegatingStoreChannel(super.open(fileName, mode)) {
@Override
public int read(ByteBuffer dst) throws IOException {
Exception stack = new Exception();
if (containsStackTraceElement(stack, item -> item.getMethodName().equals("initGenerator")) && !containsStackTraceElement(stack, item -> item.getMethodName().equals("createNodeStore"))) {
fired.set(true);
throw new IOException("Proving a point here");
}
return super.read(dst);
}
};
}
};
// WHEN
try (PageCache pageCache = pageCacheRule.getPageCache(fs)) {
newNodeStore(fs);
fail("Should fail");
}// Close the page cache here so that we can see failure to close (due to still mapped files)
catch (Exception e) {
// THEN
assertTrue(contains(e, IOException.class));
assertTrue(fired.get());
}
}
use of org.neo4j.graphdb.mockfs.DelegatingStoreChannel in project neo4j by neo4j.
the class PageCacheTest method flushingDuringPagedFileCloseMustRetryUntilItSucceeds.
@RepeatRule.Repeat(times = 100)
@Test(timeout = SHORT_TIMEOUT_MILLIS)
public void flushingDuringPagedFileCloseMustRetryUntilItSucceeds() throws IOException {
FileSystemAbstraction fs = new DelegatingFileSystemAbstraction(this.fs) {
@Override
public StoreChannel open(File fileName, String mode) throws IOException {
return new DelegatingStoreChannel(super.open(fileName, mode)) {
private int writeCount = 0;
@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, pageCachePageSize, PageCacheTracer.NULL, PageCursorTracerSupplier.NULL);
PrintStream oldSystemErr = System.err;
try (PagedFile pf = pageCache.map(file("a"), filePageSize);
PageCursor cursor = pf.io(0, PF_SHARED_WRITE_LOCK)) {
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.graphdb.mockfs.DelegatingStoreChannel in project neo4j by neo4j.
the class SingleFilePageSwapperTest method mustCloseFilesIfTakingFileLockThrows.
@Test
public void mustCloseFilesIfTakingFileLockThrows() throws Exception {
// no file locking on Windows.
assumeFalse("No file locking on Windows", SystemUtils.IS_OS_WINDOWS);
final AtomicInteger openFilesCounter = new AtomicInteger();
PageSwapperFactory factory = createSwapperFactory();
factory.setFileSystemAbstraction(new DelegatingFileSystemAbstraction(fileSystem) {
@Override
public StoreChannel open(File fileName, String mode) throws IOException {
openFilesCounter.getAndIncrement();
return new DelegatingStoreChannel(super.open(fileName, mode)) {
@Override
public void close() throws IOException {
openFilesCounter.getAndDecrement();
super.close();
}
};
}
});
File file = testDir.file("file");
try (StoreChannel ch = fileSystem.create(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(), is(0));
}
use of org.neo4j.graphdb.mockfs.DelegatingStoreChannel in project neo4j by neo4j.
the class StoreLockerTest method shouldNotObtainLockWhenStoreAlreadyInUse.
@Test
public void shouldNotObtainLockWhenStoreAlreadyInUse() throws Exception {
FileSystemAbstraction fileSystemAbstraction = new DelegatingFileSystemAbstraction(fileSystemRule.get()) {
@Override
public boolean fileExists(File fileName) {
return false;
}
@Override
public StoreChannel open(File fileName, String mode) throws IOException {
return new DelegatingStoreChannel(super.open(fileName, mode)) {
@Override
public FileLock tryLock() throws IOException {
// 'null' implies that the file has been externally locked
return null;
}
};
}
};
try (StoreLocker storeLocker = new StoreLocker(fileSystemAbstraction)) {
storeLocker.checkLock(target.directory("unused"));
fail();
} catch (StoreLockException e) {
assertThat(e.getMessage(), containsString("Store and its lock file has been locked by another process"));
}
}
Aggregations