Search in sources :

Example 66 with PravegaNodeUri

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

the class ConditionalOutputStreamTest method testNonExpiryTokenCheckFailure.

@Test(timeout = 10000)
public void testNonExpiryTokenCheckFailure() throws ConnectionFailedException {
    @Cleanup MockConnectionFactoryImpl connectionFactory = new MockConnectionFactoryImpl();
    @Cleanup MockController controller = new MockController("localhost", 0, connectionFactory, true);
    ConditionalOutputStreamFactory factory = new ConditionalOutputStreamFactoryImpl(controller, connectionFactory);
    Segment segment = new Segment("scope", "testWrite", 1);
    @Cleanup ConditionalOutputStream objectUnderTest = factory.createConditionalOutputStream(segment, DelegationTokenProviderFactory.create("token", controller, segment, AccessOperation.ANY), EventWriterConfig.builder().build());
    ByteBuffer data = ByteBuffer.allocate(10);
    ClientConnection clientConnection = Mockito.mock(ClientConnection.class);
    PravegaNodeUri location = new PravegaNodeUri("localhost", 0);
    connectionFactory.provideConnection(location, clientConnection);
    setupAppend(connectionFactory, segment, clientConnection, location);
    Mockito.doAnswer(new Answer<Void>() {

        @Override
        public Void answer(InvocationOnMock invocation) throws Throwable {
            ConditionalAppend argument = (ConditionalAppend) invocation.getArgument(0);
            ReplyProcessor processor = connectionFactory.getProcessor(location);
            processor.process(new WireCommands.AuthTokenCheckFailed(argument.getRequestId(), "SomeException", WireCommands.AuthTokenCheckFailed.ErrorCode.TOKEN_CHECK_FAILED));
            return null;
        }
    }).when(clientConnection).send(any(ConditionalAppend.class));
    AssertExtensions.assertThrows(AuthenticationException.class, () -> objectUnderTest.write(data, 0));
}
Also used : ConditionalAppend(io.pravega.shared.protocol.netty.WireCommands.ConditionalAppend) Cleanup(lombok.Cleanup) ByteBuffer(java.nio.ByteBuffer) PravegaNodeUri(io.pravega.shared.protocol.netty.PravegaNodeUri) InvocationOnMock(org.mockito.invocation.InvocationOnMock) MockConnectionFactoryImpl(io.pravega.client.stream.mock.MockConnectionFactoryImpl) MockController(io.pravega.client.stream.mock.MockController) ClientConnection(io.pravega.client.connection.impl.ClientConnection) ReplyProcessor(io.pravega.shared.protocol.netty.ReplyProcessor) Test(org.junit.Test)

Example 67 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, true);
    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(Mockito.eq(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 68 with PravegaNodeUri

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

the class RawClientTest method testOverloadConstructor.

@Test
public void testOverloadConstructor() throws ConnectionFailedException {
    PravegaNodeUri endpoint = new PravegaNodeUri("localhost", -1);
    @Cleanup MockConnectionFactoryImpl connectionFactory = new MockConnectionFactoryImpl();
    ClientConnection connection = Mockito.mock(ClientConnection.class);
    connectionFactory.provideConnection(endpoint, connection);
    RawClient rawClient = new RawClient(endpoint, connectionFactory);
    rawClient.sendRequest(1, new WireCommands.Hello(0, 0));
    Mockito.verify(connection).send(Mockito.eq(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) WireCommands(io.pravega.shared.protocol.netty.WireCommands) Cleanup(lombok.Cleanup) Test(org.junit.Test)

Example 69 with PravegaNodeUri

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

the class RawClientTest method testReplyWithoutRequest.

@Test
public void testReplyWithoutRequest() {
    PravegaNodeUri endpoint = new PravegaNodeUri("localhost", -1);
    @Cleanup MockConnectionFactoryImpl connectionFactory = new MockConnectionFactoryImpl();
    @Cleanup MockController controller = new MockController(endpoint.getEndpoint(), endpoint.getPort(), connectionFactory, true);
    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();
    ReplyProcessor processor = connectionFactory.getProcessor(endpoint);
    DataAppended reply = new DataAppended(requestId, id, 1, 0, -1);
    processor.process(reply);
    assertFalse(rawClient.isClosed());
}
Also used : 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) UUID(java.util.UUID) Cleanup(lombok.Cleanup) Segment(io.pravega.client.segment.impl.Segment) ReplyProcessor(io.pravega.shared.protocol.netty.ReplyProcessor) Test(org.junit.Test)

Example 70 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)

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