use of io.pravega.controller.stream.api.grpc.v1.Controller.PingTxnRequest 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);
}
Aggregations