views:

479

answers:

2

I'm implementing a SOAP client using Apache Axis 2. Since the SOAP client must handle heavy number of requests I am using a connection pool.

To do that I had to set a few transport layer configuration of my stub that was generated from a WSDL file:

stub._getServiceClient().getOptions().setProperty(HTTPConstants.REUSE_HTTP_CLIENT, Constants.VALUE_TRUE);

MultiThreadedHttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager();
connectionManager.getParams().setDefaultMaxConnectionsPerHost(MAX_CONNECTIONS_PER_HOST);
connectionManager.closeIdleConnections(IDLE_CONNECTION_TIMEOUT);
HttpClient httpClient = new HttpClient(connectionManager);

stub._getServiceClient().getOptions().setProperty(HTTPConstants.CACHED_HTTP_CLIENT, httpClient);

My client seems to be working just fine. However, I would like to know how can I test if the connection pool is working in a correct way (i.e. the created connections are only destroyed after the time defined by the IDLE_CONNECTION_TIMEOUT constant). Any ideas?

A: 

Write a testbed application which will make a large number of requests, and assert that the number of connections is never more than MAX_CONNECTIONS. You might be able to check on the latter by attaching jconsole or VisualVM to the process.

You could also look into using Jakarta JMeter for generating load on the class/client, and then graphing out several datapoints (not sure how you'd gain access to number of client connections created, though).

matt b
+1  A: 

Pseudo-code based on JUnit 3.x:

  setUp() {
    initialize connection manager;
    initialize connection by creating client;
  }

  tearDown() {
    close connection if necessary;
    close connection manager if necessary;
  }

  testConnectionOpen() {
    assert that connection is open;
    pause for time of idle connection timeout - 1 second;
    assert that connection **is still open**;
  }

  testConnectionClosed() {
    assert that connection is open;
    pause for time of idle connection timeout + 1 second;
    assert that connection **is closed**;
  }

Adding 1 second and subtracting 1 second should be adjusted depending on sensitivity of the connection manager.

grigory