use of io.pravega.shared.protocol.netty.WireCommands.GetStreamSegmentInfo in project pravega by pravega.
the class SegmentMetadataClientImpl method getSegmentInfo.
@Override
public SegmentInfo getSegmentInfo() {
val future = RETRY_SCHEDULE.retryingOn(ConnectionFailedException.class).throwingOn(NoSuchSegmentException.class).runAsync(() -> getStreamSegmentInfo(delegationToken), connectionFactory.getInternalExecutor());
StreamSegmentInfo info = future.join();
return new SegmentInfo(segmentId, info.getStartOffset(), info.getWriteOffset(), info.isSealed(), info.getLastModified());
}
use of io.pravega.shared.protocol.netty.WireCommands.GetStreamSegmentInfo 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;
}
use of io.pravega.shared.protocol.netty.WireCommands.GetStreamSegmentInfo in project pravega by pravega.
the class SegmentMetadataClientImpl method getStreamSegmentInfo.
private CompletableFuture<StreamSegmentInfo> getStreamSegmentInfo(String delegationToken) {
long requestId = requestIdGenerator.get();
log.debug("Getting segment info for segment: {}", segmentId);
RawClient connection = getConnection();
return connection.sendRequest(requestId, new GetStreamSegmentInfo(requestId, segmentId.getScopedName(), delegationToken)).thenApply(r -> transformReply(r, StreamSegmentInfo.class));
}
use of io.pravega.shared.protocol.netty.WireCommands.GetStreamSegmentInfo 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.WireCommands.GetStreamSegmentInfo in project pravega by pravega.
the class PravegaRequestProcessor method getStreamSegmentInfo.
@Override
public void getStreamSegmentInfo(GetStreamSegmentInfo getStreamSegmentInfo) {
String segmentName = getStreamSegmentInfo.getSegmentName();
final String operation = "getStreamSegmentInfo";
if (!verifyToken(segmentName, getStreamSegmentInfo.getRequestId(), getStreamSegmentInfo.getDelegationToken(), operation)) {
return;
}
segmentStore.getStreamSegmentInfo(segmentName, TIMEOUT).thenAccept(properties -> {
if (properties != null) {
StreamSegmentInfo result = new StreamSegmentInfo(getStreamSegmentInfo.getRequestId(), properties.getName(), true, properties.isSealed(), properties.isDeleted(), properties.getLastModified().getTime(), properties.getLength(), properties.getStartOffset());
log.trace("Read stream segment info: {}", result);
connection.send(result);
} else {
log.trace("getStreamSegmentInfo could not find segment {}", segmentName);
connection.send(new StreamSegmentInfo(getStreamSegmentInfo.getRequestId(), segmentName, false, true, true, 0, 0, 0));
}
}).exceptionally(e -> handleException(getStreamSegmentInfo.getRequestId(), segmentName, operation, e));
}
Aggregations