use of io.grpc.xds.Bootstrapper.BootstrapInfo in project grpc-java by grpc.
the class SharedXdsClientPoolProviderTest method refCountedXdsClientObjectPool_refCounted.
@Test
public void refCountedXdsClientObjectPool_refCounted() {
ServerInfo server = ServerInfo.create(SERVER_URI, InsecureChannelCredentials.create(), false);
BootstrapInfo bootstrapInfo = BootstrapInfo.builder().servers(Collections.singletonList(server)).node(node).build();
RefCountedXdsClientObjectPool xdsClientPool = new RefCountedXdsClientObjectPool(bootstrapInfo);
// getObject once
XdsClient xdsClient = xdsClientPool.getObject();
assertThat(xdsClient).isNotNull();
// getObject twice
assertThat(xdsClientPool.getObject()).isSameInstanceAs(xdsClient);
// returnObject once
assertThat(xdsClientPool.returnObject(xdsClient)).isNull();
assertThat(xdsClient.isShutDown()).isFalse();
// returnObject twice
assertThat(xdsClientPool.returnObject(xdsClient)).isNull();
assertThat(xdsClient.isShutDown()).isTrue();
}
use of io.grpc.xds.Bootstrapper.BootstrapInfo in project grpc-java by grpc.
the class SharedXdsClientPoolProviderTest method sharedXdsClientObjectPool.
@Test
public void sharedXdsClientObjectPool() throws XdsInitializationException {
ServerInfo server = ServerInfo.create(SERVER_URI, InsecureChannelCredentials.create(), false);
BootstrapInfo bootstrapInfo = BootstrapInfo.builder().servers(Collections.singletonList(server)).node(node).build();
when(bootstrapper.bootstrap()).thenReturn(bootstrapInfo);
SharedXdsClientPoolProvider provider = new SharedXdsClientPoolProvider(bootstrapper);
assertThat(provider.get()).isNull();
ObjectPool<XdsClient> xdsClientPool = provider.getOrCreate();
verify(bootstrapper).bootstrap();
assertThat(provider.getOrCreate()).isSameInstanceAs(xdsClientPool);
assertThat(provider.get()).isNotNull();
assertThat(provider.get()).isSameInstanceAs(xdsClientPool);
verifyNoMoreInteractions(bootstrapper);
}
use of io.grpc.xds.Bootstrapper.BootstrapInfo in project grpc-java by grpc.
the class SharedXdsClientPoolProviderTest method noServer.
@Test
public void noServer() throws XdsInitializationException {
BootstrapInfo bootstrapInfo = BootstrapInfo.builder().servers(Collections.<ServerInfo>emptyList()).node(node).build();
when(bootstrapper.bootstrap()).thenReturn(bootstrapInfo);
SharedXdsClientPoolProvider provider = new SharedXdsClientPoolProvider(bootstrapper);
thrown.expect(XdsInitializationException.class);
thrown.expectMessage("No xDS server provided");
provider.getOrCreate();
assertThat(provider.get()).isNull();
}
use of io.grpc.xds.Bootstrapper.BootstrapInfo in project grpc-java by grpc.
the class SharedXdsClientPoolProviderTest method refCountedXdsClientObjectPool_delayedCreation.
@Test
public void refCountedXdsClientObjectPool_delayedCreation() {
ServerInfo server = ServerInfo.create(SERVER_URI, InsecureChannelCredentials.create(), false);
BootstrapInfo bootstrapInfo = BootstrapInfo.builder().servers(Collections.singletonList(server)).node(node).build();
RefCountedXdsClientObjectPool xdsClientPool = new RefCountedXdsClientObjectPool(bootstrapInfo);
assertThat(xdsClientPool.getXdsClientForTest()).isNull();
XdsClient xdsClient = xdsClientPool.getObject();
assertThat(xdsClientPool.getXdsClientForTest()).isNotNull();
xdsClientPool.returnObject(xdsClient);
}
use of io.grpc.xds.Bootstrapper.BootstrapInfo in project grpc-java by grpc.
the class BootstrapperImplTest method parseBootstrap_grpcServerResourceId.
@Test
public void parseBootstrap_grpcServerResourceId() throws XdsInitializationException {
String rawData = "{\n" + " \"xds_servers\": [],\n" + " \"server_listener_resource_name_template\": \"grpc/serverx=%s\"\n" + "}";
bootstrapper.setFileReader(createFileReader(BOOTSTRAP_FILE_PATH, rawData));
BootstrapInfo info = bootstrapper.bootstrap();
assertThat(info.serverListenerResourceNameTemplate()).isEqualTo("grpc/serverx=%s");
}
Aggregations