summaryrefslogtreecommitdiff
path: root/java/perftests/src/test
diff options
context:
space:
mode:
authorBhupendra Bhusman Bhardwaj <bhupendrab@apache.org>2007-01-19 17:02:11 +0000
committerBhupendra Bhusman Bhardwaj <bhupendrab@apache.org>2007-01-19 17:02:11 +0000
commit4a1440c33b20897702b853c4724154a88707048b (patch)
tree44a3c7fe2b95298d9f944caa65180adeee56ccf3 /java/perftests/src/test
parentbb8331eb508558739fa11a1fe8a9a696b1a24e10 (diff)
downloadqpid-python-4a1440c33b20897702b853c4724154a88707048b.tar.gz
Added class to ping itself and a junit test for it.
git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid@497878 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'java/perftests/src/test')
-rw-r--r--java/perftests/src/test/java/org/apache/qpid/ping/PingTestPerf.java89
1 files changed, 47 insertions, 42 deletions
diff --git a/java/perftests/src/test/java/org/apache/qpid/ping/PingTestPerf.java b/java/perftests/src/test/java/org/apache/qpid/ping/PingTestPerf.java
index 4b42283023..7cdfd29120 100644
--- a/java/perftests/src/test/java/org/apache/qpid/ping/PingTestPerf.java
+++ b/java/perftests/src/test/java/org/apache/qpid/ping/PingTestPerf.java
@@ -1,14 +1,16 @@
package org.apache.qpid.ping;
-import java.net.InetAddress;
import java.util.Properties;
import javax.jms.*;
-import junit.framework.TestCase;
+import junit.framework.Test;
+import junit.framework.TestSuite;
+import junit.framework.Assert;
import org.apache.log4j.Logger;
import org.apache.log4j.NDC;
+import uk.co.thebadgerset.junit.extensions.AsymptoticTestCase;
/**
*
@@ -16,8 +18,7 @@ import org.apache.log4j.NDC;
* simultaneously to simluate many clients/producers/connections.
*
* <p/>A single run of the test using the default JUnit test runner will result in the sending and timing of a single
- * full round trip ping. This test may be scaled up using a suitable JUnit test runner. See {@link TKTestRunner} or
- * {@link PPTestRunner} for more information on how to do this.
+ * full round trip ping. This test may be scaled up using a suitable JUnit test runner.
*
* <p/>The setup/teardown cycle establishes a connection to a broker and sets up a queue to send ping messages to and a
* temporary queue for replies. This setup is only established once for all the test repeats/threads that may be run,
@@ -35,7 +36,7 @@ import org.apache.log4j.NDC;
*
* @author Rupert Smith
*/
-public class PingTestPerf extends TestCase //implements TimingControllerAware
+public class PingTestPerf extends AsymptoticTestCase //implements TimingControllerAware
{
private static Logger _logger = Logger.getLogger(PingTestPerf.class);
@@ -57,6 +58,9 @@ public class PingTestPerf extends TestCase //implements TimingControllerAware
/** Holds the name of the property to get the test broker virtual path. */
private static final String VIRTUAL_PATH_PROPNAME = "virtualPath";
+ /** Holds the waiting timeout for response messages */
+ private static final String TIMEOUT_PROPNAME = "timeout";
+
/** Holds the size of message body to attach to the ping messages. */
private static final int MESSAGE_SIZE_DEFAULT = 0;
@@ -76,7 +80,7 @@ public class PingTestPerf extends TestCase //implements TimingControllerAware
private static final String VIRTUAL_PATH_DEFAULT = "/test";
/** Sets a default ping timeout. */
- private static final long TIMEOUT = 3000;
+ private static final long TIMEOUT_DEFAULT = 3000;
// Sets up the test parameters with defaults.
static
@@ -87,13 +91,11 @@ public class PingTestPerf extends TestCase //implements TimingControllerAware
setSystemPropertyIfNull(TRANSACTED_PROPNAME, Boolean.toString(TRANSACTED_DEFAULT));
setSystemPropertyIfNull(BROKER_PROPNAME, BROKER_DEFAULT);
setSystemPropertyIfNull(VIRTUAL_PATH_PROPNAME, VIRTUAL_PATH_DEFAULT);
+ setSystemPropertyIfNull(TIMEOUT_PROPNAME, Long.toString(TIMEOUT_DEFAULT));
}
- /** Holds the test ping-pong producer. */
- private TestPingProducer _testPingProducer;
-
/** Holds the test ping client. */
- private TestPingClient _testPingClient;
+ private TestPingItself _pingItselfClient;
// Set up a property reader to extract the test parameters from. Once ContextualProperties is available in
// the project dependencies, use it to get property overrides for configurable tests and to notify the test runner
@@ -114,26 +116,22 @@ public class PingTestPerf extends TestCase //implements TimingControllerAware
}
}
- public void testPingOk() throws Exception
+ public void testPingOk(int numPings) throws Exception
{
// Generate a sample message. This message is already time stamped and has its reply-to destination set.
- ObjectMessage msg =
- _testPingProducer.getTestMessage(null, Integer.parseInt(testParameters.getProperty(MESSAGE_SIZE_PROPNAME)),
+ ObjectMessage msg = _pingItselfClient.getTestMessage(null,
+ Integer.parseInt(testParameters.getProperty(MESSAGE_SIZE_PROPNAME)),
Boolean.parseBoolean(testParameters.getProperty(PERSISTENT_MODE_PROPNAME)));
- // Use the test timing controller to reset the test timer now and obtain the current time.
- // This can be used to remove the message creation time from the test.
- //TestTimingController timingUtils = getTimingController();
- //long startTime = timingUtils.restart();
-
- // Send the message.
- _testPingProducer.ping(msg);
-
+ // start the test
+ long timeout = Long.parseLong(testParameters.getProperty(TIMEOUT_PROPNAME));
+ int numReplies = _pingItselfClient.pingAndWaitForReply(msg, numPings, timeout);
+ _logger.info("replies = " + numReplies);
// Fail the test if the timeout was exceeded.
- /*if (reply == null)
+ if (numReplies != numPings)
{
- Assert.fail("The ping timed out for message id: " + msg.getJMSMessageID());
- }*/
+ Assert.fail("The ping timed out. Messages Sent = " + numReplies + ", MessagesReceived = " + numPings);
+ }
}
protected void setUp() throws Exception
@@ -142,7 +140,7 @@ public class PingTestPerf extends TestCase //implements TimingControllerAware
NDC.push(getName());
// Ensure that the connection, session and ping queue are established, if they have not already been.
- if (_testPingProducer == null)
+ if (_pingItselfClient == null)
{
// Extract the test set up paramaeters.
String brokerDetails = testParameters.getProperty(BROKER_PROPNAME);
@@ -156,17 +154,12 @@ public class PingTestPerf extends TestCase //implements TimingControllerAware
boolean verbose = false;
int messageSize = Integer.parseInt(testParameters.getProperty(MESSAGE_SIZE_PROPNAME));
- // Establish a bounce back client on the ping queue to bounce back the pings.
- _testPingClient = new TestPingClient(brokerDetails, username, password, queueName, virtualpath, transacted,
- selector, verbose);
-
- // Establish a ping-pong client on the ping queue to send the pings with.
- _testPingProducer = new TestPingProducer(brokerDetails, username, password, virtualpath, queueName, transacted,
- persistent, messageSize, verbose);
+ // Establish a client to ping a Queue and listen the reply back from same Queue
+ _pingItselfClient = new TestPingItself(brokerDetails, username, password, virtualpath, queueName,
+ selector, transacted, persistent, messageSize, verbose);
- // Start the connections for client and producer running.
- _testPingClient.getConnection().start();
- _testPingProducer.getConnection().start();
+ // Start the client connection
+ _pingItselfClient.getConnection().start();
}
}
@@ -174,19 +167,31 @@ public class PingTestPerf extends TestCase //implements TimingControllerAware
{
try
{
- if ((_testPingClient != null) && (_testPingClient.getConnection() != null))
+ /*
+ if ((_pingItselfClient != null) && (_pingItselfClient.getConnection() != null))
{
- _testPingClient.getConnection().close();
- }
-
- if ((_testPingProducer != null) && (_testPingProducer.getConnection() != null))
- {
- _testPingProducer.getConnection().close();
+ _pingItselfClient.getConnection().close();
}
+ */
}
finally
{
NDC.pop();
}
}
+
+ /**
+ * Compile all the tests into a test suite.
+ */
+ public static Test suite()
+ {
+ // Build a new test suite
+ TestSuite suite = new TestSuite("Ping Performance Tests");
+
+ // Run performance tests in read committed mode.
+ suite.addTest(new PingTestPerf("testPingOk"));
+
+ return suite;
+ //return new junit.framework.TestSuite(PingTestPerf.class);
+ }
}