|
@@ -23,10 +23,12 @@ import java.util.ArrayList;
|
|
|
import java.util.Arrays;
|
|
|
import java.util.Collections;
|
|
|
import java.util.Comparator;
|
|
|
+import java.util.HashSet;
|
|
|
import java.util.List;
|
|
|
+import java.util.Set;
|
|
|
|
|
|
+import com.google.common.collect.Sets;
|
|
|
import org.apache.commons.lang.ClassUtils;
|
|
|
-import org.apache.hadoop.hdfs.protocol.ReconfigurationProtocol;
|
|
|
import org.apache.hadoop.hdfs.qjournal.server.JournalNodeRpcServer;
|
|
|
import org.apache.hadoop.hdfs.server.namenode.NameNodeRpcServer;
|
|
|
import org.apache.hadoop.hdfs.server.datanode.DataNode;
|
|
@@ -57,7 +59,7 @@ public class TestHDFSPolicyProvider {
|
|
|
private static final Logger LOG =
|
|
|
LoggerFactory.getLogger(TestHDFSPolicyProvider.class);
|
|
|
|
|
|
- private static List<Class<?>> policyProviderProtocols;
|
|
|
+ private static Set<Class<?>> policyProviderProtocols;
|
|
|
|
|
|
private static final Comparator<Class<?>> CLASS_NAME_COMPARATOR =
|
|
|
new Comparator<Class<?>>() {
|
|
@@ -75,11 +77,10 @@ public class TestHDFSPolicyProvider {
|
|
|
@BeforeClass
|
|
|
public static void initialize() {
|
|
|
Service[] services = new HDFSPolicyProvider().getServices();
|
|
|
- policyProviderProtocols = new ArrayList<>(services.length);
|
|
|
+ policyProviderProtocols = new HashSet<>(services.length);
|
|
|
for (Service service : services) {
|
|
|
policyProviderProtocols.add(service.getProtocol());
|
|
|
}
|
|
|
- Collections.sort(policyProviderProtocols, CLASS_NAME_COMPARATOR);
|
|
|
}
|
|
|
|
|
|
public TestHDFSPolicyProvider(Class<?> rpcServerClass) {
|
|
@@ -98,29 +99,25 @@ public class TestHDFSPolicyProvider {
|
|
|
@Test
|
|
|
public void testPolicyProviderForServer() {
|
|
|
List<?> ifaces = ClassUtils.getAllInterfaces(rpcServerClass);
|
|
|
- List<Class<?>> serverProtocols = new ArrayList<>(ifaces.size());
|
|
|
+ Set<Class<?>> serverProtocols = new HashSet<>(ifaces.size());
|
|
|
for (Object obj : ifaces) {
|
|
|
Class<?> iface = (Class<?>)obj;
|
|
|
- // ReconfigurationProtocol is not covered in HDFSPolicyProvider
|
|
|
- // currently, so we have a special case to skip it. This needs follow-up
|
|
|
- // investigation.
|
|
|
- if (iface.getSimpleName().endsWith("Protocol") &&
|
|
|
- iface != ReconfigurationProtocol.class) {
|
|
|
+ if (iface.getSimpleName().endsWith("Protocol")) {
|
|
|
serverProtocols.add(iface);
|
|
|
}
|
|
|
}
|
|
|
- Collections.sort(serverProtocols, CLASS_NAME_COMPARATOR);
|
|
|
LOG.info("Running test {} for RPC server {}. Found server protocols {} "
|
|
|
+ "and policy provider protocols {}.", testName.getMethodName(),
|
|
|
rpcServerClass.getName(), serverProtocols, policyProviderProtocols);
|
|
|
assertFalse("Expected to find at least one protocol in server.",
|
|
|
serverProtocols.isEmpty());
|
|
|
+ final Set<Class<?>> differenceSet =
|
|
|
+ Sets.difference(serverProtocols, policyProviderProtocols);
|
|
|
assertTrue(
|
|
|
- String.format("Expected all protocols for server %s to be defined in "
|
|
|
- + "%s. Server contains protocols %s. Policy provider contains "
|
|
|
- + "protocols %s.", rpcServerClass.getName(),
|
|
|
- HDFSPolicyProvider.class.getName(), serverProtocols,
|
|
|
- policyProviderProtocols),
|
|
|
- policyProviderProtocols.containsAll(serverProtocols));
|
|
|
+ String.format("Following protocols for server %s are not defined in "
|
|
|
+ + "%s: %s",
|
|
|
+ rpcServerClass.getName(), HDFSPolicyProvider.class.getName(),
|
|
|
+ Arrays.toString(differenceSet.toArray())),
|
|
|
+ differenceSet.isEmpty());
|
|
|
}
|
|
|
}
|