Search in sources :

Example 16 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 17 with StreamConfiguration

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

the class ControllerEventProcessorTest method setUp.

@Before
public void setUp() throws Exception {
    executor = Executors.newScheduledThreadPool(10);
    zkServer = new TestingServerStarter().start();
    zkServer.start();
    zkClient = CuratorFrameworkFactory.newClient(zkServer.getConnectString(), new RetryOneTime(2000));
    zkClient.start();
    streamStore = StreamStoreFactory.createZKStore(zkClient, executor);
    hostStore = HostStoreFactory.createInMemoryStore(HostMonitorConfigImpl.dummyConfig());
    segmentHelperMock = SegmentHelperMock.getSegmentHelperMock();
    streamMetadataTasks = new StreamMetadataTasks(streamStore, hostStore, TaskStoreFactory.createInMemoryStore(executor), segmentHelperMock, executor, "1", mock(ConnectionFactory.class), false, "");
    // region createStream
    final ScalingPolicy policy1 = ScalingPolicy.fixed(2);
    final StreamConfiguration configuration1 = StreamConfiguration.builder().scope(SCOPE).streamName(STREAM).scalingPolicy(policy1).build();
    streamStore.createScope(SCOPE).join();
    long start = System.currentTimeMillis();
    streamStore.createStream(SCOPE, STREAM, configuration1, start, null, executor).join();
    streamStore.setState(SCOPE, STREAM, State.ACTIVE, null, executor).join();
// endregion
}
Also used : ScalingPolicy(io.pravega.client.stream.ScalingPolicy) RetryOneTime(org.apache.curator.retry.RetryOneTime) TestingServerStarter(io.pravega.test.common.TestingServerStarter) StreamConfiguration(io.pravega.client.stream.StreamConfiguration) StreamMetadataTasks(io.pravega.controller.task.Stream.StreamMetadataTasks) Before(org.junit.Before)

Example 18 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 19 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 20 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)

Aggregations

StreamConfiguration (io.pravega.client.stream.StreamConfiguration)80 Test (org.junit.Test)67 ScalingPolicy (io.pravega.client.stream.ScalingPolicy)44 HashMap (java.util.HashMap)21 ArrayList (java.util.ArrayList)20 Controller (io.pravega.client.stream.impl.Controller)19 TestingServerStarter (io.pravega.test.common.TestingServerStarter)17 List (java.util.List)17 Cleanup (lombok.Cleanup)17 ConnectionFactoryImpl (io.pravega.client.netty.impl.ConnectionFactoryImpl)16 CompletableFuture (java.util.concurrent.CompletableFuture)16 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)16 TestingServer (org.apache.curator.test.TestingServer)16 Before (org.junit.Before)16 ClientFactory (io.pravega.client.ClientFactory)15 ClientFactoryImpl (io.pravega.client.stream.impl.ClientFactoryImpl)15 Executors (java.util.concurrent.Executors)15 After (org.junit.After)15 Assert.assertEquals (org.junit.Assert.assertEquals)15 Map (java.util.Map)14