本文整理汇总了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();
}
示例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();
}
示例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();
}
示例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();
}
示例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();
}
示例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);
}
示例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();
}
示例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();
}
示例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));
}
示例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());
}
示例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);
}
示例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();
}