@Test public void shouldReturnNonOverlappingGeese() { AtomicInteger counter = new AtomicInteger(); UnaryOperator<Integer> sequentialGenerator = i -> counter.getAndIncrement(); int numberOfGeese = 5; grpcServerRule.getServiceRegistry() .addService(new GeeseService((min, max) -> numberOfGeese, sequentialGenerator, new InjectedFailureProvider())); GeeseServiceBlockingStub geeseClient = GeeseServiceGrpc.newBlockingStub(grpcServerRule.getChannel()); GeeseResponse response = geeseClient.getGeese(GetGeeseRequest.newBuilder() .setLinesCount(1).setGooseWidth(10).setLineWidth(50).build()); GeeseResponse geeseResponse = GeeseResponse.newBuilder() .addLines(GeeseLine.newBuilder().addAllGeesePositions(asList(0, 10, 20, 30, 40)).build()) .build(); assertThat(response).isEqualTo(geeseResponse); }
@Override public void getGeese(GetGeeseRequest request, StreamObserver<GeeseResponse> responseObserver) { GeeseResponse.Builder response = GeeseResponse.newBuilder(); int gooseWidth = Integer.max(request.getGooseWidth(), DEFAULT_GOOSE_WIDTH); IntStream.range(0, request.getLinesCount()) .mapToObj(i -> generateGeeseLine(request.getLineWidth(), gooseWidth)) .forEach(response::addLines); responseObserver.onNext(response.build()); responseObserver.onCompleted(); }
GeeseService extends GeeseServiceImplBase { @Override public void getGeese(GetGeeseRequest request, StreamObserver<GeeseResponse> responseObserver) { GeeseResponse.Builder response = GeeseResponse.newBuilder(); int gooseWidth = Integer.max(request.getGooseWidth(), DEFAULT_GOOSE_WIDTH); IntStream.range(0, request.getLinesCount()) .mapToObj(i -> generateGeeseLine(request.getLineWidth(), gooseWidth)) .forEach(response::addLines); responseObserver.onNext(response.build()); responseObserver.onCompleted(); } }
GeeseService extends GeeseServiceImplBase { @Override public void getGeese(GetGeeseRequest request, StreamObserver<GeeseResponse> responseObserver) { GeeseResponse.Builder response = GeeseResponse.newBuilder(); int gooseWidth = Integer.max(request.getGooseWidth(), DEFAULT_GOOSE_WIDTH); IntStream.range(0, request.getLinesCount()) .mapToObj(i -> generateGeeseLine(request.getLineWidth(), gooseWidth)) .forEach(response::addLines); responseObserver.onNext(response.build()); responseObserver.onCompleted(); } GeeseService(BinaryOperator<Integer> numberOfGeeseGenerator,
                 UnaryOperator<Integer> geeseGenerator,
                 FixtureFailureProvider fixtureFailureProvider); }
GeeseService extends GeeseServiceImplBase { @Override public void getGeese(GetGeeseRequest request, StreamObserver<GeeseResponse> responseObserver) { GeeseResponse.Builder response = GeeseResponse.newBuilder(); int gooseWidth = Integer.max(request.getGooseWidth(), DEFAULT_GOOSE_WIDTH); IntStream.range(0, request.getLinesCount()) .mapToObj(i -> generateGeeseLine(request.getLineWidth(), gooseWidth)) .forEach(response::addLines); responseObserver.onNext(response.build()); responseObserver.onCompleted(); } GeeseService(BinaryOperator<Integer> numberOfGeeseGenerator,
                 UnaryOperator<Integer> geeseGenerator,
                 FixtureFailureProvider fixtureFailureProvider); @Override void getGeese(GetGeeseRequest request,
                         StreamObserver<GeeseResponse> responseObserver); }
GeeseService extends GeeseServiceImplBase { @Override public void getGeese(GetGeeseRequest request, StreamObserver<GeeseResponse> responseObserver) { GeeseResponse.Builder response = GeeseResponse.newBuilder(); int gooseWidth = Integer.max(request.getGooseWidth(), DEFAULT_GOOSE_WIDTH); IntStream.range(0, request.getLinesCount()) .mapToObj(i -> generateGeeseLine(request.getLineWidth(), gooseWidth)) .forEach(response::addLines); responseObserver.onNext(response.build()); responseObserver.onCompleted(); } GeeseService(BinaryOperator<Integer> numberOfGeeseGenerator,
                 UnaryOperator<Integer> geeseGenerator,
                 FixtureFailureProvider fixtureFailureProvider); @Override void getGeese(GetGeeseRequest request,
                         StreamObserver<GeeseResponse> responseObserver);  }