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);
}
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));
}
Aggregations