Java Code Examples for com.alibaba.dubbo.common.utils.NetUtils

The following examples show how to use com.alibaba.dubbo.common.utils.NetUtils. These examples are extracted from open source projects. 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 Project: dubbox   Source File: EnumBak.java    License: Apache License 2.0 6 votes vote down vote up
@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 2
Source Project: dubbo-2.6.5   Source File: AbsentConfiguratorTest.java    License: Apache License 2.0 6 votes vote down vote up
@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 3
Source Project: dubbox   Source File: RpcContext.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 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 4
Source Project: dubbox-hystrix   Source File: FileGroup.java    License: Apache License 2.0 6 votes vote down vote up
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 5
Source Project: dubbox   Source File: ReferenceCountExchangeClientTest.java    License: Apache License 2.0 6 votes vote down vote up
@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 6
Source Project: dubbo-remoting-netty4   Source File: ClientReconnectTest.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 重连日志的校验
 */
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 7
Source Project: dubbox-hystrix   Source File: DeprecatedTelnetCodec.java    License: Apache License 2.0 6 votes vote down vote up
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 8
Source Project: dubbox-hystrix   Source File: AbstractCodec.java    License: Apache License 2.0 6 votes vote down vote up
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 9
Source Project: dubbox   Source File: ListTelnetHandlerTest.java    License: Apache License 2.0 6 votes vote down vote up
@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 10
Source Project: dubbox-hystrix   Source File: ClientReconnectTest.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 重连日志的校验,时间不够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 11
Source Project: dubbox-hystrix   Source File: Envs.java    License: Apache License 2.0 6 votes vote down vote up
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 12
Source Project: dubbox-hystrix   Source File: FileExchangeGroup.java    License: Apache License 2.0 6 votes vote down vote up
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 13
Source Project: dubbo3   Source File: ClientReconnectTest.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 重连日志的校验
 */
@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 14
Source Project: dubbo-remoting-netty4   Source File: ClientReconnectTest.java    License: Apache License 2.0 6 votes vote down vote up
/**
   * 测试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 15
Source Project: dubbox   Source File: ConfigTest.java    License: Apache License 2.0 6 votes vote down vote up
@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 16
Source Project: dubbox   Source File: Envs.java    License: Apache License 2.0 6 votes vote down vote up
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 17
Source Project: dubbox   Source File: ConfigTest.java    License: Apache License 2.0 6 votes vote down vote up
@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 18
Source Project: dubbox   Source File: ClientReconnectTest.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 重连日志的校验,时间不够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 19
Source Project: dubbox   Source File: ClientReconnectTest.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 重连日志的校验,不能一直抛出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 20
Source Project: dubbo-2.6.5   Source File: ConfigTest.java    License: Apache License 2.0 6 votes vote down vote up
@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 21
Source Project: dubbox   Source File: ServersPageHandler.java    License: Apache License 2.0 6 votes vote down vote up
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 22
Source Project: dubbox   Source File: ClientReconnectTest.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 重连日志的校验,不能一直抛出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 23
Source Project: dubbox   Source File: ExplicitCallbackTest.java    License: Apache License 2.0 5 votes vote down vote up
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 24
Source Project: dubbo-2.6.5   Source File: AbstractClusterInvoker.java    License: Apache License 2.0 5 votes vote down vote up
protected void checkWhetherDestroyed() {

        if (destroyed.get()) {
            throw new RpcException("Rpc cluster invoker for " + getInterface() + " on consumer " + NetUtils.getLocalHost()
                    + " use dubbo version " + Version.getVersion()
                    + " is now destroyed! Can not invoke any more.");
        }
    }
 
Example 25
Source Project: dubbox   Source File: ConditionRouterTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testRoute_Placeholder(){
    Router router = new ConditionRouterFactory().getRouter(getRouteUrl("host = " + NetUtils.getLocalHost() + " => " + " host = $host"));
    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 26
Source Project: dubbo-plus   Source File: Netty4Server.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public Collection<Channel> getChannels() {
    Collection<Channel> chs = new HashSet<Channel>();
    for (Channel channel : this.channels.values()) {
        if (channel.isConnected()) {
            chs.add(channel);
        } else {
            channels.remove(NetUtils.toAddressString(channel.getRemoteAddress()));
        }
    }
    return chs;
}
 
Example 27
Source Project: dubbox   Source File: NettyServer.java    License: Apache License 2.0 5 votes vote down vote up
public Collection<Channel> getChannels() {
    Collection<Channel> chs = new HashSet<Channel>();
    for (Channel channel : this.channels.values()) {
        if (channel.isConnected()) {
            chs.add(channel);
        } else {
            channels.remove(NetUtils.toAddressString(channel.getRemoteAddress()));
        }
    }
    return chs;
}
 
Example 28
Source Project: dubbox   Source File: EnumBak.java    License: Apache License 2.0 5 votes vote down vote up
public void testGenericExport() throws InterruptedException{
    int port = NetUtils.getAvailablePort();
    port = 20880;
    URL serviceurl = URL.valueOf("dubbo://127.0.0.1:"+port+"/test?timeout="+Integer.MAX_VALUE
            );
    DemoService demo = new DemoServiceImpl();
    Invoker<DemoService> invoker = proxy.getInvoker(demo, DemoService.class, serviceurl);
    protocol.export(invoker);
    
    
    //SERVER
    Thread.sleep(Integer.MAX_VALUE);
}
 
Example 29
Source Project: dubbo-2.6.5   Source File: ConditionRouterTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testRoute_Empty_HostFilter() {
    Router router = new ConditionRouterFactory().getRouter(getRouteUrl(" => " + " 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 30
Source Project: dubbox-hystrix   Source File: ConsumerContextFilterTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testSetContext(){
    URL url = URL.valueOf("test://test:11/test?group=dubbo&version=1.1");
    Invoker<DemoService> invoker = new MyInvoker<DemoService>(url);
    Invocation invocation = new MockInvocation();
    consumerContextFilter.invoke(invoker, invocation);
    assertEquals(invoker,RpcContext.getContext().getInvoker());
    assertEquals(invocation,RpcContext.getContext().getInvocation());
    assertEquals(NetUtils.getLocalHost() + ":0",RpcContext.getContext().getLocalAddressString());
    assertEquals("test:11",RpcContext.getContext().getRemoteAddressString());
    
}