use of org.apache.flink.shaded.netty4.io.netty.channel.embedded.EmbeddedChannel in project cassandra by apache.
the class EntireSSTableStreamConcurrentComponentMutationTest method createMockNettyChannel.
private EmbeddedChannel createMockNettyChannel(ByteBuf serializedFile) {
WritableByteChannel wbc = new WritableByteChannel() {
private boolean isOpen = true;
public int write(ByteBuffer src) {
int size = src.limit();
serializedFile.writeBytes(src);
return size;
}
public boolean isOpen() {
return isOpen;
}
public void close() {
isOpen = false;
}
};
return new EmbeddedChannel(new ChannelOutboundHandlerAdapter() {
@Override
public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception {
if (msg instanceof BufferPoolAllocator.Wrapped) {
ByteBuffer buf = ((BufferPoolAllocator.Wrapped) msg).adopt();
wbc.write(buf);
} else {
((SharedDefaultFileRegion) msg).transferTo(wbc, 0);
}
super.write(ctx, msg, promise);
}
});
}
use of org.apache.flink.shaded.netty4.io.netty.channel.embedded.EmbeddedChannel in project cassandra by apache.
the class CassandraEntireSSTableStreamWriterTest method testBlockWriterOverWire.
@Test
public void testBlockWriterOverWire() throws IOException {
StreamSession session = setupStreamingSessionForTest();
EmbeddedChannel channel = new EmbeddedChannel();
try (AsyncStreamingOutputPlus out = new AsyncStreamingOutputPlus(channel);
ComponentContext context = ComponentContext.create(descriptor)) {
CassandraEntireSSTableStreamWriter writer = new CassandraEntireSSTableStreamWriter(sstable, session, context);
writer.write(out);
Queue msgs = channel.outboundMessages();
assertTrue(msgs.peek() instanceof DefaultFileRegion);
}
}
use of org.apache.flink.shaded.netty4.io.netty.channel.embedded.EmbeddedChannel in project cassandra by apache.
the class CassandraEntireSSTableStreamWriterTest method testBlockReadingAndWritingOverWire.
@Test
public void testBlockReadingAndWritingOverWire() throws Throwable {
StreamSession session = setupStreamingSessionForTest();
InetAddressAndPort peer = FBUtilities.getBroadcastAddressAndPort();
// This is needed as Netty releases the ByteBuffers as soon as the channel is flushed
ByteBuf serializedFile = Unpooled.buffer(8192);
EmbeddedChannel channel = createMockNettyChannel(serializedFile);
try (AsyncStreamingOutputPlus out = new AsyncStreamingOutputPlus(channel);
ComponentContext context = ComponentContext.create(descriptor)) {
CassandraEntireSSTableStreamWriter writer = new CassandraEntireSSTableStreamWriter(sstable, session, context);
writer.write(out);
session.prepareReceiving(new StreamSummary(sstable.metadata().id, 1, 5104));
CassandraStreamHeader header = CassandraStreamHeader.builder().withSSTableFormat(sstable.descriptor.formatType).withSSTableVersion(sstable.descriptor.version).withSSTableLevel(0).withEstimatedKeys(sstable.estimatedKeys()).withSections(Collections.emptyList()).withSerializationHeader(sstable.header.toComponent()).withComponentManifest(context.manifest()).isEntireSSTable(true).withFirstKey(sstable.first).withTableId(sstable.metadata().id).build();
CassandraEntireSSTableStreamReader reader = new CassandraEntireSSTableStreamReader(new StreamMessageHeader(sstable.metadata().id, peer, session.planId(), false, 0, 0, 0, null), header, session);
SSTableMultiWriter sstableWriter = reader.read(new DataInputBuffer(serializedFile.nioBuffer(), false));
Collection<SSTableReader> newSstables = sstableWriter.finished();
assertEquals(1, newSstables.size());
}
}
use of org.apache.flink.shaded.netty4.io.netty.channel.embedded.EmbeddedChannel 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();
}
}
use of org.apache.flink.shaded.netty4.io.netty.channel.embedded.EmbeddedChannel in project cassandra by apache.
the class AsyncStreamingOutputPlusTest method testWriteFileToChannel.
private void testWriteFileToChannel(boolean zeroCopy) throws IOException {
File file = populateTempData("zero_copy_" + zeroCopy);
int length = (int) file.length();
EmbeddedChannel channel = new TestChannel(4);
StreamManager.StreamRateLimiter limiter = zeroCopy ? StreamManager.getEntireSSTableRateLimiter(FBUtilities.getBroadcastAddressAndPort()) : StreamManager.getRateLimiter(FBUtilities.getBroadcastAddressAndPort());
try (FileChannel fileChannel = file.newReadChannel();
AsyncStreamingOutputPlus out = new AsyncStreamingOutputPlus(channel)) {
assertTrue(fileChannel.isOpen());
if (zeroCopy)
out.writeFileToChannelZeroCopy(fileChannel, limiter, length, length, length * 2);
else
out.writeFileToChannel(fileChannel, limiter, length);
assertEquals(length, out.flushed());
assertEquals(length, out.flushedToNetwork());
assertEquals(length, out.position());
assertFalse(fileChannel.isOpen());
}
}
Aggregations