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);
}
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);
}
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);
}
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=");
}
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);
}
Aggregations