Search in sources :

Example 1 with StreamCut

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();
}
Also used : StreamCut(io.pravega.client.stream.StreamCut) HashMap(java.util.HashMap) Stream(io.pravega.client.stream.Stream) Segment(io.pravega.client.segment.impl.Segment) Test(org.junit.Test)

Example 2 with StreamCut

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();
}
Also used : StreamCut(io.pravega.client.stream.StreamCut) HashMap(java.util.HashMap) Stream(io.pravega.client.stream.Stream) Segment(io.pravega.client.segment.impl.Segment) Test(org.junit.Test)

Example 3 with StreamCut

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();
}
Also used : StreamCut(io.pravega.client.stream.StreamCut) HashMap(java.util.HashMap) Stream(io.pravega.client.stream.Stream) Segment(io.pravega.client.segment.impl.Segment) Test(org.junit.Test)

Example 4 with StreamCut

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();
}
Also used : lombok.val(lombok.val) Segment(io.pravega.client.segment.impl.Segment) StreamCut(io.pravega.client.stream.StreamCut) SortedSet(java.util.SortedSet) ConnectionFactory(io.pravega.client.connection.impl.ConnectionFactory) SegmentMetadataClientFactoryImpl(io.pravega.client.segment.impl.SegmentMetadataClientFactoryImpl) CompletableFuture(java.util.concurrent.CompletableFuture) ConnectionPoolImpl(io.pravega.client.connection.impl.ConnectionPoolImpl) SegmentMetadataClientFactory(io.pravega.client.segment.impl.SegmentMetadataClientFactory) TreeSet(java.util.TreeSet) StreamCutHelper(io.pravega.client.admin.impl.StreamCutHelper) SegmentRange(io.pravega.client.batch.SegmentRange) Stream(io.pravega.client.stream.Stream) AccessOperation(io.pravega.shared.security.auth.AccessOperation) SegmentInputStreamFactoryImpl(io.pravega.client.segment.impl.SegmentInputStreamFactoryImpl) BatchClientFactory(io.pravega.client.BatchClientFactory) Serializer(io.pravega.client.stream.Serializer) SegmentInputStreamFactory(io.pravega.client.segment.impl.SegmentInputStreamFactory) Futures.getAndHandleExceptions(io.pravega.common.concurrent.Futures.getAndHandleExceptions) ConnectionPool(io.pravega.client.connection.impl.ConnectionPool) SegmentIterator(io.pravega.client.batch.SegmentIterator) lombok.val(lombok.val) SegmentInfo(io.pravega.client.segment.impl.SegmentInfo) DelegationTokenProviderFactory(io.pravega.client.security.auth.DelegationTokenProviderFactory) Collectors(java.util.stream.Collectors) Beta(com.google.common.annotations.Beta) DelegationTokenProvider(io.pravega.client.security.auth.DelegationTokenProvider) SegmentMetadataClient(io.pravega.client.segment.impl.SegmentMetadataClient) StreamSegmentSuccessors(io.pravega.client.stream.impl.StreamSegmentSuccessors) List(java.util.List) Slf4j(lombok.extern.slf4j.Slf4j) Optional(java.util.Optional) Preconditions(com.google.common.base.Preconditions) StreamSegmentsIterator(io.pravega.client.batch.StreamSegmentsIterator) Controller(io.pravega.client.control.impl.Controller) Futures(io.pravega.common.concurrent.Futures) ClientConfig(io.pravega.client.ClientConfig) SegmentRange(io.pravega.client.batch.SegmentRange) StreamSegmentSuccessors(io.pravega.client.stream.impl.StreamSegmentSuccessors) TreeSet(java.util.TreeSet) Segment(io.pravega.client.segment.impl.Segment) DelegationTokenProvider(io.pravega.client.security.auth.DelegationTokenProvider)

Example 5 with StreamCut

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());
}
Also used : lombok.val(lombok.val) StreamCut(io.pravega.client.stream.StreamCut)

Aggregations

StreamCut (io.pravega.client.stream.StreamCut)79 Stream (io.pravega.client.stream.Stream)65 Test (org.junit.Test)65 Segment (io.pravega.client.segment.impl.Segment)48 ReaderGroupConfig (io.pravega.client.stream.ReaderGroupConfig)47 HashMap (java.util.HashMap)39 StreamCutImpl (io.pravega.client.stream.impl.StreamCutImpl)37 Cleanup (lombok.Cleanup)30 StreamConfiguration (io.pravega.client.stream.StreamConfiguration)26 Map (java.util.Map)25 ReaderGroupManager (io.pravega.client.admin.ReaderGroupManager)21 ScalingPolicy (io.pravega.client.stream.ScalingPolicy)21 ArgumentMatchers.anyLong (org.mockito.ArgumentMatchers.anyLong)20 CompletableFuture (java.util.concurrent.CompletableFuture)19 ReaderGroup (io.pravega.client.stream.ReaderGroup)18 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)18 EventStreamClientFactory (io.pravega.client.EventStreamClientFactory)17 ClientConfig (io.pravega.client.ClientConfig)16 Futures (io.pravega.common.concurrent.Futures)15 AtomicLong (java.util.concurrent.atomic.AtomicLong)15