Search in sources :

Example 1 with ServerRequest

use of io.pravega.controller.stream.api.grpc.v1.Controller.ServerRequest in project pravega by pravega.

the class ControllerImplLBTest method setup.

@Before
public void setup() throws IOException {
    final int serverPort1 = TestUtils.getAvailableListenPort();
    final int serverPort2 = TestUtils.getAvailableListenPort();
    final int serverPort3 = TestUtils.getAvailableListenPort();
    // Setup fake servers for simulating multiple controllers with discovery info.
    ControllerServiceImplBase fakeServerImpl1 = new ControllerServiceImplBase() {

        @Override
        public void getControllerServerList(ServerRequest request, StreamObserver<ServerResponse> responseObserver) {
            responseObserver.onNext(ServerResponse.newBuilder().addNodeURI(NodeUri.newBuilder().setEndpoint("localhost").setPort(serverPort1).build()).addNodeURI(NodeUri.newBuilder().setEndpoint("localhost").setPort(serverPort2).build()).addNodeURI(NodeUri.newBuilder().setEndpoint("localhost").setPort(serverPort3).build()).build());
            responseObserver.onCompleted();
        }

        @Override
        public void getURI(SegmentId request, StreamObserver<NodeUri> responseObserver) {
            responseObserver.onNext(NodeUri.newBuilder().setEndpoint("localhost1").setPort(1).build());
            responseObserver.onCompleted();
        }
    };
    ControllerServiceImplBase fakeServerImpl2 = new ControllerServiceImplBase() {

        @Override
        public void getControllerServerList(ServerRequest request, StreamObserver<ServerResponse> responseObserver) {
            responseObserver.onNext(ServerResponse.newBuilder().addNodeURI(NodeUri.newBuilder().setEndpoint("localhost").setPort(serverPort1).build()).addNodeURI(NodeUri.newBuilder().setEndpoint("localhost").setPort(serverPort2).build()).addNodeURI(NodeUri.newBuilder().setEndpoint("localhost").setPort(serverPort3).build()).build());
            responseObserver.onCompleted();
        }

        @Override
        public void getURI(SegmentId request, StreamObserver<NodeUri> responseObserver) {
            responseObserver.onNext(NodeUri.newBuilder().setEndpoint("localhost2").setPort(2).build());
            responseObserver.onCompleted();
        }
    };
    ControllerServiceImplBase fakeServerImpl3 = new ControllerServiceImplBase() {

        @Override
        public void getURI(SegmentId request, StreamObserver<NodeUri> responseObserver) {
            responseObserver.onNext(NodeUri.newBuilder().setEndpoint("localhost3").setPort(3).build());
            responseObserver.onCompleted();
        }
    };
    testRPCServer1 = NettyServerBuilder.forPort(serverPort1).addService(fakeServerImpl1).build().start();
    testRPCServer2 = NettyServerBuilder.forPort(serverPort2).addService(fakeServerImpl2).build().start();
    testRPCServer3 = NettyServerBuilder.forPort(serverPort3).addService(fakeServerImpl3).build().start();
}
Also used : StreamObserver(io.grpc.stub.StreamObserver) ControllerServiceImplBase(io.pravega.controller.stream.api.grpc.v1.ControllerServiceGrpc.ControllerServiceImplBase) SegmentId(io.pravega.controller.stream.api.grpc.v1.Controller.SegmentId) ServerRequest(io.pravega.controller.stream.api.grpc.v1.Controller.ServerRequest) Before(org.junit.Before)

Aggregations

StreamObserver (io.grpc.stub.StreamObserver)1 SegmentId (io.pravega.controller.stream.api.grpc.v1.Controller.SegmentId)1 ServerRequest (io.pravega.controller.stream.api.grpc.v1.Controller.ServerRequest)1 ControllerServiceImplBase (io.pravega.controller.stream.api.grpc.v1.ControllerServiceGrpc.ControllerServiceImplBase)1 Before (org.junit.Before)1