Search in sources :

Example 11 with AppendBatchSizeTracker

use of io.pravega.shared.protocol.netty.AppendBatchSizeTracker in project pravega by pravega.

the class CommandEncoderTest method testAppendsQueued.

@Test
public void testAppendsQueued() throws IOException {
    AppendBatchSizeTracker batchSizeTracker = new FixedBatchSizeTracker(100);
    DecodingOutputStream output = new DecodingOutputStream();
    PravegaNodeUri endpoint = new PravegaNodeUri("localhost", SERVICE_PORT);
    CommandEncoder commandEncoder = new CommandEncoder(x -> batchSizeTracker, null, output, null, endpoint);
    UUID writerId1 = UUID.randomUUID();
    WireCommand setupAppend = new WireCommands.SetupAppend(0, writerId1, "seg", "");
    commandEncoder.write(setupAppend);
    assertEquals(output.decoded.remove(0), setupAppend);
    UUID writerId2 = UUID.randomUUID();
    setupAppend = new WireCommands.SetupAppend(0, writerId2, "seg", "");
    commandEncoder.write(setupAppend);
    assertEquals(output.decoded.remove(0), setupAppend);
    ByteBuf data = Unpooled.wrappedBuffer(new byte[40]);
    WireCommands.Event event = new WireCommands.Event(data);
    Append append1 = new Append("seg", writerId1, 1, event, 0);
    commandEncoder.write(append1);
    Append appendOther = new Append("seg", writerId2, 100, event, 0);
    commandEncoder.write(appendOther);
    Append append2 = new Append("seg", writerId1, 2, event, 0);
    Append append3 = new Append("seg", writerId1, 3, event, 0);
    commandEncoder.write(append2);
    commandEncoder.write(append3);
    AppendBlock block = (AppendBlock) output.decoded.remove(0);
    assertEquals(108, block.getData().readableBytes());
    AppendBlockEnd blockEnd = (AppendBlockEnd) output.decoded.remove(0);
    assertEquals(writerId1, blockEnd.getWriterId());
    assertEquals(80 + 16, blockEnd.getSizeOfWholeEvents());
    assertEquals(40 + 4, blockEnd.getData().readableBytes());
    assertEquals(3, blockEnd.getNumEvents());
    block = (AppendBlock) output.decoded.remove(0);
    assertEquals(48, block.getData().readableBytes());
    blockEnd = (AppendBlockEnd) output.decoded.remove(0);
    assertEquals(writerId2, blockEnd.getWriterId());
    assertEquals(48, blockEnd.getSizeOfWholeEvents());
    assertEquals(0, blockEnd.getData().readableBytes());
    assertEquals(1, blockEnd.getNumEvents());
}
Also used : WireCommand(io.pravega.shared.protocol.netty.WireCommand) AppendBatchSizeTracker(io.pravega.shared.protocol.netty.AppendBatchSizeTracker) ByteBuf(io.netty.buffer.ByteBuf) AppendBlock(io.pravega.shared.protocol.netty.WireCommands.AppendBlock) Append(io.pravega.shared.protocol.netty.Append) PravegaNodeUri(io.pravega.shared.protocol.netty.PravegaNodeUri) AppendBlockEnd(io.pravega.shared.protocol.netty.WireCommands.AppendBlockEnd) Event(io.pravega.shared.protocol.netty.WireCommands.Event) UUID(java.util.UUID) WireCommands(io.pravega.shared.protocol.netty.WireCommands) Event(io.pravega.shared.protocol.netty.WireCommands.Event) Test(org.junit.Test)

Example 12 with AppendBatchSizeTracker

use of io.pravega.shared.protocol.netty.AppendBatchSizeTracker in project pravega by pravega.

the class CommandEncoderTest method testAppendsQueuedBreak.

