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());
}
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
}
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());
}
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());
}
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();
}
Aggregations