Search in sources :

Example 1 with Reply

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

the class ClientConnectionInboundHandler method channelRead.

@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) {
    Reply cmd = (Reply) msg;
    log.debug(connectionName + " processing reply: {}", cmd);
    if (cmd instanceof WireCommands.DataAppended) {
        batchSizeTracker.recordAck(((WireCommands.DataAppended) cmd).getEventNumber());
    }
    try {
        processor.process(cmd);
    } catch (Exception e) {
        processor.processingFailure(e);
    }
}
Also used : Reply(io.pravega.shared.protocol.netty.Reply) WireCommands(io.pravega.shared.protocol.netty.WireCommands) ConnectionFailedException(io.pravega.shared.protocol.netty.ConnectionFailedException)

Example 2 with Reply

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

the class AppendTest method sendRequest.

static Reply sendRequest(EmbeddedChannel channel, Request request) throws Exception {
    channel.writeInbound(request);
    Object encodedReply = channel.readOutbound();
    for (int i = 0; encodedReply == null && i < 50; i++) {
        channel.runPendingTasks();
        Thread.sleep(10);
        encodedReply = channel.readOutbound();
    }
    if (encodedReply == null) {
        throw new IllegalStateException("No reply to request: " + request);
    }
    WireCommand decoded = CommandDecoder.parseCommand((ByteBuf) encodedReply);
    ((ByteBuf) encodedReply).release();
    assertNotNull(decoded);
    return (Reply) decoded;
}
Also used : WireCommand(io.pravega.shared.protocol.netty.WireCommand) Reply(io.pravega.shared.protocol.netty.Reply) ByteBuf(io.netty.buffer.ByteBuf)

Example 3 with Reply

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

the class RawClientTest method testRequestReply.

@Test
public void testRequestReply() throws ConnectionFailedException, InterruptedException, ExecutionException {
    PravegaNodeUri endpoint = new PravegaNodeUri("localhost", -1);
    @Cleanup MockConnectionFactoryImpl connectionFactory = new MockConnectionFactoryImpl();
    @Cleanup MockController controller = new MockController(endpoint.getEndpoint(), endpoint.getPort(), connectionFactory);
    ClientConnection connection = Mockito.mock(ClientConnection.class);
    connectionFactory.provideConnection(endpoint, connection);
    @Cleanup RawClient rawClient = new RawClient(controller, connectionFactory, new Segment("scope", "testHello", 0));
    UUID id = UUID.randomUUID();
    ConditionalAppend request = new ConditionalAppend(id, 1, 0, Unpooled.EMPTY_BUFFER);
    CompletableFuture<Reply> future = rawClient.sendRequest(1, request);
    Mockito.verify(connection).send(request);
    assertFalse(future.isDone());
    ReplyProcessor processor = connectionFactory.getProcessor(endpoint);
    DataAppended reply = new DataAppended(id, 1, 0);
    processor.process(reply);
    assertTrue(future.isDone());
    assertEquals(reply, future.get());
}
Also used : ConditionalAppend(io.pravega.shared.protocol.netty.WireCommands.ConditionalAppend) Cleanup(lombok.Cleanup) Segment(io.pravega.client.segment.impl.Segment) PravegaNodeUri(io.pravega.shared.protocol.netty.PravegaNodeUri) DataAppended(io.pravega.shared.protocol.netty.WireCommands.DataAppended) MockConnectionFactoryImpl(io.pravega.client.stream.mock.MockConnectionFactoryImpl) MockController(io.pravega.client.stream.mock.MockController) Reply(io.pravega.shared.protocol.netty.Reply) UUID(java.util.UUID) ReplyProcessor(io.pravega.shared.protocol.netty.ReplyProcessor) Test(org.junit.Test)

Aggregations

Reply (io.pravega.shared.protocol.netty.Reply)3 ByteBuf (io.netty.buffer.ByteBuf)1 Segment (io.pravega.client.segment.impl.Segment)1 MockConnectionFactoryImpl (io.pravega.client.stream.mock.MockConnectionFactoryImpl)1 MockController (io.pravega.client.stream.mock.MockController)1 ConnectionFailedException (io.pravega.shared.protocol.netty.ConnectionFailedException)1 PravegaNodeUri (io.pravega.shared.protocol.netty.PravegaNodeUri)1 ReplyProcessor (io.pravega.shared.protocol.netty.ReplyProcessor)1 WireCommand (io.pravega.shared.protocol.netty.WireCommand)1 WireCommands (io.pravega.shared.protocol.netty.WireCommands)1 ConditionalAppend (io.pravega.shared.protocol.netty.WireCommands.ConditionalAppend)1 DataAppended (io.pravega.shared.protocol.netty.WireCommands.DataAppended)1 UUID (java.util.UUID)1 Cleanup (lombok.Cleanup)1 Test (org.junit.Test)1