Search in sources :

Example 1 with StreamConfiguration

use of io.pravega.client.stream.StreamConfiguration in project pravega by pravega.

the class ControllerServiceWithZKStreamTest method getSegmentsImmediatelyFollowingTest.

@Test(timeout = 5000)
public void getSegmentsImmediatelyFollowingTest() throws Exception {
    final ScalingPolicy policy1 = ScalingPolicy.fixed(2);
    final StreamConfiguration configuration1 = StreamConfiguration.builder().scope(SCOPE).streamName(STREAM).scalingPolicy(policy1).build();
    // Start time  when stream is created.
    long start = System.currentTimeMillis();
    // Create stream and scope
    Controller.CreateScopeStatus scopeStatus = consumer.createScope(SCOPE).join();
    assertEquals(Controller.CreateScopeStatus.Status.SUCCESS, scopeStatus.getStatus());
    Controller.CreateStreamStatus streamStatus = consumer.createStream(configuration1, start).get();
    assertEquals(Controller.CreateStreamStatus.Status.SUCCESS, streamStatus.getStatus());
    List<Controller.SegmentRange> currentSegments = consumer.getCurrentSegments(SCOPE, STREAM).get();
    assertEquals(2, currentSegments.size());
    // scale segment 1 which has key range from 0.5 to 1.0 at time: start+20
    Map<Double, Double> keyRanges = new HashMap<>(2);
    keyRanges.put(0.5, 0.75);
    keyRanges.put(0.75, 1.0);
    assertFalse(consumer.checkScale(SCOPE, STREAM, 0).get().getStatus().equals(Controller.ScaleStatusResponse.ScaleStatus.SUCCESS));
    Controller.ScaleResponse scaleStatus = consumer.scale(SCOPE, STREAM, Arrays.asList(1), keyRanges, start + 20).get();
    assertEquals(Controller.ScaleResponse.ScaleStreamStatus.STARTED, scaleStatus.getStatus());
    AtomicBoolean done = new AtomicBoolean(false);
    Futures.loop(() -> !done.get(), () -> consumer.checkScale(SCOPE, STREAM, scaleStatus.getEpoch()).thenAccept(x -> done.set(x.getStatus().equals(Controller.ScaleStatusResponse.ScaleStatus.SUCCESS))), executor).get();
    // After scale the current number of segments is 3;
    List<Controller.SegmentRange> currentSegmentsAfterScale = consumer.getCurrentSegments(SCOPE, STREAM).get();
    assertEquals(3, currentSegmentsAfterScale.size());
    Map<Controller.SegmentRange, List<Integer>> successorsOfSeg1 = consumer.getSegmentsImmediatelyFollowing(ModelHelper.createSegmentId(SCOPE, STREAM, 1)).get();
    // two segments follow segment 1
    assertEquals(2, successorsOfSeg1.size());
    Map<Controller.SegmentRange, List<Integer>> successorsOfSeg0 = consumer.getSegmentsImmediatelyFollowing(ModelHelper.createSegmentId(SCOPE, STREAM, 0)).get();
    // no segments follow segment 0
    assertEquals(0, successorsOfSeg0.size());
}
Also used : ScalingPolicy(io.pravega.client.stream.ScalingPolicy) HashMap(java.util.HashMap) Controller(io.pravega.controller.stream.api.grpc.v1.Controller) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) StreamConfiguration(io.pravega.client.stream.StreamConfiguration) List(java.util.List) Test(org.junit.Test)

Example 2 with StreamConfiguration

use of io.pravega.client.stream.StreamConfiguration in project pravega by pravega.

the class ControllerServiceImplTest method updateStreamTests.

@Test
public void updateStreamTests() {
    createScopeAndStream(SCOPE1, STREAM1, ScalingPolicy.fixed(2));
    final StreamConfiguration configuration2 = StreamConfiguration.builder().scope(SCOPE1).streamName(STREAM1).scalingPolicy(ScalingPolicy.fixed(3)).build();
    ResultObserver<UpdateStreamStatus> result2 = new ResultObserver<>();
    this.controllerService.updateStream(ModelHelper.decode(configuration2), result2);
    UpdateStreamStatus updateStreamStatus = result2.get();
    Assert.assertEquals(updateStreamStatus.getStatus(), UpdateStreamStatus.Status.SUCCESS);
    // Update stream for non-existent stream.
    ResultObserver<UpdateStreamStatus> result3 = new ResultObserver<>();
    final StreamConfiguration configuration3 = StreamConfiguration.builder().scope(SCOPE1).streamName("unknownstream").scalingPolicy(ScalingPolicy.fixed(1)).build();
    this.controllerService.updateStream(ModelHelper.decode(configuration3), result3);
    updateStreamStatus = result3.get();
    Assert.assertEquals(UpdateStreamStatus.Status.STREAM_NOT_FOUND, updateStreamStatus.getStatus());
}
Also used : UpdateStreamStatus(io.pravega.controller.stream.api.grpc.v1.Controller.UpdateStreamStatus) StreamConfiguration(io.pravega.client.stream.StreamConfiguration) Test(org.junit.Test)

Example 3 with StreamConfiguration

use of io.pravega.client.stream.StreamConfiguration in project pravega by pravega.

the class ControllerServiceImplTest method createScopeAndStream.

