当前位置: 首页>>代码示例>>Java>>正文


Java NetUtils.getAvailablePort方法代码示例

本文整理汇总了Java中com.alibaba.dubbo.common.utils.NetUtils.getAvailablePort方法的典型用法代码示例。如果您正苦于以下问题:Java NetUtils.getAvailablePort方法的具体用法?Java NetUtils.getAvailablePort怎么用?Java NetUtils.getAvailablePort使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.alibaba.dubbo.common.utils.NetUtils的用法示例。


在下文中一共展示了NetUtils.getAvailablePort方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testNormal

import com.alibaba.dubbo.common.utils.NetUtils; //导入方法依赖的package包/类
@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();
    }
 
开发者ID:zhuxiaolei,项目名称:dubbo2,代码行数:21,代码来源:EnumBak.java

示例2: testReconnectErrorLog

import com.alibaba.dubbo.common.utils.NetUtils; //导入方法依赖的package包/类
/**
 * 重连日志的校验,不能一直抛出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();
}
 
开发者ID:dachengxi,项目名称:EatDubbo,代码行数:20,代码来源:ClientReconnectTest.java

示例3: testClientReconnectMethod

import com.alibaba.dubbo.common.utils.NetUtils; //导入方法依赖的package包/类
/**
   * 测试client重连方法不会导致重连线程失效.
   */
  @Test
  public void testClientReconnectMethod() throws RemotingException, InterruptedException{
      int port = NetUtils.getAvailablePort();
      String url = "exchange://127.0.0.3:"+port + "/client.reconnect.test?check=false&"
      +Constants.RECONNECT_KEY+"="+10 //1ms reconnect,保证有足够频率的重连
      +"&reconnect.waring.period=1";
      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();
  }
 
开发者ID:dachengxi,项目名称:EatDubbo,代码行数:21,代码来源:ClientReconnectTest.java

示例4: testReconnectWaringLog

import com.alibaba.dubbo.common.utils.NetUtils; //导入方法依赖的package包/类
/**
 * 重连日志的校验
 */
@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();
}
 
开发者ID:dachengxi,项目名称:EatDubbo,代码行数:28,代码来源:ClientReconnectTest.java

示例5: testExportService

import com.alibaba.dubbo.common.utils.NetUtils; //导入方法依赖的package包/类
@Ignore
    @Test
    public void testExportService() throws InterruptedException{
        int port = NetUtils.getAvailablePort();
        URL serviceurl = URL.valueOf("dubbo://127.0.0.1:"+port+"/test?proxy=jdk&timeout="+Integer.MAX_VALUE
                );
        DemoService demo = new DemoServiceImpl();
        Invoker<DemoService> invoker = proxy.getInvoker(demo, DemoService.class, serviceurl);
        protocol.export(invoker);
        synchronized (EnumBak.class) {
            EnumBak.class.wait();
        }
        
//        URL consumerurl = serviceurl;
//        Invoker<DemoService> reference = protocol.refer(DemoService.class, consumerurl);
//        DemoService demoProxy = (DemoService)proxyFactory.createProxy(reference);
////        System.out.println(demoProxy.getThreadName());
//        System.out.println("byte:"+demoProxy.getbyte((byte)-128));
//        
//        invoker.destroy();
//        reference.destroy();
    }
 
开发者ID:yunhaibin,项目名称:dubbox-hystrix,代码行数:23,代码来源:EnumBak.java

示例6: testListDetail

import com.alibaba.dubbo.common.utils.NetUtils; //导入方法依赖的package包/类
@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);
}
 
开发者ID:zhuxiaolei,项目名称:dubbo2,代码行数:17,代码来源:ListTelnetHandlerTest.java

示例7: testNormalEnum

import com.alibaba.dubbo.common.utils.NetUtils; //导入方法依赖的package包/类
@Test
public void testNormalEnum(){
    int port = NetUtils.getAvailablePort();
    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);
    
    URL consumerurl = serviceurl;
    Invoker<DemoService> reference = protocol.refer(DemoService.class, consumerurl);
    DemoService demoProxy = (DemoService)proxy.getProxy(reference);
    Type type = demoProxy.enumlength(Type.High);
    System.out.println(type);
    Assert.assertEquals(Type.High, type);
    
    invoker.destroy();
    reference.destroy();
}
 
开发者ID:yunhaibin,项目名称:dubbox-hystrix,代码行数:20,代码来源:EnumBak.java

示例8: testReconnectWarnLog

import com.alibaba.dubbo.common.utils.NetUtils; //导入方法依赖的package包/类
/**
 * 重连日志的校验,时间不够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();
}
 
开发者ID:flychao88,项目名称:dubbocloud,代码行数:22,代码来源:ClientReconnectTest.java

示例9: initOrResetUrl

import com.alibaba.dubbo.common.utils.NetUtils; //导入方法依赖的package包/类
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));
    }
 
开发者ID:flychao88,项目名称:dubbocloud,代码行数:15,代码来源:ExplicitCallbackTest.java

示例10: testSticky4

import com.alibaba.dubbo.common.utils.NetUtils; //导入方法依赖的package包/类
@Test
public void testSticky4() {
    int port = NetUtils.getAvailablePort();
    URL url = URL.valueOf("dubbo://127.0.0.1:"+port+"/hi?"+Constants.LAZY_CONNECT_KEY+"=true");
    
    ProtocolUtils.export(new DemoServiceImpl(), IDemoService.class, url);
    
    IDemoService service = (IDemoService)ProtocolUtils.refer(IDemoService.class, url);
    Assert.assertEquals("ok", service.get());
}
 
开发者ID:dachengxi,项目名称:EatDubbo,代码行数:11,代码来源:DubboLazyConnectTest.java

示例11: testGenericExport

import com.alibaba.dubbo.common.utils.NetUtils; //导入方法依赖的package包/类
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);
}
 
开发者ID:dachengxi,项目名称:EatDubbo,代码行数:14,代码来源:EnumBak.java

示例12: initOrResetUrl

import com.alibaba.dubbo.common.utils.NetUtils; //导入方法依赖的package包/类
public void initOrResetUrl(boolean isAsync) throws Exception {
    int port = NetUtils.getAvailablePort() ;
    consumerUrl = serviceURL =  URL.valueOf("dubbo://127.0.0.1:"+port+"/"+IDemoService.class.getName()+"?group=test&async="+isAsync+"&timeout=100000&reference.filter=future" );
    StaticContext.getSystemContext().clear();
}
 
开发者ID:dachengxi,项目名称:EatDubbo,代码行数:6,代码来源:ImplicitCallBackTest.java


注:本文中的com.alibaba.dubbo.common.utils.NetUtils.getAvailablePort方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。