Search in sources :

Example 1 with BootstrapInfo

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();
}
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 BootstrapInfo

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

Example 3 with BootstrapInfo

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

Example 4 with BootstrapInfo

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);
}
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 5 with BootstrapInfo

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

Aggregations

BootstrapInfo (io.grpc.xds.Bootstrapper.BootstrapInfo)17 Test (org.junit.Test)15 ServerInfo (io.grpc.xds.Bootstrapper.ServerInfo)10 RefCountedXdsClientObjectPool (io.grpc.xds.SharedXdsClientPoolProvider.RefCountedXdsClientObjectPool)3 AuthorityInfo (io.grpc.xds.Bootstrapper.AuthorityInfo)2