Search in sources :

Example 36 with StreamCutImpl

use of io.pravega.client.stream.impl.StreamCutImpl in project pravega by pravega.

the class ControllerImplTest method testUpdateReaderGroup.

@Test
public void testUpdateReaderGroup() throws Exception {
    CompletableFuture<Long> updateRGStatus;
    final Segment seg0 = new Segment("scope1", "stream1", 0L);
    final Segment seg1 = new Segment("scope1", "stream1", 1L);
    ImmutableMap<Segment, Long> startStreamCut = ImmutableMap.of(seg0, 10L, seg1, 10L);
    Map<Stream, StreamCut> startSC = ImmutableMap.of(Stream.of("scope1", "stream1"), new StreamCutImpl(Stream.of("scope1", "stream1"), startStreamCut));
    ImmutableMap<Segment, Long> endStreamCut = ImmutableMap.of(seg0, 200L, seg1, 300L);
    Map<Stream, StreamCut> endSC = ImmutableMap.of(Stream.of("scope1", "stream1"), new StreamCutImpl(Stream.of("scope1", "stream1"), 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, UUID.randomUUID(), 0L);
    updateRGStatus = controllerClient.updateReaderGroup("scope1", "rg1", config);
    assertNotNull(updateRGStatus.get());
    updateRGStatus = controllerClient.updateReaderGroup("scope1", "rg2", config);
    AssertExtensions.assertFutureThrows("Server should throw exception", updateRGStatus, Throwable -> true);
    updateRGStatus = controllerClient.updateReaderGroup("scope1", "rg3", config);
    AssertExtensions.assertFutureThrows("Server should throw exception", updateRGStatus, throwable -> throwable instanceof IllegalArgumentException);
    updateRGStatus = controllerClient.updateReaderGroup("scope1", "rg4", config);
    AssertExtensions.assertFutureThrows("Server should throw exception", updateRGStatus, throwable -> throwable instanceof ReaderGroupConfigRejectedException);
}
Also used : ReaderGroupConfig(io.pravega.client.stream.ReaderGroupConfig) StreamCut(io.pravega.client.stream.StreamCut) SubscriberStreamCut(io.pravega.controller.stream.api.grpc.v1.Controller.SubscriberStreamCut) StreamCutImpl(io.pravega.client.stream.impl.StreamCutImpl) ArgumentMatchers.anyLong(org.mockito.ArgumentMatchers.anyLong) Stream(io.pravega.client.stream.Stream) Segment(io.pravega.client.segment.impl.Segment) Test(org.junit.Test)

Example 37 with StreamCutImpl

use of io.pravega.client.stream.impl.StreamCutImpl in project pravega by pravega.

the class ModelHelperTest method testReaderGroupConfig.

@Test
public void testReaderGroupConfig() {
    String scope = "test";
    String stream = "test";
    ImmutableMap<Segment, Long> positions = ImmutableMap.<Segment, Long>builder().put(new Segment(scope, stream, 0), 90L).build();
    StreamCut sc = new StreamCutImpl(Stream.of(scope, stream), positions);
    ReaderGroupConfig config = ReaderGroupConfig.builder().disableAutomaticCheckpoints().stream(getScopedStreamName(scope, stream), StreamCut.UNBOUNDED, sc).build();
    Controller.ReaderGroupConfiguration decodedConfig = decode(scope, "group", config);
    assertEquals(config, ModelHelper.encode(decodedConfig));
}
Also used : ReaderGroupConfig(io.pravega.client.stream.ReaderGroupConfig) StreamCut(io.pravega.client.stream.StreamCut) StreamCutImpl(io.pravega.client.stream.impl.StreamCutImpl) Controller(io.pravega.controller.stream.api.grpc.v1.Controller) Segment(io.pravega.client.segment.impl.Segment) Test(org.junit.Test)

Example 38 with StreamCutImpl

use of io.pravega.client.stream.impl.StreamCutImpl in project pravega by pravega.

the class LocalControllerTest method testCreateReaderGroup.

@Test(timeout = 10000)
public void testCreateReaderGroup() throws ExecutionException, InterruptedException {
    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();
    final ReaderGroupConfig config = ReaderGroupConfig.cloneConfig(rgConfig, UUID.randomUUID(), 0L);
    StreamMetadataTasks mockStreamMetaTasks = mock(StreamMetadataTasks.class);
    final String scope = "scope";
    final String rgName = "subscriber";
    when(this.mockControllerService.getStreamMetadataTasks()).thenReturn(mockStreamMetaTasks);
    Controller.ReaderGroupConfiguration expectedConfig = ModelHelper.decode(scope, rgName, config);
    when(mockStreamMetaTasks.createReaderGroupInternal(anyString(), any(), any(), anyLong(), anyLong())).thenReturn(CompletableFuture.completedFuture(Controller.CreateReaderGroupResponse.newBuilder().setConfig(expectedConfig).setStatus(Controller.CreateReaderGroupResponse.Status.SUCCESS).build()));
    ReaderGroupConfig responseCfg = this.testController.createReaderGroup(scope, rgName, config).join();
    Assert.assertEquals(UUID.fromString(expectedConfig.getReaderGroupId()), responseCfg.getReaderGroupId());
    Assert.assertEquals(expectedConfig.getRetentionType(), responseCfg.getRetentionType().ordinal());
    Assert.assertEquals(expectedConfig.getGeneration(), responseCfg.getGeneration());
    Assert.assertEquals(expectedConfig.getGroupRefreshTimeMillis(), responseCfg.getGroupRefreshTimeMillis());
    Assert.assertEquals(expectedConfig.getAutomaticCheckpointIntervalMillis(), responseCfg.getAutomaticCheckpointIntervalMillis());
    Assert.assertEquals(expectedConfig.getMaxOutstandingCheckpointRequest(), responseCfg.getMaxOutstandingCheckpointRequest());
    when(mockStreamMetaTasks.createReaderGroupInternal(anyString(), any(), any(), anyLong(), anyLong())).thenReturn(CompletableFuture.completedFuture(Controller.CreateReaderGroupResponse.newBuilder().setConfig(expectedConfig).setStatus(Controller.CreateReaderGroupResponse.Status.FAILURE).build()));
    assertThrows("Expected ControllerFailureException", () -> this.testController.createReaderGroup("scope", "subscriber", config).join(), ex -> ex instanceof ControllerFailureException);
    when(mockStreamMetaTasks.createReaderGroupInternal(anyString(), any(), any(), anyLong(), anyLong())).thenReturn(CompletableFuture.completedFuture(Controller.CreateReaderGroupResponse.newBuilder().setConfig(expectedConfig).setStatus(Controller.CreateReaderGroupResponse.Status.INVALID_RG_NAME).build()));
    assertThrows("Expected IllegalArgumentException", () -> this.testController.createReaderGroup("scope", "subscriber", config).join(), ex -> ex instanceof IllegalArgumentException);
    when(mockStreamMetaTasks.createReaderGroupInternal(anyString(), any(), any(), anyLong(), anyLong())).thenReturn(CompletableFuture.completedFuture(Controller.CreateReaderGroupResponse.newBuilder().setConfig(expectedConfig).setStatus(Controller.CreateReaderGroupResponse.Status.SCOPE_NOT_FOUND).build()));
    assertThrows("Expected IllegalArgumentException", () -> this.testController.createReaderGroup("scope", "subscriber", config).join(), ex -> ex instanceof IllegalArgumentException);
    when(mockStreamMetaTasks.createReaderGroupInternal(anyString(), any(), any(), anyLong(), anyLong())).thenReturn(CompletableFuture.completedFuture(Controller.CreateReaderGroupResponse.newBuilder().setStatusValue(-1).build()));
    assertThrows("Expected ControllerFailureException", () -> this.testController.createReaderGroup("scope", "subscriber", config).join(), ex -> ex instanceof ControllerFailureException);
}
Also used : ReaderGroupConfig(io.pravega.client.stream.ReaderGroupConfig) 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) ArgumentMatchers.anyLong(org.mockito.ArgumentMatchers.anyLong) ControllerFailureException(io.pravega.client.control.impl.ControllerFailureException) Stream(io.pravega.client.stream.Stream) StreamMetadataTasks(io.pravega.controller.task.Stream.StreamMetadataTasks) Test(org.junit.Test)

