Search in sources :

Example 1 with ServerResponse

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

Example 2 with ServerResponse

use of io.pravega.controller.stream.api.grpc.v1.Controller.ServerResponse 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)2 SegmentId (io.pravega.controller.stream.api.grpc.v1.Controller.SegmentId)2 ServerRequest (io.pravega.controller.stream.api.grpc.v1.Controller.ServerRequest)2 ControllerServiceImplBase (io.pravega.controller.stream.api.grpc.v1.ControllerServiceGrpc.ControllerServiceImplBase)2 Before (org.junit.Before)2