xref: /aosp_15_r20/external/grpc-grpc-java/xds/src/test/java/io/grpc/xds/XdsTestLoadReportingService.java (revision e07d83d3ffcef9ecfc9f7f475418ec639ff0e5fe)
1 /*
2  * Copyright 2023 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.xds;
18 
19 import io.envoyproxy.envoy.service.load_stats.v3.LoadReportingServiceGrpc;
20 import io.envoyproxy.envoy.service.load_stats.v3.LoadStatsRequest;
21 import io.envoyproxy.envoy.service.load_stats.v3.LoadStatsResponse;
22 import io.grpc.stub.StreamObserver;
23 
24 /**
25  * This dummy implementation is just used to allow tests that utilize load reporting to successfully
26  * connect to a test control plane server. It can be later expanded to e.g. store the requests it
27  * receives for tests to verify.
28  */
29 final class XdsTestLoadReportingService extends
30     LoadReportingServiceGrpc.LoadReportingServiceImplBase {
31 
32   @Override
streamLoadStats( StreamObserver<LoadStatsResponse> responseObserver)33   public StreamObserver<LoadStatsRequest> streamLoadStats(
34       StreamObserver<LoadStatsResponse> responseObserver) {
35     return new StreamObserver<LoadStatsRequest>() {
36       @Override
37       public void onNext(LoadStatsRequest request) {
38         responseObserver.onNext(LoadStatsResponse.newBuilder().build());
39       }
40 
41       @Override
42       public void onError(Throwable t) {
43         responseObserver.onError(t);
44       }
45 
46       @Override
47       public void onCompleted() {
48         responseObserver.onCompleted();
49       }
50     };
51   }
52 }
53