Skip to content
Permalink
Browse files
Conditionally compile the test since .NET CF does not support the thr…
…eading model used in the test.

Refactor the multiple tests down to a single test that takes variable parameters.
Add the test to the Visual Studio project file.
  • Loading branch information
Jim Gomes committed Aug 1, 2012
1 parent 4f88b4f commit e77632963e452f75c64838117f2c8042b979ae4d
Showing 2 changed files with 31 additions and 95 deletions.
@@ -18,22 +18,19 @@
/*
* The main goal of this test list is to make sure that a producer and a consumer with
* separate connections can communicate properly and consitently despite a waiting time
* between messages TestStability500WithSleep would be the important test, as a delay of
* between messages TestStability with 500 sleep would be the important test, as a delay of
* 30s is executed at each 100 (100, 200, 300, ...).
*/

using System;
using System.Threading;
using Apache.NMS;
using Apache.NMS.Util;
using Apache.NMS.Test;
using Apache.NMS.Stomp;
using NUnit.Framework;
using System;

namespace Apache.NMS.Stomp.Test
{
[TestFixture]
public class NMSTester : NMSTestSupport
public class NMSTestStability : NMSTestSupport
{
// TODO set proper configuration parameters
private const string destination = "test";
@@ -114,41 +111,35 @@ public void Dispose()
producerThread = null;
}

[Test]
public void TestStability5Continuous()
{
numberOfMessages = 5;

consumerThread = new Thread(new ThreadStart(NMSTester.ConsumerThread));
consumerThread.Start();

producerThread = new Thread(new ThreadStart(NMSTester.ProducerThreadContinuous));
producerThread.Start();

Thread.Sleep(100);

Assert.IsTrue(consumerThread.IsAlive && producerThread.IsAlive);

while (consumerThread.IsAlive && producerThread.IsAlive)
{
Thread.Sleep(100);
}

Assert.AreEqual("", possibleConsumerException);
Assert.AreEqual("", possibleProducerException);
Assert.AreEqual(numberOfMessages, producerMessageCounter);
Assert.AreEqual(numberOfMessages, consumerMessageCounter);
}
#if !NETCF
public enum ProducerTestType
{
CONTINUOUS,
WITHSLEEP
}

[Test]
public void TestStability50Continuous()
public void TestStability(
[Values(5, 50, 500)]
int testMessages,
[Values(ProducerTestType.CONTINUOUS, ProducerTestType.WITHSLEEP)]
ProducerTestType producerType)
{
numberOfMessages = 50;
//At 100,200,300, ... a delay of 30 seconds is executed in the producer to cause an unexpected disconnect, due to a malformed ACK?
numberOfMessages = testMessages;

consumerThread = new Thread(new ThreadStart(NMSTester.ConsumerThread));
consumerThread = new Thread(NMSTestStability.ConsumerThread);
consumerThread.Start();

producerThread = new Thread(new ThreadStart(NMSTester.ProducerThreadContinuous));
if(ProducerTestType.CONTINUOUS == producerType)
{
producerThread = new Thread(NMSTestStability.ProducerThreadContinuous);
}
else
{
producerThread = new Thread(NMSTestStability.ProducerThreadWithSleep);
}

producerThread.Start();

Thread.Sleep(100);
@@ -160,68 +151,12 @@ public void TestStability50Continuous()
Thread.Sleep(100);
}

Assert.AreEqual("", possibleConsumerException);
Assert.AreEqual("", possibleProducerException);
Assert.IsEmpty(possibleConsumerException);
Assert.IsEmpty(possibleProducerException);
Assert.AreEqual(numberOfMessages, producerMessageCounter);
Assert.AreEqual(numberOfMessages, consumerMessageCounter);
}

[Test]
public void TestStability500Continuous()
{
numberOfMessages = 500; //At 100,200,300, ... a delay of 30 seconds is executed in the producer to cause an unexpected disconnect, due to a malformed ACK?

consumerThread = new Thread(new ThreadStart(NMSTester.ConsumerThread));
consumerThread.Start();

producerThread = new Thread(new ThreadStart(NMSTester.ProducerThreadContinuous));
producerThread.Start();

Thread.Sleep(100);

Assert.IsTrue(consumerThread.IsAlive && producerThread.IsAlive);

while (consumerThread.IsAlive && producerThread.IsAlive)
{
Thread.Sleep(100);
}

Assert.AreEqual("", possibleConsumerException);
Assert.AreEqual("", possibleProducerException);
Assert.AreEqual(numberOfMessages, producerMessageCounter);
Assert.AreEqual(numberOfMessages, consumerMessageCounter);
}

[Test]
public void TestStability500WithSleep()
{
numberOfMessages = 500; //At 100,200,300, ... a delay of 30 seconds is executed in the producer to cause an unexpected disconnect, due to a malformed ACK?

consumerThread = new Thread(new ThreadStart(NMSTester.ConsumerThread));
consumerThread.Start();

producerThread = new Thread(new ThreadStart(NMSTester.ProducerThreadWithSleep));
producerThread.Start();

Thread.Sleep(100);

Assert.IsTrue(consumerThread.IsAlive && producerThread.IsAlive);

while (consumerThread.IsAlive && producerThread.IsAlive)
{
Thread.Sleep(100);
}

Assert.AreEqual("", possibleConsumerException);
Assert.AreEqual("", possibleProducerException);
Assert.AreEqual(numberOfMessages, producerMessageCounter);
Assert.AreEqual(numberOfMessages, consumerMessageCounter);
}

public static void Main(string[] args)
{

}
#endif

#region Consumer
private static void ConsumerThread()
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="3.5">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
@@ -99,6 +99,7 @@
<VisualStudio />
</ProjectExtensions>
<ItemGroup>
<Compile Include="src\test\csharp\AMQNET383Test.cs" />
<Compile Include="src\test\csharp\StompHelperTest.cs" />
<Compile Include="src\test\csharp\StompRedeliveryPolicyTest.cs" />
<Compile Include="src\test\csharp\Threads\CompositeTaskRunnerTest.cs" />

0 comments on commit e776329

Please sign in to comment.