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);
}
}
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);
}
}
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();
}
}
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]));
}
}
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);
}
}
Aggregations