Search in sources :

Example 16 with CreateSubchannelArgs

use of io.grpc.LoadBalancer.CreateSubchannelArgs in project grpc-java by grpc.

the class LoadBalancerTest method createSubchannelArgs_build.

@Test
public void createSubchannelArgs_build() {
    CreateSubchannelArgs.Key<Object> testKey = CreateSubchannelArgs.Key.create("test-key");
    Object testValue = new Object();
    CreateSubchannelArgs args = CreateSubchannelArgs.newBuilder().setAddresses(eag).setAttributes(attrs).addOption(testKey, testValue).build();
    CreateSubchannelArgs rebuildedArgs = args.toBuilder().build();
    assertThat(rebuildedArgs.getAddresses()).containsExactly(eag);
    assertThat(rebuildedArgs.getAttributes()).isSameInstanceAs(attrs);
    assertThat(rebuildedArgs.getOption(testKey)).isSameInstanceAs(testValue);
}
Also used : CreateSubchannelArgs(io.grpc.LoadBalancer.CreateSubchannelArgs) Test(org.junit.Test)

Example 17 with CreateSubchannelArgs

use of io.grpc.LoadBalancer.CreateSubchannelArgs in project grpc-java by grpc.

the class LoadBalancerTest method createSubchannelArgs_option_addGet.

@Test
public void createSubchannelArgs_option_addGet() {
    String testValue = "test-value";
    CreateSubchannelArgs.Key<String> testKey = CreateSubchannelArgs.Key.create("test-key");
    CreateSubchannelArgs args = CreateSubchannelArgs.newBuilder().setAddresses(eag).setAttributes(attrs).addOption(testKey, testValue).build();
    assertThat(args.getOption(testKey)).isEqualTo(testValue);
}
Also used : CreateSubchannelArgs(io.grpc.LoadBalancer.CreateSubchannelArgs) Test(org.junit.Test)

Example 18 with CreateSubchannelArgs

use of io.grpc.LoadBalancer.CreateSubchannelArgs in project grpc-java by grpc.

the class LoadBalancerTest method createSubchannelArgs_option_keyOps.

@Test
public void createSubchannelArgs_option_keyOps() {
    CreateSubchannelArgs.Key<String> testKey = CreateSubchannelArgs.Key.create("test-key");
    String testValue = "test-value";
    CreateSubchannelArgs.Key<String> testWithDefaultKey = CreateSubchannelArgs.Key.createWithDefault("test-key", testValue);
    CreateSubchannelArgs args = CreateSubchannelArgs.newBuilder().setAddresses(eag).setAttributes(attrs).build();
    assertThat(args.getOption(testKey)).isNull();
    assertThat(args.getOption(testWithDefaultKey)).isSameInstanceAs(testValue);
}
Also used : CreateSubchannelArgs(io.grpc.LoadBalancer.CreateSubchannelArgs) Test(org.junit.Test)

Example 19 with CreateSubchannelArgs

use of io.grpc.LoadBalancer.CreateSubchannelArgs in project grpc-java by grpc.

the class LoadBalancerTest method createSubchannelArgs_toString.

@Test
public void createSubchannelArgs_toString() {
    CreateSubchannelArgs.Key<String> testKey = CreateSubchannelArgs.Key.create("test-key");
    CreateSubchannelArgs args = CreateSubchannelArgs.newBuilder().setAddresses(eag).setAttributes(attrs).addOption(testKey, "test-value").build();
    String str = args.toString();
    assertThat(str).contains("addrs=");
    assertThat(str).contains("attrs=");
    assertThat(str).contains("customOptions=");
}
Also used : CreateSubchannelArgs(io.grpc.LoadBalancer.CreateSubchannelArgs) Test(org.junit.Test)

Example 20 with CreateSubchannelArgs

use of io.grpc.LoadBalancer.CreateSubchannelArgs in project grpc-java by grpc.

the class AutoConfiguredLoadBalancerFactoryTest method handleResolvedAddressGroups_noLbPolicySelected_defaultToPickFirst.

@Test
public void handleResolvedAddressGroups_noLbPolicySelected_defaultToPickFirst() {
    final List<EquivalentAddressGroup> servers = Collections.singletonList(new EquivalentAddressGroup(new SocketAddress() {
    }));
    Helper helper = new TestHelper() {

        @Override
        public Subchannel createSubchannel(CreateSubchannelArgs args) {
            assertThat(args.getAddresses()).isEqualTo(servers);
            return new TestSubchannel(args);
        }
    };
    AutoConfiguredLoadBalancer lb = lbf.newLoadBalancer(helper);
    Status handleResult = lb.tryHandleResolvedAddresses(ResolvedAddresses.newBuilder().setAddresses(servers).setLoadBalancingPolicyConfig(null).build());
    assertThat(handleResult.getCode()).isEqualTo(Status.Code.OK);
    assertThat(lb.getDelegate()).isInstanceOf(PickFirstLoadBalancer.class);
}
Also used : ForwardingLoadBalancerHelper(io.grpc.util.ForwardingLoadBalancerHelper) Helper(io.grpc.LoadBalancer.Helper) AutoConfiguredLoadBalancer(io.grpc.internal.AutoConfiguredLoadBalancerFactory.AutoConfiguredLoadBalancer) Status(io.grpc.Status) CreateSubchannelArgs(io.grpc.LoadBalancer.CreateSubchannelArgs) EquivalentAddressGroup(io.grpc.EquivalentAddressGroup) SocketAddress(java.net.SocketAddress) InetSocketAddress(java.net.InetSocketAddress) Test(org.junit.Test)

Aggregations

CreateSubchannelArgs (io.grpc.LoadBalancer.CreateSubchannelArgs)32 Test (org.junit.Test)29 EquivalentAddressGroup (io.grpc.EquivalentAddressGroup)15 Subchannel (io.grpc.LoadBalancer.Subchannel)14 InOrder (org.mockito.InOrder)13 SubchannelPicker (io.grpc.LoadBalancer.SubchannelPicker)9 Status (io.grpc.Status)9 SocketAddress (java.net.SocketAddress)8 Attributes (io.grpc.Attributes)6 ConnectivityState (io.grpc.ConnectivityState)6 Helper (io.grpc.LoadBalancer.Helper)6 SubchannelStateListener (io.grpc.LoadBalancer.SubchannelStateListener)6 AutoConfiguredLoadBalancer (io.grpc.internal.AutoConfiguredLoadBalancerFactory.AutoConfiguredLoadBalancer)5 InitialLoadBalanceResponse (io.grpc.lb.v1.InitialLoadBalanceResponse)5 LoadBalanceResponse (io.grpc.lb.v1.LoadBalanceResponse)5 ForwardingLoadBalancerHelper (io.grpc.util.ForwardingLoadBalancerHelper)5 InetSocketAddress (java.net.InetSocketAddress)5 ConnectivityStateInfo (io.grpc.ConnectivityStateInfo)4 InitialLoadBalanceRequest (io.grpc.lb.v1.InitialLoadBalanceRequest)4 LoadBalanceRequest (io.grpc.lb.v1.LoadBalanceRequest)4