Search in sources :

Example 1 with CachedTailSeekableByteChannel

use of org.apache.beam.runners.dataflow.worker.IsmReaderImpl.CachedTailSeekableByteChannel in project beam by apache.

the class IsmReaderTest method testCachedTailSeekableByteChannelThrowsOnTruncate.

@Test
public void testCachedTailSeekableByteChannelThrowsOnTruncate() throws Exception {
    try (SeekableByteChannel channel = new CachedTailSeekableByteChannel(0, new byte[0])) {
        expectedException.expect(NonWritableChannelException.class);
        channel.truncate(0);
    }
}
Also used : SeekableByteChannel(java.nio.channels.SeekableByteChannel) CachedTailSeekableByteChannel(org.apache.beam.runners.dataflow.worker.IsmReaderImpl.CachedTailSeekableByteChannel) CachedTailSeekableByteChannel(org.apache.beam.runners.dataflow.worker.IsmReaderImpl.CachedTailSeekableByteChannel) Test(org.junit.Test)

Example 2 with CachedTailSeekableByteChannel

use of org.apache.beam.runners.dataflow.worker.IsmReaderImpl.CachedTailSeekableByteChannel in project beam by apache.

the class IsmReaderTest method testCachedTailSeekableByteChannelSeekBeforeBounds.

@Test
public void testCachedTailSeekableByteChannelSeekBeforeBounds() throws Exception {
    try (SeekableByteChannel channel = new CachedTailSeekableByteChannel(1, new byte[0])) {
        // Seek to only valid position
        channel.position(1);
        expectedException.expect(IllegalArgumentException.class);
        channel.position(0);
    }
}
Also used : SeekableByteChannel(java.nio.channels.SeekableByteChannel) CachedTailSeekableByteChannel(org.apache.beam.runners.dataflow.worker.IsmReaderImpl.CachedTailSeekableByteChannel) CachedTailSeekableByteChannel(org.apache.beam.runners.dataflow.worker.IsmReaderImpl.CachedTailSeekableByteChannel) Test(org.junit.Test)

Example 3 with CachedTailSeekableByteChannel

use of org.apache.beam.runners.dataflow.worker.IsmReaderImpl.CachedTailSeekableByteChannel in project beam by apache.

the class IsmReaderTest method testCachedTailSeekableByteChannelRead.

@Test
public void testCachedTailSeekableByteChannelRead() throws Exception {
    final int offset = 10;
    try (SeekableByteChannel channel = new CachedTailSeekableByteChannel(offset, new byte[] { 0, 1, 2 })) {
        ByteBuffer buffer = ByteBuffer.allocate(1);
        channel.position(offset);
        assertEquals(1, channel.read(buffer));
        assertEquals(0, buffer.get(0));
        assertEquals(offset + 1, channel.position());
        buffer.clear();
        assertEquals(1, channel.read(buffer));
        assertEquals(1, buffer.get(0));
        assertEquals(offset + 2, channel.position());
        buffer.clear();
        assertEquals(1, channel.read(buffer));
        assertEquals(2, buffer.get(0));
        assertEquals(offset + 3, channel.position());
        buffer.clear();
        // Reposition the stream and do a read
        channel.position(offset + 1);
        assertEquals(1, channel.read(buffer));
        assertEquals(1, buffer.get(0));
        assertEquals(offset + 2, channel.position());
        buffer.clear();
        assertEquals(1, channel.read(buffer));
        assertEquals(2, buffer.get(0));
        assertEquals(offset + 3, channel.position());
        buffer.clear();
        // This read is expected to return EOF
        assertEquals(-1, channel.read(buffer));
        buffer.clear();
        // Reposition the stream to EOF and do a read, expected to return EOF
        channel.position(offset + 3);
        assertEquals(-1, channel.read(buffer));
        buffer.clear();
    }
}
Also used : SeekableByteChannel(java.nio.channels.SeekableByteChannel) CachedTailSeekableByteChannel(org.apache.beam.runners.dataflow.worker.IsmReaderImpl.CachedTailSeekableByteChannel) ByteBuffer(java.nio.ByteBuffer) CachedTailSeekableByteChannel(org.apache.beam.runners.dataflow.worker.IsmReaderImpl.CachedTailSeekableByteChannel) Test(org.junit.Test)

Example 4 with CachedTailSeekableByteChannel

use of org.apache.beam.runners.dataflow.worker.IsmReaderImpl.CachedTailSeekableByteChannel in project beam by apache.

the class IsmReaderTest method testCachedTailSeekableByteChannelThrowsOnWrite.

@Test
public void testCachedTailSeekableByteChannelThrowsOnWrite() throws Exception {
    try (SeekableByteChannel channel = new CachedTailSeekableByteChannel(0, new byte[0])) {
        expectedException.expect(NonWritableChannelException.class);
        channel.write(ByteBuffer.wrap(new byte[0]));
    }
}
Also used : SeekableByteChannel(java.nio.channels.SeekableByteChannel) CachedTailSeekableByteChannel(org.apache.beam.runners.dataflow.worker.IsmReaderImpl.CachedTailSeekableByteChannel) CachedTailSeekableByteChannel(org.apache.beam.runners.dataflow.worker.IsmReaderImpl.CachedTailSeekableByteChannel) Test(org.junit.Test)

Example 5 with CachedTailSeekableByteChannel

use of org.apache.beam.runners.dataflow.worker.IsmReaderImpl.CachedTailSeekableByteChannel in project beam by apache.

the class IsmReaderTest method testCachedTailSeekableByteChannelSeekBeyondBounds.

@Test
public void testCachedTailSeekableByteChannelSeekBeyondBounds() throws Exception {
    try (SeekableByteChannel channel = new CachedTailSeekableByteChannel(1, new byte[0])) {
        // Seek to only valid position
        channel.position(1);
        expectedException.expect(IllegalArgumentException.class);
        channel.position(2);
    }
}
Also used : SeekableByteChannel(java.nio.channels.SeekableByteChannel) CachedTailSeekableByteChannel(org.apache.beam.runners.dataflow.worker.IsmReaderImpl.CachedTailSeekableByteChannel) CachedTailSeekableByteChannel(org.apache.beam.runners.dataflow.worker.IsmReaderImpl.CachedTailSeekableByteChannel) Test(org.junit.Test)

Aggregations

SeekableByteChannel (java.nio.channels.SeekableByteChannel)5 CachedTailSeekableByteChannel (org.apache.beam.runners.dataflow.worker.IsmReaderImpl.CachedTailSeekableByteChannel)5 Test (org.junit.Test)5 ByteBuffer (java.nio.ByteBuffer)1