use of io.grpc.xds.Bootstrapper.BootstrapInfo in project grpc-java by grpc.
the class BootstrapperImplTest method parseAuthorities.
@Test
public void parseAuthorities() throws Exception {
BootstrapperImpl.enableFederation = true;
String rawData = "{\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.authorities()).isEmpty();
rawData = "{\n" + " \"authorities\": {\n" + " \"a.com\": {\n" + " \"client_listener_resource_name_template\": \"xdstp://a.com/v1.Listener/id-%s\"\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));
info = bootstrapper.bootstrap();
assertThat(info.authorities()).hasSize(1);
AuthorityInfo authorityInfo = info.authorities().get("a.com");
assertThat(authorityInfo.clientListenerResourceNameTemplate()).isEqualTo("xdstp://a.com/v1.Listener/id-%s");
// Defaults to top-level servers.
assertThat(authorityInfo.xdsServers()).hasSize(1);
assertThat(authorityInfo.xdsServers().get(0).target()).isEqualTo(SERVER_URI);
rawData = "{\n" + " \"authorities\": {\n" + " \"a.com\": {\n" + " \"xds_servers\": [\n" + " {\n" + " \"server_uri\": \"td2.googleapis.com:443\",\n" + " \"channel_creds\": [\n" + " {\"type\": \"insecure\"}\n" + " ]\n" + " }\n" + " ]\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));
info = bootstrapper.bootstrap();
assertThat(info.authorities()).hasSize(1);
authorityInfo = info.authorities().get("a.com");
// Defaults to "xdstp://<authority_name>>/envoy.config.listener.v3.Listener/%s"
assertThat(authorityInfo.clientListenerResourceNameTemplate()).isEqualTo("xdstp://a.com/envoy.config.listener.v3.Listener/%s");
assertThat(authorityInfo.xdsServers()).hasSize(1);
assertThat(authorityInfo.xdsServers().get(0).target()).isEqualTo("td2.googleapis.com:443");
}
use of io.grpc.xds.Bootstrapper.BootstrapInfo in project grpc-java by grpc.
the class SharedXdsClientPoolProviderTest method refCountedXdsClientObjectPool_getObjectCreatesNewInstanceIfAlreadyShutdown.
@Test
public void refCountedXdsClientObjectPool_getObjectCreatesNewInstanceIfAlreadyShutdown() {
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);
XdsClient xdsClient1 = xdsClientPool.getObject();
assertThat(xdsClientPool.returnObject(xdsClient1)).isNull();
assertThat(xdsClient1.isShutDown()).isTrue();
XdsClient xdsClient2 = xdsClientPool.getObject();
assertThat(xdsClient2).isNotSameInstanceAs(xdsClient1);
xdsClientPool.returnObject(xdsClient2);
}
Aggregations