RmiProtocol extends AbstractProxyProtocol { public RmiProtocol() { super(RemoteAccessException.class, RemoteException.class); } RmiProtocol(); @Override int getDefaultPort(); static final int DEFAULT_PORT; }
@Test public void testRmiProtocol() throws Exception { { DemoService service = new DemoServiceImpl(); Exporter<?> rpcExporter = protocol.export(proxy.getInvoker(service, DemoService.class, URL.valueOf("rmi: service = proxy.getProxy(protocol.refer(DemoService.class, URL.valueOf("rmi: assertEquals(service.getSize(null), -1); assertEquals(service.getSize(new String[]{"", "", ""}), 3); Object result = service.invoke("rmi: assertEquals("rmi: rpcExporter.unexport(); } { int port = NetUtils.getAvailablePort(); RemoteService remoteService = new RemoteServiceImpl(); Exporter<?> rpcExporter = protocol.export(proxy.getInvoker(remoteService, RemoteService.class, URL.valueOf("rmi: remoteService = proxy.getProxy(protocol.refer(RemoteService.class, URL.valueOf("rmi: remoteService.getThreadName(); for (int i = 0; i < 100; i++) { String say = remoteService.sayHello("abcd"); assertEquals("hello abcd@" + RemoteServiceImpl.class.getName(), say); } rpcExporter.unexport(); } }