Added: 
incubator/qpid/branches/M2.1/dotnet/Qpid.Integration.Tests/testcases/ConnectionTest.cs
URL: 
http://svn.apache.org/viewvc/incubator/qpid/branches/M2.1/dotnet/Qpid.Integration.Tests/testcases/ConnectionTest.cs?rev=612165&view=auto
==============================================================================
--- 
incubator/qpid/branches/M2.1/dotnet/Qpid.Integration.Tests/testcases/ConnectionTest.cs
 (added)
+++ 
incubator/qpid/branches/M2.1/dotnet/Qpid.Integration.Tests/testcases/ConnectionTest.cs
 Tue Jan 15 09:29:41 2008
@@ -0,0 +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:[EMAIL 
PROTECTED]/testpath?brokerlist='tcp://localhost:5673?retries='0''";
+            new AMQConnection(QpidConnectionInfo.FromUrl(url));
+            Assert.Fail("Connection should not be established");
+        }
+    }
+}

Added: 
incubator/qpid/branches/M2.1/dotnet/Qpid.Integration.Tests/testcases/HeadersExchangeTest.cs
URL: 
http://svn.apache.org/viewvc/incubator/qpid/branches/M2.1/dotnet/Qpid.Integration.Tests/testcases/HeadersExchangeTest.cs?rev=612165&view=auto
==============================================================================
--- 
incubator/qpid/branches/M2.1/dotnet/Qpid.Integration.Tests/testcases/HeadersExchangeTest.cs
 (added)
+++ 
incubator/qpid/branches/M2.1/dotnet/Qpid.Integration.Tests/testcases/HeadersExchangeTest.cs
 Tue Jan 15 09:29:41 2008