Example 39 with StreamCutImpl

use of io.pravega.client.stream.impl.StreamCutImpl in project pravega by pravega.

the class LocalControllerTest method testGetReaderGroupConfig.

@Test(timeout = 10000)
public void testGetReaderGroupConfig() throws ExecutionException, InterruptedException {
    final String scope = "scope";
    final String streamName = "stream1";
    final Segment seg0 = new Segment(scope, streamName, 0L);
    final Segment seg1 = new Segment(scope, streamName, 1L);
    ImmutableMap<Segment, Long> startStreamCut = ImmutableMap.of(seg0, 10L, seg1, 10L);
    Map<Stream, StreamCut> startSC = ImmutableMap.of(Stream.of(scope, streamName), new StreamCutImpl(Stream.of(scope, streamName), startStreamCut));
    ImmutableMap<Segment, Long> endStreamCut = ImmutableMap.of(seg0, 200L, seg1, 300L);
    Map<Stream, StreamCut> endSC = ImmutableMap.of(Stream.of(scope, streamName), new StreamCutImpl(Stream.of(scope, streamName), endStreamCut));
    ReaderGroupConfig rgConfig = ReaderGroupConfig.builder().automaticCheckpointIntervalMillis(30000L).groupRefreshTimeMillis(20000L).maxOutstandingCheckpointRequest(2).retentionType(ReaderGroupConfig.StreamDataRetention.AUTOMATIC_RELEASE_AT_LAST_CHECKPOINT).startingStreamCuts(startSC).endingStreamCuts(endSC).build();
    ReaderGroupConfig config = ReaderGroupConfig.cloneConfig(rgConfig, UUID.randomUUID(), 0L);
    final String rgName = "subscriber";
    Controller.ReaderGroupConfiguration expectedConfig = ModelHelper.decode(scope, rgName, config);
    when(this.mockControllerService.getReaderGroupConfig(anyString(), anyString(), anyLong())).thenReturn(CompletableFuture.completedFuture(Controller.ReaderGroupConfigResponse.newBuilder().setStatus(Controller.ReaderGroupConfigResponse.Status.SUCCESS).setConfig(expectedConfig).build()));
    Assert.assertEquals(this.testController.getReaderGroupConfig(scope, rgName).join().getAutomaticCheckpointIntervalMillis(), config.getAutomaticCheckpointIntervalMillis());
    when(this.mockControllerService.getReaderGroupConfig(anyString(), anyString(), anyLong())).thenReturn(CompletableFuture.completedFuture(Controller.ReaderGroupConfigResponse.newBuilder().setStatus(Controller.ReaderGroupConfigResponse.Status.FAILURE).setConfig(Controller.ReaderGroupConfiguration.getDefaultInstance()).build()));
    assertThrows("Expected ControllerFailureException", () -> this.testController.getReaderGroupConfig("scope", "subscriber").join(), ex -> ex instanceof ControllerFailureException);
    when(this.mockControllerService.getReaderGroupConfig(anyString(), anyString(), anyLong())).thenReturn(CompletableFuture.completedFuture(Controller.ReaderGroupConfigResponse.newBuilder().setStatus(Controller.ReaderGroupConfigResponse.Status.RG_NOT_FOUND).setConfig(Controller.ReaderGroupConfiguration.getDefaultInstance()).build()));
    assertThrows("Expected IllegalArgumentException", () -> this.testController.getReaderGroupConfig("scope", "subscriber").join(), ex -> ex instanceof IllegalArgumentException);
    when(this.mockControllerService.getReaderGroupConfig(eq("scope"), eq("subscriber"), anyLong())).thenReturn(CompletableFuture.completedFuture(Controller.ReaderGroupConfigResponse.newBuilder().setStatusValue(-1).build()));
    assertThrows("Expected ControllerFailureException", () -> this.testController.getReaderGroupConfig("scope", "subscriber").join(), ex -> ex instanceof ControllerFailureException);
}
Also used : ReaderGroupConfig(io.pravega.client.stream.ReaderGroupConfig) 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) ArgumentMatchers.anyLong(org.mockito.ArgumentMatchers.anyLong) ControllerFailureException(io.pravega.client.control.impl.ControllerFailureException) Stream(io.pravega.client.stream.Stream) Test(org.junit.Test)

