From 56c9945fab16ae5c2df607b4705a79ba85128674 Mon Sep 17 00:00:00 2001 From: Bhupendra Bhusman Bhardwaj Date: Fri, 19 Jan 2007 17:02:11 +0000 Subject: Added class to ping itself and a junit test for it. git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk@497878 13f79535-47bb-0310-9956-ffa450edef68 --- .../java/org/apache/qpid/ping/PingTestPerf.java | 89 ++++++++++++---------- 1 file changed, 47 insertions(+), 42 deletions(-) (limited to 'qpid/java/perftests/src/test') diff --git a/qpid/java/perftests/src/test/java/org/apache/qpid/ping/PingTestPerf.java b/qpid/java/perftests/src/test/java/org/apache/qpid/ping/PingTestPerf.java index 4b42283023..7cdfd29120 100644 --- a/qpid/java/perftests/src/test/java/org/apache/qpid/ping/PingTestPerf.java +++ b/qpid/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. * *

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. * *

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); + } } -- cgit v1.2.1