Search in sources :

Example 1 with PravegaNodeUri

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

the class RawClientTest method testHello.

@Test
public void testHello() throws ConnectionFailedException {
    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);
    RawClient rawClient = new RawClient(controller, connectionFactory, new Segment("scope", "testHello", 0));
    rawClient.sendRequest(1, new WireCommands.Hello(0, 0));
    Mockito.verify(connection).send(new WireCommands.Hello(0, 0));
    rawClient.close();
    Mockito.verify(connection).close();
}
Also used : PravegaNodeUri(io.pravega.shared.protocol.netty.PravegaNodeUri) MockConnectionFactoryImpl(io.pravega.client.stream.mock.MockConnectionFactoryImpl) MockController(io.pravega.client.stream.mock.MockController) WireCommands(io.pravega.shared.protocol.netty.WireCommands) Cleanup(lombok.Cleanup) Segment(io.pravega.client.segment.impl.Segment) Test(org.junit.Test)

Example 2 with PravegaNodeUri

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

the class SegmentOutputStreamTest method testFailDurringFlush.

@Test(timeout = 10000)
public void testFailDurringFlush() throws ConnectionFailedException {
    UUID cid = UUID.randomUUID();
    PravegaNodeUri uri = new PravegaNodeUri("endpoint", SERVICE_PORT);
    MockConnectionFactoryImpl cf = new MockConnectionFactoryImpl();
    ScheduledExecutorService executor = mock(ScheduledExecutorService.class);
    // Ensure task submitted to executor is run inline.
    implementAsDirectExecutor(executor);
    cf.setExecutor(executor);
    MockController controller = new MockController(uri.getEndpoint(), uri.getPort(), cf);
    ClientConnection connection = mock(ClientConnection.class);
    cf.provideConnection(uri, connection);
    InOrder order = Mockito.inOrder(connection);
    SegmentOutputStreamImpl output = new SegmentOutputStreamImpl(SEGMENT, controller, cf, cid, segmentSealedCallback, RETRY_SCHEDULE, "");
    output.reconnect();
    order.verify(connection).send(new SetupAppend(1, cid, SEGMENT, ""));
    cf.getProcessor(uri).appendSetup(new AppendSetup(1, SEGMENT, cid, 0));
    ByteBuffer data = getBuffer("test");
    CompletableFuture<Boolean> ack = new CompletableFuture<>();
    output.write(new PendingEvent(null, data, ack));
    order.verify(connection).send(new Append(SEGMENT, cid, 1, Unpooled.wrappedBuffer(data), null));
    assertEquals(false, ack.isDone());
    Mockito.doThrow(new ConnectionFailedException()).when(connection).send(new WireCommands.KeepAlive());
    Mockito.doAnswer(new Answer<Void>() {

        @Override
        public Void answer(InvocationOnMock invocation) throws Throwable {
            cf.getProcessor(uri).appendSetup(new AppendSetup(3, SEGMENT, cid, 1));
            return null;
        }
    }).when(connection).send(new SetupAppend(3, cid, SEGMENT, ""));
    Async.testBlocking(() -> {
        output.flush();
    }, () -> {
        cf.getProcessor(uri).connectionDropped();
    });
    order.verify(connection).send(new SetupAppend(3, cid, SEGMENT, ""));
    assertEquals(true, ack.isDone());
}
Also used : ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) InOrder(org.mockito.InOrder) ByteBuffer(java.nio.ByteBuffer) AppendSetup(io.pravega.shared.protocol.netty.WireCommands.AppendSetup) CompletableFuture(java.util.concurrent.CompletableFuture) Append(io.pravega.shared.protocol.netty.Append) SetupAppend(io.pravega.shared.protocol.netty.WireCommands.SetupAppend) PravegaNodeUri(io.pravega.shared.protocol.netty.PravegaNodeUri) PendingEvent(io.pravega.client.stream.impl.PendingEvent) InvocationOnMock(org.mockito.invocation.InvocationOnMock) MockConnectionFactoryImpl(io.pravega.client.stream.mock.MockConnectionFactoryImpl) SetupAppend(io.pravega.shared.protocol.netty.WireCommands.SetupAppend) MockController(io.pravega.client.stream.mock.MockController) ClientConnection(io.pravega.client.netty.impl.ClientConnection) UUID(java.util.UUID) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) WireCommands(io.pravega.shared.protocol.netty.WireCommands) ConnectionFailedException(io.pravega.shared.protocol.netty.ConnectionFailedException) Test(org.junit.Test)

