From 6b54ebb02e87cc4cc0a7bcd1d9d820c463f76e7f Mon Sep 17 00:00:00 2001 From: Rupert Smith Date: Wed, 1 Aug 2007 16:19:31 +0000 Subject: Extensive refactoring of the distributed test framework. git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/branches/M2@561855 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/qpid/requestreply/PingPongBouncer.java | 10 +- .../apache/qpid/requestreply/PingPongProducer.java | 14 +- .../qpid/perftests/QpidTestThroughputPerf.java | 170 +++++++++++++++++++++ 3 files changed, 182 insertions(+), 12 deletions(-) create mode 100644 java/perftests/src/test/java/org/apache/qpid/perftests/QpidTestThroughputPerf.java (limited to 'java/perftests/src') diff --git a/java/perftests/src/main/java/org/apache/qpid/requestreply/PingPongBouncer.java b/java/perftests/src/main/java/org/apache/qpid/requestreply/PingPongBouncer.java index 78ab7c4c73..82b36bf233 100644 --- a/java/perftests/src/main/java/org/apache/qpid/requestreply/PingPongBouncer.java +++ b/java/perftests/src/main/java/org/apache/qpid/requestreply/PingPongBouncer.java @@ -92,10 +92,10 @@ public class PingPongBouncer implements MessageListener /** The producer for sending replies with. */ private MessageProducer _replyProducer; - /** The consumer session. */ + /** The consumer controlSession. */ private Session _consumerSession; - /** The producer session. */ + /** The producer controlSession. */ private Session _producerSession; /** Holds the connection to the broker. */ @@ -149,7 +149,7 @@ public class PingPongBouncer implements MessageListener // Set up the failover notifier. getConnection().setConnectionListener(new FailoverNotifier()); - // Create a session to listen for messages on and one to send replies on, transactional depending on the + // Create a controlSession to listen for messages on and one to send replies on, transactional depending on the // command line option. _consumerSession = (Session) getConnection().createSession(transacted, Session.AUTO_ACKNOWLEDGE); _producerSession = (Session) getConnection().createSession(transacted, Session.AUTO_ACKNOWLEDGE); @@ -323,8 +323,8 @@ public class PingPongBouncer implements MessageListener } /** - * Convenience method to commit the transaction on the specified session. If the session to commit on is not - * a transactional session, this method does nothing. + * Convenience method to commit the transaction on the specified controlSession. If the controlSession to commit on is not + * a transactional controlSession, this method does nothing. * *

