qpid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rgr...@apache.org
Subject svn commit: r535874 - in /incubator/qpid/branches/M2/java/integrationtests/src/main/java/org/apache/qpid/interop: coordinator/ coordinator/testcases/ testclient/ testclient/testcases/
Date Mon, 07 May 2007 13:13:07 GMT
Author: rgreig
Date: Mon May  7 06:13:06 2007
New Revision: 535874

URL: http://svn.apache.org/viewvc?view=rev&rev=535874
Log:
Added remaining test case.

Added:
    incubator/qpid/branches/M2/java/integrationtests/src/main/java/org/apache/qpid/interop/coordinator/testcases/CoordinatingTestCase3BasicPubSub.java
    incubator/qpid/branches/M2/java/integrationtests/src/main/java/org/apache/qpid/interop/testclient/testcases/TestCase3BasicPubSub.java
Modified:
    incubator/qpid/branches/M2/java/integrationtests/src/main/java/org/apache/qpid/interop/coordinator/Coordinator.java
    incubator/qpid/branches/M2/java/integrationtests/src/main/java/org/apache/qpid/interop/coordinator/testcases/CoordinatingTestCase1DummyRun.java
    incubator/qpid/branches/M2/java/integrationtests/src/main/java/org/apache/qpid/interop/coordinator/testcases/CoordinatingTestCase2BasicP2P.java
    incubator/qpid/branches/M2/java/integrationtests/src/main/java/org/apache/qpid/interop/testclient/TestClient.java

Modified: incubator/qpid/branches/M2/java/integrationtests/src/main/java/org/apache/qpid/interop/coordinator/Coordinator.java
URL: http://svn.apache.org/viewvc/incubator/qpid/branches/M2/java/integrationtests/src/main/java/org/apache/qpid/interop/coordinator/Coordinator.java?view=diff&rev=535874&r1=535873&r2=535874
==============================================================================
--- incubator/qpid/branches/M2/java/integrationtests/src/main/java/org/apache/qpid/interop/coordinator/Coordinator.java
(original)
+++ incubator/qpid/branches/M2/java/integrationtests/src/main/java/org/apache/qpid/interop/coordinator/Coordinator.java
Mon May  7 06:13:06 2007
@@ -33,6 +33,7 @@
 
 import org.apache.qpid.interop.coordinator.testcases.CoordinatingTestCase1DummyRun;
 import org.apache.qpid.interop.coordinator.testcases.CoordinatingTestCase2BasicP2P;
+import org.apache.qpid.interop.coordinator.testcases.CoordinatingTestCase3BasicPubSub;
 import org.apache.qpid.interop.testclient.TestClient;
 import org.apache.qpid.util.CommandLineParser;
 import org.apache.qpid.util.ConversationFactory;
@@ -126,7 +127,11 @@
             // ClasspathScanner.getMatches(CoordinatingTestCase.class, "^Test.*", true);
             // Hard code the test classes till the classpath scanner is fixed.
             Collections.addAll(testCaseClasses,
-                new Class[] { CoordinatingTestCase1DummyRun.class, CoordinatingTestCase2BasicP2P.class
});
+                new Class[]
+                {
+                    CoordinatingTestCase1DummyRun.class, CoordinatingTestCase2BasicP2P.class,
+                    CoordinatingTestCase3BasicPubSub.class
+                });
 
             // Check that some test classes were actually found.
             if ((testCaseClasses == null) || testCaseClasses.isEmpty())
@@ -145,9 +150,12 @@
 
             // Create a coordinator and begin its test procedure.
             Coordinator coordinator = new Coordinator(brokerUrl, virtualHost);
+
+            boolean failure = false;
+
             TestResult testResult = coordinator.start(testClassNames);
 
-            if (!testResult.wasSuccessful())
+            if (failure)
             {
                 System.exit(FAILURE_EXIT);
             }
