You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by ta...@apache.org on 2010/11/03 22:00:43 UTC
svn commit: r1030682 - in
/activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/test/csharp:
NetTxConnectionFactoryTest.cs NetTxTransactionTest.cs
Author: tabish
Date: Wed Nov 3 21:00:43 2010
New Revision: 1030682
URL: http://svn.apache.org/viewvc?rev=1030682&view=rev
Log:
tests for: https://issues.apache.org/activemq/browse/AMQNET-290
Added:
activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/test/csharp/NetTxConnectionFactoryTest.cs (with props)
activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/test/csharp/NetTxTransactionTest.cs (with props)
Added: activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/test/csharp/NetTxConnectionFactoryTest.cs
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/test/csharp/NetTxConnectionFactoryTest.cs?rev=1030682&view=auto
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/test/csharp/NetTxConnectionFactoryTest.cs (added)
+++ activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/test/csharp/NetTxConnectionFactoryTest.cs Wed Nov 3 21:00:43 2010
@@ -0,0 +1,198 @@
+/*
+ * 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.NMS.Test;
+using Apache.NMS.Util;
+using Apache.NMS.ActiveMQ;
+
+namespace Apache.NMS.ActiveMQ.Test
+{
+ [TestFixture]
+ public class NetTxConnectionFactoryTest : NMSTestSupport
+ {
+ [Test]
+ [TestCase("tcp://${activemqhost}:61616")]
+ [TestCase("tcp://${activemqhost}:61616")]
+ [TestCase("tcp://${activemqhost}:61616/0.0.0.0:0")]
+ [TestCase("tcp://${activemqhost}:61616?connection.asyncclose=false")]
+ [TestCase("failover:tcp://${activemqhost}:61616")]
+ [TestCase("failover:(tcp://${activemqhost}:61616)")]
+ [TestCase("failover:(tcp://${activemqhost}:61616,tcp://${activemqhost}:61616)")]
+ [TestCase("failover://(tcp://${activemqhost}:61616)?transport.initialReconnectDelay=100")]
+ [TestCase("failover:(tcp://${activemqhost}:61616)?connection.asyncSend=true")]
+ [TestCase("failover:(tcp://${activemqhost}:61616)?transport.timeout=100&connection.asyncSend=true")]
+ [TestCase("failover:tcp://${activemqhost}:61616?keepAlive=false&wireFormat.maxInactivityDuration=1000")]
+ [TestCase("failover:(tcp://${activemqhost}:61616?keepAlive=false&wireFormat.maxInactivityDuration=1000)")]
+ [TestCase("failover:(tcp://${activemqhost}:61616?keepAlive=false&wireFormat.maxInactivityDuration=1000)?connection.asyncclose=false")]
+ [TestCase("failover:(tcp://${activemqhost}:61616?keepAlive=true&wireFormat.maxInactivityDuration=300000&wireFormat.tcpNoDelayEnabled=true)?initialReconnectDelay=100&randomize=false&timeout=15000")]
+ public void TestURI(string connectionURI)
+ {
+ {
+ Uri uri = URISupport.CreateCompatibleUri(NMSTestSupport.ReplaceEnvVar(connectionURI));
+ NetTxConnectionFactory factory = new NetTxConnectionFactory(uri);
+ Assert.IsNotNull(factory);
+ using(IConnection connection = factory.CreateConnection("", ""))
+ {
+ Assert.IsNotNull(connection);
+
+ using(ISession session = connection.CreateSession())
+ {
+ IDestination destination = session.CreateTemporaryTopic();
+ using(IMessageProducer producer = session.CreateProducer(destination))
+ {
+ producer.Close();
+ }
+
+ using(IMessageConsumer consumer = session.CreateConsumer(destination))
+ {
+ consumer.Close();
+ }
+
+ session.Close();
+ }
+
+ connection.Close();
+ }
+ }
+
+ {
+ NetTxConnectionFactory factory = new NetTxConnectionFactory(NMSTestSupport.ReplaceEnvVar(connectionURI));
+ Assert.IsNotNull(factory);
+ using(IConnection connection = factory.CreateConnection("", ""))
+ {
+ Assert.IsNotNull(connection);
+
+ using(ISession session = connection.CreateSession())
+ {
+ Assert.IsNotNull(session as INetTxSession);
+
+ IDestination destination = session.CreateTemporaryTopic();
+ using(IMessageProducer producer = session.CreateProducer(destination))
+ {
+ producer.Close();
+ }
+
+ using(IMessageConsumer consumer = session.CreateConsumer(destination))
+ {
+ consumer.Close();
+ }
+
+ session.Close();
+ }
+
+ connection.Close();
+ }
+ }
+ }
+
+ [Test, Sequential]
+ public void TestConnectionFactorySetParams(
+ [Values("tcp://${activemqhost}:61616", "activemq:tcp://${activemqhost}:61616")]
+ string connectionURI,
+ [Values(AcknowledgementMode.ClientAcknowledge, AcknowledgementMode.AutoAcknowledge)]
+ AcknowledgementMode ackMode,
+ [Values(true, false)]
+ bool asyncSend,
+ [Values(true, false)]
+ bool alwaysSyncSend,
+ [Values(true, false)]
+ bool asyncClose,
+ [Values(true, false)]
+ bool copyMessageOnSend,
+ [Values(3000, 1000)]
+ int requestTimeout,
+ [Values(true, false)]
+ bool sendAcksAsync,
+ [Values(true, false)]
+ bool dispatchAsync)
+ {
+ NetTxConnectionFactory factory = new NetTxConnectionFactory(NMSTestSupport.ReplaceEnvVar(connectionURI));
+
+ factory.AcknowledgementMode = ackMode;
+ factory.AsyncSend = asyncSend;
+ factory.AlwaysSyncSend = alwaysSyncSend;
+ factory.AsyncClose = asyncClose;
+ factory.CopyMessageOnSend = copyMessageOnSend;
+ factory.RequestTimeout = requestTimeout;
+ factory.SendAcksAsync = sendAcksAsync;
+ factory.DispatchAsync = dispatchAsync;
+
+ using(Connection connection = factory.CreateConnection() as Connection)
+ {
+ Assert.AreEqual(ackMode, connection.AcknowledgementMode);
+ Assert.AreEqual(asyncSend, connection.AsyncSend);
+ Assert.AreEqual(alwaysSyncSend, connection.AlwaysSyncSend);
+ Assert.AreEqual(asyncClose, connection.AsyncClose);
+ Assert.AreEqual(copyMessageOnSend, connection.CopyMessageOnSend);
+ Assert.AreEqual(requestTimeout, connection.RequestTimeout.TotalMilliseconds);
+ Assert.AreEqual(sendAcksAsync, connection.SendAcksAsync);
+ Assert.AreEqual(dispatchAsync, connection.DispatchAsync);
+ }
+ }
+
+ [Test, Sequential]
+ public void TestConnectionFactoryParseParams(
+ [Values("tcp://${activemqhost}:61616", "activemq:tcp://${activemqhost}:61616")]
+ string baseConnectionURI,
+ [Values(AcknowledgementMode.ClientAcknowledge, AcknowledgementMode.AutoAcknowledge)]
+ AcknowledgementMode ackMode,
+ [Values(true, false)]
+ bool asyncSend,
+ [Values(true, false)]
+ bool alwaysSyncSend,
+ [Values(true, false)]
+ bool asyncClose,
+ [Values(true, false)]
+ bool copyMessageOnSend,
+ [Values(3000, 1000)]
+ int requestTimeout,
+ [Values(true, false)]
+ bool sendAcksAsync,
+ [Values(true, false)]
+ bool dispatchAsync)
+ {
+ string connectionURI = string.Format("{0}?" +
+ "connection.AckMode={1}&" +
+ "connection.AsyncSend={2}&" +
+ "connection.AlwaysSyncSend={3}&" +
+ "connection.AsyncClose={4}&" +
+ "connection.CopyMessageOnSend={5}&" +
+ "connection.RequestTimeout={6}&" +
+ "connection.SendAcksAsync={7}&" +
+ "connection.DispatchAsync={8}",
+ baseConnectionURI, ackMode, asyncSend, alwaysSyncSend, asyncClose, copyMessageOnSend, requestTimeout, sendAcksAsync, dispatchAsync);
+
+ NetTxConnectionFactory factory = new NetTxConnectionFactory(NMSTestSupport.ReplaceEnvVar(connectionURI));
+
+ using(Connection connection = factory.CreateConnection() as Connection)
+ {
+ Assert.AreEqual(ackMode, connection.AcknowledgementMode);
+ Assert.AreEqual(asyncSend, connection.AsyncSend);
+ Assert.AreEqual(alwaysSyncSend, connection.AlwaysSyncSend);
+ Assert.AreEqual(asyncClose, connection.AsyncClose);
+ Assert.AreEqual(copyMessageOnSend, connection.CopyMessageOnSend);
+ Assert.AreEqual(requestTimeout, connection.RequestTimeout.TotalMilliseconds);
+ Assert.AreEqual(sendAcksAsync, connection.SendAcksAsync);
+ Assert.AreEqual(dispatchAsync, connection.DispatchAsync);
+ }
+ }
+ }
+}
+
+
Propchange: activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/test/csharp/NetTxConnectionFactoryTest.cs
------------------------------------------------------------------------------
svn:eol-style = native
Added: activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/test/csharp/NetTxTransactionTest.cs
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/test/csharp/NetTxTransactionTest.cs?rev=1030682&view=auto
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/test/csharp/NetTxTransactionTest.cs (added)
+++ activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/test/csharp/NetTxTransactionTest.cs Wed Nov 3 21:00:43 2010
@@ -0,0 +1,285 @@
+/*
+ * 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 System.Transactions;
+
+using NUnit.Framework;
+using Apache.NMS.Test;
+using Apache.NMS.Util;
+using Apache.NMS.ActiveMQ;
+
+namespace Apache.NMS.ActiveMQ.Test
+{
+ [TestFixture]
+ public class NetTxTransactionTest : NMSTestSupport
+ {
+ private const int MSG_COUNT = 50;
+
+ [Test]
+ public void TestTransactedProduceAndConsume(
+ [Values("tcp://${activemqhost}:61616")]
+ string baseConnectionURI)
+ {
+ INetTxConnectionFactory factory = new NetTxConnectionFactory(NMSTestSupport.ReplaceEnvVar(baseConnectionURI));
+
+ using(INetTxConnection connection = factory.CreateNetTxConnection())
+ {
+ connection.Start();
+
+ using(INetTxSession session = connection.CreateNetTxSession())
+ {
+ IDestination destination = session.CreateTemporaryQueue();
+ using(IMessageProducer producer = session.CreateProducer(destination))
+ {
+ using(TransactionScope scoped = new TransactionScope(TransactionScopeOption.RequiresNew))
+ {
+ Assert.IsNotNull(Transaction.Current);
+ for(int i = 0; i < MSG_COUNT; ++i)
+ {
+ producer.Send(session.CreateTextMessage("Hello World"));
+ }
+
+ scoped.Complete();
+ }
+ }
+
+ using(IMessageConsumer consumer = session.CreateConsumer(destination))
+ {
+ Thread.Sleep(100);
+
+ using(TransactionScope scoped = new TransactionScope(TransactionScopeOption.RequiresNew))
+ {
+ for(int i = 0; i < MSG_COUNT; ++i)
+ {
+ IMessage msg = consumer.Receive(TimeSpan.FromMilliseconds(2000));
+ Assert.IsNotNull(msg, "Message was null for index: " + i);
+ }
+ scoped.Complete();
+ }
+ }
+
+ // No more messages should be in the Q, non rolled back or otherwise.
+ using(IMessageConsumer consumer = session.CreateConsumer(destination))
+ {
+ Thread.Sleep(100);
+ IMessage msg = consumer.Receive(TimeSpan.FromMilliseconds(2000));
+ Assert.IsNull(msg, "Message was not null.");
+ }
+
+ session.Close();
+ }
+
+ connection.Close();
+ }
+ }
+
+ [Test]
+ public void TestTransactedProduceRollbackAndConsume(
+ [Values("tcp://${activemqhost}:61616")]
+ string baseConnectionURI)
+ {
+ INetTxConnectionFactory factory = new NetTxConnectionFactory(NMSTestSupport.ReplaceEnvVar(baseConnectionURI));
+
+ using(INetTxConnection connection = factory.CreateNetTxConnection())
+ {
+ connection.Start();
+
+ using(INetTxSession session = connection.CreateNetTxSession())
+ {
+ IDestination destination = session.CreateTemporaryQueue();
+ using(IMessageProducer producer = session.CreateProducer(destination))
+ {
+ using(TransactionScope scoped = new TransactionScope(TransactionScopeOption.RequiresNew))
+ {
+ Assert.IsNotNull(Transaction.Current);
+ for(int i = 0; i < MSG_COUNT; ++i)
+ {
+ producer.Send(session.CreateTextMessage("Hello World"));
+ }
+ }
+ }
+
+ using(IMessageConsumer consumer = session.CreateConsumer(destination))
+ {
+ Thread.Sleep(100);
+
+ using(TransactionScope scoped = new TransactionScope(TransactionScopeOption.RequiresNew))
+ {
+ for(int i = 0; i < MSG_COUNT; ++i)
+ {
+ IMessage msg = consumer.Receive(TimeSpan.FromMilliseconds(50));
+ Assert.IsNull(msg, "Message was not null for index: " + i);
+ }
+ scoped.Complete();
+ }
+ }
+
+ session.Close();
+ }
+
+ connection.Close();
+ }
+ }
+
+ [Test]
+ public void TestTransactedProduceConsumeRollbackConsume(
+ [Values("tcp://${activemqhost}:61616")]
+ string baseConnectionURI)
+ {
+ INetTxConnectionFactory factory = new NetTxConnectionFactory(NMSTestSupport.ReplaceEnvVar(baseConnectionURI));
+
+ using(INetTxConnection connection = factory.CreateNetTxConnection())
+ {
+ connection.Start();
+
+ using(INetTxSession session = connection.CreateNetTxSession())
+ {
+ IDestination destination = session.CreateTemporaryQueue();
+ using(IMessageProducer producer = session.CreateProducer(destination))
+ {
+ using(TransactionScope scoped = new TransactionScope(TransactionScopeOption.RequiresNew))
+ {
+ Assert.IsNotNull(Transaction.Current);
+ for(int i = 0; i < MSG_COUNT; ++i)
+ {
+ producer.Send(session.CreateTextMessage("Hello World"));
+ }
+ scoped.Complete();
+ }
+ }
+
+ using(IMessageConsumer consumer = session.CreateConsumer(destination))
+ {
+ Thread.Sleep(200);
+
+ using(TransactionScope scoped = new TransactionScope(TransactionScopeOption.RequiresNew))
+ {
+ for(int i = 0; i < MSG_COUNT; ++i)
+ {
+ IMessage msg = consumer.Receive(TimeSpan.FromMilliseconds(2000));
+ Assert.IsNotNull(msg, "Message was null for index: " + i);
+ }
+ }
+
+ using(TransactionScope scoped = new TransactionScope(TransactionScopeOption.RequiresNew))
+ {
+ for(int i = 0; i < MSG_COUNT; ++i)
+ {
+ IMessage msg = consumer.Receive(TimeSpan.FromMilliseconds(2000));
+ Assert.IsNotNull(msg, "Message was null for index: " + i);
+ }
+ }
+ }
+
+ using(IMessageConsumer consumer = session.CreateConsumer(destination))
+ {
+ Thread.Sleep(200);
+
+ using(TransactionScope scoped = new TransactionScope(TransactionScopeOption.RequiresNew))
+ {
+ for(int i = 0; i < MSG_COUNT; ++i)
+ {
+ IMessage msg = consumer.Receive(TimeSpan.FromMilliseconds(2000));
+ Assert.IsNotNull(msg, "Message was null for index: " + i);
+ Assert.IsTrue(msg.NMSRedelivered);
+ }
+ scoped.Complete();
+ }
+ }
+
+ session.Close();
+ }
+
+ connection.Close();
+ }
+ }
+
+ [Test]
+ public void TestTransactedProduceConsumeWithSessionClose(
+ [Values("tcp://${activemqhost}:61616")]
+ string baseConnectionURI)
+ {
+ INetTxConnectionFactory factory = new NetTxConnectionFactory(NMSTestSupport.ReplaceEnvVar(baseConnectionURI));
+
+ using(INetTxConnection connection = factory.CreateNetTxConnection())
+ {
+ connection.Start();
+
+ IDestination destination = null;
+
+ using(INetTxSession session = connection.CreateNetTxSession())
+ {
+ destination = session.CreateTemporaryQueue();
+ using(IMessageProducer producer = session.CreateProducer(destination))
+ {
+ using(TransactionScope scoped = new TransactionScope(TransactionScopeOption.RequiresNew))
+ {
+ Assert.IsNotNull(Transaction.Current);
+ for(int i = 0; i < MSG_COUNT; ++i)
+ {
+ producer.Send(session.CreateTextMessage("Hello World"));
+ }
+
+ session.Close();
+
+ scoped.Complete();
+ }
+ }
+ }
+
+ using(INetTxSession session = connection.CreateNetTxSession())
+ {
+ using(IMessageConsumer consumer = session.CreateConsumer(destination))
+ {
+ using(TransactionScope scoped = new TransactionScope(TransactionScopeOption.RequiresNew))
+ {
+ for(int i = 0; i < MSG_COUNT; ++i)
+ {
+ IMessage msg = consumer.Receive(TimeSpan.FromMilliseconds(2000));
+ Assert.IsNotNull(msg, "Message was null for index: " + i);
+ }
+
+ session.Close();
+
+ scoped.Complete();
+ }
+ }
+ }
+
+ using(INetTxSession session = connection.CreateNetTxSession())
+ {
+ using(IMessageConsumer consumer = session.CreateConsumer(destination))
+ {
+ for(int i = 0; i < MSG_COUNT; ++i)
+ {
+ IMessage msg = consumer.Receive(TimeSpan.FromMilliseconds(50));
+ Assert.IsNull(msg, "Message was not null for index: " + i);
+ }
+ }
+
+ session.Close();
+ }
+
+ connection.Close();
+ }
+ }
+
+ }
+}
+
Propchange: activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/test/csharp/NetTxTransactionTest.cs
------------------------------------------------------------------------------
svn:eol-style = native