api: delete LoadBalancer.Helper APIs that had been deprecated for a long time (#7793)

This commit is contained in:
Chengyuan Zhang 2021-01-11 15:25:35 -08:00 committed by GitHub
parent ca7f1e4cee
commit b66d182bb9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
15 changed files with 0 additions and 390 deletions

View File

@ -904,45 +904,6 @@ public abstract class LoadBalancer {
@ThreadSafe
@ExperimentalApi("https://github.com/grpc/grpc-java/issues/1771")
public abstract static class Helper {
/**
* Equivalent to {@link #createSubchannel(List, Attributes)} with the given single {@code
* EquivalentAddressGroup}.
*
* @since 1.2.0
* @deprecated Use {@link #createSubchannel(io.grpc.LoadBalancer.CreateSubchannelArgs)}
* instead. Note the new API must be called from {@link #getSynchronizationContext
* the Synchronization Context}.
*/
@Deprecated
public final Subchannel createSubchannel(EquivalentAddressGroup addrs, Attributes attrs) {
checkNotNull(addrs, "addrs");
return createSubchannel(Collections.singletonList(addrs), attrs);
}
/**
* Creates a Subchannel, which is a logical connection to the given group of addresses which are
* considered equivalent. The {@code attrs} are custom attributes associated with this
* Subchannel, and can be accessed later through {@link Subchannel#getAttributes
* Subchannel.getAttributes()}.
*
* <p>It is recommended you call this method from the Synchronization Context, otherwise your
* logic around the creation may race with {@link #handleSubchannelState}. See
* <a href="https://github.com/grpc/grpc-java/issues/5015">#5015</a> for more discussions.
*
* <p>The LoadBalancer is responsible for closing unused Subchannels, and closing all
* Subchannels within {@link #shutdown}.
*
* @throws IllegalArgumentException if {@code addrs} is empty
* @since 1.14.0
* @deprecated Use {@link #createSubchannel(io.grpc.LoadBalancer.CreateSubchannelArgs)}
* instead. Note the new API must be called from {@link #getSynchronizationContext
* the Synchronization Context}.
*/
@Deprecated
public Subchannel createSubchannel(List<EquivalentAddressGroup> addrs, Attributes attrs) {
throw new UnsupportedOperationException();
}
/**
* Creates a Subchannel, which is a logical connection to the given group of addresses which are
* considered equivalent. The {@code attrs} are custom attributes associated with this
@ -960,44 +921,6 @@ public abstract class LoadBalancer {
throw new UnsupportedOperationException();
}
/**
* Equivalent to {@link #updateSubchannelAddresses(io.grpc.LoadBalancer.Subchannel, List)} with
* the given single {@code EquivalentAddressGroup}.
*
* <p>It should be called from the Synchronization Context. Currently will log a warning if
* violated. It will become an exception eventually. See <a
* href="https://github.com/grpc/grpc-java/issues/5015">#5015</a> for the background.
*
* @since 1.4.0
* @deprecated use {@link Subchannel#updateAddresses} instead
*/
@Deprecated
public final void updateSubchannelAddresses(
Subchannel subchannel, EquivalentAddressGroup addrs) {
checkNotNull(addrs, "addrs");
updateSubchannelAddresses(subchannel, Collections.singletonList(addrs));
}
/**
* Replaces the existing addresses used with {@code subchannel}. This method is superior to
* {@link #createSubchannel} when the new and old addresses overlap, since the subchannel can
* continue using an existing connection.
*
* <p>It should be called from the Synchronization Context. Currently will log a warning if
* violated. It will become an exception eventually. See <a
* href="https://github.com/grpc/grpc-java/issues/5015">#5015</a> for the background.
*
* @throws IllegalArgumentException if {@code subchannel} was not returned from {@link
* #createSubchannel} or {@code addrs} is empty
* @since 1.14.0
* @deprecated use {@link Subchannel#updateAddresses} instead
*/
@Deprecated
public void updateSubchannelAddresses(
Subchannel subchannel, List<EquivalentAddressGroup> addrs) {
throw new UnsupportedOperationException();
}
/**
* Out-of-band channel for LoadBalancers own RPC needs, e.g., talking to an external
* load-balancer service.
@ -1115,18 +1038,6 @@ public abstract class LoadBalancer {
throw new UnsupportedOperationException();
}
/**
* Schedule a task to be run in the Synchronization Context, which serializes the task with the
* callback methods on the {@link LoadBalancer} interface.
*
* @since 1.2.0
* @deprecated use/implement {@code getSynchronizationContext()} instead
*/
@Deprecated
public void runSerialized(Runnable task) {
getSynchronizationContext().execute(task);
}
/**
* Returns a {@link SynchronizationContext} that runs tasks in the same Synchronization Context
* as that the callback methods on the {@link LoadBalancer} interface are run in.
@ -1157,17 +1068,6 @@ public abstract class LoadBalancer {
throw new UnsupportedOperationException();
}
/**
* Returns the NameResolver of the channel.
*
* @since 1.2.0
*
* @deprecated this method will be deleted in a future release. If you think it shouldn't be
* deleted, please file an issue on <a href="https://github.com/grpc/grpc-java">github</a>.
*/
@Deprecated
public abstract NameResolver.Factory getNameResolverFactory();
/**
* Returns the authority string of the channel, which is derived from the DNS-style target name.
* If overridden by a load balancer, {@link #getUnsafeChannelCredentials} must also be

View File

@ -45,7 +45,6 @@ public class LoadBalancerTest {
private final Attributes attrs = Attributes.newBuilder()
.set(Attributes.Key.create("trash"), new Object())
.build();
private final Subchannel emptySubchannel = new EmptySubchannel();
@Test
public void pickResult_withSubchannel() {
@ -123,38 +122,6 @@ public class LoadBalancerTest {
assertThat(error1).isNotEqualTo(drop1);
}
@Deprecated
@Test
public void helper_createSubchannel_old_delegates() {
class OverrideCreateSubchannel extends NoopHelper {
boolean ran;
@Override
public Subchannel createSubchannel(List<EquivalentAddressGroup> addrsIn, Attributes attrsIn) {
assertThat(addrsIn).hasSize(1);
assertThat(addrsIn.get(0)).isSameInstanceAs(eag);
assertThat(attrsIn).isSameInstanceAs(attrs);
ran = true;
return subchannel;
}
}
OverrideCreateSubchannel helper = new OverrideCreateSubchannel();
assertThat(helper.createSubchannel(eag, attrs)).isSameInstanceAs(subchannel);
assertThat(helper.ran).isTrue();
}
@Test
@SuppressWarnings("deprecation")
public void helper_createSubchannelList_oldApi_throws() {
try {
new NoopHelper().createSubchannel(Arrays.asList(eag), attrs);
fail("Should throw");
} catch (UnsupportedOperationException e) {
// expected
}
}
@Test
public void helper_createSubchannelList_throws() {
try {
@ -168,33 +135,6 @@ public class LoadBalancerTest {
}
}
@Deprecated
@Test
public void helper_updateSubchannelAddresses_delegates() {
class OverrideUpdateSubchannel extends NoopHelper {
boolean ran;
@Override
public void updateSubchannelAddresses(
Subchannel subchannelIn, List<EquivalentAddressGroup> addrsIn) {
assertThat(subchannelIn).isSameInstanceAs(emptySubchannel);
assertThat(addrsIn).hasSize(1);
assertThat(addrsIn.get(0)).isSameInstanceAs(eag);
ran = true;
}
}
OverrideUpdateSubchannel helper = new OverrideUpdateSubchannel();
helper.updateSubchannelAddresses(emptySubchannel, eag);
assertThat(helper.ran).isTrue();
}
@Deprecated
@Test(expected = UnsupportedOperationException.class)
public void helper_updateSubchannelAddressesList_throws() {
new NoopHelper().updateSubchannelAddresses(null, Arrays.asList(eag));
}
@Test
public void subchannel_getAddresses_delegates() {
class OverrideGetAllAddresses extends EmptySubchannel {
@ -410,12 +350,6 @@ public class LoadBalancerTest {
return null;
}
@Deprecated
@Override
public NameResolver.Factory getNameResolverFactory() {
return null;
}
@Override public String getAuthority() {
return null;
}

View File

@ -1388,36 +1388,6 @@ final class ManagedChannelImpl extends ManagedChannel implements
private class LbHelperImpl extends LoadBalancer.Helper {
AutoConfiguredLoadBalancer lb;
@Deprecated
@Override
public AbstractSubchannel createSubchannel(
List<EquivalentAddressGroup> addressGroups, Attributes attrs) {
logWarningIfNotInSyncContext("createSubchannel()");
// TODO(ejona): can we be even stricter? Like loadBalancer == null?
checkNotNull(addressGroups, "addressGroups");
checkNotNull(attrs, "attrs");
final SubchannelImpl subchannel = createSubchannelInternal(
CreateSubchannelArgs.newBuilder()
.setAddresses(addressGroups)
.setAttributes(attrs)
.build());
final SubchannelStateListener listener =
new LoadBalancer.SubchannelStateListener() {
@Override
public void onSubchannelState(ConnectivityStateInfo newState) {
// Call LB only if it's not shutdown. If LB is shutdown, lbHelper won't match.
if (LbHelperImpl.this != ManagedChannelImpl.this.lbHelper) {
return;
}
lb.handleSubchannelState(subchannel, newState);
}
};
subchannel.internalStart(listener);
return subchannel;
}
@Override
public AbstractSubchannel createSubchannel(CreateSubchannelArgs args) {
syncContext.throwIfNotInThisSynchronizationContext();
@ -1469,16 +1439,6 @@ final class ManagedChannelImpl extends ManagedChannel implements
syncContext.execute(new LoadBalancerRefreshNameResolution());
}
@Deprecated
@Override
public void updateSubchannelAddresses(
LoadBalancer.Subchannel subchannel, List<EquivalentAddressGroup> addrs) {
checkArgument(subchannel instanceof SubchannelImpl,
"subchannel must have been returned from createSubchannel");
logWarningIfNotInSyncContext("updateSubchannelAddresses()");
((InternalSubchannel) subchannel.getInternalSubchannel()).updateAddresses(addrs);
}
@Override
public ManagedChannel createOobChannel(EquivalentAddressGroup addressGroup, String authority) {
// TODO(ejona): can we be even stricter? Like terminating?
@ -1616,12 +1576,6 @@ final class ManagedChannelImpl extends ManagedChannel implements
return ManagedChannelImpl.this.authority();
}
@Deprecated
@Override
public NameResolver.Factory getNameResolverFactory() {
return nameResolverFactory;
}
@Override
public SynchronizationContext getSynchronizationContext() {
return syncContext;

View File

@ -17,7 +17,6 @@
package io.grpc.util;
import com.google.common.base.MoreObjects;
import io.grpc.Attributes;
import io.grpc.ChannelCredentials;
import io.grpc.ChannelLogger;
import io.grpc.ConnectivityState;
@ -32,7 +31,6 @@ import io.grpc.ManagedChannelBuilder;
import io.grpc.NameResolver;
import io.grpc.NameResolverRegistry;
import io.grpc.SynchronizationContext;
import java.util.List;
import java.util.concurrent.ScheduledExecutorService;
@ExperimentalApi("https://github.com/grpc/grpc-java/issues/1771")
@ -42,24 +40,11 @@ public abstract class ForwardingLoadBalancerHelper extends LoadBalancer.Helper {
*/
protected abstract LoadBalancer.Helper delegate();
@Deprecated
@Override
public Subchannel createSubchannel(List<EquivalentAddressGroup> addrs, Attributes attrs) {
return delegate().createSubchannel(addrs, attrs);
}
@Override
public Subchannel createSubchannel(CreateSubchannelArgs args) {
return delegate().createSubchannel(args);
}
@Deprecated
@Override
public void updateSubchannelAddresses(
Subchannel subchannel, List<EquivalentAddressGroup> addrs) {
delegate().updateSubchannelAddresses(subchannel, addrs);
}
@Override
public ManagedChannel createOobChannel(EquivalentAddressGroup eag, String authority) {
return delegate().createOobChannel(eag, authority);
@ -97,18 +82,6 @@ public abstract class ForwardingLoadBalancerHelper extends LoadBalancer.Helper {
delegate().refreshNameResolution();
}
@Override
@Deprecated
public void runSerialized(Runnable task) {
delegate().runSerialized(task);
}
@Deprecated
@Override
public NameResolver.Factory getNameResolverFactory() {
return delegate().getNameResolverFactory();
}
@Override
public String getAuthority() {
return delegate().getAuthority();

View File

@ -134,10 +134,6 @@ import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicLong;
import java.util.concurrent.atomic.AtomicReference;
import java.util.logging.Handler;
import java.util.logging.Level;
import java.util.logging.LogRecord;
import java.util.logging.Logger;
import javax.annotation.Nullable;
import org.junit.After;
import org.junit.Assert;
@ -367,89 +363,6 @@ public class ManagedChannelImplTest {
LoadBalancerRegistry.getDefaultRegistry().deregister(mockLoadBalancerProvider);
}
@Deprecated
@Test
public void createSubchannel_old_outsideSynchronizationContextShouldLogWarning() {
createChannel();
final AtomicReference<LogRecord> logRef = new AtomicReference<>();
Handler handler = new Handler() {
@Override
public void publish(LogRecord record) {
logRef.set(record);
}
@Override
public void flush() {
}
@Override
public void close() throws SecurityException {
}
};
Logger logger = Logger.getLogger(ManagedChannelImpl.class.getName());
try {
logger.addHandler(handler);
helper.createSubchannel(addressGroup, Attributes.EMPTY);
LogRecord record = logRef.get();
assertThat(record.getLevel()).isEqualTo(Level.WARNING);
assertThat(record.getMessage()).contains(
"createSubchannel() should be called from SynchronizationContext");
assertThat(record.getThrown()).isInstanceOf(IllegalStateException.class);
} finally {
logger.removeHandler(handler);
}
}
@Deprecated
@Test
public void createSubchannel_old_insideSyncContextFollowedByRequestConnectionShouldSucceed() {
createChannel();
final AtomicReference<Throwable> error = new AtomicReference<>();
helper.getSynchronizationContext().execute(new Runnable() {
@Override
public void run() {
try {
Subchannel subchannel = helper.createSubchannel(addressGroup, Attributes.EMPTY);
subchannel.requestConnection();
} catch (Throwable e) {
error.set(e);
}
}
});
assertThat(error.get()).isNull();
}
@Deprecated
@Test
@SuppressWarnings("deprecation")
public void createSubchannel_old_propagateSubchannelStatesToOldApi() {
createChannel();
Subchannel subchannel = helper.createSubchannel(addressGroup, Attributes.EMPTY);
subchannel.requestConnection();
verify(mockTransportFactory)
.newClientTransport(
any(SocketAddress.class), any(ClientTransportOptions.class), any(ChannelLogger.class));
verify(mockLoadBalancer).handleSubchannelState(
same(subchannel), eq(ConnectivityStateInfo.forNonError(CONNECTING)));
MockClientTransportInfo transportInfo = transports.poll();
transportInfo.listener.transportReady();
verify(mockLoadBalancer).handleSubchannelState(
same(subchannel), eq(ConnectivityStateInfo.forNonError(READY)));
channel.shutdown();
verify(mockLoadBalancer).shutdown();
subchannel.shutdown();
verify(mockLoadBalancer, atLeast(0)).canHandleEmptyAddressListFromNameResolution();
verify(mockLoadBalancer, atLeast(0)).handleNameResolutionError(any(Status.class));
// handleSubchannelState() should not be called after shutdown()
verifyNoMoreInteractions(mockLoadBalancer);
}
@Test
public void createSubchannel_outsideSynchronizationContextShouldThrow() {
createChannel();

View File

@ -25,7 +25,6 @@ import static org.junit.Assert.assertEquals;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.ArgumentMatchers.isA;
import static org.mockito.Mockito.any;
import static org.mockito.Mockito.atLeast;
import static org.mockito.Mockito.inOrder;
import static org.mockito.Mockito.never;
@ -114,11 +113,8 @@ public class PickFirstLoadBalancerTest {
}
@After
@SuppressWarnings("deprecation")
public void tearDown() throws Exception {
verifyNoMoreInteractions(mockArgs);
verify(mockHelper, never()).createSubchannel(
ArgumentMatchers.<EquivalentAddressGroup>anyList(), any(Attributes.class));
}
@Test

View File

@ -71,7 +71,6 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
import org.mockito.ArgumentCaptor;
import org.mockito.ArgumentMatchers;
import org.mockito.Captor;
import org.mockito.InOrder;
import org.mockito.Mock;
@ -141,11 +140,8 @@ public class RoundRobinLoadBalancerTest {
}
@After
@SuppressWarnings("deprecation")
public void tearDown() throws Exception {
verifyNoMoreInteractions(mockArgs);
verify(mockHelper, never()).createSubchannel(
ArgumentMatchers.<List<EquivalentAddressGroup>>any(), any(Attributes.class));
}
@Test

View File

@ -65,7 +65,6 @@ import io.grpc.LoadBalancer.SubchannelPicker;
import io.grpc.LoadBalancer.SubchannelStateListener;
import io.grpc.ManagedChannel;
import io.grpc.Metadata;
import io.grpc.NameResolver;
import io.grpc.Status;
import io.grpc.Status.Code;
import io.grpc.SynchronizationContext;
@ -2650,12 +2649,6 @@ public class GrpclbLoadBalancerTest {
currentPicker = newPicker;
}
@Override
@SuppressWarnings("deprecation")
public NameResolver.Factory getNameResolverFactory() {
return mock(NameResolver.Factory.class);
}
@Override
public void refreshNameResolution() {
}

View File

@ -46,7 +46,6 @@ import io.grpc.LoadBalancerProvider;
import io.grpc.ManagedChannel;
import io.grpc.ManagedChannelBuilder;
import io.grpc.Metadata;
import io.grpc.NameResolver;
import io.grpc.NameResolver.ConfigOrError;
import io.grpc.Status;
import io.grpc.Status.Code;
@ -578,12 +577,6 @@ public class CachingRlsLbClientTest {
// no-op
}
@Override
@Deprecated
public NameResolver.Factory getNameResolverFactory() {
throw new UnsupportedOperationException();
}
@Override
public String getAuthority() {
throw new UnsupportedOperationException();

View File

@ -50,7 +50,6 @@ import io.grpc.Metadata;
import io.grpc.MethodDescriptor;
import io.grpc.MethodDescriptor.Marshaller;
import io.grpc.MethodDescriptor.MethodType;
import io.grpc.NameResolver;
import io.grpc.NameResolver.ConfigOrError;
import io.grpc.Status;
import io.grpc.SynchronizationContext;
@ -471,12 +470,6 @@ public class RlsLoadBalancerTest {
// no-op
}
@Override
@Deprecated
public NameResolver.Factory getNameResolverFactory() {
throw new UnsupportedOperationException();
}
@Override
public String getAuthority() {
return "fake-bigtable.googleapis.com";

View File

@ -55,7 +55,6 @@ import io.grpc.LoadBalancer.Subchannel;
import io.grpc.LoadBalancer.SubchannelPicker;
import io.grpc.LoadBalancer.SubchannelStateListener;
import io.grpc.ManagedChannel;
import io.grpc.NameResolver;
import io.grpc.Server;
import io.grpc.Status;
import io.grpc.Status.Code;
@ -1263,12 +1262,6 @@ public class HealthCheckingLoadBalancerFactoryTest {
return clock.getScheduledExecutorService();
}
@Deprecated
@Override
public NameResolver.Factory getNameResolverFactory() {
throw new AssertionError("Should not be called");
}
@Override
public String getAuthority() {
throw new AssertionError("Should not be called");

View File

@ -34,7 +34,6 @@ import io.grpc.LoadBalancer.SubchannelPicker;
import io.grpc.LoadBalancerProvider;
import io.grpc.LoadBalancerRegistry;
import io.grpc.ManagedChannel;
import io.grpc.NameResolver;
import io.grpc.Status;
import io.grpc.Status.Code;
import io.grpc.SynchronizationContext;
@ -432,12 +431,6 @@ public class CdsLoadBalancerTest {
return syncContext;
}
@Deprecated
@Override
public NameResolver.Factory getNameResolverFactory() {
throw new UnsupportedOperationException("should not be called");
}
@Override
public String getAuthority() {
return AUTHORITY;

View File

@ -38,7 +38,6 @@ import io.grpc.LoadBalancer.SubchannelPicker;
import io.grpc.LoadBalancerProvider;
import io.grpc.ManagedChannel;
import io.grpc.Metadata;
import io.grpc.NameResolver;
import io.grpc.Status;
import io.grpc.Status.Code;
import io.grpc.SynchronizationContext;
@ -614,12 +613,6 @@ public class ClusterImplLoadBalancerTest {
throw new UnsupportedOperationException("should not be called");
}
@Deprecated
@Override
public NameResolver.Factory getNameResolverFactory() {
throw new UnsupportedOperationException("should not be called");
}
@Override
public String getAuthority() {
return AUTHORITY;

View File

@ -39,7 +39,6 @@ import io.grpc.LoadBalancer.SubchannelPicker;
import io.grpc.LoadBalancerProvider;
import io.grpc.LoadBalancerRegistry;
import io.grpc.ManagedChannel;
import io.grpc.NameResolver;
import io.grpc.Status;
import io.grpc.Status.Code;
import io.grpc.SynchronizationContext;
@ -856,12 +855,6 @@ public class EdsLoadBalancer2Test {
throw new UnsupportedOperationException("should not be called");
}
@Deprecated
@Override
public NameResolver.Factory getNameResolverFactory() {
throw new UnsupportedOperationException("should not be called");
}
@Override
public String getAuthority() {
return AUTHORITY;

View File

@ -53,7 +53,6 @@ import io.grpc.LoadBalancer.Subchannel;
import io.grpc.LoadBalancer.SubchannelPicker;
import io.grpc.LoadBalancer.SubchannelStateListener;
import io.grpc.ManagedChannel;
import io.grpc.NameResolver;
import io.grpc.Status;
import io.grpc.SynchronizationContext;
import io.grpc.inprocess.InProcessChannelBuilder;
@ -873,12 +872,6 @@ public class OrcaOobUtilTest {
return fakeClock.getScheduledExecutorService();
}
@Deprecated
@Override
public NameResolver.Factory getNameResolverFactory() {
throw new AssertionError("Should not be called");
}
@Override
public String getAuthority() {
throw new AssertionError("Should not be called");