use of io.grpc.xds.Bootstrapper.ServerInfo 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.ServerInfo 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.ServerInfo 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.ServerInfo in project grpc-java by grpc.
the class BootstrapperImplTest method parseBootstrap_singleXdsServer.
@Test
public void parseBootstrap_singleXdsServer() throws XdsInitializationException {
String rawData = "{\n" + " \"node\": {\n" + " \"id\": \"ENVOY_NODE_ID\",\n" + " \"cluster\": \"ENVOY_CLUSTER\",\n" + " \"locality\": {\n" + " \"region\": \"ENVOY_REGION\",\n" + " \"zone\": \"ENVOY_ZONE\",\n" + " \"sub_zone\": \"ENVOY_SUBZONE\"\n" + " },\n" + " \"metadata\": {\n" + " \"TRAFFICDIRECTOR_INTERCEPTION_PORT\": \"ENVOY_PORT\",\n" + " \"TRAFFICDIRECTOR_NETWORK_NAME\": \"VPC_NETWORK_NAME\"\n" + " }\n" + " },\n" + " \"xds_servers\": [\n" + " {\n" + " \"server_uri\": \"" + SERVER_URI + "\",\n" + " \"channel_creds\": [\n" + " {\"type\": \"insecure\"}\n" + " ]\n" + " }\n" + " ]\n" + "}";
bootstrapper.setFileReader(createFileReader(BOOTSTRAP_FILE_PATH, rawData));
BootstrapInfo info = bootstrapper.bootstrap();
assertThat(info.servers()).hasSize(1);
ServerInfo serverInfo = Iterables.getOnlyElement(info.servers());
assertThat(serverInfo.target()).isEqualTo(SERVER_URI);
assertThat(serverInfo.channelCredentials()).isInstanceOf(InsecureChannelCredentials.class);
assertThat(info.node()).isEqualTo(getNodeBuilder().setId("ENVOY_NODE_ID").setCluster("ENVOY_CLUSTER").setLocality(Locality.create("ENVOY_REGION", "ENVOY_ZONE", "ENVOY_SUBZONE")).setMetadata(ImmutableMap.of("TRAFFICDIRECTOR_INTERCEPTION_PORT", "ENVOY_PORT", "TRAFFICDIRECTOR_NETWORK_NAME", "VPC_NETWORK_NAME")).build());
}
use of io.grpc.xds.Bootstrapper.ServerInfo in project grpc-java by grpc.
the class BootstrapperImplTest method useV2ProtocolByDefault.
@Test
public void useV2ProtocolByDefault() throws XdsInitializationException {
String rawData = "{\n" + " \"xds_servers\": [\n" + " {\n" + " \"server_uri\": \"" + SERVER_URI + "\",\n" + " \"channel_creds\": [\n" + " {\"type\": \"insecure\"}\n" + " ],\n" + " \"server_features\": []\n" + " }\n" + " ]\n" + "}";
bootstrapper.setFileReader(createFileReader(BOOTSTRAP_FILE_PATH, rawData));
BootstrapInfo info = bootstrapper.bootstrap();
ServerInfo serverInfo = Iterables.getOnlyElement(info.servers());
assertThat(serverInfo.target()).isEqualTo(SERVER_URI);
assertThat(serverInfo.channelCredentials()).isInstanceOf(InsecureChannelCredentials.class);
assertThat(serverInfo.useProtocolV3()).isFalse();
}
Aggregations