Improve testing infrastructure to run all tests together

Fix test that were failing due to typos of property values in XML config that have changed.
This commit is contained in:
markpollack
2010-07-15 21:49:33 +00:00
parent d9db104cd2
commit 781785b112
8 changed files with 100 additions and 37 deletions

View File

@@ -46,33 +46,12 @@ namespace Spring.Messaging.Core
[SetUp]
public override void SetUp()
{
RecreateMessageQueue(@".\Private$\testqueue", false);
RecreateMessageQueue(@".\Private$\testtxqueue", true);
MessageQueueUtils.RecreateMessageQueue(@".\Private$\testqueue", false);
MessageQueueUtils.RecreateMessageQueue(@".\Private$\testtxqueue", true);
base.SetUp();
}
private void RecreateMessageQueue(string path, bool transactional)
{
bool defaultCacheEnabled = MessageQueue.EnableConnectionCache;
MessageQueue.ClearConnectionCache();
MessageQueue.EnableConnectionCache = false;
if (MessageQueue.Exists(path))
{
MessageQueue queue;
// TODO (EE): delete/create doesn't work for some reason
// MessageQueue.Delete(path);
// queue = MessageQueue.Create(path, transactional);
queue = new MessageQueue(path);
queue.Purge();
queue.Dispose();
}
else
{
MessageQueue.Create(path, transactional).Dispose();
}
MessageQueue.ClearConnectionCache();
MessageQueue.EnableConnectionCache = defaultCacheEnabled; // set to default
}
#if NET_2_0 || NET_3_0
[Test]

View File

@@ -0,0 +1,55 @@
#region License
/*
* Copyright 2002-2010 the original author or authors.
*
* 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.
*/
#endregion
using System.Messaging;
namespace Spring.Messaging.Core
{
/// <summary>
/// Utility class to recreate message queues if they do not exist.
/// </summary>
/// <author>Mark Pollack</author>
public class MessageQueueUtils
{
public static void RecreateMessageQueue(string path, bool transactional)
{
bool defaultCacheEnabled = MessageQueue.EnableConnectionCache;
MessageQueue.ClearConnectionCache();
MessageQueue.EnableConnectionCache = false;
if (MessageQueue.Exists(path))
{
MessageQueue queue;
// TODO (EE): delete/create doesn't work for some reason
// MessageQueue.Delete(path);
// queue = MessageQueue.Create(path, transactional);
queue = new MessageQueue(path);
queue.Purge();
queue.Dispose();
}
else
{
MessageQueue.Create(path, transactional).Dispose();
}
MessageQueue.ClearConnectionCache();
MessageQueue.EnableConnectionCache = defaultCacheEnabled; // set to default
}
}
}

View File

