InjvmProtocol extends AbstractProtocol implements Protocol { @Override public <T> Exporter<T> export(Invoker<T> invoker) throws RpcException { return new InjvmExporter<T>(invoker, invoker.getUrl().getServiceKey(), exporterMap); } InjvmProtocol(); static InjvmProtocol getInjvmProtocol(); @Override int getDefaultPort(); @Override Exporter<T> export(Invoker<T> invoker); @Override Invoker<T> protocolBindingRefer(Class<T> serviceType, URL url); boolean isInjvmRefer(URL url); static final String NAME; static final int DEFAULT_PORT; }
@Test public void testLocalProtocol() throws Exception { DemoService service = new DemoServiceImpl(); Invoker<?> invoker = proxy.getInvoker(service, DemoService.class, URL.valueOf("injvm: assertTrue(invoker.isAvailable()); Exporter<?> exporter = protocol.export(invoker); exporters.add(exporter); service = proxy.getProxy(protocol.refer(DemoService.class, URL.valueOf("injvm: assertEquals(service.getSize(new String[]{"", "", ""}), 3); service.invoke("injvm: InjvmInvoker injvmInvoker = new InjvmInvoker(DemoService.class, URL.valueOf("injvm: assertFalse(injvmInvoker.isAvailable()); }
@Test public void testRemoteApplicationName() throws Exception { DemoService service = new DemoServiceImpl(); URL url = URL.valueOf("injvm: Invoker<?> invoker = proxy.getInvoker(service, DemoService.class, url); assertTrue(invoker.isAvailable()); Exporter<?> exporter = protocol.export(invoker); exporters.add(exporter); service = proxy.getProxy(protocol.refer(DemoService.class, url)); assertEquals(service.getRemoteApplicationName(), "consumer"); }