use of io.pravega.client.stream.StreamCut in project pravega by pravega.
the class ReaderGroupImpl method getUnreadBytes.
private long getUnreadBytes(Map<Stream, Map<Segment, Long>> positions, SegmentMetadataClientFactory metaFactory) {
log.debug("Compute unread bytes from position {}", positions);
long totalLength = 0;
for (Entry<Stream, Map<Segment, Long>> streamPosition : positions.entrySet()) {
StreamCut position = new StreamCutImpl(streamPosition.getKey(), streamPosition.getValue());
totalLength += getRemainingBytes(metaFactory, position);
}
return totalLength;
}
use of io.pravega.client.stream.StreamCut in project pravega by pravega.
the class ReaderGroupImpl method getStreamCuts.
@Override
public Map<Stream, StreamCut> getStreamCuts() {
@Cleanup StateSynchronizer<ReaderGroupState> synchronizer = createSynchronizer();
synchronizer.fetchUpdates();
ReaderGroupState state = synchronizer.getState();
Map<Stream, Map<Segment, Long>> positions = state.getPositions();
HashMap<Stream, StreamCut> cuts = new HashMap<>();
for (Entry<Stream, Map<Segment, Long>> streamPosition : positions.entrySet()) {
StreamCut position = new StreamCutImpl(streamPosition.getKey(), streamPosition.getValue());
cuts.put(streamPosition.getKey(), position);
}
return cuts;
}
use of io.pravega.client.stream.StreamCut in project pravega by pravega.
the class ReaderGroupImpl method resetReadersToCheckpoint.
@SuppressWarnings("deprecation")
@Override
public void resetReadersToCheckpoint(Checkpoint checkpoint) {
@Cleanup StateSynchronizer<ReaderGroupState> synchronizer = createSynchronizer();
synchronizer.updateState(state -> {
ReaderGroupConfig config = state.getConfig();
Map<Segment, Long> positions = new HashMap<>();
for (StreamCut cut : checkpoint.asImpl().getPositions().values()) {
positions.putAll(cut.asImpl().getPositions());
}
return Collections.singletonList(new ReaderGroupStateInit(config, positions));
});
}
use of io.pravega.client.stream.StreamCut in project pravega by pravega.
the class ControllerImplTest method testCutpointSuccessors.
@Test
public void testCutpointSuccessors() throws Exception {
String scope = "scope1";
String stream = "stream1";
Stream s = new StreamImpl(scope, stream);
Map<Segment, Long> segments = new HashMap<>();
segments.put(new Segment(scope, stream, 0), 4L);
segments.put(new Segment(scope, stream, 1), 6L);
StreamCut cut = new StreamCutImpl(s, segments);
Set<Segment> successors = controllerClient.getSuccessors(cut).get().getSegments();
assertEquals(ImmutableSet.of(new Segment(scope, stream, 0), new Segment(scope, stream, 1), new Segment(scope, stream, 2), new Segment(scope, stream, 3), new Segment(scope, stream, 4), new Segment(scope, stream, 5), new Segment(scope, stream, 6), new Segment(scope, stream, 7)), successors);
}
use of io.pravega.client.stream.StreamCut in project pravega by pravega.
the class ControllerImplTest method testGetSegmentsWithValidStreamCuts.
@Test
public void testGetSegmentsWithValidStreamCuts() throws Exception {
String scope = "scope1";
String stream = "stream1";
Stream s = new StreamImpl(scope, stream);
Map<Segment, Long> startSegments = new HashMap<>();
startSegments.put(new Segment(scope, stream, 0), 4L);
startSegments.put(new Segment(scope, stream, 1), 6L);
StreamCut cut = new StreamCutImpl(s, startSegments);
Map<Segment, Long> endSegments = new HashMap<>();
endSegments.put(new Segment(scope, stream, 6), 10L);
endSegments.put(new Segment(scope, stream, 7), 10L);
StreamCut endSC = new StreamCutImpl(s, endSegments);
Set<Segment> result = controllerClient.getSegments(cut, endSC).get().getSegments();
assertEquals(ImmutableSet.of(new Segment(scope, stream, 0), new Segment(scope, stream, 1), new Segment(scope, stream, 2), new Segment(scope, stream, 3), new Segment(scope, stream, 4), new Segment(scope, stream, 5), new Segment(scope, stream, 6), new Segment(scope, stream, 7)), result);
}
Aggregations