Example 3 with PravegaNodeUri

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

the class ControllerImplLBTest method testDiscoverySuccessUsingIPAddress.

@Test
public void testDiscoverySuccessUsingIPAddress() throws Exception {
    final int serverPort1 = testRPCServer1.getPort();
    final int serverPort2 = testRPCServer2.getPort();
    // Use 2 servers to discover all the servers.
    String localIP = InetAddress.getLoopbackAddress().getHostAddress();
    @Cleanup("shutdown") InlineExecutor executor = new InlineExecutor();
    final ControllerImpl controllerClient = new ControllerImpl(ControllerImplConfig.builder().clientConfig(ClientConfig.builder().controllerURI(URI.create("pravega://" + localIP + ":" + serverPort1 + "," + localIP + ":" + serverPort2)).build()).retryAttempts(1).build(), executor);
    final Set<PravegaNodeUri> uris = fetchFromServers(controllerClient, 3);
    // Verify we could reach all 3 controllers.
    Assert.assertEquals(3, uris.size());
}
Also used : PravegaNodeUri(io.pravega.shared.protocol.netty.PravegaNodeUri) InlineExecutor(io.pravega.test.common.InlineExecutor) Cleanup(lombok.Cleanup) Test(org.junit.Test)

Example 4 with PravegaNodeUri

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

the class ControllerImplLBTest method testDirectSuccessUsingIPAddress.

@Test
public void testDirectSuccessUsingIPAddress() throws Exception {
    final int serverPort1 = testRPCServer1.getPort();
    final int serverPort2 = testRPCServer2.getPort();
    final int serverPort3 = testRPCServer3.getPort();
    // Directly use all 3 servers and verify.
    String localIP = InetAddress.getLoopbackAddress().getHostAddress();
    @Cleanup("shutdown") InlineExecutor executor = new InlineExecutor();
    final ControllerImpl controllerClient = new ControllerImpl(ControllerImplConfig.builder().clientConfig(ClientConfig.builder().controllerURI(URI.create("tcp://" + localIP + ":" + serverPort1 + "," + localIP + ":" + serverPort2 + "," + localIP + ":" + serverPort3)).build()).retryAttempts(1).build(), executor);
    final Set<PravegaNodeUri> uris = fetchFromServers(controllerClient, 3);
    Assert.assertEquals(3, uris.size());
}
Also used : PravegaNodeUri(io.pravega.shared.protocol.netty.PravegaNodeUri) InlineExecutor(io.pravega.test.common.InlineExecutor) Cleanup(lombok.Cleanup) Test(org.junit.Test)

Example 5 with PravegaNodeUri

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

the class ControllerImplLBTest method testDiscoverySuccess.

@Test
public void testDiscoverySuccess() throws Exception {
    final int serverPort1 = testRPCServer1.getPort();
    final int serverPort2 = testRPCServer2.getPort();
    // Use 2 servers to discover all the servers.
    @Cleanup("shutdown") InlineExecutor executor = new InlineExecutor();
    final ControllerImpl controllerClient = new ControllerImpl(ControllerImplConfig.builder().clientConfig(ClientConfig.builder().controllerURI(URI.create("pravega://localhost:" + serverPort1 + ",localhost:" + serverPort2)).build()).retryAttempts(1).build(), executor);
    final Set<PravegaNodeUri> uris = fetchFromServers(controllerClient, 3);
    // Verify we could reach all 3 controllers.
    Assert.assertEquals(3, uris.size());
}
Also used : PravegaNodeUri(io.pravega.shared.protocol.netty.PravegaNodeUri) InlineExecutor(io.pravega.test.common.InlineExecutor) Cleanup(lombok.Cleanup) 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