Search in sources :

Example 56 with PravegaNodeUri

use of io.pravega.shared.protocol.netty.PravegaNodeUri 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 57 with PravegaNodeUri

use of io.pravega.shared.protocol.netty.PravegaNodeUri 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 58 with PravegaNodeUri

use of io.pravega.shared.protocol.netty.PravegaNodeUri 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)

Example 59 with PravegaNodeUri

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

the class CommandEncoderTest method testExactBatch.

@Test
public void testExactBatch() 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[100]);
    Event event = new WireCommands.Event(data);
    Append append = new Append("seg", writerId, 1, event, 0);
    commandEncoder.write(append);
    AppendBlock block = (AppendBlock) output.decoded.remove(0);
    assertEquals(108, block.getData().readableBytes());
    AppendBlockEnd blockEnd = (AppendBlockEnd) output.decoded.remove(0);
    assertEquals(writerId, blockEnd.getWriterId());
    assertEquals(108, 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) Test(org.junit.Test)

Example 60 with PravegaNodeUri

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

the class CommandEncoderTest method testOverBatchSize.

@Test
public void testOverBatchSize() 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[200]);
    Event event = new WireCommands.Event(data);
    Append append = new Append("seg", writerId, 1, event, 0);
    commandEncoder.write(append);
    AppendBlock block = (AppendBlock) output.decoded.remove(0);
    assertEquals(208, block.getData().readableBytes());
    AppendBlockEnd blockEnd = (AppendBlockEnd) output.decoded.remove(0);
    assertEquals(writerId, blockEnd.getWriterId());
    assertEquals(208, 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) Test(org.junit.Test)

Aggregations

PravegaNodeUri (io.pravega.shared.protocol.netty.PravegaNodeUri)185 Test (org.junit.Test)154 Cleanup (lombok.Cleanup)124 MockController (io.pravega.client.stream.mock.MockController)122 MockConnectionFactoryImpl (io.pravega.client.stream.mock.MockConnectionFactoryImpl)119 ClientConnection (io.pravega.client.connection.impl.ClientConnection)81 WireCommands (io.pravega.shared.protocol.netty.WireCommands)70 UUID (java.util.UUID)57 Segment (io.pravega.client.segment.impl.Segment)49 CompletableFuture (java.util.concurrent.CompletableFuture)44 InvocationOnMock (org.mockito.invocation.InvocationOnMock)44 ReplyProcessor (io.pravega.shared.protocol.netty.ReplyProcessor)40 ConnectionFailedException (io.pravega.shared.protocol.netty.ConnectionFailedException)35 AppendSetup (io.pravega.shared.protocol.netty.WireCommands.AppendSetup)35 SetupAppend (io.pravega.shared.protocol.netty.WireCommands.SetupAppend)35 ByteBuffer (java.nio.ByteBuffer)34 Append (io.pravega.shared.protocol.netty.Append)33 AtomicLong (java.util.concurrent.atomic.AtomicLong)31 MockSegmentStreamFactory (io.pravega.client.stream.mock.MockSegmentStreamFactory)30 InOrder (org.mockito.InOrder)28