Example 40 with StreamCutImpl

use of io.pravega.client.stream.impl.StreamCutImpl in project pravega by pravega.

the class LocalControllerTest method testGetSegmentsBetween.

@Test(timeout = 10000)
public void testGetSegmentsBetween() throws ExecutionException, InterruptedException {
    List<StreamSegmentRecord> list = new ArrayList<>();
    when(this.mockControllerService.getSegmentsBetweenStreamCuts(any(), anyLong())).thenReturn(CompletableFuture.completedFuture(list));
    Assert.assertTrue(Futures.await(this.testController.getSegments(new StreamCutImpl(new StreamImpl("scope", "stream"), Collections.emptyMap()), new StreamCutImpl(new StreamImpl("scope", "stream"), Collections.emptyMap()))));
}
Also used : StreamSegmentRecord(io.pravega.controller.store.stream.records.StreamSegmentRecord) StreamCutImpl(io.pravega.client.stream.impl.StreamCutImpl) StreamImpl(io.pravega.client.stream.impl.StreamImpl) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Aggregations

StreamCutImpl (io.pravega.client.stream.impl.StreamCutImpl)41 Segment (io.pravega.client.segment.impl.Segment)37 StreamCut (io.pravega.client.stream.StreamCut)34 Test (org.junit.Test)33 Stream (io.pravega.client.stream.Stream)28 ReaderGroupConfig (io.pravega.client.stream.ReaderGroupConfig)27 StreamConfiguration (io.pravega.client.stream.StreamConfiguration)17 ArgumentMatchers.anyLong (org.mockito.ArgumentMatchers.anyLong)17 ScalingPolicy (io.pravega.client.stream.ScalingPolicy)15 HashMap (java.util.HashMap)15 AtomicLong (java.util.concurrent.atomic.AtomicLong)12 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)12 Controller (io.pravega.controller.stream.api.grpc.v1.Controller)11 Map (java.util.Map)10 Cleanup (lombok.Cleanup)10 StreamImpl (io.pravega.client.stream.impl.StreamImpl)8 ImmutableMap (com.google.common.collect.ImmutableMap)7 EventStreamClientFactory (io.pravega.client.EventStreamClientFactory)7 ReaderGroupManager (io.pravega.client.admin.ReaderGroupManager)7 ClientConfig (io.pravega.client.ClientConfig)6