Search in sources :

Example 6 with AsyncStreamingInputPlus

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

the class AsyncStreamingInputPlusTest method read.

@Test
public void read() throws IOException {
    inputPlus = new AsyncStreamingInputPlus(channel);
    // put two buffers of 8 bytes each into the queue.
    // then read an int, then a long. the latter tests offset into the inputPlus, as well as spanning across queued buffers.
    // the values of those int/long will both be '42', but spread across both queue buffers.
    ByteBuf buf = channel.alloc().buffer(8);
    buf.writeInt(42);
    buf.writerIndex(8);
    inputPlus.append(buf);
    buf = channel.alloc().buffer(8);
    buf.writeInt(42);
    buf.writerIndex(8);
    inputPlus.append(buf);
    Assert.assertEquals(16, inputPlus.unsafeAvailable());
// ByteBuffer out = ByteBuffer.allocate(4);
// int readCount = inputPlus.read(out);
// Assert.assertEquals(4, readCount);
// out.flip();
// Assert.assertEquals(42, out.getInt());
// Assert.assertEquals(12, inputPlus.unsafeAvailable());
// out = ByteBuffer.allocate(8);
// readCount = inputPlus.read(out);
// Assert.assertEquals(8, readCount);
// out.flip();
// Assert.assertEquals(42, out.getLong());
// Assert.assertEquals(4, inputPlus.unsafeAvailable());
}
Also used : AsyncStreamingInputPlus(org.apache.cassandra.net.AsyncStreamingInputPlus) ByteBuf(io.netty.buffer.ByteBuf) Test(org.junit.Test)

Example 7 with AsyncStreamingInputPlus

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

the class AsyncStreamingInputPlusTest method append_normal.

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

Example 8 with AsyncStreamingInputPlus

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

the class AsyncStreamingInputPlusTest method available_ClosedButWithBytes.

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

Example 9 with AsyncStreamingInputPlus

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

the class ZeroCopyStreamingBenchmark method partialStreamReader.

@Benchmark
@BenchmarkMode(Mode.Throughput)
public void partialStreamReader(BenchmarkState state) throws Throwable {
    EmbeddedChannel channel = createMockNettyChannel();
    AsyncStreamingInputPlus in = new AsyncStreamingInputPlus(channel);
    in.append(state.serializedPartialStream.retainedDuplicate());
    SSTableMultiWriter sstableWriter = state.partialStreamReader.read(in);
    Collection<SSTableReader> newSstables = sstableWriter.finished();
    in.close();
    channel.finishAndReleaseAll();
}
Also used : AsyncStreamingInputPlus(org.apache.cassandra.net.AsyncStreamingInputPlus) SSTableReader(org.apache.cassandra.io.sstable.format.SSTableReader) EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) SSTableMultiWriter(org.apache.cassandra.io.sstable.SSTableMultiWriter) BenchmarkMode(org.openjdk.jmh.annotations.BenchmarkMode) Benchmark(org.openjdk.jmh.annotations.Benchmark)

Example 10 with AsyncStreamingInputPlus

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

the class ZeroCopyStreamingBenchmark method blockStreamReader.

@Benchmark
@BenchmarkMode(Mode.Throughput)
public void blockStreamReader(BenchmarkState state) throws Throwable {
    EmbeddedChannel channel = createMockNettyChannel();
    AsyncStreamingInputPlus in = new AsyncStreamingInputPlus(channel);
    in.append(state.serializedBlockStream.retainedDuplicate());
    SSTableMultiWriter sstableWriter = state.blockStreamReader.read(in);
    Collection<SSTableReader> newSstables = sstableWriter.finished();
    in.close();
    channel.finishAndReleaseAll();
}
Also used : AsyncStreamingInputPlus(org.apache.cassandra.net.AsyncStreamingInputPlus) SSTableReader(org.apache.cassandra.io.sstable.format.SSTableReader) EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) SSTableMultiWriter(org.apache.cassandra.io.sstable.SSTableMultiWriter) BenchmarkMode(org.openjdk.jmh.annotations.BenchmarkMode) Benchmark(org.openjdk.jmh.annotations.Benchmark)

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