@@ -0,0 +1,268 @@
+/*
+ *
+ * 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;
+
+namespace Apache.Qpid.Integration.Tests.testcases
+{
+    /// <summary>
+    /// 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.
+    /// </summary>
+    ///
+    /// <todo>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.</todo>
+    /// 
+    /// <todo>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.</todo>
+  [TestFixture, Category("Integration")]
+    public class HeadersExchangeTest : BaseMessagingTestFixture
+    {
+        private static ILog _logger = 
LogManager.GetLogger(typeof(HeadersExchangeTest));
+
+        /// <summary> Holds the default test timeout for broker communications 
before tests give up. </summary>
+        private static readonly int TIMEOUT = 1000;
+
+        /// <summary> Holds the name of the headers exchange to create to send 
test messages on. </summary>
+        private string _exchangeName = "ServiceQ1";
+
+        /// <summary> Used to preserve the most recent exception in case test 
cases need to examine it. </summary>
+        private Exception _lastException = null;
+
+        /// <summary> Used to preserve the most recent message from the test 
consumer. </summary>
+        private IMessage _lastMessage = null;
+
+        /// <summary> The test consumer to get messages from the broker with. 
</summary>
+        private IMessageConsumer _consumer;
+
+        private IMessagePublisher _publisher;
+
+        private AutoResetEvent _evt = new AutoResetEvent(false);
+
+        private MessageReceivedDelegate _msgRecDelegate;
+        private ExceptionListenerDelegate _exceptionDelegate;
+
+        [SetUp]
+        public override void Init()
+        {          
+            // Ensure that the base init method is called. It establishes a 
connection with the broker.
+            base.Init();            
+
+            _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();
+        }
+
+        /// <summary>
+        /// Deregisters the on message delegate before closing the connection.
+        /// </summary>
+        [TearDown]
+        public override void Shutdown()
+        {
+            _logger.Info("public void Shutdown(): called");
+
+            //_consumer.OnMessage -= _msgRecDelegate;
+            //_connection.ExceptionListener -= _exceptionDelegate;
+
+            _connection.Stop();
+
+            base.Shutdown();
+        }
+
+        /// <summary>
+        /// Callback method that is passed any messages received on the test 
channel.
+        /// </summary>
+        /// 
+        /// <param name="message">The received message.</param>
+        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();
+        }
+
+        /// <summary>Callback method to handle any exceptions raised by the 
test connection.</summary>
+        /// 
+        /// <param name="e">The connection exception.</param>
+        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();
+        }
+
+        /// <summary>Check that a message matching all fields of a headers 
exchange is passed by the exchange.</summary>
+        [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);
+        }
+
+        /// <summary>Check that a message containing values for empty fields 
of a headers exchange is passed by the exchange.</summary>
+        [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);
+        }
+
+        /// <summary>Check that a message matching only some fields of a 
headers exchange is not passed by the exchange.</summary>
+        [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);
+        }
+
+        /// <summary>
+        /// Check that a message with additional fields to the correct 
matching fields of a headers exchange is passed by 
+        /// the exchange.
+        /// </summary>
+        [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);
+        }
+
+        /// <summary>
+        /// 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.
+        /// </summary>
+        /// 
+        /// <param name="msgSend">The message to send.</param>
+        /// <param name="shouldPass">A flag to indicate whether or not the 
message should be received by the consumer.</param>
+        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.");
+            }
+        }
+
+        /// <summary> Returns a field table containing patterns to match the 
test header exchange against. </summary>
+        /// 
+        /// <returns> A field table containing test patterns. </returns>
+        private FieldTable CreatePatternAsFieldTable()
+        {
+            FieldTable matchTable = new FieldTable();
+
+            matchTable["match1"] = "foo";
+            matchTable["match2"] = "";
+            matchTable["x-match"] = "all";
+
+            return matchTable;
+        }
+    }
+}

Added: 
incubator/qpid/branches/M2.1/dotnet/Qpid.Integration.Tests/testcases/MandatoryMessageTest.cs
URL: 
http://svn.apache.org/viewvc/incubator/qpid/branches/M2.1/dotnet/Qpid.Integration.Tests/testcases/MandatoryMessageTest.cs?rev=612165&view=auto
==============================================================================
--- 
incubator/qpid/branches/M2.1/dotnet/Qpid.Integration.Tests/testcases/MandatoryMessageTest.cs
 (added)
+++ 
incubator/qpid/branches/M2.1/dotnet/Qpid.Integration.Tests/testcases/MandatoryMessageTest.cs
 Tue Jan 15 09:29:41 2008
@@ -0,0 +1,232 @@
+/*
+ *
+ * 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.Runtime.InteropServices;
+using System.Threading;
+using log4net;
+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 MandatoryMessageTest
+    {
+        private static readonly ILog _log = 
LogManager.GetLogger(typeof(MandatoryMessageTest));
+
+        /// <summary>Specifies the number of times to run the test 
cycle.</summary>
+        const int NUM_MESSAGES = 10;
+
+        /// <summary>Determines how many messages to send within each 
commit.</summary>
+        const int COMMIT_BATCH_SIZE = 1;
+
+        /// <summary>Specifies the duration of the pause to place between each 
message sent in the test.</summary>
+        //const int SLEEP_MILLIS = 1;
+
+        /// <summary>Specified the maximum time in milliseconds to wait for 
the test to complete.</summary>
+        const int TIMEOUT = 10000;
+
+        /// <summary>Defines the number of test messages to send, before 
prompting the user to fail a broker.</summary>
+        const int FAIL_POINT = 5;
+
+        /// <summary>Specified the ack mode to use for the test.</summary>
+        AcknowledgeMode _acknowledgeMode = AcknowledgeMode.AutoAcknowledge;
+
+        /// <summary>Determines whether this test runs transactionally or not. 
</summary>
+        bool transacted = false;
+
+        /// <summary>Holds the connection to run the test over.</summary>
+        AMQConnection _connection;
+
+        /// <summary>Holds the channel for the test message publisher. 
</summary>
+        IChannel publishingChannel;
+
+        /// <summary>Holds the test message publisher. </summary>
+        IMessagePublisher publisher;
+
+        /// <summary>Used to keep count of the number of messages sent. 
</summary>
+        int messagesSent;
+
+        /// <summary>Used to keep count of the number of messages received. 
</summary>
+        int messagesReceived;
+
+        /// <summary>Used to wait for test completion on. </summary>
+        private static object testComplete = new Object();
+
+        /// <summary>
+        /// </summary>
+        /// [SetUp]
+        public void Init(IConnectionInfo connectionInfo)
+        {
+            // Reset all counts.
+            messagesSent = 0;
+            messagesReceived = 0;
+
+            // Create a connection for the test.
+            _connection = new AMQConnection(connectionInfo);
+
+            // Create a consumer to receive the test messages.
+            IChannel receivingChannel = _connection.CreateChannel(false, 
_acknowledgeMode);
+
+            string queueName = receivingChannel.GenerateUniqueName();
+            receivingChannel.DeclareQueue(queueName, false, true, true);
+            receivingChannel.Bind(queueName, "amq.direct", queueName);
+
+            IMessageConsumer consumer = 
receivingChannel.CreateConsumerBuilder(queueName)
+                .WithPrefetchLow(30)
+                .WithPrefetchHigh(60).Create();
+
+            consumer.OnMessage = new MessageReceivedDelegate(OnMessage);
+            _connection.Start();
+
+            // Create a publisher to send the test messages.
+            publishingChannel = _connection.CreateChannel(transacted, 
AcknowledgeMode.NoAcknowledge);
+            publisher = publishingChannel.CreatePublisherBuilder()
+                .WithRoutingKey(queueName)
+                .Create();
+
+            _log.Debug("connection = " + _connection);
+            _log.Debug("connectionInfo = " + connectionInfo);
+            _log.Debug("connection.AsUrl = " + _connection.toURL());
+            _log.Debug("AcknowledgeMode is " + _acknowledgeMode);
+        }
+
+        /// <summary>
+        /// Clean up the test connection.
+        /// </summary>
+        [TearDown]
+        public virtual void Shutdown()
+        {
+            Thread.Sleep(2000);
+            _connection.Close();
+        }
+
+        /// <summary>
+        /// Runs a failover test, with the failover configuration specified in 
the Qpid connection URL format.
+        /// </summary>
+        [Test]
+        public void TestWithUrl()
+        {
+            _log.Debug("public void runTestWithUrl(): called");
+
+            // Parse the connection parameters from a URL.
+            String clientId = "failover" + DateTime.Now.Ticks;
+            string defaultUrl = "amqp://guest:guest@" + clientId + "/test" +
+                
"?brokerlist='tcp://localhost:5672;tcp://localhost:5673'&failover='roundrobin'";
            
+            IConnectionInfo connectionInfo = 
QpidConnectionInfo.FromUrl(defaultUrl);
+            
+            Init(connectionInfo);
+            DoMandatoryMessageTest();
+        }
+
+        /// <summary>
+        /// Send the test messages, prompting at the fail point for the user 
to cause a broker failure. The test checks that all messages sent
+        /// are received within the test time limit.
+        /// </summary>
+        ///
+        /// <param name="connectionInfo">The connection parameters, specifying 
the brokers to fail between.</param>
+        void DoMandatoryMessageTest()
+        {
+            _log.Debug("void DoMandatoryMessageTest(IConnectionInfo 
connectionInfo): called");
+
+            for (int i = 1; i <= NUM_MESSAGES; ++i)
+            {
+                ITextMessage msg = 
publishingChannel.CreateTextMessage("message=" + messagesSent);
+                //_log.Debug("sending message = " + msg.Text);
+                publisher.Send(msg);
+                messagesSent++;
+
+                _log.Debug("messagesSent = " + messagesSent);
+
+                if (transacted)
+                {
+                    publishingChannel.Commit();
+                }
+            }
+
+            // Wait for all of the test messages to be received, checking that 
this occurs within the test time limit.
+            bool withinTimeout;
+
+            lock(testComplete)
+            {
+                withinTimeout = Monitor.Wait(testComplete, TIMEOUT);
+            }            
+
+            if (!withinTimeout)
+            {
+                Assert.Fail("Test timed out, before all messages received.");
+            }
+
+            _log.Debug("void DoMandatoryMessageTest(IConnectionInfo 
connectionInfo): exiting");
+        }
+
+        /// <summary>
+        /// Receives all of the test messages.
+        /// </summary>
+        ///
+        /// <param name="message">The newly arrived test message.</param>
+        public void OnMessage(IMessage message)
+        {
+            try
+            {
+                if (_acknowledgeMode == AcknowledgeMode.ClientAcknowledge)
+                {
+                    message.Acknowledge();
+                }
+
+                messagesReceived++;
+
+                _log.Debug("messagesReceived = " + messagesReceived);
+
+                // Check if all of the messages in the test have been 
received, in which case notify the message producer that the test has 
+                // succesfully completed.
+                if (messagesReceived == NUM_MESSAGES)
+                {
+                    lock (testComplete)
+                    {
+                        Monitor.Pulse(testComplete);
+                    }
+                }
+            }
+            catch (QpidException e)
+            {
+                _log.Fatal("Exception received. About to stop.", e);
+                Stop();
+            }
+        }
+
+        // <summary>Closes the test connection.</summary>
+        private void Stop()
+        {
+            _log.Debug("Stopping...");
+            try
+            {
+                _connection.Close();
+            }
+            catch (QpidException e)
+            {
+                _log.Debug("Failed to shutdown: ", e);
+            }
+        }
+    }
+}

Added: 
incubator/qpid/branches/M2.1/dotnet/Qpid.Integration.Tests/testcases/ProducerMultiConsumerTest.cs
URL: 
http://svn.apache.org/viewvc/incubator/qpid/branches/M2.1/dotnet/Qpid.Integration.Tests/testcases/ProducerMultiConsumerTest.cs?rev=612165&view=auto
==============================================================================
--- 
incubator/qpid/branches/M2.1/dotnet/Qpid.Integration.Tests/testcases/ProducerMultiConsumerTest.cs
 (added)
+++ 
incubator/qpid/branches/M2.1/dotnet/Qpid.Integration.Tests/testcases/ProducerMultiConsumerTest.cs
 Tue Jan 15 09:29:41 2008
@@ -0,0 +1,127 @@
+/*
+ *
+ * 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;
+
+namespace Apache.Qpid.Integration.Tests.testcases
+{
+  [TestFixture, Category("Integration")]
+    public class ProducerMultiConsumerTest : BaseMessagingTestFixture
+    {
+        private static readonly ILog _logger = 
LogManager.GetLogger(typeof(ProducerMultiConsumerTest));
+
+        private string _commandQueueName = "ServiceQ1";
+
+        private const int CONSUMER_COUNT = 5;
+
+        private const int MESSAGE_COUNT = 1000;
+
+        private const string MESSAGE_DATA_BYTES = "****jfd ghljgl hjvhlj 
cvhvjf ldhfsj lhfdsjf hldsjfk hdslkfj hsdflk  ";
+
+        AutoResetEvent _finishedEvent = new AutoResetEvent(false);
+
+        private static String GetData(int size)
+        {
+            StringBuilder buf = new StringBuilder(size);
+            int count = 0;
+            while (count < size + MESSAGE_DATA_BYTES.Length)
+            {
+                buf.Append(MESSAGE_DATA_BYTES);
+                count += MESSAGE_DATA_BYTES.Length;
+            }
+            if (count < size)
+            {
+                buf.Append(MESSAGE_DATA_BYTES, 0, size - count);
+            }
+
+            return buf.ToString();
+        }
+
+        private IMessagePublisher _publisher;
+
+        private IMessageConsumer[] _consumers = new 
IMessageConsumer[CONSUMER_COUNT];
+
+        private int _messageReceivedCount = 0;
+
+        [SetUp]
+        public override void Init()
+        {
+            base.Init();
+            _publisher = _channel.CreatePublisherBuilder()
+                .WithRoutingKey(_commandQueueName)
+                .WithExchangeName(ExchangeNameDefaults.TOPIC)
+                .Create();
+
+            _publisher.DisableMessageTimestamp = true;
+            _publisher.DeliveryMode = DeliveryMode.NonPersistent;
+
+            for (int i = 0; i < CONSUMER_COUNT; i++)
+            {
+                string queueName = _channel.GenerateUniqueName();
+                _channel.DeclareQueue(queueName, false, true, true);
+                
+                _channel.Bind(queueName, ExchangeNameDefaults.TOPIC, 
_commandQueueName);
+
+                _consumers[i] = _channel.CreateConsumerBuilder(queueName)
+                    .WithPrefetchLow(100).Create();
+                _consumers[i].OnMessage = new 
MessageReceivedDelegate(OnMessage);
+            }
+            _connection.Start();
+        }
+
+        public void OnMessage(IMessage m)
+        {
+            int newCount = Interlocked.Increment(ref _messageReceivedCount);
+            if (newCount % 1000 == 0) _logger.Info("Received count=" + 
newCount);
+            if (newCount == (MESSAGE_COUNT * CONSUMER_COUNT))
+            {
+                _logger.Info("All messages received");
+                _finishedEvent.Set();
+            }
+            if ( newCount % 100 == 0 ) 
+               System.Diagnostics.Debug.WriteLine(((ITextMessage)m).Text);
+         }
+        
+        [Test]
+        public void RunTest()
+        {
+            for (int i = 0; i < MESSAGE_COUNT; i++)
+            {
+                ITextMessage msg;
+                try
+                {
+                   msg = _channel.CreateTextMessage(GetData(512 + 8*i));
+                }
+                catch (Exception e)
+                {
+                    _logger.Error("Error creating message: " + e, e);
+                    break;
+                }
+                _publisher.Send(msg);
+            }
+            _finishedEvent.WaitOne();
+        }
+    }
+}

Added: 
incubator/qpid/branches/M2.1/dotnet/Qpid.Integration.Tests/testcases/SslConnectionTest.cs
URL: 
http://svn.apache.org/viewvc/incubator/qpid/branches/M2.1/dotnet/Qpid.Integration.Tests/testcases/SslConnectionTest.cs?rev=612165&view=auto
==============================================================================
--- 
incubator/qpid/branches/M2.1/dotnet/Qpid.Integration.Tests/testcases/SslConnectionTest.cs
 (added)
+++ 
incubator/qpid/branches/M2.1/dotnet/Qpid.Integration.Tests/testcases/SslConnectionTest.cs
 Tue Jan 15 09:29:41 2008
@@ -0,0 +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
+{
+   /// <summary>
+   /// Test SSL/TLS connections to the broker
+   /// </summary>
+   [TestFixture, Category("Integration")]
+   public class SslConnectionTest
+   {
+      /// <summary>
+      /// Make a test TLS connection to the broker
+      /// without using client-certificates
+      /// </summary>
+      [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);
+         }
+      }
+   }
+}

Added: 
incubator/qpid/branches/M2.1/dotnet/Qpid.Integration.Tests/testcases/SyncConsumerTest.cs
URL: 
http://svn.apache.org/viewvc/incubator/qpid/branches/M2.1/dotnet/Qpid.Integration.Tests/testcases/SyncConsumerTest.cs?rev=612165&view=auto
==============================================================================
--- 
incubator/qpid/branches/M2.1/dotnet/Qpid.Integration.Tests/testcases/SyncConsumerTest.cs
 (added)
+++ 
incubator/qpid/branches/M2.1/dotnet/Qpid.Integration.Tests/testcases/SyncConsumerTest.cs
 Tue Jan 15 09:29:41 2008
@@ -0,0 +1,127 @@
+/*
+ *
+ * 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;
+
+namespace Apache.Qpid.Integration.Tests.testcases
+{
+  [TestFixture, Category("Integration")]
+   public class SyncConsumerTest : BaseMessagingTestFixture
+   {
+      private static readonly ILog _logger = 
LogManager.GetLogger(typeof(SyncConsumerTest));
+
+      private string _commandQueueName = "ServiceQ1";
+      private const int MESSAGE_COUNT = 1000;
+      private const string MESSAGE_DATA_BYTES = "jfd ghljgl hjvhlj cvhvjf 
ldhfsj lhfdsjf hldsjfk hdslkfj hsdflk  ";
+
+      private static String GetData(int size)
+      {
+         StringBuilder buf = new StringBuilder(size);
+         int count = 0;
+         while ( count < size + MESSAGE_DATA_BYTES.Length )
+         {
+            buf.Append(MESSAGE_DATA_BYTES);
+            count += MESSAGE_DATA_BYTES.Length;
+         }
+         if ( count < size )
+         {
+            buf.Append(MESSAGE_DATA_BYTES, 0, size - count);
+         }
+
+         return buf.ToString();
+      }
+
+      private IMessageConsumer _consumer;
+      private IMessagePublisher _publisher;
+
+      [SetUp]
+      public override void Init()
+      {
+         base.Init();
+         _publisher = _channel.CreatePublisherBuilder()
+             .WithRoutingKey(_commandQueueName)
+             .WithExchangeName(ExchangeNameDefaults.TOPIC)
+             .Create();
+
+         _publisher.DisableMessageTimestamp = true;
+         _publisher.DeliveryMode = DeliveryMode.NonPersistent;
+
+         string queueName = _channel.GenerateUniqueName();
+         _channel.DeclareQueue(queueName, false, true, true);
+
+         _channel.Bind(queueName, ExchangeNameDefaults.TOPIC, 
_commandQueueName);
+
+         _consumer = _channel.CreateConsumerBuilder(queueName)
+             .WithPrefetchLow(100).Create();
+         _connection.Start();
+      }
+
+      [Test]
+      public void ReceiveWithInfiniteWait()
+      {
+         // send all messages
+         for ( int i = 0; i < MESSAGE_COUNT; i++ )
+         {
+            ITextMessage msg;
+            try
+            {
+               msg = _channel.CreateTextMessage(GetData(512 + 8 * i));
+            } catch ( Exception e )
+            {
+               _logger.Error("Error creating message: " + e, e);
+               break;
+            }
+            _publisher.Send(msg);
+         }
+
+         _logger.Debug("All messages sent");
+         // receive all messages
+         for ( int i = 0; i < MESSAGE_COUNT; i++ )
+         {
+            try
+            {
+               IMessage msg = _consumer.Receive();
+               Assert.IsNotNull(msg);
+            } catch ( Exception e )
+            {
+               _logger.Error("Error receiving message: " + e, e);
+               Assert.Fail(e.ToString());
+            }
+         }
+      }
+
+      [Test]
+      public void ReceiveWithTimeout()
+      {
+         ITextMessage msg = _channel.CreateTextMessage(GetData(512 + 8));
+         _publisher.Send(msg);
+
+         IMessage recvMsg = _consumer.Receive();
+         Assert.IsNotNull(recvMsg);
+         // empty queue, should timeout
+         Assert.IsNull(_consumer.Receive(1000));
+      }
+   }
+}

Added: 
incubator/qpid/branches/M2.1/dotnet/Qpid.Integration.Tests/testcases/UndeliverableTest.cs
URL: 
http://svn.apache.org/viewvc/incubator/qpid/branches/M2.1/dotnet/Qpid.Integration.Tests/testcases/UndeliverableTest.cs?rev=612165&view=auto
==============================================================================
--- 
incubator/qpid/branches/M2.1/dotnet/Qpid.Integration.Tests/testcases/UndeliverableTest.cs
 (added)
+++ 
incubator/qpid/branches/M2.1/dotnet/Qpid.Integration.Tests/testcases/UndeliverableTest.cs
 Tue Jan 15 09:29:41 2008
@@ -0,0 +1,128 @@
+/*
+ *
+ * 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;
+
+namespace Apache.Qpid.Integration.Tests.testcases
+{
+   /// <summary>
+   /// Tests that when sending undeliverable messages with the 
+   /// mandatory flag set, an exception is raised on the connection
+   /// as the message is bounced back by the broker
+   /// </summary>
+  [TestFixture, Category("Integration")]
+   public class UndeliverableTest : BaseMessagingTestFixture
+   {
+      private static ILog _logger = 
LogManager.GetLogger(typeof(UndeliverableTest));
+      private ManualResetEvent _event;
+      public const int TIMEOUT = 1000;
+      private Exception _lastException;
+
+      [SetUp]
+      public override void Init()
+      {
+         base.Init();
+         _event = new ManualResetEvent(false);
+         _lastException = null;
+
+         try
+         {
+            _connection.ExceptionListener = new 
ExceptionListenerDelegate(OnException);
+         } catch ( QpidException e )
+         {
+            _logger.Error("Could not add ExceptionListener", e);
+         }
+      }
+
+      public void OnException(Exception e)
+      {
+         // Here we dig out the AMQUndelivered exception (if present) in order 
to log the returned message.
+
+         _lastException = e;
+         _logger.Error("OnException handler received connection-level 
exception", e);
+         if ( e is QpidException )
+         {
+            QpidException qe = (QpidException)e;
+            if ( qe.InnerException is AMQUndeliveredException )
+            {
+               AMQUndeliveredException ue = 
(AMQUndeliveredException)qe.InnerException;
+               _logger.Error("inner exception is AMQUndeliveredException", ue);
+               _logger.Error(string.Format("Returned message = {0}", 
ue.GetUndeliveredMessage()));
+            }
+         }
+         _event.Set();
+      }
+
+      [Test]
+      public void SendUndeliverableMessageOnDefaultExchange()
+      {
+         SendOne("default exchange", null);
+      }
+      [Test]
+      public void SendUndeliverableMessageOnDirectExchange()
+      {
+         SendOne("direct exchange", ExchangeNameDefaults.DIRECT);
+      }
+      [Test]
+      public void SendUndeliverableMessageOnTopicExchange()
+      {
+         SendOne("topic exchange", ExchangeNameDefaults.TOPIC);
+      }
+      [Test]
+      public void SendUndeliverableMessageOnHeadersExchange()
+      {
+         SendOne("headers exchange", ExchangeNameDefaults.HEADERS);
+      }
+
+      private void SendOne(string exchangeNameFriendly, string exchangeName)
+      {
+         _logger.Info("Sending undeliverable message to " + 
exchangeNameFriendly);
+
+         // Send a test message to a non-existant queue 
+         // on the specified exchange. See if message is returned!
+         MessagePublisherBuilder builder = _channel.CreatePublisherBuilder()
+             .WithRoutingKey("Non-existant route key!")
+             .WithMandatory(true); // necessary so that the server bounces the 
message back
+         if ( exchangeName != null )
+         {
+            builder.WithExchangeName(exchangeName);
+         }
+         IMessagePublisher publisher = builder.Create();
+         publisher.Send(_channel.CreateTextMessage("Hiya!"));
+
+         // check we received an exception on the connection
+         // and that it is of the right type
+         _event.WaitOne(TIMEOUT, true);
+
+         Type expectedException = typeof(AMQUndeliveredException);
+         Exception ex = _lastException;
+         Assert.IsNotNull(ex, "No exception was thrown by the test. Expected " 
+ expectedException);
+
+         if ( ex.InnerException != null )
+            ex = ex.InnerException;
+
+         Assert.IsInstanceOfType(expectedException, ex);
+      }
+   }
+}


Reply via email to