@Test
public void testAppendsQueuedBreak() throws IOException {
    AppendBatchSizeTracker batchSizeTracker = new FixedBatchSizeTracker(100);
    DecodingOutputStream output = new DecodingOutputStream();
    PravegaNodeUri endpoint = new PravegaNodeUri("localhost", SERVICE_PORT);
    CommandEncoder commandEncoder = new CommandEncoder(x -> batchSizeTracker, null, output, null, endpoint);
    UUID writerId1 = UUID.randomUUID();
    WireCommand setupAppend = new WireCommands.SetupAppend(0, writerId1, "seg", "");
    commandEncoder.write(setupAppend);
    assertEquals(output.decoded.remove(0), setupAppend);
    UUID writerId2 = UUID.randomUUID();
    setupAppend = new WireCommands.SetupAppend(0, writerId2, "seg", "");
    commandEncoder.write(setupAppend);
    assertEquals(output.decoded.remove(0), setupAppend);
    ByteBuf data = Unpooled.wrappedBuffer(new byte[40]);
    WireCommands.Event event = new WireCommands.Event(data);
    Append append1 = new Append("seg", writerId1, 1, event, 0);
    commandEncoder.write(append1);
    Append appendOther1 = new Append("seg", writerId2, 101, event, 0);
    Append appendOther2 = new Append("seg", writerId2, 102, event, 0);
    Append appendOther3 = new Append("seg", writerId2, 103, event, 0);
    commandEncoder.write(appendOther1);
    commandEncoder.write(appendOther2);
    commandEncoder.write(appendOther3);
    commandEncoder.write(new WireCommands.KeepAlive());
    AppendBlock block = (AppendBlock) output.decoded.remove(0);
    assertEquals(108, block.getData().readableBytes());
    AppendBlockEnd blockEnd = (AppendBlockEnd) output.decoded.remove(0);
    assertEquals(writerId1, blockEnd.getWriterId());
    assertEquals(48, blockEnd.getSizeOfWholeEvents());
    assertEquals(0, blockEnd.getData().readableBytes());
    assertEquals(1, blockEnd.getNumEvents());
    block = (AppendBlock) output.decoded.remove(0);
    assertEquals(48 * 3, block.getData().readableBytes());
    blockEnd = (AppendBlockEnd) output.decoded.remove(0);
    assertEquals(writerId2, blockEnd.getWriterId());
    assertEquals(48 * 3, blockEnd.getSizeOfWholeEvents());
    assertEquals(0, blockEnd.getData().readableBytes());
    assertEquals(3, blockEnd.getNumEvents());
}
Also used : WireCommand(io.pravega.shared.protocol.netty.WireCommand) AppendBatchSizeTracker(io.pravega.shared.protocol.netty.AppendBatchSizeTracker) ByteBuf(io.netty.buffer.ByteBuf) AppendBlock(io.pravega.shared.protocol.netty.WireCommands.AppendBlock) Append(io.pravega.shared.protocol.netty.Append) PravegaNodeUri(io.pravega.shared.protocol.netty.PravegaNodeUri) AppendBlockEnd(io.pravega.shared.protocol.netty.WireCommands.AppendBlockEnd) Event(io.pravega.shared.protocol.netty.WireCommands.Event) UUID(java.util.UUID) WireCommands(io.pravega.shared.protocol.netty.WireCommands) Event(io.pravega.shared.protocol.netty.WireCommands.Event) Test(org.junit.Test)

Aggregations

AppendBatchSizeTracker (io.pravega.shared.protocol.netty.AppendBatchSizeTracker)12 Test (org.junit.Test)10 ByteBuf (io.netty.buffer.ByteBuf)9 Append (io.pravega.shared.protocol.netty.Append)8 PravegaNodeUri (io.pravega.shared.protocol.netty.PravegaNodeUri)8 WireCommand (io.pravega.shared.protocol.netty.WireCommand)8 AppendBlock (io.pravega.shared.protocol.netty.WireCommands.AppendBlock)8 AppendBlockEnd (io.pravega.shared.protocol.netty.WireCommands.AppendBlockEnd)8 Event (io.pravega.shared.protocol.netty.WireCommands.Event)8 UUID (java.util.UUID)8 WireCommands (io.pravega.shared.protocol.netty.WireCommands)6 CompletableFuture (java.util.concurrent.CompletableFuture)2 Bootstrap (io.netty.bootstrap.Bootstrap)1 Channel (io.netty.channel.Channel)1 ChannelFuture (io.netty.channel.ChannelFuture)1 ChannelFutureListener (io.netty.channel.ChannelFutureListener)1 ChannelPipeline (io.netty.channel.ChannelPipeline)1 EpollSocketChannel (io.netty.channel.epoll.EpollSocketChannel)1 SocketChannel (io.netty.channel.socket.SocketChannel)1 NioSocketChannel (io.netty.channel.socket.nio.NioSocketChannel)1