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();
}
Aggregations