From aa5637e85fb23d453ac226ec2622269c9993ace3 Mon Sep 17 00:00:00 2001 From: OrDTesters <44483852+OrDTesters@users.noreply.github.com> Date: Mon, 10 Dec 2018 03:16:56 -0600 Subject: [PATCH] Resetting ExtensionLoader to remove test order dependencies in StickyTest (#2807) --- .../org/apache/dubbo/rpc/cluster/StickyTest.java | 3 +++ .../dubbo/common/extension/ExtensionLoader.java | 14 ++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/dubbo-cluster/src/test/java/org/apache/dubbo/rpc/cluster/StickyTest.java b/dubbo-cluster/src/test/java/org/apache/dubbo/rpc/cluster/StickyTest.java index 869ac524464..f8fdb3178b1 100644 --- a/dubbo-cluster/src/test/java/org/apache/dubbo/rpc/cluster/StickyTest.java +++ b/dubbo-cluster/src/test/java/org/apache/dubbo/rpc/cluster/StickyTest.java @@ -19,6 +19,7 @@ import org.apache.dubbo.common.Constants; import org.apache.dubbo.common.URL; +import org.apache.dubbo.common.extension.ExtensionLoader; import org.apache.dubbo.rpc.Invocation; import org.apache.dubbo.rpc.Invoker; import org.apache.dubbo.rpc.Result; @@ -68,6 +69,8 @@ public void setUp() throws Exception { invokers.add(invoker2); clusterinvoker = new StickyClusterInvoker(dic); + + ExtensionLoader.resetExtensionLoader(LoadBalance.class); } @Test diff --git a/dubbo-common/src/main/java/org/apache/dubbo/common/extension/ExtensionLoader.java b/dubbo-common/src/main/java/org/apache/dubbo/common/extension/ExtensionLoader.java index 49a7bdbde24..54de28041b3 100644 --- a/dubbo-common/src/main/java/org/apache/dubbo/common/extension/ExtensionLoader.java +++ b/dubbo-common/src/main/java/org/apache/dubbo/common/extension/ExtensionLoader.java @@ -124,6 +124,20 @@ public static ExtensionLoader getExtensionLoader(Class type) { return loader; } + // For testing purposes only + public static void resetExtensionLoader(Class type) { + ExtensionLoader loader = EXTENSION_LOADERS.get(type); + if (loader != null) { + // Remove all instances associated with this loader as well + Map> classes = loader.getExtensionClasses(); + for (Map.Entry> entry : classes.entrySet()) { + EXTENSION_INSTANCES.remove(entry.getValue()); + } + classes.clear(); + EXTENSION_LOADERS.remove(type); + } + } + private static ClassLoader findClassLoader() { return ClassHelper.getClassLoader(ExtensionLoader.class); }