Resetting ExtensionLoader to remove test order dependencies in StickyTest (#2807)
authorOrDTesters <44483852+OrDTesters@users.noreply.github.com>
Mon, 10 Dec 2018 09:16:56 +0000 (03:16 -0600)
committerIan Luo <ian.luo@gmail.com>
Mon, 10 Dec 2018 09:16:56 +0000 (17:16 +0800)
dubbo-cluster/src/test/java/org/apache/dubbo/rpc/cluster/StickyTest.java
dubbo-common/src/main/java/org/apache/dubbo/common/extension/ExtensionLoader.java

index 869ac52..f8fdb31 100644 (file)
@@ -19,6 +19,7 @@ package org.apache.dubbo.rpc.cluster;
 
 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 class StickyTest {
         invokers.add(invoker2);
 
         clusterinvoker = new StickyClusterInvoker<StickyTest>(dic);
+
+        ExtensionLoader.resetExtensionLoader(LoadBalance.class);
     }
 
     @Test
index 49a7bdb..54de280 100644 (file)
@@ -124,6 +124,20 @@ public class ExtensionLoader<T> {
         return loader;\r
     }\r
 \r
+    // For testing purposes only\r
+    public static void resetExtensionLoader(Class type) {\r
+        ExtensionLoader loader = EXTENSION_LOADERS.get(type);\r
+        if (loader != null) {\r
+            // Remove all instances associated with this loader as well\r
+            Map<String, Class<?>> classes = loader.getExtensionClasses();\r
+            for (Map.Entry<String, Class<?>> entry : classes.entrySet()) {\r
+                EXTENSION_INSTANCES.remove(entry.getValue());\r
+            }\r
+            classes.clear();\r
+            EXTENSION_LOADERS.remove(type);\r
+        }\r
+    }\r
+\r
     private static ClassLoader findClassLoader() {\r
         return ClassHelper.getClassLoader(ExtensionLoader.class);\r
     }\r