use of io.pravega.shared.protocol.netty.PravegaNodeUri in project pravega by pravega.
the class SegmentHelperTest method testGetSegmentAttribute.
@Test
public void testGetSegmentAttribute() {
MockConnectionFactory factory = new MockConnectionFactory();
@Cleanup SegmentHelper helper = new SegmentHelper(factory, new MockHostControllerStore(), executorService());
CompletableFuture<WireCommands.SegmentAttribute> retVal = helper.getSegmentAttribute("", new UUID(Long.MIN_VALUE, 0), new PravegaNodeUri("localhost", 12345), "");
long requestId = ((MockConnection) (factory.connection)).getRequestId();
factory.rp.process(new WireCommands.AuthTokenCheckFailed(requestId, "SomeException"));
AssertExtensions.assertThrows("", retVal::join, ex -> Exceptions.unwrap(ex) instanceof WireCommandFailedException);
CompletableFuture<WireCommands.SegmentAttribute> result = helper.getSegmentAttribute("", new UUID(Long.MIN_VALUE, 0), new PravegaNodeUri("localhost", 12345), "");
requestId = ((MockConnection) (factory.connection)).getRequestId();
factory.rp.process(new WireCommands.SegmentAttribute(requestId, 0L));
result.join();
Supplier<CompletableFuture<?>> futureSupplier = () -> helper.getSegmentAttribute("", new UUID(Long.MIN_VALUE, 0), new PravegaNodeUri("localhost", 12345), "");
validateProcessingFailureCFE(factory, futureSupplier);
testConnectionFailure(factory, futureSupplier);
}
use of io.pravega.shared.protocol.netty.PravegaNodeUri in project pravega by pravega.
the class SegmentHelper method sendRequestAsync.
private <ResultT> void sendRequestAsync(final WireCommand request, final ReplyProcessor replyProcessor, final CompletableFuture<ResultT> resultFuture, final ConnectionFactory connectionFactory, final PravegaNodeUri uri) {
CompletableFuture<ClientConnection> connectionFuture = connectionFactory.establishConnection(uri, replyProcessor);
connectionFuture.whenComplete((connection, e) -> {
if (connection == null) {
resultFuture.completeExceptionally(new WireCommandFailedException(new ConnectionFailedException(e), request.getType(), WireCommandFailedException.Reason.ConnectionFailed));
} else {
try {
connection.send(request);
} catch (ConnectionFailedException cfe) {
throw new WireCommandFailedException(cfe, request.getType(), WireCommandFailedException.Reason.ConnectionFailed);
} catch (Exception e2) {
throw new RuntimeException(e2);
}
}
}).exceptionally(e -> {
Throwable cause = Exceptions.unwrap(e);
if (cause instanceof WireCommandFailedException) {
resultFuture.completeExceptionally(cause);
} else if (cause instanceof ConnectionFailedException) {
resultFuture.completeExceptionally(new WireCommandFailedException(cause, request.getType(), WireCommandFailedException.Reason.ConnectionFailed));
} else {
resultFuture.completeExceptionally(new RuntimeException(cause));
}
return null;
});
resultFuture.whenComplete((result, e) -> {
connectionFuture.thenAccept(ClientConnection::close);
});
}
use of io.pravega.shared.protocol.netty.PravegaNodeUri in project pravega by pravega.
the class ControllerImpl method getEndpointForSegment.
@Override
public CompletableFuture<PravegaNodeUri> getEndpointForSegment(final String qualifiedSegmentName) {
Exceptions.checkNotClosed(closed.get(), this);
Exceptions.checkNotNullOrEmpty(qualifiedSegmentName, "qualifiedSegmentName");
long traceId = LoggerHelpers.traceEnter(log, "getEndpointForSegment", qualifiedSegmentName);
final CompletableFuture<NodeUri> result = this.retryConfig.runAsync(() -> {
RPCAsyncCallback<NodeUri> callback = new RPCAsyncCallback<>();
Segment segment = Segment.fromScopedName(qualifiedSegmentName);
client.getURI(ModelHelper.createSegmentId(segment.getScope(), segment.getStreamName(), segment.getSegmentNumber()), callback);
return callback.getFuture();
}, this.executor);
return result.thenApply(ModelHelper::encode).whenComplete((x, e) -> {
if (e != null) {
log.warn("getEndpointForSegment failed: ", e);
}
LoggerHelpers.traceLeave(log, "getEndpointForSegment", traceId);
});
}
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());
}
Aggregations