Search in sources :

Example 26 with StreamCut

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

Example 27 with StreamCut

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

Example 28 with StreamCut

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());
}
Also used : ReaderGroupConfigResponse(io.pravega.controller.stream.api.grpc.v1.Controller.ReaderGroupConfigResponse) ReaderGroupConfiguration(io.pravega.controller.stream.api.grpc.v1.Controller.ReaderGroupConfiguration) ArgumentMatchers.anyLong(org.mockito.ArgumentMatchers.anyLong) UpdateSubscriberStatus(io.pravega.controller.stream.api.grpc.v1.Controller.UpdateSubscriberStatus) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test)

Aggregations

ReaderGroupConfig (io.pravega.client.stream.ReaderGroupConfig)22 Stream (io.pravega.client.stream.Stream)21 StreamCutImpl (io.pravega.client.stream.impl.StreamCutImpl)21 StreamCut (io.pravega.client.stream.StreamCut)20 Test (org.junit.Test)20 Segment (io.pravega.client.segment.impl.Segment)19 Controller (io.pravega.controller.stream.api.grpc.v1.Controller)18 ArgumentMatchers.anyLong (org.mockito.ArgumentMatchers.anyLong)17 StreamConfiguration (io.pravega.client.stream.StreamConfiguration)14 ScalingPolicy (io.pravega.client.stream.ScalingPolicy)13 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)13 UpdateSubscriberStatus (io.pravega.controller.stream.api.grpc.v1.Controller.UpdateSubscriberStatus)12 HashMap (java.util.HashMap)12 RetentionPolicy (io.pravega.client.stream.RetentionPolicy)10 StreamCutRecord (io.pravega.controller.store.stream.records.StreamCutRecord)10 StreamTruncationRecord (io.pravega.controller.store.stream.records.StreamTruncationRecord)10 ReaderGroupConfigResponse (io.pravega.controller.stream.api.grpc.v1.Controller.ReaderGroupConfigResponse)10 RGStreamCutRecord (io.pravega.shared.controller.event.RGStreamCutRecord)10 AtomicLong (java.util.concurrent.atomic.AtomicLong)10 ImmutableMap (com.google.common.collect.ImmutableMap)9