use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.Channel in project beam by apache.
the class GrpcWindmillServer method initializeLocalHost.
private synchronized void initializeLocalHost(int port) throws IOException {
this.logEveryNStreamFailures = 1;
this.maxBackoff = Duration.millis(500);
// For local testing use short deadlines.
this.unaryDeadlineSeconds = 10;
Channel channel = localhostChannel(port);
if (streamingEngineEnabled()) {
this.stubList.add(CloudWindmillServiceV1Alpha1Grpc.newStub(channel));
this.syncStubList.add(CloudWindmillServiceV1Alpha1Grpc.newBlockingStub(channel));
} else {
this.syncApplianceStub = WindmillApplianceGrpc.newBlockingStub(channel);
}
}
use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.Channel in project beam by apache.
the class GrpcWindmillServer method remoteChannel.
private Channel remoteChannel(HostAndPort endpoint) throws IOException {
NettyChannelBuilder builder = NettyChannelBuilder.forAddress(endpoint.getHost(), endpoint.getPort());
int timeoutSec = options.getWindmillServiceRpcChannelAliveTimeoutSec();
if (timeoutSec > 0) {
builder = builder.keepAliveTime(timeoutSec, TimeUnit.SECONDS).keepAliveTimeout(timeoutSec, TimeUnit.SECONDS).keepAliveWithoutCalls(true);
}
return builder.flowControlWindow(10 * 1024 * 1024).maxInboundMessageSize(java.lang.Integer.MAX_VALUE).maxInboundMetadataSize(1024 * 1024).negotiationType(NegotiationType.TLS).sslContext(GrpcSslContexts.forClient().ciphers(null).build()).build();
}
use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.Channel in project beam by apache.
the class BeamFnDataGrpcServiceTest method testMessageReceivedByProperClientWhenThereAreMultipleClients.
@Test
public void testMessageReceivedByProperClientWhenThereAreMultipleClients() throws Exception {
ConcurrentHashMap<String, LinkedBlockingQueue<Elements>> clientInboundElements = new ConcurrentHashMap<>();
ExecutorService executorService = Executors.newCachedThreadPool();
CountDownLatch waitForInboundElements = new CountDownLatch(1);
int numberOfClients = 3;
int numberOfMessages = 3;
for (int client = 0; client < numberOfClients; ++client) {
String clientId = Integer.toString(client);
clientInboundElements.put(clientId, new LinkedBlockingQueue<>());
executorService.submit(() -> {
ManagedChannel channel = ManagedChannelFactory.createDefault().withInterceptors(Arrays.asList(AddHarnessIdInterceptor.create(clientId))).forDescriptor(service.getApiServiceDescriptor());
StreamObserver<BeamFnApi.Elements> outboundObserver = BeamFnDataGrpc.newStub(channel).data(TestStreams.withOnNext(clientInboundElements.get(clientId)::add).build());
waitForInboundElements.await();
outboundObserver.onCompleted();
return null;
});
}
for (int client = 0; client < numberOfClients; ++client) {
for (int i = 0; i < 3; ++i) {
String instructionId = client + "-" + i;
CloseableFnDataReceiver<WindowedValue<String>> consumer = service.getDataService(Integer.toString(client)).send(LogicalEndpoint.data(instructionId, TRANSFORM_ID), CODER);
consumer.accept(valueInGlobalWindow("A" + instructionId));
consumer.accept(valueInGlobalWindow("B" + instructionId));
consumer.accept(valueInGlobalWindow("C" + instructionId));
consumer.close();
}
}
for (int client = 0; client < numberOfClients; ++client) {
// Specifically copy the elements to a new list so we perform blocking calls on the queue
// to ensure the elements arrive.
ArrayList<BeamFnApi.Elements> copy = new ArrayList<>();
for (int i = 0; i < numberOfMessages; ++i) {
copy.add(clientInboundElements.get(Integer.toString(client)).take());
}
assertThat(copy, containsInAnyOrder(elementsWithData(client + "-" + 0), elementsWithData(client + "-" + 1), elementsWithData(client + "-" + 2)));
}
waitForInboundElements.countDown();
}
use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.Channel in project beam by apache.
the class BeamFnLoggingServiceTest method testServerCloseHangsUpClients.
@Test
public void testServerCloseHangsUpClients() throws Exception {
LinkedBlockingQueue<BeamFnApi.LogEntry> logs = new LinkedBlockingQueue<>();
ExecutorService executorService = Executors.newCachedThreadPool();
Collection<Future<Void>> futures = new ArrayList<>();
try (BeamFnLoggingService service = new BeamFnLoggingService(findOpenPort(), logs::add, ServerStreamObserverFactory.fromOptions(PipelineOptionsFactory.create())::from, GrpcContextHeaderAccessorProvider.getHeaderAccessor())) {
server = ServerFactory.createDefault().create(Arrays.asList(service), service.getApiServiceDescriptor());
for (int i = 1; i <= 3; ++i) {
long instructionId = i;
futures.add(executorService.submit(() -> {
CountDownLatch waitForServerHangup = new CountDownLatch(1);
ManagedChannel channel = ManagedChannelFactory.createDefault().withInterceptors(Arrays.asList(AddHarnessIdInterceptor.create(WORKER_ID + instructionId))).forDescriptor(service.getApiServiceDescriptor());
StreamObserver<BeamFnApi.LogEntry.List> outboundObserver = BeamFnLoggingGrpc.newStub(channel).logging(TestStreams.withOnNext(BeamFnLoggingServiceTest::discardMessage).withOnCompleted(waitForServerHangup::countDown).build());
outboundObserver.onNext(createLogsWithIds(instructionId));
waitForServerHangup.await();
return null;
}));
}
// Wait till each client has sent their message showing that they have connected.
for (int i = 1; i <= 3; ++i) {
logs.take();
}
service.close();
server.shutdownNow();
}
for (Future<Void> future : futures) {
future.get();
}
}
use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.Channel in project beam by apache.
the class BeamFnLoggingServiceTest method testMultipleClientsSuccessfullyProcessed.
@Test
public void testMultipleClientsSuccessfullyProcessed() throws Exception {
ConcurrentLinkedQueue<BeamFnApi.LogEntry> logs = new ConcurrentLinkedQueue<>();
try (BeamFnLoggingService service = new BeamFnLoggingService(findOpenPort(), logs::add, ServerStreamObserverFactory.fromOptions(PipelineOptionsFactory.create())::from, GrpcContextHeaderAccessorProvider.getHeaderAccessor())) {
server = ServerFactory.createDefault().create(Arrays.asList(service), service.getApiServiceDescriptor());
Collection<Callable<Void>> tasks = new ArrayList<>();
for (int i = 1; i <= 3; ++i) {
int instructionId = i;
tasks.add(() -> {
CountDownLatch waitForServerHangup = new CountDownLatch(1);
ManagedChannel channel = ManagedChannelFactory.createDefault().withInterceptors(Arrays.asList(AddHarnessIdInterceptor.create(WORKER_ID + instructionId))).forDescriptor(service.getApiServiceDescriptor());
StreamObserver<BeamFnApi.LogEntry.List> outboundObserver = BeamFnLoggingGrpc.newStub(channel).logging(TestStreams.withOnNext(BeamFnLoggingServiceTest::discardMessage).withOnCompleted(waitForServerHangup::countDown).build());
outboundObserver.onNext(createLogsWithIds(instructionId, -instructionId));
outboundObserver.onCompleted();
waitForServerHangup.await();
return null;
});
}
ExecutorService executorService = Executors.newCachedThreadPool();
executorService.invokeAll(tasks);
assertThat(logs, containsInAnyOrder(createLogWithId(1L), createLogWithId(2L), createLogWithId(3L), createLogWithId(-1L), createLogWithId(-2L), createLogWithId(-3L)));
}
}
Aggregations