ProviderMessageRouter implements MessageHandler { protected Response call(Request request, Provider<?> provider) { try { return strategy.call(request, provider); } catch (Exception e) { return MotanFrameworkUtil.buildErrorResponse(request, new MotanBizException("provider call process error", e)); } } ProviderMessageRouter();  ProviderMessageRouter(URL url);  ProviderMessageRouter(Provider<?> provider); @Override Object handle(Channel channel, Object message); synchronized void addProvider(Provider<?> provider); synchronized void removeProvider(Provider<?> provider); int getPublicMethodCount();  }
@Test public void testCall() { ProviderMessageRouter providerMessageRouter = new ProviderMessageRouter(); Provider<ProviderA> providerA = new DefaultProvider<ProviderA>(new A(), new URL("injvm", "localhost", 0, ProviderA.class.getName()), ProviderA.class); Provider<ProviderB> providerB = new DefaultProvider<ProviderB>(new B(), new URL("injvm", "localhost", 0, ProviderB.class.getName()), ProviderB.class); providerMessageRouter.addProvider(providerA); providerMessageRouter.addProvider(providerB); Assert.assertEquals(providerMessageRouter.getPublicMethodCount(), PUBLIC_METHOD_COUNT_ALL); DefaultRequest requestA = new DefaultRequest(); requestA.setInterfaceName(com.weibo.api.motan.transport.ProviderA.class.getName()); requestA.setMethodName("providerA"); requestA.setParamtersDesc(ReflectUtil.EMPTY_PARAM); Response response = (Response) providerMessageRouter.handle(new MockChannel(TestConstants.EMPTY_URL), requestA); Assert.assertEquals("A", response.getValue()); DefaultRequest requestB = new DefaultRequest(); requestB.setInterfaceName(com.weibo.api.motan.transport.ProviderB.class.getName()); requestB.setMethodName("providerB"); requestB.setParamtersDesc(ReflectUtil.EMPTY_PARAM); response = (Response) providerMessageRouter.handle(new MockChannel(TestConstants.EMPTY_URL), requestB); Assert.assertEquals("B", response.getValue()); providerMessageRouter.removeProvider(providerA); Assert.assertEquals(providerMessageRouter.getPublicMethodCount(), PUBLIC_METHOD_COUNT_B); try { Response result = (Response) providerMessageRouter.handle(new MockChannel(TestConstants.EMPTY_URL), requestA); result.getValue(); Assert.assertTrue(false); } catch (Exception e) { Assert.assertTrue(true); } }