YarRpcProtocol extends AbstractProtocol { public ProviderMessageRouter initRequestRouter(URL url, Provider<?> provider) { String ipPort = url.getServerPortStr(); ProviderMessageRouter requestRouter = ipPort2RequestRouter.get(ipPort); if (requestRouter == null) { ipPort2RequestRouter.putIfAbsent(ipPort, new YarMessageRouter(url)); requestRouter = ipPort2RequestRouter.get(ipPort); } requestRouter.addProvider(provider); return requestRouter; }  ProviderMessageRouter initRequestRouter(URL url, Provider<?> provider); void unexport(URL url, Provider<?> provider);  }
@SuppressWarnings({"unchecked", "rawtypes"}) @Test public void testInitRequestRouter() { YarRpcProtocol protocol = new YarRpcProtocol(); URL url = new URL("motan", "localhost", 8002, "urlpath"); Provider provider = new DefaultProvider(null, url, MessageHandler.class); ProviderMessageRouter router = protocol.initRequestRouter(url, provider); assertNotNull(router); URL url2 = new URL("motan", "localhost", 8003, "urlpath2"); Provider provider2 = new DefaultProvider(null, url2, MessageHandler.class); ProviderMessageRouter router2 = protocol.initRequestRouter(url2, provider2); assertNotNull(router2); assertFalse(router2.equals(router)); URL url3 = new URL("motan", "localhost", 8002, "urlpath3"); Provider provider3 = new DefaultProvider(null, url3, MessageHandler.class); ProviderMessageRouter router3 = protocol.initRequestRouter(url3, provider3); assertNotNull(router3); assertTrue(router3.equals(router)); try { protocol.initRequestRouter(url, provider); assertTrue(false); } catch (Exception e) { assertTrue(e.getMessage().contains("duplicate yar provider")); } }