package qnd;

import org.apache.commons.lang3.StringUtils;
import org.apache.thrift.transport.TTransportException;

import test.utils.Benchmark;
import test.utils.BenchmarkResult;
import test.utils.Operation;

import com.github.btnguyen2k.idserver.thrift.TIdService;
import com.github.ddth.id.jclient.thrift.ThriftClientFactory;
import com.github.ddth.thriftpool.ThriftClientPool;

public class QndBenchmarkThriftClientPing extends BaseQndThriftClient {

    private static void runTest(
            final ThriftClientPool<TIdService.Client, TIdService.Iface> clientPool,
            final int numRuns, final int numThreads, final int numNamespaces)
            throws TTransportException {
        BenchmarkResult result = new Benchmark(new Operation() {
            @Override
            public void run(int runId) {
                try {
                    TIdService.Iface client = clientPool.borrowObject();
                    try {
                        client.ping();
                    } finally {
                        clientPool.returnObject(client);
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }, numRuns, numThreads).run();
        System.out.println(result.summarize());
    }

    /**
     * @param args
     * @throws TTransportException
     */
    public static void main(String[] args) throws TTransportException {
        String thriftHost = System.getProperty("thriftHost");
        if (StringUtils.isBlank(thriftHost)) {
            thriftHost = "localhost";
        }
        int thriftPort;
        try {
            thriftPort = Integer.parseInt(System.getProperty("thriftPort"));
        } catch (Exception e) {
            thriftPort = 9090;
        }
        final ThriftClientPool<TIdService.Client, TIdService.Iface> clientPool = ThriftClientFactory
                .newDefaultClientPool(thriftHost, thriftPort);

        int numRuns, numThreads, numNamespaces;

        try {
            numRuns = Integer.parseInt(System.getProperty("numRuns"));
        } catch (Exception e) {
            numRuns = 100000;
        }
        try {
            numThreads = Integer.parseInt(System.getProperty("numThreads"));
        } catch (Exception e) {
            numThreads = 4;
        }
        try {
            numNamespaces = Integer.parseInt(System.getProperty("numNamespaces"));
        } catch (Exception e) {
            numNamespaces = 4;
        }

        for (int i = 0; i < 10; i++) {
            runTest(clientPool, numRuns, numThreads, numNamespaces);
        }

        clientPool.destroy();
    }
}

@@ -52,16 +52,257 @@
 gUtils;%0A
+import org.apache.thrift.protocol.TCompactProtocol;%0Aimport org.apache.thrift.protocol.TProtocol;%0Aimport org.apache.thrift.transport.TFramedTransport;%0Aimport org.apache.thrift.transport.TSocket;%0Aimport org.apache.thrift.transport.TTransport;%0A
 import o
@@ -345,24 +345,24 @@
 tException;%0A
-
 %0Aimport test
@@ -813,24 +813,59 @@
 %0A           
+ final String host, final int port,
  final int n
@@ -893,16 +893,28 @@
 Threads,
+%0A           
  final i
@@ -930,28 +930,16 @@
 espaces)
-%0A           
  throws 
@@ -951,32 +951,340 @@
 sportException %7B
+%0A%0A        TSocket socket = new TSocket(host, port);%0A        socket.setTimeout(10000);%0A        TTransport transport = new TFramedTransport(socket);%0A        TProtocol protocol = new TCompactProtocol(transport);%0A        transport.open();%0A        final TIdService.Iface client = new TIdService.Client(protocol);%0A
 %0A        Benchma
@@ -1437,16 +1437,19 @@
         
+ //
  TIdServ
@@ -1610,24 +1610,27 @@
             
+ //
  clientPool.
@@ -1872,16 +1872,44 @@
 rize());
+%0A%0A        transport.close();
 %0A    %7D%0A%0A
@@ -3133,24 +3133,24 @@
  10; i++) %7B%0A
-
             
@@ -3168,16 +3168,40 @@
 entPool,
+ thriftHost, thriftPort,
  numRuns

Update client