use of io.grpc.ManagedChannel in project grpc-java by grpc.
the class GrpclbLoadBalancerTest method grpclbUpdatedAddresses_avoidsReconnect.
@Test
public void grpclbUpdatedAddresses_avoidsReconnect() {
List<EquivalentAddressGroup> backendList = createResolvedBackendAddresses(1);
List<EquivalentAddressGroup> grpclbBalancerList = createResolvedBalancerAddresses(1);
deliverResolvedAddresses(backendList, grpclbBalancerList);
verify(helper).createOobChannel(eq(xattr(grpclbBalancerList)), eq(lbAuthority(0) + NO_USE_AUTHORITY_SUFFIX));
ManagedChannel oobChannel = fakeOobChannels.poll();
assertEquals(1, lbRequestObservers.size());
List<EquivalentAddressGroup> backendList2 = createResolvedBackendAddresses(1);
List<EquivalentAddressGroup> grpclbBalancerList2 = createResolvedBalancerAddresses(2);
deliverResolvedAddresses(backendList2, grpclbBalancerList2);
verify(helper).updateOobChannelAddresses(eq(oobChannel), eq(xattr(grpclbBalancerList2)));
// No additional RPC
assertEquals(1, lbRequestObservers.size());
}
use of io.grpc.ManagedChannel in project grpc-java by grpc.
the class Http2OkHttpTest method hostnameVerifierWithBadHostname.
@Test
public void hostnameVerifierWithBadHostname() throws Exception {
int port = ((InetSocketAddress) getListenAddress()).getPort();
ManagedChannel channel = createChannelBuilderPreCredentialsApi().overrideAuthority(GrpcUtil.authorityFromHostAndPort(BAD_HOSTNAME, port)).hostnameVerifier(new HostnameVerifier() {
@Override
public boolean verify(String hostname, SSLSession session) {
return true;
}
}).build();
TestServiceGrpc.TestServiceBlockingStub blockingStub = TestServiceGrpc.newBlockingStub(channel);
blockingStub.emptyCall(Empty.getDefaultInstance());
channel.shutdown();
}
use of io.grpc.ManagedChannel in project grpc-java by grpc.
the class StressTestClient method runStressTest.
@VisibleForTesting
void runStressTest() throws Exception {
Preconditions.checkState(!shutdown, "client was shutdown.");
if (testCaseWeightPairs.isEmpty()) {
return;
}
int numChannels = addresses.size() * channelsPerServer;
int numThreads = numChannels * stubsPerChannel;
threadpool = MoreExecutors.listeningDecorator(newFixedThreadPool(numThreads));
int serverIdx = -1;
for (InetSocketAddress address : addresses) {
serverIdx++;
for (int i = 0; i < channelsPerServer; i++) {
ManagedChannel channel = createChannel(address);
channels.add(channel);
for (int j = 0; j < stubsPerChannel; j++) {
String gaugeName = String.format("/stress_test/server_%d/channel_%d/stub_%d/qps", serverIdx, i, j);
Worker worker = new Worker(channel, testCaseWeightPairs, durationSecs, gaugeName);
workerFutures.add(threadpool.submit(worker));
}
}
}
}
use of io.grpc.ManagedChannel in project grpc-java by grpc.
the class StressTestClient method shutdown.
@VisibleForTesting
void shutdown() {
if (shutdown) {
return;
}
shutdown = true;
for (ManagedChannel ch : channels) {
try {
ch.shutdownNow();
ch.awaitTermination(1, SECONDS);
} catch (Throwable t) {
log.log(Level.WARNING, "Error shutting down channel!", t);
}
}
try {
metricsServer.shutdownNow();
} catch (Throwable t) {
log.log(Level.WARNING, "Error shutting down metrics service!", t);
}
try {
if (threadpool != null) {
threadpool.shutdownNow();
}
} catch (Throwable t) {
log.log(Level.WARNING, "Error shutting down threadpool.", t);
}
}
use of io.grpc.ManagedChannel in project grpc-java by grpc.
the class HealthCheckingLoadBalancerFactoryTest method setup.
@Before
@SuppressWarnings("unchecked")
public void setup() throws Exception {
MockitoAnnotations.initMocks(this);
for (int i = 0; i < NUM_SUBCHANNELS; i++) {
HealthImpl healthImpl = new HealthImpl();
healthImpls[i] = healthImpl;
Server server = InProcessServerBuilder.forName("health-check-test-" + i).addService(healthImpl).directExecutor().build().start();
servers[i] = server;
ManagedChannel channel = InProcessChannelBuilder.forName("health-check-test-" + i).directExecutor().build();
channels[i] = channel;
EquivalentAddressGroup eag = new EquivalentAddressGroup(new FakeSocketAddress("address-" + i));
eags[i] = eag;
List<EquivalentAddressGroup> eagList = Arrays.asList(eag);
eagLists[i] = eagList;
mockStateListeners[i] = mock(SubchannelStateListener.class);
}
resolvedAddressList = Arrays.asList(eags);
when(backoffPolicyProvider.get()).thenReturn(backoffPolicy1, backoffPolicy2);
when(backoffPolicy1.nextBackoffNanos()).thenReturn(11L, 21L, 31L);
when(backoffPolicy2.nextBackoffNanos()).thenReturn(12L, 22L, 32L);
hcLbFactory = new HealthCheckingLoadBalancerFactory(origLbFactory, backoffPolicyProvider, clock.getStopwatchSupplier());
hcLb = hcLbFactory.newLoadBalancer(origHelper);
// Make sure all calls into the hcLb is from the syncContext
hcLbEventDelivery = new LoadBalancer() {
// Per LoadBalancer API, no more callbacks will be called after shutdown() is called.
boolean shutdown;
@Override
public void handleResolvedAddresses(final ResolvedAddresses resolvedAddresses) {
syncContext.execute(new Runnable() {
@Override
public void run() {
if (!shutdown) {
hcLb.handleResolvedAddresses(resolvedAddresses);
}
}
});
}
@Override
public void handleNameResolutionError(Status error) {
throw new AssertionError("Not supposed to be called");
}
@Override
public void shutdown() {
syncContext.execute(new Runnable() {
@Override
public void run() {
if (!shutdown) {
shutdown = true;
hcLb.shutdown();
}
}
});
}
};
verify(origLbFactory).newLoadBalancer(any(Helper.class));
}
Aggregations