Search in sources :

Example 1 with WireCommand

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

the class ClientConnectionTest method testConnectionSetup.

@Test(timeout = 10000)
public void testConnectionSetup() throws Exception {
    ReplyProcessor processor = new ReplyProcessor();
    @Cleanup MockServer server = new MockServer();
    server.start();
    @Cleanup InlineExecutor executor = new InlineExecutor();
    @Cleanup ClientConnection clientConnection = TcpClientConnection.connect(server.getUri(), ClientConfig.builder().build(), processor, executor, null).join();
    clientConnection.send(new WireCommands.Hello(0, 1));
    LinkedBlockingQueue<WireCommand> messages = server.getReadCommands();
    WireCommand wireCommand = messages.take();
    assertEquals(WireCommandType.HELLO, wireCommand.getType());
    assertNull(messages.poll());
    clientConnection.send(new WireCommands.SetupAppend(1, new UUID(1, 2), "segment", ""));
    wireCommand = messages.take();
    assertEquals(WireCommandType.SETUP_APPEND, wireCommand.getType());
    assertNull(messages.poll());
    clientConnection.send(new Append("segment", new UUID(1, 2), 1, new Event(Unpooled.EMPTY_BUFFER), 2));
    wireCommand = messages.take();
    assertEquals(WireCommandType.APPEND_BLOCK, wireCommand.getType());
    assertFalse(processor.failure.get());
}
Also used : WireCommand(io.pravega.shared.protocol.netty.WireCommand) Cleanup(lombok.Cleanup) Append(io.pravega.shared.protocol.netty.Append) InlineExecutor(io.pravega.test.common.InlineExecutor) Event(io.pravega.shared.protocol.netty.WireCommands.Event) WireCommands(io.pravega.shared.protocol.netty.WireCommands) UUID(java.util.UUID) FailingReplyProcessor(io.pravega.shared.protocol.netty.FailingReplyProcessor) Test(org.junit.Test)

Example 2 with WireCommand

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

the class CommandEncoderTest method testAppendSizeQueuedBreak.

@Test
public void testAppendSizeQueuedBreak() 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);
    WireCommands.Event largeEvent = new WireCommands.Event(Unpooled.wrappedBuffer(new byte[CommandEncoder.MAX_QUEUED_SIZE]));
    Append appendOther2 = new Append("seg", writerId2, 102, largeEvent, 0);
    commandEncoder.write(appendOther1);
    commandEncoder.write(appendOther2);
    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(CommandEncoder.MAX_QUEUED_SIZE + 48 + 8, block.getData().readableBytes());
    blockEnd = (AppendBlockEnd) output.decoded.remove(0);
    assertEquals(writerId2, blockEnd.getWriterId());
    assertEquals(CommandEncoder.MAX_QUEUED_SIZE + 48 + 8, blockEnd.getSizeOfWholeEvents());
    assertEquals(0, blockEnd.getData().readableBytes());
    assertEquals(2, 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 3 with WireCommand

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

the class CommandEncoderTest method testRoundTrip.

@Test
public void testRoundTrip() throws IOException {
    AppendBatchSizeTrackerImpl batchSizeTracker = new AppendBatchSizeTrackerImpl();
    DecodingOutputStream output = new DecodingOutputStream();
    PravegaNodeUri endpoint = new PravegaNodeUri("localhost", SERVICE_PORT);
    CommandEncoder commandEncoder = new CommandEncoder(x -> batchSizeTracker, null, output, null, endpoint);
    WireCommand command = new WireCommands.Hello(0, 1);
    commandEncoder.write(command);
    assertEquals(output.decoded.remove(0), command);
    command = new WireCommands.CreateTableSegment(0, "segment", false, 16, "", 1024 * 1024 * 1024);
    commandEncoder.write(command);
    assertEquals(output.decoded.remove(0), command);
    command = new WireCommands.TruncateSegment(12, "s", 354, "d");
    commandEncoder.write(command);
    assertEquals(output.decoded.remove(0), command);
}
Also used : WireCommand(io.pravega.shared.protocol.netty.WireCommand) PravegaNodeUri(io.pravega.shared.protocol.netty.PravegaNodeUri) WireCommands(io.pravega.shared.protocol.netty.WireCommands) Test(org.junit.Test)

Example 4 with WireCommand

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

the class CommandEncoderTest method testAppendsAreBatched.

@Test
public void testAppendsAreBatched() 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 writerId = UUID.randomUUID();
    WireCommand setupAppend = new WireCommands.SetupAppend(0, writerId, "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", writerId, 1, event, 0);
    Append append2 = new Append("seg", writerId, 2, event, 0);
    Append append3 = new Append("seg", writerId, 3, event, 0);
    commandEncoder.write(append1);
    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(writerId, blockEnd.getWriterId());
    assertEquals(80 + 16, blockEnd.getSizeOfWholeEvents());
    assertEquals(40 + 4, 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)

Example 5 with WireCommand

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

the class CommandEncoderTest method testBatchInterupted.

@Test
public void testBatchInterupted() 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 writerId = UUID.randomUUID();
    WireCommand setupAppend = new WireCommands.SetupAppend(0, writerId, "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", writerId, 1, event, 0);
    commandEncoder.write(append1);
    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(writerId, blockEnd.getWriterId());
    assertEquals(48, blockEnd.getSizeOfWholeEvents());
    assertEquals(0, blockEnd.getData().readableBytes());
    assertEquals(1, blockEnd.getNumEvents());
    WireCommands.KeepAlive breakingCommand = (WireCommands.KeepAlive) output.decoded.remove(0);
    assertNotNull(breakingCommand);
}
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

WireCommand (io.pravega.shared.protocol.netty.WireCommand)23 Test (org.junit.Test)18 WireCommands (io.pravega.shared.protocol.netty.WireCommands)17 ByteBuf (io.netty.buffer.ByteBuf)15 UUID (java.util.UUID)15 PravegaNodeUri (io.pravega.shared.protocol.netty.PravegaNodeUri)13 Append (io.pravega.shared.protocol.netty.Append)12 Event (io.pravega.shared.protocol.netty.WireCommands.Event)10 Cleanup (lombok.Cleanup)9 AppendBatchSizeTracker (io.pravega.shared.protocol.netty.AppendBatchSizeTracker)8 AppendBlock (io.pravega.shared.protocol.netty.WireCommands.AppendBlock)8 AppendBlockEnd (io.pravega.shared.protocol.netty.WireCommands.AppendBlockEnd)8 lombok.val (lombok.val)7 StreamSegmentStore (io.pravega.segmentstore.contracts.StreamSegmentStore)6 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)6 TableStore (io.pravega.segmentstore.contracts.tables.TableStore)5 PassingTokenVerifier (io.pravega.segmentstore.server.host.delegationtoken.PassingTokenVerifier)5 SynchronousStreamSegmentStore (io.pravega.segmentstore.server.mocks.SynchronousStreamSegmentStore)5 ServiceBuilder (io.pravega.segmentstore.server.store.ServiceBuilder)5 CompletableFuture (java.util.concurrent.CompletableFuture)5