@@ -20,6 +20,7 @@
#region Imports
using System.Messaging;
using System.Threading;
using NUnit.Framework;
using Spring.Messaging.Core;
@@ -36,10 +37,20 @@ namespace Spring.Messaging.Listener
[TestFixture]
public class DistributedTxMessageListenerContainerTests : AbstractDependencyInjectionSpringContextTests
{
private int waitInMillis = 20000;
private DistributedTxMessageListenerContainer distributedTxMessageListenerContainer;
private SimpleHandler listener;
[SetUp]
public override void SetUp()
{
MessageQueueUtils.RecreateMessageQueue(@".\Private$\testtxqueue", true);
MessageQueueUtils.RecreateMessageQueue(@".\Private$\testtxretryqueue", true);
base.SetUp();
}
public DistributedTxMessageListenerContainer DistributedTxMessageListenerContainer
{
@@ -80,7 +91,6 @@ namespace Spring.Messaging.Listener
Assert.AreEqual("Goodbye World 1", textMsg);
}
[Test]
public void SendAndAsyncReceive()
{
@@ -100,7 +110,7 @@ namespace Spring.Messaging.Listener
distributedTxMessageListenerContainer.Start();
Thread.Sleep(waitInMillis);
Assert.AreEqual(5, listener.MessageCount);
Assert.AreEqual(15, listener.MessageCount);
distributedTxMessageListenerContainer.Stop();
distributedTxMessageListenerContainer.Shutdown();

View File

@@ -13,12 +13,12 @@
<object id='msmqtxqueue' type='Spring.Messaging.Support.MessageQueueFactoryObject, Spring.Messaging'>
<property name='Path' value='.\Private$\testtxqueue'/>
<property name='MessageReadPropertyFilterSetAll' value='true'/>
<property name='MessageReadPropertyFilterSetAll' value='true'/>
<property name='ProductTemplate'>
<object>
<property name='Label' value='MyTxLabel'/>
</object>
</property>
</property>
</object>
<object id='msmqtxresponsequeue' type='Spring.Messaging.Support.MessageQueueFactoryObject, Spring.Messaging'>
@@ -33,7 +33,7 @@
<object id='msmqtxretryqueue' type='Spring.Messaging.Support.MessageQueueFactoryObject, Spring.Messaging'>
<property name='Path' value='.\Private$\testtxretryqueue'/>
<property name='MessageReadPropertyFilterSetAll' value='true'/>
<property name='MessageReadPropertyFilterSetAll' value='true'/>
<property name='ProductTemplate'>
<object>
<property name='Label' value='MyTxRetryLabel'/>
@@ -57,10 +57,10 @@
</object>
<object id="transactionalMessageListenerContainer" type="Spring.Messaging.Listener.DistributedTxMessageListenerContainer, Spring.Messaging">
<property name="DefaultMessageQueueObjectName" value="msmqtxqueue"/>
<property name="MessageQueueObjectName" value="msmqtxqueue"/>
<property name="PlatformTransactionManager" ref="txScopeTransactionManager"/>
<property name="MaxConcurrentListeners" value="1"/>
<property name="ListenerTimeLimitInMillis" value="20000"/>
<property name="ListenerTimeLimit" value="20000"/>
<property name="MessageListener" ref="messageListenerAdapter"/>
<property name="DistributedTransactionExceptionHandler" ref="distributedTransactionExceptionHandler"/>
<property name="AutoStartup" value="false"/>

View File

@@ -43,9 +43,12 @@ namespace Spring.Messaging.Listener
private SimpleHandler listener;
private SimpleExceptionHandler exceptionHandler;
[Test]
public void Test()
[SetUp]
public override void SetUp()
{
MessageQueueUtils.RecreateMessageQueue(@".\Private$\testqueue", false);
MessageQueueUtils.RecreateMessageQueue(@".\Private$\testresponsequeue", false);
base.SetUp();
}
public SimpleExceptionHandler ExceptionHandler
@@ -68,6 +71,10 @@ namespace Spring.Messaging.Listener
[Test]
public void SendAndAsyncReceiveWithExceptionHandling()
{
//Reset the state so that running all tests together will succeed.
exceptionHandler.MessageCount = 0;
MessageQueueTemplate q = applicationContext["testQueueTemplate"] as MessageQueueTemplate;
Assert.IsNotNull(q);
q.ConvertAndSend("Goodbye World 1");
@@ -95,8 +102,9 @@ namespace Spring.Messaging.Listener
q.ConvertAndSend("Hello World 3");
q.ConvertAndSend("Hello World 4");
q.ConvertAndSend("Hello World 5");
//Reset the state so that running all tests together will succeed.
exceptionHandler.MessageCount = 0;
Assert.AreEqual(0, listener.MessageCount);

View File

@@ -34,7 +34,7 @@
</object>
<object id='testremotequeue' type='Spring.Messaging.Support.MessageQueueFactoryObject, Spring.Messaging'>
<property name='Path' value='FormatName:Direct=OS:MARKT60\Private$\testqueue'/>
<property name='Path' value='FormatName:Direct=OS:MARK6500\Private$\testqueue'/>
<property name='RemoteQueue' value="true"/>
</object>

View File

@@ -41,6 +41,16 @@ namespace Spring.Messaging.Listener
private TransactionalMessageListenerContainer transactionalMessageListenerContainer;
private SimpleHandler listener;
[SetUp]
public override void SetUp()
{
MessageQueueUtils.RecreateMessageQueue(@".\Private$\testtxqueue", true);
MessageQueueUtils.RecreateMessageQueue(@".\Private$\testtxretryqueue", true);
MessageQueueUtils.RecreateMessageQueue(@".\Private$\testtxresponsequeue", true);
base.SetUp();
}
public TransactionalMessageListenerContainer TransactionalMessageListenerContainer
{
set { transactionalMessageListenerContainer = value; }
@@ -52,7 +62,7 @@ namespace Spring.Messaging.Listener
set { listener = value; }
}
[Test, ExpectedException(typeof(ArgumentException), ExpectedMessage = "Property 'DefaultMessageQueue' is required")]
[Test, ExpectedException(typeof(ArgumentException), ExpectedMessage = "Property 'MessageQueueObjectName' is required")]
public void EnsureMessageQueuePropertyIsSet()
{
TransactionalMessageListenerContainer container = new TransactionalMessageListenerContainer();

View File

@@ -89,6 +89,7 @@
<Compile Include="MessagingCompilerOptionsTests.cs" />
<Compile Include="MessagingExceptionTests.cs" />
<Compile Include="Messaging\Core\MessageQueueMetadataCacheTests.cs" />
<Compile Include="Messaging\Core\MessageQueueUtils.cs" />
<Compile Include="Messaging\Core\ThreadingTests.cs" />
<Compile Include="Messaging\Listener\Adapter\MessageListenerAdapterTests.cs" />
<Compile Include="Messaging\Listener\DistributedTxMessageListenerContainerTests.cs" />