Skip to content

Commit

Permalink
Resetting ExtensionLoader to remove test order dependencies in Sticky…
Browse files Browse the repository at this point in the history
…Test (apache#2807)
  • Loading branch information
OrDTesters authored and beiwei30 committed Dec 10, 2018
1 parent dabd428 commit aa5637e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -68,6 +69,8 @@ public void setUp() throws Exception {
invokers.add(invoker2);

clusterinvoker = new StickyClusterInvoker<StickyTest>(dic);

ExtensionLoader.resetExtensionLoader(LoadBalance.class);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,20 @@ public static <T> ExtensionLoader<T> getExtensionLoader(Class<T> 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<String, Class<?>> classes = loader.getExtensionClasses();
for (Map.Entry<String, Class<?>> entry : classes.entrySet()) {
EXTENSION_INSTANCES.remove(entry.getValue());
}
classes.clear();
EXTENSION_LOADERS.remove(type);
}
}

private static ClassLoader findClassLoader() {
return ClassHelper.getClassLoader(ExtensionLoader.class);
}
Expand Down

0 comments on commit aa5637e

Please sign in to comment.