com.alibaba.dubbo.common.utils.NetUtils Java Examples
The following examples show how to use
com.alibaba.dubbo.common.utils.NetUtils.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: FileExchangeGroup.java From dubbox-hystrix with Apache License 2.0 | 6 votes |
public ExchangePeer joinExchange(URL url, ExchangeHandler handler) throws RemotingException { ExchangePeer peer = super.join(url, handler); try { String full = url.toFullString(); String[] lines = IOUtils.readLines(file); for (String line : lines) { if (full.equals(line)) { return peer; } } IOUtils.appendLines(file, new String[] {full}); } catch (IOException e) { throw new RemotingException(new InetSocketAddress(NetUtils.getLocalHost(), 0), getUrl().toInetSocketAddress(), e.getMessage(), e); } return peer; }
Example #2
Source File: ClientReconnectTest.java From dubbox with Apache License 2.0 | 6 votes |
/** * 重连日志的校验,时间不够shutdown time时,不能有error日志,但必须有一条warn日志 */ @Test public void testReconnectWarnLog() throws RemotingException, InterruptedException{ int port = NetUtils.getAvailablePort(); DubboAppender.doStart(); String url = "exchange://127.0.0.2:"+port + "/client.reconnect.test?check=false&" +Constants.RECONNECT_KEY+"="+1 ; //1ms reconnect,保证有足够频率的重连 try{ Exchangers.connect(url); }catch (Exception e) { //do nothing } Thread.sleep(1500);//重连线程的运行 //时间不够长,不会产生error日志 Assert.assertEquals("no error message ", 0 , LogUtil.findMessage(Level.ERROR, "client reconnect to ")); //第一次重连失败就会有warn日志 Assert.assertEquals("must have one warn message ", 1 , LogUtil.findMessage(Level.WARN, "client reconnect to ")); DubboAppender.doStop(); }
Example #3
Source File: ReferenceCountExchangeClientTest.java From dubbox with Apache License 2.0 | 6 votes |
@SuppressWarnings("unchecked") private void init(int connections){ int port = NetUtils.getAvailablePort(); URL demoUrl = URL.valueOf("dubbo://127.0.0.1:"+port+"/demo?"+Constants.CONNECTIONS_KEY+"="+connections); URL helloUrl = URL.valueOf("dubbo://127.0.0.1:"+port+"/hello?"+Constants.CONNECTIONS_KEY+"="+connections); demoExporter = export(new DemoServiceImpl(), IDemoService.class, demoUrl); helloExporter = export(new HelloServiceImpl(), IHelloService.class, helloUrl); demoServiceInvoker = (Invoker<IDemoService>) referInvoker(IDemoService.class, demoUrl); demoService = proxy.getProxy(demoServiceInvoker); Assert.assertEquals("demo", demoService.demo()); helloServiceInvoker = (Invoker<IHelloService>) referInvoker(IHelloService.class, helloUrl); helloService = proxy.getProxy(helloServiceInvoker); Assert.assertEquals("hello", helloService.hello()); demoClient = getClient(demoServiceInvoker); helloClient = getClient(helloServiceInvoker); }
Example #4
Source File: EnumBak.java From dubbox with Apache License 2.0 | 6 votes |
@Test public void testNormal(){ int port = NetUtils.getAvailablePort(); URL serviceurl = URL.valueOf("dubbo://127.0.0.1:"+port+"/test?proxy=jdk" + "&interface=" + DemoService.class.getName() + "&timeout=" + Integer.MAX_VALUE ); DemoService demo = new DemoServiceImpl(); Invoker<DemoService> invoker = proxy.getInvoker(demo, DemoService.class, serviceurl); protocol.export(invoker); URL consumerurl = serviceurl; Invoker<DemoService> reference = protocol.refer(DemoService.class, consumerurl); DemoService demoProxy = (DemoService)proxy.getProxy(reference); // System.out.println(demoProxy.getThreadName()); Assert.assertEquals((byte)-128, demoProxy.getbyte((byte)-128)); // invoker.destroy(); reference.destroy(); }
Example #5
Source File: ClientReconnectTest.java From dubbox with Apache License 2.0 | 6 votes |
/** * 重连日志的校验,不能一直抛出error日志. */ @Test public void testReconnectErrorLog() throws RemotingException, InterruptedException{ int port = NetUtils.getAvailablePort(); DubboAppender.doStart(); String url = "exchange://127.0.0.3:"+port + "/client.reconnect.test?check=false&" +Constants.RECONNECT_KEY+"="+1 + //1ms reconnect,保证有足够频率的重连 "&"+Constants.SHUTDOWN_TIMEOUT_KEY+ "=1";//shutdown时间足够短,确保error日志输出 try{ Exchangers.connect(url); }catch (Exception e) { //do nothing } Thread.sleep(1500);//重连线程的运行 Assert.assertEquals("only one error message ", 1 , LogUtil.findMessage(Level.ERROR, "client reconnect to ")); DubboAppender.doStop(); }
Example #6
Source File: ServersPageHandler.java From dubbox with Apache License 2.0 | 6 votes |
public Page handle(URL url) { List<List<String>> rows = new ArrayList<List<String>>(); Collection<ExchangeServer> servers = DubboProtocol.getDubboProtocol().getServers(); int clientCount = 0; if (servers != null && servers.size() > 0) { for (ExchangeServer s : servers) { List<String> row = new ArrayList<String>(); String address = s.getUrl().getAddress(); row.add(NetUtils.getHostName(address) + "/" + address); int clientSize = s.getExchangeChannels().size(); clientCount += clientSize; row.add("<a href=\"clients.html?port=" + s.getUrl().getPort() + "\">Clients(" + clientSize + ")</a>"); rows.add(row); } } return new Page("Servers", "Servers (" + rows.size() + ")", new String[]{"Server Address:", "Clients(" + clientCount + ")"}, rows); }
Example #7
Source File: ConfigTest.java From dubbo-2.6.5 with Apache License 2.0 | 6 votes |
@Test public void testMultiProtocolRegister() { SimpleRegistryService registryService = new SimpleRegistryService(); Exporter<RegistryService> exporter = SimpleRegistryExporter.export(4547, registryService); ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(ConfigTest.class.getPackage().getName().replace('.', '/') + "/multi-protocol-register.xml"); ctx.start(); try { List<URL> urls = registryService.getRegistered().get("com.alibaba.dubbo.config.spring.api.DemoService"); assertNotNull(urls); assertEquals(1, urls.size()); assertEquals("dubbo://" + NetUtils.getLocalHost() + ":20824/com.alibaba.dubbo.config.spring.api.DemoService", urls.get(0).toIdentityString()); } finally { ctx.stop(); ctx.close(); exporter.unexport(); } }
Example #8
Source File: RpcContext.java From dubbox with Apache License 2.0 | 6 votes |
/** * is consumer side. * * @return consumer side. */ public boolean isConsumerSide() { URL url = getUrl(); if (url == null) { return false; } InetSocketAddress address = getRemoteAddress(); if (address == null) { return false; } String host; if (address.getAddress() == null) { host = address.getHostName(); } else { host = address.getAddress().getHostAddress(); } return url.getPort() == address.getPort() && NetUtils.filterLocalHost(url.getIp()).equals(NetUtils.filterLocalHost(host)); }
Example #9
Source File: AbsentConfiguratorTest.java From dubbo-2.6.5 with Apache License 2.0 | 6 votes |
@Test public void testOverride_Host() { AbsentConfigurator configurator = new AbsentConfigurator(URL.valueOf("override://" + NetUtils.getLocalHost() + "/com.foo.BarService?timeout=200")); URL url = configurator.configure(URL.valueOf("dubbo://10.20.153.10:20880/com.foo.BarService?application=foo&side=consumer")); Assert.assertEquals("200", url.getParameter("timeout")); url = configurator.configure(URL.valueOf("dubbo://10.20.153.10:20880/com.foo.BarService?application=foo&timeout=1000&side=consumer")); Assert.assertEquals("1000", url.getParameter("timeout")); AbsentConfigurator configurator1 = new AbsentConfigurator(URL.valueOf("override://10.20.153.10/com.foo.BarService?timeout=200")); url = configurator1.configure(URL.valueOf("dubbo://10.20.153.10:20880/com.foo.BarService?application=bar&side=consumer")); Assert.assertNull(url.getParameter("timeout")); url = configurator1.configure(URL.valueOf("dubbo://10.20.153.10:20880/com.foo.BarService?application=bar&timeout=1000&side=consumer")); Assert.assertEquals("1000", url.getParameter("timeout")); }
Example #10
Source File: FileGroup.java From dubbox-hystrix with Apache License 2.0 | 6 votes |
public Peer join(URL url, ChannelHandler handler) throws RemotingException { Peer peer = super.join(url, handler); try { String full = url.toFullString(); String[] lines = IOUtils.readLines(file); for (String line : lines) { if (full.equals(line)) { return peer; } } IOUtils.appendLines(file, new String[] {full}); } catch (IOException e) { throw new RemotingException(new InetSocketAddress(NetUtils.getLocalHost(), 0), getUrl().toInetSocketAddress(), e.getMessage(), e); } return peer; }
Example #11
Source File: ConfigTest.java From dubbox with Apache License 2.0 | 6 votes |
@Test public void testDelayFixedTime() throws Exception { SimpleRegistryService registryService = new SimpleRegistryService(); Exporter<RegistryService> exporter = SimpleRegistryExporter.export(4548, registryService); ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(ConfigTest.class.getPackage().getName().replace('.', '/') + "/delay-fixed-time.xml"); ctx.start(); try { List<URL> urls = registryService.getRegistered().get("com.alibaba.dubbo.config.spring.api.DemoService"); assertNull(urls); int i = 0; while ((i ++) < 60 && urls == null) { urls = registryService.getRegistered().get("com.alibaba.dubbo.config.spring.api.DemoService"); Thread.sleep(10); } assertNotNull(urls); assertEquals(1, urls.size()); assertEquals("dubbo://" + NetUtils.getLocalHost() + ":20883/com.alibaba.dubbo.config.spring.api.DemoService", urls.get(0).toIdentityString()); } finally { ctx.stop(); ctx.close(); exporter.unexport(); } }
Example #12
Source File: DeprecatedTelnetCodec.java From dubbox-hystrix with Apache License 2.0 | 6 votes |
protected boolean isClientSide(Channel channel) { String side = (String) channel.getAttribute(Constants.SIDE_KEY); if ("client".equals(side)) { return true; } else if ("server".equals(side)) { return false; } else { InetSocketAddress address = channel.getRemoteAddress(); URL url = channel.getUrl(); boolean client = url.getPort() == address.getPort() && NetUtils.filterLocalHost(url.getIp()).equals( NetUtils.filterLocalHost(address.getAddress() .getHostAddress())); channel.setAttribute(Constants.SIDE_KEY, client ? "client" : "server"); return client; } }
Example #13
Source File: ClientReconnectTest.java From dubbox with Apache License 2.0 | 6 votes |
/** * 重连日志的校验,不能一直抛出error日志. */ @Test public void testReconnectErrorLog() throws RemotingException, InterruptedException{ int port = NetUtils.getAvailablePort(); DubboAppender.doStart(); String url = "exchange://127.0.0.3:"+port + "/client.reconnect.test?check=false&" +Constants.RECONNECT_KEY+"="+1 + //1ms reconnect,保证有足够频率的重连 "&"+Constants.SHUTDOWN_TIMEOUT_KEY+ "=1";//shutdown时间足够短,确保error日志输出 try{ Exchangers.connect(url); }catch (Exception e) { //do nothing } Thread.sleep(1500);//重连线程的运行 Assert.assertEquals("only one error message ", 1 , LogUtil.findMessage(Level.ERROR, "client reconnect to ")); DubboAppender.doStop(); }
Example #14
Source File: ClientReconnectTest.java From dubbo3 with Apache License 2.0 | 6 votes |
/** * 重连日志的校验 */ @Test public void testReconnectWaringLog() throws RemotingException, InterruptedException{ int port = NetUtils.getAvailablePort(); DubboAppender.doStart(); String url = "exchange://127.0.0.4:"+port + "/client.reconnect.test?check=false&" +Constants.RECONNECT_KEY+"="+1 //1ms reconnect,保证有足够频率的重连 +"&"+Constants.SHUTDOWN_TIMEOUT_KEY+ "=1"//shutdown时间足够短,确保error日志输出 +"&reconnect.waring.period=100";//每隔多少warning记录一次 try{ Exchangers.connect(url); }catch (Exception e) { //do nothing } int count = 0; for (int i=0;i<100;i++){ count = LogUtil.findMessage(Level.WARN, "client reconnect to ") ; if (count >=1){ break; } Thread.sleep(50);//重连线程的运行 } Assert.assertTrue("warning message count must >= 1, real :"+count, count>= 1); DubboAppender.doStop(); }
Example #15
Source File: Envs.java From dubbox-hystrix with Apache License 2.0 | 6 votes |
public void index(Map<String, Object> context) throws Exception { Map<String, String> properties = new TreeMap<String, String>(); StringBuilder msg = new StringBuilder(); msg.append("Version: "); msg.append(Version.getVersion(Envs.class, "2.2.0")); properties.put("Registry", msg.toString()); String address = NetUtils.getLocalHost(); properties.put("Host", NetUtils.getHostName(address) + "/" + address); properties.put("Java", System.getProperty("java.runtime.name") + " " + System.getProperty("java.runtime.version")); properties.put("OS", System.getProperty("os.name") + " " + System.getProperty("os.version")); properties.put("CPU", System.getProperty("os.arch", "") + ", " + String.valueOf(Runtime.getRuntime().availableProcessors()) + " cores"); properties.put("Locale", Locale.getDefault().toString() + "/" + System.getProperty("file.encoding")); properties.put("Uptime", formatUptime(ManagementFactory.getRuntimeMXBean().getUptime()) + " From " + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS Z").format(new Date(ManagementFactory.getRuntimeMXBean().getStartTime())) + " To " + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS Z").format(new Date())); context.put("properties", properties); }
Example #16
Source File: ClientReconnectTest.java From dubbox-hystrix with Apache License 2.0 | 6 votes |
/** * 重连日志的校验,时间不够shutdown time时,不能有error日志,但必须有一条warn日志 */ @Test public void testReconnectWarnLog() throws RemotingException, InterruptedException{ int port = NetUtils.getAvailablePort(); DubboAppender.doStart(); String url = "exchange://127.0.0.2:"+port + "/client.reconnect.test?check=false&" +Constants.RECONNECT_KEY+"="+1 ; //1ms reconnect,保证有足够频率的重连 try{ Exchangers.connect(url); }catch (Exception e) { //do nothing } Thread.sleep(1500);//重连线程的运行 //时间不够长,不会产生error日志 Assert.assertEquals("no error message ", 0 , LogUtil.findMessage(Level.ERROR, "client reconnect to ")); //第一次重连失败就会有warn日志 Assert.assertEquals("must have one warn message ", 1 , LogUtil.findMessage(Level.WARN, "client reconnect to ")); DubboAppender.doStop(); }
Example #17
Source File: ClientReconnectTest.java From dubbo-remoting-netty4 with Apache License 2.0 | 6 votes |
/** * 测试client重连方法不会导致重连线程失效. */ public void testClientReconnectMethod() throws RemotingException, InterruptedException{ int port = NetUtils.getAvailablePort(); String url = "exchange://127.0.0.3:"+port + "/client.reconnect.test?transporter=netty4&check=false&" +Constants.RECONNECT_KEY+"="+10 //1ms reconnect,保证有足够频率的重连 +"&reconnect.waring.period=100"; DubboAppender.doStart(); Client client = Exchangers.connect(url); try { client.reconnect(); } catch (Exception e) { //do nothing } Thread.sleep(1500);//重连线程的运行 Assert.assertTrue("have more then one warn msgs . bug was :" + LogUtil.findMessage(Level.WARN, "client reconnect to "),LogUtil.findMessage(Level.WARN, "client reconnect to ") >1); DubboAppender.doStop(); }
Example #18
Source File: ListTelnetHandlerTest.java From dubbox with Apache License 2.0 | 6 votes |
@SuppressWarnings("unchecked") @Test public void testListDetail() throws RemotingException { int port = NetUtils.getAvailablePort(); mockInvoker = EasyMock.createMock(Invoker.class); EasyMock.expect(mockInvoker.getInterface()).andReturn(DemoService.class).anyTimes(); EasyMock.expect(mockInvoker.getUrl()).andReturn(URL.valueOf("dubbo://127.0.0.1:"+port+"/demo")).anyTimes(); EasyMock.expect(mockInvoker.invoke((Invocation) EasyMock.anyObject())).andReturn(new RpcResult("ok")).anyTimes(); mockChannel = EasyMock.createMock(Channel.class); EasyMock.expect(mockChannel.getAttribute("telnet.service")).andReturn(null).anyTimes(); EasyMock.replay(mockChannel, mockInvoker); DubboProtocol.getDubboProtocol().export(mockInvoker); String result = list.telnet(mockChannel, "-l"); assertEquals("com.alibaba.dubbo.rpc.protocol.dubbo.support.DemoService -> dubbo://127.0.0.1:"+port+"/demo", result); EasyMock.reset(mockChannel); }
Example #19
Source File: ConfigTest.java From dubbox with Apache License 2.0 | 6 votes |
@Test public void testMultiProtocolRegister() { SimpleRegistryService registryService = new SimpleRegistryService(); Exporter<RegistryService> exporter = SimpleRegistryExporter.export(4547, registryService); ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(ConfigTest.class.getPackage().getName().replace('.', '/') + "/multi-protocol-register.xml"); ctx.start(); try { List<URL> urls = registryService.getRegistered().get("com.alibaba.dubbo.config.spring.api.DemoService"); assertNotNull(urls); assertEquals(1, urls.size()); assertEquals("dubbo://" + NetUtils.getLocalHost() + ":20824/com.alibaba.dubbo.config.spring.api.DemoService", urls.get(0).toIdentityString()); } finally { ctx.stop(); ctx.close(); exporter.unexport(); } }
Example #20
Source File: Envs.java From dubbox with Apache License 2.0 | 6 votes |
public void index(Map<String, Object> context) throws Exception { Map<String, String> properties = new TreeMap<String, String>(); StringBuilder msg = new StringBuilder(); msg.append("Version: "); msg.append(Version.getVersion(Envs.class, "2.2.0")); properties.put("Registry", msg.toString()); String address = NetUtils.getLocalHost(); properties.put("Host", NetUtils.getHostName(address) + "/" + address); properties.put("Java", System.getProperty("java.runtime.name") + " " + System.getProperty("java.runtime.version")); properties.put("OS", System.getProperty("os.name") + " " + System.getProperty("os.version")); properties.put("CPU", System.getProperty("os.arch", "") + ", " + String.valueOf(Runtime.getRuntime().availableProcessors()) + " cores"); properties.put("Locale", Locale.getDefault().toString() + "/" + System.getProperty("file.encoding")); properties.put("Uptime", formatUptime(ManagementFactory.getRuntimeMXBean().getUptime()) + " From " + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS Z").format(new Date(ManagementFactory.getRuntimeMXBean().getStartTime())) + " To " + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS Z").format(new Date())); context.put("properties", properties); }
Example #21
Source File: AbstractCodec.java From dubbox-hystrix with Apache License 2.0 | 6 votes |
protected boolean isClientSide(Channel channel) { String side = (String) channel.getAttribute(Constants.SIDE_KEY); if ("client".equals(side)) { return true; } else if ("server".equals(side)) { return false; } else { InetSocketAddress address = channel.getRemoteAddress(); URL url = channel.getUrl(); boolean client = url.getPort() == address.getPort() && NetUtils.filterLocalHost(url.getIp()).equals( NetUtils.filterLocalHost(address.getAddress() .getHostAddress())); channel.setAttribute(Constants.SIDE_KEY, client ? "client" : "server"); return client; } }
Example #22
Source File: ClientReconnectTest.java From dubbo-remoting-netty4 with Apache License 2.0 | 6 votes |
/** * 重连日志的校验 */ public void testReconnectWaringLog() throws RemotingException, InterruptedException{ int port = NetUtils.getAvailablePort(); DubboAppender.doStart(); String url = "exchange://127.0.0.4:"+port + "/client.reconnect.test?transporter=netty4&check=false&" +Constants.RECONNECT_KEY+"="+100 +"&"+Constants.SHUTDOWN_TIMEOUT_KEY+ "=1"//shutdown时间足够短,确保error日志输出 +"&reconnect.waring.period=500";//每隔多少warning记录一次 try{ Exchangers.connect(url); }catch (Exception e) { //do nothing } int count = 0; for (int i=0;i<10;i++){ count = LogUtil.findMessage(Level.WARN, "client reconnect to ") ; if (count >=1){ break; } Thread.sleep(50);//重连线程的运行 } Assert.assertTrue("warning message count must >= 1, real :"+count, count>= 1); DubboAppender.doStop(); }
Example #23
Source File: JettyContainer.java From dubbox with Apache License 2.0 | 5 votes |
public void start() { String serverPort = ConfigUtils.getProperty(JETTY_PORT); int port; if (serverPort == null || serverPort.length() == 0) { port = DEFAULT_JETTY_PORT; } else { port = Integer.parseInt(serverPort); } connector = new SelectChannelConnector(); connector.setPort(port); ServletHandler handler = new ServletHandler(); String resources = ConfigUtils.getProperty(JETTY_DIRECTORY); if (resources != null && resources.length() > 0) { FilterHolder resourceHolder = handler.addFilterWithMapping(ResourceFilter.class, "/*", Handler.DEFAULT); resourceHolder.setInitParameter("resources", resources); } ServletHolder pageHolder = handler.addServletWithMapping(PageServlet.class, "/*"); pageHolder.setInitParameter("pages", ConfigUtils.getProperty(JETTY_PAGES)); pageHolder.setInitOrder(2); Server server = new Server(); server.addConnector(connector); server.addHandler(handler); try { server.start(); } catch (Exception e) { throw new IllegalStateException("Failed to start jetty server on " + NetUtils.getLocalHost() + ":" + port + ", cause: " + e.getMessage(), e); } }
Example #24
Source File: Tool.java From dubbox-hystrix with Apache License 2.0 | 5 votes |
public static String getHostAddress(String address) { if (address != null && address.length() > 0) { int i = address.indexOf(':'); String port = address.substring(i+1); String hostname = NetUtils.getHostName(address); if (! address.equals(hostname)) { return hostname + ":" + port; } } return ""; }
Example #25
Source File: FailfastClusterInvoker.java From dubbox with Apache License 2.0 | 5 votes |
public Result doInvoke(Invocation invocation, List<Invoker<T>> invokers, LoadBalance loadbalance) throws RpcException { checkInvokers(invokers, invocation); Invoker<T> invoker = select(loadbalance, invocation, invokers, null); try { return invoker.invoke(invocation); } catch (Throwable e) { if (e instanceof RpcException && ((RpcException)e).isBiz()) { // biz exception. throw (RpcException) e; } throw new RpcException(e instanceof RpcException ? ((RpcException)e).getCode() : 0, "Failfast invoke providers " + invoker.getUrl() + " " + loadbalance.getClass().getSimpleName() + " select from all providers " + invokers + " for service " + getInterface().getName() + " method " + invocation.getMethodName() + " on consumer " + NetUtils.getLocalHost() + " use dubbo version " + Version.getVersion() + ", but no luck to perform the invocation. Last error is: " + e.getMessage(), e.getCause() != null ? e.getCause() : e); } }
Example #26
Source File: AbstractMonitorFactoryTest.java From dubbox with Apache License 2.0 | 5 votes |
@Test public void testMonitorFactoryCache() throws Exception { URL url = URL.valueOf("dubbo://" + NetUtils.getLocalAddress().getHostAddress() + ":2233"); Monitor monitor1 = monitorFactory.getMonitor(url); Monitor monitor2 = monitorFactory.getMonitor(url); Assert.assertEquals(monitor1, monitor2); }
Example #27
Source File: ConditionRouterTest.java From dubbox with Apache License 2.0 | 5 votes |
@Test public void testRoute_HostFilter(){ Router router = new ConditionRouterFactory().getRouter(getRouteUrl("host = " + NetUtils.getLocalHost() + " => " + " host = " + NetUtils.getLocalHost())); List<Invoker<String>> invokers = new ArrayList<Invoker<String>>(); Invoker<String> invoker1 = new MockInvoker<String>(URL.valueOf("dubbo://10.20.3.3:20880/com.foo.BarService")) ; Invoker<String> invoker2 = new MockInvoker<String>(URL.valueOf("dubbo://" + NetUtils.getLocalHost() + ":20880/com.foo.BarService")) ; Invoker<String> invoker3 = new MockInvoker<String>(URL.valueOf("dubbo://" + NetUtils.getLocalHost() + ":20880/com.foo.BarService")) ; invokers.add(invoker1); invokers.add(invoker2); invokers.add(invoker3); List<Invoker<String>> fileredInvokers = router.route(invokers, URL.valueOf("consumer://" + NetUtils.getLocalHost() + "/com.foo.BarService"), new RpcInvocation()); Assert.assertEquals(2, fileredInvokers.size()); Assert.assertEquals(invoker2, fileredInvokers.get(0)); Assert.assertEquals(invoker3, fileredInvokers.get(1)); }
Example #28
Source File: ExplicitCallbackTest.java From dubbox with Apache License 2.0 | 5 votes |
public void initOrResetUrl(int callbacks, int timeout) throws Exception { int port = NetUtils.getAvailablePort() ; consumerUrl = serviceURL = URL.valueOf("dubbo://127.0.0.1:"+port+"/"+IDemoService.class.getName()+"?group=test" +"&xxx.0.callback=true" +"&xxx2.0.callback=true" +"&unxxx2.0.callback=false" +"&timeout="+timeout +"&retries=0" +"&"+Constants.CALLBACK_INSTANCES_LIMIT_KEY+"="+callbacks ); // uncomment is unblock invoking // serviceURL = serviceURL.addParameter("yyy."+Constants.ASYNC_KEY,String.valueOf(true)); // consumerUrl = consumerUrl.addParameter("yyy."+Constants.ASYNC_KEY,String.valueOf(true)); }
Example #29
Source File: Tool.java From dubbox with Apache License 2.0 | 5 votes |
public static String getHostAddress(String address) { if (address != null && address.length() > 0) { int i = address.indexOf(':'); String port = address.substring(i+1); String hostname = NetUtils.getHostName(address); if (! address.equals(hostname)) { return hostname + ":" + port; } } return ""; }
Example #30
Source File: ConditionRouterTest.java From dubbox with Apache License 2.0 | 5 votes |
@Test public void testRoute_ReturnAll(){ Router router = new ConditionRouterFactory().getRouter(getRouteUrl("host = " + NetUtils.getLocalHost() + " => " + " host = " + NetUtils.getLocalHost())); List<Invoker<String>> invokers = new ArrayList<Invoker<String>>(); invokers.add(new MockInvoker<String>()); invokers.add(new MockInvoker<String>()); invokers.add(new MockInvoker<String>()); List<Invoker<String>> fileredInvokers = router.route(invokers, URL.valueOf("consumer://" + NetUtils.getLocalHost() + "/com.foo.BarService"), new RpcInvocation()); Assert.assertEquals(invokers, fileredInvokers); }