Java Code Examples for com.alibaba.dubbo.remoting.exchange.Exchangers#connect()
The following examples show how to use
com.alibaba.dubbo.remoting.exchange.Exchangers#connect() .
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: ClientReconnectTest.java From dubbox 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 2
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 3
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 4
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 5
Source File: NettyStringTest.java From dubbox-hystrix 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=netty"), new TelnetServerHandler()); client = Exchangers.connect(URL.valueOf("telnet://127.0.0.1:" + port + "?client=netty"), new TelnetClientHandler()); }
Example 6
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?transporter=netty4"); 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 7
Source File: PortTelnetHandlerTest.java From dubbox-hystrix with Apache License 2.0 | 5 votes |
@Test public void testListClient() throws Exception { ExchangeClient client1 = Exchangers.connect("dubbo://127.0.0.1:20887/demo"); ExchangeClient client2 = Exchangers.connect("dubbo://127.0.0.1:20887/demo"); Thread.sleep(5000); String result = port.telnet(null, "-l 20887"); String client1Addr = client1.getLocalAddress().toString(); String client2Addr = client2.getLocalAddress().toString(); System.out.printf("Result: %s %n", result); System.out.printf("Client 1 Address %s %n", client1Addr); System.out.printf("Client 2 Address %s %n", client2Addr); assertTrue(result.contains(client1Addr)); assertTrue(result.contains(client2Addr)); }
Example 8
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); }
Example 9
Source File: LazyConnectExchangeClient.java From dubbox with Apache License 2.0 | 5 votes |
private void initClient() throws RemotingException { if (client != null ) return; if (logger.isInfoEnabled()) { logger.info("Lazy connect to " + url); } connectLock.lock(); try { if (client != null) return; this.client = Exchangers.connect(url, requestHandler); } finally { connectLock.unlock(); } }
Example 10
Source File: ChanelHandlerTest.java From dubbo-2.6.5 with Apache License 2.0 | 5 votes |
public static ExchangeClient initClient(String url) { // Create client and build connection 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 11
Source File: AbstractExchangeGroup.java From dubbox-hystrix 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 12
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"); 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); }
Example 13
Source File: HeartbeatHandlerTest.java From dubbo-2.6.5 with Apache License 2.0 | 5 votes |
@Test public void testHeartbeat() 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"); 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); }
Example 14
Source File: NettyClientToServerTest.java From dubbox with Apache License 2.0 | 4 votes |
protected ExchangeChannel newClient(int port) throws RemotingException { return Exchangers.connect(URL.valueOf("exchange://localhost:" + port + "?client=netty4")); }
Example 15
Source File: NettyClientTest.java From dubbo-2.6.5 with Apache License 2.0 | 4 votes |
public static void main(String[] args) throws RemotingException, InterruptedException { ExchangeChannel client = Exchangers.connect(URL.valueOf("exchange://10.20.153.10:20880?client=netty&heartbeat=1000")); Thread.sleep(60 * 1000 * 50); }
Example 16
Source File: ClientReconnectTest.java From dubbox with Apache License 2.0 | 4 votes |
public Client startClient(int port , int reconnectPeriod) throws RemotingException{ final String url = "exchange://127.0.0.1:"+port + "/client.reconnect.test?check=false&"+Constants.RECONNECT_KEY+"="+reconnectPeriod; return Exchangers.connect(url); }
Example 17
Source File: MinaClientToServerTest.java From dubbo-2.6.5 with Apache License 2.0 | 4 votes |
@Override protected ExchangeChannel newClient(int port) throws RemotingException { return Exchangers.connect(URL.valueOf("exchange://localhost:" + port + "?client=mina")); }
Example 18
Source File: NettyClientTest.java From dubbox-hystrix with Apache License 2.0 | 4 votes |
public static void main(String[] args) throws RemotingException, InterruptedException { ExchangeChannel client = Exchangers.connect(URL.valueOf("exchange://10.20.153.10:20880?client=netty&heartbeat=1000")); Thread.sleep(60*1000*50); }
Example 19
Source File: NettyClientToServerTest.java From dubbox-hystrix with Apache License 2.0 | 4 votes |
protected ExchangeChannel newClient(int port) throws RemotingException { return Exchangers.connect(URL.valueOf("exchange://localhost:" + port + "?client=netty")); }
Example 20
Source File: NettyClientToServerTest.java From dubbo-2.6.5 with Apache License 2.0 | 4 votes |
protected ExchangeChannel newClient(int port) throws RemotingException { return Exchangers.connect(URL.valueOf("exchange://localhost:" + port + "?client=netty4")); }