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());
}
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();
}
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();
}
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());
}
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);
}
Aggregations