Search in sources :

Example 1 with ServerInfo

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();
}
Also used : BootstrapInfo(io.grpc.xds.Bootstrapper.BootstrapInfo) ServerInfo(io.grpc.xds.Bootstrapper.ServerInfo) RefCountedXdsClientObjectPool(io.grpc.xds.SharedXdsClientPoolProvider.RefCountedXdsClientObjectPool) Test(org.junit.Test)

Example 2 with ServerInfo

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);
}
Also used : BootstrapInfo(io.grpc.xds.Bootstrapper.BootstrapInfo) ServerInfo(io.grpc.xds.Bootstrapper.ServerInfo) Test(org.junit.Test)

Example 3 with ServerInfo

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);
}
Also used : BootstrapInfo(io.grpc.xds.Bootstrapper.BootstrapInfo) ServerInfo(io.grpc.xds.Bootstrapper.ServerInfo) RefCountedXdsClientObjectPool(io.grpc.xds.SharedXdsClientPoolProvider.RefCountedXdsClientObjectPool) Test(org.junit.Test)

Example 4 with ServerInfo

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());
}
Also used : BootstrapInfo(io.grpc.xds.Bootstrapper.BootstrapInfo) ServerInfo(io.grpc.xds.Bootstrapper.ServerInfo) Test(org.junit.Test)

Example 5 with ServerInfo

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();
}
Also used : BootstrapInfo(io.grpc.xds.Bootstrapper.BootstrapInfo) ServerInfo(io.grpc.xds.Bootstrapper.ServerInfo) Test(org.junit.Test)

Aggregations

ServerInfo (io.grpc.xds.Bootstrapper.ServerInfo)12 BootstrapInfo (io.grpc.xds.Bootstrapper.BootstrapInfo)10 Test (org.junit.Test)10 RefCountedXdsClientObjectPool (io.grpc.xds.SharedXdsClientPoolProvider.RefCountedXdsClientObjectPool)3 InvalidProtocolBufferException (com.google.protobuf.InvalidProtocolBufferException)1 Thresholds (io.envoyproxy.envoy.config.cluster.v3.CircuitBreakers.Thresholds)1 Cluster (io.envoyproxy.envoy.config.cluster.v3.Cluster)1 DiscoveryType (io.envoyproxy.envoy.config.cluster.v3.Cluster.DiscoveryType)1 SocketAddress (io.envoyproxy.envoy.config.core.v3.SocketAddress)1 ClusterLoadAssignment (io.envoyproxy.envoy.config.endpoint.v3.ClusterLoadAssignment)1 XdsChannelFactory (io.grpc.xds.ClientXdsClient.XdsChannelFactory)1 LbEndpoint (io.grpc.xds.Endpoints.LbEndpoint)1 UpstreamTlsContext (io.grpc.xds.EnvoyServerProtoData.UpstreamTlsContext)1 InetSocketAddress (java.net.InetSocketAddress)1 Before (org.junit.Before)1