From 2c5c69b1c0d6a66e83b67eba6a731d23ce1da96e Mon Sep 17 00:00:00 2001 From: Sergii Tkachenko Date: Wed, 4 Oct 2023 12:24:10 -0700 Subject: [PATCH] Fix ChannelAndServerBuilderTest --- .../io/grpc/ChannelAndServerBuilderTest.java | 24 ++++++++++++++----- 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/interop-testing/src/test/java/io/grpc/ChannelAndServerBuilderTest.java b/interop-testing/src/test/java/io/grpc/ChannelAndServerBuilderTest.java index 4e45b82afe1..cabe757a9e4 100644 --- a/interop-testing/src/test/java/io/grpc/ChannelAndServerBuilderTest.java +++ b/interop-testing/src/test/java/io/grpc/ChannelAndServerBuilderTest.java @@ -19,6 +19,7 @@ import static org.junit.Assert.assertSame; import static org.junit.Assert.assertTrue; +import com.google.common.collect.ImmutableSet; import com.google.common.reflect.ClassPath; import com.google.common.reflect.ClassPath.ClassInfo; import com.google.common.truth.Truth; @@ -46,17 +47,29 @@ public class ChannelAndServerBuilderTest { public Class builderClass; /** - * Javadoc. + * Returns the list of classes that have ServerBuilder or ManagedChannelBuilder in their class + * hierarchy and need to be checked for proper overrides of the static constructors. */ @Parameters(name = "class={0}") public static Collection params() throws Exception { ClassLoader loader = ChannelAndServerBuilderTest.class.getClassLoader(); - Collection classInfos = + ImmutableSet classInfos = ClassPath.from(loader).getTopLevelClassesRecursive("io.grpc"); + // Java 9 doesn't expose the URLClassLoader, which breaks searching through the classpath if (classInfos.isEmpty()) { return new ArrayList<>(); } + + // Exceptions from the check classes themselves, and ForwardingChannelBuilder. + // ForwardingChannelBuilder is deprecated and was stripped off of unnecessary methods, + // which it inherits from ForwardingChannelBuilder2. + @SuppressWarnings("deprecation") + ImmutableSet> ignoreClasses = ImmutableSet.of( + ServerBuilder.class, + ManagedChannelBuilder.class, + ForwardingChannelBuilder.class); + List classes = new ArrayList<>(); for (ClassInfo classInfo : classInfos) { String className = classInfo.getName(); @@ -64,12 +77,11 @@ public static Collection params() throws Exception { continue; } Class clazz = Class.forName(className, false /*initialize*/, loader); - if (ServerBuilder.class.isAssignableFrom(clazz) && clazz != ServerBuilder.class) { - classes.add(new Object[]{clazz}); + if (ignoreClasses.contains(clazz)) { continue; } - if (ManagedChannelBuilder.class.isAssignableFrom(clazz) - && clazz != ManagedChannelBuilder.class && clazz != ForwardingChannelBuilder2.class) { + if (ServerBuilder.class.isAssignableFrom(clazz) + || ManagedChannelBuilder.class.isAssignableFrom(clazz)) { classes.add(new Object[]{clazz}); } }