Search in sources :

Example 6 with ReadPastEndException

use of org.neo4j.storageengine.api.ReadPastEndException in project neo4j by neo4j.

the class ReadAheadChannelTest method shouldReturnPositionWithinBufferedStream.

@Test
public void shouldReturnPositionWithinBufferedStream() throws Exception {
    // given
    EphemeralFileSystemAbstraction fsa = fileSystemRule.get();
    File file = new File("foo.txt");
    int readAheadSize = 512;
    int fileSize = readAheadSize * 8;
    createFile(fsa, file, fileSize);
    ReadAheadChannel<StoreChannel> bufferedReader = new ReadAheadChannel<>(fsa.open(file, "r"), readAheadSize);
    // when
    for (int i = 0; i < fileSize / Long.BYTES; i++) {
        assertEquals(Long.BYTES * i, bufferedReader.position());
        bufferedReader.getLong();
    }
    assertEquals(fileSize, bufferedReader.position());
    try {
        bufferedReader.getLong();
        fail();
    } catch (ReadPastEndException e) {
    // expected
    }
    assertEquals(fileSize, bufferedReader.position());
}
Also used : EphemeralFileSystemAbstraction(org.neo4j.graphdb.mockfs.EphemeralFileSystemAbstraction) StoreChannel(org.neo4j.io.fs.StoreChannel) File(java.io.File) ReadPastEndException(org.neo4j.storageengine.api.ReadPastEndException) Test(org.junit.Test)

Aggregations

ReadPastEndException (org.neo4j.storageengine.api.ReadPastEndException)6 File (java.io.File)4 Test (org.junit.Test)4 EphemeralFileSystemAbstraction (org.neo4j.graphdb.mockfs.EphemeralFileSystemAbstraction)4 StoreChannel (org.neo4j.io.fs.StoreChannel)4 ByteBuffer (java.nio.ByteBuffer)3 FileSystemAbstraction (org.neo4j.io.fs.FileSystemAbstraction)3 IOException (java.io.IOException)1 ReplicatedContent (org.neo4j.causalclustering.core.replication.ReplicatedContent)1 EndOfStreamException (org.neo4j.causalclustering.messaging.EndOfStreamException)1 Exceptions.launderedException (org.neo4j.helpers.Exceptions.launderedException)1 LogPosition (org.neo4j.kernel.impl.transaction.log.LogPosition)1 LogPositionMarker (org.neo4j.kernel.impl.transaction.log.LogPositionMarker)1