Skip to content

Commit aa5637e

Browse files
OrDTestersbeiwei30
authored andcommitted
Resetting ExtensionLoader to remove test order dependencies in StickyTest (#2807)
1 parent dabd428 commit aa5637e

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

dubbo-cluster/src/test/java/org/apache/dubbo/rpc/cluster/StickyTest.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
import org.apache.dubbo.common.Constants;
2121
import org.apache.dubbo.common.URL;
22+
import org.apache.dubbo.common.extension.ExtensionLoader;
2223
import org.apache.dubbo.rpc.Invocation;
2324
import org.apache.dubbo.rpc.Invoker;
2425
import org.apache.dubbo.rpc.Result;
@@ -68,6 +69,8 @@ public void setUp() throws Exception {
6869
invokers.add(invoker2);
6970

7071
clusterinvoker = new StickyClusterInvoker<StickyTest>(dic);
72+
73+
ExtensionLoader.resetExtensionLoader(LoadBalance.class);
7174
}
7275

7376
@Test

dubbo-common/src/main/java/org/apache/dubbo/common/extension/ExtensionLoader.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,20 @@ public static <T> ExtensionLoader<T> getExtensionLoader(Class<T> type) {
124124
return loader;
125125
}
126126

127+
// For testing purposes only
128+
public static void resetExtensionLoader(Class type) {
129+
ExtensionLoader loader = EXTENSION_LOADERS.get(type);
130+
if (loader != null) {
131+
// Remove all instances associated with this loader as well
132+
Map<String, Class<?>> classes = loader.getExtensionClasses();
133+
for (Map.Entry<String, Class<?>> entry : classes.entrySet()) {
134+
EXTENSION_INSTANCES.remove(entry.getValue());
135+
}
136+
classes.clear();
137+
EXTENSION_LOADERS.remove(type);
138+
}
139+
}
140+
127141
private static ClassLoader findClassLoader() {
128142
return ClassHelper.getClassLoader(ExtensionLoader.class);
129143
}

0 commit comments

Comments
 (0)