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