use of io.pravega.controller.stream.api.grpc.v1.Controller.StreamCut in project pravega by pravega.
the class ControllerServiceWithStreamTest method createReaderGroupTest.
@Test(timeout = 5000)
public void createReaderGroupTest() throws Exception {
String stream = "stream1";
final ScalingPolicy policy1 = ScalingPolicy.fixed(2);
final StreamConfiguration configuration1 = StreamConfiguration.builder().scalingPolicy(policy1).build();
// Start time when stream is created.
long start = System.currentTimeMillis();
// Create scope
Controller.CreateScopeStatus scopeStatus = consumer.createScope(SCOPE, 0L).join();
assertEquals(Controller.CreateScopeStatus.Status.SUCCESS, scopeStatus.getStatus());
// create stream
Controller.CreateStreamStatus streamStatus = consumer.createStream(SCOPE, stream, configuration1, start, 0L).get();
assertEquals(Controller.CreateStreamStatus.Status.SUCCESS, streamStatus.getStatus());
final Segment seg0 = new Segment(SCOPE, "stream1", 0L);
final Segment seg1 = new Segment(SCOPE, "stream1", 1L);
ImmutableMap<Segment, Long> startStreamCut = ImmutableMap.of(seg0, 10L, seg1, 10L);
Map<Stream, StreamCut> startSC = ImmutableMap.of(Stream.of(SCOPE, "stream1"), new StreamCutImpl(Stream.of(SCOPE, "stream1"), startStreamCut));
ImmutableMap<Segment, Long> endStreamCut = ImmutableMap.of(seg0, 200L, seg1, 300L);
Map<Stream, StreamCut> endSC = ImmutableMap.of(Stream.of(SCOPE, "stream1"), new StreamCutImpl(Stream.of(SCOPE, "stream1"), endStreamCut));
ReaderGroupConfig rgConfig = ReaderGroupConfig.builder().automaticCheckpointIntervalMillis(30000L).groupRefreshTimeMillis(20000L).maxOutstandingCheckpointRequest(2).retentionType(ReaderGroupConfig.StreamDataRetention.AUTOMATIC_RELEASE_AT_LAST_CHECKPOINT).startingStreamCuts(startSC).endingStreamCuts(endSC).build();
Controller.CreateReaderGroupResponse rgStatus = consumer.createReaderGroup(SCOPE, "rg1", rgConfig, System.currentTimeMillis(), 0L).get();
assertEquals(Controller.CreateReaderGroupResponse.Status.SUCCESS, rgStatus.getStatus());
// there should be 1 invocation
verify(streamStore, times(1)).createReaderGroup(anyString(), anyString(), any(), anyLong(), any(), any());
rgStatus = consumer.createReaderGroup(SCOPE, "rg1", rgConfig, System.currentTimeMillis(), 0L).get();
assertEquals(Controller.CreateReaderGroupResponse.Status.SUCCESS, rgStatus.getStatus());
// verify that create readergroup is not called again
verify(streamStore, times(1)).createReaderGroup(anyString(), anyString(), any(), anyLong(), any(), any());
}
use of io.pravega.controller.stream.api.grpc.v1.Controller.StreamCut in project pravega by pravega.
the class ControllerServiceImplTest method createReaderGroup.
protected void createReaderGroup(String scope, String stream, String rgName, UUID rgId) {
final Segment seg0 = new Segment(scope, stream, 0L);
final Segment seg1 = new Segment(scope, stream, 1L);
ImmutableMap<Segment, Long> startStreamCut = ImmutableMap.of(seg0, 10L, seg1, 10L);
Map<Stream, StreamCut> startSC = ImmutableMap.of(Stream.of(scope, stream), new StreamCutImpl(Stream.of(scope, stream), startStreamCut));
ImmutableMap<Segment, Long> endStreamCut = ImmutableMap.of(seg0, 200L, seg1, 300L);
Map<Stream, StreamCut> endSC = ImmutableMap.of(Stream.of(scope, stream), new StreamCutImpl(Stream.of(scope, stream), 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, rgId, 0L);
ResultObserver<CreateReaderGroupResponse> result = new ResultObserver<>();
this.controllerService.createReaderGroup(ModelHelper.decode(scope, rgName, config), result);
CreateReaderGroupResponse createRGStatus = result.get();
assertEquals("Create Reader Group", CreateReaderGroupResponse.Status.SUCCESS, createRGStatus.getStatus());
}
use of io.pravega.controller.stream.api.grpc.v1.Controller.StreamCut in project pravega by pravega.
the class ControllerServiceImplTest method updateSubscriberStreamCutTests.
@Test
public void updateSubscriberStreamCutTests() {
createScopeAndStream(SCOPE1, STREAM1, ScalingPolicy.fixed(2));
String rgName = "rg1";
createReaderGroup(SCOPE1, STREAM1, rgName, UUID.randomUUID());
ResultObserver<ReaderGroupConfigResponse> configResponse = new ResultObserver<>();
this.controllerService.getReaderGroupConfig(ModelHelper.createReaderGroupInfo(SCOPE1, rgName, "", 0L), configResponse);
ReaderGroupConfiguration rgConfig = configResponse.get().getConfig();
// Update StreamCut for non-existent stream.
ResultObserver<UpdateSubscriberStatus> result1 = new ResultObserver<>();
ImmutableMap<Long, Long> streamCut1 = ImmutableMap.of(0L, 10L, 1L, 10L);
this.controllerService.updateSubscriberStreamCut(ModelHelper.decode(SCOPE1, "unknownstream", rgName, UUID.fromString(rgConfig.getReaderGroupId()), rgConfig.getGeneration(), streamCut1), result1);
UpdateSubscriberStatus updateStatus = result1.get();
Assert.assertEquals(UpdateSubscriberStatus.Status.STREAM_NOT_FOUND, updateStatus.getStatus());
// Update StreamCut for non-existent subscriber.
ResultObserver<UpdateSubscriberStatus> result2 = new ResultObserver<>();
this.controllerService.updateSubscriberStreamCut(ModelHelper.decode(SCOPE1, STREAM1, "scope1/somesubscriber", UUID.fromString(rgConfig.getReaderGroupId()), rgConfig.getGeneration(), streamCut1), result2);
updateStatus = result2.get();
Assert.assertEquals(UpdateSubscriberStatus.Status.SUBSCRIBER_NOT_FOUND, updateStatus.getStatus());
ResultObserver<UpdateSubscriberStatus> result3 = new ResultObserver<>();
String subscriberName = NameUtils.getScopedReaderGroupName(SCOPE1, rgName);
this.controllerService.updateSubscriberStreamCut(ModelHelper.decode(SCOPE1, STREAM1, subscriberName, UUID.fromString(rgConfig.getReaderGroupId()), 1L, streamCut1), result3);
updateStatus = result3.get();
Assert.assertEquals(UpdateSubscriberStatus.Status.GENERATION_MISMATCH, updateStatus.getStatus());
ResultObserver<UpdateSubscriberStatus> result4 = new ResultObserver<>();
this.controllerService.updateSubscriberStreamCut(ModelHelper.decode(SCOPE1, STREAM1, subscriberName, UUID.fromString(rgConfig.getReaderGroupId()), rgConfig.getGeneration(), streamCut1), result4);
updateStatus = result4.get();
Assert.assertEquals(UpdateSubscriberStatus.Status.SUCCESS, updateStatus.getStatus());
ImmutableMap<Long, Long> streamCut2 = ImmutableMap.of(0L, 5L, 1L, 5L);
ResultObserver<UpdateSubscriberStatus> result5 = new ResultObserver<>();
this.controllerService.updateSubscriberStreamCut(ModelHelper.decode(SCOPE1, STREAM1, subscriberName, UUID.fromString(rgConfig.getReaderGroupId()), rgConfig.getGeneration(), streamCut2), result5);
updateStatus = result5.get();
Assert.assertEquals(UpdateSubscriberStatus.Status.STREAM_CUT_NOT_VALID, updateStatus.getStatus());
}
Aggregations