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);
}
}
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;
}
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());
}
Aggregations