summaryrefslogtreecommitdiff
path: root/dotnet/Qpid.Client.Tests/undeliverable
diff options
context:
space:
mode:
authorSteven Shaw <steshaw@apache.org>2006-11-25 22:04:39 +0000
committerSteven Shaw <steshaw@apache.org>2006-11-25 22:04:39 +0000
commit7c1f9158be7a5d1124a48f42f8d7dcfb6d5df2a6 (patch)
tree3122525268281cd9df870e0a9cb309ee7410a424 /dotnet/Qpid.Client.Tests/undeliverable
parent8f32ca18d5281eaa5baafa769c99fa70c830b14f (diff)
downloadqpid-python-7c1f9158be7a5d1124a48f42f8d7dcfb6d5df2a6.tar.gz
QPID-128 Initial import of the C# sources.
git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid@479211 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'dotnet/Qpid.Client.Tests/undeliverable')
-rw-r--r--dotnet/Qpid.Client.Tests/undeliverable/UndeliverableTest.cs94
1 files changed, 94 insertions, 0 deletions
diff --git a/dotnet/Qpid.Client.Tests/undeliverable/UndeliverableTest.cs b/dotnet/Qpid.Client.Tests/undeliverable/UndeliverableTest.cs
new file mode 100644
index 0000000000..63c936d667
--- /dev/null
+++ b/dotnet/Qpid.Client.Tests/undeliverable/UndeliverableTest.cs
@@ -0,0 +1,94 @@
+/*
+ *
+ * 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 Qpid.Messaging;
+
+namespace Qpid.Client.Tests
+{
+ [TestFixture]
+ public class UndeliverableTest : BaseMessagingTestFixture
+ {
+ private static ILog _logger = LogManager.GetLogger(typeof(UndeliverableTest));
+
+ [SetUp]
+ public override void Init()
+ {
+ base.Init();
+
+ try
+ {
+ _connection.ExceptionListener = new ExceptionListenerDelegate(OnException);
+ }
+ catch (QpidException e)
+ {
+ _logger.Error("Could not add ExceptionListener", e);
+ }
+ }
+
+ public static void OnException(Exception e)
+ {
+ // Here we dig out the AMQUndelivered exception (if present) in order to log the returned message.
+
+ _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()));
+
+ }
+ }
+ }
+
+ [Test]
+ public void SendUndeliverableMessage()
+ {
+ SendOne("default exchange", null);
+ SendOne("direct exchange", ExchangeNameDefaults.DIRECT);
+ SendOne("topic exchange", ExchangeNameDefaults.TOPIC);
+ SendOne("headers exchange", ExchangeNameDefaults.HEADERS);
+
+ Thread.Sleep(1000); // Wait for message returns!
+ }
+
+ 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 default exchange. See if message is returned!
+ MessagePublisherBuilder builder = _channel.CreatePublisherBuilder()
+ .withRoutingKey("Non-existant route key!")
+ .withMandatory(true);
+ if (exchangeName != null)
+ {
+ builder.withExchangeName(exchangeName);
+ }
+ IMessagePublisher publisher = builder.Create();
+ publisher.Send(_channel.CreateTextMessage("Hiya!"));
+ }
+ }
+}