protected void createScopeAndStream(String scope, String stream, ScalingPolicy scalingPolicy) {
    final StreamConfiguration configuration1 = StreamConfiguration.builder().scope(scope).streamName(stream).scalingPolicy(scalingPolicy).build();
    // Create a test scope.
    ResultObserver<CreateScopeStatus> result1 = new ResultObserver<>();
    this.controllerService.createScope(ModelHelper.createScopeInfo(scope), result1);
    CreateScopeStatus createScopeStatus = result1.get();
    assertEquals("Create Scope", CreateScopeStatus.Status.SUCCESS, createScopeStatus.getStatus());
    // Create a test stream.
    ResultObserver<CreateStreamStatus> result2 = new ResultObserver<>();
    this.controllerService.createStream(ModelHelper.decode(configuration1), result2);
    CreateStreamStatus createStreamStatus = result2.get();
    assertEquals("Create stream", CreateStreamStatus.Status.SUCCESS, createStreamStatus.getStatus());
}
Also used : CreateStreamStatus(io.pravega.controller.stream.api.grpc.v1.Controller.CreateStreamStatus) CreateScopeStatus(io.pravega.controller.stream.api.grpc.v1.Controller.CreateScopeStatus) StreamConfiguration(io.pravega.client.stream.StreamConfiguration)

Example 4 with StreamConfiguration

use of io.pravega.client.stream.StreamConfiguration in project pravega by pravega.

the class ControllerServiceImplTest method truncateStreamTests.

@Test
public void truncateStreamTests() {
    CreateScopeStatus createScopeStatus;
    CreateStreamStatus createStreamStatus;
    final StreamConfiguration configuration1 = StreamConfiguration.builder().scope(SCOPE1).streamName(STREAM1).scalingPolicy(ScalingPolicy.fixed(4)).build();
    // Create a test scope.
    ResultObserver<CreateScopeStatus> result1 = new ResultObserver<>();
    this.controllerService.createScope(ModelHelper.createScopeInfo(SCOPE1), result1);
    createScopeStatus = result1.get();
    assertEquals("Create Scope", CreateScopeStatus.Status.SUCCESS, createScopeStatus.getStatus());
    // Create a test stream.
    ResultObserver<CreateStreamStatus> result2 = new ResultObserver<>();
    this.controllerService.createStream(ModelHelper.decode(configuration1), result2);
    createStreamStatus = result2.get();
    assertEquals("Create stream", CreateStreamStatus.Status.SUCCESS, createStreamStatus.getStatus());
    // Truncate the stream
    ResultObserver<UpdateStreamStatus> result3 = new ResultObserver<>();
    this.controllerService.truncateStream(Controller.StreamCut.newBuilder().setStreamInfo(StreamInfo.newBuilder().setScope(SCOPE1).setStream(STREAM1).build()).putCut(0, 0).build(), result3);
    UpdateStreamStatus truncateStreamStatus = result3.get();
}
Also used : UpdateStreamStatus(io.pravega.controller.stream.api.grpc.v1.Controller.UpdateStreamStatus) CreateStreamStatus(io.pravega.controller.stream.api.grpc.v1.Controller.CreateStreamStatus) CreateScopeStatus(io.pravega.controller.stream.api.grpc.v1.Controller.CreateScopeStatus) StreamConfiguration(io.pravega.client.stream.StreamConfiguration) Test(org.junit.Test)

Example 5 with StreamConfiguration

use of io.pravega.client.stream.StreamConfiguration in project pravega by pravega.

the class ModelHelperTest method encodeStreamConfig.

@Test
public void encodeStreamConfig() {
    StreamConfiguration config = ModelHelper.encode(ModelHelper.decode(StreamConfiguration.builder().scope("scope").streamName("test").scalingPolicy(ScalingPolicy.byEventRate(100, 2, 3)).retentionPolicy(RetentionPolicy.bySizeBytes(1000L)).build()));
    assertEquals("test", config.getStreamName());
    ScalingPolicy policy = config.getScalingPolicy();
    assertEquals(ScalingPolicy.ScaleType.BY_RATE_IN_EVENTS_PER_SEC, policy.getScaleType());
    assertEquals(100L, policy.getTargetRate());
    assertEquals(2, policy.getScaleFactor());
    assertEquals(3, policy.getMinNumSegments());
    RetentionPolicy retentionPolicy = config.getRetentionPolicy();
    assertEquals(RetentionPolicy.RetentionType.SIZE, retentionPolicy.getRetentionType());
    assertEquals(1000L, (long) retentionPolicy.getRetentionParam());
}
Also used : ScalingPolicy(io.pravega.client.stream.ScalingPolicy) StreamConfiguration(io.pravega.client.stream.StreamConfiguration) RetentionPolicy(io.pravega.client.stream.RetentionPolicy) Test(org.junit.Test)

Aggregations

StreamConfiguration (io.pravega.client.stream.StreamConfiguration)251 Test (org.junit.Test)207 ScalingPolicy (io.pravega.client.stream.ScalingPolicy)112 Cleanup (lombok.Cleanup)86 HashMap (java.util.HashMap)64 Stream (io.pravega.client.stream.Stream)63 ArrayList (java.util.ArrayList)60 CompletableFuture (java.util.concurrent.CompletableFuture)60 SocketConnectionFactoryImpl (io.pravega.client.connection.impl.SocketConnectionFactoryImpl)54 List (java.util.List)52 ReaderGroupManager (io.pravega.client.admin.ReaderGroupManager)51 ConnectionFactory (io.pravega.client.connection.impl.ConnectionFactory)49 UUID (java.util.UUID)48 ClientFactoryImpl (io.pravega.client.stream.impl.ClientFactoryImpl)47 Map (java.util.Map)46 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)45 ReaderGroupConfig (io.pravega.client.stream.ReaderGroupConfig)44 ClientConfig (io.pravega.client.ClientConfig)42 ReaderGroupManagerImpl (io.pravega.client.admin.impl.ReaderGroupManagerImpl)41 Controller (io.pravega.controller.stream.api.grpc.v1.Controller)40