use of io.pravega.client.stream.StreamCut in project pravega by pravega.
the class ControllerImplTest method testGetSegmentsWithValidStreamCut.
/*
Segment mapping of stream8 used for the below tests.
+-------+------+-------
| | 8 |
| 2 +------|
| | 7 | 10
+-------+ -----|
| | 6 |
| 1 +------+-------
| | 5 |
+-------+------|
| | 4 | 9
| 0 +------|
| | 3 |
+-------+------+--------
*/
@Test
public void testGetSegmentsWithValidStreamCut() throws Exception {
String scope = "scope1";
String stream = "stream8";
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);
startSegments.put(new Segment(scope, stream, 7), 6L);
startSegments.put(new Segment(scope, stream, 8), 6L);
StreamCut cut = new StreamCutImpl(s, startSegments);
Map<Segment, Long> endSegments = new HashMap<>();
endSegments.put(new Segment(scope, stream, 3), 10L);
endSegments.put(new Segment(scope, stream, 4), 10L);
endSegments.put(new Segment(scope, stream, 5), 10L);
endSegments.put(new Segment(scope, stream, 10), 10L);
StreamCut endSC = new StreamCutImpl(s, endSegments);
Set<Segment> segments = controllerClient.getSegments(cut, endSC).get().getSegments();
assertEquals(ImmutableSet.of(new Segment(scope, stream, 0), new Segment(scope, stream, 1), new Segment(scope, stream, 8), new Segment(scope, stream, 7), new Segment(scope, stream, 3), new Segment(scope, stream, 4), new Segment(scope, stream, 5), new Segment(scope, stream, 10), new Segment(scope, stream, 6)), segments);
}
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, Map<Segment, Long> endSegments) {
log.debug("Compute unread bytes from position {}", positions);
final List<CompletableFuture<Long>> futures = new ArrayList<>(positions.size());
for (Entry<Stream, Map<Segment, Long>> streamPosition : positions.entrySet()) {
StreamCut fromStreamCut = new StreamCutImpl(streamPosition.getKey(), streamPosition.getValue());
StreamCut toStreamCut = computeEndStreamCut(streamPosition.getKey(), endSegments);
futures.add(getRemainingBytes(streamPosition.getKey(), fromStreamCut, toStreamCut));
}
return Futures.getAndHandleExceptions(allOfWithResults(futures).thenApply(listOfLong -> {
return listOfLong.stream().mapToLong(i -> i).sum();
}), RuntimeException::new);
}
use of io.pravega.client.stream.StreamCut in project pravega by pravega.
the class ReaderGroupImpl method getStreamCuts.
@Override
@VisibleForTesting
public Map<Stream, StreamCut> getStreamCuts() {
synchronizer.fetchUpdates();
ReaderGroupState state = synchronizer.getState();
Map<Stream, Map<SegmentWithRange, Long>> positions = state.getPositions();
HashMap<Stream, StreamCut> cuts = new HashMap<>();
for (Entry<Stream, Map<SegmentWithRange, Long>> streamPosition : positions.entrySet()) {
StreamCut position = new StreamCutImpl(streamPosition.getKey(), dropRange(streamPosition.getValue()));
cuts.put(streamPosition.getKey(), position);
}
return cuts;
}
use of io.pravega.client.stream.StreamCut in project pravega by pravega.
the class ControllerImplTest method testGetStreamCutSuccessors.
@Test
public void testGetStreamCutSuccessors() throws Exception {
StreamCut from = new StreamCutImpl(new StreamImpl("scope1", "stream1"), Collections.emptyMap());
CompletableFuture<StreamSegmentSuccessors> successors = controllerClient.getSuccessors(from);
assertEquals(2, successors.get().getSegments().size());
}
use of io.pravega.client.stream.StreamCut in project pravega by pravega.
the class ControllerImplTest method testUpdateReaderGroup.
@Test
public void testUpdateReaderGroup() throws Exception {
CompletableFuture<Long> updateRGStatus;
final Segment seg0 = new Segment("scope1", "stream1", 0L);
final Segment seg1 = new Segment("scope1", "stream1", 1L);
ImmutableMap<Segment, Long> startStreamCut = ImmutableMap.of(seg0, 10L, seg1, 10L);
Map<Stream, StreamCut> startSC = ImmutableMap.of(Stream.of("scope1", "stream1"), new StreamCutImpl(Stream.of("scope1", "stream1"), startStreamCut));
ImmutableMap<Segment, Long> endStreamCut = ImmutableMap.of(seg0, 200L, seg1, 300L);
Map<Stream, StreamCut> endSC = ImmutableMap.of(Stream.of("scope1", "stream1"), new StreamCutImpl(Stream.of("scope1", "stream1"), endStreamCut));
ReaderGroupConfig config = ReaderGroupConfig.builder().automaticCheckpointIntervalMillis(30000L).groupRefreshTimeMillis(20000L).maxOutstandingCheckpointRequest(2).retentionType(ReaderGroupConfig.StreamDataRetention.AUTOMATIC_RELEASE_AT_LAST_CHECKPOINT).startingStreamCuts(startSC).endingStreamCuts(endSC).build();
config = ReaderGroupConfig.cloneConfig(config, UUID.randomUUID(), 0L);
updateRGStatus = controllerClient.updateReaderGroup("scope1", "rg1", config);
assertNotNull(updateRGStatus.get());
updateRGStatus = controllerClient.updateReaderGroup("scope1", "rg2", config);
AssertExtensions.assertFutureThrows("Server should throw exception", updateRGStatus, Throwable -> true);
updateRGStatus = controllerClient.updateReaderGroup("scope1", "rg3", config);
AssertExtensions.assertFutureThrows("Server should throw exception", updateRGStatus, throwable -> throwable instanceof IllegalArgumentException);
updateRGStatus = controllerClient.updateReaderGroup("scope1", "rg4", config);
AssertExtensions.assertFutureThrows("Server should throw exception", updateRGStatus, throwable -> throwable instanceof ReaderGroupConfigRejectedException);
}
Aggregations