From 43f0dea566c81bb72aea75b825bbd97ec5d1d950 Mon Sep 17 00:00:00 2001 From: Aidan Skinner Date: Thu, 3 Dec 2009 23:55:48 +0000 Subject: Fix eol style property git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk/qpid@886998 13f79535-47bb-0310-9956-ffa450edef68 --- .../Properties/AssemblyInfo.cs | 106 +- .../Qpid.Integration.Tests/framework/Assertion.cs | 76 +- dotnet/Qpid.Integration.Tests/framework/Circuit.cs | 202 +-- .../framework/FrameworkBaseCase.cs | 562 ++++----- .../Qpid.Integration.Tests/framework/Publisher.cs | 128 +- .../Qpid.Integration.Tests/framework/Receiver.cs | 158 +-- .../framework/TestClientDetails.cs | 168 +-- .../Qpid.Integration.Tests/framework/TestModel.cs | 1312 ++++++++++---------- .../framework/sequencers/CircuitFactory.cs | 168 +-- .../interactive/FailoverTest.cs | 4 +- .../interactive/SendReceiveTest.cs | 360 +++--- .../interop/InteropClientTestCase.cs | 174 +-- .../interop/TestCases/TestCase1DummyRun.cs | 178 +-- .../interop/TestCases/TestCase2BasicP2P.cs | 410 +++--- .../interop/TestCases/TestCase3BasicPubSub.cs | 488 ++++---- .../Qpid.Integration.Tests/interop/TestClient.cs | 758 +++++------ .../testcases/BaseMessagingTestFixture.cs | 522 ++++---- .../testcases/ChannelQueueTest.cs | 474 +++---- .../testcases/CommitRollbackTest.cs | 522 ++++---- .../testcases/ConnectionTest.cs | 146 +-- .../testcases/DurableSubscriptionTest.cs | 332 ++--- .../testcases/HeadersExchangeTest.cs | 564 ++++----- .../testcases/MandatoryMessageTest.cs | 298 ++--- .../testcases/ProducerMultiConsumerTest.cs | 334 ++--- .../testcases/SslConnectionTest.cs | 128 +- .../testcases/SustainedTest.cs | 218 ++-- 26 files changed, 4395 insertions(+), 4395 deletions(-) (limited to 'dotnet/Qpid.Integration.Tests') diff --git a/dotnet/Qpid.Integration.Tests/Properties/AssemblyInfo.cs b/dotnet/Qpid.Integration.Tests/Properties/AssemblyInfo.cs index 895688e29e..e19650559f 100644 --- a/dotnet/Qpid.Integration.Tests/Properties/AssemblyInfo.cs +++ b/dotnet/Qpid.Integration.Tests/Properties/AssemblyInfo.cs @@ -1,53 +1,53 @@ -/* - * - * 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. - * - */ -using System.Reflection; -using System.Runtime.InteropServices; -using log4net.Config; -[assembly: XmlConfigurator(ConfigFile="log4net.config")] - -// General Information about an assembly is controlled through the following -// set of attributes. Change these attribute values to modify the information -// associated with an assembly. -[assembly: AssemblyTitle("Apache.Qpid.Integration.Tests")] -[assembly: AssemblyDescription("Built from svn revision number: ")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("Apache Software Foundation")] -[assembly: AssemblyProduct("Apache.Qpid.Integration.Tests")] -[assembly: AssemblyCopyright("Apache Software Foundation")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] - -// Setting ComVisible to false makes the types in this assembly not visible -// to COM components. If you need to access a type in this assembly from -// COM, set the ComVisible attribute to true on that type. -[assembly: ComVisible(false)] - -// The following GUID is for the ID of the typelib if this project is exposed to COM -[assembly: Guid("7ebdea21-1352-4673-b66e-fdc0beff461f")] - -// Version information for an assembly consists of the following four values: -// -// Major Version -// Minor Version -// Build Number -// Revision -// -[assembly: AssemblyVersion("0.5.0.0")] +/* + * + * 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. + * + */ +using System.Reflection; +using System.Runtime.InteropServices; +using log4net.Config; +[assembly: XmlConfigurator(ConfigFile="log4net.config")] + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("Apache.Qpid.Integration.Tests")] +[assembly: AssemblyDescription("Built from svn revision number: ")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("Apache Software Foundation")] +[assembly: AssemblyProduct("Apache.Qpid.Integration.Tests")] +[assembly: AssemblyCopyright("Apache Software Foundation")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("7ebdea21-1352-4673-b66e-fdc0beff461f")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +[assembly: AssemblyVersion("0.5.0.0")] diff --git a/dotnet/Qpid.Integration.Tests/framework/Assertion.cs b/dotnet/Qpid.Integration.Tests/framework/Assertion.cs index fba8253251..de12de6522 100644 --- a/dotnet/Qpid.Integration.Tests/framework/Assertion.cs +++ b/dotnet/Qpid.Integration.Tests/framework/Assertion.cs @@ -1,39 +1,39 @@ -/* - * - * 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. - * - */ -namespace Apache.Qpid.Integration.Tests.framework -{ - /// - /// Assertion models an assertion on a test . - /// - ///

- ///
CRC Card
Responsibilities - ///
Indicate whether or not the assertion passes when applied. - ///
- ///

