Search in sources :

Example 6 with ExchangeClient

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);
}
Also used : ExchangeClient(org.apache.dubbo.remoting.exchange.ExchangeClient) Test(org.junit.jupiter.api.Test)

Example 7 with 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;
}
Also used : ExchangeClient(org.apache.dubbo.remoting.exchange.ExchangeClient)

Example 8 with 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) {
            }
        }
    }
}
Also used : ExchangeClient(org.apache.dubbo.remoting.exchange.ExchangeClient) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Test(org.junit.jupiter.api.Test)

Example 9 with ExchangeClient

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())));
}
Also used : ExchangeClient(org.apache.dubbo.remoting.exchange.ExchangeClient) Test(org.junit.jupiter.api.Test)

Example 10 with ExchangeClient

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;
}
Also used : ExchangeClient(org.apache.dubbo.remoting.exchange.ExchangeClient)

Aggregations

ExchangeClient (org.apache.dubbo.remoting.exchange.ExchangeClient)17 Test (org.junit.jupiter.api.Test)8 URL (org.apache.dubbo.common.URL)4 Field (java.lang.reflect.Field)3 ArrayList (java.util.ArrayList)3 RemotingException (org.apache.dubbo.remoting.RemotingException)3 RpcException (org.apache.dubbo.rpc.RpcException)3 List (java.util.List)2 ExecutorService (java.util.concurrent.ExecutorService)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 TimeoutException (org.apache.dubbo.remoting.TimeoutException)2 AppResponse (org.apache.dubbo.rpc.AppResponse)2 AsyncRpcResult (org.apache.dubbo.rpc.AsyncRpcResult)2 RpcInvocation (org.apache.dubbo.rpc.RpcInvocation)2 AsyncToSyncInvoker (org.apache.dubbo.rpc.protocol.AsyncToSyncInvoker)2 SimpleDateFormat (java.text.SimpleDateFormat)1 Collections (java.util.Collections)1 Comparator (java.util.Comparator)1 Date (java.util.Date)1 Map (java.util.Map)1