interop-testing: support just ServerBuilder types

This commit is contained in:
Carl Mastrangelo 2019-06-26 16:47:17 -07:00 committed by GitHub
parent 36476cb1f8
commit d5e1a4bb5d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 20 additions and 10 deletions

View File

@ -52,6 +52,7 @@ import io.grpc.ManagedChannel;
import io.grpc.Metadata; import io.grpc.Metadata;
import io.grpc.MethodDescriptor; import io.grpc.MethodDescriptor;
import io.grpc.Server; import io.grpc.Server;
import io.grpc.ServerBuilder;
import io.grpc.ServerCall; import io.grpc.ServerCall;
import io.grpc.ServerCallHandler; import io.grpc.ServerCallHandler;
import io.grpc.ServerInterceptor; import io.grpc.ServerInterceptor;
@ -160,6 +161,7 @@ public abstract class AbstractInteropTest {
private ScheduledExecutorService testServiceExecutor; private ScheduledExecutorService testServiceExecutor;
private Server server; private Server server;
private boolean customCensusModulePresent;
private final LinkedBlockingQueue<ServerStreamTracerInfo> serverStreamTracers = private final LinkedBlockingQueue<ServerStreamTracerInfo> serverStreamTracers =
new LinkedBlockingQueue<>(); new LinkedBlockingQueue<>();
@ -213,7 +215,7 @@ public abstract class AbstractInteropTest {
protected static final Empty EMPTY = Empty.getDefaultInstance(); protected static final Empty EMPTY = Empty.getDefaultInstance();
private void startServer() { private void startServer() {
AbstractServerImplBuilder<?> builder = getServerBuilder(); ServerBuilder<?> builder = getServerBuilder();
if (builder == null) { if (builder == null) {
server = null; server = null;
return; return;
@ -233,14 +235,21 @@ public abstract class AbstractInteropTest {
new TestServiceImpl(testServiceExecutor), new TestServiceImpl(testServiceExecutor),
allInterceptors)) allInterceptors))
.addStreamTracerFactory(serverStreamTracerFactory); .addStreamTracerFactory(serverStreamTracerFactory);
io.grpc.internal.TestingAccessor.setStatsImplementation( if (builder instanceof AbstractServerImplBuilder) {
builder, customCensusModulePresent = true;
new CensusStatsModule( AbstractServerImplBuilder<?> sb = (AbstractServerImplBuilder<?>) builder;
tagger, io.grpc.internal.TestingAccessor.setStatsImplementation(
tagContextBinarySerializer, sb,
serverStatsRecorder, new CensusStatsModule(
GrpcUtil.STOPWATCH_SUPPLIER, tagger,
true, true, true, false /* real-time metrics */)); tagContextBinarySerializer,
serverStatsRecorder,
GrpcUtil.STOPWATCH_SUPPLIER,
true, true, true, false /* real-time metrics */));
}
if (metricsExpected()) {
assertThat(builder).isInstanceOf(AbstractServerImplBuilder.class);
}
try { try {
server = builder.build().start(); server = builder.build().start();
} catch (IOException ex) { } catch (IOException ex) {
@ -337,7 +346,7 @@ public abstract class AbstractInteropTest {
* it shouldn't start a server in the same process. * it shouldn't start a server in the same process.
*/ */
@Nullable @Nullable
protected AbstractServerImplBuilder<?> getServerBuilder() { protected ServerBuilder<?> getServerBuilder() {
return null; return null;
} }
@ -1472,6 +1481,7 @@ public abstract class AbstractInteropTest {
@Test(timeout = 10000) @Test(timeout = 10000)
public void censusContextsPropagated() { public void censusContextsPropagated() {
Assume.assumeTrue("Skip the test because server is not in the same process.", server != null); Assume.assumeTrue("Skip the test because server is not in the same process.", server != null);
Assume.assumeTrue(customCensusModulePresent);
Span clientParentSpan = Tracing.getTracer().spanBuilder("Test.interopTest").startSpan(); Span clientParentSpan = Tracing.getTracer().spanBuilder("Test.interopTest").startSpan();
// A valid ID is guaranteed to be unique, so we can verify it is actually propagated. // A valid ID is guaranteed to be unique, so we can verify it is actually propagated.
assertTrue(clientParentSpan.getContext().getTraceId().isValid()); assertTrue(clientParentSpan.getContext().getTraceId().isValid());