- public interface Assertion - { - /// - /// Applies the assertion. - /// - /// true if the assertion passes, false if it fails. - bool apply(); - } +/* + * + * 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. + * + */ +namespace Apache.Qpid.Integration.Tests.framework +{ + /// + /// Assertion models an assertion on a test . + /// + ///

+ ///
CRC Card
Responsibilities + ///
Indicate whether or not the assertion passes when applied. + ///
+ ///

+ public interface Assertion + { + /// + /// Applies the assertion. + /// + /// true if the assertion passes, false if it fails. + bool apply(); + } } \ No newline at end of file diff --git a/dotnet/Qpid.Integration.Tests/framework/Circuit.cs b/dotnet/Qpid.Integration.Tests/framework/Circuit.cs index d5f0ed15e2..aae9ca0496 100644 --- a/dotnet/Qpid.Integration.Tests/framework/Circuit.cs +++ b/dotnet/Qpid.Integration.Tests/framework/Circuit.cs @@ -1,102 +1,102 @@ -/* - * - * 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. - * - */ -using System.Collections.Generic;//.IList; - -namespace Apache.Qpid.Integration.Tests.framework -{ - /// - /// A Circuit is the basic test unit against which test cases are to be written. A circuit consists of two 'ends', an - /// instigating 'publisher' end and a more passive 'receivers' end. - /// - ///

Once created, the life-cycle of a circuit may be controlled by ing it, or ing it. - /// Once started, the circuit is ready to send messages over. Once closed the circuit can no longer be used. - /// - ///

The state of the circuit may be taken with the method, and asserted against by the - /// method. - /// - ///

There is a default test procedure which may be performed against the circuit. The outline of this procedure is: - /// - ///

-    /// Start the circuit.
-    /// Send test messages.
-    /// Request a status report.
-    /// Assert conditions on the publishing end of the circuit.
-    /// Assert conditions on the receiving end of the circuit.
-    /// Close the circuit.
-    /// Pass with no failed assertions or fail with a list of failed assertions.
-    /// 
- /// - ///

- ///
CRC Card
Responsibilities - ///
Supply the publishing and receiving ends of a test messaging circuit. - ///
Start the circuit running. - ///
Close the circuit down. - ///
Take a reading of the circuits state. - ///
Apply assertions against the circuits state. - ///
Send test messages over the circuit. - ///
Perform the default test procedue on the circuit. - ///
- ///

- public interface Circuit - { - /// Gets the interface on the publishing end of the circuit. - /// - /// The publishing end of the circuit. - Publisher GetPublisher(); - - /// Gets the interface on the receiving end of the circuit. - /// - /// The receiving end of the circuit. - Receiver GetReceiver(); - - /// Connects and starts the circuit. After this method is called the circuit is ready to send messages. - void Start(); - - /// - /// Checks the test circuit. The effect of this is to gather the circuits state, for both ends of the circuit, - /// into a report, against which assertions may be checked. - /// - void Check(); - - /// Closes the circuit. All associated resources are closed. - void Close(); - - /// - /// Applied a list of assertions against the test circuit. The method should be called before doing - /// this, to ensure that the circuit has gathered its state into a report to assert against. - /// - /// - /// The list of assertions to apply to the circuit. - /// - /// Any assertions that failed. - IList ApplyAssertions(IList assertions); - - /// - /// Runs the default test procedure against the circuit, and checks that all of the specified assertions hold. - /// - /// - /// The number of messages to send using the default test procedure. - /// The list of assertions to apply. - /// - /// Any assertions that failed. - IList Test(int numMessages, IList assertions); - } +/* + * + * 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. + * + */ +using System.Collections.Generic;//.IList; + +namespace Apache.Qpid.Integration.Tests.framework +{ + /// + /// A Circuit is the basic test unit against which test cases are to be written. A circuit consists of two 'ends', an + /// instigating 'publisher' end and a more passive 'receivers' end. + /// + ///

Once created, the life-cycle of a circuit may be controlled by ing it, or ing it. + /// Once started, the circuit is ready to send messages over. Once closed the circuit can no longer be used. + /// + ///

The state of the circuit may be taken with the method, and asserted against by the + /// method. + /// + ///

There is a default test procedure which may be performed against the circuit. The outline of this procedure is: + /// + ///

+    /// Start the circuit.
+    /// Send test messages.
+    /// Request a status report.
+    /// Assert conditions on the publishing end of the circuit.
+    /// Assert conditions on the receiving end of the circuit.
+    /// Close the circuit.
+    /// Pass with no failed assertions or fail with a list of failed assertions.
+    /// 
+ /// + ///

+ ///
CRC Card
Responsibilities + ///
Supply the publishing and receiving ends of a test messaging circuit. + ///
Start the circuit running. + ///
Close the circuit down. + ///
Take a reading of the circuits state. + ///
Apply assertions against the circuits state. + ///
Send test messages over the circuit. + ///
Perform the default test procedue on the circuit. + ///
+ ///

+ public interface Circuit + { + /// Gets the interface on the publishing end of the circuit. + /// + /// The publishing end of the circuit. + Publisher GetPublisher(); + + /// Gets the interface on the receiving end of the circuit. + /// + /// The receiving end of the circuit. + Receiver GetReceiver(); + + /// Connects and starts the circuit. After this method is called the circuit is ready to send messages. + void Start(); + + /// + /// Checks the test circuit. The effect of this is to gather the circuits state, for both ends of the circuit, + /// into a report, against which assertions may be checked. + /// + void Check(); + + /// Closes the circuit. All associated resources are closed. + void Close(); + + /// + /// Applied a list of assertions against the test circuit. The method should be called before doing + /// this, to ensure that the circuit has gathered its state into a report to assert against. + /// + /// + /// The list of assertions to apply to the circuit. + /// + /// Any assertions that failed. + IList ApplyAssertions(IList assertions); + + /// + /// Runs the default test procedure against the circuit, and checks that all of the specified assertions hold. + /// + /// + /// The number of messages to send using the default test procedure. + /// The list of assertions to apply. + /// + /// Any assertions that failed. + IList Test(int numMessages, IList assertions); + } } \ No newline at end of file diff --git a/dotnet/Qpid.Integration.Tests/framework/FrameworkBaseCase.cs b/dotnet/Qpid.Integration.Tests/framework/FrameworkBaseCase.cs index a7a663e531..77c1cae0ad 100644 --- a/dotnet/Qpid.Integration.Tests/framework/FrameworkBaseCase.cs +++ b/dotnet/Qpid.Integration.Tests/framework/FrameworkBaseCase.cs @@ -1,282 +1,282 @@ -/* - * - * 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. - * - */ -using log4net; -using NUnit.Framework; -//using org.apache.log4j.NDC; - -using Apache.Qpid.Integration.Tests.framework.sequencers;//.CircuitFactory; - -//using uk.co.thebadgerset.junit.extensions.AsymptoticTestCase; -//using uk.co.thebadgerset.junit.extensions.SetupTaskAware; -//using uk.co.thebadgerset.junit.extensions.SetupTaskHandler; -//using uk.co.thebadgerset.junit.extensions.util.ParsedProperties; -//using uk.co.thebadgerset.junit.extensions.util.TestContextProperties; - -//using java.util.ArrayList; -using System.Collections.Generic;//.IList; - -namespace Apache.Qpid.Integration.Tests.framework -{ - /// - /// FrameworkBaseCase provides a starting point for writing test cases against the test framework. Its main purpose is - /// to provide some convenience methods for testing. - /// - ///

- ///
CRC Card
Responsibilities Collaborations - ///
Create and clean up in-vm brokers on every test case. - ///
Produce lists of assertions from assertion creation calls. - ///
Produce JUnit failures from assertion failures. - ///
Convert failed assertions to error messages. - ///
- ///

- public class FrameworkBaseCase //extends AsymptoticTestCase : FrameworkTestContext, SetupTaskAware, BrokerLifecycleAware - { - /// Used for debugging purposes. - private static ILog log = LogManager.GetLogger(typeof(FrameworkBaseCase)); - - /// Holds the test sequencer to create and run test circuits with. - protected CircuitFactory circuitFactory;// = new LocalCircuitFactory(); - - /// Used to read the tests configurable properties through. - protected TestModel testProps; - - /// A default setup task processor to delegate setup tasks to. - //protected SetupTaskHandler taskHandler = new SetupTaskHandler(); - - /// Flag used to track whether the test is in-vm or not. - //protected bool isUsingInVM; - - /// Holds the failure mechanism. - //protected CauseFailure failureMechanism = new CauseFailureUserPrompt(); - - /* - /// - /// Creates a new test case with the specified name. - /// - /// The test case name. - public FrameworkBaseCase(string name) : base(name) - { - } - */ - - /// - /// Returns the test case sequencer that provides test circuit, and test sequence implementations. The sequencer - /// that this base case returns by default is suitable for running a test circuit with both circuit ends colocated - /// on the same JVM. - /// - /// The test case sequencer. - protected CircuitFactory GetCircuitFactory() - { - return circuitFactory; - } - - /// - /// Overrides the default test circuit factory. Test decorators can use this to supply distributed test sequencers or - /// other test circuit factory specializations. - /// - /// The new test circuit factory. - public void SetCircuitFactory(CircuitFactory circuitFactory) - { - this.circuitFactory = circuitFactory; - } - - /* - /// - /// Reports the current test case name. - /// - /// The current test case name. - public TestCaseVector GetTestCaseVector() - { - return new TestCaseVector(this.getName(), 0); - } - */ - - /// - /// Reports the current test case parameters. - /// - /// The current test case parameters. - public TestModel getTestParameters() - { - return testProps; - } - - /// - /// Creates a list of assertions. - /// - /// The assertions to compile in a list. - /// - /// A list of assertions. - protected IList AssertionList(params Assertion[] asserts) - { - IList result = new List(); - - foreach (Assertion assertion in asserts) - { - result.Add(assertion); - } - - return result; - } - - /// - /// Generates a JUnit assertion exception (failure) if any assertions are passed into this method, also concatenating - /// all of the error messages in the assertions together to form an error message to diagnose the test failure with. - /// - /// The list of failed assertions. - protected static void AssertNoFailures(List asserts) - { - log.Debug("protected void assertNoFailures(List asserts = " + asserts + "): called"); - - // Check if there are no assertion failures, and return without doing anything if so. - if ((asserts == null) || (asserts.Count == 0)) - { - return; - } - - // Compile all of the assertion failure messages together. - string errorMessage = AssertionsToString(asserts); - - // Fail with the error message from all of the assertions. - Assert.Fail(errorMessage); - } - - /// - /// Converts a list of failed assertions into an error message. - /// - /// The failed assertions. - /// - /// The error message. - protected static string AssertionsToString(List asserts) - { - string errorMessage = ""; - - foreach (Assertion assertion in asserts) - { - errorMessage += assertion.ToString() + "\n"; - } - - return errorMessage; - } - - /// - /// Ensures that the in-vm broker is created and initialized. - /// - /// - /// Any exceptions allowed to fall through and fail the test. - [SetUp] - protected void SetUp() - { - //NDC.Push(Name); - - //testProps = TestContextProperties.getInstance(TestModel.defaults); - - // Process all optional setup tasks. This may include in-vm broker creation, if a decorator has added it. - //taskHandler.runSetupTasks(); - } - - /// Ensures that the in-vm broker is cleaned up after each test run. - [TearDown] - protected void TearDown() - { - //NDC.Pop(); - - // Process all optional tear down tasks. This may include in-vm broker clean up, if a decorator has added it. - //taskHandler.runTearDownTasks(); - } - - /* - /// - /// Adds the specified task to the tests setup. - /// - /// The task to add to the tests setup. - public void chainSetupTask(Runnable task) - { - taskHandler.chainSetupTask(task); - } - */ - - /* - /// - /// Adds the specified task to the tests tear down. - /// - /// The task to add to the tests tear down. - public void chainTearDownTask(Runnable task) - { - taskHandler.chainTearDownTask(task); - } - */ - - /* - /// - /// 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". - /// - /// The name of the JUnit test method. - /// - /// The name of the corresponding interop test case. - public string getTestCaseNameForTestMethod(string methodName) - { - return methodName; - } - - public void setInVmBrokers() - { - isUsingInVM = true; - } - - /// - /// Indicates whether or not a test case is using in-vm brokers. - /// - /// true if the test is using in-vm brokers, false otherwise. - public bool usingInVmBroker() - { - return isUsingInVM; - } - - /// - /// Sets the currently live in-vm broker. - /// - /// The currently live in-vm broker. - public void setLiveBroker(int i) - { } - - /// - /// Reports the currently live in-vm broker. - /// - /// The currently live in-vm broker. - public int getLiveBroker() - { - return 0; - } - - /// - /// Accepts a failure mechanism. - /// - /// The failure mechanism. - public void setFailureMechanism(CauseFailure failureMechanism) - { - this.failureMechanism = failureMechanism; - } - */ - } +/* + * + * 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. + * + */ +using log4net; +using NUnit.Framework; +//using org.apache.log4j.NDC; + +using Apache.Qpid.Integration.Tests.framework.sequencers;//.CircuitFactory; + +//using uk.co.thebadgerset.junit.extensions.AsymptoticTestCase; +//using uk.co.thebadgerset.junit.extensions.SetupTaskAware; +//using uk.co.thebadgerset.junit.extensions.SetupTaskHandler; +//using uk.co.thebadgerset.junit.extensions.util.ParsedProperties; +//using uk.co.thebadgerset.junit.extensions.util.TestContextProperties; + +//using java.util.ArrayList; +using System.Collections.Generic;//.IList; + +namespace Apache.Qpid.Integration.Tests.framework +{ + /// + /// FrameworkBaseCase provides a starting point for writing test cases against the test framework. Its main purpose is + /// to provide some convenience methods for testing. + /// + ///

+ ///
CRC Card
Responsibilities Collaborations + ///
Create and clean up in-vm brokers on every test case. + ///
Produce lists of assertions from assertion creation calls. + ///
Produce JUnit failures from assertion failures. + ///
Convert failed assertions to error messages. + ///
+ ///

+ public class FrameworkBaseCase //extends AsymptoticTestCase : FrameworkTestContext, SetupTaskAware, BrokerLifecycleAware + { + /// Used for debugging purposes. + private static ILog log = LogManager.GetLogger(typeof(FrameworkBaseCase)); + + /// Holds the test sequencer to create and run test circuits with. + protected CircuitFactory circuitFactory;// = new LocalCircuitFactory(); + + /// Used to read the tests configurable properties through. + protected TestModel testProps; + + /// A default setup task processor to delegate setup tasks to. + //protected SetupTaskHandler taskHandler = new SetupTaskHandler(); + + /// Flag used to track whether the test is in-vm or not. + //protected bool isUsingInVM; + + /// Holds the failure mechanism. + //protected CauseFailure failureMechanism = new CauseFailureUserPrompt(); + + /* + /// + /// Creates a new test case with the specified name. + /// + /// The test case name. + public FrameworkBaseCase(string name) : base(name) + { + } + */ + + /// + /// Returns the test case sequencer that provides test circuit, and test sequence implementations. The sequencer + /// that this base case returns by default is suitable for running a test circuit with both circuit ends colocated + /// on the same JVM. + /// + /// The test case sequencer. + protected CircuitFactory GetCircuitFactory() + { + return circuitFactory; + } + + /// + /// Overrides the default test circuit factory. Test decorators can use this to supply distributed test sequencers or + /// other test circuit factory specializations. + /// + /// The new test circuit factory. + public void SetCircuitFactory(CircuitFactory circuitFactory) + { + this.circuitFactory = circuitFactory; + } + + /* + /// + /// Reports the current test case name. + /// + /// The current test case name. + public TestCaseVector GetTestCaseVector() + { + return new TestCaseVector(this.getName(), 0); + } + */ + + /// + /// Reports the current test case parameters. + /// + /// The current test case parameters. + public TestModel getTestParameters() + { + return testProps; + } + + /// + /// Creates a list of assertions. + /// + /// The assertions to compile in a list. + /// + /// A list of assertions. + protected IList AssertionList(params Assertion[] asserts) + { + IList result = new List(); + + foreach (Assertion assertion in asserts) + { + result.Add(assertion); + } + + return result; + } + + /// + /// Generates a JUnit assertion exception (failure) if any assertions are passed into this method, also concatenating + /// all of the error messages in the assertions together to form an error message to diagnose the test failure with. + /// + /// The list of failed assertions. + protected static void AssertNoFailures(List asserts) + { + log.Debug("protected void assertNoFailures(List asserts = " + asserts + "): called"); + + // Check if there are no assertion failures, and return without doing anything if so. + if ((asserts == null) || (asserts.Count == 0)) + { + return; + } + + // Compile all of the assertion failure messages together. + string errorMessage = AssertionsToString(asserts); + + // Fail with the error message from all of the assertions. + Assert.Fail(errorMessage); + } + + /// + /// Converts a list of failed assertions into an error message. + /// + /// The failed assertions. + /// + /// The error message. + protected static string AssertionsToString(List asserts) + { + string errorMessage = ""; + + foreach (Assertion assertion in asserts) + { + errorMessage += assertion.ToString() + "\n"; + } + + return errorMessage; + } + + /// + /// Ensures that the in-vm broker is created and initialized. + /// + /// + /// Any exceptions allowed to fall through and fail the test. + [SetUp] + protected void SetUp() + { + //NDC.Push(Name); + + //testProps = TestContextProperties.getInstance(TestModel.defaults); + + // Process all optional setup tasks. This may include in-vm broker creation, if a decorator has added it. + //taskHandler.runSetupTasks(); + } + + /// Ensures that the in-vm broker is cleaned up after each test run. + [TearDown] + protected void TearDown() + { + //NDC.Pop(); + + // Process all optional tear down tasks. This may include in-vm broker clean up, if a decorator has added it. + //taskHandler.runTearDownTasks(); + } + + /* + /// + /// Adds the specified task to the tests setup. + /// + /// The task to add to the tests setup. + public void chainSetupTask(Runnable task) + { + taskHandler.chainSetupTask(task); + } + */ + + /* + /// + /// Adds the specified task to the tests tear down. + /// + /// The task to add to the tests tear down. + public void chainTearDownTask(Runnable task) + { + taskHandler.chainTearDownTask(task); + } + */ + + /* + /// + /// 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". + /// + /// The name of the JUnit test method. + /// + /// The name of the corresponding interop test case. + public string getTestCaseNameForTestMethod(string methodName) + { + return methodName; + } + + public void setInVmBrokers() + { + isUsingInVM = true; + } + + /// + /// Indicates whether or not a test case is using in-vm brokers. + /// + /// true if the test is using in-vm brokers, false otherwise. + public bool usingInVmBroker() + { + return isUsingInVM; + } + + /// + /// Sets the currently live in-vm broker. + /// + /// The currently live in-vm broker. + public void setLiveBroker(int i) + { } + + /// + /// Reports the currently live in-vm broker. + /// + /// The currently live in-vm broker. + public int getLiveBroker() + { + return 0; + } + + /// + /// Accepts a failure mechanism. + /// + /// The failure mechanism. + public void setFailureMechanism(CauseFailure failureMechanism) + { + this.failureMechanism = failureMechanism; + } + */ + } } \ No newline at end of file diff --git a/dotnet/Qpid.Integration.Tests/framework/Publisher.cs b/dotnet/Qpid.Integration.Tests/framework/Publisher.cs index 72bd079277..5fbdc7a907 100644 --- a/dotnet/Qpid.Integration.Tests/framework/Publisher.cs +++ b/dotnet/Qpid.Integration.Tests/framework/Publisher.cs @@ -1,65 +1,65 @@ -/* - * - * 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. - * - */ -//using uk.co.thebadgerset.junit.extensions.util.ParsedProperties; -using System; - -namespace Apache.Qpid.Integration.Tests.framework -{ - /// - /// A Publisher represents the status of the publishing side of a test circuit. Its main purpose is to provide assertions - /// that can be applied to test the behaviour of the publishers. - /// - ///

- ///
CRC Card
Responsibilities - ///
Provide assertion that the publishers received no exceptions. - ///
- ///

- public interface Publisher - { - /// - /// Provides an assertion that the publisher encountered no exceptions. - /// - /// - /// The test configuration properties. - /// - /// An assertion that the publisher encountered no exceptions. - Assertion NoExceptionsAssertion(TestModel testProps); - - /// - /// Provides an assertion that the AMQP channel was forcibly closed by an error condition. - /// - /// - /// The test configuration properties. - /// - /// An assertion that the AMQP channel was forcibly closed by an error condition. - Assertion ChannelClosedAssertion(TestModel testProps); - - /// - /// Provides an assertion that the publisher got a given exception during the test. - /// - /// - /// The test configuration properties. - /// The exception class to check for. - /// - /// An assertion that the publisher got a given exception during the test. - Assertion ExceptionAssertion(TestModel testProps, Type exceptionClass); - } +/* + * + * 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. + * + */ +//using uk.co.thebadgerset.junit.extensions.util.ParsedProperties; +using System; + +namespace Apache.Qpid.Integration.Tests.framework +{ + /// + /// A Publisher represents the status of the publishing side of a test circuit. Its main purpose is to provide assertions + /// that can be applied to test the behaviour of the publishers. + /// + ///

+ ///
CRC Card
Responsibilities + ///
Provide assertion that the publishers received no exceptions. + ///
+ ///

+ public interface Publisher + { + /// + /// Provides an assertion that the publisher encountered no exceptions. + /// + /// + /// The test configuration properties. + /// + /// An assertion that the publisher encountered no exceptions. + Assertion NoExceptionsAssertion(TestModel testProps); + + /// + /// Provides an assertion that the AMQP channel was forcibly closed by an error condition. + /// + /// + /// The test configuration properties. + /// + /// An assertion that the AMQP channel was forcibly closed by an error condition. + Assertion ChannelClosedAssertion(TestModel testProps); + + /// + /// Provides an assertion that the publisher got a given exception during the test. + /// + /// + /// The test configuration properties. + /// The exception class to check for. + /// + /// An assertion that the publisher got a given exception during the test. + Assertion ExceptionAssertion(TestModel testProps, Type exceptionClass); + } } \ No newline at end of file diff --git a/dotnet/Qpid.Integration.Tests/framework/Receiver.cs b/dotnet/Qpid.Integration.Tests/framework/Receiver.cs index 80320c68b6..96820b5980 100644 --- a/dotnet/Qpid.Integration.Tests/framework/Receiver.cs +++ b/dotnet/Qpid.Integration.Tests/framework/Receiver.cs @@ -1,80 +1,80 @@ -/* - * - * 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. - * - */ -//using uk.co.thebadgerset.junit.extensions.util.ParsedProperties; -using System; - -namespace Apache.Qpid.Integration.Tests.framework -{ - /// - /// A Receiver is a that represents the status of the receiving side of a test circuit. Its main - /// purpose is to provide assertions that can be applied to check the behaviour of the receivers. - /// - ///

- ///
CRC Card
Responsibilities - ///
Provide assertion that the receivers received no exceptions. - ///
Provide assertion that the receivers received all test messages sent to it. - ///
- ///

- public interface Receiver - { - /// - /// Provides an assertion that the receivers encountered no exceptions. - /// - /// - /// The test configuration properties. - /// - /// An assertion that the receivers encountered no exceptions. - Assertion NoExceptionsAssertion(TestModel testProps); - - /// - /// Provides an assertion that the receivers got all messages that were sent to it. - /// - /// The test configuration properties. - /// - /// An assertion that the receivers got all messages that were sent to it. - Assertion AllMessagesReceivedAssertion(TestModel testProps); - - /// - /// Provides an assertion that the receivers got none of the messages that were sent to it. - /// - /// The test configuration properties. - /// - /// An assertion that the receivers got none of the messages that were sent to it. - Assertion NoMessagesReceivedAssertion(TestModel testProps); - - /// - /// Provides an assertion that the AMQP channel was forcibly closed by an error condition. - /// - /// The test configuration properties. - /// - /// An assertion that the AMQP channel was forcibly closed by an error condition. - Assertion ChannelClosedAssertion(TestModel testProps); - - /// - /// Provides an assertion that the receiver got a given exception during the test. - /// - /// The test configuration properties. - /// The exception class to check for. - /// - /// An assertion that the receiver got a given exception during the test. - Assertion ExceptionAssertion(TestModel testProps, Type exceptionClass); - } +/* + * + * 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. + * + */ +//using uk.co.thebadgerset.junit.extensions.util.ParsedProperties; +using System; + +namespace Apache.Qpid.Integration.Tests.framework +{ + /// + /// A Receiver is a that represents the status of the receiving side of a test circuit. Its main + /// purpose is to provide assertions that can be applied to check the behaviour of the receivers. + /// + ///

+ ///
CRC Card
Responsibilities + ///
Provide assertion that the receivers received no exceptions. + ///
Provide assertion that the receivers received all test messages sent to it. + ///
+ ///

+ public interface Receiver + { + /// + /// Provides an assertion that the receivers encountered no exceptions. + /// + /// + /// The test configuration properties. + /// + /// An assertion that the receivers encountered no exceptions. + Assertion NoExceptionsAssertion(TestModel testProps); + + /// + /// Provides an assertion that the receivers got all messages that were sent to it. + /// + /// The test configuration properties. + /// + /// An assertion that the receivers got all messages that were sent to it. + Assertion AllMessagesReceivedAssertion(TestModel testProps); + + /// + /// Provides an assertion that the receivers got none of the messages that were sent to it. + /// + /// The test configuration properties. + /// + /// An assertion that the receivers got none of the messages that were sent to it. + Assertion NoMessagesReceivedAssertion(TestModel testProps); + + /// + /// Provides an assertion that the AMQP channel was forcibly closed by an error condition. + /// + /// The test configuration properties. + /// + /// An assertion that the AMQP channel was forcibly closed by an error condition. + Assertion ChannelClosedAssertion(TestModel testProps); + + /// + /// Provides an assertion that the receiver got a given exception during the test. + /// + /// The test configuration properties. + /// The exception class to check for. + /// + /// An assertion that the receiver got a given exception during the test. + Assertion ExceptionAssertion(TestModel testProps, Type exceptionClass); + } } \ No newline at end of file diff --git a/dotnet/Qpid.Integration.Tests/framework/TestClientDetails.cs b/dotnet/Qpid.Integration.Tests/framework/TestClientDetails.cs index 401e183fd0..8be8de3d96 100644 --- a/dotnet/Qpid.Integration.Tests/framework/TestClientDetails.cs +++ b/dotnet/Qpid.Integration.Tests/framework/TestClientDetails.cs @@ -1,84 +1,84 @@ -/* - * - * 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. - * - */ -using System; - -namespace Apache.Qpid.Integration.Tests.framework -{ - /// - /// TestClientDetails is used to encapsulate information about an interop test client. It pairs together the unique - /// name of the client, and the route on which it listens to its control messages. - /// - ///

- ///
CRC Card
Responsibilities Collaborations - ///
Record test clients control addresses together with their names. - ///
- ///

- public class TestClientDetails - { - /// The test clients name. - public string clientName; - - /// The routing key of the test clients control topic. - public string privateControlKey; - - /// - /// Two TestClientDetails are considered to be equal, iff they have the same client name. - /// - /// The object to compare to. - /// - /// If the object to compare to is a TestClientDetails equal to this one, false otherwise. - public override bool Equals(Object o) - { - if (this == o) - { - return true; - } - - if (!(o is TestClientDetails)) - { - return false; - } - - TestClientDetails testClientDetails = (TestClientDetails) o; - - return !((clientName != null) ? (!clientName.Equals(testClientDetails.clientName)) - : (testClientDetails.clientName != null)); - } - - /// - /// Computes a hash code compatible with the equals method; based on the client name alone. - /// - /// A hash code for this. - public override int GetHashCode() - { - return ((clientName != null) ? clientName.GetHashCode() : 0); - } - - /// - /// Outputs the client name and address details. Mostly used for debugging purposes. - /// - /// The client name and address. - public override string ToString() - { - return "TestClientDetails: [ clientName = " + clientName + ", privateControlKey = " + privateControlKey + " ]"; - } - } -} +/* + * + * 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. + * + */ +using System; + +namespace Apache.Qpid.Integration.Tests.framework +{ + /// + /// TestClientDetails is used to encapsulate information about an interop test client. It pairs together the unique + /// name of the client, and the route on which it listens to its control messages. + /// + ///

+ ///
CRC Card
Responsibilities Collaborations + ///
Record test clients control addresses together with their names. + ///
+ ///

+ public class TestClientDetails + { + /// The test clients name. + public string clientName; + + /// The routing key of the test clients control topic. + public string privateControlKey; + + /// + /// Two TestClientDetails are considered to be equal, iff they have the same client name. + /// + /// The object to compare to. + /// + /// If the object to compare to is a TestClientDetails equal to this one, false otherwise. + public override bool Equals(Object o) + { + if (this == o) + { + return true; + } + + if (!(o is TestClientDetails)) + { + return false; + } + + TestClientDetails testClientDetails = (TestClientDetails) o; + + return !((clientName != null) ? (!clientName.Equals(testClientDetails.clientName)) + : (testClientDetails.clientName != null)); + } + + /// + /// Computes a hash code compatible with the equals method; based on the client name alone. + /// + /// A hash code for this. + public override int GetHashCode() + { + return ((clientName != null) ? clientName.GetHashCode() : 0); + } + + /// + /// Outputs the client name and address details. Mostly used for debugging purposes. + /// + /// The client name and address. + public override string ToString() + { + return "TestClientDetails: [ clientName = " + clientName + ", privateControlKey = " + privateControlKey + " ]"; + } + } +} diff --git a/dotnet/Qpid.Integration.Tests/framework/TestModel.cs b/dotnet/Qpid.Integration.Tests/framework/TestModel.cs index a4a1d7db9b..88bea1e5ad 100644 --- a/dotnet/Qpid.Integration.Tests/framework/TestModel.cs +++ b/dotnet/Qpid.Integration.Tests/framework/TestModel.cs @@ -1,657 +1,657 @@ -/* - * - * 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. - * - */ -//using uk.co.thebadgerset.junit.extensions.util.ParsedProperties; - -//using javax.jms.Session; - -//using java.util.Properties; - -namespace Apache.Qpid.Integration.Tests.framework -{ - public class TestModel //extends ParsedProperties - {} - - /* - /// - /// MessagingTestConfigProperties defines a set of property names and default values for specifying a messaging topology, - /// and test parameters for running a messaging test over that topology. A Properties object holding some of these - /// properties, superimposed onto the defaults, is used to establish test topologies and control test behaviour. - /// - ///

A complete list of the parameters, default values and comments on their usage is provided here: - /// - ///

- ///
Parameters
Parameter Default Comments - ///
messageSize 0 Message size in bytes. Not including any headers. - ///
destinationName ping The root name to use to generate destination names to ping. - ///
persistent false Determines whether peristent delivery is used. - ///
transacted false Determines whether messages are sent/received in transactions. - ///
broker tcp://localhost:5672 Determines the broker to connect to. - ///
virtualHost test Determines the virtual host to send all ping over. - ///
rate 0 The maximum rate (in hertz) to send messages at. 0 means no limit. - ///
verbose false The verbose flag for debugging. Prints to console on every message. - ///
pubsub false Whether to ping topics or queues. Uses p2p by default. - ///
username guest The username to access the broker with. - ///
password guest The password to access the broker with. - ///
selector null Not used. Defines a message selector to filter pings with. - ///
destinationCount 1 The number of receivers listening to the pings. - ///
timeout 30000 In milliseconds. The timeout to stop waiting for replies. - ///
commitBatchSize 1 The number of messages per transaction in transactional mode. - ///
uniqueDests true Whether each receivers only listens to one ping destination or all. - ///
durableDests false Whether or not durable destinations are used. - ///
ackMode AUTO_ACK The message acknowledgement mode. Possible values are: - /// 0 - SESSION_TRANSACTED - /// 1 - AUTO_ACKNOWLEDGE - /// 2 - CLIENT_ACKNOWLEDGE - /// 3 - DUPS_OK_ACKNOWLEDGE - /// 257 - NO_ACKNOWLEDGE - /// 258 - PRE_ACKNOWLEDGE - ///
maxPending 0 The maximum size in bytes, of messages sent but not yet received. - /// Limits the volume of messages currently buffered on the client - /// or broker. Can help scale test clients by limiting amount of buffered - /// data to avoid out of memory errors. - ///
- /// - ///

- ///
CRC Card
Responsibilities Collaborations - ///
Provide the names and defaults of all test parameters. - ///
- ///

- /// - /// Put a type-safe wrapper around these properties, but continue to store the parameters as properties. This is - /// simply to ensure that it is a simple matter to serialize/deserialize string/string pairs onto messages. - public class MessagingTestConfigProperties extends ParsedProperties - { - // ====================== Connection Properties ================================== - - /// Holds the name of the default connection configuration. - public static final string CONNECTION_NAME = "broker"; - - /// Holds the name of the property to get the initial context factory name from. - public static final string INITIAL_CONTEXT_FACTORY_PROPNAME = "java.naming.factory.initial"; - - /// Defines the class to use as the initial context factory by default. - public static final string INITIAL_CONTEXT_FACTORY_DEFAULT = "org.apache.qpid.jndi.PropertiesFileInitialContextFactory"; - - /// Holds the name of the property to get the test broker url from. - public static final string BROKER_PROPNAME = "qpid.test.broker"; - - /// Holds the default broker url for the test. - public static final string BROKER_DEFAULT = "vm://:1"; - - /// Holds the name of the property to get the test broker virtual path. - public static final string VIRTUAL_HOST_PROPNAME = "virtualHost"; - - /// Holds the default virtual path for the test. - public static final string VIRTUAL_HOST_DEFAULT = ""; - - /// Holds the name of the property to get the broker access username from. - public static final string USERNAME_PROPNAME = "username"; - - /// Holds the default broker log on username. - public static final string USERNAME_DEFAULT = "guest"; - - /// Holds the name of the property to get the broker access password from. - public static final string PASSWORD_PROPNAME = "password"; - - /// Holds the default broker log on password. - public static final string PASSWORD_DEFAULT = "guest"; - - // ====================== Messaging Topology Properties ========================== - - /// Holds the name of the property to get the bind publisher procuder flag from. - public static final string PUBLISHER_PRODUCER_BIND_PROPNAME = "publisherProducerBind"; - - /// Holds the default value of the publisher producer flag. - public static final bool PUBLISHER_PRODUCER_BIND_DEFAULT = true; - - /// Holds the name of the property to get the bind publisher procuder flag from. - public static final string PUBLISHER_CONSUMER_BIND_PROPNAME = "publisherConsumerBind"; - - /// Holds the default value of the publisher consumer flag. - public static final bool PUBLISHER_CONSUMER_BIND_DEFAULT = false; - - /// Holds the name of the property to get the bind receivers procuder flag from. - public static final string RECEIVER_PRODUCER_BIND_PROPNAME = "receiverProducerBind"; - - /// Holds the default value of the receivers producer flag. - public static final bool RECEIVER_PRODUCER_BIND_DEFAULT = false; - - /// Holds the name of the property to get the bind receivers procuder flag from. - public static final string RECEIVER_CONSUMER_BIND_PROPNAME = "receiverConsumerBind"; - - /// Holds the default value of the receivers consumer flag. - public static final bool RECEIVER_CONSUMER_BIND_DEFAULT = true; - - /// Holds the name of the property to get the publishers consumer active flag from. - public static final string PUBLISHER_CONSUMER_ACTIVE_PROPNAME = "publisherConsumerActive"; - - /// Holds the default value of the publishers consumer active flag. - public static final bool PUBLISHER_CONSUMER_ACTIVE_DEFAULT = true; - - /// Holds the name of the property to get the receivers consumer active flag from. - public static final string RECEIVER_CONSUMER_ACTIVE_PROPNAME = "receiverConsumerActive"; - - /// Holds the default value of the receivers consumer active flag. - public static final bool RECEIVER_CONSUMER_ACTIVE_DEFAULT = true; - - /// Holds the name of the property to get the destination name root from. - public static final string SEND_DESTINATION_NAME_ROOT_PROPNAME = "sendDestinationRoot"; - - /// Holds the root of the name of the default destination to send to. - public static final string SEND_DESTINATION_NAME_ROOT_DEFAULT = "sendTo"; - - /// Holds the name of the property to get the destination name root from. - public static final string RECEIVE_DESTINATION_NAME_ROOT_PROPNAME = "receiveDestinationRoot"; - - /// Holds the root of the name of the default destination to send to. - public static final string RECEIVE_DESTINATION_NAME_ROOT_DEFAULT = "receiveFrom"; - - /// Holds the name of the proeprty to get the destination count from. - public static final string DESTINATION_COUNT_PROPNAME = "destinationCount"; - - /// Defines the default number of destinations to ping. - public static final int DESTINATION_COUNT_DEFAULT = 1; - - /// Holds the name of the property to get the p2p or pub/sub messaging mode from. - public static final string PUBSUB_PROPNAME = "pubsub"; - - /// Holds the pub/sub mode default, true means ping a topic, false means ping a queue. - public static final bool PUBSUB_DEFAULT = false; - - // ====================== JMS Options and Flags ================================= - - /// Holds the name of the property to get the test delivery mode from. - public static final string PERSISTENT_MODE_PROPNAME = "persistent"; - - /// Holds the message delivery mode to use for the test. - public static final bool PERSISTENT_MODE_DEFAULT = false; - - /// Holds the name of the property to get the test transactional mode from. - public static final string TRANSACTED_PUBLISHER_PROPNAME = "transactedPublisher"; - - /// Holds the transactional mode to use for the test. - public static final bool TRANSACTED_PUBLISHER_DEFAULT = false; - - /// Holds the name of the property to get the test transactional mode from. - public static final string TRANSACTED_RECEIVER_PROPNAME = "transactedReceiver"; - - /// Holds the transactional mode to use for the test. - public static final bool TRANSACTED_RECEIVER_DEFAULT = false; - - /// Holds the name of the property to set the no local flag from. - public static final string NO_LOCAL_PROPNAME = "noLocal"; - - /// Defines the default value of the no local flag to use when consuming messages. - public static final bool NO_LOCAL_DEFAULT = false; - - /// Holds the name of the property to get the message acknowledgement mode from. - public static final string ACK_MODE_PROPNAME = "ackMode"; - - /// Defines the default message acknowledgement mode. - public static final int ACK_MODE_DEFAULT = Session.AUTO_ACKNOWLEDGE; - - /// Holds the name of the property to get the durable subscriptions flag from, when doing pub/sub messaging. - public static final string DURABLE_SUBSCRIPTION_PROPNAME = "durableSubscription"; - - /// Defines the default value of the durable subscriptions flag. - public static final bool DURABLE_SUBSCRIPTION_DEFAULT = false; - - // ====================== Qpid/AMQP Options and Flags ================================ - - /// Holds the name of the property to set the exclusive flag from. - public static final string EXCLUSIVE_PROPNAME = "exclusive"; - - /// Defines the default value of the exclusive flag to use when consuming messages. - public static final bool EXCLUSIVE_DEFAULT = false; - - /// Holds the name of the property to set the immediate flag from. - public static final string IMMEDIATE_PROPNAME = "immediate"; - - /// Defines the default value of the immediate flag to use when sending messages. - public static final bool IMMEDIATE_DEFAULT = false; - - /// Holds the name of the property to set the mandatory flag from. - public static final string MANDATORY_PROPNAME = "mandatory"; - - /// Defines the default value of the mandatory flag to use when sending messages. - public static final bool MANDATORY_DEFAULT = false; - - /// Holds the name of the property to get the durable destinations flag from. - public static final string DURABLE_DESTS_PROPNAME = "durableDests"; - - /// Default value for the durable destinations flag. - public static final bool DURABLE_DESTS_DEFAULT = false; - - /// Holds the name of the property to set the prefetch size from. - public static final string PREFETCH_PROPNAME = "prefetch"; - - /// Defines the default prefetch size to use when consuming messages. - public static final int PREFETCH_DEFAULT = 100; - - // ====================== Common Test Parameters ================================ - - /// Holds the name of the property to get the test message size from. - public static final string MESSAGE_SIZE_PROPNAME = "messageSize"; - - /// Used to set up a default message size. - public static final int MESSAGE_SIZE_DEAFULT = 0; - - /// Holds the name of the property to get the message rate from. - public static final string RATE_PROPNAME = "rate"; - - /// Defines the default rate (in pings per second) to send pings at. 0 means as fast as possible, no restriction. - public static final int RATE_DEFAULT = 0; - - /// Holds the name of the proeprty to get the. - public static final string SELECTOR_PROPNAME = "selector"; - - /// Holds the default message selector. - public static final string SELECTOR_DEFAULT = ""; - - /// Holds the name of the property to get the waiting timeout for response messages. - public static final string TIMEOUT_PROPNAME = "timeout"; - - /// Default time to wait before assuming that a ping has timed out. - public static final long TIMEOUT_DEFAULT = 30000; - - /// Holds the name of the property to get the commit batch size from. - public static final string TX_BATCH_SIZE_PROPNAME = "commitBatchSize"; - - /// Defines the default number of pings to send in each transaction when running transactionally. - public static final int TX_BATCH_SIZE_DEFAULT = 1; - - /// Holds the name of the property to set the maximum amount of pending message data for a producer to hold. - public static final string MAX_PENDING_PROPNAME = "maxPending"; - - /// Defines the default maximum quantity of pending message data to allow producers to hold. - public static final int MAX_PENDING_DEFAULT = 0; - - /// Holds the name of the property to get the publisher rollback flag from. - public static final string ROLLBACK_PUBLISHER_PROPNAME = "rollbackPublisher"; - - /// Holds the default publisher roll back setting. - public static final bool ROLLBACK_PUBLISHER_DEFAULT = false; - - /// Holds the name of the property to get the publisher rollback flag from. - public static final string ROLLBACK_RECEIVER_PROPNAME = "rollbackReceiver"; - - /// Holds the default publisher roll back setting. - public static final bool ROLLBACK_RECEIVER_DEFAULT = false; - - // ====================== Options that control the bahviour of the test framework. ========================= - - /// Holds the name of the property to get the behavioural mode of not applicable assertions. - public static final string NOT_APPLICABLE_ASSERTION_PROPNAME = "notApplicableAssertion"; - - /// Holds the default behavioral mode of not applicable assertions, which is logging them as a warning. - public static final string NOT_APPLICABLE_ASSERTION_DEFAULT = "warn"; - - /// Holds the name of the property to get the verbose mode proeprty from. - public static final string VERBOSE_PROPNAME = "verbose"; - - /// Holds the default verbose mode. - public static final bool VERBOSE_DEFAULT = false; - - /// Holds the default configuration properties. - public static ParsedProperties defaults = new ParsedProperties(); - - static - { - defaults.setPropertyIfNull(INITIAL_CONTEXT_FACTORY_PROPNAME, INITIAL_CONTEXT_FACTORY_DEFAULT); - defaults.setPropertyIfNull(BROKER_PROPNAME, BROKER_DEFAULT); - defaults.setPropertyIfNull(VIRTUAL_HOST_PROPNAME, VIRTUAL_HOST_DEFAULT); - defaults.setPropertyIfNull(USERNAME_PROPNAME, USERNAME_DEFAULT); - defaults.setPropertyIfNull(PASSWORD_PROPNAME, PASSWORD_DEFAULT); - - defaults.setPropertyIfNull(PUBLISHER_PRODUCER_BIND_PROPNAME, PUBLISHER_PRODUCER_BIND_DEFAULT); - defaults.setPropertyIfNull(PUBLISHER_CONSUMER_BIND_PROPNAME, PUBLISHER_CONSUMER_BIND_DEFAULT); - defaults.setPropertyIfNull(RECEIVER_PRODUCER_BIND_PROPNAME, RECEIVER_PRODUCER_BIND_DEFAULT); - defaults.setPropertyIfNull(RECEIVER_CONSUMER_BIND_PROPNAME, RECEIVER_CONSUMER_BIND_DEFAULT); - defaults.setPropertyIfNull(PUBLISHER_CONSUMER_ACTIVE_PROPNAME, PUBLISHER_CONSUMER_ACTIVE_DEFAULT); - defaults.setPropertyIfNull(RECEIVER_CONSUMER_ACTIVE_PROPNAME, RECEIVER_CONSUMER_ACTIVE_DEFAULT); - defaults.setPropertyIfNull(SEND_DESTINATION_NAME_ROOT_PROPNAME, SEND_DESTINATION_NAME_ROOT_DEFAULT); - defaults.setPropertyIfNull(RECEIVE_DESTINATION_NAME_ROOT_PROPNAME, RECEIVE_DESTINATION_NAME_ROOT_DEFAULT); - defaults.setPropertyIfNull(DESTINATION_COUNT_PROPNAME, DESTINATION_COUNT_DEFAULT); - defaults.setPropertyIfNull(PUBSUB_PROPNAME, PUBSUB_DEFAULT); - - defaults.setPropertyIfNull(PERSISTENT_MODE_PROPNAME, PERSISTENT_MODE_DEFAULT); - defaults.setPropertyIfNull(TRANSACTED_PUBLISHER_PROPNAME, TRANSACTED_PUBLISHER_DEFAULT); - defaults.setPropertyIfNull(TRANSACTED_RECEIVER_PROPNAME, TRANSACTED_RECEIVER_DEFAULT); - defaults.setPropertyIfNull(NO_LOCAL_PROPNAME, NO_LOCAL_DEFAULT); - defaults.setPropertyIfNull(ACK_MODE_PROPNAME, ACK_MODE_DEFAULT); - defaults.setPropertyIfNull(DURABLE_SUBSCRIPTION_PROPNAME, DURABLE_SUBSCRIPTION_DEFAULT); - - defaults.setPropertyIfNull(EXCLUSIVE_PROPNAME, EXCLUSIVE_DEFAULT); - defaults.setPropertyIfNull(IMMEDIATE_PROPNAME, IMMEDIATE_DEFAULT); - defaults.setPropertyIfNull(MANDATORY_PROPNAME, MANDATORY_DEFAULT); - defaults.setPropertyIfNull(DURABLE_DESTS_PROPNAME, DURABLE_DESTS_DEFAULT); - defaults.setPropertyIfNull(PREFETCH_PROPNAME, PREFETCH_DEFAULT); - - defaults.setPropertyIfNull(MESSAGE_SIZE_PROPNAME, MESSAGE_SIZE_DEAFULT); - defaults.setPropertyIfNull(RATE_PROPNAME, RATE_DEFAULT); - defaults.setPropertyIfNull(SELECTOR_PROPNAME, SELECTOR_DEFAULT); - defaults.setPropertyIfNull(TIMEOUT_PROPNAME, TIMEOUT_DEFAULT); - defaults.setPropertyIfNull(TX_BATCH_SIZE_PROPNAME, TX_BATCH_SIZE_DEFAULT); - defaults.setPropertyIfNull(MAX_PENDING_PROPNAME, MAX_PENDING_DEFAULT); - defaults.setPropertyIfNull(ROLLBACK_PUBLISHER_PROPNAME, ROLLBACK_PUBLISHER_DEFAULT); - defaults.setPropertyIfNull(ROLLBACK_RECEIVER_PROPNAME, ROLLBACK_RECEIVER_DEFAULT); - - defaults.setPropertyIfNull(NOT_APPLICABLE_ASSERTION_PROPNAME, NOT_APPLICABLE_ASSERTION_DEFAULT); - defaults.setPropertyIfNull(VERBOSE_PROPNAME, VERBOSE_DEFAULT); - } - - /// Creates a test configuration based on the defaults. - public MessagingTestConfigProperties() - { - super(defaults); - } - - /// - /// Creates a test configuration based on the supplied properties. - /// - /// The test configuration. - public MessagingTestConfigProperties(Properties properties) - { - super(properties); - } - - /// - /// The size of test messages to send. - /// - /// The size of test messages to send. - public int getMessageSize() - { - return getPropertyAsInteger(MESSAGE_SIZE_PROPNAME); - } - - /// - /// Flag to indicate that the publishing producer should be set up to publish to a destination. - /// - /// Flag to indicate that the publishing producer should be set up to publish to a destination. - public bool getPublisherProducerBind() - { - return getPropertyAsBoolean(PUBLISHER_PRODUCER_BIND_PROPNAME); - } - - /// - /// Flag to indicate that the publishing consumer should be set up to receive from a destination. - /// - /// Flag to indicate that the publishing consumer should be set up to receive from a destination. - public bool getPublisherConsumerBind() - { - return getPropertyAsBoolean(PUBLISHER_CONSUMER_BIND_PROPNAME); - } - - /// - /// Flag to indicate that the receiving producer should be set up to publish to a destination. - /// - /// Flag to indicate that the receiving producer should be set up to publish to a destination. - public bool getReceiverProducerBind() - { - return getPropertyAsBoolean(RECEIVER_PRODUCER_BIND_PROPNAME); - } - - /// - /// Flag to indicate that the receiving consumer should be set up to receive from a destination. - /// - /// Flag to indicate that the receiving consumer should be set up to receive from a destination. - public bool getReceiverConsumerBind() - { - return getPropertyAsBoolean(RECEIVER_CONSUMER_BIND_PROPNAME); - } - - /// - /// Flag to indicate that the publishing consumer should be created and actively listening. - /// - /// Flag to indicate that the publishing consumer should be created. - public bool getPublisherConsumerActive() - { - return getPropertyAsBoolean(PUBLISHER_CONSUMER_ACTIVE_PROPNAME); - } - - /// - /// Flag to indicate that the receiving consumers should be created and actively listening. - /// - /// Flag to indicate that the receiving consumers should be created and actively listening. - public bool getReceiverConsumerActive() - { - return getPropertyAsBoolean(RECEIVER_CONSUMER_ACTIVE_PROPNAME); - } - - /// - /// A root to create all test destination names from. - /// - /// A root to create all test destination names from. - public string getSendDestinationNameRoot() - { - return getProperty(SEND_DESTINATION_NAME_ROOT_PROPNAME); - } - - /// - /// A root to create all receiving destination names from. - /// - /// A root to create all receiving destination names from. - public string getReceiveDestinationNameRoot() - { - return getProperty(RECEIVE_DESTINATION_NAME_ROOT_PROPNAME); - } - - /// - /// Flag to indicate that persistent messages should be used. - /// - /// Flag to indicate that persistent messages should be used. - public bool getPersistentMode() - { - return getPropertyAsBoolean(PERSISTENT_MODE_PROPNAME); - } - - /// - /// Flag to indicate that transactional messages should be sent by the publisher. - /// - /// Flag to indicate that transactional messages should be sent by the publisher. - public bool getPublisherTransacted() - { - return getPropertyAsBoolean(TRANSACTED_PUBLISHER_PROPNAME); - } - - /// - /// Flag to indicate that transactional receives should be used by the receiver. - /// - /// Flag to indicate that transactional receives should be used by the receiver. - public bool getReceiverTransacted() - { - return getPropertyAsBoolean(TRANSACTED_PUBLISHER_PROPNAME); - } - - /// - /// The name of the virtual host to run all tests over. - /// - /// The name of the virtual host to run all tests over. - public string getVirtualHost() - { - return getProperty(VIRTUAL_HOST_PROPNAME); - } - - /// - /// Limiting rate for each sender in messages per second, or zero for unlimited. - /// - /// Limiting rate for each sender in messages per second, or zero for unlimited. - public string getRate() - { - return getProperty(RATE_PROPNAME); - } - - /// - /// Flag to indicate that test messages should be received publish/subscribe style by all receivers. - /// - /// Flag to indicate that test messages should be received publish/subscribe style by all receivers. - public bool getPubsub() - { - return getPropertyAsBoolean(PUBSUB_PROPNAME); - } - - /// - /// The username credentials to run tests with. - /// - /// The username credentials to run tests with. - public string getUsername() - { - return getProperty(USERNAME_PROPNAME); - } - - /// - /// The password credentials to run tests with. - /// - /// The password credentials to run tests with. - public string getPassword() - { - return getProperty(PASSWORD_PROPNAME); - } - - /// - /// The timeout duration to fail tests on, should they receive no messages within it. - /// - /// The timeout duration to fail tests on, should they receive no messages within it. - public long getTimeout() - { - return getPropertyAsLong(TIMEOUT_PROPNAME); - } - - /// - /// The number of messages to batch into each transaction in transational tests. - /// - /// The number of messages to batch into each transaction in transational tests. - public int getTxBatchSize() - { - return getPropertyAsInteger(TX_BATCH_SIZE_PROPNAME); - } - - /// - /// Flag to indicate that tests should use durable destinations. - /// - /// Flag to indicate that tests should use durable destinations. - public bool getDurableDests() - { - return getPropertyAsBoolean(DURABLE_DESTS_PROPNAME); - } - - /// - /// The ack mode for message receivers to use. - /// - /// The ack mode for message receivers to use. - public int getAckMode() - { - return getPropertyAsInteger(ACK_MODE_PROPNAME); - } - - /// - /// Flag to indicate that tests should use durable subscriptions. - /// - /// Flag to indicate that tests should use durable subscriptions. - public bool getDurableSubscription() - { - return getPropertyAsBoolean(DURABLE_SUBSCRIPTION_PROPNAME); - } - - /// - /// The maximum amount of in-flight data, in bytes, that tests should send at any time. - /// - /// The maximum amount of in-flight data, in bytes, that tests should send at any time. - public int getMaxPending() - { - return getPropertyAsInteger(MAX_PENDING_PROPNAME); - } - - /// - /// The size of the prefetch queue to use. - /// - /// The size of the prefetch queue to use. - public int getPrefetch() - { - return getPropertyAsInteger(PREFETCH_PROPNAME); - } - - /// - /// Flag to indicate that subscriptions should be no-local. - /// - /// Flag to indicate that subscriptions should be no-local. - public bool getNoLocal() - { - return getPropertyAsBoolean(NO_LOCAL_PROPNAME); - } - - /// - /// Flag to indicate that subscriptions should be exclusive. - /// - /// Flag to indicate that subscriptions should be exclusive. - public bool getExclusive() - { - return getPropertyAsBoolean(EXCLUSIVE_PROPNAME); - } - - /// - /// Flag to indicate that messages must be delivered immediately. - /// - /// Flag to indicate that messages must be delivered immediately. - public bool getImmediate() - { - return getPropertyAsBoolean(IMMEDIATE_PROPNAME); - } - - /// - /// Flag to indicate that messages must be routable. - /// - /// Flag to indicate that messages must be routable. - public bool getMandatory() - { - return getPropertyAsBoolean(MANDATORY_PROPNAME); - } - - /// - /// Gets the value of a flag to indicate that the publisher should rollback all messages sent. - /// - /// A flag to indicate that the publisher should rollback all messages sent. - public bool getRollbackPublisher() - { - return getPropertyAsBoolean(ROLLBACK_PUBLISHER_PROPNAME); - } - - /// - /// Gets the value of a flag to indicate that the receiver should rollback all messages received, then receive them - /// again. - /// - /// A flag to indicate that the publisher should rollback all messages received. - public bool getRollbackReceiver() - { - return getPropertyAsBoolean(ROLLBACK_RECEIVER_PROPNAME); - } - - /// - /// Gets the behavioural mode of not applicable assertions. Should be one of 'quiet', 'warn' or 'fail'. - /// - /// The behavioural mode of not applicable assertions. - public string getNotApplicableAssertionMode() - { - return getProperty(NOT_APPLICABLE_ASSERTION_PROPNAME); - } - } - */ +/* + * + * 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. + * + */ +//using uk.co.thebadgerset.junit.extensions.util.ParsedProperties; + +//using javax.jms.Session; + +//using java.util.Properties; + +namespace Apache.Qpid.Integration.Tests.framework +{ + public class TestModel //extends ParsedProperties + {} + + /* + /// + /// MessagingTestConfigProperties defines a set of property names and default values for specifying a messaging topology, + /// and test parameters for running a messaging test over that topology. A Properties object holding some of these + /// properties, superimposed onto the defaults, is used to establish test topologies and control test behaviour. + /// + ///

A complete list of the parameters, default values and comments on their usage is provided here: + /// + ///

+ ///
Parameters
Parameter Default Comments + ///
messageSize 0 Message size in bytes. Not including any headers. + ///
destinationName ping The root name to use to generate destination names to ping. + ///
persistent false Determines whether peristent delivery is used. + ///
transacted false Determines whether messages are sent/received in transactions. + ///
broker tcp://localhost:5672 Determines the broker to connect to. + ///
virtualHost test Determines the virtual host to send all ping over. + ///
rate 0 The maximum rate (in hertz) to send messages at. 0 means no limit. + ///
verbose false The verbose flag for debugging. Prints to console on every message. + ///
pubsub false Whether to ping topics or queues. Uses p2p by default. + ///
username guest The username to access the broker with. + ///
password guest The password to access the broker with. + ///
selector null Not used. Defines a message selector to filter pings with. + ///
destinationCount 1 The number of receivers listening to the pings. + ///
timeout 30000 In milliseconds. The timeout to stop waiting for replies. + ///
commitBatchSize 1 The number of messages per transaction in transactional mode. + ///
uniqueDests true Whether each receivers only listens to one ping destination or all. + ///
durableDests false Whether or not durable destinations are used. + ///
ackMode AUTO_ACK The message acknowledgement mode. Possible values are: + /// 0 - SESSION_TRANSACTED + /// 1 - AUTO_ACKNOWLEDGE + /// 2 - CLIENT_ACKNOWLEDGE + /// 3 - DUPS_OK_ACKNOWLEDGE + /// 257 - NO_ACKNOWLEDGE + /// 258 - PRE_ACKNOWLEDGE + ///
maxPending 0 The maximum size in bytes, of messages sent but not yet received. + /// Limits the volume of messages currently buffered on the client + /// or broker. Can help scale test clients by limiting amount of buffered + /// data to avoid out of memory errors. + ///
+ /// + ///

+ ///
CRC Card
Responsibilities Collaborations + ///
Provide the names and defaults of all test parameters. + ///
+ ///

+ /// + /// Put a type-safe wrapper around these properties, but continue to store the parameters as properties. This is + /// simply to ensure that it is a simple matter to serialize/deserialize string/string pairs onto messages. + public class MessagingTestConfigProperties extends ParsedProperties + { + // ====================== Connection Properties ================================== + + /// Holds the name of the default connection configuration. + public static final string CONNECTION_NAME = "broker"; + + /// Holds the name of the property to get the initial context factory name from. + public static final string INITIAL_CONTEXT_FACTORY_PROPNAME = "java.naming.factory.initial"; + + /// Defines the class to use as the initial context factory by default. + public static final string INITIAL_CONTEXT_FACTORY_DEFAULT = "org.apache.qpid.jndi.PropertiesFileInitialContextFactory"; + + /// Holds the name of the property to get the test broker url from. + public static final string BROKER_PROPNAME = "qpid.test.broker"; + + /// Holds the default broker url for the test. + public static final string BROKER_DEFAULT = "vm://:1"; + + /// Holds the name of the property to get the test broker virtual path. + public static final string VIRTUAL_HOST_PROPNAME = "virtualHost"; + + /// Holds the default virtual path for the test. + public static final string VIRTUAL_HOST_DEFAULT = ""; + + /// Holds the name of the property to get the broker access username from. + public static final string USERNAME_PROPNAME = "username"; + + /// Holds the default broker log on username. + public static final string USERNAME_DEFAULT = "guest"; + + /// Holds the name of the property to get the broker access password from. + public static final string PASSWORD_PROPNAME = "password"; + + /// Holds the default broker log on password. + public static final string PASSWORD_DEFAULT = "guest"; + + // ====================== Messaging Topology Properties ========================== + + /// Holds the name of the property to get the bind publisher procuder flag from. + public static final string PUBLISHER_PRODUCER_BIND_PROPNAME = "publisherProducerBind"; + + /// Holds the default value of the publisher producer flag. + public static final bool PUBLISHER_PRODUCER_BIND_DEFAULT = true; + + /// Holds the name of the property to get the bind publisher procuder flag from. + public static final string PUBLISHER_CONSUMER_BIND_PROPNAME = "publisherConsumerBind"; + + /// Holds the default value of the publisher consumer flag. + public static final bool PUBLISHER_CONSUMER_BIND_DEFAULT = false; + + /// Holds the name of the property to get the bind receivers procuder flag from. + public static final string RECEIVER_PRODUCER_BIND_PROPNAME = "receiverProducerBind"; + + /// Holds the default value of the receivers producer flag. + public static final bool RECEIVER_PRODUCER_BIND_DEFAULT = false; + + /// Holds the name of the property to get the bind receivers procuder flag from. + public static final string RECEIVER_CONSUMER_BIND_PROPNAME = "receiverConsumerBind"; + + /// Holds the default value of the receivers consumer flag. + public static final bool RECEIVER_CONSUMER_BIND_DEFAULT = true; + + /// Holds the name of the property to get the publishers consumer active flag from. + public static final string PUBLISHER_CONSUMER_ACTIVE_PROPNAME = "publisherConsumerActive"; + + /// Holds the default value of the publishers consumer active flag. + public static final bool PUBLISHER_CONSUMER_ACTIVE_DEFAULT = true; + + /// Holds the name of the property to get the receivers consumer active flag from. + public static final string RECEIVER_CONSUMER_ACTIVE_PROPNAME = "receiverConsumerActive"; + + /// Holds the default value of the receivers consumer active flag. + public static final bool RECEIVER_CONSUMER_ACTIVE_DEFAULT = true; + + /// Holds the name of the property to get the destination name root from. + public static final string SEND_DESTINATION_NAME_ROOT_PROPNAME = "sendDestinationRoot"; + + /// Holds the root of the name of the default destination to send to. + public static final string SEND_DESTINATION_NAME_ROOT_DEFAULT = "sendTo"; + + /// Holds the name of the property to get the destination name root from. + public static final string RECEIVE_DESTINATION_NAME_ROOT_PROPNAME = "receiveDestinationRoot"; + + /// Holds the root of the name of the default destination to send to. + public static final string RECEIVE_DESTINATION_NAME_ROOT_DEFAULT = "receiveFrom"; + + /// Holds the name of the proeprty to get the destination count from. + public static final string DESTINATION_COUNT_PROPNAME = "destinationCount"; + + /// Defines the default number of destinations to ping. + public static final int DESTINATION_COUNT_DEFAULT = 1; + + /// Holds the name of the property to get the p2p or pub/sub messaging mode from. + public static final string PUBSUB_PROPNAME = "pubsub"; + + /// Holds the pub/sub mode default, true means ping a topic, false means ping a queue. + public static final bool PUBSUB_DEFAULT = false; + + // ====================== JMS Options and Flags ================================= + + /// Holds the name of the property to get the test delivery mode from. + public static final string PERSISTENT_MODE_PROPNAME = "persistent"; + + /// Holds the message delivery mode to use for the test. + public static final bool PERSISTENT_MODE_DEFAULT = false; + + /// Holds the name of the property to get the test transactional mode from. + public static final string TRANSACTED_PUBLISHER_PROPNAME = "transactedPublisher"; + + /// Holds the transactional mode to use for the test. + public static final bool TRANSACTED_PUBLISHER_DEFAULT = false; + + /// Holds the name of the property to get the test transactional mode from. + public static final string TRANSACTED_RECEIVER_PROPNAME = "transactedReceiver"; + + /// Holds the transactional mode to use for the test. + public static final bool TRANSACTED_RECEIVER_DEFAULT = false; + + /// Holds the name of the property to set the no local flag from. + public static final string NO_LOCAL_PROPNAME = "noLocal"; + + /// Defines the default value of the no local flag to use when consuming messages. + public static final bool NO_LOCAL_DEFAULT = false; + + /// Holds the name of the property to get the message acknowledgement mode from. + public static final string ACK_MODE_PROPNAME = "ackMode"; + + /// Defines the default message acknowledgement mode. + public static final int ACK_MODE_DEFAULT = Session.AUTO_ACKNOWLEDGE; + + /// Holds the name of the property to get the durable subscriptions flag from, when doing pub/sub messaging. + public static final string DURABLE_SUBSCRIPTION_PROPNAME = "durableSubscription"; + + /// Defines the default value of the durable subscriptions flag. + public static final bool DURABLE_SUBSCRIPTION_DEFAULT = false; + + // ====================== Qpid/AMQP Options and Flags ================================ + + /// Holds the name of the property to set the exclusive flag from. + public static final string EXCLUSIVE_PROPNAME = "exclusive"; + + /// Defines the default value of the exclusive flag to use when consuming messages. + public static final bool EXCLUSIVE_DEFAULT = false; + + /// Holds the name of the property to set the immediate flag from. + public static final string IMMEDIATE_PROPNAME = "immediate"; + + /// Defines the default value of the immediate flag to use when sending messages. + public static final bool IMMEDIATE_DEFAULT = false; + + /// Holds the name of the property to set the mandatory flag from. + public static final string MANDATORY_PROPNAME = "mandatory"; + + /// Defines the default value of the mandatory flag to use when sending messages. + public static final bool MANDATORY_DEFAULT = false; + + /// Holds the name of the property to get the durable destinations flag from. + public static final string DURABLE_DESTS_PROPNAME = "durableDests"; + + /// Default value for the durable destinations flag. + public static final bool DURABLE_DESTS_DEFAULT = false; + + /// Holds the name of the property to set the prefetch size from. + public static final string PREFETCH_PROPNAME = "prefetch"; + + /// Defines the default prefetch size to use when consuming messages. + public static final int PREFETCH_DEFAULT = 100; + + // ====================== Common Test Parameters ================================ + + /// Holds the name of the property to get the test message size from. + public static final string MESSAGE_SIZE_PROPNAME = "messageSize"; + + /// Used to set up a default message size. + public static final int MESSAGE_SIZE_DEAFULT = 0; + + /// Holds the name of the property to get the message rate from. + public static final string RATE_PROPNAME = "rate"; + + /// Defines the default rate (in pings per second) to send pings at. 0 means as fast as possible, no restriction. + public static final int RATE_DEFAULT = 0; + + /// Holds the name of the proeprty to get the. + public static final string SELECTOR_PROPNAME = "selector"; + + /// Holds the default message selector. + public static final string SELECTOR_DEFAULT = ""; + + /// Holds the name of the property to get the waiting timeout for response messages. + public static final string TIMEOUT_PROPNAME = "timeout"; + + /// Default time to wait before assuming that a ping has timed out. + public static final long TIMEOUT_DEFAULT = 30000; + + /// Holds the name of the property to get the commit batch size from. + public static final string TX_BATCH_SIZE_PROPNAME = "commitBatchSize"; + + /// Defines the default number of pings to send in each transaction when running transactionally. + public static final int TX_BATCH_SIZE_DEFAULT = 1; + + /// Holds the name of the property to set the maximum amount of pending message data for a producer to hold. + public static final string MAX_PENDING_PROPNAME = "maxPending"; + + /// Defines the default maximum quantity of pending message data to allow producers to hold. + public static final int MAX_PENDING_DEFAULT = 0; + + /// Holds the name of the property to get the publisher rollback flag from. + public static final string ROLLBACK_PUBLISHER_PROPNAME = "rollbackPublisher"; + + /// Holds the default publisher roll back setting. + public static final bool ROLLBACK_PUBLISHER_DEFAULT = false; + + /// Holds the name of the property to get the publisher rollback flag from. + public static final string ROLLBACK_RECEIVER_PROPNAME = "rollbackReceiver"; + + /// Holds the default publisher roll back setting. + public static final bool ROLLBACK_RECEIVER_DEFAULT = false; + + // ====================== Options that control the bahviour of the test framework. ========================= + + /// Holds the name of the property to get the behavioural mode of not applicable assertions. + public static final string NOT_APPLICABLE_ASSERTION_PROPNAME = "notApplicableAssertion"; + + /// Holds the default behavioral mode of not applicable assertions, which is logging them as a warning. + public static final string NOT_APPLICABLE_ASSERTION_DEFAULT = "warn"; + + /// Holds the name of the property to get the verbose mode proeprty from. + public static final string VERBOSE_PROPNAME = "verbose"; + + /// Holds the default verbose mode. + public static final bool VERBOSE_DEFAULT = false; + + /// Holds the default configuration properties. + public static ParsedProperties defaults = new ParsedProperties(); + + static + { + defaults.setPropertyIfNull(INITIAL_CONTEXT_FACTORY_PROPNAME, INITIAL_CONTEXT_FACTORY_DEFAULT); + defaults.setPropertyIfNull(BROKER_PROPNAME, BROKER_DEFAULT); + defaults.setPropertyIfNull(VIRTUAL_HOST_PROPNAME, VIRTUAL_HOST_DEFAULT); + defaults.setPropertyIfNull(USERNAME_PROPNAME, USERNAME_DEFAULT); + defaults.setPropertyIfNull(PASSWORD_PROPNAME, PASSWORD_DEFAULT); + + defaults.setPropertyIfNull(PUBLISHER_PRODUCER_BIND_PROPNAME, PUBLISHER_PRODUCER_BIND_DEFAULT); + defaults.setPropertyIfNull(PUBLISHER_CONSUMER_BIND_PROPNAME, PUBLISHER_CONSUMER_BIND_DEFAULT); + defaults.setPropertyIfNull(RECEIVER_PRODUCER_BIND_PROPNAME, RECEIVER_PRODUCER_BIND_DEFAULT); + defaults.setPropertyIfNull(RECEIVER_CONSUMER_BIND_PROPNAME, RECEIVER_CONSUMER_BIND_DEFAULT); + defaults.setPropertyIfNull(PUBLISHER_CONSUMER_ACTIVE_PROPNAME, PUBLISHER_CONSUMER_ACTIVE_DEFAULT); + defaults.setPropertyIfNull(RECEIVER_CONSUMER_ACTIVE_PROPNAME, RECEIVER_CONSUMER_ACTIVE_DEFAULT); + defaults.setPropertyIfNull(SEND_DESTINATION_NAME_ROOT_PROPNAME, SEND_DESTINATION_NAME_ROOT_DEFAULT); + defaults.setPropertyIfNull(RECEIVE_DESTINATION_NAME_ROOT_PROPNAME, RECEIVE_DESTINATION_NAME_ROOT_DEFAULT); + defaults.setPropertyIfNull(DESTINATION_COUNT_PROPNAME, DESTINATION_COUNT_DEFAULT); + defaults.setPropertyIfNull(PUBSUB_PROPNAME, PUBSUB_DEFAULT); + + defaults.setPropertyIfNull(PERSISTENT_MODE_PROPNAME, PERSISTENT_MODE_DEFAULT); + defaults.setPropertyIfNull(TRANSACTED_PUBLISHER_PROPNAME, TRANSACTED_PUBLISHER_DEFAULT); + defaults.setPropertyIfNull(TRANSACTED_RECEIVER_PROPNAME, TRANSACTED_RECEIVER_DEFAULT); + defaults.setPropertyIfNull(NO_LOCAL_PROPNAME, NO_LOCAL_DEFAULT); + defaults.setPropertyIfNull(ACK_MODE_PROPNAME, ACK_MODE_DEFAULT); + defaults.setPropertyIfNull(DURABLE_SUBSCRIPTION_PROPNAME, DURABLE_SUBSCRIPTION_DEFAULT); + + defaults.setPropertyIfNull(EXCLUSIVE_PROPNAME, EXCLUSIVE_DEFAULT); + defaults.setPropertyIfNull(IMMEDIATE_PROPNAME, IMMEDIATE_DEFAULT); + defaults.setPropertyIfNull(MANDATORY_PROPNAME, MANDATORY_DEFAULT); + defaults.setPropertyIfNull(DURABLE_DESTS_PROPNAME, DURABLE_DESTS_DEFAULT); + defaults.setPropertyIfNull(PREFETCH_PROPNAME, PREFETCH_DEFAULT); + + defaults.setPropertyIfNull(MESSAGE_SIZE_PROPNAME, MESSAGE_SIZE_DEAFULT); + defaults.setPropertyIfNull(RATE_PROPNAME, RATE_DEFAULT); + defaults.setPropertyIfNull(SELECTOR_PROPNAME, SELECTOR_DEFAULT); + defaults.setPropertyIfNull(TIMEOUT_PROPNAME, TIMEOUT_DEFAULT); + defaults.setPropertyIfNull(TX_BATCH_SIZE_PROPNAME, TX_BATCH_SIZE_DEFAULT); + defaults.setPropertyIfNull(MAX_PENDING_PROPNAME, MAX_PENDING_DEFAULT); + defaults.setPropertyIfNull(ROLLBACK_PUBLISHER_PROPNAME, ROLLBACK_PUBLISHER_DEFAULT); + defaults.setPropertyIfNull(ROLLBACK_RECEIVER_PROPNAME, ROLLBACK_RECEIVER_DEFAULT); + + defaults.setPropertyIfNull(NOT_APPLICABLE_ASSERTION_PROPNAME, NOT_APPLICABLE_ASSERTION_DEFAULT); + defaults.setPropertyIfNull(VERBOSE_PROPNAME, VERBOSE_DEFAULT); + } + + /// Creates a test configuration based on the defaults. + public MessagingTestConfigProperties() + { + super(defaults); + } + + /// + /// Creates a test configuration based on the supplied properties. + /// + /// The test configuration. + public MessagingTestConfigProperties(Properties properties) + { + super(properties); + } + + /// + /// The size of test messages to send. + /// + /// The size of test messages to send. + public int getMessageSize() + { + return getPropertyAsInteger(MESSAGE_SIZE_PROPNAME); + } + + /// + /// Flag to indicate that the publishing producer should be set up to publish to a destination. + /// + /// Flag to indicate that the publishing producer should be set up to publish to a destination. + public bool getPublisherProducerBind() + { + return getPropertyAsBoolean(PUBLISHER_PRODUCER_BIND_PROPNAME); + } + + /// + /// Flag to indicate that the publishing consumer should be set up to receive from a destination. + /// + /// Flag to indicate that the publishing consumer should be set up to receive from a destination. + public bool getPublisherConsumerBind() + { + return getPropertyAsBoolean(PUBLISHER_CONSUMER_BIND_PROPNAME); + } + + /// + /// Flag to indicate that the receiving producer should be set up to publish to a destination. + /// + /// Flag to indicate that the receiving producer should be set up to publish to a destination. + public bool getReceiverProducerBind() + { + return getPropertyAsBoolean(RECEIVER_PRODUCER_BIND_PROPNAME); + } + + /// + /// Flag to indicate that the receiving consumer should be set up to receive from a destination. + /// + /// Flag to indicate that the receiving consumer should be set up to receive from a destination. + public bool getReceiverConsumerBind() + { + return getPropertyAsBoolean(RECEIVER_CONSUMER_BIND_PROPNAME); + } + + /// + /// Flag to indicate that the publishing consumer should be created and actively listening. + /// + /// Flag to indicate that the publishing consumer should be created. + public bool getPublisherConsumerActive() + { + return getPropertyAsBoolean(PUBLISHER_CONSUMER_ACTIVE_PROPNAME); + } + + /// + /// Flag to indicate that the receiving consumers should be created and actively listening. + /// + /// Flag to indicate that the receiving consumers should be created and actively listening. + public bool getReceiverConsumerActive() + { + return getPropertyAsBoolean(RECEIVER_CONSUMER_ACTIVE_PROPNAME); + } + + /// + /// A root to create all test destination names from. + /// + /// A root to create all test destination names from. + public string getSendDestinationNameRoot() + { + return getProperty(SEND_DESTINATION_NAME_ROOT_PROPNAME); + } + + /// + /// A root to create all receiving destination names from. + /// + /// A root to create all receiving destination names from. + public string getReceiveDestinationNameRoot() + { + return getProperty(RECEIVE_DESTINATION_NAME_ROOT_PROPNAME); + } + + /// + /// Flag to indicate that persistent messages should be used. + /// + /// Flag to indicate that persistent messages should be used. + public bool getPersistentMode() + { + return getPropertyAsBoolean(PERSISTENT_MODE_PROPNAME); + } + + /// + /// Flag to indicate that transactional messages should be sent by the publisher. + /// + /// Flag to indicate that transactional messages should be sent by the publisher. + public bool getPublisherTransacted() + { + return getPropertyAsBoolean(TRANSACTED_PUBLISHER_PROPNAME); + } + + /// + /// Flag to indicate that transactional receives should be used by the receiver. + /// + /// Flag to indicate that transactional receives should be used by the receiver. + public bool getReceiverTransacted() + { + return getPropertyAsBoolean(TRANSACTED_PUBLISHER_PROPNAME); + } + + /// + /// The name of the virtual host to run all tests over. + /// + /// The name of the virtual host to run all tests over. + public string getVirtualHost() + { + return getProperty(VIRTUAL_HOST_PROPNAME); + } + + /// + /// Limiting rate for each sender in messages per second, or zero for unlimited. + /// + /// Limiting rate for each sender in messages per second, or zero for unlimited. + public string getRate() + { + return getProperty(RATE_PROPNAME); + } + + /// + /// Flag to indicate that test messages should be received publish/subscribe style by all receivers. + /// + /// Flag to indicate that test messages should be received publish/subscribe style by all receivers. + public bool getPubsub() + { + return getPropertyAsBoolean(PUBSUB_PROPNAME); + } + + /// + /// The username credentials to run tests with. + /// + /// The username credentials to run tests with. + public string getUsername() + { + return getProperty(USERNAME_PROPNAME); + } + + /// + /// The password credentials to run tests with. + /// + /// The password credentials to run tests with. + public string getPassword() + { + return getProperty(PASSWORD_PROPNAME); + } + + /// + /// The timeout duration to fail tests on, should they receive no messages within it. + /// + /// The timeout duration to fail tests on, should they receive no messages within it. + public long getTimeout() + { + return getPropertyAsLong(TIMEOUT_PROPNAME); + } + + /// + /// The number of messages to batch into each transaction in transational tests. + /// + /// The number of messages to batch into each transaction in transational tests. + public int getTxBatchSize() + { + return getPropertyAsInteger(TX_BATCH_SIZE_PROPNAME); + } + + /// + /// Flag to indicate that tests should use durable destinations. + /// + /// Flag to indicate that tests should use durable destinations. + public bool getDurableDests() + { + return getPropertyAsBoolean(DURABLE_DESTS_PROPNAME); + } + + /// + /// The ack mode for message receivers to use. + /// + /// The ack mode for message receivers to use. + public int getAckMode() + { + return getPropertyAsInteger(ACK_MODE_PROPNAME); + } + + /// + /// Flag to indicate that tests should use durable subscriptions. + /// + /// Flag to indicate that tests should use durable subscriptions. + public bool getDurableSubscription() + { + return getPropertyAsBoolean(DURABLE_SUBSCRIPTION_PROPNAME); + } + + /// + /// The maximum amount of in-flight data, in bytes, that tests should send at any time. + /// + /// The maximum amount of in-flight data, in bytes, that tests should send at any time. + public int getMaxPending() + { + return getPropertyAsInteger(MAX_PENDING_PROPNAME); + } + + /// + /// The size of the prefetch queue to use. + /// + /// The size of the prefetch queue to use. + public int getPrefetch() + { + return getPropertyAsInteger(PREFETCH_PROPNAME); + } + + /// + /// Flag to indicate that subscriptions should be no-local. + /// + /// Flag to indicate that subscriptions should be no-local. + public bool getNoLocal() + { + return getPropertyAsBoolean(NO_LOCAL_PROPNAME); + } + + /// + /// Flag to indicate that subscriptions should be exclusive. + /// + /// Flag to indicate that subscriptions should be exclusive. + public bool getExclusive() + { + return getPropertyAsBoolean(EXCLUSIVE_PROPNAME); + } + + /// + /// Flag to indicate that messages must be delivered immediately. + /// + /// Flag to indicate that messages must be delivered immediately. + public bool getImmediate() + { + return getPropertyAsBoolean(IMMEDIATE_PROPNAME); + } + + /// + /// Flag to indicate that messages must be routable. + /// + /// Flag to indicate that messages must be routable. + public bool getMandatory() + { + return getPropertyAsBoolean(MANDATORY_PROPNAME); + } + + /// + /// Gets the value of a flag to indicate that the publisher should rollback all messages sent. + /// + /// A flag to indicate that the publisher should rollback all messages sent. + public bool getRollbackPublisher() + { + return getPropertyAsBoolean(ROLLBACK_PUBLISHER_PROPNAME); + } + + /// + /// Gets the value of a flag to indicate that the receiver should rollback all messages received, then receive them + /// again. + /// + /// A flag to indicate that the publisher should rollback all messages received. + public bool getRollbackReceiver() + { + return getPropertyAsBoolean(ROLLBACK_RECEIVER_PROPNAME); + } + + /// + /// Gets the behavioural mode of not applicable assertions. Should be one of 'quiet', 'warn' or 'fail'. + /// + /// The behavioural mode of not applicable assertions. + public string getNotApplicableAssertionMode() + { + return getProperty(NOT_APPLICABLE_ASSERTION_PROPNAME); + } + } + */ } \ No newline at end of file diff --git a/dotnet/Qpid.Integration.Tests/framework/sequencers/CircuitFactory.cs b/dotnet/Qpid.Integration.Tests/framework/sequencers/CircuitFactory.cs index 463cf06dfb..4be08c3f38 100644 --- a/dotnet/Qpid.Integration.Tests/framework/sequencers/CircuitFactory.cs +++ b/dotnet/Qpid.Integration.Tests/framework/sequencers/CircuitFactory.cs @@ -1,85 +1,85 @@ -/* - * - * 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. - * - */ -using Apache.Qpid.Integration.Tests.framework; -//using org.apache.qpid.util.ConversationFactory; - -//using uk.co.thebadgerset.junit.extensions.util.ParsedProperties; - -//using javax.jms.JMSException; -//using javax.jms.Message; - -using System.Collections.Generic;//.IList; -//using System.Collections.Generic.IDictionary; -//using java.util.Properties; - -namespace Apache.Qpid.Integration.Tests.framework.sequencers -{ - /// - /// A CircuitFactory is responsibile for creating test circuits appropriate to the context that a test case is - /// running in, and providing an implementation of a standard test procedure over a test circuit. - /// - ///

- ///
CRC Card
Responsibilities - ///
Provide a standard test procedure over a test circuit. - ///
Construct test circuits appropriate to a tests context. - ///
- ///

- public interface CircuitFactory - { - /// - /// Creates a test circuit for the test, configered by the test parameters specified. - /// - /// The test parameters. - /// - /// A test circuit. - Circuit CreateCircuit(TestModel testProperties); - - /// - /// Sets the sender test client to coordinate the test with. - /// - /// The contact details of the sending client in the test. - void SetSender(TestClientDetails sender); - - /// - /// Sets the receiving test client to coordinate the test with. - /// - /// The contact details of the sending client in the test. - void SetReceiver(TestClientDetails receiver); - - /// - /// Supplies the sending test client. - /// - /// The sending test client. - TestClientDetails GetSender(); - - /// - /// Supplies the receiving test client. - /// - /// The receiving test client. - IList GetReceivers(); - - /// - /// Accepts the conversation factory over which to hold the test coordinating conversation. - /// - /// The conversation factory to coordinate the test over. - //void setConversationFactory(ConversationFactory conversationFactory); - } +/* + * + * 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. + * + */ +using Apache.Qpid.Integration.Tests.framework; +//using org.apache.qpid.util.ConversationFactory; + +//using uk.co.thebadgerset.junit.extensions.util.ParsedProperties; + +//using javax.jms.JMSException; +//using javax.jms.Message; + +using System.Collections.Generic;//.IList; +//using System.Collections.Generic.IDictionary; +//using java.util.Properties; + +namespace Apache.Qpid.Integration.Tests.framework.sequencers +{ + /// + /// A CircuitFactory is responsibile for creating test circuits appropriate to the context that a test case is + /// running in, and providing an implementation of a standard test procedure over a test circuit. + /// + ///

+ ///
CRC Card
Responsibilities + ///
Provide a standard test procedure over a test circuit. + ///
Construct test circuits appropriate to a tests context. + ///
+ ///

+ public interface CircuitFactory + { + /// + /// Creates a test circuit for the test, configered by the test parameters specified. + /// + /// The test parameters. + /// + /// A test circuit. + Circuit CreateCircuit(TestModel testProperties); + + /// + /// Sets the sender test client to coordinate the test with. + /// + /// The contact details of the sending client in the test. + void SetSender(TestClientDetails sender); + + /// + /// Sets the receiving test client to coordinate the test with. + /// + /// The contact details of the sending client in the test. + void SetReceiver(TestClientDetails receiver); + + /// + /// Supplies the sending test client. + /// + /// The sending test client. + TestClientDetails GetSender(); + + /// + /// Supplies the receiving test client. + /// + /// The receiving test client. + IList GetReceivers(); + + /// + /// Accepts the conversation factory over which to hold the test coordinating conversation. + /// + /// The conversation factory to coordinate the test over. + //void setConversationFactory(ConversationFactory conversationFactory); + } } \ No newline at end of file diff --git a/dotnet/Qpid.Integration.Tests/interactive/FailoverTest.cs b/dotnet/Qpid.Integration.Tests/interactive/FailoverTest.cs index 547266a7a5..142ac40b27 100644 --- a/dotnet/Qpid.Integration.Tests/interactive/FailoverTest.cs +++ b/dotnet/Qpid.Integration.Tests/interactive/FailoverTest.cs @@ -73,12 +73,12 @@ namespace Apache.Qpid.Integration.Tests.interactive /// Used to wait for test completion on. private static object testComplete = new Object(); - /// Used to wait for failover completion on. + /// Used to wait for failover completion on. private static object failoverComplete = new Object(); bool failedOver=false; - /// Used to record the extra message count (1) if the message sent right after failover actually made it to the new broker. + /// Used to record the extra message count (1) if the message sent right after failover actually made it to the new broker. int _extraMessage = 0; /// diff --git a/dotnet/Qpid.Integration.Tests/interactive/SendReceiveTest.cs b/dotnet/Qpid.Integration.Tests/interactive/SendReceiveTest.cs index ebc9307c2e..68d7a2ae68 100644 --- a/dotnet/Qpid.Integration.Tests/interactive/SendReceiveTest.cs +++ b/dotnet/Qpid.Integration.Tests/interactive/SendReceiveTest.cs @@ -1,181 +1,181 @@ -/* - * - * 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. - * - */ -using System; -using System.Threading; -using log4net; -using NUnit.Framework; -using Apache.Qpid.Messaging; -using Apache.Qpid.Client.Qms; -using Apache.Qpid.Client; -using Apache.Qpid.Integration.Tests.testcases; - -namespace Apache.Qpid.Integration.Tests.interactive -{ - /// - /// SendReceiveTest provides a quick interactive send-receive test, where the user is prompted to trigger each send or receive. - /// - ///

- ///
CRC Card
Responsibilities Collaborations - ///
Run an interactive send-receive loop prompting user to trigger each event. - ///
- ///

- [TestFixture, Category("Interactive")] - public class SendReceiveTest : BaseMessagingTestFixture - { - /// Used for debugging purposes. - private static ILog log = LogManager.GetLogger(typeof(SendReceiveTest)); - - /// Defines the name of the test topic to use with the tests. - public const string TEST_ROUTING_KEY = "quicktestkey"; - - /// The number of consumers to test. - private const int CONSUMER_COUNT = 5; - - /// The number of test messages to send. - private const int MESSAGE_COUNT = 10; - - /// Monitor used to signal succesfull receipt of all test messages. - AutoResetEvent _finishedEvent; - - /// Used to count test messages received so far. - private int _messageReceivedCount; - - /// Used to hold the expected number of messages to receive. - private int expectedMessageCount; - - /// Flag used to indicate that all messages really were received, and that the test did not just time out. - private bool allReceived; - - /// Creates one producing end-point and many consuming end-points connected on a topic. - [SetUp] - public override void Init() - { - base.Init(); - - // Reset all test counts and flags. - _messageReceivedCount = 0; - allReceived = false; - _finishedEvent = new AutoResetEvent(false); - } - - /// Cleans up all test end-points. - [TearDown] - public override void Shutdown() - { - try - { - // Close all end points for producer and consumers. - // Producer is on 0, and consumers on 1 .. n, so loop is from 0 to n inclusive. - for (int i = 0; i <= CONSUMER_COUNT; i++) - { - CloseEndPoint(i); - } - } - finally - { - base.Shutdown(); - } - } - - /// Check that all consumers on a topic each receive all message on it. - [Test] - public void AllConsumerReceiveAllMessagesOnTopic() - { - // Create end-points for all the consumers in the test. - for (int i = 1; i <= CONSUMER_COUNT; i++) - { - SetUpEndPoint(i, false, true, TEST_ROUTING_KEY + testId, AcknowledgeMode.AutoAcknowledge, false, ExchangeNameDefaults.TOPIC, - true, false, null); - testConsumer[i].OnMessage += new MessageReceivedDelegate(OnMessage); - } - - // Create an end-point to publish to the test topic. - SetUpEndPoint(0, true, false, TEST_ROUTING_KEY + testId, AcknowledgeMode.AutoAcknowledge, false, ExchangeNameDefaults.TOPIC, - true, false, null); - - expectedMessageCount = (MESSAGE_COUNT * CONSUMER_COUNT); - - PromptAndWait("Press to send..."); - - for (int i = 0; i < MESSAGE_COUNT; i++) - { - testProducer[0].Send(testChannel[0].CreateTextMessage("A")); - } - - _finishedEvent.WaitOne(new TimeSpan(0, 0, 0, 10), false); - - PromptAndWait("Press to complete test..."); - - // Check that all messages really were received. - Assert.IsTrue(allReceived, "All messages were not received, only got " + _messageReceivedCount + " but wanted " + expectedMessageCount); - } - - /// Check that consumers on the same queue receive each message once accross all consumers. - //[Test] - public void AllConsumerReceiveAllMessagesOnDirect() - { - // Create end-points for all the consumers in the test. - for (int i = 1; i <= CONSUMER_COUNT; i++) - { - SetUpEndPoint(i, false, true, TEST_ROUTING_KEY + testId, AcknowledgeMode.AutoAcknowledge, false, ExchangeNameDefaults.DIRECT, - true, false, null); - testConsumer[i].OnMessage += new MessageReceivedDelegate(OnMessage); - } - - // Create an end-point to publish to the test topic. - SetUpEndPoint(0, true, false, TEST_ROUTING_KEY + testId, AcknowledgeMode.AutoAcknowledge, false, ExchangeNameDefaults.DIRECT, - true, false, null); - - expectedMessageCount = MESSAGE_COUNT; - - for (int i = 0; i < MESSAGE_COUNT; i++) - { - testProducer[0].Send(testChannel[0].CreateTextMessage("A")); - } - - _finishedEvent.WaitOne(new TimeSpan(0, 0, 0, 10), false); - - // Check that all messages really were received. - Assert.IsTrue(allReceived, "All messages were not received, only got: " + _messageReceivedCount + " but wanted " + expectedMessageCount); - } - - /// Atomically increments the message count on every message, and signals once all messages in the test are received. - public void OnMessage(IMessage m) - { - int newCount = Interlocked.Increment(ref _messageReceivedCount); - - if (newCount >= expectedMessageCount) - { - allReceived = true; - _finishedEvent.Set(); - } - } - - /// Prompts the user on stdout and waits for a reply on stdin, using the specified prompt message. - /// - /// The message to prompt the user with. - private void PromptAndWait(string message) - { - Console.WriteLine("\n" + message); - Console.ReadLine(); - } - } +/* + * + * 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. + * + */ +using System; +using System.Threading; +using log4net; +using NUnit.Framework; +using Apache.Qpid.Messaging; +using Apache.Qpid.Client.Qms; +using Apache.Qpid.Client; +using Apache.Qpid.Integration.Tests.testcases; + +namespace Apache.Qpid.Integration.Tests.interactive +{ + /// + /// SendReceiveTest provides a quick interactive send-receive test, where the user is prompted to trigger each send or receive. + /// + ///

+ ///
CRC Card
Responsibilities Collaborations + ///
Run an interactive send-receive loop prompting user to trigger each event. + ///
+ ///

+ [TestFixture, Category("Interactive")] + public class SendReceiveTest : BaseMessagingTestFixture + { + /// Used for debugging purposes. + private static ILog log = LogManager.GetLogger(typeof(SendReceiveTest)); + + /// Defines the name of the test topic to use with the tests. + public const string TEST_ROUTING_KEY = "quicktestkey"; + + /// The number of consumers to test. + private const int CONSUMER_COUNT = 5; + + /// The number of test messages to send. + private const int MESSAGE_COUNT = 10; + + /// Monitor used to signal succesfull receipt of all test messages. + AutoResetEvent _finishedEvent; + + /// Used to count test messages received so far. + private int _messageReceivedCount; + + /// Used to hold the expected number of messages to receive. + private int expectedMessageCount; + + /// Flag used to indicate that all messages really were received, and that the test did not just time out. + private bool allReceived; + + /// Creates one producing end-point and many consuming end-points connected on a topic. + [SetUp] + public override void Init() + { + base.Init(); + + // Reset all test counts and flags. + _messageReceivedCount = 0; + allReceived = false; + _finishedEvent = new AutoResetEvent(false); + } + + /// Cleans up all test end-points. + [TearDown] + public override void Shutdown() + { + try + { + // Close all end points for producer and consumers. + // Producer is on 0, and consumers on 1 .. n, so loop is from 0 to n inclusive. + for (int i = 0; i <= CONSUMER_COUNT; i++) + { + CloseEndPoint(i); + } + } + finally + { + base.Shutdown(); + } + } + + /// Check that all consumers on a topic each receive all message on it. + [Test] + public void AllConsumerReceiveAllMessagesOnTopic() + { + // Create end-points for all the consumers in the test. + for (int i = 1; i <= CONSUMER_COUNT; i++) + { + SetUpEndPoint(i, false, true, TEST_ROUTING_KEY + testId, AcknowledgeMode.AutoAcknowledge, false, ExchangeNameDefaults.TOPIC, + true, false, null); + testConsumer[i].OnMessage += new MessageReceivedDelegate(OnMessage); + } + + // Create an end-point to publish to the test topic. + SetUpEndPoint(0, true, false, TEST_ROUTING_KEY + testId, AcknowledgeMode.AutoAcknowledge, false, ExchangeNameDefaults.TOPIC, + true, false, null); + + expectedMessageCount = (MESSAGE_COUNT * CONSUMER_COUNT); + + PromptAndWait("Press to send..."); + + for (int i = 0; i < MESSAGE_COUNT; i++) + { + testProducer[0].Send(testChannel[0].CreateTextMessage("A")); + } + + _finishedEvent.WaitOne(new TimeSpan(0, 0, 0, 10), false); + + PromptAndWait("Press to complete test..."); + + // Check that all messages really were received. + Assert.IsTrue(allReceived, "All messages were not received, only got " + _messageReceivedCount + " but wanted " + expectedMessageCount); + } + + /// Check that consumers on the same queue receive each message once accross all consumers. + //[Test] + public void AllConsumerReceiveAllMessagesOnDirect() + { + // Create end-points for all the consumers in the test. + for (int i = 1; i <= CONSUMER_COUNT; i++) + { + SetUpEndPoint(i, false, true, TEST_ROUTING_KEY + testId, AcknowledgeMode.AutoAcknowledge, false, ExchangeNameDefaults.DIRECT, + true, false, null); + testConsumer[i].OnMessage += new MessageReceivedDelegate(OnMessage); + } + + // Create an end-point to publish to the test topic. + SetUpEndPoint(0, true, false, TEST_ROUTING_KEY + testId, AcknowledgeMode.AutoAcknowledge, false, ExchangeNameDefaults.DIRECT, + true, false, null); + + expectedMessageCount = MESSAGE_COUNT; + + for (int i = 0; i < MESSAGE_COUNT; i++) + { + testProducer[0].Send(testChannel[0].CreateTextMessage("A")); + } + + _finishedEvent.WaitOne(new TimeSpan(0, 0, 0, 10), false); + + // Check that all messages really were received. + Assert.IsTrue(allReceived, "All messages were not received, only got: " + _messageReceivedCount + " but wanted " + expectedMessageCount); + } + + /// Atomically increments the message count on every message, and signals once all messages in the test are received. + public void OnMessage(IMessage m) + { + int newCount = Interlocked.Increment(ref _messageReceivedCount); + + if (newCount >= expectedMessageCount) + { + allReceived = true; + _finishedEvent.Set(); + } + } + + /// Prompts the user on stdout and waits for a reply on stdin, using the specified prompt message. + /// + /// The message to prompt the user with. + private void PromptAndWait(string message) + { + Console.WriteLine("\n" + message); + Console.ReadLine(); + } + } } \ No newline at end of file diff --git a/dotnet/Qpid.Integration.Tests/interop/InteropClientTestCase.cs b/dotnet/Qpid.Integration.Tests/interop/InteropClientTestCase.cs index c1283454c5..09361b33e8 100644 --- a/dotnet/Qpid.Integration.Tests/interop/InteropClientTestCase.cs +++ b/dotnet/Qpid.Integration.Tests/interop/InteropClientTestCase.cs @@ -1,87 +1,87 @@ -/* - * - * 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. - * - */ -using System; -using System.Text; -using Apache.Qpid.Messaging; - -namespace Apache.Qpid.Integration.Tests.interop -{ - /// Defines the possible test case roles that an interop test case can take on. - public enum Roles { SENDER, RECEIVER }; - - /// - /// InteropClientTestCase provides an interface that classes implementing test cases from the interop testing spec - /// (http://cwiki.apache.org/confluence/display/qpid/Interop+Testing+Specification) should implement. - /// - ///

- ///
CRC Card
Responsibilities - ///
Supply the name of the test case that this implements. - ///
Accept/Reject invites based on test parameters. - ///
Adapt to assigned roles. - ///
Perform test case actions. - ///
Generate test reports. - ///
- ///

- interface InteropClientTestCase - { - /// - /// Should provide the name of the test case that this class implements. The exact names are defined in the - /// interop testing spec. - /// - /// - /// The name of the test case that this implements. - string GetName(); - - /// - /// Determines whether the test invite that matched this test case is acceptable. - /// - /// - /// The invitation to accept or reject. - /// - /// true to accept the invitation, false to reject it. - /// - /// @throws JMSException Any JMSException resulting from reading the message are allowed to fall through. - bool AcceptInvite(IMessage inviteMessage); - - /// - /// 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. - /// - /// - /// The role to be played; sender or receiver. - /// The role assingment message, contains the full test parameters. - void AssignRole(Roles role, IMessage assignRoleMessage); - - /// - /// Performs the test case actions. - /// - void Start(); - - /// - /// Gets a report on the actions performed by the test case in its assigned role. - /// - /// - /// The session to create the report message in. - /// - /// The report message. - IMessage GetReport(IChannel channel); - } -} +/* + * + * 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. + * + */ +using System; +using System.Text; +using Apache.Qpid.Messaging; + +namespace Apache.Qpid.Integration.Tests.interop +{ + /// Defines the possible test case roles that an interop test case can take on. + public enum Roles { SENDER, RECEIVER }; + + /// + /// InteropClientTestCase provides an interface that classes implementing test cases from the interop testing spec + /// (http://cwiki.apache.org/confluence/display/qpid/Interop+Testing+Specification) should implement. + /// + ///

+ ///
CRC Card
Responsibilities + ///
Supply the name of the test case that this implements. + ///
Accept/Reject invites based on test parameters. + ///
Adapt to assigned roles. + ///
Perform test case actions. + ///
Generate test reports. + ///
+ ///

+ interface InteropClientTestCase + { + /// + /// Should provide the name of the test case that this class implements. The exact names are defined in the + /// interop testing spec. + /// + /// + /// The name of the test case that this implements. + string GetName(); + + /// + /// Determines whether the test invite that matched this test case is acceptable. + /// + /// + /// The invitation to accept or reject. + /// + /// true to accept the invitation, false to reject it. + /// + /// @throws JMSException Any JMSException resulting from reading the message are allowed to fall through. + bool AcceptInvite(IMessage inviteMessage); + + /// + /// 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. + /// + /// + /// The role to be played; sender or receiver. + /// The role assingment message, contains the full test parameters. + void AssignRole(Roles role, IMessage assignRoleMessage); + + /// + /// Performs the test case actions. + /// + void Start(); + + /// + /// Gets a report on the actions performed by the test case in its assigned role. + /// + /// + /// The session to create the report message in. + /// + /// The report message. + IMessage GetReport(IChannel channel); + } +} diff --git a/dotnet/Qpid.Integration.Tests/interop/TestCases/TestCase1DummyRun.cs b/dotnet/Qpid.Integration.Tests/interop/TestCases/TestCase1DummyRun.cs index a63bb84517..d908b7af0b 100644 --- a/dotnet/Qpid.Integration.Tests/interop/TestCases/TestCase1DummyRun.cs +++ b/dotnet/Qpid.Integration.Tests/interop/TestCases/TestCase1DummyRun.cs @@ -1,89 +1,89 @@ -/* - * - * 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. - * - */ -using System; -using System.Text; -using log4net; -using Apache.Qpid.Messaging; - -namespace Apache.Qpid.Integration.Tests.interop.TestCases -{ - /// - /// Implements tet case 1, dummy run. This test case sends no test messages, it exists to confirm that the test harness - /// is interacting with the coordinator correctly. - /// - ///

- ///
CRC Card
Responsibilities Collaborations - ///
Supply the name of the test case that this implements. - ///
Accept/Reject invites based on test parameters. - ///
Adapt to assigned roles. - ///
Perform test case actions. - ///
Generate test reports. - ///
- ///

- public class TestCase1DummyRun : InteropClientTestCase - { - private static ILog log = LogManager.GetLogger(typeof(TestCase1DummyRun)); - - public String GetName() - { - log.Debug("public String getName(): called"); - - return "TC1_DummyRun"; - } - - public bool AcceptInvite(IMessage inviteMessage) - { - log.Debug("public boolean acceptInvite(Message inviteMessage): called"); - - // Test parameters don't matter, accept all invites. - return true; - } - - public void AssignRole(Roles role, IMessage assignRoleMessage) - { - log.Debug("public void assignRole(Roles role, Message assignRoleMessage): called"); - - // Do nothing, both roles are the same. - } - - public void Start() - { - log.Debug("public void start(): called"); - - // Do nothing. - } - - public IMessage GetReport(IChannel channel) - { - log.Debug("public Message getReport(Session session): called"); - - // Generate a dummy report, the coordinator expects a report but doesn't care what it is. - return channel.CreateTextMessage("Dummy Run, Ok."); - } - - public void OnMessage(IMessage message) - { - log.Debug("public void onMessage(Message message = " + message + "): called"); - - // Ignore any messages. - } - } -} +/* + * + * 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. + * + */ +using System; +using System.Text; +using log4net; +using Apache.Qpid.Messaging; + +namespace Apache.Qpid.Integration.Tests.interop.TestCases +{ + /// + /// Implements tet case 1, dummy run. This test case sends no test messages, it exists to confirm that the test harness + /// is interacting with the coordinator correctly. + /// + ///

+ ///
CRC Card
Responsibilities Collaborations + ///
Supply the name of the test case that this implements. + ///
Accept/Reject invites based on test parameters. + ///
Adapt to assigned roles. + ///
Perform test case actions. + ///
Generate test reports. + ///
+ ///

+ public class TestCase1DummyRun : InteropClientTestCase + { + private static ILog log = LogManager.GetLogger(typeof(TestCase1DummyRun)); + + public String GetName() + { + log.Debug("public String getName(): called"); + + return "TC1_DummyRun"; + } + + public bool AcceptInvite(IMessage inviteMessage) + { + log.Debug("public boolean acceptInvite(Message inviteMessage): called"); + + // Test parameters don't matter, accept all invites. + return true; + } + + public void AssignRole(Roles role, IMessage assignRoleMessage) + { + log.Debug("public void assignRole(Roles role, Message assignRoleMessage): called"); + + // Do nothing, both roles are the same. + } + + public void Start() + { + log.Debug("public void start(): called"); + + // Do nothing. + } + + public IMessage GetReport(IChannel channel) + { + log.Debug("public Message getReport(Session session): called"); + + // Generate a dummy report, the coordinator expects a report but doesn't care what it is. + return channel.CreateTextMessage("Dummy Run, Ok."); + } + + public void OnMessage(IMessage message) + { + log.Debug("public void onMessage(Message message = " + message + "): called"); + + // Ignore any messages. + } + } +} diff --git a/dotnet/Qpid.Integration.Tests/interop/TestCases/TestCase2BasicP2P.cs b/dotnet/Qpid.Integration.Tests/interop/TestCases/TestCase2BasicP2P.cs index 3460d9091f..8993da832e 100644 --- a/dotnet/Qpid.Integration.Tests/interop/TestCases/TestCase2BasicP2P.cs +++ b/dotnet/Qpid.Integration.Tests/interop/TestCases/TestCase2BasicP2P.cs @@ -1,205 +1,205 @@ -/* - * - * 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. - * - */ -using System; -using System.Text; -using log4net; -using Apache.Qpid.Messaging; - -namespace Apache.Qpid.Integration.Tests.interop.TestCases -{ - /// - /// Implements test case 2, basic P2P. Sends/receives a specified number of messages to a specified route on the - /// default direct exchange. Produces reports on the actual number of messages sent/received. - /// - ///

- ///
CRC Card
Responsibilities Collaborations - ///
Supply the name of the test case that this implements. - ///
Accept/Reject invites based on test parameters. - ///
Adapt to assigned roles. - ///
Send required number of test messages. - ///
Generate test reports. - ///
- ///

- public class TestCase2BasicP2P : InteropClientTestCase - { - /// Used for debugging. - private static ILog log = LogManager.GetLogger(typeof(TestCase2BasicP2P)); - - /// 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 routing key to send them to on the default direct exchange. - private string sendDestination; - - /// The connection to send the test messages on. - private IConnection connection; - - /// The session to send the test messages on. - private IChannel channel; - - /// The producer to send the test messages with. - private IMessagePublisher publisher; - - /// - /// Should provide the name of the test case that this class implements. The exact names are defined in the - /// interop testing spec. - /// - /// - /// The name of the test case that this implements. - public String GetName() - { - log.Debug("public String GetName(): called"); - - return "TC2_BasicP2P"; - } - - /// - /// Determines whether the test invite that matched this test case is acceptable. - /// - /// - /// The invitation to accept or reject. - /// - /// true to accept the invitation, false to reject it. - public bool AcceptInvite(IMessage inviteMessage) - { - 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. - /// - /// - /// The role to be played; sender or receiver. - /// The role assingment message, contains the full test parameters. - public void AssignRole(Roles role, IMessage assignRoleMessage) - { - 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; - - // Create a new connection to pass the test messages on. - connection = - TestClient.CreateConnection(TestClient.brokerUrl, TestClient.virtualHost); - channel = connection.CreateChannel(false, AcknowledgeMode.AutoAcknowledge); - - // Extract and retain the test parameters. - numMessages = assignRoleMessage.Headers.GetInt("P2P_NUM_MESSAGES"); - string queueAndKeyName = assignRoleMessage.Headers.GetString("P2P_QUEUE_AND_KEY_NAME"); - channel.DeclareQueue(queueAndKeyName, false, true, true); - channel.Bind(queueAndKeyName, ExchangeNameDefaults.DIRECT, queueAndKeyName); - sendDestination = queueAndKeyName; - - log.Debug("numMessages = " + numMessages); - log.Debug("sendDestination = " + sendDestination); - log.Debug("role = " + role); - - switch (role) - { - // Check if the sender role is being assigned, and set up a message producer if so. - case Roles.SENDER: - publisher = channel.CreatePublisherBuilder() - .WithExchangeName(ExchangeNameDefaults.DIRECT) - .WithRoutingKey(sendDestination) - .Create(); - break; - - // Otherwise the receiver role is being assigned, so set this up to listen for messages. - case Roles.RECEIVER: - IMessageConsumer consumer = channel.CreateConsumerBuilder(sendDestination).Create(); - consumer.OnMessage += new MessageReceivedDelegate(OnMessage); - - break; - } - - connection.Start(); - } - - /// Performs the test case actions. - public void Start() - { - log.Debug("public void start(): called"); - - // Check that the sender role is being performed. - if (role == Roles.SENDER) - { - IMessage testMessage = channel.CreateTextMessage("test"); - - for (int i = 0; i < numMessages; i++) - { - publisher.Send(testMessage); - - // Increment the message count. - messageCount++; - } - } - } - - /// - /// Gets a report on the actions performed by the test case in its assigned role. - /// - /// - /// The session to create the report message in. - /// - /// The report message. - public IMessage GetReport(IChannel channel) - { - log.Debug("public Message GetReport(IChannel channel): called"); - - // Close the test connection. - //connection.Stop(); - - // Generate a report message containing the count of the number of messages passed. - IMessage report = channel.CreateMessage(); - //report.Headers.SetString("CONTROL_TYPE", "REPORT"); - report.Headers.SetInt("MESSAGE_COUNT", messageCount); - - return report; - } - - /// - /// Counts incoming test messages. - /// - /// - /// The incoming test message. - public void OnMessage(IMessage message) - { - log.Debug("public void OnMessage(IMessage message = " + message + "): called"); - - // Increment the message count. - messageCount++; - } - } -} +/* + * + * 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. + * + */ +using System; +using System.Text; +using log4net; +using Apache.Qpid.Messaging; + +namespace Apache.Qpid.Integration.Tests.interop.TestCases +{ + /// + /// Implements test case 2, basic P2P. Sends/receives a specified number of messages to a specified route on the + /// default direct exchange. Produces reports on the actual number of messages sent/received. + /// + ///

+ ///
CRC Card
Responsibilities Collaborations + ///
Supply the name of the test case that this implements. + ///
Accept/Reject invites based on test parameters. + ///
Adapt to assigned roles. + ///
Send required number of test messages. + ///
Generate test reports. + ///
+ ///

+ public class TestCase2BasicP2P : InteropClientTestCase + { + /// Used for debugging. + private static ILog log = LogManager.GetLogger(typeof(TestCase2BasicP2P)); + + /// 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 routing key to send them to on the default direct exchange. + private string sendDestination; + + /// The connection to send the test messages on. + private IConnection connection; + + /// The session to send the test messages on. + private IChannel channel; + + /// The producer to send the test messages with. + private IMessagePublisher publisher; + + /// + /// Should provide the name of the test case that this class implements. The exact names are defined in the + /// interop testing spec. + /// + /// + /// The name of the test case that this implements. + public String GetName() + { + log.Debug("public String GetName(): called"); + + return "TC2_BasicP2P"; + } + + /// + /// Determines whether the test invite that matched this test case is acceptable. + /// + /// + /// The invitation to accept or reject. + /// + /// true to accept the invitation, false to reject it. + public bool AcceptInvite(IMessage inviteMessage) + { + 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. + /// + /// + /// The role to be played; sender or receiver. + /// The role assingment message, contains the full test parameters. + public void AssignRole(Roles role, IMessage assignRoleMessage) + { + 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; + + // Create a new connection to pass the test messages on. + connection = + TestClient.CreateConnection(TestClient.brokerUrl, TestClient.virtualHost); + channel = connection.CreateChannel(false, AcknowledgeMode.AutoAcknowledge); + + // Extract and retain the test parameters. + numMessages = assignRoleMessage.Headers.GetInt("P2P_NUM_MESSAGES"); + string queueAndKeyName = assignRoleMessage.Headers.GetString("P2P_QUEUE_AND_KEY_NAME"); + channel.DeclareQueue(queueAndKeyName, false, true, true); + channel.Bind(queueAndKeyName, ExchangeNameDefaults.DIRECT, queueAndKeyName); + sendDestination = queueAndKeyName; + + log.Debug("numMessages = " + numMessages); + log.Debug("sendDestination = " + sendDestination); + log.Debug("role = " + role); + + switch (role) + { + // Check if the sender role is being assigned, and set up a message producer if so. + case Roles.SENDER: + publisher = channel.CreatePublisherBuilder() + .WithExchangeName(ExchangeNameDefaults.DIRECT) + .WithRoutingKey(sendDestination) + .Create(); + break; + + // Otherwise the receiver role is being assigned, so set this up to listen for messages. + case Roles.RECEIVER: + IMessageConsumer consumer = channel.CreateConsumerBuilder(sendDestination).Create(); + consumer.OnMessage += new MessageReceivedDelegate(OnMessage); + + break; + } + + connection.Start(); + } + + /// Performs the test case actions. + public void Start() + { + log.Debug("public void start(): called"); + + // Check that the sender role is being performed. + if (role == Roles.SENDER) + { + IMessage testMessage = channel.CreateTextMessage("test"); + + for (int i = 0; i < numMessages; i++) + { + publisher.Send(testMessage); + + // Increment the message count. + messageCount++; + } + } + } + + /// + /// Gets a report on the actions performed by the test case in its assigned role. + /// + /// + /// The session to create the report message in. + /// + /// The report message. + public IMessage GetReport(IChannel channel) + { + log.Debug("public Message GetReport(IChannel channel): called"); + + // Close the test connection. + //connection.Stop(); + + // Generate a report message containing the count of the number of messages passed. + IMessage report = channel.CreateMessage(); + //report.Headers.SetString("CONTROL_TYPE", "REPORT"); + report.Headers.SetInt("MESSAGE_COUNT", messageCount); + + return report; + } + + /// + /// Counts incoming test messages. + /// + /// + /// The incoming test message. + public void OnMessage(IMessage message) + { + log.Debug("public void OnMessage(IMessage message = " + message + "): called"); + + // Increment the message count. + messageCount++; + } + } +} diff --git a/dotnet/Qpid.Integration.Tests/interop/TestCases/TestCase3BasicPubSub.cs b/dotnet/Qpid.Integration.Tests/interop/TestCases/TestCase3BasicPubSub.cs index fd0db10fa5..79c0322bcd 100644 --- a/dotnet/Qpid.Integration.Tests/interop/TestCases/TestCase3BasicPubSub.cs +++ b/dotnet/Qpid.Integration.Tests/interop/TestCases/TestCase3BasicPubSub.cs @@ -1,244 +1,244 @@ -/* - * - * 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. - * - */ -using System; -using System.Text; -using log4net; -using Apache.Qpid.Messaging; - -namespace Apache.Qpid.Integration.Tests.interop.TestCases -{ - /// - /// 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. - /// - ///

- ///
CRC Card
Responsibilities Collaborations - ///
Supply the name of the test case that this implements. - ///
Accept/Reject invites based on test parameters. - ///
Adapt to assigned roles. - ///
Send required number of test messages using pub/sub. - ///
Generate test reports. - ///
- ///

- public class TestCase3BasicPubSub : InteropClientTestCase - { - /// Used for debugging. - private static ILog log = LogManager.GetLogger(typeof(TestCase3BasicPubSub)); - - /// 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 string sendDestination; - - /// The connections to send/receive the test messages on. - private IConnection[] connection; - - /// The sessions to send/receive the test messages on. - private IChannel[] channel; - - /// The producer to send the test messages with. - IMessagePublisher publisher; - - /// - /// Should provide the name of the test case that this class implements. The exact names are defined in the - /// interop testing spec. - /// - /// - /// 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. - /// - /// - /// The invitation to accept or reject. - /// - /// true to accept the invitation, false to reject it. - public bool AcceptInvite(IMessage inviteMessage) - { - log.Debug("public boolean AcceptInvite(IMessage 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. - /// - /// - /// The role to be played; sender or receiver. - /// The role assingment message, contains the full test parameters. - public void AssignRole(Roles role, IMessage assignRoleMessage) - { - log.Debug("public void assignRole(Roles role = " + role + ", IMessage 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.Headers.GetInt("PUBSUB_NUM_MESSAGES"); - numReceivers = assignRoleMessage.Headers.GetInt("PUBSUB_NUM_RECEIVERS"); - string sendKey = assignRoleMessage.Headers.GetString("PUBSUB_KEY"); - sendDestination = sendKey; - - 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 Roles.SENDER: - // Create a new connection to pass the test messages on. - connection = new IConnection[1]; - channel = new IChannel[1]; - - connection[0] = - TestClient.CreateConnection(TestClient.brokerUrl, TestClient.virtualHost); - channel[0] = connection[0].CreateChannel(false, AcknowledgeMode.AutoAcknowledge); - - // Extract and retain the test parameters. - publisher = channel[0].CreatePublisherBuilder() - .WithExchangeName(ExchangeNameDefaults.TOPIC) - .WithRoutingKey(sendDestination) - .WithMandatory(false) - .WithImmediate(false) - .Create(); - break; - - // Otherwise the receiver role is being assigned, so set this up to listen for messages on the required number - // of receiver connections. - case Roles.RECEIVER: - // Create the required number of receiver connections. - connection = new IConnection[numReceivers]; - channel = new IChannel[numReceivers]; - - for (int i = 0; i < numReceivers; i++) - { - connection[i] = - TestClient.CreateConnection(TestClient.brokerUrl, TestClient.virtualHost); - channel[i] = connection[i].CreateChannel(false, AcknowledgeMode.AutoAcknowledge); - - IMessageConsumer consumer = channel[i].CreateConsumerBuilder(sendDestination).Create(); - consumer.OnMessage += new MessageReceivedDelegate(OnMessage); - } - - break; - } - - // Start all the connection dispatcher threads running. - foreach (IConnection con in connection) - { - con.Start(); - } - } - - /// - /// Performs the test case actions. - /// - public void Start() - { - log.Debug("public void Start(): called"); - - // Check that the sender role is being performed. - if (role == Roles.SENDER) - { - IMessage testMessage = channel[0].CreateTextMessage("test"); - - for (int i = 0; i < numMessages; i++) - { - publisher.Send(testMessage); - - // Increment the message count. - messageCount++; - } - } - } - - /// - /// Gets a report on the actions performed by the test case in its assigned role. - /// - /// - /// The session to create the report message in. - /// - /// The report message. - public IMessage GetReport(IChannel channel) - { - log.Debug("public IMessage getReport(IChannel channel): called"); - - // Close the test connections. - /*foreach (IConnection con in connection) - { - try - { - con.Stop(); - } - catch (AMQConnectionClosedException e) - { - // The connection has already died due to an error. Log this as a warning. - log.Warn("Connection already closed."); - } - }*/ - - // Generate a report message containing the count of the number of messages passed. - IMessage report = channel.CreateMessage(); - //report.Headers.SetString("CONTROL_TYPE", "REPORT"); - report.Headers.SetInt("MESSAGE_COUNT", messageCount); - - return report; - } - - /// - /// Counts incoming test messages. - /// - /// - /// The incoming test message. - public void OnMessage(IMessage message) - { - log.Debug("public void onMessage(IMessage message = " + message + "): called"); - - // Increment the message count. - messageCount++; - } - } -} +/* + * + * 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. + * + */ +using System; +using System.Text; +using log4net; +using Apache.Qpid.Messaging; + +namespace Apache.Qpid.Integration.Tests.interop.TestCases +{ + /// + /// 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. + /// + ///

+ ///
CRC Card
Responsibilities Collaborations + ///
Supply the name of the test case that this implements. + ///
Accept/Reject invites based on test parameters. + ///
Adapt to assigned roles. + ///
Send required number of test messages using pub/sub. + ///
Generate test reports. + ///
+ ///

+ public class TestCase3BasicPubSub : InteropClientTestCase + { + /// Used for debugging. + private static ILog log = LogManager.GetLogger(typeof(TestCase3BasicPubSub)); + + /// 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 string sendDestination; + + /// The connections to send/receive the test messages on. + private IConnection[] connection; + + /// The sessions to send/receive the test messages on. + private IChannel[] channel; + + /// The producer to send the test messages with. + IMessagePublisher publisher; + + /// + /// Should provide the name of the test case that this class implements. The exact names are defined in the + /// interop testing spec. + /// + /// + /// 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. + /// + /// + /// The invitation to accept or reject. + /// + /// true to accept the invitation, false to reject it. + public bool AcceptInvite(IMessage inviteMessage) + { + log.Debug("public boolean AcceptInvite(IMessage 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. + /// + /// + /// The role to be played; sender or receiver. + /// The role assingment message, contains the full test parameters. + public void AssignRole(Roles role, IMessage assignRoleMessage) + { + log.Debug("public void assignRole(Roles role = " + role + ", IMessage 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.Headers.GetInt("PUBSUB_NUM_MESSAGES"); + numReceivers = assignRoleMessage.Headers.GetInt("PUBSUB_NUM_RECEIVERS"); + string sendKey = assignRoleMessage.Headers.GetString("PUBSUB_KEY"); + sendDestination = sendKey; + + 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 Roles.SENDER: + // Create a new connection to pass the test messages on. + connection = new IConnection[1]; + channel = new IChannel[1]; + + connection[0] = + TestClient.CreateConnection(TestClient.brokerUrl, TestClient.virtualHost); + channel[0] = connection[0].CreateChannel(false, AcknowledgeMode.AutoAcknowledge); + + // Extract and retain the test parameters. + publisher = channel[0].CreatePublisherBuilder() + .WithExchangeName(ExchangeNameDefaults.TOPIC) + .WithRoutingKey(sendDestination) + .WithMandatory(false) + .WithImmediate(false) + .Create(); + break; + + // Otherwise the receiver role is being assigned, so set this up to listen for messages on the required number + // of receiver connections. + case Roles.RECEIVER: + // Create the required number of receiver connections. + connection = new IConnection[numReceivers]; + channel = new IChannel[numReceivers]; + + for (int i = 0; i < numReceivers; i++) + { + connection[i] = + TestClient.CreateConnection(TestClient.brokerUrl, TestClient.virtualHost); + channel[i] = connection[i].CreateChannel(false, AcknowledgeMode.AutoAcknowledge); + + IMessageConsumer consumer = channel[i].CreateConsumerBuilder(sendDestination).Create(); + consumer.OnMessage += new MessageReceivedDelegate(OnMessage); + } + + break; + } + + // Start all the connection dispatcher threads running. + foreach (IConnection con in connection) + { + con.Start(); + } + } + + /// + /// Performs the test case actions. + /// + public void Start() + { + log.Debug("public void Start(): called"); + + // Check that the sender role is being performed. + if (role == Roles.SENDER) + { + IMessage testMessage = channel[0].CreateTextMessage("test"); + + for (int i = 0; i < numMessages; i++) + { + publisher.Send(testMessage); + + // Increment the message count. + messageCount++; + } + } + } + + /// + /// Gets a report on the actions performed by the test case in its assigned role. + /// + /// + /// The session to create the report message in. + /// + /// The report message. + public IMessage GetReport(IChannel channel) + { + log.Debug("public IMessage getReport(IChannel channel): called"); + + // Close the test connections. + /*foreach (IConnection con in connection) + { + try + { + con.Stop(); + } + catch (AMQConnectionClosedException e) + { + // The connection has already died due to an error. Log this as a warning. + log.Warn("Connection already closed."); + } + }*/ + + // Generate a report message containing the count of the number of messages passed. + IMessage report = channel.CreateMessage(); + //report.Headers.SetString("CONTROL_TYPE", "REPORT"); + report.Headers.SetInt("MESSAGE_COUNT", messageCount); + + return report; + } + + /// + /// Counts incoming test messages. + /// + /// + /// The incoming test message. + public void OnMessage(IMessage message) + { + log.Debug("public void onMessage(IMessage message = " + message + "): called"); + + // Increment the message count. + messageCount++; + } + } +} diff --git a/dotnet/Qpid.Integration.Tests/interop/TestClient.cs b/dotnet/Qpid.Integration.Tests/interop/TestClient.cs index 82a9de742a..e2fac9e1a4 100644 --- a/dotnet/Qpid.Integration.Tests/interop/TestClient.cs +++ b/dotnet/Qpid.Integration.Tests/interop/TestClient.cs @@ -1,379 +1,379 @@ -/* - * - * 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. - * - */ -using System; -using System.Collections; -using System.Text; -using System.Threading; -using Apache.Qpid.Messaging; -using Apache.Qpid.Client.Qms; -using Apache.Qpid.Client; -using log4net; -using Apache.Qpid.Integration.Tests.interop.TestCases; - -namespace Apache.Qpid.Integration.Tests.interop -{ - /// - /// Implements a test client as described in the interop testing spec - /// (http://cwiki.apache.org/confluence/display/qpid/Interop+Testing+Specification). A test client is an agent that - /// reacts to control message sequences send by the test coordinator. - /// - ///

- ///
Messages Handled by TestClient
Message Action - ///
Invite(compulsory) Reply with Enlist. - ///
Invite(test case) Reply with Enlist if test case available. - ///
AssignRole(test case) Reply with Accept Role if matches an enlisted test. Keep test parameters. - ///
Start Send test messages defined by test parameters. Send report on messages sent. - ///
Status Request Send report on messages received. - ///
- /// - ///

- ///
CRC Card
Responsibilities Collaborations - ///
Handle all incoming control messages. {@link InteropClientTestCase} - ///
Configure and look up test cases by name. {@link InteropClientTestCase} - ///
- ///

- public class TestClient - { - private static ILog log = LogManager.GetLogger(typeof(TestClient)); - - /// Defines the default broker for the tests, localhost, default port. - public static string DEFAULT_BROKER_URL = "amqp://guest:guest@clientid/?brokerlist='tcp://localhost:5672'"; - - /// Defines the default virtual host to use for the tests, none. - public static string DEFAULT_VIRTUAL_HOST = ""; - - /// Defines the default identifying name of this test client. - public static string DEFAULT_CLIENT_NAME = "dotnet"; - - /// Holds the URL of the broker to run the tests on. - public static string brokerUrl; - - /// Holds the virtual host to run the tests on. If null, then the default virtual host is used. - public static string virtualHost; - - /// The clients identifying name to print in test results and to distinguish from other clients. - private string clientName; - - /// Holds all the test cases. - private IDictionary testCases = new Hashtable(); - - InteropClientTestCase currentTestCase; - - private MessagePublisherBuilder publisherBuilder; - - private IChannel channel; - - /// Monitor to wait for termination events on. - private static object terminationMonitor = new Object(); - - /// - /// Creates a new interop test client, listenting to the specified broker and virtual host, with the specified - /// client identifying name. - /// - /// - /// The url of the broker to connect to. - /// The virtual host to conect to. - /// The client name to use. - public TestClient(string brokerUrl, string virtualHost, string clientName) - { - log.Info("public TestClient(string brokerUrl = " + brokerUrl + ", string virtualHost = " + virtualHost - + ", string clientName = " + clientName + "): called"); - - // Retain the connection parameters. - TestClient.brokerUrl = brokerUrl; - TestClient.virtualHost = virtualHost; - this.clientName = clientName; - } - - - /// - /// The entry point for the interop test coordinator. This client accepts the following command line arguments: - /// - /// - ///

- ///
-b The broker URL. Optional. - ///
-h The virtual host. Optional. - ///
-n The test client name. Optional. - ///
name=value Trailing argument define name/value pairs. Added to system properties. Optional. - ///
- /// - /// The command line arguments. - public static void Main(string[] args) - { - // Extract the command line options (Not exactly Posix but it will do for now...). - string brokerUrl = DEFAULT_BROKER_URL; - string virtualHost = DEFAULT_VIRTUAL_HOST; - string clientName = DEFAULT_CLIENT_NAME; - - foreach (string nextArg in args) - { - if (nextArg.StartsWith("-b")) - { - brokerUrl = nextArg.Substring(2); - } - else if (nextArg.StartsWith("-h")) - { - virtualHost = nextArg.Substring(2); - } - else if (nextArg.StartsWith("-n")) - { - clientName = nextArg.Substring(2); - } - } - - NDC.Push(clientName); - - // Create a test client and start it running. - TestClient client = new TestClient(brokerUrl, virtualHost, clientName); - - try - { - client.Start(); - } - catch (Exception e) - { - log.Error("The test client was unable to start.", e); - System.Environment.Exit(1); - } - - // Wait for a signal on the termination monitor before quitting. - lock (terminationMonitor) - { - Monitor.Wait(terminationMonitor); - } - - NDC.Pop(); - } - - ///

- /// Starts the interop test client running. This causes it to start listening for incoming test invites. - /// - private void Start() - { - log.Info("private void Start(): called"); - - // Use a class path scanner to find all the interop test case implementations. - ArrayList testCaseClasses = new ArrayList(); - - // ClasspathScanner.getMatches(InteropClientTestCase.class, "^TestCase.*", true); - // Hard code the test classes till the classpath scanner is fixed. - testCaseClasses.Add(typeof(TestCase1DummyRun)); - testCaseClasses.Add(typeof(TestCase2BasicP2P)); - testCaseClasses.Add(typeof(TestCase3BasicPubSub)); - - // Create all the test case implementations and index them by the test names. - foreach (Type testClass in testCaseClasses) - { - InteropClientTestCase testCase = (InteropClientTestCase)Activator.CreateInstance(testClass); - testCases.Add(testCase.GetName(), testCase); - - log.Info("Found test case: " + testClass); - } - - // Open a connection to communicate with the coordinator on. - log.Info("brokerUrl = " + brokerUrl); - IConnection connection = CreateConnection(brokerUrl, virtualHost); - - channel = connection.CreateChannel(false, AcknowledgeMode.AutoAcknowledge); - - // Set this up to listen for control messages. - string responseQueueName = channel.GenerateUniqueName(); - channel.DeclareQueue(responseQueueName, false, true, true); - - channel.Bind(responseQueueName, ExchangeNameDefaults.TOPIC, "iop.control." + clientName); - channel.Bind(responseQueueName, ExchangeNameDefaults.TOPIC, "iop.control"); - - IMessageConsumer consumer = channel.CreateConsumerBuilder(responseQueueName) - .Create(); - consumer.OnMessage += new MessageReceivedDelegate(OnMessage); - - // Create a publisher to send replies with. - publisherBuilder = channel.CreatePublisherBuilder() - .WithExchangeName(ExchangeNameDefaults.DIRECT); - - - // Start listening for incoming control messages. - connection.Start(); - Console.WriteLine("Test client " + clientName + " ready to receive test control messages..."); - } - - /// - /// Establishes an AMQ connection. This is a simple convenience method for code that does not anticipate handling connection failures. - /// All exceptions that indicate that the connection has failed, are allowed to fall through. - /// - /// - /// The broker url to connect to, null to use the default from the properties. - /// The virtual host to connectio to, null to use the default. - /// - /// A JMS conneciton. - public static IConnection CreateConnection(string brokerUrl, string virtualHost) - { - log.Info("public static Connection createConnection(string brokerUrl = " + brokerUrl + ", string virtualHost = " - + virtualHost + "): called"); - - // Create a connection to the broker. - IConnectionInfo connectionInfo = QpidConnectionInfo.FromUrl(brokerUrl); - connectionInfo.VirtualHost = virtualHost; - IConnection connection = new AMQConnection(connectionInfo); - - return connection; - } - - /// - /// Handles all incoming control messages. - /// - /// - /// The incoming message. - public void OnMessage(IMessage message) - { - log.Info("public void OnMessage(IMessage message = " + message + "): called"); - - try - { - string controlType = message.Headers.GetString("CONTROL_TYPE"); - string testName = message.Headers.GetString("TEST_NAME"); - - // Check if the message is a test invite. - if ("INVITE" == controlType) - { - string testCaseName = message.Headers.GetString("TEST_NAME"); - - // Flag used to indicate that an enlist should be sent. Only enlist to compulsory invites or invites - // for which test cases exist. - bool enlist = false; - - if (testCaseName != null) - { - log.Info("Got an invite to test: " + testCaseName); - - // Check if the requested test case is available. - InteropClientTestCase testCase = (InteropClientTestCase)testCases[testCaseName]; - - if (testCase != null) - { - // Make the requested test case the current test case. - currentTestCase = testCase; - enlist = true; - } - } - else - { - log.Info("Got a compulsory invite."); - - enlist = true; - } - - log.Info("enlist = " + enlist); - - if (enlist) - { - // Reply with the client name in an Enlist message. - IMessage enlistMessage = channel.CreateMessage(); - enlistMessage.Headers.SetString("CONTROL_TYPE", "ENLIST"); - enlistMessage.Headers.SetString("CLIENT_NAME", clientName); - enlistMessage.Headers.SetString("CLIENT_PRIVATE_CONTROL_KEY", "iop.control." + clientName); - enlistMessage.CorrelationId = message.CorrelationId; - - Send(enlistMessage, message.ReplyToRoutingKey); - } - } - else if ("ASSIGN_ROLE" == controlType) - { - // Assign the role to the current test case. - string roleName = message.Headers.GetString("ROLE"); - - log.Info("Got a role assignment to role: " + roleName); - - Roles role; - - if (roleName == "SENDER") - { - role = Roles.SENDER; - } - else - { - role = Roles.RECEIVER; - } - - currentTestCase.AssignRole(role, message); - - // Reply by accepting the role in an Accept Role message. - IMessage acceptRoleMessage = channel.CreateMessage(); - acceptRoleMessage.Headers.SetString("CONTROL_TYPE", "ACCEPT_ROLE"); - acceptRoleMessage.CorrelationId = message.CorrelationId; - - Send(acceptRoleMessage, message.ReplyToRoutingKey); - } - else if ("START" == controlType || "STATUS_REQUEST" == controlType) - { - if ("START" == controlType) - { - log.Info("Got a start notification."); - - // Start the current test case. - currentTestCase.Start(); - } - else - { - log.Info("Got a status request."); - } - - // Generate the report from the test case and reply with it as a Report message. - IMessage reportMessage = currentTestCase.GetReport(channel); - reportMessage.Headers.SetString("CONTROL_TYPE", "REPORT"); - reportMessage.CorrelationId = message.CorrelationId; - - Send(reportMessage, message.ReplyToRoutingKey); - } - else if ("TERMINATE" == controlType) - { - Console.WriteLine("Received termination instruction from coordinator."); - - // Is a cleaner shutdown needed? - System.Environment.Exit(1); - } - else - { - // Log a warning about this but otherwise ignore it. - log.Warn("Got an unknown control message, controlType = " + controlType + ", message = " + message); - } - } - catch (QpidException e) - { - // Log a warning about this, but otherwise ignore it. - log.Warn("A QpidException occurred whilst handling a message."); - log.Info("Got QpidException whilst handling message: " + message, e); - } - } - - /// - /// Send the specified message using the specified routing key on the direct exchange. - /// - /// - /// The message to send. - /// The routing key to send the message with. - public void Send(IMessage message, string routingKey) - { - IMessagePublisher publisher = publisherBuilder.WithRoutingKey(routingKey).Create(); - publisher.Send(message); - } - } -} +/* + * + * 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. + * + */ +using System; +using System.Collections; +using System.Text; +using System.Threading; +using Apache.Qpid.Messaging; +using Apache.Qpid.Client.Qms; +using Apache.Qpid.Client; +using log4net; +using Apache.Qpid.Integration.Tests.interop.TestCases; + +namespace Apache.Qpid.Integration.Tests.interop +{ + /// + /// Implements a test client as described in the interop testing spec + /// (http://cwiki.apache.org/confluence/display/qpid/Interop+Testing+Specification). A test client is an agent that + /// reacts to control message sequences send by the test coordinator. + /// + ///

+ ///
Messages Handled by TestClient
Message Action + ///
Invite(compulsory) Reply with Enlist. + ///
Invite(test case) Reply with Enlist if test case available. + ///
AssignRole(test case) Reply with Accept Role if matches an enlisted test. Keep test parameters. + ///
Start Send test messages defined by test parameters. Send report on messages sent. + ///
Status Request Send report on messages received. + ///
+ /// + ///

+ ///
CRC Card
Responsibilities Collaborations + ///
Handle all incoming control messages. {@link InteropClientTestCase} + ///
Configure and look up test cases by name. {@link InteropClientTestCase} + ///
+ ///

+ public class TestClient + { + private static ILog log = LogManager.GetLogger(typeof(TestClient)); + + /// Defines the default broker for the tests, localhost, default port. + public static string DEFAULT_BROKER_URL = "amqp://guest:guest@clientid/?brokerlist='tcp://localhost:5672'"; + + /// Defines the default virtual host to use for the tests, none. + public static string DEFAULT_VIRTUAL_HOST = ""; + + /// Defines the default identifying name of this test client. + public static string DEFAULT_CLIENT_NAME = "dotnet"; + + /// Holds the URL of the broker to run the tests on. + public static string brokerUrl; + + /// Holds the virtual host to run the tests on. If null, then the default virtual host is used. + public static string virtualHost; + + /// The clients identifying name to print in test results and to distinguish from other clients. + private string clientName; + + /// Holds all the test cases. + private IDictionary testCases = new Hashtable(); + + InteropClientTestCase currentTestCase; + + private MessagePublisherBuilder publisherBuilder; + + private IChannel channel; + + /// Monitor to wait for termination events on. + private static object terminationMonitor = new Object(); + + /// + /// Creates a new interop test client, listenting to the specified broker and virtual host, with the specified + /// client identifying name. + /// + /// + /// The url of the broker to connect to. + /// The virtual host to conect to. + /// The client name to use. + public TestClient(string brokerUrl, string virtualHost, string clientName) + { + log.Info("public TestClient(string brokerUrl = " + brokerUrl + ", string virtualHost = " + virtualHost + + ", string clientName = " + clientName + "): called"); + + // Retain the connection parameters. + TestClient.brokerUrl = brokerUrl; + TestClient.virtualHost = virtualHost; + this.clientName = clientName; + } + + + /// + /// The entry point for the interop test coordinator. This client accepts the following command line arguments: + /// + /// + ///

+ ///
-b The broker URL. Optional. + ///
-h The virtual host. Optional. + ///
-n The test client name. Optional. + ///
name=value Trailing argument define name/value pairs. Added to system properties. Optional. + ///
+ /// + /// The command line arguments. + public static void Main(string[] args) + { + // Extract the command line options (Not exactly Posix but it will do for now...). + string brokerUrl = DEFAULT_BROKER_URL; + string virtualHost = DEFAULT_VIRTUAL_HOST; + string clientName = DEFAULT_CLIENT_NAME; + + foreach (string nextArg in args) + { + if (nextArg.StartsWith("-b")) + { + brokerUrl = nextArg.Substring(2); + } + else if (nextArg.StartsWith("-h")) + { + virtualHost = nextArg.Substring(2); + } + else if (nextArg.StartsWith("-n")) + { + clientName = nextArg.Substring(2); + } + } + + NDC.Push(clientName); + + // Create a test client and start it running. + TestClient client = new TestClient(brokerUrl, virtualHost, clientName); + + try + { + client.Start(); + } + catch (Exception e) + { + log.Error("The test client was unable to start.", e); + System.Environment.Exit(1); + } + + // Wait for a signal on the termination monitor before quitting. + lock (terminationMonitor) + { + Monitor.Wait(terminationMonitor); + } + + NDC.Pop(); + } + + ///

+ /// Starts the interop test client running. This causes it to start listening for incoming test invites. + /// + private void Start() + { + log.Info("private void Start(): called"); + + // Use a class path scanner to find all the interop test case implementations. + ArrayList testCaseClasses = new ArrayList(); + + // ClasspathScanner.getMatches(InteropClientTestCase.class, "^TestCase.*", true); + // Hard code the test classes till the classpath scanner is fixed. + testCaseClasses.Add(typeof(TestCase1DummyRun)); + testCaseClasses.Add(typeof(TestCase2BasicP2P)); + testCaseClasses.Add(typeof(TestCase3BasicPubSub)); + + // Create all the test case implementations and index them by the test names. + foreach (Type testClass in testCaseClasses) + { + InteropClientTestCase testCase = (InteropClientTestCase)Activator.CreateInstance(testClass); + testCases.Add(testCase.GetName(), testCase); + + log.Info("Found test case: " + testClass); + } + + // Open a connection to communicate with the coordinator on. + log.Info("brokerUrl = " + brokerUrl); + IConnection connection = CreateConnection(brokerUrl, virtualHost); + + channel = connection.CreateChannel(false, AcknowledgeMode.AutoAcknowledge); + + // Set this up to listen for control messages. + string responseQueueName = channel.GenerateUniqueName(); + channel.DeclareQueue(responseQueueName, false, true, true); + + channel.Bind(responseQueueName, ExchangeNameDefaults.TOPIC, "iop.control." + clientName); + channel.Bind(responseQueueName, ExchangeNameDefaults.TOPIC, "iop.control"); + + IMessageConsumer consumer = channel.CreateConsumerBuilder(responseQueueName) + .Create(); + consumer.OnMessage += new MessageReceivedDelegate(OnMessage); + + // Create a publisher to send replies with. + publisherBuilder = channel.CreatePublisherBuilder() + .WithExchangeName(ExchangeNameDefaults.DIRECT); + + + // Start listening for incoming control messages. + connection.Start(); + Console.WriteLine("Test client " + clientName + " ready to receive test control messages..."); + } + + /// + /// Establishes an AMQ connection. This is a simple convenience method for code that does not anticipate handling connection failures. + /// All exceptions that indicate that the connection has failed, are allowed to fall through. + /// + /// + /// The broker url to connect to, null to use the default from the properties. + /// The virtual host to connectio to, null to use the default. + /// + /// A JMS conneciton. + public static IConnection CreateConnection(string brokerUrl, string virtualHost) + { + log.Info("public static Connection createConnection(string brokerUrl = " + brokerUrl + ", string virtualHost = " + + virtualHost + "): called"); + + // Create a connection to the broker. + IConnectionInfo connectionInfo = QpidConnectionInfo.FromUrl(brokerUrl); + connectionInfo.VirtualHost = virtualHost; + IConnection connection = new AMQConnection(connectionInfo); + + return connection; + } + + /// + /// Handles all incoming control messages. + /// + /// + /// The incoming message. + public void OnMessage(IMessage message) + { + log.Info("public void OnMessage(IMessage message = " + message + "): called"); + + try + { + string controlType = message.Headers.GetString("CONTROL_TYPE"); + string testName = message.Headers.GetString("TEST_NAME"); + + // Check if the message is a test invite. + if ("INVITE" == controlType) + { + string testCaseName = message.Headers.GetString("TEST_NAME"); + + // Flag used to indicate that an enlist should be sent. Only enlist to compulsory invites or invites + // for which test cases exist. + bool enlist = false; + + if (testCaseName != null) + { + log.Info("Got an invite to test: " + testCaseName); + + // Check if the requested test case is available. + InteropClientTestCase testCase = (InteropClientTestCase)testCases[testCaseName]; + + if (testCase != null) + { + // Make the requested test case the current test case. + currentTestCase = testCase; + enlist = true; + } + } + else + { + log.Info("Got a compulsory invite."); + + enlist = true; + } + + log.Info("enlist = " + enlist); + + if (enlist) + { + // Reply with the client name in an Enlist message. + IMessage enlistMessage = channel.CreateMessage(); + enlistMessage.Headers.SetString("CONTROL_TYPE", "ENLIST"); + enlistMessage.Headers.SetString("CLIENT_NAME", clientName); + enlistMessage.Headers.SetString("CLIENT_PRIVATE_CONTROL_KEY", "iop.control." + clientName); + enlistMessage.CorrelationId = message.CorrelationId; + + Send(enlistMessage, message.ReplyToRoutingKey); + } + } + else if ("ASSIGN_ROLE" == controlType) + { + // Assign the role to the current test case. + string roleName = message.Headers.GetString("ROLE"); + + log.Info("Got a role assignment to role: " + roleName); + + Roles role; + + if (roleName == "SENDER") + { + role = Roles.SENDER; + } + else + { + role = Roles.RECEIVER; + } + + currentTestCase.AssignRole(role, message); + + // Reply by accepting the role in an Accept Role message. + IMessage acceptRoleMessage = channel.CreateMessage(); + acceptRoleMessage.Headers.SetString("CONTROL_TYPE", "ACCEPT_ROLE"); + acceptRoleMessage.CorrelationId = message.CorrelationId; + + Send(acceptRoleMessage, message.ReplyToRoutingKey); + } + else if ("START" == controlType || "STATUS_REQUEST" == controlType) + { + if ("START" == controlType) + { + log.Info("Got a start notification."); + + // Start the current test case. + currentTestCase.Start(); + } + else + { + log.Info("Got a status request."); + } + + // Generate the report from the test case and reply with it as a Report message. + IMessage reportMessage = currentTestCase.GetReport(channel); + reportMessage.Headers.SetString("CONTROL_TYPE", "REPORT"); + reportMessage.CorrelationId = message.CorrelationId; + + Send(reportMessage, message.ReplyToRoutingKey); + } + else if ("TERMINATE" == controlType) + { + Console.WriteLine("Received termination instruction from coordinator."); + + // Is a cleaner shutdown needed? + System.Environment.Exit(1); + } + else + { + // Log a warning about this but otherwise ignore it. + log.Warn("Got an unknown control message, controlType = " + controlType + ", message = " + message); + } + } + catch (QpidException e) + { + // Log a warning about this, but otherwise ignore it. + log.Warn("A QpidException occurred whilst handling a message."); + log.Info("Got QpidException whilst handling message: " + message, e); + } + } + + /// + /// Send the specified message using the specified routing key on the direct exchange. + /// + /// + /// The message to send. + /// The routing key to send the message with. + public void Send(IMessage message, string routingKey) + { + IMessagePublisher publisher = publisherBuilder.WithRoutingKey(routingKey).Create(); + publisher.Send(message); + } + } +} diff --git a/dotnet/Qpid.Integration.Tests/testcases/BaseMessagingTestFixture.cs b/dotnet/Qpid.Integration.Tests/testcases/BaseMessagingTestFixture.cs index d4b61a2788..4c82dbe08c 100644 --- a/dotnet/Qpid.Integration.Tests/testcases/BaseMessagingTestFixture.cs +++ b/dotnet/Qpid.Integration.Tests/testcases/BaseMessagingTestFixture.cs @@ -1,261 +1,261 @@ -/* - * - * 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. - * - */ -using System; -using System.Text; -using log4net; -using NUnit.Framework; -using Apache.Qpid.Messaging; -using Apache.Qpid.Client.Qms; -using Apache.Qpid.Client; - -namespace Apache.Qpid.Integration.Tests.testcases -{ - /// - /// Provides a basis for writing Unit tests that communicate with an AMQ protocol broker. By default it creates a connection - /// to a message broker running on localhost on the standard AMQ port, 5672, using guest:guest login credentials. It also - /// creates a standard auto-ack channel on this connection. - /// - public class BaseMessagingTestFixture - { - private static ILog log = LogManager.GetLogger(typeof(BaseMessagingTestFixture)); - - /// Used to build dummy data to fill test messages with. - private const string MESSAGE_DATA_BYTES = "-- Test Message -- Test Message -- Test Message -- Test Message -- Test Message "; - - /// The default timeout in milliseconds to use on receives. - private const long RECEIVE_WAIT = 2000; - - /// The default AMQ connection URL to use for tests. - public const string connectionUri = "amqp://guest:guest@test/test?brokerlist='tcp://localhost:5672'"; - - /// The default AMQ connection URL parsed as a connection info. - protected IConnectionInfo connectionInfo; - - /// Holds an array of connections for building mutiple test end-points. - protected IConnection[] testConnection = new IConnection[10]; - - /// Holds an array of channels for building mutiple test end-points. - protected IChannel[] testChannel = new IChannel[10]; - - /// Holds an array of queues for building mutiple test end-points. - protected String[] testQueue = new String[10]; - - /// Holds an array of producers for building mutiple test end-points. - protected IMessagePublisher[] testProducer = new IMessagePublisher[10]; - - /// Holds an array of consumers for building mutiple test end-points. - protected IMessageConsumer[] testConsumer = new IMessageConsumer[10]; - - /// A counter used to supply unique ids. - private static int uniqueId = 0; - - /// Used to hold unique ids per test. - protected Guid testId; - - /// Creates the test connection and channel. - [SetUp] - public virtual void Init() - { - log.Debug("public virtual void Init(): called"); - - // Set up a unique id for this test. - testId = System.Guid.NewGuid(); - } - - /// - /// Disposes of the test connection. This is called manually because the connection is a field so dispose will not be automatically - /// called on it. - /// - [TearDown] - public virtual void Shutdown() - { - log.Debug("public virtual void Shutdown(): called"); - } - - /// Sets up the nth test end-point. - /// - /// The index of the test end-point to set up. - /// true to set up a producer on the end-point. - /// true to set up a consumer on the end-point. - /// The routing key for the producer to send on. - /// The ack mode for the end-points channel. - /// true to use transactions on the end-points channel. - /// The exchange to produce or consume on. - /// true if the consumers queue should be declared and bound, false if it has already been. - /// true to declare the consumers queue as durable. - /// If durable is true, the fixed unique queue name to use. - public void SetUpEndPoint(int n, bool producer, bool consumer, string routingKey, AcknowledgeMode ackMode, bool transacted, - string exchangeName, bool declareBind, bool durable, string subscriptionName) - { - // Allow client id to be fixed, or undefined. - { - // Use unique id for end point. - connectionInfo = QpidConnectionInfo.FromUrl(connectionUri); - - connectionInfo.ClientName = "test" + n; - } - - testConnection[n] = new AMQConnection(connectionInfo); - testConnection[n].Start(); - testChannel[n] = testConnection[n].CreateChannel(transacted, ackMode); - - if (producer) - { - testProducer[n] = testChannel[n].CreatePublisherBuilder() - .WithExchangeName(exchangeName) - .WithRoutingKey(routingKey) - .Create(); - } - - if (consumer) - { - string queueName; - - // Use the subscription name as the queue name if the subscription is durable, otherwise use a generated name. - if (durable) - { - // The durable queue is declared without auto-delete, and passively, in case it has already been declared. - queueName = subscriptionName; - - if (declareBind) - { - testChannel[n].DeclareQueue(queueName, durable, true, false); - testChannel[n].Bind(queueName, exchangeName, routingKey); - } - } - else - { - queueName = testChannel[n].GenerateUniqueName(); - - if (declareBind) - { - if (durable) - { - testQueue[n] = queueName; - } - testChannel[n].DeclareQueue(queueName, durable, true, true); - testChannel[n].Bind(queueName, exchangeName, routingKey); - } - } - - testConsumer[n] = testChannel[n].CreateConsumerBuilder(queueName).Create(); - } - } - - /// Closes down the nth test end-point. - public void CloseEndPoint(int n) - { - log.Debug("public void CloseEndPoint(int n): called"); - - if (testProducer[n] != null) - { - testProducer[n].Close(); - testProducer[n].Dispose(); - testProducer[n] = null; - } - - if (testConsumer[n] != null) - { - if (testQueue[n] != null) - { - testChannel[n].DeleteQueue(testQueue[n], false, false, true); - } - testConsumer[n].Close(); - testConsumer[n].Dispose(); - testConsumer[n] = null; - } - - if (testConnection[n] != null) - { - testConnection[n].Stop(); - testConnection[n].Close(); - testConnection[n].Dispose(); - testConnection[n] = null; - } - } - - /// - /// Consumes n messages, checking that the n+1th is not available within a timeout, and that the consumed messages - /// are text messages with contents equal to the specified message body. - /// - /// - /// The number of messages to consume. - /// The body text to match against all messages. - /// The message consumer to recieve the messages on. - public static void ConsumeNMessagesOnly(int n, string body, IMessageConsumer consumer) - { - ConsumeNMessages(n, body, consumer); - - // Check that one more than n cannot be received. - IMessage msg = consumer.Receive(RECEIVE_WAIT); - Assert.IsNull(msg, "Consumer got more messages than the number requested (" + n + ")."); - } - - /// - /// Consumes n messages, checking that the n+1th is not available within a timeout, and that the consumed messages - /// are text messages with contents equal to the specified message body. - /// - /// - /// The number of messages to consume. - /// The body text to match against all messages. - /// The message consumer to recieve the messages on. - public static void ConsumeNMessages(int n, string body, IMessageConsumer consumer) - { - IMessage msg; - - // Try to receive n messages. - for (int i = 0; i < n; i++) - { - msg = consumer.Receive(RECEIVE_WAIT); - Assert.IsNotNull(msg, "Consumer did not receive message number: " + i); - Assert.AreEqual(body, ((ITextMessage)msg).Text, "Incorrect Message recevied on consumer1."); - } - } - - /// Creates the requested number of bytes of dummy text. Usually used for filling test messages. - /// - /// The number of bytes of dummy text to generate. - /// - /// The requested number of bytes of dummy text. - public static String GetData(int size) - { - StringBuilder buf = new StringBuilder(size); - - if (size > 0) - { - int div = MESSAGE_DATA_BYTES.Length / size; - int mod = MESSAGE_DATA_BYTES.Length % size; - - for (int i = 0; i < div; i++) - { - buf.Append(MESSAGE_DATA_BYTES); - } - - if (mod != 0) - { - buf.Append(MESSAGE_DATA_BYTES, 0, mod); - } - } - - return buf.ToString(); - } - } -} +/* + * + * 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. + * + */ +using System; +using System.Text; +using log4net; +using NUnit.Framework; +using Apache.Qpid.Messaging; +using Apache.Qpid.Client.Qms; +using Apache.Qpid.Client; + +namespace Apache.Qpid.Integration.Tests.testcases +{ + /// + /// Provides a basis for writing Unit tests that communicate with an AMQ protocol broker. By default it creates a connection + /// to a message broker running on localhost on the standard AMQ port, 5672, using guest:guest login credentials. It also + /// creates a standard auto-ack channel on this connection. + /// + public class BaseMessagingTestFixture + { + private static ILog log = LogManager.GetLogger(typeof(BaseMessagingTestFixture)); + + /// Used to build dummy data to fill test messages with. + private const string MESSAGE_DATA_BYTES = "-- Test Message -- Test Message -- Test Message -- Test Message -- Test Message "; + + /// The default timeout in milliseconds to use on receives. + private const long RECEIVE_WAIT = 2000; + + /// The default AMQ connection URL to use for tests. + public const string connectionUri = "amqp://guest:guest@test/test?brokerlist='tcp://localhost:5672'"; + + /// The default AMQ connection URL parsed as a connection info. + protected IConnectionInfo connectionInfo; + + /// Holds an array of connections for building mutiple test end-points. + protected IConnection[] testConnection = new IConnection[10]; + + /// Holds an array of channels for building mutiple test end-points. + protected IChannel[] testChannel = new IChannel[10]; + + /// Holds an array of queues for building mutiple test end-points. + protected String[] testQueue = new String[10]; + + /// Holds an array of producers for building mutiple test end-points. + protected IMessagePublisher[] testProducer = new IMessagePublisher[10]; + + /// Holds an array of consumers for building mutiple test end-points. + protected IMessageConsumer[] testConsumer = new IMessageConsumer[10]; + + /// A counter used to supply unique ids. + private static int uniqueId = 0; + + /// Used to hold unique ids per test. + protected Guid testId; + + /// Creates the test connection and channel. + [SetUp] + public virtual void Init() + { + log.Debug("public virtual void Init(): called"); + + // Set up a unique id for this test. + testId = System.Guid.NewGuid(); + } + + /// + /// Disposes of the test connection. This is called manually because the connection is a field so dispose will not be automatically + /// called on it. + /// + [TearDown] + public virtual void Shutdown() + { + log.Debug("public virtual void Shutdown(): called"); + } + + /// Sets up the nth test end-point. + /// + /// The index of the test end-point to set up. + /// true to set up a producer on the end-point. + /// true to set up a consumer on the end-point. + /// The routing key for the producer to send on. + /// The ack mode for the end-points channel. + /// true to use transactions on the end-points channel. + /// The exchange to produce or consume on. + /// true if the consumers queue should be declared and bound, false if it has already been. + /// true to declare the consumers queue as durable. + /// If durable is true, the fixed unique queue name to use. + public void SetUpEndPoint(int n, bool producer, bool consumer, string routingKey, AcknowledgeMode ackMode, bool transacted, + string exchangeName, bool declareBind, bool durable, string subscriptionName) + { + // Allow client id to be fixed, or undefined. + { + // Use unique id for end point. + connectionInfo = QpidConnectionInfo.FromUrl(connectionUri); + + connectionInfo.ClientName = "test" + n; + } + + testConnection[n] = new AMQConnection(connectionInfo); + testConnection[n].Start(); + testChannel[n] = testConnection[n].CreateChannel(transacted, ackMode); + + if (producer) + { + testProducer[n] = testChannel[n].CreatePublisherBuilder() + .WithExchangeName(exchangeName) + .WithRoutingKey(routingKey) + .Create(); + } + + if (consumer) + { + string queueName; + + // Use the subscription name as the queue name if the subscription is durable, otherwise use a generated name. + if (durable) + { + // The durable queue is declared without auto-delete, and passively, in case it has already been declared. + queueName = subscriptionName; + + if (declareBind) + { + testChannel[n].DeclareQueue(queueName, durable, true, false); + testChannel[n].Bind(queueName, exchangeName, routingKey); + } + } + else + { + queueName = testChannel[n].GenerateUniqueName(); + + if (declareBind) + { + if (durable) + { + testQueue[n] = queueName; + } + testChannel[n].DeclareQueue(queueName, durable, true, true); + testChannel[n].Bind(queueName, exchangeName, routingKey); + } + } + + testConsumer[n] = testChannel[n].CreateConsumerBuilder(queueName).Create(); + } + } + + /// Closes down the nth test end-point. + public void CloseEndPoint(int n) + { + log.Debug("public void CloseEndPoint(int n): called"); + + if (testProducer[n] != null) + { + testProducer[n].Close(); + testProducer[n].Dispose(); + testProducer[n] = null; + } + + if (testConsumer[n] != null) + { + if (testQueue[n] != null) + { + testChannel[n].DeleteQueue(testQueue[n], false, false, true); + } + testConsumer[n].Close(); + testConsumer[n].Dispose(); + testConsumer[n] = null; + } + + if (testConnection[n] != null) + { + testConnection[n].Stop(); + testConnection[n].Close(); + testConnection[n].Dispose(); + testConnection[n] = null; + } + } + + /// + /// Consumes n messages, checking that the n+1th is not available within a timeout, and that the consumed messages + /// are text messages with contents equal to the specified message body. + /// + /// + /// The number of messages to consume. + /// The body text to match against all messages. + /// The message consumer to recieve the messages on. + public static void ConsumeNMessagesOnly(int n, string body, IMessageConsumer consumer) + { + ConsumeNMessages(n, body, consumer); + + // Check that one more than n cannot be received. + IMessage msg = consumer.Receive(RECEIVE_WAIT); + Assert.IsNull(msg, "Consumer got more messages than the number requested (" + n + ")."); + } + + /// + /// Consumes n messages, checking that the n+1th is not available within a timeout, and that the consumed messages + /// are text messages with contents equal to the specified message body. + /// + /// + /// The number of messages to consume. + /// The body text to match against all messages. + /// The message consumer to recieve the messages on. + public static void ConsumeNMessages(int n, string body, IMessageConsumer consumer) + { + IMessage msg; + + // Try to receive n messages. + for (int i = 0; i < n; i++) + { + msg = consumer.Receive(RECEIVE_WAIT); + Assert.IsNotNull(msg, "Consumer did not receive message number: " + i); + Assert.AreEqual(body, ((ITextMessage)msg).Text, "Incorrect Message recevied on consumer1."); + } + } + + /// Creates the requested number of bytes of dummy text. Usually used for filling test messages. + /// + /// The number of bytes of dummy text to generate. + /// + /// The requested number of bytes of dummy text. + public static String GetData(int size) + { + StringBuilder buf = new StringBuilder(size); + + if (size > 0) + { + int div = MESSAGE_DATA_BYTES.Length / size; + int mod = MESSAGE_DATA_BYTES.Length % size; + + for (int i = 0; i < div; i++) + { + buf.Append(MESSAGE_DATA_BYTES); + } + + if (mod != 0) + { + buf.Append(MESSAGE_DATA_BYTES, 0, mod); + } + } + + return buf.ToString(); + } + } +} diff --git a/dotnet/Qpid.Integration.Tests/testcases/ChannelQueueTest.cs b/dotnet/Qpid.Integration.Tests/testcases/ChannelQueueTest.cs index e34864aefd..4692e7ecb1 100644 --- a/dotnet/Qpid.Integration.Tests/testcases/ChannelQueueTest.cs +++ b/dotnet/Qpid.Integration.Tests/testcases/ChannelQueueTest.cs @@ -1,237 +1,237 @@ -/* - * - * 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. - * - */ -using System; -using System.Net; -using System.Threading; -using log4net; -using Apache.Qpid.Client.Qms; -using Apache.Qpid.Client; -using Apache.Qpid.Messaging; -using NUnit.Framework; - -namespace Apache.Qpid.Integration.Tests.testcases -{ - /// - /// Test the queue methods - /// - [TestFixture, Category("Integration")] - public class ChannelQueueTest - { - private static ILog _logger = LogManager.GetLogger(typeof(ChannelQueueTest)); - - /// The default AMQ connection URL to use for tests. - const string DEFAULT_URI = "amqp://guest:guest@default/test?brokerlist='tcp://localhost:5672'"; - const string _routingKey = "ServiceQ1"; - - private ExceptionListenerDelegate _exceptionDelegate; - private AutoResetEvent _evt = new AutoResetEvent(false); - private Exception _lastException = null; - - private IMessageConsumer _consumer; - private IMessagePublisher _publisher; - private IChannel _channel; - private IConnection _connection; - - private string _queueName; - - [SetUp] - public virtual void Init() - { - _logger.Info("public virtual void Init(): called"); - - // Create a connection to the broker. - IConnectionInfo connectionInfo = QpidConnectionInfo.FromUrl(DEFAULT_URI); - _connection = new AMQConnection(connectionInfo); - _logger.Info("Starting..."); - - // Register this to listen for exceptions on the test connection. - _exceptionDelegate = new ExceptionListenerDelegate(OnException); - _connection.ExceptionListener += _exceptionDelegate; - - // Establish a session on the broker. - _channel = _connection.CreateChannel(false, AcknowledgeMode.AutoAcknowledge, 1); - - // Create a durable, non-temporary, non-exclusive queue. - _queueName = _channel.GenerateUniqueName(); - _channel.DeclareQueue(_queueName, true, false, false); - - _channel.Bind(_queueName, ExchangeNameDefaults.TOPIC, _routingKey); - - // Clear the most recent message and exception. - _lastException = null; - } - - [TearDown] - public virtual void ShutDown() - { - _logger.Info("public virtual void Shutdown(): called"); - - if (_connection != null) - { - _logger.Info("Disposing connection."); - _connection.Dispose(); - _logger.Info("Connection disposed."); - } - } - - [Test] - public void DeleteUsedQueue() - { - // Create the consumer - _consumer = _channel.CreateConsumerBuilder(_queueName) - .WithPrefetchLow(100) - .Create(); - _logger.Info("Consumer was created..."); - - // delete the queue - _channel.DeleteQueue(_queueName, false, true, true); - _logger.InfoFormat("Queue {0} was delete", _queueName); - - Assert.IsNull(_lastException); - } - - [Test] - public void DeleteUnusedQueue() - { - // delete the queue - _channel.DeleteQueue(_queueName, true, true, true); - _logger.InfoFormat("Queue {0} was delete", _queueName); - - Assert.IsNull(_lastException); - } - - [Test] - public void DeleteNonEmptyQueue() - { - // Create the publisher - _publisher = _channel.CreatePublisherBuilder() - .WithExchangeName(ExchangeNameDefaults.TOPIC) - .WithRoutingKey(_routingKey) - .Create(); - _logger.Info("Publisher created..."); - SendTestMessage("DeleteNonEmptyQueue Message 1"); - - try - { - _channel.DeleteQueue(_queueName, true, false, true); - } - catch (AMQException) - { - Assert.Fail("The test fails"); - } - } - - [Test] - public void DeleteEmptyQueue() - { - // Create the publisher - _publisher = _channel.CreatePublisherBuilder() - .WithExchangeName(ExchangeNameDefaults.TOPIC) - .WithRoutingKey(_routingKey) - .Create(); - _logger.Info("Publisher created..."); - - // delete an empty queue with ifEmpty = true - _channel.DeleteQueue(_queueName, false, true, true); - - Assert.IsNull(_lastException); - } - - [Test] - public void DeleteQueueWithResponse() - { - // Create the publisher - _publisher = _channel.CreatePublisherBuilder() - .WithExchangeName(ExchangeNameDefaults.TOPIC) - .WithRoutingKey(_routingKey) - .Create(); - _logger.Info("Publisher created..."); - - SendTestMessage("DeleteQueueWithResponse Message 1"); - SendTestMessage("DeleteQueueWithResponse Message 2"); - - // delete the queue, the server must respond - _channel.DeleteQueue(_queueName, false, false, false); - } - - [Test] - public void PurgeQueueWithResponse() - { - _publisher = _channel.CreatePublisherBuilder() - .WithExchangeName(ExchangeNameDefaults.TOPIC) - .WithRoutingKey(_routingKey) - .Create(); - _logger.Info("Pubisher created"); - - SendTestMessage("Message 1"); - SendTestMessage("Message 2"); - - _channel.PurgeQueue(_queueName, false); - } - - [Test] - public void PurgeQueueWithOutResponse() - { - _publisher = _channel.CreatePublisherBuilder() - .WithExchangeName(ExchangeNameDefaults.TOPIC) - .WithRoutingKey(_routingKey) - .Create(); - _logger.Info("Pubisher created"); - - SendTestMessage("Message 1"); - SendTestMessage("Message 2"); - - _channel.PurgeQueue(_queueName, true); - } - - - /// - /// Callback method to handle any exceptions raised by the test connection. /// - /// The connection exception. - public void OnException(Exception e) - { - // Preserve the most recent exception in case test cases need to examine it. - _lastException = e; - - // Notify any waiting threads that an exception event has occurred. - _evt.Set(); - } - - /// - /// Sends the specified message to the test publisher, and confirms that it was received by the test consumer or not - /// depending on whether or not the message should be received by the consumer. - /// - /// Any exceptions raised by the connection will cause an Assert failure exception to be raised. - /// - /// - /// The message to send. - private void SendTestMessage(string msg) - { - // create the IMessage object - IMessage msgSend = _channel.CreateTextMessage(msg); - - // send the message - _publisher.Send(msgSend); - _logger.InfoFormat("The messages \"{0}\" was sent", msg); - } - - } -} +/* + * + * 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. + * + */ +using System; +using System.Net; +using System.Threading; +using log4net; +using Apache.Qpid.Client.Qms; +using Apache.Qpid.Client; +using Apache.Qpid.Messaging; +using NUnit.Framework; + +namespace Apache.Qpid.Integration.Tests.testcases +{ + /// + /// Test the queue methods + /// + [TestFixture, Category("Integration")] + public class ChannelQueueTest + { + private static ILog _logger = LogManager.GetLogger(typeof(ChannelQueueTest)); + + /// The default AMQ connection URL to use for tests. + const string DEFAULT_URI = "amqp://guest:guest@default/test?brokerlist='tcp://localhost:5672'"; + const string _routingKey = "ServiceQ1"; + + private ExceptionListenerDelegate _exceptionDelegate; + private AutoResetEvent _evt = new AutoResetEvent(false); + private Exception _lastException = null; + + private IMessageConsumer _consumer; + private IMessagePublisher _publisher; + private IChannel _channel; + private IConnection _connection; + + private string _queueName; + + [SetUp] + public virtual void Init() + { + _logger.Info("public virtual void Init(): called"); + + // Create a connection to the broker. + IConnectionInfo connectionInfo = QpidConnectionInfo.FromUrl(DEFAULT_URI); + _connection = new AMQConnection(connectionInfo); + _logger.Info("Starting..."); + + // Register this to listen for exceptions on the test connection. + _exceptionDelegate = new ExceptionListenerDelegate(OnException); + _connection.ExceptionListener += _exceptionDelegate; + + // Establish a session on the broker. + _channel = _connection.CreateChannel(false, AcknowledgeMode.AutoAcknowledge, 1); + + // Create a durable, non-temporary, non-exclusive queue. + _queueName = _channel.GenerateUniqueName(); + _channel.DeclareQueue(_queueName, true, false, false); + + _channel.Bind(_queueName, ExchangeNameDefaults.TOPIC, _routingKey); + + // Clear the most recent message and exception. + _lastException = null; + } + + [TearDown] + public virtual void ShutDown() + { + _logger.Info("public virtual void Shutdown(): called"); + + if (_connection != null) + { + _logger.Info("Disposing connection."); + _connection.Dispose(); + _logger.Info("Connection disposed."); + } + } + + [Test] + public void DeleteUsedQueue() + { + // Create the consumer + _consumer = _channel.CreateConsumerBuilder(_queueName) + .WithPrefetchLow(100) + .Create(); + _logger.Info("Consumer was created..."); + + // delete the queue + _channel.DeleteQueue(_queueName, false, true, true); + _logger.InfoFormat("Queue {0} was delete", _queueName); + + Assert.IsNull(_lastException); + } + + [Test] + public void DeleteUnusedQueue() + { + // delete the queue + _channel.DeleteQueue(_queueName, true, true, true); + _logger.InfoFormat("Queue {0} was delete", _queueName); + + Assert.IsNull(_lastException); + } + + [Test] + public void DeleteNonEmptyQueue() + { + // Create the publisher + _publisher = _channel.CreatePublisherBuilder() + .WithExchangeName(ExchangeNameDefaults.TOPIC) + .WithRoutingKey(_routingKey) + .Create(); + _logger.Info("Publisher created..."); + SendTestMessage("DeleteNonEmptyQueue Message 1"); + + try + { + _channel.DeleteQueue(_queueName, true, false, true); + } + catch (AMQException) + { + Assert.Fail("The test fails"); + } + } + + [Test] + public void DeleteEmptyQueue() + { + // Create the publisher + _publisher = _channel.CreatePublisherBuilder() + .WithExchangeName(ExchangeNameDefaults.TOPIC) + .WithRoutingKey(_routingKey) + .Create(); + _logger.Info("Publisher created..."); + + // delete an empty queue with ifEmpty = true + _channel.DeleteQueue(_queueName, false, true, true); + + Assert.IsNull(_lastException); + } + + [Test] + public void DeleteQueueWithResponse() + { + // Create the publisher + _publisher = _channel.CreatePublisherBuilder() + .WithExchangeName(ExchangeNameDefaults.TOPIC) + .WithRoutingKey(_routingKey) + .Create(); + _logger.Info("Publisher created..."); + + SendTestMessage("DeleteQueueWithResponse Message 1"); + SendTestMessage("DeleteQueueWithResponse Message 2"); + + // delete the queue, the server must respond + _channel.DeleteQueue(_queueName, false, false, false); + } + + [Test] + public void PurgeQueueWithResponse() + { + _publisher = _channel.CreatePublisherBuilder() + .WithExchangeName(ExchangeNameDefaults.TOPIC) + .WithRoutingKey(_routingKey) + .Create(); + _logger.Info("Pubisher created"); + + SendTestMessage("Message 1"); + SendTestMessage("Message 2"); + + _channel.PurgeQueue(_queueName, false); + } + + [Test] + public void PurgeQueueWithOutResponse() + { + _publisher = _channel.CreatePublisherBuilder() + .WithExchangeName(ExchangeNameDefaults.TOPIC) + .WithRoutingKey(_routingKey) + .Create(); + _logger.Info("Pubisher created"); + + SendTestMessage("Message 1"); + SendTestMessage("Message 2"); + + _channel.PurgeQueue(_queueName, true); + } + + + /// + /// Callback method to handle any exceptions raised by the test connection. /// + /// The connection exception. + public void OnException(Exception e) + { + // Preserve the most recent exception in case test cases need to examine it. + _lastException = e; + + // Notify any waiting threads that an exception event has occurred. + _evt.Set(); + } + + /// + /// Sends the specified message to the test publisher, and confirms that it was received by the test consumer or not + /// depending on whether or not the message should be received by the consumer. + /// + /// Any exceptions raised by the connection will cause an Assert failure exception to be raised. + /// + /// + /// The message to send. + private void SendTestMessage(string msg) + { + // create the IMessage object + IMessage msgSend = _channel.CreateTextMessage(msg); + + // send the message + _publisher.Send(msgSend); + _logger.InfoFormat("The messages \"{0}\" was sent", msg); + } + + } +} diff --git a/dotnet/Qpid.Integration.Tests/testcases/CommitRollbackTest.cs b/dotnet/Qpid.Integration.Tests/testcases/CommitRollbackTest.cs index 72074da809..dbb3f70aec 100644 --- a/dotnet/Qpid.Integration.Tests/testcases/CommitRollbackTest.cs +++ b/dotnet/Qpid.Integration.Tests/testcases/CommitRollbackTest.cs @@ -1,261 +1,261 @@ -/* - * - * 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. - * - */ -using System; -using System.Threading; -using log4net; -using NUnit.Framework; -using Apache.Qpid.Messaging; -using Apache.Qpid.Client.Qms; -using Apache.Qpid.Client; - -namespace Apache.Qpid.Integration.Tests.testcases -{ - /// - /// CommitRollbackTest - /// - ///

- ///
CRC Card
Responsibilities Collaborations - ///
Check that an uncommitted send cannot be received. - ///
Check that a committed send can be received. - ///
Check that a rolled back send cannot be received. - ///
Check that an uncommitted receive can be re-received. - ///
Check that a committed receive cannot be re-received. - ///
Check that a rolled back receive can be re-received. - ///
- ///

- [TestFixture, Category("Integration")] - public class CommitRollbackTest : BaseMessagingTestFixture - { - /// Used for debugging purposes. - private static ILog log = LogManager.GetLogger(typeof(CommitRollbackTest)); - - /// Defines the name of the test topic to use with the tests. - public const string TEST_ROUTING_KEY = "commitrollbacktestkey"; - - /// Used to count test messages received so far. - private int messageReceivedCount; - - /// Used to hold the expected number of messages to receive. - private int expectedMessageCount; - - /// Monitor used to signal succesfull receipt of all test messages. - AutoResetEvent finishedEvent; - - /// Flag used to indicate that all messages really were received, and that the test did not just time out. - private bool allReceived; - - [SetUp] - public override void Init() - { - base.Init(); - - // Create one producer and one consumer, p2p, tx, consumer with queue bound to producers routing key. - SetUpEndPoint(0, true, false, TEST_ROUTING_KEY + testId, AcknowledgeMode.AutoAcknowledge, true, ExchangeNameDefaults.DIRECT, - true, false, null); - SetUpEndPoint(1, true, true, TEST_ROUTING_KEY + testId, AcknowledgeMode.AutoAcknowledge, true, ExchangeNameDefaults.DIRECT, - true, false, null); - - // Clear counts - messageReceivedCount = 0; - expectedMessageCount = 0; - finishedEvent = new AutoResetEvent(false); - allReceived = false; - } - - [TearDown] - public override void Shutdown() - { - try - { - // Clean up after the test. - CloseEndPoint(0); - CloseEndPoint(1); - } - finally - { - base.Shutdown(); - } - } - - /// Check that an uncommitted send cannot be received. - [Test] - public void TestUncommittedSendNotReceived() - { - // Send messages. - testProducer[0].Send(testChannel[0].CreateTextMessage("A")); - - // Try to receive messages. - ConsumeNMessagesOnly(0, "A", testConsumer[1]); - testChannel[1].Commit(); - } - - /// Check that a committed send can be received. - [Test] - public void TestCommittedSendReceived() - { - // Send messages. - testProducer[0].Send(testChannel[0].CreateTextMessage("B")); - testChannel[0].Commit(); - - // Try to receive messages. - ConsumeNMessagesOnly(1, "B", testConsumer[1]); - testChannel[1].Commit(); - } - - /// Check that a rolled back send cannot be received. - [Test] - public void TestRolledBackSendNotReceived() - { - // Send messages. - testProducer[0].Send(testChannel[0].CreateTextMessage("B")); - testChannel[0].Rollback(); - - // Try to receive messages. - ConsumeNMessagesOnly(0, "B", testConsumer[1]); - testChannel[1].Commit(); - } - - /// Check that an uncommitted receive can be re-received. - [Test] - public void TestUncommittedReceiveCanBeRereceived() - { - // Create a third end-point as an alternative delivery route for the message. - SetUpEndPoint(2, false, true, TEST_ROUTING_KEY + testId, AcknowledgeMode.AutoAcknowledge, true, ExchangeNameDefaults.DIRECT, - true, false, null); - - // Send messages. - testProducer[0].Send(testChannel[0].CreateTextMessage("C")); - testChannel[0].Commit(); - - // Try to receive messages. - ConsumeNMessagesOnly(1, "C", testConsumer[1]); - - // Close end-point 1 without committing the message, then re-open to consume again. - CloseEndPoint(1); - - // Check that the message was released from the rolled back end-point an can be received on the alternative one instead. - ConsumeNMessagesOnly(1, "C", testConsumer[2]); - - CloseEndPoint(2); - } - - /// Check that a committed receive cannot be re-received. - [Test] - public void TestCommittedReceiveNotRereceived() - { - // Send messages. - testProducer[0].Send(testChannel[0].CreateTextMessage("D")); - testChannel[0].Commit(); - - // Try to receive messages. - ConsumeNMessagesOnly(1, "D", testConsumer[1]); - testChannel[1].Commit(); - - // Try to receive messages. - ConsumeNMessagesOnly(0, "D", testConsumer[1]); - } - - /// Check that a rolled back receive can be re-received. - [Test] - public void TestRolledBackReceiveCanBeRereceived() - { - // Send messages. - testProducer[0].Send(testChannel[0].CreateTextMessage("E")); - testChannel[0].Commit(); - - // Try to receive messages. - ConsumeNMessagesOnly(1, "E", testConsumer[1]); - - testChannel[1].Rollback(); - - // Try to receive messages. - ConsumeNMessagesOnly(1, "E", testConsumer[1]); - - } - - [Test] - public void TestReceiveAndSendRollback() - { - // Send messages - testProducer[0].Send(testChannel[0].CreateTextMessage("F")); - testChannel[0].Commit(); - - // Try to receive messages. - ConsumeNMessagesOnly(1, "F", testConsumer[1]); - testProducer[1].Send(testChannel[1].CreateTextMessage("G")); - testChannel[1].Rollback(); - - // Try to receive messages. - ConsumeNMessagesOnly(1, "F", testConsumer[1]); - - } - - [Test] - public void TestReceivePrePublished() - { - // Send messages - for (int i = 0; i < 10; ++i) - { - testProducer[0].Send(testChannel[0].CreateTextMessage("G"+i)); - testChannel[0].Commit(); - } - - for (int i = 0; i < 10; ++i) - { - ConsumeNMessages(1, "G"+i, testConsumer[1]); - } - testChannel[1].Commit(); - } - - [Test] - public void TestReceivePrePublishedOnMessageHandler() - { - testConsumer[1].OnMessage += new MessageReceivedDelegate(OnMessage); - // Send messages - for (int i = 0; i < 10; ++i) - { - testProducer[0].Send(testChannel[0].CreateTextMessage("G"+i)); - testChannel[0].Commit(); - } - expectedMessageCount = 10; - - finishedEvent.WaitOne(new TimeSpan(0, 0, 0, 30), false); - - // Check that all messages really were received. - Assert.IsTrue(allReceived, "All messages were not received, only got: " + messageReceivedCount + " but wanted " + expectedMessageCount); - - testChannel[1].Commit(); - } - - /// Atomically increments the message count on every message, and signals once all messages in the test are received. - public void OnMessage(IMessage m) - { - int newCount = Interlocked.Increment(ref messageReceivedCount); - - if (newCount >= expectedMessageCount) - { - allReceived = true; - finishedEvent.Set(); - } - } - - } -} +/* + * + * 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. + * + */ +using System; +using System.Threading; +using log4net; +using NUnit.Framework; +using Apache.Qpid.Messaging; +using Apache.Qpid.Client.Qms; +using Apache.Qpid.Client; + +namespace Apache.Qpid.Integration.Tests.testcases +{ + /// + /// CommitRollbackTest + /// + ///

+ ///
CRC Card
Responsibilities Collaborations + ///
Check that an uncommitted send cannot be received. + ///
Check that a committed send can be received. + ///
Check that a rolled back send cannot be received. + ///
Check that an uncommitted receive can be re-received. + ///
Check that a committed receive cannot be re-received. + ///
Check that a rolled back receive can be re-received. + ///
+ ///

+ [TestFixture, Category("Integration")] + public class CommitRollbackTest : BaseMessagingTestFixture + { + /// Used for debugging purposes. + private static ILog log = LogManager.GetLogger(typeof(CommitRollbackTest)); + + /// Defines the name of the test topic to use with the tests. + public const string TEST_ROUTING_KEY = "commitrollbacktestkey"; + + /// Used to count test messages received so far. + private int messageReceivedCount; + + /// Used to hold the expected number of messages to receive. + private int expectedMessageCount; + + /// Monitor used to signal succesfull receipt of all test messages. + AutoResetEvent finishedEvent; + + /// Flag used to indicate that all messages really were received, and that the test did not just time out. + private bool allReceived; + + [SetUp] + public override void Init() + { + base.Init(); + + // Create one producer and one consumer, p2p, tx, consumer with queue bound to producers routing key. + SetUpEndPoint(0, true, false, TEST_ROUTING_KEY + testId, AcknowledgeMode.AutoAcknowledge, true, ExchangeNameDefaults.DIRECT, + true, false, null); + SetUpEndPoint(1, true, true, TEST_ROUTING_KEY + testId, AcknowledgeMode.AutoAcknowledge, true, ExchangeNameDefaults.DIRECT, + true, false, null); + + // Clear counts + messageReceivedCount = 0; + expectedMessageCount = 0; + finishedEvent = new AutoResetEvent(false); + allReceived = false; + } + + [TearDown] + public override void Shutdown() + { + try + { + // Clean up after the test. + CloseEndPoint(0); + CloseEndPoint(1); + } + finally + { + base.Shutdown(); + } + } + + /// Check that an uncommitted send cannot be received. + [Test] + public void TestUncommittedSendNotReceived() + { + // Send messages. + testProducer[0].Send(testChannel[0].CreateTextMessage("A")); + + // Try to receive messages. + ConsumeNMessagesOnly(0, "A", testConsumer[1]); + testChannel[1].Commit(); + } + + /// Check that a committed send can be received. + [Test] + public void TestCommittedSendReceived() + { + // Send messages. + testProducer[0].Send(testChannel[0].CreateTextMessage("B")); + testChannel[0].Commit(); + + // Try to receive messages. + ConsumeNMessagesOnly(1, "B", testConsumer[1]); + testChannel[1].Commit(); + } + + /// Check that a rolled back send cannot be received. + [Test] + public void TestRolledBackSendNotReceived() + { + // Send messages. + testProducer[0].Send(testChannel[0].CreateTextMessage("B")); + testChannel[0].Rollback(); + + // Try to receive messages. + ConsumeNMessagesOnly(0, "B", testConsumer[1]); + testChannel[1].Commit(); + } + + /// Check that an uncommitted receive can be re-received. + [Test] + public void TestUncommittedReceiveCanBeRereceived() + { + // Create a third end-point as an alternative delivery route for the message. + SetUpEndPoint(2, false, true, TEST_ROUTING_KEY + testId, AcknowledgeMode.AutoAcknowledge, true, ExchangeNameDefaults.DIRECT, + true, false, null); + + // Send messages. + testProducer[0].Send(testChannel[0].CreateTextMessage("C")); + testChannel[0].Commit(); + + // Try to receive messages. + ConsumeNMessagesOnly(1, "C", testConsumer[1]); + + // Close end-point 1 without committing the message, then re-open to consume again. + CloseEndPoint(1); + + // Check that the message was released from the rolled back end-point an can be received on the alternative one instead. + ConsumeNMessagesOnly(1, "C", testConsumer[2]); + + CloseEndPoint(2); + } + + /// Check that a committed receive cannot be re-received. + [Test] + public void TestCommittedReceiveNotRereceived() + { + // Send messages. + testProducer[0].Send(testChannel[0].CreateTextMessage("D")); + testChannel[0].Commit(); + + // Try to receive messages. + ConsumeNMessagesOnly(1, "D", testConsumer[1]); + testChannel[1].Commit(); + + // Try to receive messages. + ConsumeNMessagesOnly(0, "D", testConsumer[1]); + } + + /// Check that a rolled back receive can be re-received. + [Test] + public void TestRolledBackReceiveCanBeRereceived() + { + // Send messages. + testProducer[0].Send(testChannel[0].CreateTextMessage("E")); + testChannel[0].Commit(); + + // Try to receive messages. + ConsumeNMessagesOnly(1, "E", testConsumer[1]); + + testChannel[1].Rollback(); + + // Try to receive messages. + ConsumeNMessagesOnly(1, "E", testConsumer[1]); + + } + + [Test] + public void TestReceiveAndSendRollback() + { + // Send messages + testProducer[0].Send(testChannel[0].CreateTextMessage("F")); + testChannel[0].Commit(); + + // Try to receive messages. + ConsumeNMessagesOnly(1, "F", testConsumer[1]); + testProducer[1].Send(testChannel[1].CreateTextMessage("G")); + testChannel[1].Rollback(); + + // Try to receive messages. + ConsumeNMessagesOnly(1, "F", testConsumer[1]); + + } + + [Test] + public void TestReceivePrePublished() + { + // Send messages + for (int i = 0; i < 10; ++i) + { + testProducer[0].Send(testChannel[0].CreateTextMessage("G"+i)); + testChannel[0].Commit(); + } + + for (int i = 0; i < 10; ++i) + { + ConsumeNMessages(1, "G"+i, testConsumer[1]); + } + testChannel[1].Commit(); + } + + [Test] + public void TestReceivePrePublishedOnMessageHandler() + { + testConsumer[1].OnMessage += new MessageReceivedDelegate(OnMessage); + // Send messages + for (int i = 0; i < 10; ++i) + { + testProducer[0].Send(testChannel[0].CreateTextMessage("G"+i)); + testChannel[0].Commit(); + } + expectedMessageCount = 10; + + finishedEvent.WaitOne(new TimeSpan(0, 0, 0, 30), false); + + // Check that all messages really were received. + Assert.IsTrue(allReceived, "All messages were not received, only got: " + messageReceivedCount + " but wanted " + expectedMessageCount); + + testChannel[1].Commit(); + } + + /// Atomically increments the message count on every message, and signals once all messages in the test are received. + public void OnMessage(IMessage m) + { + int newCount = Interlocked.Increment(ref messageReceivedCount); + + if (newCount >= expectedMessageCount) + { + allReceived = true; + finishedEvent.Set(); + } + } + + } +} diff --git a/dotnet/Qpid.Integration.Tests/testcases/ConnectionTest.cs b/dotnet/Qpid.Integration.Tests/testcases/ConnectionTest.cs index 357f164346..d7b4a4ddd2 100644 --- a/dotnet/Qpid.Integration.Tests/testcases/ConnectionTest.cs +++ b/dotnet/Qpid.Integration.Tests/testcases/ConnectionTest.cs @@ -1,73 +1,73 @@ -/* - * - * 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. - * - */ -using System; -using NUnit.Framework; -using Apache.Qpid.Client.Qms; -using Apache.Qpid.Client; -using Apache.Qpid.Messaging; - -namespace Apache.Qpid.Integration.Tests.testcases -{ - [TestFixture, Category("Integration")] - public class ConnectionTest - { - private AmqBrokerInfo _broker = - new AmqBrokerInfo("amqp", "localhost", 5672, false); - - [Test] - public void SimpleConnection() - { - IConnectionInfo connectionInfo = new QpidConnectionInfo(); - connectionInfo.VirtualHost = "test"; - connectionInfo.AddBrokerInfo(_broker); - using (IConnection connection = new AMQConnection(connectionInfo)) - { - Console.WriteLine("connection = " + connection); - } - } - - [Test] - [ExpectedException(typeof(AMQAuthenticationException))] - public void PasswordFailureConnection() - { - IConnectionInfo connectionInfo = new QpidConnectionInfo(); - connectionInfo.VirtualHost = "test"; - connectionInfo.Password = "rubbish"; - connectionInfo.AddBrokerInfo(_broker); - - using (IConnection connection = new AMQConnection(connectionInfo)) - { - Console.WriteLine("connection = " + connection); - // wrong - Assert.Fail("Authentication succeeded but should've failed"); - } - } - - [Test] - [ExpectedException(typeof(AMQConnectionException))] - public void ConnectionFailure() - { - string url = "amqp://guest:guest@clientid/testpath?brokerlist='tcp://localhost:5673?retries='0''"; - new AMQConnection(QpidConnectionInfo.FromUrl(url)); - Assert.Fail("Connection should not be established"); - } - } -} +/* + * + * 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. + * + */ +using System; +using NUnit.Framework; +using Apache.Qpid.Client.Qms; +using Apache.Qpid.Client; +using Apache.Qpid.Messaging; + +namespace Apache.Qpid.Integration.Tests.testcases +{ + [TestFixture, Category("Integration")] + public class ConnectionTest + { + private AmqBrokerInfo _broker = + new AmqBrokerInfo("amqp", "localhost", 5672, false); + + [Test] + public void SimpleConnection() + { + IConnectionInfo connectionInfo = new QpidConnectionInfo(); + connectionInfo.VirtualHost = "test"; + connectionInfo.AddBrokerInfo(_broker); + using (IConnection connection = new AMQConnection(connectionInfo)) + { + Console.WriteLine("connection = " + connection); + } + } + + [Test] + [ExpectedException(typeof(AMQAuthenticationException))] + public void PasswordFailureConnection() + { + IConnectionInfo connectionInfo = new QpidConnectionInfo(); + connectionInfo.VirtualHost = "test"; + connectionInfo.Password = "rubbish"; + connectionInfo.AddBrokerInfo(_broker); + + using (IConnection connection = new AMQConnection(connectionInfo)) + { + Console.WriteLine("connection = " + connection); + // wrong + Assert.Fail("Authentication succeeded but should've failed"); + } + } + + [Test] + [ExpectedException(typeof(AMQConnectionException))] + public void ConnectionFailure() + { + string url = "amqp://guest:guest@clientid/testpath?brokerlist='tcp://localhost:5673?retries='0''"; + new AMQConnection(QpidConnectionInfo.FromUrl(url)); + Assert.Fail("Connection should not be established"); + } + } +} diff --git a/dotnet/Qpid.Integration.Tests/testcases/DurableSubscriptionTest.cs b/dotnet/Qpid.Integration.Tests/testcases/DurableSubscriptionTest.cs index ac975100b1..b7973ae3f5 100644 --- a/dotnet/Qpid.Integration.Tests/testcases/DurableSubscriptionTest.cs +++ b/dotnet/Qpid.Integration.Tests/testcases/DurableSubscriptionTest.cs @@ -1,166 +1,166 @@ -/* - * - * 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. - * - */ -using System; -using System.Threading; -using log4net; -using NUnit.Framework; -using Apache.Qpid.Messaging; -using Apache.Qpid.Client.Qms; - -namespace Apache.Qpid.Integration.Tests.testcases -{ - /// - /// DurableSubscriptionTest checks that durable subscriptions work, by sending messages that can be picked up by - /// a subscription that is currently off-line, and checking that the subscriber gets all of its messages when it - /// does come on-line. - /// - ///

- ///
CRC Card
Responsibilities Collaborations - ///
- ///
- ///

- [TestFixture, Category("Integration")] - public class DurableSubscriptionTest : BaseMessagingTestFixture - { - /// Used for debugging purposes. - private static ILog log = LogManager.GetLogger(typeof(DurableSubscriptionTest)); - - /// Defines the name of the test topic to use with the tests. - public const string TEST_ROUTING_KEY = "durablesubtestkey"; - - [SetUp] - public override void Init() - { - base.Init(); - } - - [TearDown] - public override void Shutdown() - { - base.Shutdown(); - } - - [Test] - public void TestDurableSubscriptionNoAck() - { - TestDurableSubscription(AcknowledgeMode.NoAcknowledge); - } - - [Test] - public void TestDurableSubscriptionAutoAck() - { - TestDurableSubscription(AcknowledgeMode.AutoAcknowledge); - } - - private void TestDurableSubscription(AcknowledgeMode ackMode) - { - // Create a topic with one producer and two consumers. - SetUpEndPoint(0, true, false, TEST_ROUTING_KEY + testId, ackMode, false, ExchangeNameDefaults.TOPIC, true, false, null); - SetUpEndPoint(1, false, true, TEST_ROUTING_KEY + testId, ackMode, false, ExchangeNameDefaults.TOPIC, true, false, null); - SetUpEndPoint(2, false, true, TEST_ROUTING_KEY + testId, ackMode, false, ExchangeNameDefaults.TOPIC, true, - true, "TestSubscription" + testId); - - Thread.Sleep(500); - - // Send messages and receive on both consumers. - testProducer[0].Send(testChannel[0].CreateTextMessage("A")); - - ConsumeNMessagesOnly(1, "A", testConsumer[1]); - ConsumeNMessagesOnly(1, "A", testConsumer[2]); - - // Detach one consumer. - CloseEndPoint(2); - - // Send message and receive on one consumer. - testProducer[0].Send(testChannel[0].CreateTextMessage("B")); - - ConsumeNMessagesOnly(1, "B", testConsumer[1]); - - // Re-attach consumer, check that it gets the messages that it missed. - SetUpEndPoint(2, false, true, TEST_ROUTING_KEY + testId, ackMode, false, ExchangeNameDefaults.TOPIC, true, - true, "TestSubscription" + testId); - - ConsumeNMessagesOnly(1, "B", testConsumer[2]); - - // Clean up any open consumers at the end of the test. - CloseEndPoint(2); - CloseEndPoint(1); - CloseEndPoint(0); - } - - /// Check that an uncommitted receive can be re-received, on re-consume from the same durable subscription. - [Test] - public void TestUncommittedReceiveCanBeRereceivedNewConnection() - { - SetUpEndPoint(0, true, false, TEST_ROUTING_KEY + testId, AcknowledgeMode.AutoAcknowledge, true, ExchangeNameDefaults.TOPIC, - true, false, null); - SetUpEndPoint(1, false, true, TEST_ROUTING_KEY + testId, AcknowledgeMode.AutoAcknowledge, true, ExchangeNameDefaults.TOPIC, - true, true, "foo"+testId); - - // Send messages. - testProducer[0].Send(testChannel[0].CreateTextMessage("C")); - testChannel[0].Commit(); - - // Try to receive messages, but don't commit them. - ConsumeNMessagesOnly(1, "C", testConsumer[1]); - - // Close end-point 1 without committing the message, then re-open the subscription to consume again. - CloseEndPoint(1); - SetUpEndPoint(1, false, true, TEST_ROUTING_KEY + testId, AcknowledgeMode.AutoAcknowledge, true, ExchangeNameDefaults.TOPIC, - true, true, "foo"+testId); - - // Check that the message was released from the rolled back end-point an can be received on the alternative one instead. - ConsumeNMessagesOnly(1, "C", testConsumer[1]); - testChannel[1].Commit(); - CloseEndPoint(1); - CloseEndPoint(0); - } - - /// Check that a rolled back receive can be re-received, on re-consume from the same durable subscription. - [Test] - public void TestRolledBackReceiveCanBeRereceivedNewConnection() - { - SetUpEndPoint(0, true, false, TEST_ROUTING_KEY + testId, AcknowledgeMode.AutoAcknowledge, true, ExchangeNameDefaults.TOPIC, - true, false, null); - SetUpEndPoint(1, false, true, TEST_ROUTING_KEY + testId, AcknowledgeMode.AutoAcknowledge, true, ExchangeNameDefaults.TOPIC, - true, true, "foo"+testId); - - // Send messages. - testProducer[0].Send(testChannel[0].CreateTextMessage("D")); - testChannel[0].Commit(); - - // Try to receive messages, but roll them back. - ConsumeNMessagesOnly(1, "D", testConsumer[1]); - testChannel[1].Rollback(); - - // Close end-point 1 without committing the message, then re-open the subscription to consume again. - CloseEndPoint(1); - SetUpEndPoint(1, false, true, TEST_ROUTING_KEY + testId, AcknowledgeMode.AutoAcknowledge, true, ExchangeNameDefaults.TOPIC, - true, true, "foo"+testId); - - // Check that the message was released from the rolled back end-point an can be received on the alternative one instead. - ConsumeNMessagesOnly(1, "D", testConsumer[1]); - testChannel[1].Commit(); - CloseEndPoint(1); - CloseEndPoint(0); - } - } -} +/* + * + * 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. + * + */ +using System; +using System.Threading; +using log4net; +using NUnit.Framework; +using Apache.Qpid.Messaging; +using Apache.Qpid.Client.Qms; + +namespace Apache.Qpid.Integration.Tests.testcases +{ + /// + /// DurableSubscriptionTest checks that durable subscriptions work, by sending messages that can be picked up by + /// a subscription that is currently off-line, and checking that the subscriber gets all of its messages when it + /// does come on-line. + /// + ///

+ ///
CRC Card
Responsibilities Collaborations + ///
+ ///
+ ///

+ [TestFixture, Category("Integration")] + public class DurableSubscriptionTest : BaseMessagingTestFixture + { + /// Used for debugging purposes. + private static ILog log = LogManager.GetLogger(typeof(DurableSubscriptionTest)); + + /// Defines the name of the test topic to use with the tests. + public const string TEST_ROUTING_KEY = "durablesubtestkey"; + + [SetUp] + public override void Init() + { + base.Init(); + } + + [TearDown] + public override void Shutdown() + { + base.Shutdown(); + } + + [Test] + public void TestDurableSubscriptionNoAck() + { + TestDurableSubscription(AcknowledgeMode.NoAcknowledge); + } + + [Test] + public void TestDurableSubscriptionAutoAck() + { + TestDurableSubscription(AcknowledgeMode.AutoAcknowledge); + } + + private void TestDurableSubscription(AcknowledgeMode ackMode) + { + // Create a topic with one producer and two consumers. + SetUpEndPoint(0, true, false, TEST_ROUTING_KEY + testId, ackMode, false, ExchangeNameDefaults.TOPIC, true, false, null); + SetUpEndPoint(1, false, true, TEST_ROUTING_KEY + testId, ackMode, false, ExchangeNameDefaults.TOPIC, true, false, null); + SetUpEndPoint(2, false, true, TEST_ROUTING_KEY + testId, ackMode, false, ExchangeNameDefaults.TOPIC, true, + true, "TestSubscription" + testId); + + Thread.Sleep(500); + + // Send messages and receive on both consumers. + testProducer[0].Send(testChannel[0].CreateTextMessage("A")); + + ConsumeNMessagesOnly(1, "A", testConsumer[1]); + ConsumeNMessagesOnly(1, "A", testConsumer[2]); + + // Detach one consumer. + CloseEndPoint(2); + + // Send message and receive on one consumer. + testProducer[0].Send(testChannel[0].CreateTextMessage("B")); + + ConsumeNMessagesOnly(1, "B", testConsumer[1]); + + // Re-attach consumer, check that it gets the messages that it missed. + SetUpEndPoint(2, false, true, TEST_ROUTING_KEY + testId, ackMode, false, ExchangeNameDefaults.TOPIC, true, + true, "TestSubscription" + testId); + + ConsumeNMessagesOnly(1, "B", testConsumer[2]); + + // Clean up any open consumers at the end of the test. + CloseEndPoint(2); + CloseEndPoint(1); + CloseEndPoint(0); + } + + /// Check that an uncommitted receive can be re-received, on re-consume from the same durable subscription. + [Test] + public void TestUncommittedReceiveCanBeRereceivedNewConnection() + { + SetUpEndPoint(0, true, false, TEST_ROUTING_KEY + testId, AcknowledgeMode.AutoAcknowledge, true, ExchangeNameDefaults.TOPIC, + true, false, null); + SetUpEndPoint(1, false, true, TEST_ROUTING_KEY + testId, AcknowledgeMode.AutoAcknowledge, true, ExchangeNameDefaults.TOPIC, + true, true, "foo"+testId); + + // Send messages. + testProducer[0].Send(testChannel[0].CreateTextMessage("C")); + testChannel[0].Commit(); + + // Try to receive messages, but don't commit them. + ConsumeNMessagesOnly(1, "C", testConsumer[1]); + + // Close end-point 1 without committing the message, then re-open the subscription to consume again. + CloseEndPoint(1); + SetUpEndPoint(1, false, true, TEST_ROUTING_KEY + testId, AcknowledgeMode.AutoAcknowledge, true, ExchangeNameDefaults.TOPIC, + true, true, "foo"+testId); + + // Check that the message was released from the rolled back end-point an can be received on the alternative one instead. + ConsumeNMessagesOnly(1, "C", testConsumer[1]); + testChannel[1].Commit(); + CloseEndPoint(1); + CloseEndPoint(0); + } + + /// Check that a rolled back receive can be re-received, on re-consume from the same durable subscription. + [Test] + public void TestRolledBackReceiveCanBeRereceivedNewConnection() + { + SetUpEndPoint(0, true, false, TEST_ROUTING_KEY + testId, AcknowledgeMode.AutoAcknowledge, true, ExchangeNameDefaults.TOPIC, + true, false, null); + SetUpEndPoint(1, false, true, TEST_ROUTING_KEY + testId, AcknowledgeMode.AutoAcknowledge, true, ExchangeNameDefaults.TOPIC, + true, true, "foo"+testId); + + // Send messages. + testProducer[0].Send(testChannel[0].CreateTextMessage("D")); + testChannel[0].Commit(); + + // Try to receive messages, but roll them back. + ConsumeNMessagesOnly(1, "D", testConsumer[1]); + testChannel[1].Rollback(); + + // Close end-point 1 without committing the message, then re-open the subscription to consume again. + CloseEndPoint(1); + SetUpEndPoint(1, false, true, TEST_ROUTING_KEY + testId, AcknowledgeMode.AutoAcknowledge, true, ExchangeNameDefaults.TOPIC, + true, true, "foo"+testId); + + // Check that the message was released from the rolled back end-point an can be received on the alternative one instead. + ConsumeNMessagesOnly(1, "D", testConsumer[1]); + testChannel[1].Commit(); + CloseEndPoint(1); + CloseEndPoint(0); + } + } +} diff --git a/dotnet/Qpid.Integration.Tests/testcases/HeadersExchangeTest.cs b/dotnet/Qpid.Integration.Tests/testcases/HeadersExchangeTest.cs index 5e17cf1d2d..2094aa3b1b 100644 --- a/dotnet/Qpid.Integration.Tests/testcases/HeadersExchangeTest.cs +++ b/dotnet/Qpid.Integration.Tests/testcases/HeadersExchangeTest.cs @@ -1,282 +1,282 @@ -/* - * - * 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. - * - */ -using System; -using System.Threading; -using log4net; -using NUnit.Framework; -using Apache.Qpid.Framing; -using Apache.Qpid.Messaging; -using Apache.Qpid.Client.Qms; -using Apache.Qpid.Client; - -namespace Apache.Qpid.Integration.Tests.testcases -{ - /// - /// Sets up a producer/consumer pair to send test messages through a header exchange. The header exchange matching pattern is tested to - /// verify that it correctly matches or filters out messages based on their headers. - /// - /// Check that a message matching all fields of a headers exchange is passed by the exchange. - /// Check that a message containing values for empty fields of a headers exchange is passed by the exchange. - /// Check that a message matching only some fields of a headers exhcnage is not passed by the exchange. - /// Check that a message with additional fields to the correct matching fields of a headers exchange is passed by the exchange. - /// - /// - /// Remove the HeadersMatchingProducer class and rename this to HeaderExchangeTest. The producer and consumer are implemented - /// in a single test class to make running this as part of an automated test suite possible. - /// - /// Consider not using a delegate to callback the OnMessage method. Easier to just call receive on the consumer but using the - /// callback does demonstrate how to do so. - [TestFixture, Category("Integration")] - public class HeadersExchangeTest : BaseMessagingTestFixture - { - private static ILog _logger = LogManager.GetLogger(typeof(HeadersExchangeTest)); - - /// Holds the default test timeout for broker communications before tests give up. - private static readonly int TIMEOUT = 2000; - - /// Holds the name of the headers exchange to create to send test messages on. - private string _exchangeName = "ServiceQ1"; - - /// Used to preserve the most recent exception in case test cases need to examine it. - private Exception _lastException = null; - - /// Used to preserve the most recent message from the test consumer. - private IMessage _lastMessage = null; - - /// The test consumer to get messages from the broker with. - private IMessageConsumer _consumer; - - private IMessagePublisher _publisher; - - private AutoResetEvent _evt = new AutoResetEvent(false); - - private MessageReceivedDelegate _msgRecDelegate; - private ExceptionListenerDelegate _exceptionDelegate; - - /// Holds the test connection. - protected IConnection _connection; - - /// Holds the test channel. - protected IChannel _channel; - - [SetUp] - public override void Init() - { - // Ensure that the base init method is called. It establishes a connection with the broker. - base.Init(); - - connectionInfo = QpidConnectionInfo.FromUrl(connectionUri); - _connection = new AMQConnection(connectionInfo); - _channel = _connection.CreateChannel(false, AcknowledgeMode.AutoAcknowledge, 500, 300); - - _logger.Info("Starting..."); - _logger.Info("Exchange name is '" + _exchangeName + "'..."); - - // Register this to listen for exceptions on the test connection. - _exceptionDelegate = new ExceptionListenerDelegate(OnException); - _connection.ExceptionListener += _exceptionDelegate; - - // Declare a new headers exchange with the name of the test service. - _channel.DeclareExchange(_exchangeName, ExchangeClassConstants.HEADERS); - - // Create a non-durable, temporary (aka auto-delete), exclusive queue. - string queueName = _channel.GenerateUniqueName(); - _channel.DeclareQueue(queueName, false, true, true); - - // Bind the queue to the new headers exchange, setting up some header patterns for the exchange to match. - _channel.Bind(queueName, _exchangeName, null, CreatePatternAsFieldTable()); - - // Create a test consumer to consume messages from the test exchange. - _consumer = _channel.CreateConsumerBuilder(queueName) - .WithPrefetchLow(100) - .WithPrefetchHigh(500) - .WithNoLocal(false) // make sure we get our own messages - .Create(); - - // Register this to listen for messages on the consumer. - _msgRecDelegate = new MessageReceivedDelegate(OnMessage); - _consumer.OnMessage += _msgRecDelegate; - - // Clear the most recent message and exception. - _lastException = null; - _lastMessage = null; - - _publisher = _channel.CreatePublisherBuilder() - .WithExchangeName(_exchangeName) - .WithMandatory(true) - .Create(); - - _publisher.DeliveryMode = DeliveryMode.NonPersistent; - - // Start all channel - _connection.Start(); - } - - /// - /// Deregisters the on message delegate before closing the connection. - /// - [TearDown] - public override void Shutdown() - { - _logger.Info("public void Shutdown(): called"); - - //_consumer.OnMessage -= _msgRecDelegate; - //_connection.ExceptionListener -= _exceptionDelegate; - - _connection.Stop(); - _connection.Close(); - _connection.Dispose(); - - base.Shutdown(); - } - - /// - /// Callback method that is passed any messages received on the test channel. - /// - /// - /// The received message. - public void OnMessage(IMessage message) - { - _logger.Debug(string.Format("message.Type = {0}", message.GetType())); - _logger.Debug("Got message '" + message + "'"); - - // Preserve the most recent exception so that test cases can examine it. - _lastMessage = message; - - // Notify any waiting threads that a message has been received. - _evt.Set(); - } - - /// Callback method to handle any exceptions raised by the test connection. - /// - /// The connection exception. - public void OnException(Exception e) - { - // Preserve the most recent exception in case test cases need to examine it. - _lastException = e; - - // Notify any waiting threads that an exception event has occurred. - _evt.Set(); - } - - /// Check that a message matching all fields of a headers exchange is passed by the exchange. - [Test] - public void TestMatchAll() - { - IMessage msg = _channel.CreateTextMessage("matches match2=''"); - msg.Headers["match1"] = "foo"; - msg.Headers["match2"] = ""; - - // Use the SendTestMessage helper method to verify that the message was sent and received. - SendTestMessage(msg, true); - } - - /// Check that a message containing values for empty fields of a headers exchange is passed by the exchange. - [Test] - public void TestMatchEmptyMatchesAnything() - { - // Send a test message that matches the headers exchange. - IMessage msg = _channel.CreateTextMessage("matches match1='foo' and match2='bar'"); - msg.Headers["match1"] = "foo"; - msg.Headers["match2"] = "bar"; - - // Use the SendTestMessage helper method to verify that the message was sent and received. - SendTestMessage(msg, true); - } - - /// Check that a message matching only some fields of a headers exchange is not passed by the exchange. - [Test] - public void TestMatchOneFails() - { - IMessage msg = _channel.CreateTextMessage("not match - only match1"); - msg.Headers["match1"] = "foo"; - - // Use the SendTestMessage helper method to verify that the message was sent and not received. - SendTestMessage(msg, false); - } - - /// - /// Check that a message with additional fields to the correct matching fields of a headers exchange is passed by - /// the exchange. - /// - [Test] - public void TestMatchExtraFields() - { - IMessage msg = _channel.CreateTextMessage("matches - extra headers"); - msg.Headers["match1"] = "foo"; - msg.Headers["match2"] = "bar"; - msg.Headers["match3"] = "not required"; - - // Use the SendTestMessage helper method to verify that the message was sent and received. - SendTestMessage(msg, true); - } - - /// - /// Sends the specified message to the test publisher, and confirms that it was received by the test consumer or not - /// depending on whether or not the message should be received by the consumer. - /// - /// Any exceptions raised by the connection will cause an Assert failure exception to be raised. - /// - /// - /// The message to send. - /// A flag to indicate whether or not the message should be received by the consumer. - private void SendTestMessage(IMessage msgSend, bool shouldPass) - { - _publisher.Send(msgSend); - _evt.WaitOne(TIMEOUT, true); - - // Check that an exception other than not routable was raised in which case re-raise it as a test error. - if (_lastException != null && !(_lastException.InnerException is AMQUndeliveredException)) - { - Assert.Fail("Exception {0} was raised by the broker connection.", _lastException); - } - // Check that a message was returned if the test is expecting the message to pass. - else if (shouldPass) - { - Assert.IsNotNull(_lastMessage, "Did not get a matching message from the headers exchange."); - } - // Check that a not routable exception was raised if the test is expecting the message to fail. - else if (_lastException != null && _lastException.InnerException is AMQUndeliveredException) - { - Assert.IsNull(_lastMessage, "Message could not be routed so consumer should not have received it."); - } - // The broker did not respond within the test timeout so fail the test. - else - { - Assert.Fail("The test timed out without a response from the broker."); - } - } - - /// Returns a field table containing patterns to match the test header exchange against. - /// - /// A field table containing test patterns. - private FieldTable CreatePatternAsFieldTable() - { - FieldTable matchTable = new FieldTable(); - - matchTable["match1"] = "foo"; - matchTable["match2"] = ""; - matchTable["x-match"] = "all"; - - return matchTable; - } - } -} +/* + * + * 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. + * + */ +using System; +using System.Threading; +using log4net; +using NUnit.Framework; +using Apache.Qpid.Framing; +using Apache.Qpid.Messaging; +using Apache.Qpid.Client.Qms; +using Apache.Qpid.Client; + +namespace Apache.Qpid.Integration.Tests.testcases +{ + /// + /// Sets up a producer/consumer pair to send test messages through a header exchange. The header exchange matching pattern is tested to + /// verify that it correctly matches or filters out messages based on their headers. + /// + /// Check that a message matching all fields of a headers exchange is passed by the exchange. + /// Check that a message containing values for empty fields of a headers exchange is passed by the exchange. + /// Check that a message matching only some fields of a headers exhcnage is not passed by the exchange. + /// Check that a message with additional fields to the correct matching fields of a headers exchange is passed by the exchange. + /// + /// + /// Remove the HeadersMatchingProducer class and rename this to HeaderExchangeTest. The producer and consumer are implemented + /// in a single test class to make running this as part of an automated test suite possible. + /// + /// Consider not using a delegate to callback the OnMessage method. Easier to just call receive on the consumer but using the + /// callback does demonstrate how to do so. + [TestFixture, Category("Integration")] + public class HeadersExchangeTest : BaseMessagingTestFixture + { + private static ILog _logger = LogManager.GetLogger(typeof(HeadersExchangeTest)); + + /// Holds the default test timeout for broker communications before tests give up. + private static readonly int TIMEOUT = 2000; + + /// Holds the name of the headers exchange to create to send test messages on. + private string _exchangeName = "ServiceQ1"; + + /// Used to preserve the most recent exception in case test cases need to examine it. + private Exception _lastException = null; + + /// Used to preserve the most recent message from the test consumer. + private IMessage _lastMessage = null; + + /// The test consumer to get messages from the broker with. + private IMessageConsumer _consumer; + + private IMessagePublisher _publisher; + + private AutoResetEvent _evt = new AutoResetEvent(false); + + private MessageReceivedDelegate _msgRecDelegate; + private ExceptionListenerDelegate _exceptionDelegate; + + /// Holds the test connection. + protected IConnection _connection; + + /// Holds the test channel. + protected IChannel _channel; + + [SetUp] + public override void Init() + { + // Ensure that the base init method is called. It establishes a connection with the broker. + base.Init(); + + connectionInfo = QpidConnectionInfo.FromUrl(connectionUri); + _connection = new AMQConnection(connectionInfo); + _channel = _connection.CreateChannel(false, AcknowledgeMode.AutoAcknowledge, 500, 300); + + _logger.Info("Starting..."); + _logger.Info("Exchange name is '" + _exchangeName + "'..."); + + // Register this to listen for exceptions on the test connection. + _exceptionDelegate = new ExceptionListenerDelegate(OnException); + _connection.ExceptionListener += _exceptionDelegate; + + // Declare a new headers exchange with the name of the test service. + _channel.DeclareExchange(_exchangeName, ExchangeClassConstants.HEADERS); + + // Create a non-durable, temporary (aka auto-delete), exclusive queue. + string queueName = _channel.GenerateUniqueName(); + _channel.DeclareQueue(queueName, false, true, true); + + // Bind the queue to the new headers exchange, setting up some header patterns for the exchange to match. + _channel.Bind(queueName, _exchangeName, null, CreatePatternAsFieldTable()); + + // Create a test consumer to consume messages from the test exchange. + _consumer = _channel.CreateConsumerBuilder(queueName) + .WithPrefetchLow(100) + .WithPrefetchHigh(500) + .WithNoLocal(false) // make sure we get our own messages + .Create(); + + // Register this to listen for messages on the consumer. + _msgRecDelegate = new MessageReceivedDelegate(OnMessage); + _consumer.OnMessage += _msgRecDelegate; + + // Clear the most recent message and exception. + _lastException = null; + _lastMessage = null; + + _publisher = _channel.CreatePublisherBuilder() + .WithExchangeName(_exchangeName) + .WithMandatory(true) + .Create(); + + _publisher.DeliveryMode = DeliveryMode.NonPersistent; + + // Start all channel + _connection.Start(); + } + + /// + /// Deregisters the on message delegate before closing the connection. + /// + [TearDown] + public override void Shutdown() + { + _logger.Info("public void Shutdown(): called"); + + //_consumer.OnMessage -= _msgRecDelegate; + //_connection.ExceptionListener -= _exceptionDelegate; + + _connection.Stop(); + _connection.Close(); + _connection.Dispose(); + + base.Shutdown(); + } + + /// + /// Callback method that is passed any messages received on the test channel. + /// + /// + /// The received message. + public void OnMessage(IMessage message) + { + _logger.Debug(string.Format("message.Type = {0}", message.GetType())); + _logger.Debug("Got message '" + message + "'"); + + // Preserve the most recent exception so that test cases can examine it. + _lastMessage = message; + + // Notify any waiting threads that a message has been received. + _evt.Set(); + } + + /// Callback method to handle any exceptions raised by the test connection. + /// + /// The connection exception. + public void OnException(Exception e) + { + // Preserve the most recent exception in case test cases need to examine it. + _lastException = e; + + // Notify any waiting threads that an exception event has occurred. + _evt.Set(); + } + + /// Check that a message matching all fields of a headers exchange is passed by the exchange. + [Test] + public void TestMatchAll() + { + IMessage msg = _channel.CreateTextMessage("matches match2=''"); + msg.Headers["match1"] = "foo"; + msg.Headers["match2"] = ""; + + // Use the SendTestMessage helper method to verify that the message was sent and received. + SendTestMessage(msg, true); + } + + /// Check that a message containing values for empty fields of a headers exchange is passed by the exchange. + [Test] + public void TestMatchEmptyMatchesAnything() + { + // Send a test message that matches the headers exchange. + IMessage msg = _channel.CreateTextMessage("matches match1='foo' and match2='bar'"); + msg.Headers["match1"] = "foo"; + msg.Headers["match2"] = "bar"; + + // Use the SendTestMessage helper method to verify that the message was sent and received. + SendTestMessage(msg, true); + } + + /// Check that a message matching only some fields of a headers exchange is not passed by the exchange. + [Test] + public void TestMatchOneFails() + { + IMessage msg = _channel.CreateTextMessage("not match - only match1"); + msg.Headers["match1"] = "foo"; + + // Use the SendTestMessage helper method to verify that the message was sent and not received. + SendTestMessage(msg, false); + } + + /// + /// Check that a message with additional fields to the correct matching fields of a headers exchange is passed by + /// the exchange. + /// + [Test] + public void TestMatchExtraFields() + { + IMessage msg = _channel.CreateTextMessage("matches - extra headers"); + msg.Headers["match1"] = "foo"; + msg.Headers["match2"] = "bar"; + msg.Headers["match3"] = "not required"; + + // Use the SendTestMessage helper method to verify that the message was sent and received. + SendTestMessage(msg, true); + } + + /// + /// Sends the specified message to the test publisher, and confirms that it was received by the test consumer or not + /// depending on whether or not the message should be received by the consumer. + /// + /// Any exceptions raised by the connection will cause an Assert failure exception to be raised. + /// + /// + /// The message to send. + /// A flag to indicate whether or not the message should be received by the consumer. + private void SendTestMessage(IMessage msgSend, bool shouldPass) + { + _publisher.Send(msgSend); + _evt.WaitOne(TIMEOUT, true); + + // Check that an exception other than not routable was raised in which case re-raise it as a test error. + if (_lastException != null && !(_lastException.InnerException is AMQUndeliveredException)) + { + Assert.Fail("Exception {0} was raised by the broker connection.", _lastException); + } + // Check that a message was returned if the test is expecting the message to pass. + else if (shouldPass) + { + Assert.IsNotNull(_lastMessage, "Did not get a matching message from the headers exchange."); + } + // Check that a not routable exception was raised if the test is expecting the message to fail. + else if (_lastException != null && _lastException.InnerException is AMQUndeliveredException) + { + Assert.IsNull(_lastMessage, "Message could not be routed so consumer should not have received it."); + } + // The broker did not respond within the test timeout so fail the test. + else + { + Assert.Fail("The test timed out without a response from the broker."); + } + } + + /// Returns a field table containing patterns to match the test header exchange against. + /// + /// A field table containing test patterns. + private FieldTable CreatePatternAsFieldTable() + { + FieldTable matchTable = new FieldTable(); + + matchTable["match1"] = "foo"; + matchTable["match2"] = ""; + matchTable["x-match"] = "all"; + + return matchTable; + } + } +} diff --git a/dotnet/Qpid.Integration.Tests/testcases/MandatoryMessageTest.cs b/dotnet/Qpid.Integration.Tests/testcases/MandatoryMessageTest.cs index 6cfdad1f94..4abc56905f 100644 --- a/dotnet/Qpid.Integration.Tests/testcases/MandatoryMessageTest.cs +++ b/dotnet/Qpid.Integration.Tests/testcases/MandatoryMessageTest.cs @@ -1,149 +1,149 @@ -/* - * - * 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. - * - */ -using System; -using System.Threading; -using log4net; -using NUnit.Framework; -using Apache.Qpid.Messaging; -using Apache.Qpid.Client.Qms; -using Apache.Qpid.Client; - -namespace Apache.Qpid.Integration.Tests.testcases -{ - /// - /// MandatoryMessageTest checks that messages sent with the 'mandatory' flag, must either be routed to a valid - /// queue or returned to the sender when no route is available. - /// - ///

- ///
CRC Card
Responsibilities Collaborations - ///
Check default exchange returns unroutable mandatory messages. - ///
Check direct exchange returns unroutable mandatory messages. - ///
Check headers exchange returns unroutable mandatory messages. - ///
Check topic exchange returns unroutable mandatory messages. - ///
- ///

- [TestFixture, Category("Integration")] - public class MandatoryMessageTest : BaseMessagingTestFixture - { - /// Used for debugging purposes. - private static ILog log = LogManager.GetLogger(typeof(MandatoryMessageTest)); - - /// Defines the maximum time in milliseconds, to wait for redelivery to occurr. - public const int TIMEOUT = 1000; - - /// Defines the name of the routing key to use with the tests. - public const string TEST_ROUTING_KEY = "unboundkey"; - - /// Condition used to coordinate receipt of redelivery exception to the sending thread. - private ManualResetEvent errorEvent; - - /// Holds the last received error condition, for examination by the tests sending thread. - private Exception lastErrorException; - - /// Holds the test connection. - protected IConnection _connection; - - /// Holds the test channel. - protected IChannel _channel; - - [SetUp] - public override void Init() - { - base.Init(); - - errorEvent = new ManualResetEvent(false); - lastErrorException = null; - } - - [TearDown] - public override void Shutdown() - { - base.Shutdown(); - } - - /// - /// Handles all exception conditions on the connection. The error event is notified and the exception recorded as the last seen. - /// - /// - /// The asynchronous exception on the connection. - public void OnException(Exception e) - { - lastErrorException = e; - errorEvent.Set(); - } - - [Test] - public void SendUndeliverableMessageOnDirectExchange() - { - SendOne(ExchangeNameDefaults.DIRECT); - } - - [Test] - public void SendUndeliverableMessageOnTopicExchange() - { - SendOne(ExchangeNameDefaults.TOPIC); - } - - [Test] - public void SendUndeliverableMessageOnHeadersExchange() - { - SendOne(ExchangeNameDefaults.HEADERS); - } - - /// - /// Sends a single message to the specified exchange with the routing key 'unboundkey', marked as mandatory. - /// A check is performed to assert that a redelivery error is returned from the broker for the message. - /// - /// - /// The name of the exchange to send to. - private void SendOne(string exchangeName) - { - log.Debug("private void SendOne(string exchangeName = " + exchangeName + "): called"); - - // Send a test message to a unbound key on the specified exchange. - SetUpEndPoint(0, false, false, TEST_ROUTING_KEY + testId, AcknowledgeMode.AutoAcknowledge, false, exchangeName, - true, false, null); - testProducer[0] = testChannel[0].CreatePublisherBuilder() - .WithRoutingKey(TEST_ROUTING_KEY + testId) - .WithMandatory(true) - .WithExchangeName(exchangeName) - .Create(); - - // Set up the exception listener on the connection. - testConnection[0].ExceptionListener = new ExceptionListenerDelegate(OnException); - - // Send message that should fail. - testProducer[0].Send(testChannel[0].CreateTextMessage("Test Message")); - - // Wait for up to the timeout for a redelivery exception to be returned. - errorEvent.WaitOne(TIMEOUT, true); - - // Asserts that a redelivery exception was returned, and is of the correct type. - Type expectedException = typeof(AMQUndeliveredException); - Exception ex = lastErrorException; - - Assert.IsNotNull(ex, "No exception was thrown by the test. Expected " + expectedException); - Assert.IsInstanceOfType(expectedException, ex.InnerException); - - CloseEndPoint(0); - } - } -} +/* + * + * 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. + * + */ +using System; +using System.Threading; +using log4net; +using NUnit.Framework; +using Apache.Qpid.Messaging; +using Apache.Qpid.Client.Qms; +using Apache.Qpid.Client; + +namespace Apache.Qpid.Integration.Tests.testcases +{ + /// + /// MandatoryMessageTest checks that messages sent with the 'mandatory' flag, must either be routed to a valid + /// queue or returned to the sender when no route is available. + /// + ///

+ ///
CRC Card
Responsibilities Collaborations + ///
Check default exchange returns unroutable mandatory messages. + ///
Check direct exchange returns unroutable mandatory messages. + ///
Check headers exchange returns unroutable mandatory messages. + ///
Check topic exchange returns unroutable mandatory messages. + ///
+ ///

+ [TestFixture, Category("Integration")] + public class MandatoryMessageTest : BaseMessagingTestFixture + { + /// Used for debugging purposes. + private static ILog log = LogManager.GetLogger(typeof(MandatoryMessageTest)); + + /// Defines the maximum time in milliseconds, to wait for redelivery to occurr. + public const int TIMEOUT = 1000; + + /// Defines the name of the routing key to use with the tests. + public const string TEST_ROUTING_KEY = "unboundkey"; + + /// Condition used to coordinate receipt of redelivery exception to the sending thread. + private ManualResetEvent errorEvent; + + /// Holds the last received error condition, for examination by the tests sending thread. + private Exception lastErrorException; + + /// Holds the test connection. + protected IConnection _connection; + + /// Holds the test channel. + protected IChannel _channel; + + [SetUp] + public override void Init() + { + base.Init(); + + errorEvent = new ManualResetEvent(false); + lastErrorException = null; + } + + [TearDown] + public override void Shutdown() + { + base.Shutdown(); + } + + /// + /// Handles all exception conditions on the connection. The error event is notified and the exception recorded as the last seen. + /// + /// + /// The asynchronous exception on the connection. + public void OnException(Exception e) + { + lastErrorException = e; + errorEvent.Set(); + } + + [Test] + public void SendUndeliverableMessageOnDirectExchange() + { + SendOne(ExchangeNameDefaults.DIRECT); + } + + [Test] + public void SendUndeliverableMessageOnTopicExchange() + { + SendOne(ExchangeNameDefaults.TOPIC); + } + + [Test] + public void SendUndeliverableMessageOnHeadersExchange() + { + SendOne(ExchangeNameDefaults.HEADERS); + } + + /// + /// Sends a single message to the specified exchange with the routing key 'unboundkey', marked as mandatory. + /// A check is performed to assert that a redelivery error is returned from the broker for the message. + /// + /// + /// The name of the exchange to send to. + private void SendOne(string exchangeName) + { + log.Debug("private void SendOne(string exchangeName = " + exchangeName + "): called"); + + // Send a test message to a unbound key on the specified exchange. + SetUpEndPoint(0, false, false, TEST_ROUTING_KEY + testId, AcknowledgeMode.AutoAcknowledge, false, exchangeName, + true, false, null); + testProducer[0] = testChannel[0].CreatePublisherBuilder() + .WithRoutingKey(TEST_ROUTING_KEY + testId) + .WithMandatory(true) + .WithExchangeName(exchangeName) + .Create(); + + // Set up the exception listener on the connection. + testConnection[0].ExceptionListener = new ExceptionListenerDelegate(OnException); + + // Send message that should fail. + testProducer[0].Send(testChannel[0].CreateTextMessage("Test Message")); + + // Wait for up to the timeout for a redelivery exception to be returned. + errorEvent.WaitOne(TIMEOUT, true); + + // Asserts that a redelivery exception was returned, and is of the correct type. + Type expectedException = typeof(AMQUndeliveredException); + Exception ex = lastErrorException; + + Assert.IsNotNull(ex, "No exception was thrown by the test. Expected " + expectedException); + Assert.IsInstanceOfType(expectedException, ex.InnerException); + + CloseEndPoint(0); + } + } +} diff --git a/dotnet/Qpid.Integration.Tests/testcases/ProducerMultiConsumerTest.cs b/dotnet/Qpid.Integration.Tests/testcases/ProducerMultiConsumerTest.cs index 876e7c7bf7..bae6c76818 100644 --- a/dotnet/Qpid.Integration.Tests/testcases/ProducerMultiConsumerTest.cs +++ b/dotnet/Qpid.Integration.Tests/testcases/ProducerMultiConsumerTest.cs @@ -1,167 +1,167 @@ -/* - * - * 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. - * - */ -using System; -using System.Text; -using System.Threading; -using log4net; -using NUnit.Framework; -using Apache.Qpid.Messaging; -using Apache.Qpid.Client.Qms; -using Apache.Qpid.Client; - -namespace Apache.Qpid.Integration.Tests.testcases -{ - /// ProducerMultiConsumerTest provides some tests for one producer and multiple consumers. - /// - ///

- ///
CRC Card
Responsibilities Collaborations - ///
Check that all consumers on a topic each receive all message on it. - ///
Check that consumers on the same queue receive each message once accross all consumers. - ///
- ///

- [TestFixture, Category("Integration")] - public class ProducerMultiConsumerTest : BaseMessagingTestFixture - { - private static readonly ILog _logger = LogManager.GetLogger(typeof(ProducerMultiConsumerTest)); - - /// Base name for the routing key used for this test (made unique by adding in test id). - private const string TEST_ROUTING_KEY = "ProducerMultiConsumerTest"; - - /// The number of consumers to test. - private const int CONSUMER_COUNT = 5; - - /// The number of test messages to send. - private const int MESSAGE_COUNT = 10; - - /// Monitor used to signal succesfull receipt of all test messages. - AutoResetEvent _finishedEvent; - - /// Used to count test messages received so far. - private int _messageReceivedCount; - - /// Used to hold the expected number of messages to receive. - private int expectedMessageCount; - - /// Flag used to indicate that all messages really were received, and that the test did not just time out. - private bool allReceived; - - /// Creates one producing end-point and many consuming end-points connected on a topic. - [SetUp] - public override void Init() - { - base.Init(); - - // Reset all test counts and flags. - _messageReceivedCount = 0; - allReceived = false; - _finishedEvent = new AutoResetEvent(false); - } - - /// Cleans up all test end-points. - [TearDown] - public override void Shutdown() - { - try - { - // Close all end points for producer and consumers. - // Producer is on 0, and consumers on 1 .. n, so loop is from 0 to n inclusive. - for (int i = 0; i <= CONSUMER_COUNT; i++) - { - CloseEndPoint(i); - } - } - finally - { - base.Shutdown(); - } - } - - /// Check that all consumers on a topic each receive all message on it. - [Test] - public void AllConsumerReceiveAllMessagesOnTopic() - { - // Create end-points for all the consumers in the test. - for (int i = 1; i <= CONSUMER_COUNT; i++) - { - SetUpEndPoint(i, false, true, TEST_ROUTING_KEY + testId, AcknowledgeMode.AutoAcknowledge, false, ExchangeNameDefaults.TOPIC, - true, false, null); - testConsumer[i].OnMessage += new MessageReceivedDelegate(OnMessage); - } - - // Create an end-point to publish to the test topic. - SetUpEndPoint(0, true, false, TEST_ROUTING_KEY + testId, AcknowledgeMode.AutoAcknowledge, false, ExchangeNameDefaults.TOPIC, - true, false, null); - - expectedMessageCount = (MESSAGE_COUNT * CONSUMER_COUNT); - - for (int i = 0; i < MESSAGE_COUNT; i++) - { - testProducer[0].Send(testChannel[0].CreateTextMessage("A")); - } - - _finishedEvent.WaitOne(new TimeSpan(0, 0, 0, 30), false); - - // Check that all messages really were received. - Assert.IsTrue(allReceived, "All messages were not received, only got " + _messageReceivedCount + " but wanted " + expectedMessageCount); - } - - /// Check that consumers on the same queue receive each message once accross all consumers. - [Test] - public void AllConsumerReceiveAllMessagesOnDirect() - { - // Create end-points for all the consumers in the test. - for (int i = 1; i <= CONSUMER_COUNT; i++) - { - SetUpEndPoint(i, false, true, TEST_ROUTING_KEY + testId, AcknowledgeMode.AutoAcknowledge, false, ExchangeNameDefaults.DIRECT, - true, false, null); - testConsumer[i].OnMessage += new MessageReceivedDelegate(OnMessage); - } - - // Create an end-point to publish to the test topic. - SetUpEndPoint(0, true, false, TEST_ROUTING_KEY + testId, AcknowledgeMode.AutoAcknowledge, false, ExchangeNameDefaults.DIRECT, - true, false, null); - - expectedMessageCount = (MESSAGE_COUNT * CONSUMER_COUNT); - - for (int i = 0; i < MESSAGE_COUNT; i++) - { - testProducer[0].Send(testChannel[0].CreateTextMessage("A")); - } - - _finishedEvent.WaitOne(new TimeSpan(0, 0, 0, 30), false); - - // Check that all messages really were received. - Assert.IsTrue(allReceived, "All messages were not received, only got: " + _messageReceivedCount + " but wanted " + expectedMessageCount); - } - - /// Atomically increments the message count on every message, and signals once all messages in the test are received. - public void OnMessage(IMessage m) - { - int newCount = Interlocked.Increment(ref _messageReceivedCount); - - if (newCount >= expectedMessageCount) - { - allReceived = true; - _finishedEvent.Set(); - } - } - } -} +/* + * + * 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. + * + */ +using System; +using System.Text; +using System.Threading; +using log4net; +using NUnit.Framework; +using Apache.Qpid.Messaging; +using Apache.Qpid.Client.Qms; +using Apache.Qpid.Client; + +namespace Apache.Qpid.Integration.Tests.testcases +{ + /// ProducerMultiConsumerTest provides some tests for one producer and multiple consumers. + /// + ///

+ ///
CRC Card
Responsibilities Collaborations + ///
Check that all consumers on a topic each receive all message on it. + ///
Check that consumers on the same queue receive each message once accross all consumers. + ///
+ /// + [TestFixture, Category("Integration")] + public class ProducerMultiConsumerTest : BaseMessagingTestFixture + { + private static readonly ILog _logger = LogManager.GetLogger(typeof(ProducerMultiConsumerTest)); + + ///

Base name for the routing key used for this test (made unique by adding in test id). + private const string TEST_ROUTING_KEY = "ProducerMultiConsumerTest"; + + /// The number of consumers to test. + private const int CONSUMER_COUNT = 5; + + /// The number of test messages to send. + private const int MESSAGE_COUNT = 10; + + /// Monitor used to signal succesfull receipt of all test messages. + AutoResetEvent _finishedEvent; + + /// Used to count test messages received so far. + private int _messageReceivedCount; + + /// Used to hold the expected number of messages to receive. + private int expectedMessageCount; + + /// Flag used to indicate that all messages really were received, and that the test did not just time out. + private bool allReceived; + + /// Creates one producing end-point and many consuming end-points connected on a topic. + [SetUp] + public override void Init() + { + base.Init(); + + // Reset all test counts and flags. + _messageReceivedCount = 0; + allReceived = false; + _finishedEvent = new AutoResetEvent(false); + } + + /// Cleans up all test end-points. + [TearDown] + public override void Shutdown() + { + try + { + // Close all end points for producer and consumers. + // Producer is on 0, and consumers on 1 .. n, so loop is from 0 to n inclusive. + for (int i = 0; i <= CONSUMER_COUNT; i++) + { + CloseEndPoint(i); + } + } + finally + { + base.Shutdown(); + } + } + + /// Check that all consumers on a topic each receive all message on it. + [Test] + public void AllConsumerReceiveAllMessagesOnTopic() + { + // Create end-points for all the consumers in the test. + for (int i = 1; i <= CONSUMER_COUNT; i++) + { + SetUpEndPoint(i, false, true, TEST_ROUTING_KEY + testId, AcknowledgeMode.AutoAcknowledge, false, ExchangeNameDefaults.TOPIC, + true, false, null); + testConsumer[i].OnMessage += new MessageReceivedDelegate(OnMessage); + } + + // Create an end-point to publish to the test topic. + SetUpEndPoint(0, true, false, TEST_ROUTING_KEY + testId, AcknowledgeMode.AutoAcknowledge, false, ExchangeNameDefaults.TOPIC, + true, false, null); + + expectedMessageCount = (MESSAGE_COUNT * CONSUMER_COUNT); + + for (int i = 0; i < MESSAGE_COUNT; i++) + { + testProducer[0].Send(testChannel[0].CreateTextMessage("A")); + } + + _finishedEvent.WaitOne(new TimeSpan(0, 0, 0, 30), false); + + // Check that all messages really were received. + Assert.IsTrue(allReceived, "All messages were not received, only got " + _messageReceivedCount + " but wanted " + expectedMessageCount); + } + + /// Check that consumers on the same queue receive each message once accross all consumers. + [Test] + public void AllConsumerReceiveAllMessagesOnDirect() + { + // Create end-points for all the consumers in the test. + for (int i = 1; i <= CONSUMER_COUNT; i++) + { + SetUpEndPoint(i, false, true, TEST_ROUTING_KEY + testId, AcknowledgeMode.AutoAcknowledge, false, ExchangeNameDefaults.DIRECT, + true, false, null); + testConsumer[i].OnMessage += new MessageReceivedDelegate(OnMessage); + } + + // Create an end-point to publish to the test topic. + SetUpEndPoint(0, true, false, TEST_ROUTING_KEY + testId, AcknowledgeMode.AutoAcknowledge, false, ExchangeNameDefaults.DIRECT, + true, false, null); + + expectedMessageCount = (MESSAGE_COUNT * CONSUMER_COUNT); + + for (int i = 0; i < MESSAGE_COUNT; i++) + { + testProducer[0].Send(testChannel[0].CreateTextMessage("A")); + } + + _finishedEvent.WaitOne(new TimeSpan(0, 0, 0, 30), false); + + // Check that all messages really were received. + Assert.IsTrue(allReceived, "All messages were not received, only got: " + _messageReceivedCount + " but wanted " + expectedMessageCount); + } + + /// Atomically increments the message count on every message, and signals once all messages in the test are received. + public void OnMessage(IMessage m) + { + int newCount = Interlocked.Increment(ref _messageReceivedCount); + + if (newCount >= expectedMessageCount) + { + allReceived = true; + _finishedEvent.Set(); + } + } + } +} diff --git a/dotnet/Qpid.Integration.Tests/testcases/SslConnectionTest.cs b/dotnet/Qpid.Integration.Tests/testcases/SslConnectionTest.cs index 1c104d1451..5f953e1470 100644 --- a/dotnet/Qpid.Integration.Tests/testcases/SslConnectionTest.cs +++ b/dotnet/Qpid.Integration.Tests/testcases/SslConnectionTest.cs @@ -1,64 +1,64 @@ -/* - * - * 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. - * - */ -using System; -using System.IO; -using System.Reflection; -using System.Security.Cryptography.X509Certificates; -using NUnit.Framework; -using Apache.Qpid.Client.Qms; -using Apache.Qpid.Client; -using Apache.Qpid.Messaging; - -namespace Apache.Qpid.Integration.Tests.testcases -{ - /// - /// Test SSL/TLS connections to the broker - /// - [TestFixture, Category("Integration")] - public class SslConnectionTest - { - /// - /// Make a test TLS connection to the broker - /// without using client-certificates - /// - //[Test] - public void DoSslConnection() - { - // because for tests we don't usually trust the server certificate - // we need here to tell the client to ignore certificate validation errors - SslOptions sslConfig = new SslOptions(null, true); - - MakeBrokerConnection(sslConfig); - } - - private static void MakeBrokerConnection(SslOptions options) - { - IConnectionInfo connectionInfo = new QpidConnectionInfo(); - connectionInfo.VirtualHost = "test"; - connectionInfo.AddBrokerInfo(new AmqBrokerInfo("amqp", "localhost", 8672, options)); - - using ( IConnection connection = new AMQConnection(connectionInfo) ) - { - Console.WriteLine("connection = " + connection); - } - } - } -} +/* + * + * 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. + * + */ +using System; +using System.IO; +using System.Reflection; +using System.Security.Cryptography.X509Certificates; +using NUnit.Framework; +using Apache.Qpid.Client.Qms; +using Apache.Qpid.Client; +using Apache.Qpid.Messaging; + +namespace Apache.Qpid.Integration.Tests.testcases +{ + /// + /// Test SSL/TLS connections to the broker + /// + [TestFixture, Category("Integration")] + public class SslConnectionTest + { + /// + /// Make a test TLS connection to the broker + /// without using client-certificates + /// + //[Test] + public void DoSslConnection() + { + // because for tests we don't usually trust the server certificate + // we need here to tell the client to ignore certificate validation errors + SslOptions sslConfig = new SslOptions(null, true); + + MakeBrokerConnection(sslConfig); + } + + private static void MakeBrokerConnection(SslOptions options) + { + IConnectionInfo connectionInfo = new QpidConnectionInfo(); + connectionInfo.VirtualHost = "test"; + connectionInfo.AddBrokerInfo(new AmqBrokerInfo("amqp", "localhost", 8672, options)); + + using ( IConnection connection = new AMQConnection(connectionInfo) ) + { + Console.WriteLine("connection = " + connection); + } + } + } +} diff --git a/dotnet/Qpid.Integration.Tests/testcases/SustainedTest.cs b/dotnet/Qpid.Integration.Tests/testcases/SustainedTest.cs index aca3f396d6..4074055eba 100644 --- a/dotnet/Qpid.Integration.Tests/testcases/SustainedTest.cs +++ b/dotnet/Qpid.Integration.Tests/testcases/SustainedTest.cs @@ -1,109 +1,109 @@ -/* - * - * 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. - * - */ -using System; -using System.IO; -using System.Reflection; -using System.Threading; -using NUnit.Framework; -using Apache.Qpid.Client.Qms; -using Apache.Qpid.Client; -using Apache.Qpid.Messaging; -using log4net; - -namespace Apache.Qpid.Integration.Tests.testcases -{ - /// - /// Runs through the range of ack modes for each test case, sending and recieving a large number of messages - /// - [TestFixture, Category("Integration")] - public class SustainedTest : BaseMessagingTestFixture - { - /// The number of test messages to send. - private const int MESSAGE_COUNT = 50;//00; - - /// Base name for the routing key used for this test (made unique by adding in test id). - private const string TEST_ROUTING_KEY = "MessageOrderTest"; - - /// - /// The logger - /// - private static ILog _logger = LogManager.GetLogger(typeof(SustainedTest)); - - [Test] - public void MessageOrderTestAutoAck() - { - MessageOrderTest(AcknowledgeMode.AutoAcknowledge); - } - - [Test] - public void MessageOrderTestNoAck() - { - MessageOrderTest(AcknowledgeMode.NoAcknowledge); - } - - public void MessageOrderTest(AcknowledgeMode consumerMode) - { - - // Consumer - SetUpEndPoint(1, false, true, TEST_ROUTING_KEY, consumerMode, false, ExchangeNameDefaults.DIRECT, - true, false, null); - - - Console.WriteLine("Starting producer thread"); - Thread prodThread = new Thread(new ThreadStart(SendMessages)); - prodThread.Start(); - - Thread.Sleep(2000); - Console.WriteLine("Starting consuming"); - for (int i = 0; i < MESSAGE_COUNT; i++) - { - if ((i % 10) == 0) - { - Console.WriteLine("Consuming message "+i); - } - ConsumeNMessages(1, "Msg"+i, testConsumer[1]); - } - prodThread.Join(); - CloseEndPoint(0); - CloseEndPoint(1); - } - - private static void SendMessages() - { - AMQConnection conn = new AMQConnection(QpidConnectionInfo.FromUrl(BaseMessagingTestFixture.connectionUri)); - conn.Start(); - IChannel channel = conn.CreateChannel(false, AcknowledgeMode.AutoAcknowledge); - IMessagePublisher producer = channel.CreatePublisherBuilder(). - WithExchangeName(ExchangeNameDefaults.DIRECT). - WithRoutingKey(TEST_ROUTING_KEY). - Create(); - - for (int i = 0; i < MESSAGE_COUNT ; i++) - { - if ((i % 10) == 0) - { - Console.WriteLine("Sending message "+i); - } - producer.Send(channel.CreateTextMessage("Msg" + i)); - } - } - } -} +/* + * + * 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. + * + */ +using System; +using System.IO; +using System.Reflection; +using System.Threading; +using NUnit.Framework; +using Apache.Qpid.Client.Qms; +using Apache.Qpid.Client; +using Apache.Qpid.Messaging; +using log4net; + +namespace Apache.Qpid.Integration.Tests.testcases +{ + /// + /// Runs through the range of ack modes for each test case, sending and recieving a large number of messages + /// + [TestFixture, Category("Integration")] + public class SustainedTest : BaseMessagingTestFixture + { + /// The number of test messages to send. + private const int MESSAGE_COUNT = 50;//00; + + /// Base name for the routing key used for this test (made unique by adding in test id). + private const string TEST_ROUTING_KEY = "MessageOrderTest"; + + /// + /// The logger + /// + private static ILog _logger = LogManager.GetLogger(typeof(SustainedTest)); + + [Test] + public void MessageOrderTestAutoAck() + { + MessageOrderTest(AcknowledgeMode.AutoAcknowledge); + } + + [Test] + public void MessageOrderTestNoAck() + { + MessageOrderTest(AcknowledgeMode.NoAcknowledge); + } + + public void MessageOrderTest(AcknowledgeMode consumerMode) + { + + // Consumer + SetUpEndPoint(1, false, true, TEST_ROUTING_KEY, consumerMode, false, ExchangeNameDefaults.DIRECT, + true, false, null); + + + Console.WriteLine("Starting producer thread"); + Thread prodThread = new Thread(new ThreadStart(SendMessages)); + prodThread.Start(); + + Thread.Sleep(2000); + Console.WriteLine("Starting consuming"); + for (int i = 0; i < MESSAGE_COUNT; i++) + { + if ((i % 10) == 0) + { + Console.WriteLine("Consuming message "+i); + } + ConsumeNMessages(1, "Msg"+i, testConsumer[1]); + } + prodThread.Join(); + CloseEndPoint(0); + CloseEndPoint(1); + } + + private static void SendMessages() + { + AMQConnection conn = new AMQConnection(QpidConnectionInfo.FromUrl(BaseMessagingTestFixture.connectionUri)); + conn.Start(); + IChannel channel = conn.CreateChannel(false, AcknowledgeMode.AutoAcknowledge); + IMessagePublisher producer = channel.CreatePublisherBuilder(). + WithExchangeName(ExchangeNameDefaults.DIRECT). + WithRoutingKey(TEST_ROUTING_KEY). + Create(); + + for (int i = 0; i < MESSAGE_COUNT ; i++) + { + if ((i % 10) == 0) + { + Console.WriteLine("Sending message "+i); + } + producer.Send(channel.CreateTextMessage("Msg" + i)); + } + } + } +} -- cgit v1.2.1