Search in sources :

Example 1 with RefCountedXdsClientObjectPool

use of io.grpc.xds.SharedXdsClientPoolProvider.RefCountedXdsClientObjectPool 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 RefCountedXdsClientObjectPool

use of io.grpc.xds.SharedXdsClientPoolProvider.RefCountedXdsClientObjectPool 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 3 with RefCountedXdsClientObjectPool

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

Aggregations

BootstrapInfo (io.grpc.xds.Bootstrapper.BootstrapInfo)3 ServerInfo (io.grpc.xds.Bootstrapper.ServerInfo)3 RefCountedXdsClientObjectPool (io.grpc.xds.SharedXdsClientPoolProvider.RefCountedXdsClientObjectPool)3 Test (org.junit.Test)3