From de83f81f3e388e9ad64d0e87ff3d7e5d708b6b56 Mon Sep 17 00:00:00 2001 From: Sergii Tkachenko Date: Mon, 31 Aug 2020 18:59:52 -0400 Subject: [PATCH 1/3] api, core: create ForwardingServerBuilder and ServerImplBuilder --- .../java/io/grpc/ForwardingServerBuilder.java | 169 ++++++++++++++++++ .../io/grpc/ForwardingServerBuilderTest.java | 83 +++++++++ .../grpc/benchmarks/TransportBenchmark.java | 4 +- .../internal/AbstractServerImplBuilder.java | 2 +- .../io/grpc/internal/ServerImplBuilder.java | 105 +++++++++++ .../grpc/internal/ServerImplBuilderTest.java | 64 +++++++ 6 files changed, 424 insertions(+), 3 deletions(-) create mode 100644 api/src/main/java/io/grpc/ForwardingServerBuilder.java create mode 100644 api/src/test/java/io/grpc/ForwardingServerBuilderTest.java create mode 100644 core/src/main/java/io/grpc/internal/ServerImplBuilder.java create mode 100644 core/src/test/java/io/grpc/internal/ServerImplBuilderTest.java diff --git a/api/src/main/java/io/grpc/ForwardingServerBuilder.java b/api/src/main/java/io/grpc/ForwardingServerBuilder.java new file mode 100644 index 00000000000..4e1d5a1baf5 --- /dev/null +++ b/api/src/main/java/io/grpc/ForwardingServerBuilder.java @@ -0,0 +1,169 @@ +/* + * Copyright 2020 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 com.google.common.base.MoreObjects; +import java.io.File; +import java.io.InputStream; +import java.util.concurrent.Executor; +import java.util.concurrent.TimeUnit; +import javax.annotation.Nullable; + +/** + * A {@link ServerBuilder} that delegates all its builder method to another builder by default. + * + * @param The type of the subclass extending this abstract class. + * @since 1.33.0 + */ +@ExperimentalApi("https://github.com/grpc/grpc-java/issues/7393") +public abstract class ForwardingServerBuilder> + extends ServerBuilder { + + /** The default constructor. */ + protected ForwardingServerBuilder() {} + + /** + * This method serves to force sub classes to "hide" this static factory. + */ + public static ServerBuilder forPort(int port) { + throw new UnsupportedOperationException("Subclass failed to hide static factory"); + } + + /** + * Returns the delegated {@code ServerBuilder}. + */ + protected abstract ServerBuilder delegate(); + + @Override + public T directExecutor() { + delegate().directExecutor(); + return thisT(); + } + + @Override + public T executor(@Nullable Executor executor) { + delegate().executor(executor); + return thisT(); + } + + @Override + public T addService(ServerServiceDefinition service) { + delegate().addService(service); + return thisT(); + } + + @Override + public T addService(BindableService bindableService) { + delegate().addService(bindableService); + return thisT(); + } + + @Override + public T intercept(ServerInterceptor interceptor) { + delegate().intercept(interceptor); + return thisT(); + } + + @Override + public T addTransportFilter(ServerTransportFilter filter) { + delegate().addTransportFilter(filter); + return thisT(); + } + + @Override + public T addStreamTracerFactory(ServerStreamTracer.Factory factory) { + delegate().addStreamTracerFactory(factory); + return thisT(); + } + + @Override + public T fallbackHandlerRegistry(@Nullable HandlerRegistry fallbackRegistry) { + delegate().fallbackHandlerRegistry(fallbackRegistry); + return thisT(); + } + + @Override + public T useTransportSecurity(File certChain, File privateKey) { + delegate().useTransportSecurity(certChain, privateKey); + return thisT(); + } + + @Override + public T useTransportSecurity(InputStream certChain, InputStream privateKey) { + delegate().useTransportSecurity(certChain, privateKey); + return thisT(); + } + + @Override + public T decompressorRegistry(@Nullable DecompressorRegistry registry) { + delegate().decompressorRegistry(registry); + return thisT(); + } + + @Override + public T compressorRegistry(@Nullable CompressorRegistry registry) { + delegate().compressorRegistry(registry); + return thisT(); + } + + @Override + public T handshakeTimeout(long timeout, TimeUnit unit) { + delegate().handshakeTimeout(timeout, unit); + return thisT(); + } + + @Override + public T maxInboundMessageSize(int bytes) { + delegate().maxInboundMessageSize(bytes); + return thisT(); + } + + @Override + public T maxInboundMetadataSize(int bytes) { + delegate().maxInboundMetadataSize(bytes); + return thisT(); + } + + @Override + public T setBinaryLog(BinaryLog binaryLog) { + delegate().setBinaryLog(binaryLog); + return thisT(); + } + + /** + * Returns the {@link Server} built by the delegate by default. Overriding method can return + * different value. + */ + @Override + public Server build() { + return delegate().build(); + } + + @Override + public String toString() { + return MoreObjects.toStringHelper(this).add("delegate", delegate()).toString(); + } + + /** + * Returns the correctly typed version of the builder. + */ + protected final T thisT() { + @SuppressWarnings("unchecked") + T thisT = (T) this; + return thisT; + } +} diff --git a/api/src/test/java/io/grpc/ForwardingServerBuilderTest.java b/api/src/test/java/io/grpc/ForwardingServerBuilderTest.java new file mode 100644 index 00000000000..6a8c1c115a9 --- /dev/null +++ b/api/src/test/java/io/grpc/ForwardingServerBuilderTest.java @@ -0,0 +1,83 @@ +/* + * Copyright 2020 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.doReturn; +import static org.mockito.Mockito.mock; + +import com.google.common.base.Defaults; +import java.lang.reflect.Method; +import java.lang.reflect.Modifier; +import java.util.Collections; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; + +/** + * Unit tests for {@link ForwardingServerBuilder}. + */ +@RunWith(JUnit4.class) +public class ForwardingServerBuilderTest { + private final ServerBuilder mockDelegate = mock(ServerBuilder.class); + private final ForwardingServerBuilder testServerBuilder = new TestBuilder(); + + private final class TestBuilder extends ForwardingServerBuilder { + @Override + protected ServerBuilder delegate() { + return mockDelegate; + } + } + + @Test + public void allMethodsForwarded() throws Exception { + ForwardingTestUtil.testMethodsForwarded( + ServerBuilder.class, + mockDelegate, + testServerBuilder, + Collections.emptyList()); + } + + @Test + public void allBuilderMethodsReturnThis() throws Exception { + for (Method method : ServerBuilder.class.getDeclaredMethods()) { + if (Modifier.isStatic(method.getModifiers()) || Modifier.isPrivate(method.getModifiers())) { + continue; + } + if (method.getName().equals("build")) { + continue; + } + Class[] argTypes = method.getParameterTypes(); + Object[] args = new Object[argTypes.length]; + for (int i = 0; i < argTypes.length; i++) { + args[i] = Defaults.defaultValue(argTypes[i]); + } + + Object returnedValue = method.invoke(testServerBuilder, args); + + assertThat(returnedValue).isSameInstanceAs(testServerBuilder); + } + } + + @Test + public void buildReturnsDelegateBuildByDefault() { + Server server = mock(Server.class); + doReturn(server).when(mockDelegate).build(); + + assertThat(testServerBuilder.build()).isSameInstanceAs(server); + } +} diff --git a/benchmarks/src/jmh/java/io/grpc/benchmarks/TransportBenchmark.java b/benchmarks/src/jmh/java/io/grpc/benchmarks/TransportBenchmark.java index ec4646bff44..b673657cb35 100644 --- a/benchmarks/src/jmh/java/io/grpc/benchmarks/TransportBenchmark.java +++ b/benchmarks/src/jmh/java/io/grpc/benchmarks/TransportBenchmark.java @@ -22,6 +22,7 @@ import io.grpc.ManagedChannel; import io.grpc.ManagedChannelBuilder; import io.grpc.Server; +import io.grpc.ServerBuilder; import io.grpc.Status; import io.grpc.StatusRuntimeException; import io.grpc.benchmarks.proto.BenchmarkServiceGrpc; @@ -31,7 +32,6 @@ import io.grpc.benchmarks.qps.AsyncServer; import io.grpc.inprocess.InProcessChannelBuilder; import io.grpc.inprocess.InProcessServerBuilder; -import io.grpc.internal.AbstractServerImplBuilder; import io.grpc.netty.NegotiationType; import io.grpc.netty.NettyChannelBuilder; import io.grpc.netty.NettyServerBuilder; @@ -80,7 +80,7 @@ public enum Transport { @Setup public void setUp() throws Exception { - AbstractServerImplBuilder serverBuilder; + ServerBuilder serverBuilder; ManagedChannelBuilder channelBuilder; switch (transport) { case INPROCESS: diff --git a/core/src/main/java/io/grpc/internal/AbstractServerImplBuilder.java b/core/src/main/java/io/grpc/internal/AbstractServerImplBuilder.java index 21a1becc284..c68076cc4c6 100644 --- a/core/src/main/java/io/grpc/internal/AbstractServerImplBuilder.java +++ b/core/src/main/java/io/grpc/internal/AbstractServerImplBuilder.java @@ -283,7 +283,7 @@ final List getTracerFactories() { return Collections.unmodifiableList(tracerFactories); } - protected final InternalChannelz getChannelz() { + protected InternalChannelz getChannelz() { return channelz; } diff --git a/core/src/main/java/io/grpc/internal/ServerImplBuilder.java b/core/src/main/java/io/grpc/internal/ServerImplBuilder.java new file mode 100644 index 00000000000..ce92f1c65c3 --- /dev/null +++ b/core/src/main/java/io/grpc/internal/ServerImplBuilder.java @@ -0,0 +1,105 @@ +/* + * Copyright 2020 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.internal; + +import com.google.common.base.Preconditions; +import io.grpc.Deadline; +import io.grpc.InternalChannelz; +import io.grpc.ServerBuilder; +import io.grpc.ServerStreamTracer; +import java.io.File; +import java.util.List; +import java.util.concurrent.Executor; + +/** + * Default builder for {@link io.grpc.Server} instances, for usage in Transport implementations. + */ +public final class ServerImplBuilder extends AbstractServerImplBuilder { + private final ClientTransportServersBuilder clientTransportServersBuilder; + + /** + * An interface to provide to provide transport specific information for the server. This method + * is meant for Transport implementors and should not be used by normal users. + */ + public interface ClientTransportServersBuilder { + List buildClientTransportServers( + List streamTracerFactories); + } + + /** + * Creates a new server builder with given transport servers provider. + */ + public ServerImplBuilder(ClientTransportServersBuilder clientTransportServersBuilder) { + this.clientTransportServersBuilder = Preconditions + .checkNotNull(clientTransportServersBuilder, "clientTransportServersBuilder"); + } + + @Override + protected List buildTransportServers( + List streamTracerFactories) { + return clientTransportServersBuilder.buildClientTransportServers(streamTracerFactories); + } + + @Override + public void setDeadlineTicker(Deadline.Ticker ticker) { + super.setDeadlineTicker(ticker); + } + + @Override + public void setTracingEnabled(boolean value) { + super.setTracingEnabled(value); + } + + @Override + public void setStatsEnabled(boolean value) { + super.setStatsEnabled(value); + } + + @Override + public void setStatsRecordStartedRpcs(boolean value) { + super.setStatsRecordStartedRpcs(value); + } + + @Override + public void setStatsRecordFinishedRpcs(boolean value) { + super.setStatsRecordFinishedRpcs(value); + } + + @Override + public void setStatsRecordRealTimeMetrics(boolean value) { + super.setStatsRecordRealTimeMetrics(value); + } + + @Override + public InternalChannelz getChannelz() { + return super.getChannelz(); + } + + @Override + public ObjectPool getExecutorPool() { + return super.getExecutorPool(); + } + + @Override + public ServerImplBuilder useTransportSecurity(File certChain, File privateKey) { + throw new UnsupportedOperationException("TLS not supported in ServerImplBuilder"); + } + + public static ServerBuilder forPort(int port) { + throw new UnsupportedOperationException("ClientTransportServersBuilder is required"); + } +} diff --git a/core/src/test/java/io/grpc/internal/ServerImplBuilderTest.java b/core/src/test/java/io/grpc/internal/ServerImplBuilderTest.java new file mode 100644 index 00000000000..3b5e3c7d8c3 --- /dev/null +++ b/core/src/test/java/io/grpc/internal/ServerImplBuilderTest.java @@ -0,0 +1,64 @@ +/* + * Copyright 2020 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.internal; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.verify; + +import io.grpc.ServerStreamTracer; +import io.grpc.internal.ServerImplBuilder.ClientTransportServersBuilder; +import java.util.List; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; +import org.mockito.ArgumentMatchers; +import org.mockito.Mock; +import org.mockito.junit.MockitoJUnit; +import org.mockito.junit.MockitoRule; + +/** Unit tests for {@link ServerImplBuilder}. */ +@RunWith(JUnit4.class) +public class ServerImplBuilderTest { + @Rule public final MockitoRule mocks = MockitoJUnit.rule(); + + @Mock private ClientTransportServersBuilder mockClientTransportServersBuilder; + @Mock private List mockServerStreamTracerFactories; + @Mock private List mockInternalServers; + private ServerImplBuilder builder; + + @Before + public void setUp() throws Exception { + builder = new ServerImplBuilder(mockClientTransportServersBuilder); + } + + @Test + public void buildTransportServers() { + doReturn(mockInternalServers).when(mockClientTransportServersBuilder) + .buildClientTransportServers(ArgumentMatchers.anyList()); + + List servers = builder + .buildTransportServers(mockServerStreamTracerFactories); + assertEquals(mockInternalServers, servers); + assertNotNull(servers); + verify(mockClientTransportServersBuilder) + .buildClientTransportServers(mockServerStreamTracerFactories); + } +} From ca5f3a0f9000ba80e97c03b3d27ab1b27f744e4f Mon Sep 17 00:00:00 2001 From: Sergii Tkachenko Date: Wed, 2 Sep 2020 16:47:15 -0400 Subject: [PATCH 2/3] core, netty: server builders extend a public API class --- .../inprocess/InProcessServerBuilder.java | 41 +++++++++--- .../InternalInProcessServerBuilder.java | 32 ++++++++++ .../integration/AbstractInteropTest.java | 34 +++++----- .../integration/AutoWindowSizingOnTest.java | 10 ++- .../Http2NettyLocalChannelTest.java | 10 ++- .../testing/integration/Http2NettyTest.java | 10 ++- .../testing/integration/Http2OkHttpTest.java | 10 ++- .../testing/integration/InProcessTest.java | 16 ++++- .../integration/TransportCompressionTest.java | 10 ++- .../netty/InternalNettyServerBuilder.java | 14 ++++- .../io/grpc/netty/NettyServerBuilder.java | 62 +++++++++++++------ .../io/grpc/okhttp/OkHttpTransportTest.java | 24 ++++--- 12 files changed, 196 insertions(+), 77 deletions(-) create mode 100644 core/src/main/java/io/grpc/inprocess/InternalInProcessServerBuilder.java diff --git a/core/src/main/java/io/grpc/inprocess/InProcessServerBuilder.java b/core/src/main/java/io/grpc/inprocess/InProcessServerBuilder.java index 603a794e3db..37e6dcaede5 100644 --- a/core/src/main/java/io/grpc/inprocess/InProcessServerBuilder.java +++ b/core/src/main/java/io/grpc/inprocess/InProcessServerBuilder.java @@ -21,11 +21,16 @@ import com.google.common.base.Preconditions; import io.grpc.Deadline; import io.grpc.ExperimentalApi; +import io.grpc.ForwardingServerBuilder; +import io.grpc.Internal; +import io.grpc.ServerBuilder; import io.grpc.ServerStreamTracer; -import io.grpc.internal.AbstractServerImplBuilder; import io.grpc.internal.FixedObjectPool; import io.grpc.internal.GrpcUtil; +import io.grpc.internal.InternalServer; import io.grpc.internal.ObjectPool; +import io.grpc.internal.ServerImplBuilder; +import io.grpc.internal.ServerImplBuilder.ClientTransportServersBuilder; import io.grpc.internal.SharedResourcePool; import java.io.File; import java.util.Collections; @@ -67,8 +72,7 @@ * */ @ExperimentalApi("https://github.com/grpc/grpc-java/issues/1783") -public final class InProcessServerBuilder - extends AbstractServerImplBuilder { +public final class InProcessServerBuilder extends ForwardingServerBuilder { /** * Create a server builder that will bind with the given name. * @@ -93,6 +97,7 @@ public static String generateName() { return UUID.randomUUID().toString(); } + private final ServerImplBuilder serverImplBuilder; final String name; int maxInboundMetadataSize = Integer.MAX_VALUE; ObjectPool schedulerPool = @@ -100,15 +105,32 @@ public static String generateName() { private InProcessServerBuilder(String name) { this.name = Preconditions.checkNotNull(name, "name"); + + final class InProcessClientTransportServersBuilder implements ClientTransportServersBuilder { + @Override + public List buildClientTransportServers( + List streamTracerFactories) { + return buildTransportServers(streamTracerFactories); + } + } + + serverImplBuilder = new ServerImplBuilder(new InProcessClientTransportServersBuilder()); + // In-process transport should not record its traffic to the stats module. // https://github.com/grpc/grpc-java/issues/2284 - setStatsRecordStartedRpcs(false); - setStatsRecordFinishedRpcs(false); + serverImplBuilder.setStatsRecordStartedRpcs(false); + serverImplBuilder.setStatsRecordFinishedRpcs(false); // Disable handshake timeout because it is unnecessary, and can trigger Thread creation that can // break some environments (like tests). handshakeTimeout(Long.MAX_VALUE, TimeUnit.SECONDS); } + @Internal + @Override + protected ServerBuilder delegate() { + return serverImplBuilder; + } + /** * Provides a custom scheduled executor service. * @@ -140,7 +162,7 @@ public InProcessServerBuilder scheduledExecutorService( * @since 1.24.0 */ public InProcessServerBuilder deadlineTicker(Deadline.Ticker ticker) { - setDeadlineTicker(ticker); + serverImplBuilder.setDeadlineTicker(ticker); return this; } @@ -164,8 +186,7 @@ public InProcessServerBuilder maxInboundMetadataSize(int bytes) { return this; } - @Override - protected List buildTransportServers( + List buildTransportServers( List streamTracerFactories) { return Collections.singletonList(new InProcessServer(this, streamTracerFactories)); } @@ -174,4 +195,8 @@ protected List buildTransportServers( public InProcessServerBuilder useTransportSecurity(File certChain, File privateKey) { throw new UnsupportedOperationException("TLS not supported in InProcessServer"); } + + void setStatsEnabled(boolean value) { + this.serverImplBuilder.setStatsEnabled(value); + } } diff --git a/core/src/main/java/io/grpc/inprocess/InternalInProcessServerBuilder.java b/core/src/main/java/io/grpc/inprocess/InternalInProcessServerBuilder.java new file mode 100644 index 00000000000..df531707451 --- /dev/null +++ b/core/src/main/java/io/grpc/inprocess/InternalInProcessServerBuilder.java @@ -0,0 +1,32 @@ +/* + * Copyright 2020 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.inprocess; + +import io.grpc.Internal; + +/** + * Internal {@link InProcessServerBuilder} accessor. This is intended for usage internal to + * the gRPC team. If you *really* think you need to use this, contact the gRPC team first. + */ +@Internal +public class InternalInProcessServerBuilder { + public static void setStatsEnabled(InProcessServerBuilder builder, boolean value) { + builder.setStatsEnabled(value); + } + + private InternalInProcessServerBuilder() {} +} diff --git a/interop-testing/src/main/java/io/grpc/testing/integration/AbstractInteropTest.java b/interop-testing/src/main/java/io/grpc/testing/integration/AbstractInteropTest.java index 643d984bad8..769309a5a1a 100644 --- a/interop-testing/src/main/java/io/grpc/testing/integration/AbstractInteropTest.java +++ b/interop-testing/src/main/java/io/grpc/testing/integration/AbstractInteropTest.java @@ -64,7 +64,6 @@ import io.grpc.auth.MoreCallCredentials; import io.grpc.census.InternalCensusStatsAccessor; import io.grpc.census.internal.DeprecatedCensusConstants; -import io.grpc.internal.AbstractServerImplBuilder; import io.grpc.internal.GrpcUtil; import io.grpc.internal.testing.StatsTestUtils; import io.grpc.internal.testing.StatsTestUtils.FakeStatsRecorder; @@ -171,7 +170,6 @@ public abstract class AbstractInteropTest { private ScheduledExecutorService testServiceExecutor; private Server server; - private boolean customCensusModulePresent; private final LinkedBlockingQueue serverStreamTracers = new LinkedBlockingQueue<>(); @@ -245,21 +243,7 @@ private void startServer() { new TestServiceImpl(testServiceExecutor), allInterceptors)) .addStreamTracerFactory(serverStreamTracerFactory); - if (builder instanceof AbstractServerImplBuilder) { - customCensusModulePresent = true; - ServerStreamTracer.Factory censusTracerFactory = - InternalCensusStatsAccessor - .getServerStreamTracerFactory( - tagger, tagContextBinarySerializer, serverStatsRecorder, - GrpcUtil.STOPWATCH_SUPPLIER, - true, true, true, false /* real-time metrics */); - AbstractServerImplBuilder sb = (AbstractServerImplBuilder) builder; - io.grpc.internal.TestingAccessor.setStatsEnabled(sb, false); - sb.addStreamTracerFactory(censusTracerFactory); - } - if (metricsExpected()) { - assertThat(builder).isInstanceOf(AbstractServerImplBuilder.class); - } + try { server = builder.build().start(); } catch (IOException ex) { @@ -373,6 +357,20 @@ protected final ClientInterceptor createCensusStatsClientInterceptor() { true, true, true, false /* real-time metrics */); } + protected final ServerStreamTracer.Factory createCustomCensusTracerFactory() { + return InternalCensusStatsAccessor.getServerStreamTracerFactory( + tagger, tagContextBinarySerializer, serverStatsRecorder, + GrpcUtil.STOPWATCH_SUPPLIER, + true, true, true, false /* real-time metrics */); + } + + /** + * Override this when custom census module presence is different from {@link #metricsExpected()}. + */ + protected boolean customCensusModulePresent() { + return metricsExpected(); + } + /** * Return true if exact metric values should be checked. */ @@ -1510,7 +1508,7 @@ public void customMetadata() throws Exception { @Test(timeout = 10000) public void censusContextsPropagated() { Assume.assumeTrue("Skip the test because server is not in the same process.", server != null); - Assume.assumeTrue(customCensusModulePresent); + Assume.assumeTrue(customCensusModulePresent()); Span clientParentSpan = Tracing.getTracer().spanBuilder("Test.interopTest").startSpan(); // A valid ID is guaranteed to be unique, so we can verify it is actually propagated. assertTrue(clientParentSpan.getContext().getTraceId().isValid()); diff --git a/interop-testing/src/test/java/io/grpc/testing/integration/AutoWindowSizingOnTest.java b/interop-testing/src/test/java/io/grpc/testing/integration/AutoWindowSizingOnTest.java index a2036ecea91..05fd970e3e0 100644 --- a/interop-testing/src/test/java/io/grpc/testing/integration/AutoWindowSizingOnTest.java +++ b/interop-testing/src/test/java/io/grpc/testing/integration/AutoWindowSizingOnTest.java @@ -16,8 +16,9 @@ package io.grpc.testing.integration; -import io.grpc.internal.AbstractServerImplBuilder; +import io.grpc.ServerBuilder; import io.grpc.netty.InternalNettyChannelBuilder; +import io.grpc.netty.InternalNettyServerBuilder; import io.grpc.netty.NegotiationType; import io.grpc.netty.NettyChannelBuilder; import io.grpc.netty.NettyServerBuilder; @@ -28,9 +29,12 @@ public class AutoWindowSizingOnTest extends AbstractInteropTest { @Override - protected AbstractServerImplBuilder getServerBuilder() { - return NettyServerBuilder.forPort(0) + protected ServerBuilder getServerBuilder() { + NettyServerBuilder builder = NettyServerBuilder.forPort(0) .maxInboundMessageSize(AbstractInteropTest.MAX_MESSAGE_SIZE); + // Disable the default census stats tracer, use testing tracer instead. + InternalNettyServerBuilder.setStatsEnabled(builder, false); + return builder.addStreamTracerFactory(createCustomCensusTracerFactory()); } @Override diff --git a/interop-testing/src/test/java/io/grpc/testing/integration/Http2NettyLocalChannelTest.java b/interop-testing/src/test/java/io/grpc/testing/integration/Http2NettyLocalChannelTest.java index 4494d620b1e..778e8bdf97c 100644 --- a/interop-testing/src/test/java/io/grpc/testing/integration/Http2NettyLocalChannelTest.java +++ b/interop-testing/src/test/java/io/grpc/testing/integration/Http2NettyLocalChannelTest.java @@ -16,8 +16,9 @@ package io.grpc.testing.integration; -import io.grpc.internal.AbstractServerImplBuilder; +import io.grpc.ServerBuilder; import io.grpc.netty.InternalNettyChannelBuilder; +import io.grpc.netty.InternalNettyServerBuilder; import io.grpc.netty.NegotiationType; import io.grpc.netty.NettyChannelBuilder; import io.grpc.netty.NettyServerBuilder; @@ -38,14 +39,17 @@ public class Http2NettyLocalChannelTest extends AbstractInteropTest { private DefaultEventLoopGroup eventLoopGroup = new DefaultEventLoopGroup(); @Override - protected AbstractServerImplBuilder getServerBuilder() { - return NettyServerBuilder + protected ServerBuilder getServerBuilder() { + NettyServerBuilder builder = NettyServerBuilder .forAddress(new LocalAddress("in-process-1")) .flowControlWindow(AbstractInteropTest.TEST_FLOW_CONTROL_WINDOW) .maxInboundMessageSize(AbstractInteropTest.MAX_MESSAGE_SIZE) .channelType(LocalServerChannel.class) .workerEventLoopGroup(eventLoopGroup) .bossEventLoopGroup(eventLoopGroup); + // Disable the default census stats tracer, use testing tracer instead. + InternalNettyServerBuilder.setStatsEnabled(builder, false); + return builder.addStreamTracerFactory(createCustomCensusTracerFactory()); } @Override diff --git a/interop-testing/src/test/java/io/grpc/testing/integration/Http2NettyTest.java b/interop-testing/src/test/java/io/grpc/testing/integration/Http2NettyTest.java index 9053a1fff64..0d391039105 100644 --- a/interop-testing/src/test/java/io/grpc/testing/integration/Http2NettyTest.java +++ b/interop-testing/src/test/java/io/grpc/testing/integration/Http2NettyTest.java @@ -19,10 +19,11 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotEquals; -import io.grpc.internal.AbstractServerImplBuilder; +import io.grpc.ServerBuilder; import io.grpc.internal.testing.TestUtils; import io.grpc.netty.GrpcSslContexts; import io.grpc.netty.InternalNettyChannelBuilder; +import io.grpc.netty.InternalNettyServerBuilder; import io.grpc.netty.NettyChannelBuilder; import io.grpc.netty.NettyServerBuilder; import io.netty.handler.ssl.ClientAuth; @@ -41,10 +42,10 @@ public class Http2NettyTest extends AbstractInteropTest { @Override - protected AbstractServerImplBuilder getServerBuilder() { + protected ServerBuilder getServerBuilder() { // Starts the server with HTTPS. try { - return NettyServerBuilder.forPort(0) + NettyServerBuilder builder = NettyServerBuilder.forPort(0) .flowControlWindow(AbstractInteropTest.TEST_FLOW_CONTROL_WINDOW) .maxInboundMessageSize(AbstractInteropTest.MAX_MESSAGE_SIZE) .sslContext(GrpcSslContexts @@ -53,6 +54,9 @@ protected AbstractServerImplBuilder getServerBuilder() { .trustManager(TestUtils.loadCert("ca.pem")) .ciphers(TestUtils.preferredTestCiphers(), SupportedCipherSuiteFilter.INSTANCE) .build()); + // Disable the default census stats tracer, use testing tracer instead. + InternalNettyServerBuilder.setStatsEnabled(builder, false); + return builder.addStreamTracerFactory(createCustomCensusTracerFactory()); } catch (IOException ex) { throw new RuntimeException(ex); } diff --git a/interop-testing/src/test/java/io/grpc/testing/integration/Http2OkHttpTest.java b/interop-testing/src/test/java/io/grpc/testing/integration/Http2OkHttpTest.java index ea4ba5877ce..612774c7564 100644 --- a/interop-testing/src/test/java/io/grpc/testing/integration/Http2OkHttpTest.java +++ b/interop-testing/src/test/java/io/grpc/testing/integration/Http2OkHttpTest.java @@ -23,11 +23,12 @@ import com.google.common.base.Throwables; import com.squareup.okhttp.ConnectionSpec; import io.grpc.ManagedChannel; -import io.grpc.internal.AbstractServerImplBuilder; +import io.grpc.ServerBuilder; import io.grpc.internal.GrpcUtil; import io.grpc.internal.testing.StreamRecorder; import io.grpc.internal.testing.TestUtils; import io.grpc.netty.GrpcSslContexts; +import io.grpc.netty.InternalNettyServerBuilder; import io.grpc.netty.NettyServerBuilder; import io.grpc.okhttp.InternalOkHttpChannelBuilder; import io.grpc.okhttp.OkHttpChannelBuilder; @@ -64,7 +65,7 @@ public static void loadConscrypt() throws Exception { } @Override - protected AbstractServerImplBuilder getServerBuilder() { + protected ServerBuilder getServerBuilder() { // Starts the server with HTTPS. try { SslProvider sslProvider = SslContext.defaultServerProvider(); @@ -77,10 +78,13 @@ protected AbstractServerImplBuilder getServerBuilder() { .forServer(TestUtils.loadCert("server1.pem"), TestUtils.loadCert("server1.key")); GrpcSslContexts.configure(contextBuilder, sslProvider); contextBuilder.ciphers(TestUtils.preferredTestCiphers(), SupportedCipherSuiteFilter.INSTANCE); - return NettyServerBuilder.forPort(0) + NettyServerBuilder builder = NettyServerBuilder.forPort(0) .flowControlWindow(AbstractInteropTest.TEST_FLOW_CONTROL_WINDOW) .maxInboundMessageSize(AbstractInteropTest.MAX_MESSAGE_SIZE) .sslContext(contextBuilder.build()); + // Disable the default census stats tracer, use testing tracer instead. + InternalNettyServerBuilder.setStatsEnabled(builder, false); + return builder.addStreamTracerFactory(createCustomCensusTracerFactory()); } catch (IOException ex) { throw new RuntimeException(ex); } diff --git a/interop-testing/src/test/java/io/grpc/testing/integration/InProcessTest.java b/interop-testing/src/test/java/io/grpc/testing/integration/InProcessTest.java index 66894834b95..1ad63ae85d8 100644 --- a/interop-testing/src/test/java/io/grpc/testing/integration/InProcessTest.java +++ b/interop-testing/src/test/java/io/grpc/testing/integration/InProcessTest.java @@ -16,10 +16,11 @@ package io.grpc.testing.integration; +import io.grpc.ServerBuilder; import io.grpc.inprocess.InProcessChannelBuilder; import io.grpc.inprocess.InProcessServerBuilder; import io.grpc.inprocess.InternalInProcessChannelBuilder; -import io.grpc.internal.AbstractServerImplBuilder; +import io.grpc.inprocess.InternalInProcessServerBuilder; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; @@ -30,9 +31,12 @@ public class InProcessTest extends AbstractInteropTest { private static final String SERVER_NAME = "test"; @Override - protected AbstractServerImplBuilder getServerBuilder() { + protected ServerBuilder getServerBuilder() { // Starts the in-process server. - return InProcessServerBuilder.forName(SERVER_NAME); + InProcessServerBuilder builder = InProcessServerBuilder.forName(SERVER_NAME); + // Disable the default census stats tracer, use testing tracer instead. + InternalInProcessServerBuilder.setStatsEnabled(builder, false); + return builder.addStreamTracerFactory(createCustomCensusTracerFactory()); } @Override @@ -43,6 +47,12 @@ protected InProcessChannelBuilder createChannelBuilder() { return builder.intercept(createCensusStatsClientInterceptor()); } + @Override + protected boolean customCensusModulePresent() { + // Metrics values are not expected, but custom census module is still used. + return true; + } + @Override protected boolean metricsExpected() { // TODO(zhangkun83): InProcessTransport by-passes framer and deframer, thus message sizes are diff --git a/interop-testing/src/test/java/io/grpc/testing/integration/TransportCompressionTest.java b/interop-testing/src/test/java/io/grpc/testing/integration/TransportCompressionTest.java index 1144c75073c..8d184dd4428 100644 --- a/interop-testing/src/test/java/io/grpc/testing/integration/TransportCompressionTest.java +++ b/interop-testing/src/test/java/io/grpc/testing/integration/TransportCompressionTest.java @@ -31,13 +31,14 @@ import io.grpc.ForwardingClientCallListener; import io.grpc.Metadata; import io.grpc.MethodDescriptor; +import io.grpc.ServerBuilder; import io.grpc.ServerCall; import io.grpc.ServerCall.Listener; import io.grpc.ServerCallHandler; import io.grpc.ServerInterceptor; -import io.grpc.internal.AbstractServerImplBuilder; import io.grpc.internal.GrpcUtil; import io.grpc.netty.InternalNettyChannelBuilder; +import io.grpc.netty.InternalNettyServerBuilder; import io.grpc.netty.NettyChannelBuilder; import io.grpc.netty.NettyServerBuilder; import io.grpc.testing.integration.Messages.BoolValue; @@ -83,8 +84,8 @@ public static void registerCompressors() { } @Override - protected AbstractServerImplBuilder getServerBuilder() { - return NettyServerBuilder.forPort(0) + protected ServerBuilder getServerBuilder() { + NettyServerBuilder builder = NettyServerBuilder.forPort(0) .maxInboundMessageSize(AbstractInteropTest.MAX_MESSAGE_SIZE) .compressorRegistry(compressors) .decompressorRegistry(decompressors) @@ -98,6 +99,9 @@ public Listener interceptCall(ServerCall call, return listener; } }); + // Disable the default census stats tracer, use testing tracer instead. + InternalNettyServerBuilder.setStatsEnabled(builder, false); + return builder.addStreamTracerFactory(createCustomCensusTracerFactory()); } @Test diff --git a/netty/src/main/java/io/grpc/netty/InternalNettyServerBuilder.java b/netty/src/main/java/io/grpc/netty/InternalNettyServerBuilder.java index e89593364b3..d878e11d4d0 100644 --- a/netty/src/main/java/io/grpc/netty/InternalNettyServerBuilder.java +++ b/netty/src/main/java/io/grpc/netty/InternalNettyServerBuilder.java @@ -17,15 +17,27 @@ package io.grpc.netty; import io.grpc.Internal; +import io.grpc.ServerStreamTracer; import io.grpc.internal.SharedResourcePool; +import io.grpc.internal.TransportTracer; import io.netty.channel.socket.nio.NioServerSocketChannel; +import java.util.List; /** - * Internal {@link InternalNettyServerBuilder} accessor. This is intended for usage internal to + * Internal {@link NettyServerBuilder} accessor. This is intended for usage internal to * the gRPC team. If you *really* think you need to use this, contact the gRPC team first. */ @Internal public final class InternalNettyServerBuilder { + public static List buildTransportServers(NettyServerBuilder builder, + List streamTracerFactories) { + return builder.buildTransportServers(streamTracerFactories); + } + + public static void setTransportTracerFactory(NettyServerBuilder builder, + TransportTracer.Factory transportTracerFactory) { + builder.setTransportTracerFactory(transportTracerFactory); + } public static void setStatsEnabled(NettyServerBuilder builder, boolean value) { builder.setStatsEnabled(value); diff --git a/netty/src/main/java/io/grpc/netty/NettyServerBuilder.java b/netty/src/main/java/io/grpc/netty/NettyServerBuilder.java index 4560d697da6..8bda3d7c91e 100644 --- a/netty/src/main/java/io/grpc/netty/NettyServerBuilder.java +++ b/netty/src/main/java/io/grpc/netty/NettyServerBuilder.java @@ -27,14 +27,19 @@ import com.google.common.annotations.VisibleForTesting; import com.google.errorprone.annotations.CanIgnoreReturnValue; import io.grpc.ExperimentalApi; +import io.grpc.ForwardingServerBuilder; import io.grpc.Internal; +import io.grpc.ServerBuilder; import io.grpc.ServerStreamTracer; -import io.grpc.internal.AbstractServerImplBuilder; import io.grpc.internal.FixedObjectPool; import io.grpc.internal.GrpcUtil; +import io.grpc.internal.InternalServer; import io.grpc.internal.KeepAliveManager; import io.grpc.internal.ObjectPool; +import io.grpc.internal.ServerImplBuilder; +import io.grpc.internal.ServerImplBuilder.ClientTransportServersBuilder; import io.grpc.internal.SharedResourcePool; +import io.grpc.internal.TransportTracer; import io.netty.channel.ChannelFactory; import io.netty.channel.ChannelOption; import io.netty.channel.EventLoopGroup; @@ -61,7 +66,7 @@ */ @ExperimentalApi("https://github.com/grpc/grpc-java/issues/1784") @CanIgnoreReturnValue -public final class NettyServerBuilder extends AbstractServerImplBuilder { +public final class NettyServerBuilder extends ForwardingServerBuilder { // 1MiB public static final int DEFAULT_FLOW_CONTROL_WINDOW = 1024 * 1024; @@ -80,8 +85,10 @@ public final class NettyServerBuilder extends AbstractServerImplBuilder DEFAULT_WORKER_EVENT_LOOP_GROUP_POOL = SharedResourcePool.forResource(Utils.DEFAULT_WORKER_EVENT_LOOP_GROUP); + private final ServerImplBuilder serverImplBuilder; private final List listenAddresses = new ArrayList<>(); + private TransportTracer.Factory transportTracerFactory = TransportTracer.getDefaultFactory(); private ChannelFactory channelFactory = Utils.DEFAULT_SERVER_CHANNEL_FACTORY; private final Map, Object> channelOptions = new HashMap<>(); @@ -128,16 +135,32 @@ public static NettyServerBuilder forAddress(SocketAddress address) { return new NettyServerBuilder(address); } + private final class NettyClientTransportServersBuilder implements ClientTransportServersBuilder { + @Override + public List buildClientTransportServers( + List streamTracerFactories) { + return buildTransportServers(streamTracerFactories); + } + } + @CheckReturnValue private NettyServerBuilder(int port) { + serverImplBuilder = new ServerImplBuilder(new NettyClientTransportServersBuilder()); this.listenAddresses.add(new InetSocketAddress(port)); } @CheckReturnValue private NettyServerBuilder(SocketAddress address) { + serverImplBuilder = new ServerImplBuilder(new NettyClientTransportServersBuilder()); this.listenAddresses.add(address); } + @Internal + @Override + protected ServerBuilder delegate() { + return serverImplBuilder; + } + /** * Adds an additional address for this server to listen on. Callers must ensure that all socket * addresses are compatible with the Netty channel type, and that they don't conflict with each @@ -316,24 +339,20 @@ public final NettyServerBuilder protocolNegotiator( return this; } - @Override - protected void setTracingEnabled(boolean value) { - super.setTracingEnabled(value); + void setTracingEnabled(boolean value) { + this.serverImplBuilder.setTracingEnabled(value); } - @Override - protected void setStatsEnabled(boolean value) { - super.setStatsEnabled(value); + void setStatsEnabled(boolean value) { + this.serverImplBuilder.setStatsEnabled(value); } - @Override - protected void setStatsRecordStartedRpcs(boolean value) { - super.setStatsRecordStartedRpcs(value); + void setStatsRecordStartedRpcs(boolean value) { + this.serverImplBuilder.setStatsRecordStartedRpcs(value); } - @Override - protected void setStatsRecordRealTimeMetrics(boolean value) { - super.setStatsRecordRealTimeMetrics(value); + void setStatsRecordRealTimeMetrics(boolean value) { + this.serverImplBuilder.setStatsRecordRealTimeMetrics(value); } /** @@ -562,16 +581,15 @@ public NettyServerBuilder permitKeepAliveWithoutCalls(boolean permit) { return this; } - @Override @CheckReturnValue - protected List buildTransportServers( + List buildTransportServers( List streamTracerFactories) { assertEventLoopsAndChannelType(); ProtocolNegotiator negotiator = protocolNegotiator; if (negotiator == null) { negotiator = sslContext != null - ? ProtocolNegotiators.serverTls(sslContext, this.getExecutorPool()) + ? ProtocolNegotiators.serverTls(sslContext, this.serverImplBuilder.getExecutorPool()) : ProtocolNegotiators.serverPlaintext(); } @@ -580,12 +598,12 @@ protected List buildTransportServers( NettyServer transportServer = new NettyServer( listenAddress, channelFactory, channelOptions, childChannelOptions, bossEventLoopGroupPool, workerEventLoopGroupPool, forceHeapBuffer, negotiator, - streamTracerFactories, getTransportTracerFactory(), maxConcurrentCallsPerConnection, + streamTracerFactories, transportTracerFactory, maxConcurrentCallsPerConnection, autoFlowControl, flowControlWindow, maxMessageSize, maxHeaderListSize, keepAliveTimeInNanos, keepAliveTimeoutInNanos, maxConnectionIdleInNanos, maxConnectionAgeInNanos, maxConnectionAgeGraceInNanos, permitKeepAliveWithoutCalls, permitKeepAliveTimeInNanos, - getChannelz()); + this.serverImplBuilder.getChannelz()); transportServers.add(transportServer); } return Collections.unmodifiableList(transportServers); @@ -605,6 +623,12 @@ void assertEventLoopsAndChannelType() { + "neither should be"); } + NettyServerBuilder setTransportTracerFactory( + TransportTracer.Factory transportTracerFactory) { + this.transportTracerFactory = transportTracerFactory; + return this; + } + @Override public NettyServerBuilder useTransportSecurity(File certChain, File privateKey) { try { diff --git a/okhttp/src/test/java/io/grpc/okhttp/OkHttpTransportTest.java b/okhttp/src/test/java/io/grpc/okhttp/OkHttpTransportTest.java index 8e99b549a31..1f812fe0644 100644 --- a/okhttp/src/test/java/io/grpc/okhttp/OkHttpTransportTest.java +++ b/okhttp/src/test/java/io/grpc/okhttp/OkHttpTransportTest.java @@ -18,12 +18,12 @@ import io.grpc.ServerStreamTracer; import io.grpc.internal.AbstractTransportTest; -import io.grpc.internal.AccessProtectedHack; import io.grpc.internal.ClientTransportFactory; import io.grpc.internal.FakeClock; import io.grpc.internal.GrpcUtil; import io.grpc.internal.InternalServer; import io.grpc.internal.ManagedClientTransport; +import io.grpc.netty.InternalNettyServerBuilder; import io.grpc.netty.NettyServerBuilder; import java.net.InetSocketAddress; import java.util.List; @@ -53,23 +53,21 @@ public void releaseClientFactory() { @Override protected List newServer( List streamTracerFactories) { - return AccessProtectedHack.serverBuilderBuildTransportServer( - NettyServerBuilder - .forPort(0) - .flowControlWindow(AbstractTransportTest.TEST_FLOW_CONTROL_WINDOW), - streamTracerFactories, - fakeClockTransportTracer); + NettyServerBuilder builder = NettyServerBuilder + .forPort(0) + .flowControlWindow(AbstractTransportTest.TEST_FLOW_CONTROL_WINDOW); + InternalNettyServerBuilder.setTransportTracerFactory(builder, fakeClockTransportTracer); + return InternalNettyServerBuilder.buildTransportServers(builder, streamTracerFactories); } @Override protected List newServer( int port, List streamTracerFactories) { - return AccessProtectedHack.serverBuilderBuildTransportServer( - NettyServerBuilder - .forAddress(new InetSocketAddress(port)) - .flowControlWindow(AbstractTransportTest.TEST_FLOW_CONTROL_WINDOW), - streamTracerFactories, - fakeClockTransportTracer); + NettyServerBuilder builder = NettyServerBuilder + .forAddress(new InetSocketAddress(port)) + .flowControlWindow(AbstractTransportTest.TEST_FLOW_CONTROL_WINDOW); + InternalNettyServerBuilder.setTransportTracerFactory(builder, fakeClockTransportTracer); + return InternalNettyServerBuilder.buildTransportServers(builder, streamTracerFactories); } @Override From 1e2c4604a5d4cc70f2bf29d4cec56a5db37a28d8 Mon Sep 17 00:00:00 2001 From: Sergii Tkachenko Date: Wed, 2 Sep 2020 16:49:11 -0400 Subject: [PATCH 3/3] okhttp, testing: remove server builder accessor hacks --- .../io/grpc/internal/AccessProtectedHack.java | 33 ----------------- .../io/grpc/internal/TestingAccessor.java | 35 ------------------- 2 files changed, 68 deletions(-) delete mode 100644 okhttp/src/test/java/io/grpc/internal/AccessProtectedHack.java delete mode 100644 testing/src/main/java/io/grpc/internal/TestingAccessor.java diff --git a/okhttp/src/test/java/io/grpc/internal/AccessProtectedHack.java b/okhttp/src/test/java/io/grpc/internal/AccessProtectedHack.java deleted file mode 100644 index 6b53d821731..00000000000 --- a/okhttp/src/test/java/io/grpc/internal/AccessProtectedHack.java +++ /dev/null @@ -1,33 +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.internal; - -import io.grpc.ServerStreamTracer; -import java.util.List; - -/** A hack to access protected methods from io.grpc.internal. */ -public final class AccessProtectedHack { - public static List serverBuilderBuildTransportServer( - AbstractServerImplBuilder builder, - List streamTracerFactories, - TransportTracer.Factory transportTracerFactory) { - builder.transportTracerFactory = transportTracerFactory; - return builder.buildTransportServers(streamTracerFactories); - } - - private AccessProtectedHack() {} -} diff --git a/testing/src/main/java/io/grpc/internal/TestingAccessor.java b/testing/src/main/java/io/grpc/internal/TestingAccessor.java deleted file mode 100644 index 92dc114d9c6..00000000000 --- a/testing/src/main/java/io/grpc/internal/TestingAccessor.java +++ /dev/null @@ -1,35 +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.internal; - -/** - * Test helper that allows accessing package-private stuff. - */ -public final class TestingAccessor { - - /** - * Disable or enable server side census stats features. - */ - public static void setStatsEnabled( - AbstractServerImplBuilder builder, - boolean statsEnabled) { - builder.setStatsEnabled(statsEnabled); - } - - private TestingAccessor() { - } -}