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)));
}
Aggregations