use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.Server in project beam by apache.
the class BeamFnStatusClientTest method testWorkerStatusResponse.
@Test
public void testWorkerStatusResponse() throws Exception {
BlockingQueue<WorkerStatusResponse> values = new LinkedBlockingQueue<>();
BlockingQueue<StreamObserver<WorkerStatusRequest>> requestObservers = new LinkedBlockingQueue<>();
StreamObserver<WorkerStatusResponse> inboundServerObserver = TestStreams.withOnNext(values::add).build();
Server server = InProcessServerBuilder.forName(apiServiceDescriptor.getUrl()).addService(new BeamFnWorkerStatusImplBase() {
@Override
public StreamObserver<WorkerStatusResponse> workerStatus(StreamObserver<WorkerStatusRequest> responseObserver) {
Uninterruptibles.putUninterruptibly(requestObservers, responseObserver);
return inboundServerObserver;
}
}).build();
server.start();
try {
BundleProcessorCache processorCache = mock(BundleProcessorCache.class);
when(processorCache.getActiveBundleProcessors()).thenReturn(Collections.emptyMap());
ManagedChannelFactory channelFactory = ManagedChannelFactory.createInProcess();
new BeamFnStatusClient(apiServiceDescriptor, channelFactory::forDescriptor, processorCache, PipelineOptionsFactory.create(), Caches.noop());
StreamObserver<WorkerStatusRequest> requestObserver = requestObservers.take();
requestObserver.onNext(WorkerStatusRequest.newBuilder().setId("id").build());
WorkerStatusResponse response = values.take();
assertThat(response.getStatusInfo(), containsString("No active processing bundles."));
assertThat(response.getId(), is("id"));
} finally {
server.shutdownNow();
}
}
use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.Server in project beam by apache.
the class GrpcFnServer method create.
/**
* Create {@link GrpcFnServer}s for the provided {@link FnService}s running on a specified port.
*/
public static List<GrpcFnServer<? extends FnService>> create(List<? extends FnService> services, ApiServiceDescriptor endpoint, ServerFactory factory) throws IOException {
Server server = factory.create(Collections.unmodifiableList(services), endpoint);
AtomicInteger countdown = new AtomicInteger(services.size());
return Lists.transform(services, service -> new SharedGrpcFnServer<>(server, service, endpoint, countdown));
}
use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.Server in project beam by apache.
the class InProcessServerFactory method create.
@Override
public Server create(List<BindableService> services, ApiServiceDescriptor serviceDescriptor) throws IOException {
InProcessServerBuilder builder = InProcessServerBuilder.forName(serviceDescriptor.getUrl());
services.stream().forEach(service -> builder.addService(ServerInterceptors.intercept(service, GrpcContextHeaderAccessorProvider.interceptor())));
return builder.build().start();
}
use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.Server in project beam by apache.
the class InProcessServerFactory method allocateAddressAndCreate.
@Override
public Server allocateAddressAndCreate(List<BindableService> services, ApiServiceDescriptor.Builder builder) throws IOException {
String name = String.format("InProcessServer_%s", serviceNameUniqifier.getAndIncrement());
builder.setUrl(name);
InProcessServerBuilder serverBuilder = InProcessServerBuilder.forName(name);
services.stream().forEach(service -> serverBuilder.addService(ServerInterceptors.intercept(service, GrpcContextHeaderAccessorProvider.interceptor())));
return serverBuilder.build().start();
}
use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.Server in project hazelcast by hazelcast.
the class GrpcServiceTest method when_bidirectionalStreaming_distributed.
@Test
public void when_bidirectionalStreaming_distributed() throws IOException {
// Given
server = createServer(new GreeterServiceImpl());
final int port = server.getPort();
List<String> items = IntStream.range(0, ITEM_COUNT).mapToObj(Integer::toString).collect(toList());
Pipeline p = Pipeline.create();
BatchStageWithKey<String, String> stage = p.readFrom(TestSources.items(items)).groupingKey(i -> i);
// When
BatchStage<String> mapped = stage.mapUsingServiceAsync(bidirectionalStreaming(port), (service, key, item) -> {
HelloRequest req = HelloRequest.newBuilder().setName(item).build();
return service.call(req).thenApply(HelloReply::getMessage);
});
// Then
mapped.writeTo(AssertionSinks.assertCollected(e -> {
assertEquals("unexpected number of items received", ITEM_COUNT, e.size());
}));
instance().getJet().newJob(p).join();
}
Aggregations