use of io.pravega.client.stream.mock.MockConnectionFactoryImpl 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();
}
use of io.pravega.client.stream.mock.MockConnectionFactoryImpl 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());
}
use of io.pravega.client.stream.mock.MockConnectionFactoryImpl in project pravega by pravega.
the class StreamManagerImplTest method setUp.
@Before
public void setUp() {
PravegaNodeUri uri = new PravegaNodeUri("endpoint", SERVICE_PORT);
connectionFactory = new MockConnectionFactoryImpl();
this.controller = new MockController(uri.getEndpoint(), uri.getPort(), connectionFactory, true);
this.streamManager = new StreamManagerImpl(controller, connectionFactory);
}
use of io.pravega.client.stream.mock.MockConnectionFactoryImpl in project pravega by pravega.
the class BatchClientImplTest method testGetSegmentsWithUnboundedStreamCut.
@Test(timeout = 5000)
public void testGetSegmentsWithUnboundedStreamCut() throws Exception {
PravegaNodeUri location = new PravegaNodeUri("localhost", 0);
@Cleanup MockConnectionFactoryImpl connectionFactory = getMockConnectionFactory(location);
MockController mockController = new MockController(location.getEndpoint(), location.getPort(), connectionFactory, false);
Stream stream = createStream(SCOPE, STREAM, 3, mockController);
@Cleanup BatchClientFactoryImpl client = new BatchClientFactoryImpl(mockController, ClientConfig.builder().maxConnectionsPerSegmentStore(1).build(), connectionFactory);
Iterator<SegmentRange> unBoundedSegments = client.getSegments(stream, StreamCut.UNBOUNDED, StreamCut.UNBOUNDED).getIterator();
assertTrue(unBoundedSegments.hasNext());
assertEquals(0L, unBoundedSegments.next().asImpl().getSegment().getSegmentId());
assertTrue(unBoundedSegments.hasNext());
assertEquals(1L, unBoundedSegments.next().asImpl().getSegment().getSegmentId());
assertTrue(unBoundedSegments.hasNext());
assertEquals(2L, unBoundedSegments.next().asImpl().getSegment().getSegmentId());
assertFalse(unBoundedSegments.hasNext());
}
use of io.pravega.client.stream.mock.MockConnectionFactoryImpl in project pravega by pravega.
the class BatchClientImplTest method getMockConnectionFactory.
private MockConnectionFactoryImpl getMockConnectionFactory(PravegaNodeUri location) throws ConnectionFailedException {
MockConnectionFactoryImpl connectionFactory = new MockConnectionFactoryImpl();
ClientConnection connection = mock(ClientConnection.class);
Mockito.doAnswer(new Answer<Void>() {
@Override
public Void answer(InvocationOnMock invocation) throws Throwable {
GetStreamSegmentInfo request = (GetStreamSegmentInfo) invocation.getArgument(0);
connectionFactory.getProcessor(location).process(new StreamSegmentInfo(request.getRequestId(), request.getSegmentName(), true, false, false, 0, 0, 0));
return null;
}
}).when(connection).send(Mockito.any(GetStreamSegmentInfo.class));
connectionFactory.provideConnection(location, connection);
return connectionFactory;
}
Aggregations