Search in sources :

Example 11 with ScaleResponse

use of io.pravega.controller.stream.api.grpc.v1.Controller.ScaleResponse in project pravega by pravega.

the class StreamMetadataTasksTest method sealStreamTest.

@Test(timeout = 30000)
public void sealStreamTest() throws Exception {
    assertNotEquals(0, consumer.getCurrentSegments(SCOPE, stream1, 0L).get().size());
    WriterMock requestEventWriter = new WriterMock(streamMetadataTasks, executor);
    streamMetadataTasks.setRequestEventWriter(requestEventWriter);
    SealStreamTask sealStreamTask = new SealStreamTask(streamMetadataTasks, streamTransactionMetadataTasks, streamStorePartialMock, executor);
    AssertExtensions.assertFutureThrows("Stream not sealed", sealStreamTask.execute(new SealStreamEvent(SCOPE, stream1, 0L)), e -> Exceptions.unwrap(e) instanceof IllegalStateException);
    // seal a stream.
    CompletableFuture<UpdateStreamStatus.Status> sealOperationResult = streamMetadataTasks.sealStream(SCOPE, stream1, 0L);
    assertTrue(Futures.await(processEvent(requestEventWriter)));
    assertEquals(UpdateStreamStatus.Status.SUCCESS, sealOperationResult.get());
    // a sealed stream should have zero active/current segments
    assertEquals(0, consumer.getCurrentSegments(SCOPE, stream1, 0L).get().size());
    assertTrue(streamStorePartialMock.isSealed(SCOPE, stream1, null, executor).get());
    // reseal a sealed stream.
    assertEquals(UpdateStreamStatus.Status.SUCCESS, streamMetadataTasks.sealStream(SCOPE, stream1, 0L).get());
    assertTrue(Futures.await(processEvent(requestEventWriter)));
    // scale operation on the sealed stream.
    AbstractMap.SimpleEntry<Double, Double> segment3 = new AbstractMap.SimpleEntry<>(0.0, 0.2);
    AbstractMap.SimpleEntry<Double, Double> segment4 = new AbstractMap.SimpleEntry<>(0.2, 0.4);
    AbstractMap.SimpleEntry<Double, Double> segment5 = new AbstractMap.SimpleEntry<>(0.4, 0.5);
    ScaleResponse scaleOpResult = streamMetadataTasks.manualScale(SCOPE, stream1, Collections.singletonList(0L), Arrays.asList(segment3, segment4, segment5), 30, 0L).get();
    // scaling operation fails once a stream is sealed.
    assertEquals(ScaleStreamStatus.FAILURE, scaleOpResult.getStatus());
    AssertExtensions.assertFutureThrows("Scale should not be allowed as stream is already sealed", streamStorePartialMock.submitScale(SCOPE, stream1, Collections.singletonList(0L), Arrays.asList(segment3, segment4, segment5), 30, null, null, executor), e -> Exceptions.unwrap(e) instanceof StoreException.IllegalStateException);
}
Also used : UpdateSubscriberStatus(io.pravega.controller.stream.api.grpc.v1.Controller.UpdateSubscriberStatus) DeleteReaderGroupStatus(io.pravega.controller.stream.api.grpc.v1.Controller.DeleteReaderGroupStatus) ScaleStreamStatus(io.pravega.controller.stream.api.grpc.v1.Controller.ScaleResponse.ScaleStreamStatus) TxnStatus(io.pravega.controller.store.stream.TxnStatus) UpdateStreamStatus(io.pravega.controller.stream.api.grpc.v1.Controller.UpdateStreamStatus) SealStreamTask(io.pravega.controller.server.eventProcessor.requesthandlers.SealStreamTask) SealStreamEvent(io.pravega.shared.controller.event.SealStreamEvent) ScaleResponse(io.pravega.controller.stream.api.grpc.v1.Controller.ScaleResponse) StoreException(io.pravega.controller.store.stream.StoreException) AbstractMap(java.util.AbstractMap) ControllerEventStreamWriterMock(io.pravega.controller.mocks.ControllerEventStreamWriterMock) EventStreamWriterMock(io.pravega.controller.mocks.EventStreamWriterMock) Test(org.junit.Test)

Example 12 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().getSegmentId());
    Assert.assertEquals(computeSegmentId(2, 1), segmentRanges.getSegmentRanges(1).getSegmentId().getSegmentId());
    Assert.assertEquals(computeSegmentId(3, 1), segmentRanges.getSegmentRanges(2).getSegmentId().getSegmentId());
}
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)11 Controller (io.pravega.controller.stream.api.grpc.v1.Controller)9 AbstractMap (java.util.AbstractMap)7 HashMap (java.util.HashMap)7 StreamConfiguration (io.pravega.client.stream.StreamConfiguration)6 UpdateStreamStatus (io.pravega.controller.stream.api.grpc.v1.Controller.UpdateStreamStatus)6 ArrayList (java.util.ArrayList)6 Test (org.junit.Test)6 ScalingPolicy (io.pravega.client.stream.ScalingPolicy)5 DeleteReaderGroupStatus (io.pravega.controller.stream.api.grpc.v1.Controller.DeleteReaderGroupStatus)5 ScaleRequest (io.pravega.controller.stream.api.grpc.v1.Controller.ScaleRequest)5 UpdateSubscriberStatus (io.pravega.controller.stream.api.grpc.v1.Controller.UpdateSubscriberStatus)5 ImmutableMap (com.google.common.collect.ImmutableMap)4 ControllerEventStreamWriterMock (io.pravega.controller.mocks.ControllerEventStreamWriterMock)4 SegmentHelper (io.pravega.controller.server.SegmentHelper)4 GrpcAuthHelper (io.pravega.controller.server.security.auth.GrpcAuthHelper)4 Map (java.util.Map)4 ImmutableSet (com.google.common.collect.ImmutableSet)3 ModelHelper (io.pravega.client.control.impl.ModelHelper)3 Segment (io.pravega.client.segment.impl.Segment)3