use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.ManagedChannel 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();
}
}
use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.ManagedChannel in project grpc-java by grpc.
the class AndroidChannelBuilderTest method networkChanges_api24.
@Test
@Config(sdk = 24)
public void networkChanges_api24() {
shadowOf(connectivityManager).setActiveNetworkInfo(MOBILE_DISCONNECTED);
TestChannel delegateChannel = new TestChannel();
ManagedChannel androidChannel = new AndroidChannelBuilder.AndroidChannel(delegateChannel, ApplicationProvider.getApplicationContext());
assertThat(delegateChannel.enterIdleCount).isEqualTo(0);
// Establish an initial network connection
shadowOf(connectivityManager).setActiveNetworkInfo(MOBILE_CONNECTED);
assertThat(delegateChannel.enterIdleCount).isEqualTo(1);
// Switch to another network to trigger enterIdle()
shadowOf(connectivityManager).setActiveNetworkInfo(WIFI_CONNECTED);
assertThat(delegateChannel.enterIdleCount).isEqualTo(2);
// Switch to an offline network and then to null
shadowOf(connectivityManager).setActiveNetworkInfo(WIFI_DISCONNECTED);
shadowOf(connectivityManager).setActiveNetworkInfo(null);
assertThat(delegateChannel.enterIdleCount).isEqualTo(2);
// Establish a connection
shadowOf(connectivityManager).setActiveNetworkInfo(MOBILE_CONNECTED);
assertThat(delegateChannel.enterIdleCount).isEqualTo(3);
// Disconnect, then shutdown the channel and verify that the callback has been unregistered
shadowOf(connectivityManager).setActiveNetworkInfo(null);
androidChannel.shutdown();
shadowOf(connectivityManager).setActiveNetworkInfo(MOBILE_CONNECTED);
assertThat(delegateChannel.enterIdleCount).isEqualTo(3);
}
use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.ManagedChannel in project grpc-java by grpc.
the class AndroidChannelBuilderTest method shutdownNowUnregistersNetworkCallback_api24.
@Test
@Config(sdk = 24)
public void shutdownNowUnregistersNetworkCallback_api24() {
shadowOf(connectivityManager).setActiveNetworkInfo(null);
TestChannel delegateChannel = new TestChannel();
ManagedChannel androidChannel = new AndroidChannelBuilder.AndroidChannel(delegateChannel, ApplicationProvider.getApplicationContext());
androidChannel.shutdownNow();
shadowOf(connectivityManager).setActiveNetworkInfo(WIFI_CONNECTED);
assertThat(delegateChannel.enterIdleCount).isEqualTo(0);
}
use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.ManagedChannel in project grpc-java by grpc.
the class AndroidChannelBuilderTest method nullContextDoesNotThrow_api24.
@Test
@Config(sdk = 24)
public void nullContextDoesNotThrow_api24() {
shadowOf(connectivityManager).setActiveNetworkInfo(MOBILE_DISCONNECTED);
TestChannel delegateChannel = new TestChannel();
ManagedChannel androidChannel = new AndroidChannelBuilder.AndroidChannel(delegateChannel, null);
// Network change and shutdown should be no-op for the channel without an Android Context
shadowOf(connectivityManager).setActiveNetworkInfo(MOBILE_CONNECTED);
androidChannel.shutdown();
assertThat(delegateChannel.enterIdleCount).isEqualTo(0);
}
use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.ManagedChannel in project grpc-java by grpc.
the class AndroidChannelBuilderTest method shutdownNowUnregistersBroadcastReceiver_api23.
@Test
@Config(sdk = 23)
public void shutdownNowUnregistersBroadcastReceiver_api23() {
TestChannel delegateChannel = new TestChannel();
ManagedChannel androidChannel = new AndroidChannelBuilder.AndroidChannel(delegateChannel, ApplicationProvider.getApplicationContext());
shadowOf(connectivityManager).setActiveNetworkInfo(null);
ApplicationProvider.getApplicationContext().sendBroadcast(new Intent(ConnectivityManager.CONNECTIVITY_ACTION));
androidChannel.shutdownNow();
shadowOf(connectivityManager).setActiveNetworkInfo(WIFI_CONNECTED);
ApplicationProvider.getApplicationContext().sendBroadcast(new Intent(ConnectivityManager.CONNECTIVITY_ACTION));
assertThat(delegateChannel.enterIdleCount).isEqualTo(0);
}
Aggregations