Skip to content

Commit

Permalink
Revert ChannelAndServerBuilderTest
Browse files Browse the repository at this point in the history
  • Loading branch information
sergiitk committed Nov 2, 2023
1 parent b7b2bd7 commit d0ec2d9
Showing 1 changed file with 7 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
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;
Expand Down Expand Up @@ -47,40 +46,31 @@ public class ChannelAndServerBuilderTest {
public Class<?> builderClass;

/**
* 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.
* Javadoc.
*/
@Parameters(name = "class={0}")
public static Collection<Object[]> params() throws Exception {
ClassLoader loader = ChannelAndServerBuilderTest.class.getClassLoader();
ImmutableSet<ClassInfo> classInfos =
Collection<ClassInfo> 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.
ImmutableSet<Class<?>> ignoreClasses = ImmutableSet.of(
ServerBuilder.class,
ManagedChannelBuilder.class,
ForwardingChannelBuilder.class);

List<Object[]> classes = new ArrayList<>();
for (ClassInfo classInfo : classInfos) {
String className = classInfo.getName();
if (className.contains("io.grpc.netty.shaded.io.netty")) {
continue;
}
Class<?> clazz = Class.forName(className, false /*initialize*/, loader);
if (ignoreClasses.contains(clazz)) {
if (ServerBuilder.class.isAssignableFrom(clazz) && clazz != ServerBuilder.class) {
classes.add(new Object[]{clazz});
continue;
}
if (ServerBuilder.class.isAssignableFrom(clazz)
|| ManagedChannelBuilder.class.isAssignableFrom(clazz)) {
// ForwardingChannelBuilder extends ForwardingChannelBuilder2, not need for extra checks.
if (ManagedChannelBuilder.class.isAssignableFrom(clazz)
&& clazz != ManagedChannelBuilder.class && clazz != ForwardingChannelBuilder.class) {
classes.add(new Object[]{clazz});
}
}
Expand Down

0 comments on commit d0ec2d9

Please sign in to comment.