use of io.pravega.controller.stream.api.grpc.v1.Controller.CreateStreamStatus in project pravega by pravega.
the class ControllerImplTest method setup.
@Before
public void setup() throws IOException {
// Setup test server generating different success and failure responses.
testServerImpl = new ControllerServiceImplBase() {
@Override
public void createStream(StreamConfig request, StreamObserver<CreateStreamStatus> responseObserver) {
if (request.getStreamInfo().getStream().equals("stream1") || request.getStreamInfo().getStream().equals("stream8")) {
responseObserver.onNext(CreateStreamStatus.newBuilder().setStatus(CreateStreamStatus.Status.SUCCESS).build());
responseObserver.onCompleted();
} else if (request.getStreamInfo().getStream().equals("stream2")) {
responseObserver.onNext(CreateStreamStatus.newBuilder().setStatus(CreateStreamStatus.Status.FAILURE).build());
responseObserver.onCompleted();
} else if (request.getStreamInfo().getStream().equals("stream3")) {
responseObserver.onNext(CreateStreamStatus.newBuilder().setStatus(CreateStreamStatus.Status.SCOPE_NOT_FOUND).build());
responseObserver.onCompleted();
} else if (request.getStreamInfo().getStream().equals("stream4")) {
responseObserver.onNext(CreateStreamStatus.newBuilder().setStatus(CreateStreamStatus.Status.STREAM_EXISTS).build());
responseObserver.onCompleted();
} else if (request.getStreamInfo().getStream().equals("stream5")) {
responseObserver.onNext(CreateStreamStatus.newBuilder().setStatus(CreateStreamStatus.Status.INVALID_STREAM_NAME).build());
responseObserver.onCompleted();
} else if (request.getStreamInfo().getStream().equals("streamparallel")) {
// Simulating delay in sending response.
Exceptions.handleInterrupted(() -> Thread.sleep(500));
responseObserver.onNext(CreateStreamStatus.newBuilder().setStatus(CreateStreamStatus.Status.SUCCESS).build());
responseObserver.onCompleted();
} else if (request.getStreamInfo().getStream().equals("streamdelayed")) {
// Simulating delay in sending response. This is used for the keepalive test,
// where response time > 30 seconds is required to simulate a failure.
Exceptions.handleInterrupted(() -> Thread.sleep(40000));
responseObserver.onNext(CreateStreamStatus.newBuilder().setStatus(CreateStreamStatus.Status.SUCCESS).build());
responseObserver.onCompleted();
} else if (request.getStreamInfo().getStream().equals("streamretryfailure")) {
responseObserver.onError(Status.UNKNOWN.withDescription("Transport error").asRuntimeException());
} else if (request.getStreamInfo().getStream().equals("streamretrysuccess")) {
if (retryAttempts.incrementAndGet() > 3) {
responseObserver.onNext(CreateStreamStatus.newBuilder().setStatus(CreateStreamStatus.Status.SUCCESS).build());
responseObserver.onCompleted();
} else {
responseObserver.onError(Status.INTERNAL.withDescription("Server error").asRuntimeException());
}
} else {
responseObserver.onError(Status.INTERNAL.withDescription("Server error").asRuntimeException());
}
}
@Override
public void updateStream(StreamConfig request, StreamObserver<UpdateStreamStatus> responseObserver) {
if (request.getStreamInfo().getStream().equals("stream1")) {
responseObserver.onNext(UpdateStreamStatus.newBuilder().setStatus(UpdateStreamStatus.Status.SUCCESS).build());
responseObserver.onCompleted();
} else if (request.getStreamInfo().getStream().equals("stream2")) {
responseObserver.onNext(UpdateStreamStatus.newBuilder().setStatus(UpdateStreamStatus.Status.FAILURE).build());
responseObserver.onCompleted();
} else if (request.getStreamInfo().getStream().equals("stream3")) {
responseObserver.onNext(UpdateStreamStatus.newBuilder().setStatus(UpdateStreamStatus.Status.SCOPE_NOT_FOUND).build());
responseObserver.onCompleted();
} else if (request.getStreamInfo().getStream().equals("stream4")) {
responseObserver.onNext(UpdateStreamStatus.newBuilder().setStatus(UpdateStreamStatus.Status.STREAM_NOT_FOUND).build());
responseObserver.onCompleted();
} else if (request.getStreamInfo().getStream().equals("stream5")) {
responseObserver.onNext(UpdateStreamStatus.newBuilder().setStatus(UpdateStreamStatus.Status.UNRECOGNIZED).build());
responseObserver.onCompleted();
} else {
responseObserver.onError(Status.INTERNAL.withDescription("Server error").asRuntimeException());
}
}
@Override
public void truncateStream(Controller.StreamCut request, StreamObserver<UpdateStreamStatus> responseObserver) {
if (request.getStreamInfo().getStream().equals("stream1")) {
responseObserver.onNext(UpdateStreamStatus.newBuilder().setStatus(UpdateStreamStatus.Status.SUCCESS).build());
responseObserver.onCompleted();
} else if (request.getStreamInfo().getStream().equals("stream2")) {
responseObserver.onNext(UpdateStreamStatus.newBuilder().setStatus(UpdateStreamStatus.Status.FAILURE).build());
responseObserver.onCompleted();
} else if (request.getStreamInfo().getStream().equals("stream3")) {
responseObserver.onNext(UpdateStreamStatus.newBuilder().setStatus(UpdateStreamStatus.Status.SCOPE_NOT_FOUND).build());
responseObserver.onCompleted();
} else if (request.getStreamInfo().getStream().equals("stream4")) {
responseObserver.onNext(UpdateStreamStatus.newBuilder().setStatus(UpdateStreamStatus.Status.STREAM_NOT_FOUND).build());
responseObserver.onCompleted();
} else if (request.getStreamInfo().getStream().equals("stream5")) {
responseObserver.onNext(UpdateStreamStatus.newBuilder().setStatus(UpdateStreamStatus.Status.UNRECOGNIZED).build());
responseObserver.onCompleted();
} else {
responseObserver.onError(Status.INTERNAL.withDescription("Server error").asRuntimeException());
}
}
@Override
public void sealStream(StreamInfo request, StreamObserver<UpdateStreamStatus> responseObserver) {
if (request.getStream().equals("stream1")) {
responseObserver.onNext(UpdateStreamStatus.newBuilder().setStatus(UpdateStreamStatus.Status.SUCCESS).build());
responseObserver.onCompleted();
} else if (request.getStream().equals("stream2")) {
responseObserver.onNext(UpdateStreamStatus.newBuilder().setStatus(UpdateStreamStatus.Status.FAILURE).build());
responseObserver.onCompleted();
} else if (request.getStream().equals("stream3")) {
responseObserver.onNext(UpdateStreamStatus.newBuilder().setStatus(UpdateStreamStatus.Status.SCOPE_NOT_FOUND).build());
responseObserver.onCompleted();
} else if (request.getStream().equals("stream4")) {
responseObserver.onNext(UpdateStreamStatus.newBuilder().setStatus(UpdateStreamStatus.Status.STREAM_NOT_FOUND).build());
responseObserver.onCompleted();
} else {
responseObserver.onError(Status.INTERNAL.withDescription("Server error").asRuntimeException());
}
}
@Override
public void deleteStream(StreamInfo request, StreamObserver<DeleteStreamStatus> responseObserver) {
if (request.getStream().equals("stream1")) {
responseObserver.onNext(DeleteStreamStatus.newBuilder().setStatus(DeleteStreamStatus.Status.SUCCESS).build());
responseObserver.onCompleted();
} else if (request.getStream().equals("stream2")) {
responseObserver.onNext(DeleteStreamStatus.newBuilder().setStatus(DeleteStreamStatus.Status.FAILURE).build());
responseObserver.onCompleted();
} else if (request.getStream().equals("stream3")) {
responseObserver.onNext(DeleteStreamStatus.newBuilder().setStatus(DeleteStreamStatus.Status.STREAM_NOT_FOUND).build());
responseObserver.onCompleted();
} else if (request.getStream().equals("stream4")) {
responseObserver.onNext(DeleteStreamStatus.newBuilder().setStatus(DeleteStreamStatus.Status.STREAM_NOT_SEALED).build());
responseObserver.onCompleted();
} else {
responseObserver.onError(Status.INTERNAL.withDescription("Server error").asRuntimeException());
}
}
@Override
public void getCurrentSegments(StreamInfo request, StreamObserver<SegmentRanges> responseObserver) {
if (request.getStream().equals("stream1")) {
responseObserver.onNext(SegmentRanges.newBuilder().addSegmentRanges(ModelHelper.createSegmentRange("scope1", "stream1", 6, 0.0, 0.4)).addSegmentRanges(ModelHelper.createSegmentRange("scope1", "stream1", 7, 0.4, 1.0)).build());
responseObserver.onCompleted();
} else if (request.getStream().equals("stream8")) {
responseObserver.onNext(SegmentRanges.newBuilder().addSegmentRanges(ModelHelper.createSegmentRange("scope1", "stream8", 9, 0.0, 0.5)).addSegmentRanges(ModelHelper.createSegmentRange("scope1", "stream8", 10, 0.5, 1.0)).build());
responseObserver.onCompleted();
} else if (request.getStream().equals("streamparallel")) {
Exceptions.handleInterrupted(() -> Thread.sleep(500));
responseObserver.onNext(SegmentRanges.newBuilder().addSegmentRanges(ModelHelper.createSegmentRange("scope1", "streamparallel", 0, 0.0, 0.4)).addSegmentRanges(ModelHelper.createSegmentRange("scope1", "streamparallel", 1, 0.4, 1.0)).build());
responseObserver.onCompleted();
} else {
responseObserver.onError(Status.INTERNAL.withDescription("Server error").asRuntimeException());
}
}
@Override
public void getSegments(GetSegmentsRequest request, StreamObserver<SegmentsAtTime> responseObserver) {
if (request.getStreamInfo().getStream().equals("stream1")) {
SegmentId segment1 = ModelHelper.createSegmentId("scope1", "stream1", 0);
SegmentId segment2 = ModelHelper.createSegmentId("scope1", "stream1", 1);
responseObserver.onNext(SegmentsAtTime.newBuilder().addSegments(SegmentLocation.newBuilder().setSegmentId(segment1).setOffset(10).build()).addSegments(SegmentLocation.newBuilder().setSegmentId(segment2).setOffset(20).build()).build());
responseObserver.onCompleted();
} else if (request.getStreamInfo().getStream().equals("stream8")) {
SegmentId segment1 = ModelHelper.createSegmentId("scope1", "stream8", 0);
SegmentId segment2 = ModelHelper.createSegmentId("scope1", "stream8", 1);
SegmentId segment3 = ModelHelper.createSegmentId("scope1", "stream8", 2);
responseObserver.onNext(SegmentsAtTime.newBuilder().addSegments(SegmentLocation.newBuilder().setSegmentId(segment1).setOffset(10).build()).addSegments(SegmentLocation.newBuilder().setSegmentId(segment2).setOffset(20).build()).build());
responseObserver.onCompleted();
} else {
responseObserver.onError(Status.INTERNAL.withDescription("Server error").asRuntimeException());
}
}
@Override
public void getSegmentsImmediatlyFollowing(SegmentId request, StreamObserver<SuccessorResponse> responseObserver) {
if (request.getStreamInfo().getStream().equals("stream1")) {
Map<SegmentId, Pair<Double, Double>> result = new HashMap<>();
if (request.getSegmentNumber() == 0) {
result.put(ModelHelper.createSegmentId("scope1", "stream1", 2), Pair.of(0.0, 0.25));
result.put(ModelHelper.createSegmentId("scope1", "stream1", 3), Pair.of(0.25, 0.5));
} else if (request.getSegmentNumber() == 1) {
result.put(ModelHelper.createSegmentId("scope1", "stream1", 4), Pair.of(0.5, 0.75));
result.put(ModelHelper.createSegmentId("scope1", "stream1", 5), Pair.of(0.75, 1.0));
} else if (request.getSegmentNumber() == 2 || request.getSegmentNumber() == 3) {
result.put(ModelHelper.createSegmentId("scope1", "stream1", 6), Pair.of(0.0, 0.5));
} else if (request.getSegmentNumber() == 4 || request.getSegmentNumber() == 5) {
result.put(ModelHelper.createSegmentId("scope1", "stream1", 7), Pair.of(0.5, 0.25));
}
val builder = SuccessorResponse.newBuilder();
for (Entry<SegmentId, Pair<Double, Double>> entry : result.entrySet()) {
builder.addSegments(SuccessorResponse.SegmentEntry.newBuilder().setSegment(Controller.SegmentRange.newBuilder().setSegmentId(entry.getKey()).setMinKey(entry.getValue().getLeft()).setMaxKey(entry.getValue().getRight()).build()).addValue(10 * entry.getKey().getSegmentNumber()).build());
}
responseObserver.onNext(builder.build());
responseObserver.onCompleted();
} else if (request.getStreamInfo().getStream().equals("stream8")) {
Map<SegmentId, Pair<Double, Double>> result = new HashMap<>();
if (request.getSegmentNumber() == 0) {
result.put(ModelHelper.createSegmentId("scope1", "stream8", 3), Pair.of(0.0, 0.2));
result.put(ModelHelper.createSegmentId("scope1", "stream8", 4), Pair.of(0.2, 0.33));
} else if (request.getSegmentNumber() == 1) {
result.put(ModelHelper.createSegmentId("scope1", "stream8", 5), Pair.of(0.33, 0.5));
result.put(ModelHelper.createSegmentId("scope1", "stream8", 6), Pair.of(0.5, 0.66));
} else if (request.getSegmentNumber() == 2) {
result.put(ModelHelper.createSegmentId("scope1", "stream8", 7), Pair.of(0.66, 0.8));
result.put(ModelHelper.createSegmentId("scope1", "stream8", 8), Pair.of(0.8, 1.0));
} else if (request.getSegmentNumber() == 3 || request.getSegmentNumber() == 4 || request.getSegmentNumber() == 5) {
result.put(ModelHelper.createSegmentId("scope1", "stream8", 9), Pair.of(0.0, 0.5));
} else if (request.getSegmentNumber() == 6 || request.getSegmentNumber() == 7 || request.getSegmentNumber() == 8) {
result.put(ModelHelper.createSegmentId("scope1", "stream8", 10), Pair.of(0.5, 1.0));
}
val builder = SuccessorResponse.newBuilder();
for (Entry<SegmentId, Pair<Double, Double>> entry : result.entrySet()) {
builder.addSegments(SuccessorResponse.SegmentEntry.newBuilder().setSegment(Controller.SegmentRange.newBuilder().setSegmentId(entry.getKey()).setMinKey(entry.getValue().getLeft()).setMaxKey(entry.getValue().getRight()).build()).addValue(10 * entry.getKey().getSegmentNumber()).build());
}
responseObserver.onNext(builder.build());
responseObserver.onCompleted();
} else {
responseObserver.onError(Status.INTERNAL.withDescription("Server error").asRuntimeException());
}
}
@Override
public void scale(ScaleRequest request, StreamObserver<ScaleResponse> responseObserver) {
if (request.getStreamInfo().getStream().equals("stream1")) {
responseObserver.onNext(ScaleResponse.newBuilder().setStatus(ScaleResponse.ScaleStreamStatus.STARTED).addSegments(ModelHelper.createSegmentRange("scope1", "stream1", 0, 0.0, 0.5)).addSegments(ModelHelper.createSegmentRange("scope1", "stream1", 1, 0.5, 1.0)).setEpoch(0).build());
responseObserver.onCompleted();
} else {
responseObserver.onError(Status.INTERNAL.withDescription("Server error").asRuntimeException());
}
}
@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());
}
}
@Override
public void getURI(SegmentId request, StreamObserver<NodeUri> responseObserver) {
if (request.getStreamInfo().getStream().equals("stream1")) {
responseObserver.onNext(NodeUri.newBuilder().setEndpoint("localhost").setPort(SERVICE_PORT).build());
responseObserver.onCompleted();
} else {
responseObserver.onError(Status.INTERNAL.withDescription("Server error").asRuntimeException());
}
}
@Override
public void isSegmentValid(SegmentId request, StreamObserver<SegmentValidityResponse> responseObserver) {
if (request.getStreamInfo().getStream().equals("stream1")) {
responseObserver.onNext(SegmentValidityResponse.newBuilder().setResponse(true).build());
responseObserver.onCompleted();
} else if (request.getStreamInfo().getStream().equals("stream2")) {
responseObserver.onNext(SegmentValidityResponse.newBuilder().setResponse(false).build());
responseObserver.onCompleted();
} else {
responseObserver.onError(Status.INTERNAL.withDescription("Server error").asRuntimeException());
}
}
@Override
public void createTransaction(CreateTxnRequest request, StreamObserver<Controller.CreateTxnResponse> responseObserver) {
Controller.CreateTxnResponse.Builder builder = Controller.CreateTxnResponse.newBuilder();
if (request.getStreamInfo().getStream().equals("stream1")) {
builder.setTxnId(TxnId.newBuilder().setHighBits(11L).setLowBits(22L).build());
builder.addActiveSegments(ModelHelper.createSegmentRange("scope1", "stream1", 0, 0.0, 0.5));
builder.addActiveSegments(ModelHelper.createSegmentRange("scope1", "stream1", 1, 0.5, 1.0));
responseObserver.onNext(builder.build());
responseObserver.onCompleted();
} else if (request.getStreamInfo().getStream().equals("stream2")) {
builder.addActiveSegments(ModelHelper.createSegmentRange("scope1", "stream2", 0, 0.0, 1.0));
builder.setTxnId(TxnId.newBuilder().setHighBits(33L).setLowBits(44L).build());
responseObserver.onNext(builder.build());
responseObserver.onCompleted();
} else {
responseObserver.onError(Status.INTERNAL.withDescription("Server error").asRuntimeException());
}
}
@Override
public void commitTransaction(TxnRequest request, StreamObserver<Controller.TxnStatus> responseObserver) {
if (request.getStreamInfo().getStream().equals("stream1")) {
responseObserver.onNext(Controller.TxnStatus.newBuilder().setStatus(Controller.TxnStatus.Status.SUCCESS).build());
responseObserver.onCompleted();
} else if (request.getStreamInfo().getStream().equals("stream2")) {
responseObserver.onNext(Controller.TxnStatus.newBuilder().setStatus(Controller.TxnStatus.Status.FAILURE).build());
responseObserver.onCompleted();
} else if (request.getStreamInfo().getStream().equals("stream3")) {
responseObserver.onNext(Controller.TxnStatus.newBuilder().setStatus(Controller.TxnStatus.Status.STREAM_NOT_FOUND).build());
responseObserver.onCompleted();
} else if (request.getStreamInfo().getStream().equals("stream4")) {
responseObserver.onNext(Controller.TxnStatus.newBuilder().setStatus(Controller.TxnStatus.Status.TRANSACTION_NOT_FOUND).build());
responseObserver.onCompleted();
} else {
responseObserver.onError(Status.INTERNAL.withDescription("Server error").asRuntimeException());
}
}
@Override
public void abortTransaction(TxnRequest request, StreamObserver<Controller.TxnStatus> responseObserver) {
if (request.getStreamInfo().getStream().equals("stream1")) {
responseObserver.onNext(Controller.TxnStatus.newBuilder().setStatus(Controller.TxnStatus.Status.SUCCESS).build());
responseObserver.onCompleted();
} else if (request.getStreamInfo().getStream().equals("stream2")) {
responseObserver.onNext(Controller.TxnStatus.newBuilder().setStatus(Controller.TxnStatus.Status.FAILURE).build());
responseObserver.onCompleted();
} else if (request.getStreamInfo().getStream().equals("stream3")) {
responseObserver.onNext(Controller.TxnStatus.newBuilder().setStatus(Controller.TxnStatus.Status.STREAM_NOT_FOUND).build());
responseObserver.onCompleted();
} else if (request.getStreamInfo().getStream().equals("stream4")) {
responseObserver.onNext(Controller.TxnStatus.newBuilder().setStatus(Controller.TxnStatus.Status.TRANSACTION_NOT_FOUND).build());
responseObserver.onCompleted();
} else {
responseObserver.onError(Status.INTERNAL.withDescription("Server error").asRuntimeException());
}
}
@Override
public void pingTransaction(PingTxnRequest request, StreamObserver<PingTxnStatus> responseObserver) {
if (request.getStreamInfo().getStream().equals("stream1")) {
responseObserver.onNext(PingTxnStatus.newBuilder().setStatus(PingTxnStatus.Status.OK).build());
responseObserver.onCompleted();
} else {
responseObserver.onError(Status.INTERNAL.withDescription("Server error").asRuntimeException());
}
}
@Override
public void checkTransactionState(TxnRequest request, StreamObserver<TxnState> responseObserver) {
if (request.getStreamInfo().getStream().equals("stream1")) {
responseObserver.onNext(TxnState.newBuilder().setState(TxnState.State.OPEN).build());
responseObserver.onCompleted();
} else if (request.getStreamInfo().getStream().equals("stream2")) {
responseObserver.onNext(TxnState.newBuilder().setState(TxnState.State.UNKNOWN).build());
responseObserver.onCompleted();
} else if (request.getStreamInfo().getStream().equals("stream3")) {
responseObserver.onNext(TxnState.newBuilder().setState(TxnState.State.COMMITTING).build());
responseObserver.onCompleted();
} else if (request.getStreamInfo().getStream().equals("stream4")) {
responseObserver.onNext(TxnState.newBuilder().setState(TxnState.State.COMMITTED).build());
responseObserver.onCompleted();
} else if (request.getStreamInfo().getStream().equals("stream5")) {
responseObserver.onNext(TxnState.newBuilder().setState(TxnState.State.ABORTING).build());
responseObserver.onCompleted();
} else if (request.getStreamInfo().getStream().equals("stream6")) {
responseObserver.onNext(TxnState.newBuilder().setState(TxnState.State.ABORTED).build());
responseObserver.onCompleted();
} else {
responseObserver.onError(Status.INTERNAL.withDescription("Server error").asRuntimeException());
}
}
@Override
public void createScope(ScopeInfo request, StreamObserver<CreateScopeStatus> responseObserver) {
if (request.getScope().equals("scope1")) {
responseObserver.onNext(CreateScopeStatus.newBuilder().setStatus(CreateScopeStatus.Status.SUCCESS).build());
responseObserver.onCompleted();
} else if (request.getScope().equals("scope2")) {
responseObserver.onNext(CreateScopeStatus.newBuilder().setStatus(CreateScopeStatus.Status.FAILURE).build());
responseObserver.onCompleted();
} else if (request.getScope().equals("scope3")) {
responseObserver.onNext(CreateScopeStatus.newBuilder().setStatus(CreateScopeStatus.Status.INVALID_SCOPE_NAME).build());
responseObserver.onCompleted();
} else if (request.getScope().equals("scope4")) {
responseObserver.onNext(CreateScopeStatus.newBuilder().setStatus(CreateScopeStatus.Status.SCOPE_EXISTS).build());
responseObserver.onCompleted();
} else {
responseObserver.onError(Status.INTERNAL.withDescription("Server error").asRuntimeException());
}
}
@Override
public void getDelegationToken(io.pravega.controller.stream.api.grpc.v1.Controller.StreamInfo request, io.grpc.stub.StreamObserver<io.pravega.controller.stream.api.grpc.v1.Controller.DelegationToken> responseObserver) {
responseObserver.onNext(Controller.DelegationToken.newBuilder().setDelegationToken("token").build());
responseObserver.onCompleted();
}
@Override
public void deleteScope(ScopeInfo request, StreamObserver<DeleteScopeStatus> responseObserver) {
if (request.getScope().equals("scope1")) {
responseObserver.onNext(DeleteScopeStatus.newBuilder().setStatus(DeleteScopeStatus.Status.SUCCESS).build());
responseObserver.onCompleted();
} else if (request.getScope().equals("scope2")) {
responseObserver.onNext(DeleteScopeStatus.newBuilder().setStatus(DeleteScopeStatus.Status.FAILURE).build());
responseObserver.onCompleted();
} else if (request.getScope().equals("scope3")) {
responseObserver.onNext(DeleteScopeStatus.newBuilder().setStatus(DeleteScopeStatus.Status.SCOPE_NOT_EMPTY).build());
responseObserver.onCompleted();
} else if (request.getScope().equals("scope4")) {
responseObserver.onNext(DeleteScopeStatus.newBuilder().setStatus(DeleteScopeStatus.Status.SCOPE_NOT_FOUND).build());
responseObserver.onCompleted();
} else {
responseObserver.onError(Status.INTERNAL.withDescription("Server error").asRuntimeException());
}
}
};
serverPort = TestUtils.getAvailableListenPort();
serverBuilder = NettyServerBuilder.forPort(serverPort).addService(testServerImpl);
if (testSecure) {
serverBuilder = serverBuilder.useTransportSecurity(new File("../config/cert.pem"), new File("../config/key.pem"));
creds = new DefaultCredentials("1111_aaaa", "admin");
}
testGRPCServer = serverBuilder.build().start();
executor = Executors.newSingleThreadScheduledExecutor();
controllerClient = new ControllerImpl(ControllerImplConfig.builder().clientConfig(ClientConfig.builder().controllerURI(URI.create((testSecure ? "tls://" : "tcp://") + "localhost:" + serverPort)).credentials(new DefaultCredentials("1111_aaaa", "admin")).trustStore("../config/cert.pem").build()).retryAttempts(1).build(), executor);
}
use of io.pravega.controller.stream.api.grpc.v1.Controller.CreateStreamStatus in project pravega by pravega.
the class ControllerServiceImplTest method createScopeAndStream.
protected void createScopeAndStream(String scope, String stream, ScalingPolicy scalingPolicy) {
final StreamConfiguration configuration1 = StreamConfiguration.builder().scope(scope).streamName(stream).scalingPolicy(scalingPolicy).build();
// Create a test scope.
ResultObserver<CreateScopeStatus> result1 = new ResultObserver<>();
this.controllerService.createScope(ModelHelper.createScopeInfo(scope), result1);
CreateScopeStatus createScopeStatus = result1.get();
assertEquals("Create Scope", CreateScopeStatus.Status.SUCCESS, createScopeStatus.getStatus());
// Create a test stream.
ResultObserver<CreateStreamStatus> result2 = new ResultObserver<>();
this.controllerService.createStream(ModelHelper.decode(configuration1), result2);
CreateStreamStatus createStreamStatus = result2.get();
assertEquals("Create stream", CreateStreamStatus.Status.SUCCESS, createStreamStatus.getStatus());
}
use of io.pravega.controller.stream.api.grpc.v1.Controller.CreateStreamStatus in project pravega by pravega.
the class ControllerServiceImplTest method truncateStreamTests.
@Test
public void truncateStreamTests() {
CreateScopeStatus createScopeStatus;
CreateStreamStatus createStreamStatus;
final StreamConfiguration configuration1 = StreamConfiguration.builder().scope(SCOPE1).streamName(STREAM1).scalingPolicy(ScalingPolicy.fixed(4)).build();
// Create a test scope.
ResultObserver<CreateScopeStatus> result1 = new ResultObserver<>();
this.controllerService.createScope(ModelHelper.createScopeInfo(SCOPE1), result1);
createScopeStatus = result1.get();
assertEquals("Create Scope", CreateScopeStatus.Status.SUCCESS, createScopeStatus.getStatus());
// Create a test stream.
ResultObserver<CreateStreamStatus> result2 = new ResultObserver<>();
this.controllerService.createStream(ModelHelper.decode(configuration1), result2);
createStreamStatus = result2.get();
assertEquals("Create stream", CreateStreamStatus.Status.SUCCESS, createStreamStatus.getStatus());
// Truncate the stream
ResultObserver<UpdateStreamStatus> result3 = new ResultObserver<>();
this.controllerService.truncateStream(Controller.StreamCut.newBuilder().setStreamInfo(StreamInfo.newBuilder().setScope(SCOPE1).setStream(STREAM1).build()).putCut(0, 0).build(), result3);
UpdateStreamStatus truncateStreamStatus = result3.get();
}
use of io.pravega.controller.stream.api.grpc.v1.Controller.CreateStreamStatus in project pravega by pravega.
the class ControllerServiceImplTest method sealStreamTests.
@Test
public void sealStreamTests() {
CreateScopeStatus createScopeStatus;
CreateStreamStatus createStreamStatus;
UpdateStreamStatus updateStreamStatus;
final StreamConfiguration configuration1 = StreamConfiguration.builder().scope(SCOPE1).streamName(STREAM1).scalingPolicy(ScalingPolicy.fixed(4)).build();
// Create a test scope.
ResultObserver<CreateScopeStatus> result1 = new ResultObserver<>();
this.controllerService.createScope(ModelHelper.createScopeInfo(SCOPE1), result1);
createScopeStatus = result1.get();
assertEquals("Create Scope", CreateScopeStatus.Status.SUCCESS, createScopeStatus.getStatus());
// Create a test stream.
ResultObserver<CreateStreamStatus> result2 = new ResultObserver<>();
this.controllerService.createStream(ModelHelper.decode(configuration1), result2);
createStreamStatus = result2.get();
assertEquals("Create stream", CreateStreamStatus.Status.SUCCESS, createStreamStatus.getStatus());
// Seal a test stream.
ResultObserver<UpdateStreamStatus> result3 = new ResultObserver<>();
this.controllerService.sealStream(ModelHelper.createStreamInfo(SCOPE1, STREAM1), result3);
updateStreamStatus = result3.get();
assertEquals("Seal Stream", UpdateStreamStatus.Status.SUCCESS, updateStreamStatus.getStatus());
// Seal a non-existent stream.
ResultObserver<UpdateStreamStatus> result4 = new ResultObserver<>();
this.controllerService.sealStream(ModelHelper.createStreamInfo(SCOPE1, "dummyStream"), result4);
updateStreamStatus = result4.get();
assertEquals("Seal non-existent stream", UpdateStreamStatus.Status.STREAM_NOT_FOUND, updateStreamStatus.getStatus());
// Seal a non-existent stream.
ResultObserver<UpdateStreamStatus> result5 = new ResultObserver<>();
this.controllerService.sealStream(ModelHelper.createStreamInfo("dummyScope", STREAM1), result5);
updateStreamStatus = result5.get();
assertEquals("Seal non-existent stream", UpdateStreamStatus.Status.STREAM_NOT_FOUND, updateStreamStatus.getStatus());
}
use of io.pravega.controller.stream.api.grpc.v1.Controller.CreateStreamStatus in project pravega by pravega.
the class ControllerServiceImplTest method createStreamTests.
@Test
public void createStreamTests() {
final ScalingPolicy policy1 = ScalingPolicy.fixed(2);
final ScalingPolicy policy2 = ScalingPolicy.fixed(3);
final StreamConfiguration configuration1 = StreamConfiguration.builder().scope(SCOPE1).streamName(STREAM1).scalingPolicy(policy1).build();
final StreamConfiguration configuration2 = StreamConfiguration.builder().scope(SCOPE1).streamName(STREAM2).scalingPolicy(policy2).build();
final StreamConfiguration configuration3 = StreamConfiguration.builder().scope("SCOPE3").streamName(STREAM2).scalingPolicy(policy2).build();
CreateStreamStatus status;
// region checkStream
ResultObserver<CreateScopeStatus> result = new ResultObserver<>();
this.controllerService.createScope(ScopeInfo.newBuilder().setScope(SCOPE1).build(), result);
Assert.assertEquals(result.get().getStatus(), CreateScopeStatus.Status.SUCCESS);
ResultObserver<CreateStreamStatus> result1 = new ResultObserver<>();
this.controllerService.createStream(ModelHelper.decode(configuration1), result1);
status = result1.get();
Assert.assertEquals(status.getStatus(), CreateStreamStatus.Status.SUCCESS);
ResultObserver<CreateStreamStatus> result2 = new ResultObserver<>();
this.controllerService.createStream(ModelHelper.decode(configuration2), result2);
status = result2.get();
Assert.assertEquals(status.getStatus(), CreateStreamStatus.Status.SUCCESS);
// endregion
// region duplicate create stream
ResultObserver<CreateStreamStatus> result3 = new ResultObserver<>();
this.controllerService.createStream(ModelHelper.decode(configuration1), result3);
status = result3.get();
Assert.assertEquals(status.getStatus(), CreateStreamStatus.Status.STREAM_EXISTS);
// endregion
// create stream for non-existent scope
ResultObserver<CreateStreamStatus> result4 = new ResultObserver<>();
this.controllerService.createStream(ModelHelper.decode(configuration3), result4);
status = result4.get();
Assert.assertEquals(status.getStatus(), CreateStreamStatus.Status.SCOPE_NOT_FOUND);
// create stream with invalid stream name "abc/def"
ResultObserver<CreateStreamStatus> result5 = new ResultObserver<>();
final StreamConfiguration configuration4 = StreamConfiguration.builder().scope("SCOPE3").streamName("abc/def").scalingPolicy(policy2).build();
this.controllerService.createStream(ModelHelper.decode(configuration4), result5);
status = result5.get();
assertEquals(status.getStatus(), CreateStreamStatus.Status.INVALID_STREAM_NAME);
// Create stream with an internal stream name.
ResultObserver<CreateStreamStatus> result6 = new ResultObserver<>();
final StreamConfiguration configuration6 = StreamConfiguration.builder().scope(SCOPE1).streamName(NameUtils.getInternalNameForStream("abcdef")).scalingPolicy(policy2).build();
this.controllerService.createStream(ModelHelper.decode(configuration6), result6);
status = result6.get();
assertEquals(status.getStatus(), CreateStreamStatus.Status.SUCCESS);
}
Aggregations