com.alibaba.dubbo.remoting.exchange.Exchangers Java Examples
The following examples show how to use
com.alibaba.dubbo.remoting.exchange.Exchangers.
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: DubboProtocol.java From dubbox-hystrix with Apache License 2.0 | 6 votes |
private ExchangeServer createServer(URL url) { //默认开启server关闭时发送readonly事件 url = url.addParameterIfAbsent(Constants.CHANNEL_READONLYEVENT_SENT_KEY, Boolean.TRUE.toString()); //默认开启heartbeat url = url.addParameterIfAbsent(Constants.HEARTBEAT_KEY, String.valueOf(Constants.DEFAULT_HEARTBEAT)); String str = url.getParameter(Constants.SERVER_KEY, Constants.DEFAULT_REMOTING_SERVER); if (str != null && str.length() > 0 && ! ExtensionLoader.getExtensionLoader(Transporter.class).hasExtension(str)) throw new RpcException("Unsupported server type: " + str + ", url: " + url); url = url.addParameter(Constants.CODEC_KEY, Version.isCompatibleVersion() ? COMPATIBLE_CODEC_NAME : DubboCodec.NAME); ExchangeServer server; try { server = Exchangers.bind(url, requestHandler); } catch (RemotingException e) { throw new RpcException("Fail to start server(url: " + url + ") " + e.getMessage(), e); } str = url.getParameter(Constants.CLIENT_KEY); if (str != null && str.length() > 0) { Set<String> supportedTypes = ExtensionLoader.getExtensionLoader(Transporter.class).getSupportedExtensions(); if (!supportedTypes.contains(str)) { throw new RpcException("Unsupported client type: " + str); } } return server; }
Example #2
Source File: ThriftProtocol.java From dubbo-2.6.5 with Apache License 2.0 | 6 votes |
private ExchangeServer getServer(URL url) { // enable sending readonly event when server closes by default url = url.addParameterIfAbsent(Constants.CHANNEL_READONLYEVENT_SENT_KEY, Boolean.TRUE.toString()); String str = url.getParameter(Constants.SERVER_KEY, Constants.DEFAULT_REMOTING_SERVER); if (str != null && str.length() > 0 && !ExtensionLoader.getExtensionLoader(Transporter.class).hasExtension(str)) throw new RpcException("Unsupported server type: " + str + ", url: " + url); ExchangeServer server; try { server = Exchangers.bind(url, handler); } catch (RemotingException e) { throw new RpcException("Fail to start server(url: " + url + ") " + e.getMessage(), e); } str = url.getParameter(Constants.CLIENT_KEY); if (str != null && str.length() > 0) { Set<String> supportedTypes = ExtensionLoader.getExtensionLoader(Transporter.class).getSupportedExtensions(); if (!supportedTypes.contains(str)) { throw new RpcException("Unsupported client type: " + str); } } return server; }
Example #3
Source File: DubboProtocol.java From dubbox with Apache License 2.0 | 6 votes |
private ExchangeServer createServer(URL url) { //默认开启server关闭时发送readonly事件 url = url.addParameterIfAbsent(Constants.CHANNEL_READONLYEVENT_SENT_KEY, Boolean.TRUE.toString()); //默认开启heartbeat url = url.addParameterIfAbsent(Constants.HEARTBEAT_KEY, String.valueOf(Constants.DEFAULT_HEARTBEAT)); String str = url.getParameter(Constants.SERVER_KEY, Constants.DEFAULT_REMOTING_SERVER); if (str != null && str.length() > 0 && ! ExtensionLoader.getExtensionLoader(Transporter.class).hasExtension(str)) throw new RpcException("Unsupported server type: " + str + ", url: " + url); url = url.addParameter(Constants.CODEC_KEY, Version.isCompatibleVersion() ? COMPATIBLE_CODEC_NAME : DubboCodec.NAME); ExchangeServer server; try { server = Exchangers.bind(url, requestHandler); } catch (RemotingException e) { throw new RpcException("Fail to start server(url: " + url + ") " + e.getMessage(), e); } str = url.getParameter(Constants.CLIENT_KEY); if (str != null && str.length() > 0) { Set<String> supportedTypes = ExtensionLoader.getExtensionLoader(Transporter.class).getSupportedExtensions(); if (!supportedTypes.contains(str)) { throw new RpcException("Unsupported client type: " + str); } } return server; }
Example #4
Source File: ClientReconnectTest.java From dubbox-hystrix 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 #5
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 #6
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 #7
Source File: ThriftProtocol.java From dubbox with Apache License 2.0 | 6 votes |
private ExchangeServer getServer(URL url) { //默认开启server关闭时发送readonly事件 url = url.addParameterIfAbsent(Constants.CHANNEL_READONLYEVENT_SENT_KEY, Boolean.TRUE.toString()); String str = url.getParameter(Constants.SERVER_KEY, Constants.DEFAULT_REMOTING_SERVER); if (str != null && str.length() > 0 && ! ExtensionLoader.getExtensionLoader(Transporter.class).hasExtension(str)) throw new RpcException("Unsupported server type: " + str + ", url: " + url); ExchangeServer server; try { server = Exchangers.bind(url, handler); } catch (RemotingException e) { throw new RpcException("Fail to start server(url: " + url + ") " + e.getMessage(), e); } str = url.getParameter(Constants.CLIENT_KEY); if (str != null && str.length() > 0) { Set<String> supportedTypes = ExtensionLoader.getExtensionLoader(Transporter.class).getSupportedExtensions(); if (!supportedTypes.contains(str)) { throw new RpcException("Unsupported client type: " + str); } } return server; }
Example #8
Source File: ClientReconnectTest.java From dubbox with Apache License 2.0 | 6 votes |
/** * 测试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(); }
Example #9
Source File: ThriftProtocol.java From dubbox with Apache License 2.0 | 6 votes |
private ExchangeServer getServer(URL url) { //默认开启server关闭时发送readonly事件 url = url.addParameterIfAbsent(Constants.CHANNEL_READONLYEVENT_SENT_KEY, Boolean.TRUE.toString()); String str = url.getParameter(Constants.SERVER_KEY, Constants.DEFAULT_REMOTING_SERVER); if (str != null && str.length() > 0 && ! ExtensionLoader.getExtensionLoader(Transporter.class).hasExtension(str)) throw new RpcException("Unsupported server type: " + str + ", url: " + url); ExchangeServer server; try { server = Exchangers.bind(url, handler); } catch (RemotingException e) { throw new RpcException("Fail to start server(url: " + url + ") " + e.getMessage(), e); } str = url.getParameter(Constants.CLIENT_KEY); if (str != null && str.length() > 0) { Set<String> supportedTypes = ExtensionLoader.getExtensionLoader(Transporter.class).getSupportedExtensions(); if (!supportedTypes.contains(str)) { throw new RpcException("Unsupported client type: " + str); } } return server; }
Example #10
Source File: ClientReconnectTest.java From dubbox 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 #11
Source File: ClientReconnectTest.java From dubbox-hystrix with Apache License 2.0 | 6 votes |
/** * 测试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(); }
Example #12
Source File: ClientReconnectTest.java From dubbo-2.6.5 with Apache License 2.0 | 6 votes |
/** * Reconnect log check, when the time is not enough for shutdown time, there is no error log, but there must be a warn log */ @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, ensure that there is enough frequency to reconnect try { Exchangers.connect(url); } catch (Exception e) { //do nothing } Thread.sleep(1500); //Time is not long enough to produce a error log Assert.assertEquals("no error message ", 0, LogUtil.findMessage(Level.ERROR, "client reconnect to ")); //The first reconnection failed to have a warn log Assert.assertEquals("must have one warn message ", 1, LogUtil.findMessage(Level.WARN, "client reconnect to ")); DubboAppender.doStop(); }
Example #13
Source File: ClientReconnectTest.java From dubbox 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 #14
Source File: Main.java From dubbox-hystrix with Apache License 2.0 | 6 votes |
private static void test(int port) throws Exception { ExchangeChannel client = Exchangers.connect(URL.valueOf("dubbo://localhost:" + port)); MockResult result = (MockResult)client.request(new RpcMessage(DemoService.class.getName(),"plus",new Class<?>[]{int.class, int.class},new Object[]{55,25})).get(); System.out.println("55+25="+result.getResult()); for(int i=0;i<100;i++) client.request(new RpcMessage(DemoService.class.getName(),"sayHello", new Class<?>[]{String.class},new Object[]{"qianlei"+i})); for(int i=0;i<100;i++) client.request(new Main.Data()); System.out.println("=====test invoke====="); for(int i=0;i<100;i++){ ResponseFuture future = client.request(new Main.Data()); System.out.println("invoke and get"); System.out.println("invoke result:" + future.get()); } System.out.println("=====the end====="); }
Example #15
Source File: Main.java From dubbo-2.6.5 with Apache License 2.0 | 6 votes |
private static void test(int port) throws Exception { ExchangeChannel client = Exchangers.connect(URL.valueOf("dubbo://localhost:" + port)); MockResult result = (MockResult) client.request(new RpcMessage(DemoService.class.getName(), "plus", new Class<?>[]{int.class, int.class}, new Object[]{55, 25})).get(); System.out.println("55+25=" + result.getResult()); for (int i = 0; i < 100; i++) client.request(new RpcMessage(DemoService.class.getName(), "sayHello", new Class<?>[]{String.class}, new Object[]{"qianlei" + i})); for (int i = 0; i < 100; i++) client.request(new Main.Data()); System.out.println("=====test invoke====="); for (int i = 0; i < 100; i++) { ResponseFuture future = client.request(new Main.Data()); System.out.println("invoke and get"); System.out.println("invoke result:" + future.get()); } System.out.println("=====the end====="); }
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: Main.java From dubbox with Apache License 2.0 | 6 votes |
private static void test(int port) throws Exception { ExchangeChannel client = Exchangers.connect(URL.valueOf("dubbo://localhost:" + port)); MockResult result = (MockResult)client.request(new RpcMessage(DemoService.class.getName(),"plus",new Class<?>[]{int.class, int.class},new Object[]{55,25})).get(); System.out.println("55+25="+result.getResult()); for(int i=0;i<100;i++) client.request(new RpcMessage(DemoService.class.getName(),"sayHello", new Class<?>[]{String.class},new Object[]{"qianlei"+i})); for(int i=0;i<100;i++) client.request(new Main.Data()); System.out.println("=====test invoke====="); for(int i=0;i<100;i++){ ResponseFuture future = client.request(new Main.Data()); System.out.println("invoke and get"); System.out.println("invoke result:" + future.get()); } System.out.println("=====the end====="); }
Example #18
Source File: AbstractExchangeGroup.java From dubbox with Apache License 2.0 | 5 votes |
public ExchangePeer join(URL url, ExchangeHandler handler) throws RemotingException { ExchangeServer server = servers.get(url); if (server == null) { // TODO 有并发间隙 server = Exchangers.bind(url, handler); servers.put(url, server); dispatcher.addChannelHandler(handler); } return new ExchangeServerPeer(server, clients, this); }
Example #19
Source File: NettyStringTest.java From dubbox with Apache License 2.0 | 5 votes |
@BeforeClass public static void setUp() throws Exception { //int port = (int) (1000 * Math.random() + 10000); int port = 10001; System.out.println(port); server = Exchangers.bind(URL.valueOf("telnet://0.0.0.0:" + port + "?server=netty4"), new TelnetServerHandler()); client = Exchangers.connect(URL.valueOf("telnet://127.0.0.1:" + port + "?client=netty4"), new TelnetClientHandler()); }
Example #20
Source File: AbstractExchangeGroup.java From dubbox with Apache License 2.0 | 5 votes |
protected Client connect(URL url) throws RemotingException { if (servers.containsKey(url)) { return null; } ExchangeClient client = clients.get(url); if (client == null) { // TODO 有并发间隙 client = Exchangers.connect(url, dispatcher); clients.put(url, client); } return client; }
Example #21
Source File: NettyClientTest.java From dubbox with Apache License 2.0 | 5 votes |
@Test public void testServerClose() throws Exception { for (int i = 0; i < 100; i++) { Server aServer = Exchangers.bind(URL.valueOf("exchange://localhost:" + (5000 + i) + "?client=netty"), new TelnetServerHandler()); aServer.close(); } }
Example #22
Source File: NettyClientTest.java From dubbox-hystrix with Apache License 2.0 | 5 votes |
@Test public void testServerClose() throws Exception { for (int i = 0; i < 100; i++) { Server aServer = Exchangers.bind(URL.valueOf("exchange://localhost:" + (5000 + i) + "?client=netty"), new TelnetServerHandler()); aServer.close(); } }
Example #23
Source File: HeartbeatHandlerTest.java From dubbox with Apache License 2.0 | 5 votes |
@Test public void testServerHeartbeat() throws Exception { URL serverURL = URL.valueOf("header://localhost:55555"); serverURL = serverURL.addParameter(Constants.HEARTBEAT_KEY, 1000); TestHeartbeatHandler handler = new TestHeartbeatHandler(); server = Exchangers.bind(serverURL, handler); System.out.println("Server bind successfully"); FakeChannelHandlers.setTestingChannelHandlers(); serverURL = serverURL.removeParameter(Constants.HEARTBEAT_KEY); client = Exchangers.connect(serverURL); Thread.sleep(10000); Assert.assertTrue(handler.disconnectCount > 0); System.out.println("disconnect count " + handler.disconnectCount); }
Example #24
Source File: HeartbeatHandlerTest.java From dubbox with Apache License 2.0 | 5 votes |
@Test public void testClientHeartbeat() throws Exception { FakeChannelHandlers.setTestingChannelHandlers(); URL serverURL = URL.valueOf("header://localhost:55555"); TestHeartbeatHandler handler = new TestHeartbeatHandler(); server = Exchangers.bind(serverURL, handler); System.out.println("Server bind successfully"); FakeChannelHandlers.resetChannelHandlers(); serverURL = serverURL.addParameter(Constants.HEARTBEAT_KEY, 1000); client = Exchangers.connect(serverURL); Thread.sleep(10000); Assert.assertTrue(handler.connectCount > 0); System.out.println("connect count " + handler.connectCount); }
Example #25
Source File: ExchangeClientFactory.java From dubbox-hystrix with Apache License 2.0 | 5 votes |
protected ExchangeClient createClient(String targetIP, int targetPort, int connectTimeout) throws Exception { StringBuilder url = new StringBuilder(); url.append("exchange://"); url.append(targetIP); url.append(":"); url.append(targetPort); url.append("?"); url.append("timeout="); url.append(connectTimeout); return Exchangers.connect(url.toString()); }
Example #26
Source File: AbstractExchangeGroup.java From dubbox-hystrix with Apache License 2.0 | 5 votes |
public ExchangePeer join(URL url, ExchangeHandler handler) throws RemotingException { ExchangeServer server = servers.get(url); if (server == null) { // TODO 有并发间隙 server = Exchangers.bind(url, handler); servers.put(url, server); dispatcher.addChannelHandler(handler); } return new ExchangeServerPeer(server, clients, this); }
Example #27
Source File: NettyClientTest.java From dubbox with Apache License 2.0 | 5 votes |
@Test public void testServerClose() throws Exception { for (int i = 0; i < 100; i++) { Server aServer = Exchangers.bind(URL.valueOf("exchange://localhost:" + (5000 + i) + "?transporter=netty4"), new TelnetServerHandler()); aServer.close(); } }
Example #28
Source File: ChanelHandlerTest.java From dubbox-hystrix with Apache License 2.0 | 5 votes |
public static ExchangeClient initClient(String url){ // 创建客户端 ExchangeClient exchangeClient = null; PeformanceTestHandler handler = new PeformanceTestHandler(url); boolean run = true; while(run){ try{ exchangeClient= Exchangers.connect(url,handler); } catch (Throwable t){ if(t!=null && t.getCause()!=null && t.getCause().getClass()!=null && (t.getCause().getClass()==java.net.ConnectException.class || t.getCause().getClass()== java.net.ConnectException.class)){ }else { t.printStackTrace(); } try { Thread.sleep(50); } catch (InterruptedException e) { e.printStackTrace(); } } if (exchangeClient != null) { run = false; } } return exchangeClient; }
Example #29
Source File: HeartbeatHandlerTest.java From dubbox with Apache License 2.0 | 5 votes |
@Test public void testClientHeartbeat() throws Exception { FakeChannelHandlers.setTestingChannelHandlers(); URL serverURL = URL.valueOf("header://localhost:55555?transporter=netty4"); TestHeartbeatHandler handler = new TestHeartbeatHandler(); server = Exchangers.bind(serverURL, handler); System.out.println("Server bind successfully"); FakeChannelHandlers.resetChannelHandlers(); serverURL = serverURL.addParameter(Constants.HEARTBEAT_KEY, 1000); client = Exchangers.connect(serverURL); Thread.sleep(10000); Assert.assertTrue(handler.connectCount > 0); System.out.println("connect count " + handler.connectCount); }
Example #30
Source File: HeartbeatHandlerTest.java From dubbox with Apache License 2.0 | 5 votes |
@Test public void testHeartbeat() throws Exception { URL serverURL = URL.valueOf("header://localhost:55555?transporter=netty4"); serverURL = serverURL.addParameter(Constants.HEARTBEAT_KEY, 1000); TestHeartbeatHandler handler = new TestHeartbeatHandler(); server = Exchangers.bind(serverURL, handler); System.out.println("Server bind successfully"); client = Exchangers.connect(serverURL); Thread.sleep(10000); System.err.println("++++++++++++++ disconnect count " + handler.disconnectCount); System.err.println("++++++++++++++ connect count " + handler.connectCount); Assert.assertTrue(handler.disconnectCount == 0); Assert.assertTrue(handler.connectCount == 1); }