If the {@link #_failBeforeCommit} flag is set, this will prompt the user to kill the broker before the * commit is applied. If the {@link #_failAfterCommit} flag is set, this will prompt the user to kill the broker diff --git a/java/perftests/src/main/java/org/apache/qpid/requestreply/PingPongProducer.java b/java/perftests/src/main/java/org/apache/qpid/requestreply/PingPongProducer.java index 03f5f0549d..140e3bad1c 100644 --- a/java/perftests/src/main/java/org/apache/qpid/requestreply/PingPongProducer.java +++ b/java/perftests/src/main/java/org/apache/qpid/requestreply/PingPongProducer.java @@ -395,10 +395,10 @@ public class PingPongProducer implements Runnable, MessageListener, ExceptionLis /** Holds the connection to the broker. */ protected Connection _connection; - /** Holds the session on which ping replies are received. */ + /** Holds the controlSession on which ping replies are received. */ protected Session _consumerSession; - /** Holds the producer session, needed to create ping messages. */ + /** Holds the producer controlSession, needed to create ping messages. */ protected Session _producerSession; /** Holds the destination where the response messages will arrive. */ @@ -1305,8 +1305,8 @@ public class PingPongProducer implements Runnable, MessageListener, ExceptionLis } /** - * Convenience method to commit the transaction on the specified session. If the session to commit on is not a - * transactional session, this method does nothing (unless the failover after send flag is set). + * Convenience method to commit the transaction on the specified controlSession. If the controlSession to commit on is not a + * transactional controlSession, this method does nothing (unless the failover after send flag is set). * *

If the {@link #_failAfterSend} flag is set, this will prompt the user to kill the broker before the commit is * applied. This flag applies whether the pinger is transactional or not. @@ -1315,9 +1315,9 @@ public class PingPongProducer implements Runnable, MessageListener, ExceptionLis * is applied. If the {@link #_failAfterCommit} flag is set, this will prompt the user to kill the broker after the * commit is applied. These flags will only apply if using a transactional pinger. * - * @param session The session to commit + * @param session The controlSession to commit * - * @return true if the session was committed, false if it was not. + * @return true if the controlSession was committed, false if it was not. * * @throws javax.jms.JMSException If the commit fails and then the rollback fails. * @@ -1327,7 +1327,7 @@ public class PingPongProducer implements Runnable, MessageListener, ExceptionLis */ protected boolean commitTx(Session session) throws JMSException { - // log.debug("protected void commitTx(Session session): called"); + // log.debug("protected void commitTx(Session controlSession): called"); boolean committed = false; diff --git a/java/perftests/src/test/java/org/apache/qpid/perftests/QpidTestThroughputPerf.java b/java/perftests/src/test/java/org/apache/qpid/perftests/QpidTestThroughputPerf.java new file mode 100644 index 0000000000..760d1c84a4 --- /dev/null +++ b/java/perftests/src/test/java/org/apache/qpid/perftests/QpidTestThroughputPerf.java @@ -0,0 +1,170 @@ +/* + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +package org.apache.qpid.perftests; + +import junit.framework.Test; +import junit.framework.TestSuite; + +import org.apache.log4j.Logger; + +import org.apache.qpid.test.framework.Assertion; +import org.apache.qpid.test.framework.Circuit; +import org.apache.qpid.test.framework.FrameworkBaseCase; +import org.apache.qpid.test.framework.MessagingTestConfigProperties; +import org.apache.qpid.test.framework.sequencers.CircuitFactory; + +import uk.co.thebadgerset.junit.extensions.TestThreadAware; +import uk.co.thebadgerset.junit.extensions.TimingController; +import uk.co.thebadgerset.junit.extensions.TimingControllerAware; +import uk.co.thebadgerset.junit.extensions.util.ParsedProperties; +import uk.co.thebadgerset.junit.extensions.util.TestContextProperties; + +import java.util.LinkedList; + +/** + * QpidTestThroughputPerf runs a test over a {@link Circuit} controlled by the test parameters. It logs timings of + * the time required to receive samples consisting of batches of messages. As the time samples is taken over a reasonable + * sized message batch, it measures message throughput. + * + *

+ *
CRC Card
Responsibilities Collaborations + *
+ *
+ * + * @todo Check that all of the messages were sent. Check that the receiving end got the same number of messages as + * the publishing end. + */ +public class QpidTestThroughputPerf extends FrameworkBaseCase implements TimingControllerAware, TestThreadAware +{ + /** Used for debugging. */ + private static final Logger log = Logger.getLogger(QpidTestThroughputPerf.class); + + /** Holds the timing controller, used to log test timings from self-timed tests. */ + private TimingController timingController; + + /** Thread local to hold the per-thread test setup fields. */ + ThreadLocal threadSetup = new ThreadLocal(); + + /** + * Creates a new test case with the specified name. + * + * @param name The test case name. + */ + public QpidTestThroughputPerf(String name) + { + super(name); + } + + /** + * Performs the a basic P2P test case. + * + * @param numMessages The number of messages to send in the test. + */ + public void testThroughput(int numMessages) + { + log.debug("public void testThroughput(): called"); + + PerThreadSetup setup = threadSetup.get(); + assertNoFailures(setup.testCircuit.test(numMessages, new LinkedList())); + } + + /** + * Should provide a translation from the junit method name of a test to its test case name as known to the test + * clients that will run the test. The purpose of this is to convert the JUnit method name into the correct test + * case name to place into the test invite. For example the method "testP2P" might map onto the interop test case + * name "TC2_BasicP2P". + * + * @param methodName The name of the JUnit test method. + * + * @return The name of the corresponding interop test case. + */ + public String getTestCaseNameForTestMethod(String methodName) + { + log.debug("public String getTestCaseNameForTestMethod(String methodName = " + methodName + "): called"); + + return "DEFAULT_CIRCUIT_TEST"; + } + + /** + * Used by test runners that can supply a {@link uk.co.thebadgerset.junit.extensions.TimingController} to set the + * controller on an aware test. + * + * @param controller The timing controller. + */ + public void setTimingController(TimingController controller) + { + timingController = controller; + } + + /** + * Performs test fixture creation on a per thread basis. This will only be called once for each test thread. + */ + public void threadSetUp() + { + // Get the test parameters, any overrides on the command line will have been applied. + ParsedProperties testProps = TestContextProperties.getInstance(MessagingTestConfigProperties.defaults); + + // Customize the test parameters. + testProps.setProperty("TEST_NAME", "DEFAULT_CIRCUIT_TEST"); + testProps.setProperty(MessagingTestConfigProperties.SEND_DESTINATION_NAME_ROOT_PROPNAME, "testqueue"); + + // Get the test circuit factory to create test circuits and run the standard test procedure through. + CircuitFactory circuitFactory = getCircuitFactory(); + + // Create the test circuit. This projects the circuit onto the available test nodes and connects it up. + Circuit testCircuit = circuitFactory.createCircuit(testProps); + + // Store the test configuration for the thread. + PerThreadSetup setup = new PerThreadSetup(); + setup.testCircuit = testCircuit; + threadSetup.set(setup); + } + + /** + * Called when a test thread is destroyed. + */ + public void threadTearDown() + { } + + /** + * Holds the per-thread test configurations. + */ + protected static class PerThreadSetup + { + /** Holds the test circuit to run tests on. */ + Circuit testCircuit; + } + + /** + * Compiles all the tests in this class into a suite. + * + * @return The test suite. + */ + public static Test suite() + { + // Build a new test suite + TestSuite suite = new TestSuite("Qpid Throughput Performance Tests"); + + suite.addTest(new QpidTestThroughputPerf("testThroughput")); + + return suite; + } +} -- cgit v1.2.1