Search in sources :

Example 6 with Append

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();
}
Also used : Append(io.pravega.shared.protocol.netty.Append) PravegaNodeUri(io.pravega.shared.protocol.netty.PravegaNodeUri) InlineExecutor(io.pravega.test.common.InlineExecutor) ClientConfig(io.pravega.client.ClientConfig) FailingReplyProcessor(io.pravega.shared.protocol.netty.FailingReplyProcessor) ReplyProcessor(io.pravega.shared.protocol.netty.ReplyProcessor) Before(org.junit.Before)

Example 7 with Append

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());
}
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 8 with Append

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());
}
Also used : Cleanup(lombok.Cleanup) Append(io.pravega.shared.protocol.netty.Append) InlineExecutor(io.pravega.test.common.InlineExecutor) Event(io.pravega.shared.protocol.netty.WireCommands.Event) UUID(java.util.UUID) WireCommands(io.pravega.shared.protocol.netty.WireCommands) FailingReplyProcessor(io.pravega.shared.protocol.netty.FailingReplyProcessor) Test(org.junit.Test)

Example 9 with Append

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)));
}
Also used : Append(io.pravega.shared.protocol.netty.Append) InlineExecutor(io.pravega.test.common.InlineExecutor) Event(io.pravega.shared.protocol.netty.WireCommands.Event) UUID(java.util.UUID) WireCommands(io.pravega.shared.protocol.netty.WireCommands) Cleanup(lombok.Cleanup) FailingReplyProcessor(io.pravega.shared.protocol.netty.FailingReplyProcessor) Test(org.junit.Test)

Example 10 with Append

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());
}
Also used : ArrayList(java.util.ArrayList) Cleanup(lombok.Cleanup) ConnectionFailedException(io.pravega.shared.protocol.netty.ConnectionFailedException) CompletableFuture(java.util.concurrent.CompletableFuture) Append(io.pravega.shared.protocol.netty.Append) InlineExecutor(io.pravega.test.common.InlineExecutor) Event(io.pravega.shared.protocol.netty.WireCommands.Event) UUID(java.util.UUID) WireCommands(io.pravega.shared.protocol.netty.WireCommands) FailingReplyProcessor(io.pravega.shared.protocol.netty.FailingReplyProcessor) Test(org.junit.Test)

Aggregations

Append (io.pravega.shared.protocol.netty.Append)74 UUID (java.util.UUID)67 Test (org.junit.Test)64 SetupAppend (io.pravega.shared.protocol.netty.WireCommands.SetupAppend)52 AppendSetup (io.pravega.shared.protocol.netty.WireCommands.AppendSetup)44 WireCommands (io.pravega.shared.protocol.netty.WireCommands)37 Cleanup (lombok.Cleanup)37 CompletableFuture (java.util.concurrent.CompletableFuture)33 PravegaNodeUri (io.pravega.shared.protocol.netty.PravegaNodeUri)31 StreamSegmentStore (io.pravega.segmentstore.contracts.StreamSegmentStore)27 InOrder (org.mockito.InOrder)22 ClientConnection (io.pravega.client.connection.impl.ClientConnection)21 MockConnectionFactoryImpl (io.pravega.client.stream.mock.MockConnectionFactoryImpl)21 MockController (io.pravega.client.stream.mock.MockController)21 Event (io.pravega.shared.protocol.netty.WireCommands.Event)21 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)21 lombok.val (lombok.val)20 DataAppended (io.pravega.shared.protocol.netty.WireCommands.DataAppended)17 ByteBuffer (java.nio.ByteBuffer)17 ByteBuf (io.netty.buffer.ByteBuf)16