activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tab...@apache.org
Subject svn commit: r829820 - /activemq/activemq-dotnet/Apache.NMS/trunk/src/test/csharp/ConsumerTest.cs
Date Mon, 26 Oct 2009 15:03:36 GMT
Author: tabish
Date: Mon Oct 26 15:03:35 2009
New Revision: 829820

URL: http://svn.apache.org/viewvc?rev=829820&view=rev
Log:
Adds test to ensure that a timed consumer receive gets a message if its initaited before a
producer sends a message.

Modified:
    activemq/activemq-dotnet/Apache.NMS/trunk/src/test/csharp/ConsumerTest.cs

Modified: activemq/activemq-dotnet/Apache.NMS/trunk/src/test/csharp/ConsumerTest.cs
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS/trunk/src/test/csharp/ConsumerTest.cs?rev=829820&r1=829819&r2=829820&view=diff
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS/trunk/src/test/csharp/ConsumerTest.cs (original)
+++ activemq/activemq-dotnet/Apache.NMS/trunk/src/test/csharp/ConsumerTest.cs Mon Oct 26 15:03:35
2009
@@ -126,6 +126,69 @@
 				}
 			}
 		}
+
+        internal class ThreadArg
+        {
+            internal IConnection connection = null;
+            internal ISession session = null;
+            internal IDestination destination = null;
+        }
+
+        protected void DelayedProducerThreadProc(Object arg)
+        {
+            try
+            {
+                ThreadArg args = arg as ThreadArg;
+
+                using(ISession session = args.connection.CreateSession())
+                {
+                    using(IMessageProducer producer = session.CreateProducer(args.destination))
+                    {
+                        // Give the consumer time to enter the receive.
+                        Thread.Sleep(5000);
+        
+                        producer.Send(args.session.CreateTextMessage("Hello World"));
+                    }
+                }
+            }
+            catch(Exception e)
+            {
+                // Some other exception occurred.
+                Assert.Fail("Test failed with exception: " + e.Message);
+            }
+        }
+        
+        [RowTest]
+        [Row(AcknowledgementMode.AutoAcknowledge)]
+        [Row(AcknowledgementMode.ClientAcknowledge)]
+        [Row(AcknowledgementMode.DupsOkAcknowledge)]
+        [Row(AcknowledgementMode.Transactional)]
+        public void TestConsumerReceiveBeforeMessageDispatched(AcknowledgementMode ackMode)
+        {
+            // Launch a thread to perform a delayed send.
+            Thread sendThread = new Thread(DelayedProducerThreadProc);
+            using(IConnection connection = CreateConnection(TEST_CLIENT_ID))
+            {
+                connection.Start();
+                using(ISession session = connection.CreateSession(ackMode))
+                {
+                    ITemporaryQueue queue = session.CreateTemporaryQueue();
+                    using(IMessageConsumer consumer = session.CreateConsumer(queue))
+                    {
+                        ThreadArg arg = new ThreadArg();
+
+                        arg.connection = connection;
+                        arg.session = session;
+                        arg.destination = queue;
+                        
+                        sendThread.Start(arg);
+                        IMessage message = consumer.Receive(TimeSpan.FromMinutes(1));
+                        Assert.IsNotNull(message);
+                    }
+                }
+            }
+        }
+
 #endif
 
 	}



Mime
View raw message