Search in sources :

Example 1 with AsyncStreamingInputPlus

use of org.apache.cassandra.net.AsyncStreamingInputPlus in project cassandra by apache.

the class BigTableZeroCopyWriterTest method writeDataFile_RebufferingByteBufDataInputPlus.

@Test
public void writeDataFile_RebufferingByteBufDataInputPlus() {
    try (AsyncStreamingInputPlus input = new AsyncStreamingInputPlus(new EmbeddedChannel())) {
        writeDataTestCycle(buffer -> {
            input.append(Unpooled.wrappedBuffer(buffer));
            return input;
        });
        input.requestClosure();
    }
}
Also used : AsyncStreamingInputPlus(org.apache.cassandra.net.AsyncStreamingInputPlus) EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) Test(org.junit.Test)

Example 2 with AsyncStreamingInputPlus

use of org.apache.cassandra.net.AsyncStreamingInputPlus in project cassandra by apache.

the class AsyncStreamingInputPlusTest method consumeUntilTestCycle.

private void consumeUntilTestCycle(int nBuffs, int buffSize, int startOffset, int len) throws IOException {
    inputPlus = new AsyncStreamingInputPlus(channel);
    byte[] expectedBytes = new byte[len];
    int count = 0;
    for (int j = 0; j < nBuffs; j++) {
        ByteBuf buf = channel.alloc().buffer(buffSize);
        for (int i = 0; i < buf.capacity(); i++) {
            buf.writeByte(j);
            if (count >= startOffset && (count - startOffset) < len)
                expectedBytes[count - startOffset] = (byte) j;
            count++;
        }
        inputPlus.append(buf);
    }
    inputPlus.requestClosure();
    TestableWritableByteChannel wbc = new TestableWritableByteChannel(len);
    inputPlus.skipBytesFully(startOffset);
    BufferedDataOutputStreamPlus writer = new BufferedDataOutputStreamPlus(wbc);
    inputPlus.consume(buffer -> {
        writer.write(buffer);
        return buffer.remaining();
    }, len);
    writer.close();
    Assert.assertEquals(String.format("Test with %d buffers starting at %d consuming %d bytes", nBuffs, startOffset, len), len, wbc.writtenBytes.readableBytes());
    Assert.assertArrayEquals(expectedBytes, wbc.writtenBytes.array());
}
Also used : AsyncStreamingInputPlus(org.apache.cassandra.net.AsyncStreamingInputPlus) ByteBuf(io.netty.buffer.ByteBuf) BufferedDataOutputStreamPlus(org.apache.cassandra.io.util.BufferedDataOutputStreamPlus)

Example 3 with AsyncStreamingInputPlus

use of org.apache.cassandra.net.AsyncStreamingInputPlus in project cassandra by apache.

the class AsyncStreamingInputPlusTest method append_closed.

// @Test
// public void isOpen()
// {
// Assert.assertTrue(inputPlus.isOpen());
// inputPlus.requestClosure();
// Assert.assertFalse(inputPlus.isOpen());
// }
@Test
public void append_closed() {
    inputPlus = new AsyncStreamingInputPlus(channel);
    inputPlus.requestClosure();
    inputPlus.close();
    buf = channel.alloc().buffer(4);
    assertFalse(inputPlus.append(buf));
}
Also used : AsyncStreamingInputPlus(org.apache.cassandra.net.AsyncStreamingInputPlus) Test(org.junit.Test)

Example 4 with AsyncStreamingInputPlus

use of org.apache.cassandra.net.AsyncStreamingInputPlus in project cassandra by apache.

the class AsyncStreamingInputPlusTest method available_HappyPath.

@Test
public void available_HappyPath() {
    inputPlus = new AsyncStreamingInputPlus(channel);
    int size = 4;
    buf = channel.alloc().heapBuffer(size);
    buf.writerIndex(size);
    inputPlus.append(buf);
    Assert.assertEquals(size, inputPlus.unsafeAvailable());
}
Also used : AsyncStreamingInputPlus(org.apache.cassandra.net.AsyncStreamingInputPlus) Test(org.junit.Test)

Example 5 with AsyncStreamingInputPlus

use of org.apache.cassandra.net.AsyncStreamingInputPlus in project cassandra by apache.

the class AsyncStreamingInputPlusTest method available_closed.

// @Test (expected = EOFException.class)
// public void read_closed() throws IOException
// {
// inputPlus.requestClosure();
// ByteBuffer buf = ByteBuffer.allocate(1);
// inputPlus.read(buf);
// }
@Test
public void available_closed() {
    inputPlus = new AsyncStreamingInputPlus(channel);
    inputPlus.requestClosure();
    inputPlus.unsafeAvailable();
}
Also used : AsyncStreamingInputPlus(org.apache.cassandra.net.AsyncStreamingInputPlus) Test(org.junit.Test)

Aggregations

AsyncStreamingInputPlus (org.apache.cassandra.net.AsyncStreamingInputPlus)11 Test (org.junit.Test)8 EmbeddedChannel (io.netty.channel.embedded.EmbeddedChannel)3 ByteBuf (io.netty.buffer.ByteBuf)2 SSTableMultiWriter (org.apache.cassandra.io.sstable.SSTableMultiWriter)2 SSTableReader (org.apache.cassandra.io.sstable.format.SSTableReader)2 Benchmark (org.openjdk.jmh.annotations.Benchmark)2 BenchmarkMode (org.openjdk.jmh.annotations.BenchmarkMode)2 BufferedDataOutputStreamPlus (org.apache.cassandra.io.util.BufferedDataOutputStreamPlus)1 InputTimeoutException (org.apache.cassandra.net.AsyncStreamingInputPlus.InputTimeoutException)1