Skip to content

Commit b30c7ca

Browse files
committed
Remove temporary AbstractManagedChannelImplBuilderTest
1 parent 08c9e5c commit b30c7ca

File tree

8 files changed

+34
-133
lines changed

8 files changed

+34
-133
lines changed

api/src/main/java/io/grpc/ForwardingChannelBuilder.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
@ExperimentalApi("https://github.com/grpc/grpc-java/issues/3363")
3636
public abstract class ForwardingChannelBuilder<T extends ForwardingChannelBuilder<T>>
3737
extends ManagedChannelBuilder<T> {
38+
// TODO(sergiitk): explain why to ForwardingChannelBuilder2 over this. Also - deprecate?
3839

3940
/**
4041
* The default constructor.

core/src/main/java/io/grpc/internal/AbstractManagedChannelImplBuilder.java renamed to api/src/main/java/io/grpc/ForwardingChannelBuilder2.java

Lines changed: 14 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2020 The gRPC Authors
2+
* Copyright 2023 The gRPC Authors
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -14,58 +14,43 @@
1414
* limitations under the License.
1515
*/
1616

17-
package io.grpc.internal;
17+
package io.grpc;
1818

1919
import com.google.common.base.MoreObjects;
20-
import com.google.common.base.Preconditions;
2120
import com.google.errorprone.annotations.DoNotCall;
22-
import io.grpc.BinaryLog;
23-
import io.grpc.ClientInterceptor;
24-
import io.grpc.CompressorRegistry;
25-
import io.grpc.DecompressorRegistry;
26-
import io.grpc.ManagedChannel;
27-
import io.grpc.ManagedChannelBuilder;
28-
import io.grpc.NameResolver;
29-
import io.grpc.ProxyDetector;
3021
import java.util.List;
3122
import java.util.Map;
3223
import java.util.concurrent.Executor;
3324
import java.util.concurrent.TimeUnit;
3425
import javax.annotation.Nullable;
3526

3627
/**
37-
* Temporarily duplicates {@link io.grpc.ForwardingChannelBuilder} to fix ABI backward
38-
* compatibility.
28+
* A {@link ManagedChannelBuilder} that delegates all its builder methods to another builder by
29+
* default.
3930
*
40-
* @param <T> The concrete type of this builder.
41-
* @see <a href="https://github.com/grpc/grpc-java/issues/7211">grpc/grpc-java#7211</a>
31+
* @param <T> The type of the subclass extending this abstract class.
32+
* @since TODO
4233
*/
43-
public abstract class AbstractManagedChannelImplBuilder
44-
<T extends AbstractManagedChannelImplBuilder<T>> extends ManagedChannelBuilder<T> {
45-
46-
/**
47-
* Added for ABI compatibility.
48-
*
49-
* <p>See details in {@link #maxInboundMessageSize(int)}.
50-
* TODO(sergiitk): move back to concrete classes as a private field, when this class is removed.
51-
*/
52-
protected int maxInboundMessageSize = GrpcUtil.DEFAULT_MAX_MESSAGE_SIZE;
34+
@ExperimentalApi("https://github.com/grpc/grpc-java/issues/TODO")
35+
public abstract class ForwardingChannelBuilder2<T extends ManagedChannelBuilder<T>>
36+
extends ManagedChannelBuilder<T> {
37+
// TODO(sergiitk): explain why to choose over ForwardingChannelBuilder
5338

5439
/**
5540
* The default constructor.
5641
*/
57-
protected AbstractManagedChannelImplBuilder() {}
42+
protected ForwardingChannelBuilder2() {}
5843

5944
/**
60-
* This method serves to force sub classes to "hide" this static factory.
45+
* This method serves to force subclasses to "hide" this static factory.
6146
*/
6247
@DoNotCall("Unsupported")
6348
public static ManagedChannelBuilder<?> forAddress(String name, int port) {
6449
throw new UnsupportedOperationException("Subclass failed to hide static factory");
6550
}
6651

6752
/**
68-
* This method serves to force sub classes to "hide" this static factory.
53+
* This method serves to force subclasses to "hide" this static factory.
6954
*/
7055
@DoNotCall("Unsupported")
7156
public static ManagedChannelBuilder<?> forTarget(String target) {
@@ -170,31 +155,7 @@ public T idleTimeout(long value, TimeUnit unit) {
170155

171156
@Override
172157
public T maxInboundMessageSize(int max) {
173-
/*
174-
Why this method is not delegating, as the rest of the methods?
175-
176-
In refactoring described in #7211, the implementation of #maxInboundMessageSize(int)
177-
(and its corresponding field) was pulled down from internal AbstractManagedChannelImplBuilder
178-
to concrete classes that actually enforce this setting. For the same reason, it wasn't ported
179-
to ManagedChannelImplBuilder (the #delegate()).
180-
181-
Then AbstractManagedChannelImplBuilder was brought back to fix ABI backward compatibility,
182-
and temporarily turned into a ForwardingChannelBuilder, ref PR #7564. Eventually it will
183-
be deleted, after a period with "bridge" ABI solution introduced in #7834.
184-
185-
However, restoring AbstractManagedChannelImplBuilder unintentionally made ABI of
186-
#maxInboundMessageSize(int) implemented by the concrete classes backward incompatible:
187-
pre-refactoring builds expect it to be a method of AbstractManagedChannelImplBuilder,
188-
and not concrete classes, ref #8313.
189-
190-
The end goal is to keep #maxInboundMessageSize(int) only in concrete classes that enforce it.
191-
To fix method's ABI, we temporary reintroduce it to the original layer it was removed from:
192-
AbstractManagedChannelImplBuilder. This class' only intention is to provide short-term
193-
ABI compatibility. Once we move forward with dropping the ABI, both fixes are no longer
194-
necessary, and both will perish with removing AbstractManagedChannelImplBuilder.
195-
*/
196-
Preconditions.checkArgument(max >= 0, "negative max");
197-
maxInboundMessageSize = max;
158+
delegate().maxInboundMessageSize(max);
198159
return thisT();
199160
}
200161

core/src/test/java/io/grpc/internal/AbstractManagedChannelImplBuilderTest.java renamed to api/src/test/java/io/grpc/ForwardingChannelBuilder2Test.java

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2020 The gRPC Authors
2+
* Copyright 2023 The gRPC Authors
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -14,33 +14,30 @@
1414
* limitations under the License.
1515
*/
1616

17-
package io.grpc.internal;
17+
package io.grpc;
1818

1919
import static com.google.common.truth.Truth.assertThat;
2020
import static org.mockito.Mockito.doReturn;
2121
import static org.mockito.Mockito.mock;
2222

2323
import com.google.common.base.Defaults;
24-
import com.google.common.collect.ImmutableSet;
25-
import io.grpc.ForwardingTestUtil;
26-
import io.grpc.ManagedChannel;
27-
import io.grpc.ManagedChannelBuilder;
2824
import java.lang.reflect.Method;
2925
import java.lang.reflect.Modifier;
26+
import java.util.Collections;
3027
import org.junit.Test;
3128
import org.junit.runner.RunWith;
3229
import org.junit.runners.JUnit4;
3330

3431
/**
35-
* Unit tests for {@link AbstractManagedChannelImplBuilder}.
32+
* Unit tests for {@link ForwardingChannelBuilder2}.
3633
*/
3734
@RunWith(JUnit4.class)
38-
public class AbstractManagedChannelImplBuilderTest {
35+
public class ForwardingChannelBuilder2Test {
3936
private final ManagedChannelBuilder<?> mockDelegate = mock(ManagedChannelBuilder.class);
4037

41-
private final AbstractManagedChannelImplBuilder<?> testChannelBuilder = new TestBuilder();
38+
private final ForwardingChannelBuilder2<?> testChannelBuilder = new TestBuilder();
4239

43-
private final class TestBuilder extends AbstractManagedChannelImplBuilder<TestBuilder> {
40+
private final class TestBuilder extends ForwardingChannelBuilder2<TestBuilder> {
4441
@Override
4542
protected ManagedChannelBuilder<?> delegate() {
4643
return mockDelegate;
@@ -53,8 +50,7 @@ public void allMethodsForwarded() throws Exception {
5350
ManagedChannelBuilder.class,
5451
mockDelegate,
5552
testChannelBuilder,
56-
// maxInboundMessageSize is the only method that shouldn't forward.
57-
ImmutableSet.of(ManagedChannelBuilder.class.getMethod("maxInboundMessageSize", int.class)),
53+
Collections.emptyList(),
5854
new ForwardingTestUtil.ArgumentProvider() {
5955
@Override
6056
public Object get(Method method, int argPos, Class<?> clazz) {
@@ -67,15 +63,6 @@ public Object get(Method method, int argPos, Class<?> clazz) {
6763
});
6864
}
6965

70-
@Test
71-
public void testMaxInboundMessageSize() {
72-
assertThat(testChannelBuilder.maxInboundMessageSize)
73-
.isEqualTo(GrpcUtil.DEFAULT_MAX_MESSAGE_SIZE);
74-
75-
testChannelBuilder.maxInboundMessageSize(42);
76-
assertThat(testChannelBuilder.maxInboundMessageSize).isEqualTo(42);
77-
}
78-
7966
@Test
8067
public void allBuilderMethodsReturnThis() throws Exception {
8168
for (Method method : ManagedChannelBuilder.class.getDeclaredMethods()) {

core/build.gradle

Lines changed: 0 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,6 @@ plugins {
1414
id "ru.vyarus.animalsniffer"
1515
}
1616

17-
import static java.nio.charset.StandardCharsets.US_ASCII;
18-
19-
import com.google.common.primitives.Bytes;
20-
2117
description = 'gRPC: Core'
2218

2319
dependencies {
@@ -73,50 +69,6 @@ animalsniffer {
7369
components.java.withVariantsFromConfiguration(configurations.testFixturesApiElements) { skip() }
7470
components.java.withVariantsFromConfiguration(configurations.testFixturesRuntimeElements) { skip() }
7571

76-
import net.ltgt.gradle.errorprone.CheckSeverity
77-
78-
def replaceBytes(byte[] haystack, byte[] needle, byte[] replacement) {
79-
int i = Bytes.indexOf(haystack, needle);
80-
assert i != -1;
81-
byte[] result = new byte[haystack.length - needle.length + replacement.length];
82-
System.arraycopy(haystack, 0, result, 0, i);
83-
System.arraycopy(replacement, 0, result, i, replacement.length);
84-
System.arraycopy(haystack, i + needle.length, result, i + replacement.length, haystack.length - i - needle.length);
85-
return result;
86-
}
87-
88-
def bigEndianShortBytes(int value) {
89-
return [value >> 8, value & 0xFF] as byte[];
90-
}
91-
92-
def replaceConstant(File file, String needle, String replacement) {
93-
// CONSTANT_Utf8_info. https://docs.oracle.com/javase/specs/jvms/se7/html/jvms-4.html#jvms-4.4.7
94-
byte[] needleBytes = Bytes.concat(
95-
[1] as byte[], bigEndianShortBytes(needle.length()), needle.getBytes(US_ASCII));
96-
byte[] replacementBytes = Bytes.concat(
97-
[1] as byte[], bigEndianShortBytes(replacement.length()), replacement.getBytes(US_ASCII));
98-
file.setBytes(replaceBytes(file.getBytes(), needleBytes, replacementBytes));
99-
}
100-
101-
plugins.withId("java") {
102-
tasks.named("compileJava").configure {
103-
doLast {
104-
// Replace value of Signature Attribute.
105-
// https://docs.oracle.com/javase/specs/jvms/se7/html/jvms-4.html#jvms-4.7.9
106-
//
107-
// Have new compilations compile against a public class, without breaking the internal
108-
// ABI for the moment. After giving users some time to recompile, this should be removed
109-
// and #7211 can continue. When this is removed, at the very least the generics need to
110-
// be changed to avoid <? extends io.grpc.internal.*>.
111-
project.replaceConstant(
112-
destinationDirectory.file(
113-
"io/grpc/internal/AbstractManagedChannelImplBuilder.class").get().getAsFile(),
114-
"<T:Lio/grpc/internal/AbstractManagedChannelImplBuilder<TT;>;>Lio/grpc/ManagedChannelBuilder<TT;>;",
115-
"<T:Lio/grpc/ManagedChannelBuilder<TT;>;>Lio/grpc/ManagedChannelBuilder<TT;>;");
116-
}
117-
}
118-
}
119-
12072
tasks.register("versionFile") {
12173
doLast {
12274
new File(buildDir, "version").write("${project.version}\n")

cronet/src/main/java/io/grpc/cronet/CronetChannelBuilder.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@
2828
import io.grpc.ChannelCredentials;
2929
import io.grpc.ChannelLogger;
3030
import io.grpc.ExperimentalApi;
31+
import io.grpc.ForwardingChannelBuilder2;
3132
import io.grpc.Internal;
3233
import io.grpc.ManagedChannelBuilder;
33-
import io.grpc.internal.AbstractManagedChannelImplBuilder;
3434
import io.grpc.internal.ClientTransportFactory;
3535
import io.grpc.internal.ConnectionClientTransport;
3636
import io.grpc.internal.GrpcUtil;
@@ -52,8 +52,7 @@
5252

5353
/** Convenience class for building channels with the cronet transport. */
5454
@ExperimentalApi("There is no plan to make this API stable, given transport API instability")
55-
public final class CronetChannelBuilder
56-
extends AbstractManagedChannelImplBuilder<CronetChannelBuilder> {
55+
public final class CronetChannelBuilder extends ForwardingChannelBuilder2<CronetChannelBuilder> {
5756

5857
private static final String LOG_TAG = "CronetChannelBuilder";
5958

inprocess/src/main/java/io/grpc/inprocess/InProcessChannelBuilder.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@
2323
import io.grpc.ChannelCredentials;
2424
import io.grpc.ChannelLogger;
2525
import io.grpc.ExperimentalApi;
26+
import io.grpc.ForwardingChannelBuilder2;
2627
import io.grpc.Internal;
2728
import io.grpc.ManagedChannelBuilder;
28-
import io.grpc.internal.AbstractManagedChannelImplBuilder;
2929
import io.grpc.internal.ClientTransportFactory;
3030
import io.grpc.internal.ConnectionClientTransport;
3131
import io.grpc.internal.GrpcUtil;
@@ -47,7 +47,8 @@
4747
*/
4848
@ExperimentalApi("https://github.com/grpc/grpc-java/issues/1783")
4949
public final class InProcessChannelBuilder extends
50-
AbstractManagedChannelImplBuilder<InProcessChannelBuilder> {
50+
ForwardingChannelBuilder2<InProcessChannelBuilder> {
51+
5152
/**
5253
* Create a channel builder that will connect to the server with the given name.
5354
*

netty/src/main/java/io/grpc/netty/NettyChannelBuilder.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@
3333
import io.grpc.ChannelLogger;
3434
import io.grpc.EquivalentAddressGroup;
3535
import io.grpc.ExperimentalApi;
36+
import io.grpc.ForwardingChannelBuilder2;
3637
import io.grpc.HttpConnectProxiedSocketAddress;
3738
import io.grpc.Internal;
3839
import io.grpc.ManagedChannelBuilder;
39-
import io.grpc.internal.AbstractManagedChannelImplBuilder;
4040
import io.grpc.internal.AtomicBackoff;
4141
import io.grpc.internal.ClientTransportFactory;
4242
import io.grpc.internal.ConnectionClientTransport;
@@ -72,8 +72,7 @@
7272
*/
7373
@ExperimentalApi("https://github.com/grpc/grpc-java/issues/1784")
7474
@CheckReturnValue
75-
public final class NettyChannelBuilder extends
76-
AbstractManagedChannelImplBuilder<NettyChannelBuilder> {
75+
public final class NettyChannelBuilder extends ForwardingChannelBuilder2<NettyChannelBuilder> {
7776

7877
// 1MiB.
7978
public static final int DEFAULT_FLOW_CONTROL_WINDOW = 1024 * 1024;
@@ -102,6 +101,7 @@ public final class NettyChannelBuilder extends
102101
private boolean autoFlowControl = DEFAULT_AUTO_FLOW_CONTROL;
103102
private int flowControlWindow = DEFAULT_FLOW_CONTROL_WINDOW;
104103
private int maxHeaderListSize = GrpcUtil.DEFAULT_MAX_HEADER_LIST_SIZE;
104+
private int maxInboundMessageSize = GrpcUtil.DEFAULT_MAX_MESSAGE_SIZE;
105105
private long keepAliveTimeNanos = KEEPALIVE_TIME_NANOS_DISABLED;
106106
private long keepAliveTimeoutNanos = DEFAULT_KEEPALIVE_TIMEOUT_NANOS;
107107
private boolean keepAliveWithoutCalls;

okhttp/src/main/java/io/grpc/okhttp/OkHttpChannelBuilder.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,11 @@
2929
import io.grpc.CompositeCallCredentials;
3030
import io.grpc.CompositeChannelCredentials;
3131
import io.grpc.ExperimentalApi;
32+
import io.grpc.ForwardingChannelBuilder2;
3233
import io.grpc.InsecureChannelCredentials;
3334
import io.grpc.Internal;
3435
import io.grpc.ManagedChannelBuilder;
3536
import io.grpc.TlsChannelCredentials;
36-
import io.grpc.internal.AbstractManagedChannelImplBuilder;
3737
import io.grpc.internal.AtomicBackoff;
3838
import io.grpc.internal.ClientTransportFactory;
3939
import io.grpc.internal.ConnectionClientTransport;
@@ -83,8 +83,7 @@
8383

8484
/** Convenience class for building channels with the OkHttp transport. */
8585
@ExperimentalApi("https://github.com/grpc/grpc-java/issues/1785")
86-
public final class OkHttpChannelBuilder extends
87-
AbstractManagedChannelImplBuilder<OkHttpChannelBuilder> {
86+
public final class OkHttpChannelBuilder extends ForwardingChannelBuilder2<OkHttpChannelBuilder> {
8887
private static final Logger log = Logger.getLogger(OkHttpChannelBuilder.class.getName());
8988
public static final int DEFAULT_FLOW_CONTROL_WINDOW = 65535;
9089

@@ -188,6 +187,7 @@ public static OkHttpChannelBuilder forTarget(String target, ChannelCredentials c
188187
private long keepAliveTimeoutNanos = DEFAULT_KEEPALIVE_TIMEOUT_NANOS;
189188
private int flowControlWindow = DEFAULT_FLOW_CONTROL_WINDOW;
190189
private boolean keepAliveWithoutCalls;
190+
private int maxInboundMessageSize = GrpcUtil.DEFAULT_MAX_MESSAGE_SIZE;
191191
private int maxInboundMetadataSize = Integer.MAX_VALUE;
192192

193193
/**

0 commit comments

Comments
 (0)