Search in sources :

Example 1 with PhysicalFlushableChannel

use of org.neo4j.io.fs.PhysicalFlushableChannel in project neo4j by neo4j.

the class PhysicalFlushableChannelTest method shouldBeAbleToWriteValuesGreaterThanHalfTheBufferSize.

@Test
void shouldBeAbleToWriteValuesGreaterThanHalfTheBufferSize() 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 = 262_145;
    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);
}
Also used : Path(java.nio.file.Path) PhysicalFlushableChannel(org.neo4j.io.fs.PhysicalFlushableChannel) InputStream(java.io.InputStream) StoreChannel(org.neo4j.io.fs.StoreChannel) Test(org.junit.jupiter.api.Test)

Example 2 with PhysicalFlushableChannel

use of org.neo4j.io.fs.PhysicalFlushableChannel 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);
}
Also used : Path(java.nio.file.Path) PhysicalFlushableChannel(org.neo4j.io.fs.PhysicalFlushableChannel) StoreChannel(org.neo4j.io.fs.StoreChannel) Test(org.junit.jupiter.api.Test)

Example 3 with PhysicalFlushableChannel

use of org.neo4j.io.fs.PhysicalFlushableChannel 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);
}
Also used : Path(java.nio.file.Path) PhysicalFlushableChannel(org.neo4j.io.fs.PhysicalFlushableChannel) StoreChannel(org.neo4j.io.fs.StoreChannel) Test(org.junit.jupiter.api.Test)

Example 4 with PhysicalFlushableChannel

use of org.neo4j.io.fs.PhysicalFlushableChannel 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);
}
Also used : Path(java.nio.file.Path) PhysicalFlushableChannel(org.neo4j.io.fs.PhysicalFlushableChannel) InputStream(java.io.InputStream) StoreChannel(org.neo4j.io.fs.StoreChannel) Test(org.junit.jupiter.api.Test)

Example 5 with PhysicalFlushableChannel

use of org.neo4j.io.fs.PhysicalFlushableChannel 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);
}
Also used : Path(java.nio.file.Path) HeapScopedBuffer(org.neo4j.io.memory.HeapScopedBuffer) PhysicalFlushableChannel(org.neo4j.io.fs.PhysicalFlushableChannel) InputStream(java.io.InputStream) StoreChannel(org.neo4j.io.fs.StoreChannel) Test(org.junit.jupiter.api.Test)

Aggregations

Path (java.nio.file.Path)6 Test (org.junit.jupiter.api.Test)6 PhysicalFlushableChannel (org.neo4j.io.fs.PhysicalFlushableChannel)6 StoreChannel (org.neo4j.io.fs.StoreChannel)6 InputStream (java.io.InputStream)3 HeapScopedBuffer (org.neo4j.io.memory.HeapScopedBuffer)1 LocalMemoryTracker (org.neo4j.memory.LocalMemoryTracker)1