use of org.apache.dubbo.remoting.exchange.ExchangeClient in project dubbo by alibaba.
the class ChanelHandlerTest method testClient.
@Test
public void testClient() throws Throwable {
// read server info from property
if (PerformanceUtils.getProperty("server", null) == null) {
logger.warn("Please set -Dserver=127.0.0.1:9911");
return;
}
final String server = System.getProperty("server", "127.0.0.1:9911");
final String transporter = PerformanceUtils.getProperty(Constants.TRANSPORTER_KEY, Constants.DEFAULT_TRANSPORTER);
final String serialization = PerformanceUtils.getProperty(Constants.SERIALIZATION_KEY, Constants.DEFAULT_REMOTING_SERIALIZATION);
final int timeout = PerformanceUtils.getIntProperty(TIMEOUT_KEY, DEFAULT_TIMEOUT);
int sleep = PerformanceUtils.getIntProperty("sleep", 60 * 1000 * 60);
final String url = "exchange://" + server + "?transporter=" + transporter + "&serialization=" + serialization + "&timeout=" + timeout;
ExchangeClient exchangeClient = initClient(url);
Thread.sleep(sleep);
closeClient(exchangeClient);
}
use of org.apache.dubbo.remoting.exchange.ExchangeClient in project dubbo by alibaba.
the class ChanelHandlerTest method initClient.
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;
}
use of org.apache.dubbo.remoting.exchange.ExchangeClient in project dubbo by alibaba.
the class PerformanceClientCloseTest method testClient.
@Test
public void testClient() throws Throwable {
// read server info from property
if (PerformanceUtils.getProperty("server", null) == null) {
logger.warn("Please set -Dserver=127.0.0.1:9911");
return;
}
final String server = System.getProperty("server", "127.0.0.1:9911");
final String transporter = PerformanceUtils.getProperty(Constants.TRANSPORTER_KEY, Constants.DEFAULT_TRANSPORTER);
final String serialization = PerformanceUtils.getProperty(Constants.SERIALIZATION_KEY, Constants.DEFAULT_REMOTING_SERIALIZATION);
final int timeout = PerformanceUtils.getIntProperty(TIMEOUT_KEY, DEFAULT_TIMEOUT);
final int concurrent = PerformanceUtils.getIntProperty("concurrent", 1);
final int runs = PerformanceUtils.getIntProperty("runs", Integer.MAX_VALUE);
final String onerror = PerformanceUtils.getProperty("onerror", "continue");
final String url = "exchange://" + server + "?transporter=" + transporter + "&serialization=" + serialization + // + "&"+Constants.CHANNEL_HANDLER_KEY+"=connection"
"&timeout=" + timeout;
final AtomicInteger count = new AtomicInteger();
final AtomicInteger error = new AtomicInteger();
for (int n = 0; n < concurrent; n++) {
new Thread(new Runnable() {
public void run() {
for (int i = 0; i < runs; i++) {
ExchangeClient client = null;
try {
client = Exchangers.connect(url);
int c = count.incrementAndGet();
if (c % 100 == 0) {
System.out.println("count: " + count.get() + ", error: " + error.get());
}
} catch (Exception e) {
error.incrementAndGet();
e.printStackTrace();
System.out.println("count: " + count.get() + ", error: " + error.get());
if ("exit".equals(onerror)) {
System.exit(-1);
} else if ("break".equals(onerror)) {
break;
} else if ("sleep".equals(onerror)) {
try {
Thread.sleep(30000);
} catch (InterruptedException e1) {
}
}
} finally {
if (client != null) {
client.close();
}
}
}
}
}).start();
}
synchronized (PerformanceServerTest.class) {
while (true) {
try {
PerformanceServerTest.class.wait();
} catch (InterruptedException e) {
}
}
}
}
use of org.apache.dubbo.remoting.exchange.ExchangeClient in project dubbo by alibaba.
the class PortTelnetHandlerTest method testListClient.
/**
* In NAT network scenario, server's channel.getRemoteAddress() possibly get the address of network gateway, or
* the address converted by NAT. In this case, check port only.
*/
@Test
public void testListClient() throws Exception {
ExchangeClient client1 = Exchangers.connect("dubbo://127.0.0.1:" + availablePort + "/demo");
ExchangeClient client2 = Exchangers.connect("dubbo://127.0.0.1:" + availablePort + "/demo");
Thread.sleep(5000);
String result = port.telnet(null, "-l " + availablePort + "");
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(String.valueOf(client1.getLocalAddress().getPort())));
assertTrue(result.contains(String.valueOf(client2.getLocalAddress().getPort())));
}
use of org.apache.dubbo.remoting.exchange.ExchangeClient in project dubbo by alibaba.
the class AbstractExchangeGroup method connect.
protected Client connect(URL url) throws RemotingException {
if (servers.containsKey(url)) {
return null;
}
ExchangeClient client = clients.get(url);
if (client == null) {
// TODO exist concurrent gap
client = Exchangers.connect(url, dispatcher);
clients.put(url, client);
}
return client;
}
Aggregations