Search in sources :

Example 61 with MockConnectionFactoryImpl

use of io.pravega.client.stream.mock.MockConnectionFactoryImpl 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());
}
Also used : ConditionalAppend(io.pravega.shared.protocol.netty.WireCommands.ConditionalAppend) Cleanup(lombok.Cleanup) Segment(io.pravega.client.segment.impl.Segment) 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) Reply(io.pravega.shared.protocol.netty.Reply) UUID(java.util.UUID) ReplyProcessor(io.pravega.shared.protocol.netty.ReplyProcessor) Test(org.junit.Test)

Example 62 with MockConnectionFactoryImpl

use of io.pravega.client.stream.mock.MockConnectionFactoryImpl in project pravega by pravega.

the class RawClientTest method testExceptionHandling.

@Test
public void testExceptionHandling() 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);
    Segment segment = new Segment("scope", "test", 0);
    RawClient rawClient = new RawClient(controller, connectionFactory, segment);
    WireCommands.ReadSegment request1 = new WireCommands.ReadSegment(segment.getScopedName(), 0, 10, "", requestId);
    CompletableFuture<Reply> future = rawClient.sendRequest(requestId, request1);
    // Verify if the request was sent over the connection.
    Mockito.verify(connection).send(Mockito.eq(request1));
    assertFalse("Since there is no response the future should not be completed", future.isDone());
    ReplyProcessor processor = connectionFactory.getProcessor(endpoint);
    processor.processingFailure(new ConnectionFailedException("Custom error"));
    assertTrue(future.isCompletedExceptionally());
    assertFutureThrows("The future should be completed exceptionally", future, t -> t instanceof ConnectionFailedException);
    rawClient.close();
    rawClient = new RawClient(controller, connectionFactory, segment);
    WireCommands.ReadSegment request2 = new WireCommands.ReadSegment(segment.getScopedName(), 0, 10, "", 2L);
    future = rawClient.sendRequest(2L, request2);
    // Verify if the request was sent over the connection.
    Mockito.verify(connection).send(Mockito.eq(request2));
    assertFalse("Since there is no response the future should not be completed", future.isDone());
    processor = connectionFactory.getProcessor(endpoint);
    processor.authTokenCheckFailed(new WireCommands.AuthTokenCheckFailed(2L, "", WireCommands.AuthTokenCheckFailed.ErrorCode.TOKEN_CHECK_FAILED));
    assertTrue(future.isCompletedExceptionally());
    assertFutureThrows("The future should be completed exceptionally", future, t -> t instanceof AuthenticationException);
    rawClient.close();
}
Also used : AuthenticationException(io.pravega.auth.AuthenticationException) Cleanup(lombok.Cleanup) Segment(io.pravega.client.segment.impl.Segment) PravegaNodeUri(io.pravega.shared.protocol.netty.PravegaNodeUri) MockConnectionFactoryImpl(io.pravega.client.stream.mock.MockConnectionFactoryImpl) MockController(io.pravega.client.stream.mock.MockController) Reply(io.pravega.shared.protocol.netty.Reply) WireCommands(io.pravega.shared.protocol.netty.WireCommands) ConnectionFailedException(io.pravega.shared.protocol.netty.ConnectionFailedException) ReplyProcessor(io.pravega.shared.protocol.netty.ReplyProcessor) Test(org.junit.Test)

Example 63 with MockConnectionFactoryImpl

use of io.pravega.client.stream.mock.MockConnectionFactoryImpl in project pravega by pravega.

the class RawClientTest method testRecvErrorMessage.

@Test
public void testRecvErrorMessage() {
    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);
    Segment segment = new Segment("scope", "testHello", 0);
    @Cleanup RawClient rawClient = new RawClient(controller, connectionFactory, segment);
    ReplyProcessor processor = connectionFactory.getProcessor(endpoint);
    WireCommands.ErrorMessage reply = new ErrorMessage(requestId, segment.getScopedName(), "error.", ErrorMessage.ErrorCode.ILLEGAL_ARGUMENT_EXCEPTION);
    processor.process(reply);
    Mockito.verify(connection).close();
}
Also used : ErrorMessage(io.pravega.shared.protocol.netty.WireCommands.ErrorMessage) 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) ErrorMessage(io.pravega.shared.protocol.netty.WireCommands.ErrorMessage) Cleanup(lombok.Cleanup) Segment(io.pravega.client.segment.impl.Segment) ReplyProcessor(io.pravega.shared.protocol.netty.ReplyProcessor) Test(org.junit.Test)

