use of io.pravega.controller.stream.api.grpc.v1.Controller.ScaleResponse in project pravega by pravega.
the class ControllerServiceImplTest method scaleTest.
@Test
public void scaleTest() {
long createTime = System.currentTimeMillis();
createScopeAndStream(SCOPE1, STREAM1, ScalingPolicy.fixed(2));
// Scale segment 1 which has key range from 0.5 to 1.0 at time: createTime + 20.
Map<Double, Double> keyRanges = new HashMap<>(2);
keyRanges.put(0.5, 0.75);
keyRanges.put(0.75, 1.0);
final ScaleRequest scaleRequest = ScaleRequest.newBuilder().setStreamInfo(ModelHelper.createStreamInfo(SCOPE1, STREAM1)).setScaleTimestamp(createTime + 20).addSealedSegments(1).addNewKeyRanges(ScaleRequest.KeyRangeEntry.newBuilder().setStart(0.5).setEnd(0.75).build()).addNewKeyRanges(ScaleRequest.KeyRangeEntry.newBuilder().setStart(0.75).setEnd(1.0).build()).build();
ResultObserver<ScaleResponse> result2 = new ResultObserver<>();
this.controllerService.scale(scaleRequest, result2);
final ScaleResponse scaleResponse = result2.get();
Assert.assertEquals(ScaleResponse.ScaleStreamStatus.STARTED, scaleResponse.getStatus());
boolean done = false;
while (!done) {
final Controller.ScaleStatusRequest scalestatusRequest = Controller.ScaleStatusRequest.newBuilder().setStreamInfo(ModelHelper.createStreamInfo(SCOPE1, STREAM1)).setEpoch(scaleResponse.getEpoch()).build();
ResultObserver<Controller.ScaleStatusResponse> checkScaleResult = new ResultObserver<>();
this.controllerService.checkScale(scalestatusRequest, checkScaleResult);
final Controller.ScaleStatusResponse scalestatusResponse = checkScaleResult.get();
done = scalestatusResponse.getStatus().equals(Controller.ScaleStatusResponse.ScaleStatus.SUCCESS);
}
Assert.assertEquals(2, scaleResponse.getSegmentsCount());
ResultObserver<SegmentRanges> result3 = new ResultObserver<>();
this.controllerService.getCurrentSegments(ModelHelper.createStreamInfo(SCOPE1, STREAM1), result3);
final SegmentRanges segmentRanges = result3.get();
Assert.assertEquals(3, segmentRanges.getSegmentRangesCount());
Assert.assertEquals(0, segmentRanges.getSegmentRanges(0).getSegmentId().getSegmentNumber());
Assert.assertEquals(2, segmentRanges.getSegmentRanges(1).getSegmentId().getSegmentNumber());
Assert.assertEquals(3, segmentRanges.getSegmentRanges(2).getSegmentId().getSegmentNumber());
}
Aggregations