use of org.apache.beam.model.fnexecution.v1.BeamFnApi.LogEntry in project beam by apache.
the class GrpcLoggingServiceTest method testServerCloseHangsUpClients.
@Test
public void testServerCloseHangsUpClients() throws Exception {
LinkedBlockingQueue<LogEntry> logs = new LinkedBlockingQueue<>();
ExecutorService executorService = Executors.newCachedThreadPool();
Collection<Future<Void>> futures = new ArrayList<>();
final GrpcLoggingService service = GrpcLoggingService.forWriter(new CollectionAppendingLogWriter(logs));
try (GrpcFnServer<GrpcLoggingService> server = GrpcFnServer.allocatePortAndCreateFor(service, InProcessServerFactory.create())) {
for (int i = 1; i <= 3; ++i) {
final long instructionId = i;
futures.add(executorService.submit(() -> {
{
CountDownLatch waitForServerHangup = new CountDownLatch(1);
ManagedChannel channel = InProcessChannelBuilder.forName(server.getApiServiceDescriptor().getUrl()).build();
StreamObserver<LogEntry.List> outboundObserver = BeamFnLoggingGrpc.newStub(channel).logging(TestStreams.withOnNext(messageDiscarder).withOnCompleted(new CountDown(waitForServerHangup)).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();
}
}
for (Future<Void> future : futures) {
future.get();
}
}
Aggregations