use of io.pravega.shared.protocol.netty.WireCommands.StreamSegmentInfo 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.StreamSegmentInfo in project pravega by pravega.
the class SegmentMetadataClientTest method testCurrentStreamLength.
@Test(timeout = 10000)
public void testCurrentStreamLength() throws Exception {
Segment segment = new Segment("scope", "testRetry", 4);
PravegaNodeUri endpoint = new PravegaNodeUri("localhost", 0);
@Cleanup MockConnectionFactoryImpl cf = new MockConnectionFactoryImpl();
@Cleanup MockController controller = new MockController(endpoint.getEndpoint(), endpoint.getPort(), cf);
@Cleanup ClientConnection connection = mock(ClientConnection.class);
cf.provideConnection(endpoint, connection);
SegmentMetadataClientImpl client = new SegmentMetadataClientImpl(segment, controller, cf, "");
client.getConnection();
ReplyProcessor processor = cf.getProcessor(endpoint);
Mockito.doAnswer(new Answer<Void>() {
@Override
public Void answer(InvocationOnMock invocation) throws Throwable {
processor.process(new StreamSegmentInfo(1, segment.getScopedName(), true, false, false, 0, 123, 121));
return null;
}
}).when(connection).send(new WireCommands.GetStreamSegmentInfo(1, segment.getScopedName(), ""));
long length = client.fetchCurrentSegmentLength();
assertEquals(123, length);
}
use of io.pravega.shared.protocol.netty.WireCommands.StreamSegmentInfo in project pravega by pravega.
the class PravegaRequestProcessor method getStreamSegmentInfo.
@Override
public void getStreamSegmentInfo(GetStreamSegmentInfo getStreamSegmentInfo) {
String segmentName = getStreamSegmentInfo.getSegmentName();
if (!verifyToken(segmentName, getStreamSegmentInfo.getRequestId(), getStreamSegmentInfo.getDelegationToken(), READ, "Get Stream Segment Info")) {
return;
}
segmentStore.getStreamSegmentInfo(segmentName, false, 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, "Get segment info", e));
}
use of io.pravega.shared.protocol.netty.WireCommands.StreamSegmentInfo 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.StreamSegmentInfo 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());
}
Aggregations