Search in sources :

Example 16 with StreamCutRecord

use of io.pravega.controller.store.stream.records.StreamCutRecord in project pravega by pravega.

the class StreamMetadataStoreTest method retentionSetTest.

@Test(timeout = 30000)
public void retentionSetTest() throws Exception {
    final String scope = "ScopeRetain";
    final String stream = "StreamRetain";
    final ScalingPolicy policy = ScalingPolicy.fixed(2);
    final RetentionPolicy retentionPolicy = RetentionPolicy.builder().retentionType(RetentionPolicy.RetentionType.TIME).retentionParam(Duration.ofDays(2).toMillis()).build();
    final StreamConfiguration configuration = StreamConfiguration.builder().scalingPolicy(policy).retentionPolicy(retentionPolicy).build();
    long start = System.currentTimeMillis();
    store.createScope(scope, null, executor).get();
    store.createStream(scope, stream, configuration, start, null, executor).get();
    store.setState(scope, stream, State.ACTIVE, null, executor).get();
    bucketStore.addStreamToBucketStore(BucketStore.ServiceType.RetentionService, scope, stream, executor).get();
    Set<String> streams = bucketStore.getStreamsForBucket(BucketStore.ServiceType.RetentionService, 0, executor).get();
    assertTrue(streams.contains(String.format("%s/%s", scope, stream)));
    Map<Long, Long> map1 = new HashMap<>();
    map1.put(0L, 0L);
    map1.put(1L, 0L);
    long recordingTime = System.currentTimeMillis();
    StreamCutRecord streamCut1 = new StreamCutRecord(recordingTime, Long.MIN_VALUE, ImmutableMap.copyOf(map1));
    store.addStreamCutToRetentionSet(scope, stream, streamCut1, null, executor).get();
    Map<Long, Long> map2 = new HashMap<>();
    map2.put(0L, 10L);
    map2.put(1L, 10L);
    StreamCutRecord streamCut2 = new StreamCutRecord(recordingTime + 10, Long.MIN_VALUE, ImmutableMap.copyOf(map2));
    store.addStreamCutToRetentionSet(scope, stream, streamCut2, null, executor).get();
    Map<Long, Long> map3 = new HashMap<>();
    map3.put(0L, 20L);
    map3.put(1L, 20L);
    StreamCutRecord streamCut3 = new StreamCutRecord(recordingTime + 20, Long.MIN_VALUE, ImmutableMap.copyOf(map3));
    store.addStreamCutToRetentionSet(scope, stream, streamCut3, null, executor).get();
    List<StreamCutRecord> list = store.getRetentionSet(scope, stream, null, executor).thenCompose(x -> Futures.allOfWithResults(x.getRetentionRecords().stream().map(y -> store.getStreamCutRecord(scope, stream, y, null, executor)).collect(Collectors.toList()))).join();
    assertTrue(list.contains(streamCut1));
    assertTrue(list.contains(streamCut2));
    assertTrue(list.contains(streamCut3));
    store.deleteStreamCutBefore(scope, stream, streamCut2.getReferenceRecord(), null, executor).get();
    list = store.getRetentionSet(scope, stream, null, executor).thenCompose(x -> Futures.allOfWithResults(x.getRetentionRecords().stream().map(y -> store.getStreamCutRecord(scope, stream, y, null, executor)).collect(Collectors.toList()))).join();
    assertTrue(!list.contains(streamCut1));
    assertTrue(!list.contains(streamCut2));
    assertTrue(list.contains(streamCut3));
    bucketStore.removeStreamFromBucketStore(BucketStore.ServiceType.RetentionService, scope, stream, executor).get();
    streams = bucketStore.getStreamsForBucket(BucketStore.ServiceType.RetentionService, 0, executor).get();
    assertTrue(!streams.contains(String.format("%s/%s", scope, stream)));
}
Also used : Arrays(java.util.Arrays) StreamCut(io.pravega.client.stream.StreamCut) ArgumentMatchers(org.mockito.ArgumentMatchers) StreamSegmentRecord(io.pravega.controller.store.stream.records.StreamSegmentRecord) AssertExtensions(io.pravega.test.common.AssertExtensions) Random(java.util.Random) StreamConfiguration(io.pravega.client.stream.StreamConfiguration) VersionedMetadata(io.pravega.controller.store.VersionedMetadata) Pair(org.apache.commons.lang3.tuple.Pair) Stream(io.pravega.client.stream.Stream) Duration(java.time.Duration) Map(java.util.Map) After(org.junit.After) Mockito.doAnswer(org.mockito.Mockito.doAnswer) Controller(io.pravega.controller.stream.api.grpc.v1.Controller) ReaderGroupConfig(io.pravega.client.stream.ReaderGroupConfig) DeleteScopeStatus(io.pravega.controller.stream.api.grpc.v1.Controller.DeleteScopeStatus) EpochTransitionRecord(io.pravega.controller.store.stream.records.EpochTransitionRecord) StreamCutReferenceRecord(io.pravega.controller.store.stream.records.StreamCutReferenceRecord) StreamTruncationRecord(io.pravega.controller.store.stream.records.StreamTruncationRecord) ImmutableMap(com.google.common.collect.ImmutableMap) Set(java.util.Set) CompletionException(java.util.concurrent.CompletionException) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) List(java.util.List) Assert.assertFalse(org.junit.Assert.assertFalse) Optional(java.util.Optional) HistoryTimeSeries(io.pravega.controller.store.stream.records.HistoryTimeSeries) Futures(io.pravega.common.concurrent.Futures) Segment(io.pravega.client.segment.impl.Segment) CommittingTransactionsRecord(io.pravega.controller.store.stream.records.CommittingTransactionsRecord) NameUtils.computeSegmentId(io.pravega.shared.NameUtils.computeSegmentId) RetentionPolicy(io.pravega.client.stream.RetentionPolicy) Exceptions(io.pravega.common.Exceptions) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) RetentionSet(io.pravega.controller.store.stream.records.RetentionSet) Mockito.spy(org.mockito.Mockito.spy) ArrayList(java.util.ArrayList) Strings(com.google.common.base.Strings) ReaderGroupConfigRecord(io.pravega.controller.store.stream.records.ReaderGroupConfigRecord) Lists(com.google.common.collect.Lists) StreamCutImpl(io.pravega.client.stream.impl.StreamCutImpl) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) RecordHelper(io.pravega.controller.store.stream.records.RecordHelper) SimpleEntry(java.util.AbstractMap.SimpleEntry) SealedSegmentsMapShard(io.pravega.controller.store.stream.records.SealedSegmentsMapShard) Before(org.junit.Before) NameUtils(io.pravega.shared.NameUtils) Assert.assertNotNull(org.junit.Assert.assertNotNull) WriterMark(io.pravega.controller.store.stream.records.WriterMark) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) StreamCutRecord(io.pravega.controller.store.stream.records.StreamCutRecord) TxnResource(io.pravega.controller.store.task.TxnResource) Assert.assertNotEquals(org.junit.Assert.assertNotEquals) ExecutionException(java.util.concurrent.ExecutionException) StreamConfigurationRecord(io.pravega.controller.store.stream.records.StreamConfigurationRecord) AbstractMap(java.util.AbstractMap) EpochRecord(io.pravega.controller.store.stream.records.EpochRecord) Assert.assertNull(org.junit.Assert.assertNull) Version(io.pravega.controller.store.Version) ExecutorServiceHelpers(io.pravega.common.concurrent.ExecutorServiceHelpers) Assert(org.junit.Assert) Collections(java.util.Collections) Mockito.reset(org.mockito.Mockito.reset) ScalingPolicy(io.pravega.client.stream.ScalingPolicy) Assert.assertEquals(org.junit.Assert.assertEquals) ScalingPolicy(io.pravega.client.stream.ScalingPolicy) HashMap(java.util.HashMap) StreamConfiguration(io.pravega.client.stream.StreamConfiguration) StreamCutRecord(io.pravega.controller.store.stream.records.StreamCutRecord) RetentionPolicy(io.pravega.client.stream.RetentionPolicy) Test(org.junit.Test)

