Search in sources :

Example 51 with StreamCut

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);
}
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 52 with StreamCut

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);
}
Also used : StreamCut(io.pravega.client.stream.StreamCut) ReaderGroupStateInit(io.pravega.client.stream.impl.ReaderGroupState.ReaderGroupStateInit) SneakyThrows(lombok.SneakyThrows) UpdatingConfig(io.pravega.client.stream.impl.ReaderGroupState.UpdatingConfig) ReaderGroup(io.pravega.client.stream.ReaderGroup) ReaderGroupMetrics(io.pravega.client.stream.ReaderGroupMetrics) EndOfDataNotification(io.pravega.client.stream.notifications.EndOfDataNotification) Position(io.pravega.client.stream.Position) Stream(io.pravega.client.stream.Stream) AccessOperation(io.pravega.shared.security.auth.AccessOperation) Duration(java.time.Duration) Map(java.util.Map) Checkpoint(io.pravega.client.stream.Checkpoint) Futures.getThrowingException(io.pravega.common.concurrent.Futures.getThrowingException) ReaderGroupConfig(io.pravega.client.stream.ReaderGroupConfig) ImmutableMap(com.google.common.collect.ImmutableMap) Set(java.util.Set) DelegationTokenProviderFactory(io.pravega.client.security.auth.DelegationTokenProviderFactory) UUID(java.util.UUID) InitialUpdate(io.pravega.client.state.InitialUpdate) Collectors(java.util.stream.Collectors) SegmentMetadataClient(io.pravega.client.segment.impl.SegmentMetadataClient) NotifierFactory(io.pravega.client.stream.notifications.NotifierFactory) Base64(java.util.Base64) List(java.util.List) Slf4j(lombok.extern.slf4j.Slf4j) Observable(io.pravega.client.stream.notifications.Observable) Entry(java.util.Map.Entry) Optional(java.util.Optional) Controller(io.pravega.client.control.impl.Controller) Futures(io.pravega.common.concurrent.Futures) ClearCheckpointsBefore(io.pravega.client.stream.impl.ReaderGroupState.ClearCheckpointsBefore) StateSynchronizer(io.pravega.client.state.StateSynchronizer) Segment(io.pravega.client.segment.impl.Segment) NotificationSystem(io.pravega.client.stream.notifications.NotificationSystem) Exceptions(io.pravega.common.Exceptions) SegmentMetadataClientFactoryImpl(io.pravega.client.segment.impl.SegmentMetadataClientFactoryImpl) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) ReaderGroupConfigRejectedException(io.pravega.client.control.impl.ReaderGroupConfigRejectedException) SegmentMetadataClientFactory(io.pravega.client.segment.impl.SegmentMetadataClientFactory) ArrayList(java.util.ArrayList) Update(io.pravega.client.state.Update) SegmentNotification(io.pravega.client.stream.notifications.SegmentNotification) CreateCheckpoint(io.pravega.client.stream.impl.ReaderGroupState.CreateCheckpoint) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) SynchronizerConfig(io.pravega.client.state.SynchronizerConfig) Serializer(io.pravega.client.stream.Serializer) NameUtils(io.pravega.shared.NameUtils) Futures.getAndHandleExceptions(io.pravega.common.concurrent.Futures.getAndHandleExceptions) ConnectionPool(io.pravega.client.connection.impl.ConnectionPool) lombok.val(lombok.val) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) Futures.allOfWithResults(io.pravega.common.concurrent.Futures.allOfWithResults) DelegationTokenProvider(io.pravega.client.security.auth.DelegationTokenProvider) SynchronizerClientFactory(io.pravega.client.SynchronizerClientFactory) ReaderSegmentDistribution(io.pravega.client.stream.ReaderSegmentDistribution) Data(lombok.Data) InvalidStreamException(io.pravega.client.stream.InvalidStreamException) Preconditions(com.google.common.base.Preconditions) VisibleForTesting(com.google.common.annotations.VisibleForTesting) Collections(java.util.Collections) CompletableFuture(java.util.concurrent.CompletableFuture) StreamCut(io.pravega.client.stream.StreamCut) ArrayList(java.util.ArrayList) Stream(io.pravega.client.stream.Stream) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) HashMap(java.util.HashMap)

Example 53 with StreamCut

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;
}
Also used : StreamCut(io.pravega.client.stream.StreamCut) HashMap(java.util.HashMap) Stream(io.pravega.client.stream.Stream) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) HashMap(java.util.HashMap) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 54 with StreamCut

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());
}
Also used : StreamCut(io.pravega.client.stream.StreamCut) SubscriberStreamCut(io.pravega.controller.stream.api.grpc.v1.Controller.SubscriberStreamCut) StreamCutImpl(io.pravega.client.stream.impl.StreamCutImpl) StreamSegmentSuccessors(io.pravega.client.stream.impl.StreamSegmentSuccessors) StreamImpl(io.pravega.client.stream.impl.StreamImpl) Test(org.junit.Test)

Example 55 with StreamCut

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);
}
Also used : ReaderGroupConfig(io.pravega.client.stream.ReaderGroupConfig) StreamCut(io.pravega.client.stream.StreamCut) SubscriberStreamCut(io.pravega.controller.stream.api.grpc.v1.Controller.SubscriberStreamCut) StreamCutImpl(io.pravega.client.stream.impl.StreamCutImpl) ArgumentMatchers.anyLong(org.mockito.ArgumentMatchers.anyLong) Stream(io.pravega.client.stream.Stream) Segment(io.pravega.client.segment.impl.Segment) Test(org.junit.Test)

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