Skip to content

Commit

Permalink
improve:remove spi of TagRouter
Browse files Browse the repository at this point in the history
  • Loading branch information
xujingfeng committed Jan 17, 2019
1 parent ebc9cfa commit e59711d
Show file tree
Hide file tree
Showing 5 changed files with 260 additions and 314 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,6 @@ public class TagRouter extends AbstractRouter {
private static final int DEFAULT_PRIORITY = 100;
private static final URL ROUTER_URL = new URL("tag", Constants.ANYHOST_VALUE, 0, Constants.ANY_VALUE).addParameters(Constants.RUNTIME_KEY, "true");

public TagRouter(URL url) {
this.url = url;
url.addParameters(Constants.RUNTIME_KEY, "true");
this.priority = url.getParameter(Constants.PRIORITY_KEY, DEFAULT_PRIORITY);
}

public TagRouter() {
this.url = ROUTER_URL;
this.priority = url.getParameter(Constants.PRIORITY_KEY, DEFAULT_PRIORITY);
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
file=com.alibaba.dubbo.rpc.cluster.router.file.FileRouterFactory
script=com.alibaba.dubbo.rpc.cluster.router.script.ScriptRouterFactory
condition=com.alibaba.dubbo.rpc.cluster.router.condition.ConditionRouterFactory
tag=com.alibaba.dubbo.rpc.cluster.router.tag.TagRouterFactory
condition=com.alibaba.dubbo.rpc.cluster.router.condition.ConditionRouterFactory
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,6 @@

public class TagRouterTest {

private URL tagUrl = new URL("tag"
, Constants.ANYHOST_VALUE, 0
, Constants.ANY_VALUE)
.addParameters(
Constants.RUNTIME_KEY, "true"
);

@BeforeClass
public static void setUpBeforeClass() throws Exception {
}
Expand Down Expand Up @@ -71,7 +64,7 @@ public void testRoute_matchTag() {
invokers.add(blueInvoker);
invokers.add(defaultInvoker);

Router tagRouter = new TagRouterFactory().getRouter(tagUrl);
Router tagRouter = new TagRouter();
List<Invoker<String>> filteredInvokers = tagRouter.route(invokers, URL.valueOf("consumer://" + NetUtils.getLocalHost() + "/com.foo.BarService"), new RpcInvocation());
Assert.assertTrue(filteredInvokers.contains(redInvoker));
Assert.assertFalse(filteredInvokers.contains(yellowInvoker));
Expand Down Expand Up @@ -99,7 +92,7 @@ public void testRoute_matchDefault() {
invokers.add(blueInvoker);
invokers.add(defaultInvoker);

Router tagRouter = new TagRouterFactory().getRouter(tagUrl);
Router tagRouter = new TagRouter();
List<Invoker<String>> filteredInvokers = tagRouter.route(invokers, URL.valueOf("consumer://" + NetUtils.getLocalHost() + "/com.foo.BarService"), new RpcInvocation());
Assert.assertTrue(filteredInvokers.contains(defaultInvoker));
Assert.assertFalse(filteredInvokers.contains(yellowInvoker));
Expand Down Expand Up @@ -127,7 +120,7 @@ public void testRoute_requestWithTag_shouldDowngrade() {
invokers.add(blueInvoker);
invokers.add(defaultInvoker);

Router tagRouter = new TagRouterFactory().getRouter(tagUrl);
Router tagRouter = new TagRouter();
List<Invoker<String>> filteredInvokers = tagRouter.route(invokers, URL.valueOf("consumer://" + NetUtils.getLocalHost() + "/com.foo.BarService"), new RpcInvocation());
Assert.assertTrue(filteredInvokers.contains(defaultInvoker));
Assert.assertFalse(filteredInvokers.contains(yellowInvoker));
Expand All @@ -152,18 +145,9 @@ public void testRoute_requestWithoutTag_shouldNotDowngrade() {
invokers.add(yellowInvoker);
invokers.add(blueInvoker);

Router tagRouter = new TagRouterFactory().getRouter(tagUrl);
Router tagRouter = new TagRouter();
List<Invoker<String>> filteredInvokers = tagRouter.route(invokers, URL.valueOf("consumer://" + NetUtils.getLocalHost() + "/com.foo.BarService"), new RpcInvocation());
Assert.assertEquals(0, filteredInvokers.size());
}

@Test
public void testRoute_createBySpi() {
URL zkProvider = URL.valueOf("zookeeper://10.20.3.1:20880/com.foo.BarService?router=tag");
String parameter = zkProvider.getParameter(Constants.ROUTER_KEY);
RouterFactory routerFactory = ExtensionLoader.getExtensionLoader(RouterFactory.class).getExtension(parameter);
Router tagRouter = routerFactory.getRouter(zkProvider);
Assert.assertTrue(tagRouter instanceof TagRouter);
}

}
Loading

0 comments on commit e59711d

Please sign in to comment.