Revive concurrency tests.

This commit is contained in:
markpollack
2010-03-25 16:31:39 +00:00
parent 56a36ea7ba
commit 8807ea5879
5 changed files with 127 additions and 4 deletions

View File

@@ -4,15 +4,15 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.net http://www.springframework.net/xsd/spring-objects.xsd">
<object id="object1"
type="Spring.Objects.Factory.ConcurrentObjectFactoryTests$ConcurrentObject, Spring.Core.Tests"
<object id="object1"
type="Spring.Objects.Factory.ConcurrentObjectFactoryTests+ConcurrentObject, Spring.Core.Tests"
singleton="false">
<property name="date">
<value>2004/08/08</value>
</property>
</object>
<object id="object2"
type="Spring.Objects.Factory.ConcurrentObjectFactoryTests$ConcurrentObject, Spring.Core.Tests"
type="Spring.Objects.Factory.ConcurrentObjectFactoryTests+ConcurrentObject, Spring.Core.Tests"
singleton="false">
<property name="date">
<value>2000/02/02</value>

View File

@@ -0,0 +1,106 @@
#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;
using NUnit.Framework;
using Spring.Core.IO;
using Spring.Objects.Factory.Xml;
using Spring.Threading;
namespace Spring.Objects.Factory
{
[TestFixture]
public class ConcurrentObjectFactoryTests
{
private IObjectFactory factory;
private DateTime date1 = DateTime.Parse("2004/08/08");
private DateTime date2 = DateTime.Parse("2000/02/02");
[SetUp]
public void SetUp()
{
IResource resource = new ReadOnlyXmlTestResource("concurrent.xml", GetType());
factory = new XmlObjectFactory(resource);
}
[Test]
public void SingleThread()
{
for (int i = 0; i < 100; i++)
{
PerformTest();
}
}
[Test]
public void Concurrent()
{
AsyncTestTask t1 = new ObjectFactoryTask(500, this).Start();
t1.AssertNoException();
}
private void PerformTest()
{
ConcurrentObject c1 = (ConcurrentObject) factory.GetObject("object1");
ConcurrentObject c2 = (ConcurrentObject) factory.GetObject("object2");
Assert.AreEqual(date1, c1.Date);
Assert.AreEqual(date2, c2.Date);
}
public class ConcurrentObject
{
private DateTime date;
public DateTime Date
{
get { return date; }
set { date = value; }
}
}
public class ObjectFactoryTask : AsyncTestTask
{
private ConcurrentObjectFactoryTests test;
public ObjectFactoryTask(int iterations, ConcurrentObjectFactoryTests test)
: base(iterations)
{
this.test = test;
}
#region Overrides of AsyncTestTask
public override void DoExecute()
{
test.PerformTest();
}
#endregion
}
}
}

View File

@@ -48,5 +48,14 @@ namespace Spring.Objects.Factory.Config
// non-existant variable
Assert.IsNull(vs.ResolveVariable("dummy"));
}
[Test]
public void EnviornmentStuff()
{
long size = Environment.WorkingSet;
int procCount = Environment.ProcessorCount;
Console.WriteLine("working set : " + size);
Console.WriteLine("Processor count : " + procCount);
}
}
}

View File

@@ -32,7 +32,8 @@ using Spring.Threading;
namespace Spring.Objects.Factory
{
/// <summary>
/// This class contains tests related to performance of the object factory implementation. Ignored by default.
/// This class contains tests related to performance of the object factory implementation and some concurrency test.
/// The performance test are ignored by default.
/// </summary>
/// <author>Mark Pollack</author>
[TestFixture]
@@ -106,6 +107,12 @@ namespace Spring.Objects.Factory
iterations / duration));
}
[Test]
public void ConcurrencyTest()
{
AsyncTestTask t1 = new BeanFactoryTask(100).Start();
t1.AssertNoException();
}
}

View File

@@ -319,6 +319,7 @@
<Compile Include="Objects\Factory\Attributes\MyRequiredAttribute.cs" />
<Compile Include="Objects\Factory\Attributes\RequiredAttributeObjectPostProcessorTests.cs" />
<Compile Include="Objects\Factory\Attributes\RequiredTestObject.cs" />
<Compile Include="Objects\Factory\ConcurrentObjectFactoryTests.cs" />
<Compile Include="Objects\Factory\Config\CommandLineArgsVariableSourceTests.cs" />
<Compile Include="Objects\Factory\Config\ConfigSectionVariableSourceTests.cs" />
<Compile Include="Objects\Factory\Config\ConnectionStringsVariableSourceTests.cs" />