use of io.pravega.shared.protocol.netty.PravegaNodeUri in project pravega by pravega.
the class BatchClientImplTest method testSegmentIterator.
@Test(timeout = 5000)
public void testSegmentIterator() throws ConnectionFailedException {
MockConnectionFactoryImpl connectionFactory = new MockConnectionFactoryImpl();
ClientConnection connection = Mockito.mock(ClientConnection.class);
PravegaNodeUri location = new PravegaNodeUri("localhost", 0);
Mockito.doAnswer(new Answer<Void>() {
@Override
public Void answer(InvocationOnMock invocation) throws Throwable {
CreateSegment request = (CreateSegment) invocation.getArgument(0);
connectionFactory.getProcessor(location).process(new SegmentCreated(request.getRequestId(), request.getSegment()));
return null;
}
}).when(connection).send(Mockito.any(CreateSegment.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);
MockController mockController = new MockController(location.getEndpoint(), location.getPort(), connectionFactory);
BatchClientImpl client = new BatchClientImpl(mockController, connectionFactory);
Stream stream = new StreamImpl("scope", "stream");
mockController.createScope("scope");
mockController.createStream(StreamConfiguration.builder().scope("scope").streamName("stream").scalingPolicy(ScalingPolicy.fixed(3)).build()).join();
Iterator<SegmentRange> segments = client.getSegments(stream, null, null).getIterator();
assertTrue(segments.hasNext());
assertEquals(0, segments.next().asImpl().getSegment().getSegmentNumber());
assertTrue(segments.hasNext());
assertEquals(1, segments.next().asImpl().getSegment().getSegmentNumber());
assertTrue(segments.hasNext());
assertEquals(2, segments.next().asImpl().getSegment().getSegmentNumber());
assertFalse(segments.hasNext());
}
use of io.pravega.shared.protocol.netty.PravegaNodeUri 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.shared.protocol.netty.PravegaNodeUri in project pravega by pravega.
the class AsyncSegmentInputStreamTest method testRead.
@Test(timeout = 10000)
public void testRead() throws ConnectionFailedException {
Segment segment = new Segment("scope", "testRead", 1);
PravegaNodeUri endpoint = new PravegaNodeUri("localhost", SERVICE_PORT);
MockConnectionFactoryImpl connectionFactory = new MockConnectionFactoryImpl();
MockController controller = new MockController(endpoint.getEndpoint(), endpoint.getPort(), connectionFactory);
@Cleanup AsyncSegmentInputStreamImpl in = new AsyncSegmentInputStreamImpl(controller, connectionFactory, segment, "");
ClientConnection c = mock(ClientConnection.class);
connectionFactory.provideConnection(endpoint, c);
WireCommands.SegmentRead segmentRead = new WireCommands.SegmentRead(segment.getScopedName(), 1234, false, false, ByteBuffer.allocate(0));
CompletableFuture<SegmentRead> readFuture = in.read(1234, 5678);
Async.testBlocking(() -> readFuture.get(), () -> {
ReplyProcessor processor = connectionFactory.getProcessor(endpoint);
processor.segmentRead(segmentRead);
});
verify(c).sendAsync(new WireCommands.ReadSegment(segment.getScopedName(), 1234, 5678, ""));
assertTrue(Futures.isSuccessful(readFuture));
assertEquals(segmentRead, readFuture.join());
verifyNoMoreInteractions(c);
}
use of io.pravega.shared.protocol.netty.PravegaNodeUri in project pravega by pravega.
the class AsyncSegmentInputStreamTest method testRetry.
@Test(timeout = 10000)
public void testRetry() throws ConnectionFailedException {
Segment segment = new Segment("scope", "testRetry", 4);
PravegaNodeUri endpoint = new PravegaNodeUri("localhost", SERVICE_PORT);
MockConnectionFactoryImpl connectionFactory = new MockConnectionFactoryImpl();
MockController controller = new MockController(endpoint.getEndpoint(), endpoint.getPort(), connectionFactory);
@Cleanup AsyncSegmentInputStreamImpl in = new AsyncSegmentInputStreamImpl(controller, connectionFactory, segment, "");
ClientConnection c = mock(ClientConnection.class);
InOrder inOrder = Mockito.inOrder(c);
connectionFactory.provideConnection(endpoint, c);
WireCommands.SegmentRead segmentRead = new WireCommands.SegmentRead(segment.getScopedName(), 1234, false, false, ByteBuffer.allocate(0));
Mockito.doAnswer(new Answer<Void>() {
@Override
public Void answer(InvocationOnMock invocation) throws Throwable {
connectionFactory.getProcessor(endpoint).connectionDropped();
return null;
}
}).doAnswer(new Answer<Void>() {
@Override
public Void answer(InvocationOnMock invocation) throws Throwable {
connectionFactory.getProcessor(endpoint).authTokenCheckFailed(new WireCommands.AuthTokenCheckFailed(100));
return null;
}
}).doAnswer(new Answer<Void>() {
@Override
public Void answer(InvocationOnMock invocation) throws Throwable {
connectionFactory.getProcessor(endpoint).segmentRead(segmentRead);
return null;
}
}).when(c).sendAsync(Mockito.any(ReadSegment.class));
CompletableFuture<SegmentRead> readFuture = in.read(1234, 5678);
assertEquals(segmentRead, readFuture.join());
assertTrue(Futures.isSuccessful(readFuture));
inOrder.verify(c).sendAsync(new WireCommands.ReadSegment(segment.getScopedName(), 1234, 5678, ""));
inOrder.verify(c).close();
inOrder.verify(c).sendAsync(new WireCommands.ReadSegment(segment.getScopedName(), 1234, 5678, ""));
inOrder.verify(c).close();
inOrder.verify(c).sendAsync(new WireCommands.ReadSegment(segment.getScopedName(), 1234, 5678, ""));
verifyNoMoreInteractions(c);
}
use of io.pravega.shared.protocol.netty.PravegaNodeUri in project pravega by pravega.
the class AsyncSegmentInputStreamTest method testCloseAbortsRead.
@Test(timeout = 10000)
public void testCloseAbortsRead() throws InterruptedException, ExecutionException {
Segment segment = new Segment("scope", "testRetry", 4);
PravegaNodeUri endpoint = new PravegaNodeUri("localhost", SERVICE_PORT);
MockConnectionFactoryImpl connectionFactory = new MockConnectionFactoryImpl();
MockController controller = new MockController(endpoint.getEndpoint(), endpoint.getPort(), connectionFactory);
@Cleanup AsyncSegmentInputStreamImpl in = new AsyncSegmentInputStreamImpl(controller, connectionFactory, segment, "");
ClientConnection c = mock(ClientConnection.class);
connectionFactory.provideConnection(endpoint, c);
// Make sure connection is established.
in.getConnection().get();
CompletableFuture<SegmentRead> read = in.read(1234, 5678);
assertFalse(read.isDone());
in.close();
AssertExtensions.assertThrows(ConnectionClosedException.class, () -> Futures.getThrowingException(read));
verify(c).close();
}
Aggregations