mirror of https://github.com/grpc/grpc-java.git
core: delete ManagedChannelBuilder.loadBalancerFactory() and all deprecated factories (#5480)
This has been deprecated since 1.18.0
This commit is contained in:
parent
a395eec4a3
commit
39e66fa22b
|
|
@ -123,13 +123,6 @@ public abstract class ForwardingChannelBuilder<T extends ForwardingChannelBuilde
|
|||
return thisT();
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
@Override
|
||||
public T loadBalancerFactory(LoadBalancer.Factory loadBalancerFactory) {
|
||||
delegate().loadBalancerFactory(loadBalancerFactory);
|
||||
return thisT();
|
||||
}
|
||||
|
||||
@Override
|
||||
public T defaultLoadBalancingPolicy(String policy) {
|
||||
delegate().defaultLoadBalancingPolicy(policy);
|
||||
|
|
|
|||
|
|
@ -220,27 +220,6 @@ public abstract class ManagedChannelBuilder<T extends ManagedChannelBuilder<T>>
|
|||
@ExperimentalApi("https://github.com/grpc/grpc-java/issues/1770")
|
||||
public abstract T nameResolverFactory(NameResolver.Factory resolverFactory);
|
||||
|
||||
/**
|
||||
* Provides a custom {@link LoadBalancer.Factory} for the channel.
|
||||
*
|
||||
* <p>If this method is not called, the builder will use {@link PickFirstBalancerFactory}
|
||||
* for the channel.
|
||||
*
|
||||
* <p>This method is implemented by all stock channel builders that
|
||||
* are shipped with gRPC, but may not be implemented by custom channel builders, in which case
|
||||
* this method will throw.
|
||||
*
|
||||
* @deprecated this method disables service-config-based policy selection, and may cause problems
|
||||
* if NameResolver returns GRPCLB balancer addresses but a non-GRPCLB LoadBalancer
|
||||
* is passed in here. Use {@link #defaultLoadBalancingPolicy} instead.
|
||||
*
|
||||
* @return this
|
||||
* @since 1.0.0
|
||||
*/
|
||||
@Deprecated
|
||||
@ExperimentalApi("https://github.com/grpc/grpc-java/issues/1771")
|
||||
public abstract T loadBalancerFactory(LoadBalancer.Factory loadBalancerFactory);
|
||||
|
||||
/**
|
||||
* Sets the default load-balancing policy that will be used if the service config doesn't specify
|
||||
* one. If not set, the default will be the "pick_first" policy.
|
||||
|
|
|
|||
|
|
@ -1,56 +0,0 @@
|
|||
/*
|
||||
* Copyright 2015 The gRPC Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package io.grpc;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
/**
|
||||
* A {@link LoadBalancer} that provides no load balancing mechanism over the
|
||||
* addresses from the {@link NameResolver}. The channel's default behavior
|
||||
* (currently pick-first) is used for all addresses found.
|
||||
*
|
||||
* @deprecated this is the default balancer and should not be referenced to. This will be deleted
|
||||
* soon.
|
||||
*/
|
||||
@ExperimentalApi("https://github.com/grpc/grpc-java/issues/1771")
|
||||
@Deprecated
|
||||
public final class PickFirstBalancerFactory extends LoadBalancer.Factory {
|
||||
private static PickFirstBalancerFactory instance;
|
||||
|
||||
private final LoadBalancerProvider provider;
|
||||
|
||||
private PickFirstBalancerFactory() {
|
||||
provider = checkNotNull(
|
||||
LoadBalancerRegistry.getDefaultRegistry().getProvider("pick_first"),
|
||||
"pick_first balancer not available");
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets an instance of this factory.
|
||||
*/
|
||||
public static synchronized PickFirstBalancerFactory getInstance() {
|
||||
if (instance == null) {
|
||||
instance = new PickFirstBalancerFactory();
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
@Override
|
||||
public LoadBalancer newLoadBalancer(LoadBalancer.Helper helper) {
|
||||
return provider.newLoadBalancer(helper);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,41 +0,0 @@
|
|||
/*
|
||||
* Copyright 2016 The gRPC Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package io.grpc;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verifyZeroInteractions;
|
||||
|
||||
import io.grpc.LoadBalancer.Helper;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.JUnit4;
|
||||
|
||||
/** Unit test for {@link PickFirstBalancerFactory}. */
|
||||
@RunWith(JUnit4.class)
|
||||
public class PickFirstBalancerFactoryTest {
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Test
|
||||
public void setUp() {
|
||||
Helper helper = mock(Helper.class);
|
||||
assertThat(
|
||||
PickFirstBalancerFactory.getInstance().newLoadBalancer(helper).getClass().getName())
|
||||
.isEqualTo("io.grpc.internal.PickFirstLoadBalancer");
|
||||
verifyZeroInteractions(helper);
|
||||
}
|
||||
}
|
||||
|
|
@ -28,7 +28,6 @@ import io.grpc.CompressorRegistry;
|
|||
import io.grpc.DecompressorRegistry;
|
||||
import io.grpc.EquivalentAddressGroup;
|
||||
import io.grpc.InternalChannelz;
|
||||
import io.grpc.LoadBalancer;
|
||||
import io.grpc.ManagedChannel;
|
||||
import io.grpc.ManagedChannelBuilder;
|
||||
import io.grpc.NameResolver;
|
||||
|
|
@ -116,8 +115,6 @@ public abstract class AbstractManagedChannelImplBuilder
|
|||
@Nullable
|
||||
String authorityOverride;
|
||||
|
||||
@Nullable LoadBalancer.Factory loadBalancerFactory;
|
||||
|
||||
String defaultLbPolicy = GrpcUtil.DEFAULT_LB_POLICY;
|
||||
|
||||
boolean fullStreamDecompression;
|
||||
|
|
@ -246,16 +243,6 @@ public abstract class AbstractManagedChannelImplBuilder
|
|||
return thisT();
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
@Override
|
||||
public final T loadBalancerFactory(LoadBalancer.Factory loadBalancerFactory) {
|
||||
Preconditions.checkState(directServerAddress == null,
|
||||
"directServerAddress is set (%s), which forbids the use of LoadBalancer.Factory",
|
||||
directServerAddress);
|
||||
this.loadBalancerFactory = loadBalancerFactory;
|
||||
return thisT();
|
||||
}
|
||||
|
||||
@Override
|
||||
public final T defaultLoadBalancingPolicy(String policy) {
|
||||
Preconditions.checkState(directServerAddress == null,
|
||||
|
|
|
|||
|
|
@ -559,14 +559,9 @@ final class ManagedChannelImpl extends ManagedChannel implements
|
|||
ProxyDetector proxyDetector =
|
||||
builder.proxyDetector != null ? builder.proxyDetector : GrpcUtil.getDefaultProxyDetector();
|
||||
this.retryEnabled = builder.retryEnabled && !builder.temporarilyDisableRetry;
|
||||
AutoConfiguredLoadBalancerFactory autoConfiguredLoadBalancerFactory = null;
|
||||
if (builder.loadBalancerFactory == null) {
|
||||
autoConfiguredLoadBalancerFactory =
|
||||
new AutoConfiguredLoadBalancerFactory(builder.defaultLbPolicy);
|
||||
this.loadBalancerFactory = autoConfiguredLoadBalancerFactory;
|
||||
} else {
|
||||
this.loadBalancerFactory = builder.loadBalancerFactory;
|
||||
}
|
||||
AutoConfiguredLoadBalancerFactory autoConfiguredLoadBalancerFactory =
|
||||
new AutoConfiguredLoadBalancerFactory(builder.defaultLbPolicy);
|
||||
this.loadBalancerFactory = autoConfiguredLoadBalancerFactory;
|
||||
this.nameResolverHelper =
|
||||
new NrHelper(
|
||||
builder.getDefaultPort(),
|
||||
|
|
@ -583,7 +578,6 @@ final class ManagedChannelImpl extends ManagedChannel implements
|
|||
logId, builder.maxTraceEvents, timeProvider.currentTimeNanos(),
|
||||
"Channel for '" + target + "'");
|
||||
channelLogger = new ChannelLoggerImpl(channelTracer, timeProvider);
|
||||
|
||||
this.executorPool = checkNotNull(builder.executorPool, "executorPool");
|
||||
this.balancerRpcExecutorPool = checkNotNull(balancerRpcExecutorPool, "balancerRpcExecutorPool");
|
||||
this.balancerRpcExecutorHolder = new ExecutorHolder(balancerRpcExecutorPool);
|
||||
|
|
|
|||
|
|
@ -1,61 +0,0 @@
|
|||
/*
|
||||
* Copyright 2016 The gRPC Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package io.grpc.util;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import io.grpc.ExperimentalApi;
|
||||
import io.grpc.LoadBalancer;
|
||||
import io.grpc.LoadBalancerProvider;
|
||||
import io.grpc.LoadBalancerRegistry;
|
||||
|
||||
/**
|
||||
* A {@link LoadBalancer} that provides round-robin load balancing mechanism over the
|
||||
* addresses.
|
||||
*
|
||||
* @deprecated use {@link io.grpc.LoadBalancerRegistry#getProvider} with "round_robin" policy. This
|
||||
* class will be deleted soon.
|
||||
*/
|
||||
@ExperimentalApi("https://github.com/grpc/grpc-java/issues/1771")
|
||||
@Deprecated
|
||||
public final class RoundRobinLoadBalancerFactory extends LoadBalancer.Factory {
|
||||
|
||||
private static RoundRobinLoadBalancerFactory instance;
|
||||
|
||||
private final LoadBalancerProvider provider;
|
||||
|
||||
private RoundRobinLoadBalancerFactory() {
|
||||
provider = checkNotNull(
|
||||
LoadBalancerRegistry.getDefaultRegistry().getProvider("round_robin"),
|
||||
"round_robin balancer not available");
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the singleton instance of this factory.
|
||||
*/
|
||||
public static synchronized RoundRobinLoadBalancerFactory getInstance() {
|
||||
if (instance == null) {
|
||||
instance = new RoundRobinLoadBalancerFactory();
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
@Override
|
||||
public LoadBalancer newLoadBalancer(LoadBalancer.Helper helper) {
|
||||
return provider.newLoadBalancer(helper);
|
||||
}
|
||||
}
|
||||
|
|
@ -33,7 +33,6 @@ import io.grpc.ClientCall;
|
|||
import io.grpc.ClientInterceptor;
|
||||
import io.grpc.CompressorRegistry;
|
||||
import io.grpc.DecompressorRegistry;
|
||||
import io.grpc.LoadBalancer;
|
||||
import io.grpc.MethodDescriptor;
|
||||
import io.grpc.NameResolver;
|
||||
import io.grpc.internal.testing.StatsTestUtils.FakeStatsRecorder;
|
||||
|
|
@ -125,34 +124,6 @@ public class AbstractManagedChannelImplBuilderTest {
|
|||
directAddressBuilder.nameResolverFactory(mock(NameResolver.Factory.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void loadBalancerFactory_default() {
|
||||
assertNull(builder.loadBalancerFactory);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Deprecated
|
||||
public void loadBalancerFactory_normal() {
|
||||
LoadBalancer.Factory loadBalancerFactory = mock(LoadBalancer.Factory.class);
|
||||
assertEquals(builder, builder.loadBalancerFactory(loadBalancerFactory));
|
||||
assertEquals(loadBalancerFactory, builder.loadBalancerFactory);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Deprecated
|
||||
public void loadBalancerFactory_null() {
|
||||
LoadBalancer.Factory defaultValue = builder.loadBalancerFactory;
|
||||
builder.loadBalancerFactory(mock(LoadBalancer.Factory.class));
|
||||
assertEquals(builder, builder.loadBalancerFactory(null));
|
||||
assertEquals(defaultValue, builder.loadBalancerFactory);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalStateException.class)
|
||||
@Deprecated
|
||||
public void loadBalancerFactory_notAllowedWithDirectAddress() {
|
||||
directAddressBuilder.loadBalancerFactory(mock(LoadBalancer.Factory.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void defaultLoadBalancingPolicy_default() {
|
||||
assertEquals("pick_first", builder.defaultLbPolicy);
|
||||
|
|
|
|||
|
|
@ -959,74 +959,6 @@ public class ManagedChannelImplTest {
|
|||
serviceConfig, actualAttrs.get(GrpcAttributes.NAME_RESOLVER_SERVICE_CONFIG));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Deprecated
|
||||
public void nameResolverReturnsEmptySubLists_becomeErrorByDefault_lbFactorySetDirectly()
|
||||
throws Exception {
|
||||
String errorDescription = "returned an empty list";
|
||||
|
||||
// Pass a FakeNameResolverFactory with an empty list and LB config
|
||||
FakeNameResolverFactory nameResolverFactory =
|
||||
new FakeNameResolverFactory.Builder(expectedUri).build();
|
||||
Map<String, Object> serviceConfig =
|
||||
parseConfig("{\"loadBalancingConfig\": [ {\"mock_lb\": { \"setting1\": \"high\" } } ] }");
|
||||
Attributes serviceConfigAttrs =
|
||||
Attributes.newBuilder()
|
||||
.set(GrpcAttributes.NAME_RESOLVER_SERVICE_CONFIG, serviceConfig)
|
||||
.build();
|
||||
nameResolverFactory.nextResolvedAttributes.set(serviceConfigAttrs);
|
||||
channelBuilder.nameResolverFactory(nameResolverFactory);
|
||||
|
||||
// Pass a LoadBalancerFactory directly to the builder, bypassing
|
||||
// AutoConfiguredLoadBalancerFactory. The empty-list check is done in ManagedChannelImpl rather
|
||||
// than AutoConfiguredLoadBalancerFactory
|
||||
channelBuilder.loadBalancerFactory(mockLoadBalancerProvider);
|
||||
|
||||
createChannel();
|
||||
|
||||
// LoadBalancer received the error
|
||||
verify(mockLoadBalancerProvider).newLoadBalancer(any(Helper.class));
|
||||
verify(mockLoadBalancer).handleNameResolutionError(statusCaptor.capture());
|
||||
Status status = statusCaptor.getValue();
|
||||
assertSame(Status.Code.UNAVAILABLE, status.getCode());
|
||||
Truth.assertThat(status.getDescription()).contains(errorDescription);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Deprecated
|
||||
public void nameResolverReturnsEmptySubLists_optionallyAllowed_lbFactorySetDirectly()
|
||||
throws Exception {
|
||||
when(mockLoadBalancer.canHandleEmptyAddressListFromNameResolution()).thenReturn(true);
|
||||
|
||||
// Pass a FakeNameResolverFactory with an empty list and LB config
|
||||
FakeNameResolverFactory nameResolverFactory =
|
||||
new FakeNameResolverFactory.Builder(expectedUri).build();
|
||||
Map<String, Object> serviceConfig =
|
||||
parseConfig("{\"loadBalancingConfig\": [ {\"mock_lb\": { \"setting1\": \"high\" } } ] }");
|
||||
Attributes serviceConfigAttrs =
|
||||
Attributes.newBuilder()
|
||||
.set(GrpcAttributes.NAME_RESOLVER_SERVICE_CONFIG, serviceConfig)
|
||||
.build();
|
||||
nameResolverFactory.nextResolvedAttributes.set(serviceConfigAttrs);
|
||||
channelBuilder.nameResolverFactory(nameResolverFactory);
|
||||
|
||||
// Pass a LoadBalancerFactory directly to the builder, bypassing
|
||||
// AutoConfiguredLoadBalancerFactory. The empty-list check is done in ManagedChannelImpl rather
|
||||
// than AutoConfiguredLoadBalancerFactory
|
||||
channelBuilder.loadBalancerFactory(mockLoadBalancerProvider);
|
||||
|
||||
createChannel();
|
||||
|
||||
// LoadBalancer received the empty list and the LB config
|
||||
verify(mockLoadBalancerProvider).newLoadBalancer(any(Helper.class));
|
||||
verify(mockLoadBalancer).handleResolvedAddresses(
|
||||
ResolvedAddresses.newBuilder()
|
||||
.setAddresses(Collections.<EquivalentAddressGroup>emptyList())
|
||||
.setAttributes(serviceConfigAttrs)
|
||||
.build());
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void loadBalancerThrowsInHandleResolvedAddresses() {
|
||||
RuntimeException ex = new RuntimeException("simulated");
|
||||
|
|
|
|||
|
|
@ -1,41 +0,0 @@
|
|||
/*
|
||||
* Copyright 2016 The gRPC Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package io.grpc.util;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verifyZeroInteractions;
|
||||
|
||||
import io.grpc.LoadBalancer.Helper;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.JUnit4;
|
||||
|
||||
/** Unit test for {@link RoundRobinLoadBalancerFactory}. */
|
||||
@RunWith(JUnit4.class)
|
||||
public class RoundRobinLoadBalancerFactoryTest {
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Test
|
||||
public void getInstance() {
|
||||
Helper helper = mock(Helper.class);
|
||||
assertThat(
|
||||
RoundRobinLoadBalancerFactory.getInstance().newLoadBalancer(helper).getClass().getName())
|
||||
.isEqualTo("io.grpc.util.RoundRobinLoadBalancer");
|
||||
verifyZeroInteractions(helper);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,64 +0,0 @@
|
|||
/*
|
||||
* Copyright 2017 The gRPC Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package io.grpc.grpclb;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import io.grpc.ExperimentalApi;
|
||||
import io.grpc.LoadBalancer;
|
||||
import io.grpc.LoadBalancerProvider;
|
||||
import io.grpc.LoadBalancerRegistry;
|
||||
|
||||
/**
|
||||
* A factory for {@link LoadBalancer}s that uses the GRPCLB protocol.
|
||||
*
|
||||
* <p><b>Experimental:</b>This only works with the GRPCLB load-balancer service, which is not
|
||||
* available yet. Right now it's only good for internal testing.
|
||||
*
|
||||
* @deprecated The "grpclb" policy will be selected when environment is set up correctly, thus no
|
||||
* need to directly reference the factory. If explicit selection is needed, use {@link
|
||||
* io.grpc.LoadBalancerRegistry#getProvider} with "grpclb" policy. This class will be
|
||||
* deleted soon.
|
||||
*/
|
||||
@ExperimentalApi("https://github.com/grpc/grpc-java/issues/1782")
|
||||
@Deprecated
|
||||
public final class GrpclbLoadBalancerFactory extends LoadBalancer.Factory {
|
||||
|
||||
private static GrpclbLoadBalancerFactory instance;
|
||||
private final LoadBalancerProvider provider;
|
||||
|
||||
private GrpclbLoadBalancerFactory() {
|
||||
provider = checkNotNull(
|
||||
LoadBalancerRegistry.getDefaultRegistry().getProvider("grpclb"),
|
||||
"grpclb balancer not available");
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the instance.
|
||||
*/
|
||||
public static GrpclbLoadBalancerFactory getInstance() {
|
||||
if (instance == null) {
|
||||
instance = new GrpclbLoadBalancerFactory();
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
@Override
|
||||
public LoadBalancer newLoadBalancer(LoadBalancer.Helper helper) {
|
||||
return provider.newLoadBalancer(helper);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,63 +0,0 @@
|
|||
/*
|
||||
* Copyright 2016 The gRPC Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package io.grpc.grpclb;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.verifyNoMoreInteractions;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import io.grpc.ChannelLogger;
|
||||
import io.grpc.LoadBalancer.Helper;
|
||||
import io.grpc.SynchronizationContext;
|
||||
import io.grpc.internal.FakeClock;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.JUnit4;
|
||||
|
||||
/** Unit test for {@link GrpclbLoadBalancerFactory}. */
|
||||
@RunWith(JUnit4.class)
|
||||
public class GrpclbLoadBalancerFactoryTest {
|
||||
private final FakeClock clock = new FakeClock();
|
||||
private final SynchronizationContext syncContext = new SynchronizationContext(
|
||||
new Thread.UncaughtExceptionHandler() {
|
||||
@Override
|
||||
public void uncaughtException(Thread t, Throwable e) {
|
||||
throw new AssertionError(e);
|
||||
}
|
||||
});
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Test
|
||||
public void getInstance() {
|
||||
Helper helper = mock(Helper.class);
|
||||
when(helper.getSynchronizationContext()).thenReturn(syncContext);
|
||||
when(helper.getScheduledExecutorService()).thenReturn(clock.getScheduledExecutorService());
|
||||
when(helper.getAuthority()).thenReturn("fakeauthority");
|
||||
when(helper.getChannelLogger()).thenReturn(mock(ChannelLogger.class));
|
||||
|
||||
assertThat(GrpclbLoadBalancerFactory.getInstance().newLoadBalancer(helper))
|
||||
.isInstanceOf(io.grpc.grpclb.GrpclbLoadBalancer.class);
|
||||
|
||||
verify(helper).getSynchronizationContext();
|
||||
verify(helper).getScheduledExecutorService();
|
||||
verify(helper).getAuthority();
|
||||
verify(helper).getChannelLogger();
|
||||
verifyNoMoreInteractions(helper);
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue