use of io.pravega.client.stream.StreamCut in project pravega by pravega.
the class ControllerImplTest method testGetSegmentsWithOverlappingStreamCuts.
@Test(expected = IllegalArgumentException.class)
public void testGetSegmentsWithOverlappingStreamCuts() 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, 3), 4L);
startSegments.put(new Segment(scope, stream, 2), 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, 0), 10L);
endSegments.put(new Segment(scope, stream, 7), 10L);
StreamCut endSC = new StreamCutImpl(s, endSegments);
controllerClient.getSegments(cut, endSC).get().getSegments();
}
use of io.pravega.client.stream.StreamCut in project pravega by pravega.
the class ControllerImplTest method testGetSegmentsWithPartialOverlapStreamCuts.
@Test(expected = IllegalArgumentException.class)
public void testGetSegmentsWithPartialOverlapStreamCuts() 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, 7), 6L);
StreamCut cut = new StreamCutImpl(s, startSegments);
Map<Segment, Long> endSegments = new HashMap<>();
endSegments.put(new Segment(scope, stream, 5), 10L);
endSegments.put(new Segment(scope, stream, 4), 10L);
endSegments.put(new Segment(scope, stream, 6), 10L);
StreamCut endSC = new StreamCutImpl(s, endSegments);
controllerClient.getSegments(cut, endSC).get().getSegments();
}
use of io.pravega.client.stream.StreamCut in project pravega by pravega.
the class ControllerImplTest method testGetSegmentsWithPartialOverlapStreamCut.
@Test(expected = IllegalArgumentException.class)
public void testGetSegmentsWithPartialOverlapStreamCut() 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, 5), 6L);
startSegments.put(new Segment(scope, stream, 6), 6L);
startSegments.put(new Segment(scope, stream, 2), 6L);
StreamCut cut = new StreamCutImpl(s, startSegments);
Map<Segment, Long> endSegments = new HashMap<>();
endSegments.put(new Segment(scope, stream, 8), 10L);
endSegments.put(new Segment(scope, stream, 7), 10L);
endSegments.put(new Segment(scope, stream, 1), 10L);
endSegments.put(new Segment(scope, stream, 3), 10L);
endSegments.put(new Segment(scope, stream, 4), 10L);
StreamCut endSC = new StreamCutImpl(s, endSegments);
controllerClient.getSegments(cut, endSC).get().getSegments();
}
use of io.pravega.client.stream.StreamCut in project pravega by pravega.
the class BatchClientFactoryImpl method getStreamSegmentInfo.
private StreamSegmentsIterator getStreamSegmentInfo(final Stream stream, final StreamCut startStreamCut, final StreamCut endStreamCut) {
log.debug("Start stream cut: {}, End stream cut: {}", startStreamCut, endStreamCut);
StreamSegmentsInfoImpl.validateStreamCuts(startStreamCut, endStreamCut);
StreamSegmentSuccessors segments = getAndHandleExceptions(controller.getSegments(startStreamCut, endStreamCut), RuntimeException::new);
final SortedSet<Segment> segmentSet = new TreeSet<>(segments.getSegments());
final DelegationTokenProvider tokenProvider = DelegationTokenProviderFactory.create(controller, stream.getScope(), stream.getStreamName(), AccessOperation.READ);
log.debug("List of Segments between the start and end stream cuts : {}", segmentSet);
val futures = segmentSet.stream().map(s -> getSegmentRange(s, startStreamCut, endStreamCut, tokenProvider)).collect(Collectors.toList());
List<SegmentRange> results = Futures.getThrowingException(Futures.allOfWithResults(futures));
return StreamSegmentsInfoImpl.builder().segmentRangeIterator(results.iterator()).startStreamCut(startStreamCut).endStreamCut(endStreamCut).build();
}
use of io.pravega.client.stream.StreamCut in project pravega by pravega.
the class BatchClientFactoryImpl method listSegments.
private StreamSegmentsIterator listSegments(final Stream stream, final Optional<StreamCut> startStreamCut, final Optional<StreamCut> endStreamCut) {
val startCut = startStreamCut.filter(sc -> !sc.equals(StreamCut.UNBOUNDED));
val endCut = endStreamCut.filter(sc -> !sc.equals(StreamCut.UNBOUNDED));
// Validate that the stream cuts are for the requested stream.
startCut.ifPresent(streamCut -> Preconditions.checkArgument(stream.equals(streamCut.asImpl().getStream())));
endCut.ifPresent(streamCut -> Preconditions.checkArgument(stream.equals(streamCut.asImpl().getStream())));
// if startStreamCut is not provided use the streamCut at the start of the stream.
// if toStreamCut is not provided obtain a streamCut at the tail of the stream.
CompletableFuture<StreamCut> startSCFuture = startCut.isPresent() ? CompletableFuture.completedFuture(startCut.get()) : streamCutHelper.fetchHeadStreamCut(stream);
CompletableFuture<StreamCut> endSCFuture = endCut.isPresent() ? CompletableFuture.completedFuture(endCut.get()) : streamCutHelper.fetchTailStreamCut(stream);
// fetch the StreamSegmentsInfo based on start and end streamCuts.
return getStreamSegmentInfo(stream, startSCFuture.join(), endSCFuture.join());
}
Aggregations