Search in sources :

Example 6 with ScaleResponse

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());
}
Also used : HashMap(java.util.HashMap) ScaleResponse(io.pravega.controller.stream.api.grpc.v1.Controller.ScaleResponse) Controller(io.pravega.controller.stream.api.grpc.v1.Controller) SegmentRanges(io.pravega.controller.stream.api.grpc.v1.Controller.SegmentRanges) ScaleRequest(io.pravega.controller.stream.api.grpc.v1.Controller.ScaleRequest) Test(org.junit.Test)

Aggregations

ScaleResponse (io.pravega.controller.stream.api.grpc.v1.Controller.ScaleResponse)6 Test (org.junit.Test)5 ControllerEventStreamWriterMock (io.pravega.controller.mocks.ControllerEventStreamWriterMock)4 StartScaleResponse (io.pravega.controller.store.stream.StartScaleResponse)4 Controller (io.pravega.controller.stream.api.grpc.v1.Controller)4 UpdateStreamStatus (io.pravega.controller.stream.api.grpc.v1.Controller.UpdateStreamStatus)4 AbstractMap (java.util.AbstractMap)4 HashMap (java.util.HashMap)4 ScalingPolicy (io.pravega.client.stream.ScalingPolicy)3 StreamConfiguration (io.pravega.client.stream.StreamConfiguration)3 ScaleStreamStatus (io.pravega.controller.stream.api.grpc.v1.Controller.ScaleResponse.ScaleStreamStatus)3 ScaleOperationTask (io.pravega.controller.server.eventProcessor.requesthandlers.ScaleOperationTask)2 TaskExceptions (io.pravega.controller.server.eventProcessor.requesthandlers.TaskExceptions)2 TruncateStreamTask (io.pravega.controller.server.eventProcessor.requesthandlers.TruncateStreamTask)2 StoreException (io.pravega.controller.store.stream.StoreException)2 ArrayList (java.util.ArrayList)2 Lists (com.google.common.collect.Lists)1 NettyChannelBuilder (io.grpc.netty.NettyChannelBuilder)1 NettyServerBuilder (io.grpc.netty.NettyServerBuilder)1 ClientConfig (io.pravega.client.ClientConfig)1