Search in sources :

Example 26 with StreamCut

use of io.pravega.client.stream.StreamCut in project pravega by pravega.

the class ReaderGroupImpl method getUnreadBytesIgnoringRange.

private long getUnreadBytesIgnoringRange(Map<Stream, Map<SegmentWithRange, Long>> positions, Map<Segment, Long> endSegments) {
    log.debug("Compute unread bytes from position {}", positions);
    long totalLength = 0;
    for (Entry<Stream, Map<SegmentWithRange, Long>> streamPosition : positions.entrySet()) {
        StreamCut fromStreamCut = new StreamCutImpl(streamPosition.getKey(), dropRange(streamPosition.getValue()));
        StreamCut toStreamCut = computeEndStreamCut(streamPosition.getKey(), endSegments);
        totalLength += Futures.getAndHandleExceptions(getRemainingBytes(streamPosition.getKey(), fromStreamCut, toStreamCut), RuntimeException::new).longValue();
    }
    return totalLength;
}
Also used : StreamCut(io.pravega.client.stream.StreamCut) Stream(io.pravega.client.stream.Stream) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) HashMap(java.util.HashMap)

Example 27 with StreamCut

use of io.pravega.client.stream.StreamCut in project pravega by pravega.

the class ReaderGroupManagerImplTest method testDeleteReaderGroupRGStreamDeleted.

@Test
public void testDeleteReaderGroupRGStreamDeleted() {
    ReaderGroupConfig config = ReaderGroupConfig.builder().startFromStreamCuts(ImmutableMap.<Stream, StreamCut>builder().put(createStream("s1"), createStreamCut("s1", 2)).put(createStream("s2"), createStreamCut("s2", 3)).build()).retentionType(ReaderGroupConfig.StreamDataRetention.MANUAL_RELEASE_AT_USER_STREAMCUT).build();
    when(clientFactory.createStateSynchronizer(anyString(), any(Serializer.class), any(Serializer.class), any(SynchronizerConfig.class))).thenThrow(new InvalidStreamException(""));
    when(controller.getReaderGroupConfig(SCOPE, GROUP_NAME)).thenReturn(CompletableFuture.completedFuture(config));
    when(controller.deleteReaderGroup(SCOPE, GROUP_NAME, config.getReaderGroupId())).thenReturn(CompletableFuture.completedFuture(true));
    // Delete ReaderGroup
    readerGroupManager.deleteReaderGroup(GROUP_NAME);
    verify(controller, times(1)).getReaderGroupConfig(SCOPE, GROUP_NAME);
    verify(controller, times(1)).deleteReaderGroup(SCOPE, GROUP_NAME, config.getReaderGroupId());
}
Also used : ReaderGroupConfig(io.pravega.client.stream.ReaderGroupConfig) StreamCut(io.pravega.client.stream.StreamCut) IntStream(java.util.stream.IntStream) Stream(io.pravega.client.stream.Stream) SynchronizerConfig(io.pravega.client.state.SynchronizerConfig) InvalidStreamException(io.pravega.client.stream.InvalidStreamException) Serializer(io.pravega.client.stream.Serializer) Test(org.junit.Test)

Example 28 with StreamCut

use of io.pravega.client.stream.StreamCut in project pravega by pravega.

the class ReaderGroupManagerImplTest method testDeleteRGMigrationConfigOnController.

@Test
@SuppressWarnings("unchecked")
public void testDeleteRGMigrationConfigOnController() {
    ReaderGroupConfig config = ReaderGroupConfig.builder().startFromStreamCuts(ImmutableMap.<Stream, StreamCut>builder().put(createStream("s1"), createStreamCut("s1", 2)).put(createStream("s2"), createStreamCut("s2", 3)).build()).retentionType(ReaderGroupConfig.StreamDataRetention.MANUAL_RELEASE_AT_USER_STREAMCUT).build();
    when(clientFactory.createStateSynchronizer(anyString(), any(Serializer.class), any(Serializer.class), any(SynchronizerConfig.class))).thenReturn(synchronizer);
    when(synchronizer.getState()).thenReturn(state);
    when(state.getConfig()).thenReturn(config);
    ReaderGroupConfig expectedConfig = ReaderGroupConfig.cloneConfig(config, UUID.randomUUID(), 0L);
    when(controller.getReaderGroupConfig(anyString(), anyString())).thenReturn(CompletableFuture.completedFuture(expectedConfig));
    when(controller.deleteReaderGroup(anyString(), anyString(), any(UUID.class))).thenReturn(CompletableFuture.completedFuture(true));
    // Delete ReaderGroup
    readerGroupManager.deleteReaderGroup(GROUP_NAME);
    verify(controller, times(1)).getReaderGroupConfig(SCOPE, GROUP_NAME);
    verify(controller, times(1)).deleteReaderGroup(SCOPE, GROUP_NAME, expectedConfig.getReaderGroupId());
}
Also used : ReaderGroupConfig(io.pravega.client.stream.ReaderGroupConfig) StreamCut(io.pravega.client.stream.StreamCut) IntStream(java.util.stream.IntStream) Stream(io.pravega.client.stream.Stream) UUID(java.util.UUID) SynchronizerConfig(io.pravega.client.state.SynchronizerConfig) Serializer(io.pravega.client.stream.Serializer) Test(org.junit.Test)

