use of org.neo4j.io.fs.StoreChannel in project neo4j by neo4j.
the class FileSenderTest method sendSmallFile.
@Test
public void sendSmallFile() throws Exception {
// given
byte[] bytes = new byte[10];
random.nextBytes(bytes);
File smallFile = testDirectory.file("smallFile");
try (StoreChannel storeChannel = fs.create(smallFile)) {
storeChannel.write(ByteBuffer.wrap(bytes));
}
FileSender fileSender = new FileSender(fs.open(smallFile, "r"));
// when + then
assertFalse(fileSender.isEndOfInput());
assertEquals(FileChunk.create(bytes, true), fileSender.readChunk(allocator));
assertNull(fileSender.readChunk(allocator));
assertTrue(fileSender.isEndOfInput());
}
use of org.neo4j.io.fs.StoreChannel in project neo4j by neo4j.
the class CheckTxLogsTest method writeContent.
private void writeContent(File log, ThrowingConsumer<TransactionLogWriter, IOException> consumer) throws IOException {
FileSystemAbstraction fs = ensureLogExists(log);
try (StoreChannel channel = fs.open(log, "rw");
LogVersionedStoreChannel versionedChannel = new PhysicalLogVersionedStoreChannel(channel, 0, (byte) 0);
PhysicalFlushableChannel writableLogChannel = new PhysicalFlushableChannel(versionedChannel)) {
long offset = channel.size();
channel.position(offset);
consumer.accept(new TransactionLogWriter(new LogEntryWriter(writableLogChannel)));
}
}
use of org.neo4j.io.fs.StoreChannel in project neo4j by neo4j.
the class RecoveryProtocolTest method createLogFile.
private void createLogFile(EphemeralFileSystemAbstraction fsa, long prevFileLastIndex, long fileNameVersion, long headerVersion, long prevIndex, long prevTerm) throws IOException {
StoreChannel channel = fsa.open(fileNames.getForVersion(fileNameVersion), "w");
PhysicalFlushableChannel writer = new PhysicalFlushableChannel(channel);
headerMarshal.marshal(new SegmentHeader(prevFileLastIndex, headerVersion, prevIndex, prevTerm), writer);
writer.prepareForFlush().flush();
channel.close();
}
use of org.neo4j.io.fs.StoreChannel in project neo4j by neo4j.
the class SegmentFileTest method shouldNotReturnReaderExperiencingErrorToPool.
@Test
public void shouldNotReturnReaderExperiencingErrorToPool() throws Exception {
// given
StoreChannel channel = mock(StoreChannel.class);
Reader reader = mock(Reader.class);
ReaderPool readerPool = mock(ReaderPool.class);
when(channel.read(any(ByteBuffer.class))).thenThrow(new IOException());
when(reader.channel()).thenReturn(channel);
when(readerPool.acquire(anyLong(), anyLong())).thenReturn(reader);
try (SegmentFile segment = create(fsRule.get(), fileNames.getForVersion(0), readerPool, 0, contentMarshal, logProvider, segmentHeader)) {
// given
IOCursor<EntryRecord> cursor = segment.getCursor(0);
try {
cursor.next();
fail();
} catch (IOException e) {
// expected from mocking
}
// when
cursor.close();
// then
verify(readerPool, never()).release(reader);
verify(reader).close();
}
}
use of org.neo4j.io.fs.StoreChannel in project neo4j by neo4j.
the class MuninnPageCacheTest method mustFlushDirtyPagesOnEvictingFirstPage.
@Test
public void mustFlushDirtyPagesOnEvictingFirstPage() throws Exception {
writeInitialDataTo(file("a"));
RecordingPageCacheTracer tracer = new RecordingPageCacheTracer();
RecordingPageCursorTracer cursorTracer = new RecordingPageCursorTracer();
ConfigurablePageCursorTracerSupplier cursorTracerSupplier = new ConfigurablePageCursorTracerSupplier(cursorTracer);
MuninnPageCache pageCache = createPageCache(fs, 2, 8, blockCacheFlush(tracer), cursorTracerSupplier);
PagedFile pagedFile = pageCache.map(file("a"), 8);
try (PageCursor cursor = pagedFile.io(0, PF_SHARED_WRITE_LOCK)) {
assertTrue(cursor.next());
cursor.putLong(0L);
}
cursorTracer.reportEvents();
assertNotNull(cursorTracer.observe(Fault.class));
assertEquals(1, cursorTracer.faults());
assertEquals(1, tracer.faults());
int clockArm = pageCache.evictPages(1, 0, tracer.beginPageEvictions(1));
assertThat(clockArm, is(1));
assertNotNull(tracer.observe(Evict.class));
ByteBuffer buf = ByteBuffer.allocate(16);
StoreChannel channel = fs.open(file("a"), "r");
channel.read(buf);
buf.flip();
assertThat(buf.getLong(), is(0L));
assertThat(buf.getLong(), is(y));
}
Aggregations