Aggregations

StreamCutRecord (io.pravega.controller.store.stream.records.StreamCutRecord)16 RetentionPolicy (io.pravega.client.stream.RetentionPolicy)15 ScalingPolicy (io.pravega.client.stream.ScalingPolicy)15 StreamConfiguration (io.pravega.client.stream.StreamConfiguration)15 StreamTruncationRecord (io.pravega.controller.store.stream.records.StreamTruncationRecord)14 Test (org.junit.Test)14 ReaderGroupConfig (io.pravega.client.stream.ReaderGroupConfig)13 Stream (io.pravega.client.stream.Stream)13 HashMap (java.util.HashMap)13 RGStreamCutRecord (io.pravega.shared.controller.event.RGStreamCutRecord)12 AtomicLong (java.util.concurrent.atomic.AtomicLong)12 Segment (io.pravega.client.segment.impl.Segment)11 StreamCut (io.pravega.client.stream.StreamCut)11 StreamCutImpl (io.pravega.client.stream.impl.StreamCutImpl)11 ControllerEventStreamWriterMock (io.pravega.controller.mocks.ControllerEventStreamWriterMock)10 EventStreamWriterMock (io.pravega.controller.mocks.EventStreamWriterMock)10 StreamConfigurationRecord (io.pravega.controller.store.stream.records.StreamConfigurationRecord)10 Controller (io.pravega.controller.stream.api.grpc.v1.Controller)10 ArgumentMatchers.anyLong (org.mockito.ArgumentMatchers.anyLong)10 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)10