提交 cfd6a08c 编写于 作者: W william.liangf

DUBBO-204 增加本地路由单元测试

git-svn-id: http://code.alibabatech.com/svn/dubbo/trunk@1613 1a56cb94-b969-4eaa-88fa-be21384802f2
上级 e0ffd001
/*
* Copyright 1999-2011 Alibaba Group.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.dubbo.rpc.cluster.router.condition;
import java.util.ArrayList;
import java.util.List;
import junit.framework.Assert;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import com.alibaba.dubbo.common.Constants;
import com.alibaba.dubbo.common.URL;
import com.alibaba.dubbo.common.utils.NetUtils;
import com.alibaba.dubbo.rpc.Invoker;
import com.alibaba.dubbo.rpc.RpcInvocation;
import com.alibaba.dubbo.rpc.cluster.Router;
import com.alibaba.dubbo.rpc.cluster.router.MockInvoker;
public class ConditionRouterTest {
@BeforeClass
public static void setUpBeforeClass() throws Exception {
}
@Before
public void setUp() throws Exception {
}
private URL SCRIPT_URL = URL.valueOf("condition://0.0.0.0/com.foo.BarService");
private URL getRouteUrl(String rule) {
return SCRIPT_URL.addParameterAndEncoded(Constants.RULE_KEY, rule);
}
@Test
public void testRoute_ReturnAll(){
Router router = new ConditionRouterFactory().getRouter(getRouteUrl("consumer.host = " + NetUtils.getLocalHost() + " => " + " provider.host = " + NetUtils.getLocalHost()));
List<Invoker<String>> invokers = new ArrayList<Invoker<String>>();
invokers.add(new MockInvoker<String>());
invokers.add(new MockInvoker<String>());
invokers.add(new MockInvoker<String>());
List<Invoker<String>> fileredInvokers = router.route(invokers, URL.valueOf("consumer://" + NetUtils.getLocalHost() + "/com.foo.BarService"), new RpcInvocation());
Assert.assertEquals(invokers, fileredInvokers);
}
@Test
public void testRoute_PickInvokers(){
Router router = new ConditionRouterFactory().getRouter(getRouteUrl("consumer.host = " + NetUtils.getLocalHost() + " => " + " provider.host = " + NetUtils.getLocalHost()));
List<Invoker<String>> invokers = new ArrayList<Invoker<String>>();
Invoker<String> invoker1 = new MockInvoker<String>(URL.valueOf("dubbo://10.20.3.3:20880/com.foo.BarService")) ;
Invoker<String> invoker2 = new MockInvoker<String>(URL.valueOf("dubbo://" + NetUtils.getLocalHost() + ":20880/com.foo.BarService")) ;
Invoker<String> invoker3 = new MockInvoker<String>(URL.valueOf("dubbo://" + NetUtils.getLocalHost() + ":20880/com.foo.BarService")) ;
invokers.add(invoker1);
invokers.add(invoker2);
invokers.add(invoker3);
List<Invoker<String>> fileredInvokers = router.route(invokers, URL.valueOf("consumer://" + NetUtils.getLocalHost() + "/com.foo.BarService"), new RpcInvocation());
Assert.assertEquals(2, fileredInvokers.size());
Assert.assertEquals(invoker2, fileredInvokers.get(0));
Assert.assertEquals(invoker3, fileredInvokers.get(1));
}
}
\ No newline at end of file
......@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.dubbo.rpc.cluster.router;
package com.alibaba.dubbo.rpc.cluster.router.script;
import java.util.ArrayList;
......@@ -30,9 +30,10 @@ import com.alibaba.dubbo.common.URL;
import com.alibaba.dubbo.rpc.Invoker;
import com.alibaba.dubbo.rpc.RpcInvocation;
import com.alibaba.dubbo.rpc.cluster.Router;
import com.alibaba.dubbo.rpc.cluster.router.MockInvoker;
import com.alibaba.dubbo.rpc.cluster.router.script.ScriptRouterFactory;
public class ScriptRouterEngineTest {
public class ScriptRouterTest {
@BeforeClass
public static void setUpBeforeClass() throws Exception {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册