Search in sources :

Example 1 with TestChainRouter2

use of com.alipay.sofa.rpc.client.router.TestChainRouter2 in project sofa-rpc by sofastack.

the class RouterChainTest method testParseExcludeRouter.

@Test
public void testParseExcludeRouter() throws InvocationTargetException, IllegalAccessException, NoSuchMethodException {
    String methodName = "parseExcludeRouter";
    List<Router> routers = new CopyOnWriteArrayList<>();
    routers.add(new TestChainRouter1());
    routers.add(new TestChainRouter2());
    routers.add(new TestChainRouter3());
    routers.add(new TestChainRouter4());
    routers.add(new ExcludeRouter("-testChainRouter5"));
    Method parseExcludeRouter = RouterChain.class.getDeclaredMethod(methodName, List.class);
    parseExcludeRouter.setAccessible(true);
    Object invokeResult = parseExcludeRouter.invoke(Router.class, routers);
    Set<String> result = new HashSet<>();
    result.add(invokeResult.toString());
    Assert.assertEquals(1, result.size());
    Assert.assertNotNull(invokeResult);
}
Also used : Method(java.lang.reflect.Method) TestChainRouter3(com.alipay.sofa.rpc.client.router.TestChainRouter3) TestChainRouter2(com.alipay.sofa.rpc.client.router.TestChainRouter2) TestChainRouter1(com.alipay.sofa.rpc.client.router.TestChainRouter1) TestChainRouter4(com.alipay.sofa.rpc.client.router.TestChainRouter4) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 2 with TestChainRouter2

use of com.alipay.sofa.rpc.client.router.TestChainRouter2 in project sofa-rpc by sofastack.

the class RouterChainTest method buildProviderChain.

@Test
public void buildProviderChain() {
    ConsumerConfig config = new ConsumerConfig();
    config.setBootstrap("test");
    ArrayList<Router> list = new ArrayList<Router>();
    config.setRouter(Arrays.asList("testChainRouter0", "-testChainRouter8", "notExistChainRouter"));
    list.add(new TestChainRouter1());
    list.add(new TestChainRouter2());
    list.add(new TestChainRouter3());
    list.add(new TestChainRouter4());
    list.add(new ExcludeRouter("-testChainRouter5"));
    config.setRouterRef(list);
    ConsumerBootstrap consumerBootstrap = Bootstraps.from(config);
    RouterChain chain = RouterChain.buildConsumerChain(consumerBootstrap);
    // build test data
    SofaRequest request = new SofaRequest();
    request.setMethodArgs(new String[] { "xxx" });
    request.setInvokeType("sync");
    List<ProviderInfo> providerInfos = new ArrayList<ProviderInfo>();
    ProviderInfo providerInfo = new ProviderInfo();
    providerInfo.setHost("127.0.0.1");
    providerInfo.setPort(12200);
    providerInfos.add(providerInfo);
    chain.route(request, providerInfos);
    Assert.assertEquals("r0>r7>r2>r4", RpcInternalContext.getContext().getAttachment(RpcConstants.INTERNAL_KEY_ROUTER_RECORD));
}
Also used : SofaRequest(com.alipay.sofa.rpc.core.request.SofaRequest) ArrayList(java.util.ArrayList) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) TestChainRouter3(com.alipay.sofa.rpc.client.router.TestChainRouter3) TestChainRouter2(com.alipay.sofa.rpc.client.router.TestChainRouter2) ConsumerBootstrap(com.alipay.sofa.rpc.bootstrap.ConsumerBootstrap) TestChainRouter1(com.alipay.sofa.rpc.client.router.TestChainRouter1) TestChainRouter4(com.alipay.sofa.rpc.client.router.TestChainRouter4) ConsumerConfig(com.alipay.sofa.rpc.config.ConsumerConfig) Test(org.junit.Test)

Aggregations

TestChainRouter1 (com.alipay.sofa.rpc.client.router.TestChainRouter1)2 TestChainRouter2 (com.alipay.sofa.rpc.client.router.TestChainRouter2)2 TestChainRouter3 (com.alipay.sofa.rpc.client.router.TestChainRouter3)2 TestChainRouter4 (com.alipay.sofa.rpc.client.router.TestChainRouter4)2 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)2 Test (org.junit.Test)2 ConsumerBootstrap (com.alipay.sofa.rpc.bootstrap.ConsumerBootstrap)1 ConsumerConfig (com.alipay.sofa.rpc.config.ConsumerConfig)1 SofaRequest (com.alipay.sofa.rpc.core.request.SofaRequest)1 Method (java.lang.reflect.Method)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1