Example 29 with StreamCut

use of io.pravega.client.stream.StreamCut in project pravega by pravega.

the class ReaderGroupManagerImplTest method testDeleteReaderGroup.

@Test
public void testDeleteReaderGroup() {
    final UUID rgId = UUID.randomUUID();
    ReaderGroupConfig config = ReaderGroupConfig.builder().startFromStreamCuts(ImmutableMap.<Stream, StreamCut>builder().put(createStream("s1"), createStreamCut("s1", 2)).put(createStream("s2"), createStreamCut("s2", 3)).build()).retentionType(ReaderGroupConfig.StreamDataRetention.MANUAL_RELEASE_AT_USER_STREAMCUT).build();
    config = ReaderGroupConfig.cloneConfig(config, rgId, 0L);
    when(clientFactory.createStateSynchronizer(anyString(), any(Serializer.class), any(Serializer.class), any(SynchronizerConfig.class))).thenReturn(synchronizer);
    when(synchronizer.getState()).thenReturn(state);
    when(state.getConfig()).thenReturn(config);
    when(controller.deleteReaderGroup(SCOPE, GROUP_NAME, config.getReaderGroupId())).thenReturn(CompletableFuture.completedFuture(true));
    // Delete ReaderGroup
    readerGroupManager.deleteReaderGroup(GROUP_NAME);
    verify(controller, times(1)).deleteReaderGroup(SCOPE, GROUP_NAME, config.getReaderGroupId());
}
Also used : ReaderGroupConfig(io.pravega.client.stream.ReaderGroupConfig) StreamCut(io.pravega.client.stream.StreamCut) IntStream(java.util.stream.IntStream) Stream(io.pravega.client.stream.Stream) UUID(java.util.UUID) SynchronizerConfig(io.pravega.client.state.SynchronizerConfig) Serializer(io.pravega.client.stream.Serializer) Test(org.junit.Test)

Example 30 with StreamCut

use of io.pravega.client.stream.StreamCut in project pravega by pravega.

the class ReaderGroupManagerImplTest method testCreateReaderGroupWithSameConfig.

@Test
public void testCreateReaderGroupWithSameConfig() {
    ReaderGroupConfig config = ReaderGroupConfig.builder().startFromStreamCuts(ImmutableMap.<Stream, StreamCut>builder().put(createStream("s1"), createStreamCut("s1", 2)).put(createStream("s2"), createStreamCut("s2", 3)).build()).retentionType(ReaderGroupConfig.StreamDataRetention.MANUAL_RELEASE_AT_USER_STREAMCUT).build();
    ReaderGroupConfig expectedConfig = ReaderGroupConfig.cloneConfig(config, UUID.randomUUID(), 1L);
    when(controller.createReaderGroup(anyString(), anyString(), any(ReaderGroupConfig.class))).thenReturn(CompletableFuture.completedFuture(expectedConfig));
    // Create a ReaderGroup
    boolean created = readerGroupManager.createReaderGroup(GROUP_NAME, config);
    assertFalse(created);
    verify(clientFactory, never()).createStateSynchronizer(anyString(), any(Serializer.class), any(Serializer.class), any(SynchronizerConfig.class));
    verify(synchronizer, never()).initialize(any(InitialUpdate.class));
}
Also used : ReaderGroupConfig(io.pravega.client.stream.ReaderGroupConfig) StreamCut(io.pravega.client.stream.StreamCut) IntStream(java.util.stream.IntStream) Stream(io.pravega.client.stream.Stream) SynchronizerConfig(io.pravega.client.state.SynchronizerConfig) InitialUpdate(io.pravega.client.state.InitialUpdate) Serializer(io.pravega.client.stream.Serializer) 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