use of org.neo4j.io.fs.StoreChannel in project neo4j by neo4j.
the class PhysicalFlushableChannelTest method shouldThrowClosedChannelExceptionWhenChannelUnexpectedlyClosed.
@Test
void shouldThrowClosedChannelExceptionWhenChannelUnexpectedlyClosed() throws Exception {
// GIVEN
final Path file = directory.homePath().resolve("file");
StoreChannel storeChannel = fileSystem.write(file);
PhysicalLogVersionedStoreChannel versionedStoreChannel = new PhysicalLogVersionedStoreChannel(storeChannel, 1, (byte) -1, file, nativeChannelAccessor);
PhysicalFlushableChannel channel = new PhysicalFlushableChannel(versionedStoreChannel, INSTANCE);
// just close the underlying channel
storeChannel.close();
// WHEN just appending something to the buffer
channel.put((byte) 0);
// and wanting to empty that into the channel
assertThrows(ClosedChannelException.class, channel::prepareForFlush);
}
use of org.neo4j.io.fs.StoreChannel in project neo4j by neo4j.
the class PhysicalFlushableChannelTest method shouldThrowIllegalStateExceptionAfterClosed.
@Test
void shouldThrowIllegalStateExceptionAfterClosed() throws Exception {
// GIVEN
final Path file = directory.homePath().resolve("file");
StoreChannel storeChannel = fileSystem.write(file);
PhysicalLogVersionedStoreChannel versionedStoreChannel = new PhysicalLogVersionedStoreChannel(storeChannel, 1, (byte) -1, file, nativeChannelAccessor);
PhysicalFlushableChannel channel = new PhysicalFlushableChannel(versionedStoreChannel, INSTANCE);
// closing the WritableLogChannel, then the underlying channel is what PhysicalLogFile does
channel.close();
storeChannel.close();
// WHEN just appending something to the buffer
channel.put((byte) 0);
// and wanting to empty that into the channel
assertThrows(IllegalStateException.class, channel::prepareForFlush);
}
use of org.neo4j.io.fs.StoreChannel in project neo4j by neo4j.
the class PhysicalFlushableChannelTest method shouldBeAbleToWriteValuesGreaterThanTheBufferSize.
@Test
void shouldBeAbleToWriteValuesGreaterThanTheBufferSize() throws IOException {
final Path firstFile = directory.homePath().resolve("file1");
StoreChannel storeChannel = fileSystem.write(firstFile);
PhysicalLogVersionedStoreChannel versionedStoreChannel = new PhysicalLogVersionedStoreChannel(storeChannel, 1, (byte) -1, firstFile, nativeChannelAccessor);
int length = 1_000_000;
byte[] bytes;
try (PhysicalFlushableChannel channel = new PhysicalFlushableChannel(versionedStoreChannel, INSTANCE)) {
bytes = generateBytes(length);
channel.put(bytes, length);
}
byte[] writtenBytes = new byte[length];
try (InputStream in = Files.newInputStream(firstFile)) {
in.read(writtenBytes);
}
assertArrayEquals(bytes, writtenBytes);
}
use of org.neo4j.io.fs.StoreChannel in project neo4j by neo4j.
the class PhysicalFlushableChannelTest method shouldBeAbleToWriteSmallNumberOfBytes.
@Test
void shouldBeAbleToWriteSmallNumberOfBytes() throws IOException {
final Path firstFile = directory.homePath().resolve("file1");
StoreChannel storeChannel = fileSystem.write(firstFile);
PhysicalLogVersionedStoreChannel versionedStoreChannel = new PhysicalLogVersionedStoreChannel(storeChannel, 1, (byte) -1, firstFile, nativeChannelAccessor);
int length = 26_145;
byte[] bytes;
try (PhysicalFlushableChannel channel = new PhysicalFlushableChannel(versionedStoreChannel, new HeapScopedBuffer(100, INSTANCE))) {
bytes = generateBytes(length);
channel.put(bytes, length);
}
byte[] writtenBytes = new byte[length];
try (InputStream in = Files.newInputStream(firstFile)) {
in.read(writtenBytes);
}
assertArrayEquals(bytes, writtenBytes);
}
use of org.neo4j.io.fs.StoreChannel in project neo4j by neo4j.
the class PhysicalFlushableChannelTest method releaseBufferMemoryOnClose.
@Test
void releaseBufferMemoryOnClose() throws IOException {
var memoryTracker = new LocalMemoryTracker();
final Path firstFile = directory.homePath().resolve("file2");
StoreChannel storeChannel = fileSystem.write(firstFile);
PhysicalLogVersionedStoreChannel versionedStoreChannel = new PhysicalLogVersionedStoreChannel(storeChannel, 1, (byte) -1, firstFile, nativeChannelAccessor);
assertThat(memoryTracker.estimatedHeapMemory()).isZero();
assertThat(memoryTracker.usedNativeMemory()).isZero();
try (PhysicalFlushableChannel channel = new PhysicalFlushableChannel(versionedStoreChannel, memoryTracker)) {
channel.put((byte) 1);
assertThat(memoryTracker.usedNativeMemory()).isZero();
assertThat(memoryTracker.estimatedHeapMemory()).isGreaterThan(0);
}
assertThat(memoryTracker.estimatedHeapMemory()).isZero();
assertThat(memoryTracker.usedNativeMemory()).isZero();
}
Aggregations