1 /* 2 * Copyright 2022 The gRPC Authors 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package io.grpc.gcp.observability; 18 19 import io.grpc.stub.StreamObserver; 20 import io.grpc.testing.protobuf.SimpleRequest; 21 import io.grpc.testing.protobuf.SimpleResponse; 22 import io.grpc.testing.protobuf.SimpleServiceGrpc; 23 24 public class ObservabilityTestHelper { 25 makeUnaryRpcViaClientStub( String requestMessage, SimpleServiceGrpc.SimpleServiceBlockingStub blockingStub)26 static String makeUnaryRpcViaClientStub( 27 String requestMessage, SimpleServiceGrpc.SimpleServiceBlockingStub blockingStub) { 28 SimpleRequest request = SimpleRequest.newBuilder().setRequestMessage(requestMessage).build(); 29 SimpleResponse response = blockingStub.unaryRpc(request); 30 return response.getResponseMessage(); 31 } 32 33 static class SimpleServiceImpl extends SimpleServiceGrpc.SimpleServiceImplBase { 34 35 @Override unaryRpc(SimpleRequest req, StreamObserver<SimpleResponse> responseObserver)36 public void unaryRpc(SimpleRequest req, StreamObserver<SimpleResponse> responseObserver) { 37 SimpleResponse response = 38 SimpleResponse.newBuilder() 39 .setResponseMessage("Hello " + req.getRequestMessage()) 40 .build(); 41 responseObserver.onNext(response); 42 responseObserver.onCompleted(); 43 } 44 } 45 } 46