Example 64 with MockConnectionFactoryImpl

use of io.pravega.client.stream.mock.MockConnectionFactoryImpl in project pravega by pravega.

the class RawClientTest method testRequestReply.

@Test
public void testRequestReply() throws InterruptedException, ExecutionException, 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);
    @Cleanup RawClient rawClient = new RawClient(controller, connectionFactory, new Segment("scope", "testHello", 0));
    UUID id = UUID.randomUUID();
    ConditionalAppend request = new ConditionalAppend(id, 1, 0, new Event(Unpooled.EMPTY_BUFFER), requestId);
    CompletableFuture<Reply> future = rawClient.sendRequest(1, request);
    Mockito.verify(connection).send(Mockito.eq(request));
    assertFalse(future.isDone());
    ReplyProcessor processor = connectionFactory.getProcessor(endpoint);
    DataAppended reply = new DataAppended(requestId, id, 1, 0, -1);
    processor.process(reply);
    assertTrue(future.isDone());
    assertEquals(reply, future.get());
}
Also used : ConditionalAppend(io.pravega.shared.protocol.netty.WireCommands.ConditionalAppend) Cleanup(lombok.Cleanup) Segment(io.pravega.client.segment.impl.Segment) 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) Event(io.pravega.shared.protocol.netty.WireCommands.Event) Reply(io.pravega.shared.protocol.netty.Reply) UUID(java.util.UUID) ReplyProcessor(io.pravega.shared.protocol.netty.ReplyProcessor) Test(org.junit.Test)

Example 65 with MockConnectionFactoryImpl

use of io.pravega.client.stream.mock.MockConnectionFactoryImpl in project pravega by pravega.

the class ByteStreamReaderTest method setup.

@Before
public void setup() {
    PravegaNodeUri endpoint = new PravegaNodeUri("localhost", 0);
    connectionFactory = new MockConnectionFactoryImpl();
    controller = new MockController(endpoint.getEndpoint(), endpoint.getPort(), connectionFactory, false);
    controller.createScope(SCOPE);
    controller.createStream(SCOPE, STREAM, StreamConfiguration.builder().scalingPolicy(ScalingPolicy.fixed(1)).build());
    MockSegmentStreamFactory streamFactory = new MockSegmentStreamFactory();
    clientFactory = new ByteStreamClientImpl(SCOPE, controller, connectionFactory, streamFactory, streamFactory, streamFactory);
}
Also used : PravegaNodeUri(io.pravega.shared.protocol.netty.PravegaNodeUri) MockSegmentStreamFactory(io.pravega.client.stream.mock.MockSegmentStreamFactory) MockConnectionFactoryImpl(io.pravega.client.stream.mock.MockConnectionFactoryImpl) MockController(io.pravega.client.stream.mock.MockController) ByteStreamClientImpl(io.pravega.client.byteStream.impl.ByteStreamClientImpl) Before(org.junit.Before)

Aggregations

MockConnectionFactoryImpl (io.pravega.client.stream.mock.MockConnectionFactoryImpl)121 MockController (io.pravega.client.stream.mock.MockController)118 PravegaNodeUri (io.pravega.shared.protocol.netty.PravegaNodeUri)114 Test (org.junit.Test)114 Cleanup (lombok.Cleanup)86 ClientConnection (io.pravega.client.connection.impl.ClientConnection)73 Segment (io.pravega.client.segment.impl.Segment)41 WireCommands (io.pravega.shared.protocol.netty.WireCommands)37 UUID (java.util.UUID)37 InvocationOnMock (org.mockito.invocation.InvocationOnMock)37 ReplyProcessor (io.pravega.shared.protocol.netty.ReplyProcessor)36 AppendSetup (io.pravega.shared.protocol.netty.WireCommands.AppendSetup)34 SetupAppend (io.pravega.shared.protocol.netty.WireCommands.SetupAppend)34 ByteBuffer (java.nio.ByteBuffer)32 MockSegmentStreamFactory (io.pravega.client.stream.mock.MockSegmentStreamFactory)31 AtomicLong (java.util.concurrent.atomic.AtomicLong)29 CompletableFuture (java.util.concurrent.CompletableFuture)27 InOrder (org.mockito.InOrder)27 SynchronizerClientFactory (io.pravega.client.SynchronizerClientFactory)26 SynchronizerConfig (io.pravega.client.state.SynchronizerConfig)22