use of io.pravega.shared.protocol.netty.Append in project pravega by pravega.
the class FlowHandlerTest method setUp.
@Before
public void setUp() throws Exception {
flow = new Flow(10, 0);
loop = new InlineExecutor();
appendCmd = new Append("segment0", UUID.randomUUID(), 2, 1, buffer, 10L, flow.asLong());
when(connectionFactory.establishConnection(any(PravegaNodeUri.class), any(ReplyProcessor.class))).thenReturn(CompletableFuture.completedFuture(connection));
when(connectionFactory.getInternalExecutor()).thenReturn(loop);
ClientConfig clientConfig = ClientConfig.builder().build();
PravegaNodeUri pravegaNodeUri = new PravegaNodeUri("testConnection", 0);
flowHandler = FlowHandler.openConnection(pravegaNodeUri, new TestMetricNotifier(), connectionFactory).join();
}
use of io.pravega.shared.protocol.netty.Append 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());
}
use of io.pravega.shared.protocol.netty.Append in project pravega by pravega.
the class ClientConnectionTest method testAppend.
@Test
public void testAppend() throws Exception {
byte[] payload = new byte[100];
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();
UUID writerId = new UUID(1, 2);
clientConnection.send(new WireCommands.SetupAppend(1, writerId, "segment", ""));
for (int i = 0; i < 100; i++) {
clientConnection.send(new Append("segment", writerId, i, new Event(Unpooled.wrappedBuffer(payload)), 1));
server.sendReply(new WireCommands.DataAppended(i, writerId, i, i - 1, i * 100));
}
AssertExtensions.assertEventuallyEquals(100, () -> processor.replies.size(), 5000);
assertFalse(processor.failure.get());
}
use of io.pravega.shared.protocol.netty.Append in project pravega by pravega.
the class ClientConnectionTest method testFailedSendAppend.
@Test
public void testFailedSendAppend() throws Exception {
byte[] payload = new byte[100];
ReplyProcessor processor = new ReplyProcessor();
@Cleanup MockServer server = new MockServer();
server.start();
@Cleanup InlineExecutor executor = new InlineExecutor();
@Cleanup TcpClientConnection clientConnection = TcpClientConnection.connect(server.getUri(), ClientConfig.builder().build(), processor, executor, null).join();
UUID writerId = new UUID(1, 2);
clientConnection.send(new WireCommands.SetupAppend(1, writerId, "segment", ""));
server.getOutputStream().join().close();
AssertExtensions.assertThrows(ConnectionFailedException.class, () -> {
for (int i = 0; i < 100; i++) {
clientConnection.send(new Append("segment", writerId, i, new Event(Unpooled.wrappedBuffer(payload)), 1));
Thread.sleep(100);
}
});
assertTrue(clientConnection.toString(), clientConnection.isClosed());
AssertExtensions.assertThrows(ConnectionFailedException.class, () -> clientConnection.send(new Append("segment", writerId, 100, new Event(Unpooled.wrappedBuffer(payload)), 1)));
}
use of io.pravega.shared.protocol.netty.Append in project pravega by pravega.
the class ClientConnectionTest method testSendAsync.
@Test
public void testSendAsync() throws Exception {
byte[] payload = new byte[100];
byte[] payload2 = new byte[101];
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();
UUID writerId = new UUID(1, 2);
clientConnection.send(new WireCommands.SetupAppend(1, writerId, "segment", ""));
// clear setup.
server.getReadCommands().take();
ArrayList<Append> appends = new ArrayList<>();
appends.add(new Append("segment", writerId, 1, new Event(Unpooled.wrappedBuffer(payload)), 1));
appends.add(new Append("segment", writerId, 2, new Event(Unpooled.wrappedBuffer(payload2)), 1));
CompletableFuture<Exception> future = new CompletableFuture<Exception>();
clientConnection.sendAsync(appends, e -> future.complete(e));
assertNull(future.join());
assertEquals(AppendBlock.class, server.getReadCommands().take().getClass());
assertEquals(AppendBlockEnd.class, server.getReadCommands().take().getClass());
assertEquals(AppendBlock.class, server.getReadCommands().take().getClass());
assertEquals(AppendBlockEnd.class, server.getReadCommands().take().getClass());
assertTrue(server.getReadCommands().isEmpty());
assertFalse(processor.failure.get());
}
Aggregations