@Test public void testScaleStream() throws ExecutionException, InterruptedException { when(this.mockControllerService.checkScale(anyString(), anyString(), anyInt())).thenReturn( CompletableFuture.completedFuture(Controller.ScaleStatusResponse.newBuilder() .setStatus(Controller.ScaleStatusResponse.ScaleStatus.SUCCESS).build())); when(this.mockControllerService.scale(any(), any(), any(), any(), anyLong())).thenReturn( CompletableFuture.completedFuture(Controller.ScaleResponse.newBuilder() .setStatus(Controller.ScaleResponse.ScaleStreamStatus.STARTED).build())); Assert.assertTrue(this.testController.scaleStream(new StreamImpl("scope", "stream"), new ArrayList<>(), new HashMap<>(), executorService()).getFuture().join()); when(this.mockControllerService.scale(any(), any(), any(), any(), anyLong())).thenReturn( CompletableFuture.completedFuture(Controller.ScaleResponse.newBuilder() .setStatus(Controller.ScaleResponse.ScaleStreamStatus.PRECONDITION_FAILED).build())); Assert.assertFalse(this.testController.scaleStream(new StreamImpl("scope", "stream"), new ArrayList<>(), new HashMap<>(), executorService()).getFuture().join()); when(this.mockControllerService.scale(any(), any(), any(), any(), anyLong())).thenReturn( CompletableFuture.completedFuture(Controller.ScaleResponse.newBuilder() .setStatus(Controller.ScaleResponse.ScaleStreamStatus.FAILURE).build())); assertThrows("Expected ControllerFailureException", () -> this.testController.startScale(new StreamImpl("scope", "stream"), new ArrayList<>(), new HashMap<>()).join(), ex -> ex instanceof ControllerFailureException); when(this.mockControllerService.scale(any(), any(), any(), any(), anyLong())).thenReturn( CompletableFuture.completedFuture(Controller.ScaleResponse.newBuilder() .setStatusValue(-1).build())); assertThrows("Expected ControllerFailureException", () -> this.testController.startScale(new StreamImpl("scope", "stream"), new ArrayList<>(), new HashMap<>()).join(), ex -> ex instanceof ControllerFailureException); }
}, this.executor); return result.thenApply(response -> { switch (response.getStatus()) { case IN_PROGRESS: return false;
@java.lang.Override public int hashCode() { if (memoizedHashCode != 0) { return memoizedHashCode; } int hash = 41; hash = (19 * hash) + getDescriptor().hashCode(); hash = (37 * hash) + STATUS_FIELD_NUMBER; hash = (53 * hash) + status_; hash = (29 * hash) + unknownFields.hashCode(); memoizedHashCode = hash; return hash; }
done = scalestatusResponse.getStatus().equals(Controller.ScaleStatusResponse.ScaleStatus.SUCCESS);
return streamMetadataStore.getActiveEpoch(scope, stream, context, true, executor) .handle((activeEpoch, ex) -> { ScaleStatusResponse.Builder response = ScaleStatusResponse.newBuilder();
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(1L), keyRanges, start + 20) .get(); 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();
@io.grpc.stub.annotations.RpcMethod( fullMethodName = SERVICE_NAME + '/' + "checkScale", requestType = io.pravega.controller.stream.api.grpc.v1.Controller.ScaleStatusRequest.class, responseType = io.pravega.controller.stream.api.grpc.v1.Controller.ScaleStatusResponse.class, methodType = io.grpc.MethodDescriptor.MethodType.UNARY) public static io.grpc.MethodDescriptor<io.pravega.controller.stream.api.grpc.v1.Controller.ScaleStatusRequest, io.pravega.controller.stream.api.grpc.v1.Controller.ScaleStatusResponse> getCheckScaleMethod() { io.grpc.MethodDescriptor<io.pravega.controller.stream.api.grpc.v1.Controller.ScaleStatusRequest, io.pravega.controller.stream.api.grpc.v1.Controller.ScaleStatusResponse> getCheckScaleMethod; if ((getCheckScaleMethod = ControllerServiceGrpc.getCheckScaleMethod) == null) { synchronized (ControllerServiceGrpc.class) { if ((getCheckScaleMethod = ControllerServiceGrpc.getCheckScaleMethod) == null) { ControllerServiceGrpc.getCheckScaleMethod = getCheckScaleMethod = io.grpc.MethodDescriptor.<io.pravega.controller.stream.api.grpc.v1.Controller.ScaleStatusRequest, io.pravega.controller.stream.api.grpc.v1.Controller.ScaleStatusResponse>newBuilder() .setType(io.grpc.MethodDescriptor.MethodType.UNARY) .setFullMethodName(generateFullMethodName( "io.pravega.controller.stream.api.grpc.v1.ControllerService", "checkScale")) .setSampledToLocalTracing(true) .setRequestMarshaller(io.grpc.protobuf.ProtoUtils.marshaller( io.pravega.controller.stream.api.grpc.v1.Controller.ScaleStatusRequest.getDefaultInstance())) .setResponseMarshaller(io.grpc.protobuf.ProtoUtils.marshaller( io.pravega.controller.stream.api.grpc.v1.Controller.ScaleStatusResponse.getDefaultInstance())) .setSchemaDescriptor(new ControllerServiceMethodDescriptorSupplier("checkScale")) .build(); } } } return getCheckScaleMethod; }
@Test public void eventWriterInitializationTest() throws Exception { final ScalingPolicy policy = ScalingPolicy.fixed(1); final StreamConfiguration configuration = StreamConfiguration.builder().scalingPolicy(policy).build(); streamStorePartialMock.createStream(SCOPE, "test", configuration, System.currentTimeMillis(), null, executor).get(); streamStorePartialMock.setState(SCOPE, "test", State.ACTIVE, null, executor).get(); AssertExtensions.assertThrows("", () -> streamMetadataTasks.manualScale(SCOPE, "test", Collections.singletonList(0L), Arrays.asList(), 30, null).get(), e -> e instanceof TaskExceptions.ProcessingDisabledException); streamMetadataTasks.setRequestEventWriter(new ControllerEventStreamWriterMock(streamRequestHandler, executor)); List<AbstractMap.SimpleEntry<Double, Double>> newRanges = new ArrayList<>(); newRanges.add(new AbstractMap.SimpleEntry<>(0.0, 0.5)); newRanges.add(new AbstractMap.SimpleEntry<>(0.5, 1.0)); ScaleResponse scaleOpResult = streamMetadataTasks.manualScale(SCOPE, "test", Collections.singletonList(0L), newRanges, 30, null).get(); assertEquals(ScaleStreamStatus.STARTED, scaleOpResult.getStatus()); Controller.ScaleStatusResponse scaleStatusResult = streamMetadataTasks.checkScale(SCOPE, "UNKNOWN", 0, null).get(); assertEquals(Controller.ScaleStatusResponse.ScaleStatus.INVALID_INPUT, scaleStatusResult.getStatus()); scaleStatusResult = streamMetadataTasks.checkScale("UNKNOWN", "test", 0, null).get(); assertEquals(Controller.ScaleStatusResponse.ScaleStatus.INVALID_INPUT, scaleStatusResult.getStatus()); scaleStatusResult = streamMetadataTasks.checkScale(SCOPE, "test", 5, null).get(); assertEquals(Controller.ScaleStatusResponse.ScaleStatus.INVALID_INPUT, scaleStatusResult.getStatus()); }
@Override public CompletableFuture<Boolean> checkScaleStatus(final Stream stream, final int epoch) { return this.controller.checkScale(stream.getScope(), stream.getStreamName(), epoch) .thenApply(response -> { switch (response.getStatus()) { case IN_PROGRESS: return false; case SUCCESS: return true; case INVALID_INPUT: throw new ControllerFailureException("invalid input"); case INTERNAL_ERROR: default: throw new ControllerFailureException("unknown error"); } }); }
public Builder newBuilderForType() { return newBuilder(); } public static Builder newBuilder() {
public io.pravega.controller.stream.api.grpc.v1.Controller.ScaleStatusResponse getDefaultInstanceForType() { return io.pravega.controller.stream.api.grpc.v1.Controller.ScaleStatusResponse.getDefaultInstance(); }
public static final com.google.protobuf.Descriptors.EnumDescriptor getDescriptor() { return io.pravega.controller.stream.api.grpc.v1.Controller.ScaleStatusResponse.getDescriptor().getEnumTypes().get(0); }
private void scale(long start, List<Long> segmentsToSeal, Map<Double, Double> keyRanges) throws InterruptedException, java.util.concurrent.ExecutionException { Controller.ScaleResponse scaleStatus = consumer.scale(SCOPE, STREAM, segmentsToSeal, keyRanges, start) .get(); AtomicBoolean done = new AtomicBoolean(false); Futures.loop(() -> !done.get(), () -> Futures.delayedFuture(() -> consumer.checkScale(SCOPE, STREAM, scaleStatus.getEpoch()), 1000, executor) .thenAccept(x -> done.set(x.getStatus().equals(Controller.ScaleStatusResponse.ScaleStatus.SUCCESS))), executor).get(); } }
public io.pravega.controller.stream.api.grpc.v1.Controller.ScaleStatusResponse buildPartial() { io.pravega.controller.stream.api.grpc.v1.Controller.ScaleStatusResponse result = new io.pravega.controller.stream.api.grpc.v1.Controller.ScaleStatusResponse(this); result.status_ = status_; onBuilt(); return result; }
public Builder mergeFrom(io.pravega.controller.stream.api.grpc.v1.Controller.ScaleStatusResponse other) { if (other == io.pravega.controller.stream.api.grpc.v1.Controller.ScaleStatusResponse.getDefaultInstance()) return this; if (other.status_ != 0) { setStatusValue(other.getStatusValue()); } this.mergeUnknownFields(other.unknownFields); onChanged(); return this; }
public io.pravega.controller.stream.api.grpc.v1.Controller.ScaleStatusResponse build() { io.pravega.controller.stream.api.grpc.v1.Controller.ScaleStatusResponse result = buildPartial(); if (!result.isInitialized()) { throw newUninitializedMessageException(result); } return result; }
@Override public void checkScale(ScaleStatusRequest request, StreamObserver<ScaleStatusResponse> responseObserver) { if (request.getStreamInfo().getStream().equals("stream1")) { responseObserver.onNext(ScaleStatusResponse.newBuilder() .setStatus(ScaleStatusResponse.ScaleStatus.SUCCESS).build()); responseObserver.onCompleted(); } else { responseObserver.onError(Status.INTERNAL.withDescription("Server error").asRuntimeException()); } }