Return-Path: Delivered-To: apmail-geronimo-activemq-commits-archive@www.apache.org Received: (qmail 18579 invoked from network); 10 Mar 2006 23:44:50 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 10 Mar 2006 23:44:50 -0000 Received: (qmail 43875 invoked by uid 500); 10 Mar 2006 23:44:50 -0000 Delivered-To: apmail-geronimo-activemq-commits-archive@geronimo.apache.org Received: (qmail 43842 invoked by uid 500); 10 Mar 2006 23:44:49 -0000 Mailing-List: contact activemq-commits-help@geronimo.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: activemq-dev@geronimo.apache.org Delivered-To: mailing list activemq-commits@geronimo.apache.org Received: (qmail 43833 invoked by uid 99); 10 Mar 2006 23:44:49 -0000 Received: from asf.osuosl.org (HELO asf.osuosl.org) (140.211.166.49) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 10 Mar 2006 15:44:49 -0800 X-ASF-Spam-Status: No, hits=-9.4 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from [209.237.227.194] (HELO minotaur.apache.org) (209.237.227.194) by apache.org (qpsmtpd/0.29) with SMTP; Fri, 10 Mar 2006 15:44:48 -0800 Received: (qmail 17999 invoked by uid 65534); 10 Mar 2006 23:44:28 -0000 Message-ID: <20060310234428.17998.qmail@minotaur.apache.org> Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r384955 [2/2] - in /incubator/activemq/trunk/activemq-dotnet: ./ src/main/csharp/ActiveMQ/ src/main/csharp/ActiveMQ/OpenWire/ src/main/csharp/NMS/ src/test/csharp/NMS/ Date: Fri, 10 Mar 2006 23:44:26 -0000 To: activemq-commits@geronimo.apache.org From: chirino@apache.org X-Mailer: svnmailer-1.0.7 X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N Modified: incubator/activemq/trunk/activemq-dotnet/src/test/csharp/NMS/TransactionTest.cs URL: http://svn.apache.org/viewcvs/incubator/activemq/trunk/activemq-dotnet/src/test/csharp/NMS/TransactionTest.cs?rev=384955&r1=384954&r2=384955&view=diff ============================================================================== --- incubator/activemq/trunk/activemq-dotnet/src/test/csharp/NMS/TransactionTest.cs (original) +++ incubator/activemq/trunk/activemq-dotnet/src/test/csharp/NMS/TransactionTest.cs Fri Mar 10 15:44:24 2006 @@ -1,253 +1,253 @@ -/* - * Copyright 2006 The Apache Software Foundation or its licensors, as - * applicable. - * - * Licensed 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 NMS; -using NUnit.Framework; -using System; -using System.Collections; - - -namespace NMS -{ - [TestFixture] - public class TransactionTest : JMSTestSupport - { - private static int destinationCounter; - - IMessageProducer producer; - IMessageConsumer consumer; - - [SetUp] - override public void SetUp() - { - acknowledgementMode = AcknowledgementMode.Transactional; - base.SetUp(); - Drain(); - } - - [TearDown] - override public void TearDown() - { - base.TearDown(); - } - - - [Test] - public void TestSendRollback() - { - IMessage[] outbound = new IMessage[]{ - session.CreateTextMessage("First Message"), - session.CreateTextMessage("Second Message") - }; - - //sends a message - producer.Send(outbound[0]); - session.Commit(); - - //sends a message that gets rollbacked - producer.Send(session.CreateTextMessage("I'm going to get rolled back.")); - session.Rollback(); - - //sends a message - producer.Send(outbound[1]); - session.Commit(); - - //receives the first message - ArrayList messages = new ArrayList(); - Console.WriteLine("About to consume message 1"); - IMessage message = consumer.Receive(1000); - messages.Add(message); - Console.WriteLine("Received: " + message); - - //receives the second message - Console.WriteLine("About to consume message 2"); - message = consumer.Receive(4000); - messages.Add(message); - Console.WriteLine("Received: " + message); - - //validates that the rollbacked was not consumed - session.Commit(); - IMessage[] inbound = new IMessage[messages.Count]; - messages.CopyTo(inbound); - AssertTextMessagesEqual("Rollback did not work.", outbound, inbound); - } - - [Test] - public void TestSendSessionClose() - { - IMessage[] outbound = new IMessage[]{ - session.CreateTextMessage("First Message"), - session.CreateTextMessage("Second Message") - }; - - //sends a message - producer.Send(outbound[0]); - session.Commit(); - - //sends a message that gets rollbacked - producer.Send(session.CreateTextMessage("I'm going to get rolled back.")); - consumer.Dispose(); - session.Dispose(); - - Reconnect(); - - //sends a message - producer.Send(outbound[1]); - session.Commit(); - - //receives the first message - ArrayList messages = new ArrayList(); - Console.WriteLine("About to consume message 1"); - IMessage message = consumer.Receive(1000); - messages.Add(message); - Console.WriteLine("Received: " + message); - - //receives the second message - Console.WriteLine("About to consume message 2"); - message = consumer.Receive(4000); - messages.Add(message); - Console.WriteLine("Received: " + message); - - //validates that the rollbacked was not consumed - session.Commit(); - IMessage[] inbound = new IMessage[messages.Count]; - messages.CopyTo(inbound); - AssertTextMessagesEqual("Rollback did not work.", outbound, inbound); - } - - [Test] - public void TestReceiveRollback() - { - IMessage[] outbound = new IMessage[]{ - session.CreateTextMessage("First Message"), - session.CreateTextMessage("Second Message") - }; - - //sent both messages - producer.Send(outbound[0]); - producer.Send(outbound[1]); - session.Commit(); - - Console.WriteLine("Sent 0: " + outbound[0]); - Console.WriteLine("Sent 1: " + outbound[1]); - - ArrayList messages = new ArrayList(); - IMessage message = consumer.Receive(1000); - messages.Add(message); - Assert.AreEqual(outbound[0], message); - session.Commit(); - - // rollback so we can get that last message again. - message = consumer.Receive(1000); - Assert.IsNotNull(message); - Assert.AreEqual(outbound[1], message); - session.Rollback(); - - // Consume again.. the previous message should - // get redelivered. - message = consumer.Receive(5000); - Assert.IsNotNull(message, "Should have re-received the message again!"); - messages.Add(message); - session.Commit(); - - IMessage[] inbound = new IMessage[messages.Count]; - messages.CopyTo(inbound); - AssertTextMessagesEqual("Rollback did not work", outbound, inbound); - } - - - [Test] - public void TestReceiveTwoThenRollback() - { - IMessage[] outbound = new IMessage[]{ - session.CreateTextMessage("First Message"), - session.CreateTextMessage("Second Message") - }; - - producer.Send(outbound[0]); - producer.Send(outbound[1]); - session.Commit(); - - Console.WriteLine("Sent 0: " + outbound[0]); - Console.WriteLine("Sent 1: " + outbound[1]); - - ArrayList messages = new ArrayList(); - IMessage message = consumer.Receive(1000); - AssertTextMessageEqual("first mesage received before rollback", outbound[0], message); - - message = consumer.Receive(1000); - Assert.IsNotNull(message); - AssertTextMessageEqual("second message received before rollback", outbound[1], message); - session.Rollback(); - - // Consume again.. the previous message should - // get redelivered. - message = consumer.Receive(5000); - Assert.IsNotNull(message, "Should have re-received the first message again!"); - messages.Add(message); - AssertTextMessageEqual("first message received after rollback", outbound[0], message); - - message = consumer.Receive(5000); - Assert.IsNotNull(message, "Should have re-received the second message again!"); - messages.Add(message); - AssertTextMessageEqual("second message received after rollback", outbound[1], message); - - Assert.IsNull(consumer.ReceiveNoWait()); - session.Commit(); - - IMessage[] inbound = new IMessage[messages.Count]; - messages.CopyTo(inbound); - AssertTextMessagesEqual("Rollback did not work", outbound, inbound); - } - - protected override string CreateDestinationName() - { - // TODO - how can we get the test name? - return base.CreateDestinationName() + (++destinationCounter); - } - - protected void AssertTextMessagesEqual(String message, IMessage[] expected, IMessage[] actual) - { - Assert.AreEqual(expected.Length, actual.Length, "Incorrect number of messages received"); - - for (int i = 0; i < expected.Length; i++) - { - AssertTextMessageEqual(message + ". Index: " + i, expected[i], actual[i]); - } - } - - protected void AssertTextMessageEqual(String message, IMessage expected, IMessage actual) - { - Assert.IsTrue(expected is ITextMessage, "expected object not a text message"); - Assert.IsTrue(actual is ITextMessage, "actual object not a text message"); - - String expectedText = ((ITextMessage) expected).Text; - String actualText = ((ITextMessage) actual).Text; - - Assert.AreEqual(expectedText, actualText, message); - } - - protected override void Connect() - { - base.Connect(); - consumer = session.CreateConsumer(Destination); - producer = session.CreateProducer(Destination); - } - - } -} - - +/* + * Copyright 2006 The Apache Software Foundation or its licensors, as + * applicable. + * + * Licensed 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 NMS; +using NUnit.Framework; +using System; +using System.Collections; + + +namespace NMS +{ + [TestFixture] + public class TransactionTest : JMSTestSupport + { + private static int destinationCounter; + + IMessageProducer producer; + IMessageConsumer consumer; + + [SetUp] + override public void SetUp() + { + acknowledgementMode = AcknowledgementMode.Transactional; + base.SetUp(); + Drain(); + } + + [TearDown] + override public void TearDown() + { + base.TearDown(); + } + + + [Test] + public void TestSendRollback() + { + IMessage[] outbound = new IMessage[]{ + session.CreateTextMessage("First Message"), + session.CreateTextMessage("Second Message") + }; + + //sends a message + producer.Send(outbound[0]); + session.Commit(); + + //sends a message that gets rollbacked + producer.Send(session.CreateTextMessage("I'm going to get rolled back.")); + session.Rollback(); + + //sends a message + producer.Send(outbound[1]); + session.Commit(); + + //receives the first message + ArrayList messages = new ArrayList(); + Console.WriteLine("About to consume message 1"); + IMessage message = consumer.Receive(TimeSpan.FromMilliseconds(1000)); + messages.Add(message); + Console.WriteLine("Received: " + message); + + //receives the second message + Console.WriteLine("About to consume message 2"); + message = consumer.Receive(TimeSpan.FromMilliseconds(4000)); + messages.Add(message); + Console.WriteLine("Received: " + message); + + //validates that the rollbacked was not consumed + session.Commit(); + IMessage[] inbound = new IMessage[messages.Count]; + messages.CopyTo(inbound); + AssertTextMessagesEqual("Rollback did not work.", outbound, inbound); + } + + [Test] + public void TestSendSessionClose() + { + IMessage[] outbound = new IMessage[]{ + session.CreateTextMessage("First Message"), + session.CreateTextMessage("Second Message") + }; + + //sends a message + producer.Send(outbound[0]); + session.Commit(); + + //sends a message that gets rollbacked + producer.Send(session.CreateTextMessage("I'm going to get rolled back.")); + consumer.Dispose(); + session.Dispose(); + + Reconnect(); + + //sends a message + producer.Send(outbound[1]); + session.Commit(); + + //receives the first message + ArrayList messages = new ArrayList(); + Console.WriteLine("About to consume message 1"); + IMessage message = consumer.Receive(TimeSpan.FromMilliseconds(1000)); + messages.Add(message); + Console.WriteLine("Received: " + message); + + //receives the second message + Console.WriteLine("About to consume message 2"); + message = consumer.Receive(TimeSpan.FromMilliseconds(4000)); + messages.Add(message); + Console.WriteLine("Received: " + message); + + //validates that the rollbacked was not consumed + session.Commit(); + IMessage[] inbound = new IMessage[messages.Count]; + messages.CopyTo(inbound); + AssertTextMessagesEqual("Rollback did not work.", outbound, inbound); + } + + [Test] + public void TestReceiveRollback() + { + IMessage[] outbound = new IMessage[]{ + session.CreateTextMessage("First Message"), + session.CreateTextMessage("Second Message") + }; + + //sent both messages + producer.Send(outbound[0]); + producer.Send(outbound[1]); + session.Commit(); + + Console.WriteLine("Sent 0: " + outbound[0]); + Console.WriteLine("Sent 1: " + outbound[1]); + + ArrayList messages = new ArrayList(); + IMessage message = consumer.Receive(TimeSpan.FromMilliseconds(1000)); + messages.Add(message); + Assert.AreEqual(outbound[0], message); + session.Commit(); + + // rollback so we can get that last message again. + message = consumer.Receive(TimeSpan.FromMilliseconds(1000)); + Assert.IsNotNull(message); + Assert.AreEqual(outbound[1], message); + session.Rollback(); + + // Consume again.. the previous message should + // get redelivered. + message = consumer.Receive(TimeSpan.FromMilliseconds(5000)); + Assert.IsNotNull(message, "Should have re-received the message again!"); + messages.Add(message); + session.Commit(); + + IMessage[] inbound = new IMessage[messages.Count]; + messages.CopyTo(inbound); + AssertTextMessagesEqual("Rollback did not work", outbound, inbound); + } + + + [Test] + public void TestReceiveTwoThenRollback() + { + IMessage[] outbound = new IMessage[]{ + session.CreateTextMessage("First Message"), + session.CreateTextMessage("Second Message") + }; + + producer.Send(outbound[0]); + producer.Send(outbound[1]); + session.Commit(); + + Console.WriteLine("Sent 0: " + outbound[0]); + Console.WriteLine("Sent 1: " + outbound[1]); + + ArrayList messages = new ArrayList(); + IMessage message = consumer.Receive(TimeSpan.FromMilliseconds(1000)); + AssertTextMessageEqual("first mesage received before rollback", outbound[0], message); + + message = consumer.Receive(TimeSpan.FromMilliseconds(1000)); + Assert.IsNotNull(message); + AssertTextMessageEqual("second message received before rollback", outbound[1], message); + session.Rollback(); + + // Consume again.. the previous message should + // get redelivered. + message = consumer.Receive(TimeSpan.FromMilliseconds(5000)); + Assert.IsNotNull(message, "Should have re-received the first message again!"); + messages.Add(message); + AssertTextMessageEqual("first message received after rollback", outbound[0], message); + + message = consumer.Receive(TimeSpan.FromMilliseconds(5000)); + Assert.IsNotNull(message, "Should have re-received the second message again!"); + messages.Add(message); + AssertTextMessageEqual("second message received after rollback", outbound[1], message); + + Assert.IsNull(consumer.ReceiveNoWait()); + session.Commit(); + + IMessage[] inbound = new IMessage[messages.Count]; + messages.CopyTo(inbound); + AssertTextMessagesEqual("Rollback did not work", outbound, inbound); + } + + protected override string CreateDestinationName() + { + // TODO - how can we get the test name? + return base.CreateDestinationName() + (++destinationCounter); + } + + protected void AssertTextMessagesEqual(String message, IMessage[] expected, IMessage[] actual) + { + Assert.AreEqual(expected.Length, actual.Length, "Incorrect number of messages received"); + + for (int i = 0; i < expected.Length; i++) + { + AssertTextMessageEqual(message + ". Index: " + i, expected[i], actual[i]); + } + } + + protected void AssertTextMessageEqual(String message, IMessage expected, IMessage actual) + { + Assert.IsTrue(expected is ITextMessage, "expected object not a text message"); + Assert.IsTrue(actual is ITextMessage, "actual object not a text message"); + + String expectedText = ((ITextMessage) expected).Text; + String actualText = ((ITextMessage) actual).Text; + + Assert.AreEqual(expectedText, actualText, message); + } + + protected override void Connect() + { + base.Connect(); + consumer = session.CreateConsumer(Destination); + producer = session.CreateProducer(Destination); + } + + } +} + +