@@ -175,8 +183,7 @@
      */
     public TestResult start(String[] testClassNames) throws Exception
     {
-        log.debug("public TestResult start(String[] testClassNames = " + PrettyPrintingUtils.printArray(testClassNames)
-            + "): called");
+        log.debug("public TestResult start(String testClassName): called");
 
         // Connect to the broker.
         connection = TestClient.createConnection(DEFAULT_CONNECTION_PROPS_RESOURCE, brokerUrl,
virtualHost);
@@ -202,8 +209,13 @@
 
         enlistedClients = extractEnlists(enlists);
 
-        // Run all of the tests in the suite using JUnit.
-        TestResult result = super.start(testClassNames);
+        // Run the test in the suite using JUnit.
+        TestResult result = null;
+
+        for (String testClassName : testClassNames)
+        {
+            result = super.start(new String[] { testClassName });
+        }
 
         // At this point in time, all tests have completed. Broadcast the shutdown message.
         Message terminate = session.createMessage();

Modified: incubator/qpid/branches/M2/java/integrationtests/src/main/java/org/apache/qpid/interop/coordinator/testcases/CoordinatingTestCase1DummyRun.java
URL: http://svn.apache.org/viewvc/incubator/qpid/branches/M2/java/integrationtests/src/main/java/org/apache/qpid/interop/coordinator/testcases/CoordinatingTestCase1DummyRun.java?view=diff&rev=535874&r1=535873&r2=535874
==============================================================================
--- incubator/qpid/branches/M2/java/integrationtests/src/main/java/org/apache/qpid/interop/coordinator/testcases/CoordinatingTestCase1DummyRun.java
(original)
+++ incubator/qpid/branches/M2/java/integrationtests/src/main/java/org/apache/qpid/interop/coordinator/testcases/CoordinatingTestCase1DummyRun.java
Mon May  7 06:13:06 2007
@@ -2,7 +2,6 @@
 
 import java.util.HashMap;
 import java.util.Map;
-import java.util.Properties;
 
 import javax.jms.Message;
 
@@ -22,7 +21,7 @@
 public class CoordinatingTestCase1DummyRun extends CoordinatingTestCase
 {
     /** Used for debugging. */
-    private static final Logger log = Logger.getLogger(CoordinatingTestCase2BasicP2P.class);
+    private static final Logger log = Logger.getLogger(CoordinatingTestCase1DummyRun.class);
 
     /**
      * Creates a new coordinating test case with the specified name.
@@ -62,5 +61,4 @@
     {
         return "TC1_DummyRun";
     }
-
 }

Modified: incubator/qpid/branches/M2/java/integrationtests/src/main/java/org/apache/qpid/interop/coordinator/testcases/CoordinatingTestCase2BasicP2P.java
URL: http://svn.apache.org/viewvc/incubator/qpid/branches/M2/java/integrationtests/src/main/java/org/apache/qpid/interop/coordinator/testcases/CoordinatingTestCase2BasicP2P.java?view=diff&rev=535874&r1=535873&r2=535874
==============================================================================
--- incubator/qpid/branches/M2/java/integrationtests/src/main/java/org/apache/qpid/interop/coordinator/testcases/CoordinatingTestCase2BasicP2P.java
(original)
+++ incubator/qpid/branches/M2/java/integrationtests/src/main/java/org/apache/qpid/interop/coordinator/testcases/CoordinatingTestCase2BasicP2P.java
Mon May  7 06:13:06 2007
@@ -2,7 +2,6 @@
 
 import java.util.HashMap;
 import java.util.Map;
-import java.util.Properties;
 
 import javax.jms.Message;
 

Added: incubator/qpid/branches/M2/java/integrationtests/src/main/java/org/apache/qpid/interop/coordinator/testcases/CoordinatingTestCase3BasicPubSub.java
URL: http://svn.apache.org/viewvc/incubator/qpid/branches/M2/java/integrationtests/src/main/java/org/apache/qpid/interop/coordinator/testcases/CoordinatingTestCase3BasicPubSub.java?view=auto&rev=535874
==============================================================================
--- incubator/qpid/branches/M2/java/integrationtests/src/main/java/org/apache/qpid/interop/coordinator/testcases/CoordinatingTestCase3BasicPubSub.java
(added)
+++ incubator/qpid/branches/M2/java/integrationtests/src/main/java/org/apache/qpid/interop/coordinator/testcases/CoordinatingTestCase3BasicPubSub.java
Mon May  7 06:13:06 2007
@@ -0,0 +1,71 @@
+package org.apache.qpid.interop.coordinator.testcases;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.jms.Message;
+
+import junit.framework.Assert;
+
+import org.apache.log4j.Logger;
+
+import org.apache.qpid.interop.coordinator.CoordinatingTestCase;
+
+/**
+ * <p><table id="crc"><caption>CRC Card</caption>
+ * <tr><th> Responsibilities <th> Collaborations
+ * <tr><td> Setup pub/sub test parameters and compare with test output. <td>
{@link CoordinatingTestCase}
+ * </table>
+ */
+public class CoordinatingTestCase3BasicPubSub extends CoordinatingTestCase
+{
+    /** Used for debugging. */
+    private static final Logger log = Logger.getLogger(CoordinatingTestCase3BasicPubSub.class);
+
+    /**
+     * Creates a new coordinating test case with the specified name.
+     *
+     * @param name The test case name.
+     */
+    public CoordinatingTestCase3BasicPubSub(String name)
+    {
+        super(name);
+    }
+
+    /**
+     * Performs the basic P2P test case, "Test Case 2" in the specification.
+     */
+    public void testBasicPubSub() throws Exception
+    {
+        log.debug("public void testBasicPubSub(): called");
+
+        Map<String, Object> testConfig = new HashMap<String, Object>();
+        testConfig.put("TEST_NAME", "TC3_BasicPubSub");
+        testConfig.put("PUBSUB_KEY", "tc3route");
+        testConfig.put("PUBSUB_NUM_MESSAGES", 10);
+        testConfig.put("PUBSUB_NUM_RECEIVERS", 5);
+
+        Message[] reports = sequenceTest(testConfig);
+
+        // Compare sender and receiver reports.
+        int messagesSent = reports[0].getIntProperty("MESSAGE_COUNT");
+        int messagesReceived = reports[1].getIntProperty("MESSAGE_COUNT");
+
+        Assert.assertEquals("The requested number of messages were not sent.", 10, messagesSent);
+        Assert.assertEquals("Received messages did not match up to num sent * num receivers.",
messagesSent * 5,
+            messagesReceived);
+    }
+
+    /**
+     * Should provide a translation from the junit method name of a test to its test case
name as defined in the
+     * interop testing specification. 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)
+    {
+        return "TC3_BasicPubSub";
+    }
+}

Modified: incubator/qpid/branches/M2/java/integrationtests/src/main/java/org/apache/qpid/interop/testclient/TestClient.java
URL: http://svn.apache.org/viewvc/incubator/qpid/branches/M2/java/integrationtests/src/main/java/org/apache/qpid/interop/testclient/TestClient.java?view=diff&rev=535874&r1=535873&r2=535874
==============================================================================
--- incubator/qpid/branches/M2/java/integrationtests/src/main/java/org/apache/qpid/interop/testclient/TestClient.java
(original)
+++ incubator/qpid/branches/M2/java/integrationtests/src/main/java/org/apache/qpid/interop/testclient/TestClient.java
Mon May  7 06:13:06 2007
@@ -32,6 +32,7 @@
 
 import org.apache.qpid.interop.testclient.testcases.TestCase1DummyRun;
 import org.apache.qpid.interop.testclient.testcases.TestCase2BasicP2P;
+import org.apache.qpid.interop.testclient.testcases.TestCase3BasicPubSub;
 import org.apache.qpid.util.ClasspathScanner;
 import org.apache.qpid.util.CommandLineParser;
 import org.apache.qpid.util.PropertiesUtils;
@@ -175,7 +176,8 @@
             new ArrayList<Class<? extends InteropClientTestCase>>();
         // ClasspathScanner.getMatches(InteropClientTestCase.class, "^TestCase.*", true);
         // Hard code the test classes till the classpath scanner is fixed.
-        Collections.addAll(testCaseClasses, new Class[] { TestCase1DummyRun.class, TestCase2BasicP2P.class
});
+        Collections.addAll(testCaseClasses,
+            new Class[] { TestCase1DummyRun.class, TestCase2BasicP2P.class, TestCase3BasicPubSub.class
});
 
         // Create all the test case implementations and index them by the test names.
         for (Class<? extends InteropClientTestCase> nextClass : testCaseClasses)

Added: incubator/qpid/branches/M2/java/integrationtests/src/main/java/org/apache/qpid/interop/testclient/testcases/TestCase3BasicPubSub.java
URL: http://svn.apache.org/viewvc/incubator/qpid/branches/M2/java/integrationtests/src/main/java/org/apache/qpid/interop/testclient/testcases/TestCase3BasicPubSub.java?view=auto&rev=535874
==============================================================================
--- incubator/qpid/branches/M2/java/integrationtests/src/main/java/org/apache/qpid/interop/testclient/testcases/TestCase3BasicPubSub.java
(added)
+++ incubator/qpid/branches/M2/java/integrationtests/src/main/java/org/apache/qpid/interop/testclient/testcases/TestCase3BasicPubSub.java
Mon May  7 06:13:06 2007
@@ -0,0 +1,224 @@
+package org.apache.qpid.interop.testclient.testcases;
+
+import javax.jms.*;
+
+import org.apache.log4j.Logger;
+
+import org.apache.qpid.interop.testclient.InteropClientTestCase;
+import org.apache.qpid.interop.testclient.TestClient;
+
+/**
+ * Implements test case 3, basic pub/sub. Sends/received a specified number of messages to
a specified route on the
+ * default topic exchange, using the specified number of receiver connections. Produces reports
on the actual number of
+ * messages sent/received.
+ *
+ * <p><table id="crc"><caption>CRC Card</caption>
+ * <tr><th> Responsibilities <th> Collaborations
+ * <tr><td> Supply the name of the test case that this implements.
+ * <tr><td> Accept/Reject invites based on test parameters.
+ * <tr><td> Adapt to assigned roles.
+ * <tr><td> Send required number of test messages using pub/sub.
+ * <tr><td> Generate test reports.
+ * </table>
+ */
+public class TestCase3BasicPubSub implements InteropClientTestCase
+{
+    /** Used for debugging. */
+    private static final Logger log = Logger.getLogger(TestCase3BasicPubSub.class);
+
+    /** Holds the count of test messages received. */
+    private int messageCount;
+
+    /** The role to be played by the test. */
+    private Roles role;
+
+    /** The number of test messages to send. */
+    private int numMessages;
+
+    /** The number of receiver connection to use. */
+    private int numReceivers;
+
+    /** The routing key to send them to on the default direct exchange. */
+    private Destination sendDestination;
+
+    /** The connections to send/receive the test messages on. */
+    private Connection[] connection;
+
+    /** The sessions to send/receive the test messages on. */
+    private Session[] session;
+
+    /** The producer to send the test messages with. */
+    MessageProducer producer;
+
+    /**
+     * Should provide the name of the test case that this class implements. The exact names
are defined in the
+     * interop testing spec.
+     *
+     * @return The name of the test case that this implements.
+     */
+    public String getName()
+    {
+        log.debug("public String getName(): called");
+
+        return "TC3_BasicPubSub";
+    }
+
+    /**
+     * Determines whether the test invite that matched this test case is acceptable.
+     *
+     * @param inviteMessage The invitation to accept or reject.
+     *
+     * @return <tt>true</tt> to accept the invitation, <tt>false</tt>
to reject it.
+     *
+     * @throws javax.jms.JMSException Any JMSException resulting from reading the message
are allowed to fall through.
+     */
+    public boolean acceptInvite(Message inviteMessage) throws JMSException
+    {
+        log.debug("public boolean acceptInvite(Message inviteMessage = " + inviteMessage
+ "): called");
+
+        // All invites are acceptable.
+        return true;
+    }
+
+    /**
+     * Assigns the role to be played by this test case. The test parameters are fully specified
in the
+     * assignment message. When this method return the test case will be ready to execute.
+     *
+     * @param role              The role to be played; sender or receiver.
+     *
+     * @param assignRoleMessage The role assingment message, contains the full test parameters.
+     *
+     * @throws JMSException Any JMSException resulting from reading the message are allowed
to fall through.
+     */
+    public void assignRole(Roles role, Message assignRoleMessage) throws JMSException
+    {
+        log.debug("public void assignRole(Roles role = " + role + ", Message assignRoleMessage
= " + assignRoleMessage
+            + "): called");
+
+        // Reset the message count for a new test.
+        messageCount = 0;
+
+        // Take note of the role to be played.
+        this.role = role;
+
+        // Extract and retain the test parameters.
+        numMessages = assignRoleMessage.getIntProperty("PUBSUB_NUM_MESSAGES");
+        numReceivers = assignRoleMessage.getIntProperty("PUBSUB_NUM_RECEIVERS");
+        String sendKey = assignRoleMessage.getStringProperty("PUBSUB_KEY");
+
+        log.debug("numMessages = " + numMessages);
+        log.debug("numReceivers = " + numReceivers);
+        log.debug("sendKey = " + sendKey);
+        log.debug("role = " + role);
+
+        switch (role)
+        {
+        // Check if the sender role is being assigned, and set up a single message producer
if so.
+        case SENDER:
+            // Create a new connection to pass the test messages on.
+            connection = new Connection[1];
+            session = new Session[1];
+
+            connection[0] =
+                TestClient.createConnection(TestClient.DEFAULT_CONNECTION_PROPS_RESOURCE,
TestClient.brokerUrl,
+                    TestClient.virtualHost);
+            session[0] = connection[0].createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+            // Extract and retain the test parameters.
+            sendDestination = session[0].createTopic(sendKey);
+
+            producer = session[0].createProducer(sendDestination);
+            break;
+
+        // Otherwise the receiver role is being assigned, so set this up to listen for messages
on the required number
+        // of receiver connections.
+        case RECEIVER:
+            // Create the required number of receiver connections.
+            connection = new Connection[numReceivers];
+            session = new Session[numReceivers];
+
+            for (int i = 0; i < numReceivers; i++)
+            {
+                connection[i] =
+                    TestClient.createConnection(TestClient.DEFAULT_CONNECTION_PROPS_RESOURCE,
TestClient.brokerUrl,
+                        TestClient.virtualHost);
+                session[i] = connection[i].createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+                sendDestination = session[i].createTopic(sendKey);
+
+                MessageConsumer consumer = session[i].createConsumer(sendDestination);
+                consumer.setMessageListener(this);
+            }
+
+            break;
+        }
+
+        // Start all the connection dispatcher threads running.
+        for (int i = 0; i < connection.length; i++)
+        {
+            connection[i].start();
+        }
+    }
+
+    /**
+     * Performs the test case actions.
+     */
+    public void start() throws JMSException
+    {
+        log.debug("public void start(): called");
+
+        // Check that the sender role is being performed.
+        if (role.equals(Roles.SENDER))
+        {
+            Message testMessage = session[0].createTextMessage("test");
+
+            for (int i = 0; i < numMessages; i++)
+            {
+                producer.send(testMessage);
+
+                // Increment the message count.
+                messageCount++;
+            }
+        }
+    }
+
+    /**
+     * Gets a report on the actions performed by the test case in its assigned role.
+     *
+     * @param session The session to create the report message in.
+     *
+     * @return The report message.
+     *
+     * @throws JMSException Any JMSExceptions resulting from creating the report are allowed
to fall through.
+     */
+    public Message getReport(Session session) throws JMSException
+    {
+        log.debug("public Message getReport(Session session): called");
+
+        // Close the test connections.
+        for (int i = 0; i < connection.length; i++)
+        {
+            connection[i].close();
+        }
+
+        // Generate a report message containing the count of the number of messages passed.
+        Message report = session.createMessage();
+        report.setStringProperty("CONTROL_TYPE", "REPORT");
+        report.setIntProperty("MESSAGE_COUNT", messageCount);
+
+        return report;
+    }
+
+    /**
+     * Counts incoming test messages.
+     *
+     * @param message The incoming test message.
+     */
+    public void onMessage(Message message)
+    {
+        log.debug("public void onMessage(Message message = " + message + "): called");
+
+        // Increment the message count.
+        messageCount++;
+    }
+}



Mime
View raw message