From 4fa14823a4110d82c26edcc1aaf0cd9d325a9dd4 Mon Sep 17 00:00:00 2001 From: Robert Greig Date: Wed, 2 May 2007 16:47:36 +0000 Subject: Removed accidentally included copyright and author tags. git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid@534539 13f79535-47bb-0310-9956-ffa450edef68 --- .../interop/coordinator/CoordinatingTestCase.java | 5 +- .../qpid/interop/coordinator/Coordinator.java | 65 +++++++++++----------- .../interop/coordinator/InvitingTestDecorator.java | 32 +++++------ .../testcases/CoordinatingTestCase2BasicP2P.java | 48 ++++++++++++++++ .../org/apache/qpid/util/ConversationHelper.java | 27 ++++----- 5 files changed, 112 insertions(+), 65 deletions(-) create mode 100644 java/integrationtests/src/main/java/org/apache/qpid/interop/coordinator/testcases/CoordinatingTestCase2BasicP2P.java (limited to 'java/integrationtests/src') diff --git a/java/integrationtests/src/main/java/org/apache/qpid/interop/coordinator/CoordinatingTestCase.java b/java/integrationtests/src/main/java/org/apache/qpid/interop/coordinator/CoordinatingTestCase.java index f2c0acbc16..36c270ef11 100644 --- a/java/integrationtests/src/main/java/org/apache/qpid/interop/coordinator/CoordinatingTestCase.java +++ b/java/integrationtests/src/main/java/org/apache/qpid/interop/coordinator/CoordinatingTestCase.java @@ -1,3 +1,4 @@ +/* Copyright Rupert Smith, 2005 to 2006, all rights reserved. */ /* * * Licensed to the Apache Software Foundation (ASF) under one @@ -125,7 +126,7 @@ public abstract class CoordinatingTestCase extends TestCase /** * Holds a test coordinating conversation with the test clients. This is the basic implementation of the inner - * loop of Use Case 5. It consists of assign the test roles, begining the test and gathering the test reports + * loop of Use Case 5. It consists of assigning the test roles, begining the test and gathering the test reports * from the participants. * * @param testProperties The test case definition. @@ -134,7 +135,7 @@ public abstract class CoordinatingTestCase extends TestCase * * @throws JMSException All underlying JMSExceptions are allowed to fall through. */ - protected Object[] sequenceTest(Properties testProperties) throws JMSException + protected Message[] sequenceTest(Properties testProperties) throws JMSException { // Assign the sender role to the sending test client. Message assignSender = conversation.getSession().createMessage(); diff --git a/java/integrationtests/src/main/java/org/apache/qpid/interop/coordinator/Coordinator.java b/java/integrationtests/src/main/java/org/apache/qpid/interop/coordinator/Coordinator.java index 3f87becc3d..5e0f5b4941 100644 --- a/java/integrationtests/src/main/java/org/apache/qpid/interop/coordinator/Coordinator.java +++ b/java/integrationtests/src/main/java/org/apache/qpid/interop/coordinator/Coordinator.java @@ -31,8 +31,11 @@ import junit.framework.TestSuite; import org.apache.log4j.Logger; +import org.apache.qpid.interop.coordinator.testcases.CoordinatingTestCase2BasicP2P; import org.apache.qpid.interop.testclient.InteropClientTestCase; import org.apache.qpid.interop.testclient.TestClient; +import org.apache.qpid.interop.testclient.testcases.TestCase1DummyRun; +import org.apache.qpid.interop.testclient.testcases.TestCase2BasicP2P; import org.apache.qpid.util.ClasspathScanner; import org.apache.qpid.util.CommandLineParser; import org.apache.qpid.util.ConversationHelper; @@ -69,6 +72,10 @@ public class Coordinator extends TestRunnerImprovedErrorHandling /** Holds the list of all clients that enlisted, when the compulsory invite was issued. */ Set enlistedClients = new HashSet(); + /** Holds the conversation helper for the control conversation. */ + private ConversationHelper conversation; + private Connection connection; + /** * Creates an interop test coordinator on the specified broker and virtual host. * @@ -99,39 +106,34 @@ public class Coordinator extends TestRunnerImprovedErrorHandling { try { - // Use the command line parser to evaluate the command line. - CommandLineParser commandLine = - new CommandLineParser(new String[][] - { - { "b", "The broker URL.", "broker", "false" }, - { "h", "The virtual host to use.", "virtual host", "false" } - }); - - // Capture the command line arguments or display errors and correct usage and then exit. - Properties options = null; - - try - { - options = commandLine.parseCommandLine(args); - } - catch (IllegalArgumentException e) - { - System.out.println(commandLine.getErrors()); - System.out.println(commandLine.getUsage()); - System.exit(1); - } + // Use the command line parser to evaluate the command line with standard handling behaviour (print errors + // and usage then exist if there are errors). + Properties options = + CommandLineParser.processCommandLine(args, + new CommandLineParser( + new String[][] + { + { "b", "The broker URL.", "broker", "false" }, + { "h", "The virtual host to use.", "virtual host", "false" } + })); // Extract the command line options. String brokerUrl = options.getProperty("b"); String virtualHost = options.getProperty("h"); - // Add all the trailing command line options (name=value pairs) to system properties. Tests may pick up - // overridden values from there. - commandLine.addCommandLineToSysProperties(); - // Scan for available test cases using a classpath scanner. Collection> testCaseClasses = - ClasspathScanner.getMatches(CoordinatingTestCase.class, "^Test.*", true); + new ArrayList>(); + // ClasspathScanner.getMatches(CoordinatingTestCase.class, "^Test.*", true); + // Hard code the test classes till the classpath scanner is fixed. + Collections.addAll(testCaseClasses, new Class[] { CoordinatingTestCase2BasicP2P.class }); + + // Check that some test classes were actually found. + if ((testCaseClasses == null) || testCaseClasses.isEmpty()) + { + throw new RuntimeException( + "No test classes implementing CoordinatingTestCase were found on the class path."); + } int i = 0; String[] testClassNames = new String[testCaseClasses.size()]; @@ -174,17 +176,16 @@ public class Coordinator extends TestRunnerImprovedErrorHandling public TestResult start(String[] testClassNames) throws Exception { log.debug("public TestResult start(String[] testClassNames = " + PrettyPrintingUtils.printArray(testClassNames) - + "): called"); + + "): called"); // Connect to the broker. - Connection connection = TestClient.createConnection(DEFAULT_CONNECTION_PROPS_RESOURCE, brokerUrl, virtualHost); + connection = TestClient.createConnection(DEFAULT_CONNECTION_PROPS_RESOURCE, brokerUrl, virtualHost); Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); Destination controlTopic = session.createTopic("iop.control"); Destination responseQueue = session.createQueue("coordinator"); - ConversationHelper conversation = - new ConversationHelper(connection, controlTopic, responseQueue, LinkedBlockingQueue.class); + conversation = new ConversationHelper(connection, controlTopic, responseQueue, LinkedBlockingQueue.class); // Broadcast the compulsory invitation to find out what clients are available to test. Message invite = session.createMessage(); @@ -222,7 +223,7 @@ public class Coordinator extends TestRunnerImprovedErrorHandling public static Set extractEnlists(Collection enlists) throws JMSException { log.debug("public static Set extractEnlists(Collection enlists = " + enlists - + "): called"); + + "): called"); Set enlistedClients = new HashSet(); @@ -282,7 +283,7 @@ public class Coordinator extends TestRunnerImprovedErrorHandling } // Wrap the tests in an inviting test decorator, to perform the invite/test cycle. - targetTest = new InvitingTestDecorator(targetTest, enlistedClients); + targetTest = new InvitingTestDecorator(targetTest, enlistedClients, conversation); return super.doRun(targetTest, wait); } diff --git a/java/integrationtests/src/main/java/org/apache/qpid/interop/coordinator/InvitingTestDecorator.java b/java/integrationtests/src/main/java/org/apache/qpid/interop/coordinator/InvitingTestDecorator.java index 64770be654..2975082631 100644 --- a/java/integrationtests/src/main/java/org/apache/qpid/interop/coordinator/InvitingTestDecorator.java +++ b/java/integrationtests/src/main/java/org/apache/qpid/interop/coordinator/InvitingTestDecorator.java @@ -21,6 +21,7 @@ package org.apache.qpid.interop.coordinator; import java.util.*; +import java.util.concurrent.LinkedBlockingQueue; import javax.jms.JMSException; import javax.jms.Message; @@ -47,34 +48,33 @@ public class InvitingTestDecorator extends WrappedSuiteTestDecorator { private static final Logger log = Logger.getLogger(InvitingTestDecorator.class); + /** Holds the contact information for all test clients that are available and that may take part in the test. */ Set allClients; + + /** Holds the conversation helper for the control level conversation for coordinating the test through. */ ConversationHelper conversation; + /** Holds the underlying {@link CoordinatingTestCase}s that this decorator wraps. */ WrappedSuiteTestDecorator testSuite; - /** - * Creates a wrappred suite test decorator from a test suite. - * - * @param suite The test suite. - * @param allClients The list of all clients that responded to the compulsory invite. - */ - /*public InvitingTestDecorator(TestSuite suite, Collection allClients, ConversationHelper conversation) - { - super(suite); - }*/ - /** * Creates a wrapped suite test decorator from another one. * - * @param suite The test suite. - * @param allClients The list of all clients that responded to the compulsory invite. + * @param suite The test suite. + * @param availableClients The list of all clients that responded to the compulsory invite. + * @param controlConversation The conversation helper for the control level, test coordination conversation. */ - public InvitingTestDecorator(WrappedSuiteTestDecorator suite, Set allClients) + public InvitingTestDecorator(WrappedSuiteTestDecorator suite, Set availableClients, + ConversationHelper controlConversation) { super(suite); log.debug("public InvitingTestDecorator(WrappedSuiteTestDecorator suite, Set allClients = " - + allClients + "): called"); + + availableClients + ", ConversationHelper controlConversation = " + controlConversation + "): called"); + + testSuite = suite; + allClients = availableClients; + conversation = controlConversation; } /** @@ -127,7 +127,7 @@ public class InvitingTestDecorator extends WrappedSuiteTestDecorator for (List failPair : failPairs) { - CoordinatingTestCase failTest = new OptOutTestCase(""); + CoordinatingTestCase failTest = new OptOutTestCase("testOptOut"); failTest.setSender(failPair.get(0)); failTest.setReceiver(failPair.get(1)); diff --git a/java/integrationtests/src/main/java/org/apache/qpid/interop/coordinator/testcases/CoordinatingTestCase2BasicP2P.java b/java/integrationtests/src/main/java/org/apache/qpid/interop/coordinator/testcases/CoordinatingTestCase2BasicP2P.java new file mode 100644 index 0000000000..4fb9729c4a --- /dev/null +++ b/java/integrationtests/src/main/java/org/apache/qpid/interop/coordinator/testcases/CoordinatingTestCase2BasicP2P.java @@ -0,0 +1,48 @@ +package org.apache.qpid.interop.coordinator.testcases; + +import java.util.Properties; + +import javax.jms.Message; + +import junit.framework.Assert; + +import org.apache.qpid.interop.coordinator.CoordinatingTestCase; + +/** + *

+ *
CRC Card
Responsibilities Collaborations + *
Setup p2p test parameters and compare with test output. {@link CoordinatingTestCase} + *
+ */ +public class CoordinatingTestCase2BasicP2P extends CoordinatingTestCase +{ + /** + * Creates a new coordinating test case with the specified name. + * + * @param name The test case name. + */ + public CoordinatingTestCase2BasicP2P(String name) + { + super(name); + } + + /** + * Performs the basic P2P test case, "Test Case 2" in the specification. + */ + public void testBasicP2P() throws Exception + { + Properties testConfig = new Properties(); + testConfig.setProperty("TEST_CASE", "TC2_BasicP2P"); + testConfig.setProperty("P2P_QUEUE_AND_KEY_NAME", "tc2queue"); + testConfig.setProperty("P2P_NUM_MESSAGES", "50"); + + 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.", 50, messagesSent); + Assert.assertEquals("Sender and receiver messages sent did not match up.", messagesSent, messagesReceived); + } +} diff --git a/java/integrationtests/src/main/java/org/apache/qpid/util/ConversationHelper.java b/java/integrationtests/src/main/java/org/apache/qpid/util/ConversationHelper.java index 9b0bc07ba9..1fd1fee377 100644 --- a/java/integrationtests/src/main/java/org/apache/qpid/util/ConversationHelper.java +++ b/java/integrationtests/src/main/java/org/apache/qpid/util/ConversationHelper.java @@ -31,19 +31,16 @@ import javax.jms.*; * A conversation helper, uses a message correlation id pattern to match up sent and received messages as a conversation * over JMS messaging. Incoming message traffic is divided up by correlation id. Each id has a queue (behaviour dependant * on the queue implementation). Clients of this de-multiplexer can wait on messages, defined by message correlation ids. - * The correlating listener is a message listener, and can therefore be attached to a MessageConsumer which is consuming - * from a queue or topic. * - *

One use of the correlating listener is to act as a conversation synchronizer where multiple threads are carrying - * out conversations over a multiplexed messaging route. This can be usefull, as JMS sessions are not multi-threaded. - * Setting up the correlating listener with synchronous queues will allow these threads to be written in a synchronous - * style, but with their execution order governed by the asynchronous message flow. For example, something like the - * following code could run a multi-threaded conversation (the conversation methods can be called many times in - * parallel): + *

One use of this is as a conversation synchronizer where multiple threads are carrying out conversations over a + * multiplexed messaging route. This can be usefull, as JMS sessions are not multi-threaded. Setting up the conversation + * with synchronous queues will allow these threads to be written in a synchronous style, but with their execution order + * governed by the asynchronous message flow. For example, something like the following code could run a multi-threaded + * conversation (the conversation methods can be called many times in parallel): * *

- * MessageListener conversation = new ConversationHelper(java.util.concurrent.LinkedBlockingQueue.class),
- *                                                       sendDesitination, replyDestination);
+ * ConversationHelper conversation = new ConversationHelper(connection, sendDesitination, replyDestination,
+ *                                                          java.util.concurrent.LinkedBlockingQueue.class);
  *
  * initiateConversation()
  * {
@@ -79,9 +76,9 @@ import javax.jms.*;
  *
  * 

*
CRC Card
Responsibilities Collaborations - *
Associate messages to a conversation using correlation ids. + *
Associate messages to an ongoing conversation using correlation ids. *
Auto manage sessions for conversations. - *
Store messages not in conversation in dead letter box. + *
Store messages not in a conversation in dead letter box. *
* * @todo Non-transactional, can use shared session. Transactional, must have session per-thread. Session pool? In @@ -91,9 +88,9 @@ import javax.jms.*; * to restrict receives on that session to prevent it picking up messages bound for other conversations. Or use * a temporary response queue, with only that session listening to it. * - * @todo Want something convenient that hides many details. Write out some example use cases to get the best feel for + * @todo Want something convenient that hides details. Write out some example use cases to get the best feel for * it. Pass in connection, send destination, receive destination. Provide endConvo, send, receive - * methods. Bind corrId, session etc. on thread locals. Clean on endConvo. Provide deadLetter box, that + * methods. Bind corrId, session etc. on thread locals? Clean on endConvo. Provide deadLetter box, that * uncorrelated or late messages go in. Provide time-out on wait methods, and global time-out. * PingPongProducer provides a good use-case example (sends messages, waits for replies). * @@ -139,7 +136,7 @@ public class ConversationHelper * @throws JMSException All undelying JMSExceptions are allowed to fall through. */ public ConversationHelper(Connection connection, Destination sendDestination, Destination receiveDestination, - Class queueClass) throws JMSException + Class queueClass) throws JMSException { session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); producer = session.createProducer(sendDestination); -- cgit v1.2.1