use of io.pravega.shared.protocol.netty.WireCommands.StreamSegmentInfo in project pravega by pravega.
the class SegmentMetadataClientTest method testReconnects.
@Test(timeout = 10000)
public void testReconnects() throws Exception {
Segment segment = new Segment("scope", "testRetry", 4);
PravegaNodeUri endpoint = new PravegaNodeUri("localhost", 0);
@Cleanup MockConnectionFactoryImpl cf = Mockito.spy(new MockConnectionFactoryImpl());
@Cleanup MockController controller = new MockController(endpoint.getEndpoint(), endpoint.getPort(), cf);
@Cleanup ClientConnection connection = mock(ClientConnection.class);
cf.provideConnection(endpoint, connection);
@Cleanup SegmentMetadataClientImpl client = new SegmentMetadataClientImpl(segment, controller, cf, "");
client.getConnection();
WireCommands.GetStreamSegmentInfo getSegmentInfo1 = new WireCommands.GetStreamSegmentInfo(1, segment.getScopedName(), "");
Mockito.doAnswer(new Answer<Void>() {
@Override
public Void answer(InvocationOnMock invocation) throws Throwable {
ReplyProcessor processor = cf.getProcessor(endpoint);
processor.connectionDropped();
return null;
}
}).when(connection).send(getSegmentInfo1);
WireCommands.GetStreamSegmentInfo getSegmentInfo2 = new WireCommands.GetStreamSegmentInfo(2, segment.getScopedName(), "");
Mockito.doAnswer(new Answer<Void>() {
@Override
public Void answer(InvocationOnMock invocation) throws Throwable {
ReplyProcessor processor = cf.getProcessor(endpoint);
processor.process(new StreamSegmentInfo(2, segment.getScopedName(), true, false, false, 0, 123, 121));
return null;
}
}).when(connection).send(getSegmentInfo2);
long length = client.fetchCurrentSegmentLength();
InOrder order = Mockito.inOrder(connection, cf);
order.verify(cf).establishConnection(eq(endpoint), any(ReplyProcessor.class));
order.verify(connection).send(getSegmentInfo1);
order.verify(cf).establishConnection(eq(endpoint), any(ReplyProcessor.class));
order.verify(connection).send(getSegmentInfo2);
order.verify(cf).getProcessor(eq(endpoint));
order.verifyNoMoreInteractions();
assertEquals(123, length);
}
use of io.pravega.shared.protocol.netty.WireCommands.StreamSegmentInfo in project pravega by pravega.
the class SegmentMetadataClientTest method testExceptionOnSend.
@Test(timeout = 10000)
public void testExceptionOnSend() throws Exception {
Segment segment = new Segment("scope", "testRetry", 4);
PravegaNodeUri endpoint = new PravegaNodeUri("localhost", 0);
@Cleanup("shutdown") InlineExecutor executor = new InlineExecutor();
@Cleanup ConnectionFactory cf = Mockito.mock(ConnectionFactory.class);
Mockito.when(cf.getInternalExecutor()).thenReturn(executor);
@Cleanup MockController controller = new MockController(endpoint.getEndpoint(), endpoint.getPort(), cf);
ClientConnection connection1 = mock(ClientConnection.class);
ClientConnection connection2 = mock(ClientConnection.class);
AtomicReference<ReplyProcessor> processor = new AtomicReference<>();
Mockito.when(cf.establishConnection(Mockito.eq(endpoint), Mockito.any())).thenReturn(Futures.failedFuture(new ConnectionFailedException())).thenReturn(CompletableFuture.completedFuture(connection1)).thenAnswer(new Answer<CompletableFuture<ClientConnection>>() {
@Override
public CompletableFuture<ClientConnection> answer(InvocationOnMock invocation) throws Throwable {
processor.set(invocation.getArgument(1));
return CompletableFuture.completedFuture(connection2);
}
});
WireCommands.GetStreamSegmentInfo getSegmentInfo1 = new WireCommands.GetStreamSegmentInfo(2, segment.getScopedName(), "");
Mockito.doThrow(new ConnectionFailedException()).when(connection1).send(getSegmentInfo1);
WireCommands.GetStreamSegmentInfo getSegmentInfo2 = new WireCommands.GetStreamSegmentInfo(3, segment.getScopedName(), "");
Mockito.doAnswer(new Answer<Void>() {
@Override
public Void answer(InvocationOnMock invocation) throws Throwable {
processor.get().process(new StreamSegmentInfo(3, segment.getScopedName(), true, false, false, 0, 123, 121));
return null;
}
}).when(connection2).send(getSegmentInfo2);
@Cleanup SegmentMetadataClientImpl client = new SegmentMetadataClientImpl(segment, controller, cf, "");
InOrder order = Mockito.inOrder(connection1, connection2, cf);
long length = client.fetchCurrentSegmentLength();
order.verify(cf, Mockito.times(2)).establishConnection(Mockito.eq(endpoint), Mockito.any());
order.verify(connection1).send(getSegmentInfo1);
order.verify(connection1).close();
order.verify(cf).establishConnection(Mockito.eq(endpoint), Mockito.any());
order.verify(connection2).send(getSegmentInfo2);
order.verifyNoMoreInteractions();
assertEquals(123, length);
}
Aggregations