From 8807ea58799a4b68baba064494d095357c5bb7a0 Mon Sep 17 00:00:00 2001 From: markpollack Date: Thu, 25 Mar 2010 16:31:39 +0000 Subject: [PATCH] Revive concurrency tests. --- .../Spring/Objects/Factory/concurrent.xml | 6 +- .../Factory/ConcurrentObjectFactoryTests.cs | 106 ++++++++++++++++++ .../Config/EnvironmentVariableSourceTests.cs | 9 ++ .../DefaultListableObjectFactoryPerfTests.cs | 9 +- .../Spring.Core.Tests.2008.csproj | 1 + 5 files changed, 127 insertions(+), 4 deletions(-) create mode 100644 test/Spring/Spring.Core.Tests/Objects/Factory/ConcurrentObjectFactoryTests.cs diff --git a/test/Spring/Spring.Core.Tests/Data/Spring/Objects/Factory/concurrent.xml b/test/Spring/Spring.Core.Tests/Data/Spring/Objects/Factory/concurrent.xml index 48863bbf..9462abc8 100644 --- a/test/Spring/Spring.Core.Tests/Data/Spring/Objects/Factory/concurrent.xml +++ b/test/Spring/Spring.Core.Tests/Data/Spring/Objects/Factory/concurrent.xml @@ -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"> - 2004/08/08 2000/02/02 diff --git a/test/Spring/Spring.Core.Tests/Objects/Factory/ConcurrentObjectFactoryTests.cs b/test/Spring/Spring.Core.Tests/Objects/Factory/ConcurrentObjectFactoryTests.cs new file mode 100644 index 00000000..69024be3 --- /dev/null +++ b/test/Spring/Spring.Core.Tests/Objects/Factory/ConcurrentObjectFactoryTests.cs @@ -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 + } + } +} \ No newline at end of file diff --git a/test/Spring/Spring.Core.Tests/Objects/Factory/Config/EnvironmentVariableSourceTests.cs b/test/Spring/Spring.Core.Tests/Objects/Factory/Config/EnvironmentVariableSourceTests.cs index da85ee45..1504abc1 100644 --- a/test/Spring/Spring.Core.Tests/Objects/Factory/Config/EnvironmentVariableSourceTests.cs +++ b/test/Spring/Spring.Core.Tests/Objects/Factory/Config/EnvironmentVariableSourceTests.cs @@ -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); + } } } diff --git a/test/Spring/Spring.Core.Tests/Objects/Factory/DefaultListableObjectFactoryPerfTests.cs b/test/Spring/Spring.Core.Tests/Objects/Factory/DefaultListableObjectFactoryPerfTests.cs index 895dd1fa..a2b4d210 100644 --- a/test/Spring/Spring.Core.Tests/Objects/Factory/DefaultListableObjectFactoryPerfTests.cs +++ b/test/Spring/Spring.Core.Tests/Objects/Factory/DefaultListableObjectFactoryPerfTests.cs @@ -32,7 +32,8 @@ using Spring.Threading; namespace Spring.Objects.Factory { /// - /// 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. /// /// Mark Pollack [TestFixture] @@ -106,6 +107,12 @@ namespace Spring.Objects.Factory iterations / duration)); } + [Test] + public void ConcurrencyTest() + { + AsyncTestTask t1 = new BeanFactoryTask(100).Start(); + t1.AssertNoException(); + } } diff --git a/test/Spring/Spring.Core.Tests/Spring.Core.Tests.2008.csproj b/test/Spring/Spring.Core.Tests/Spring.Core.Tests.2008.csproj index 6e95001e..0969d3c2 100644 --- a/test/Spring/Spring.Core.Tests/Spring.Core.Tests.2008.csproj +++ b/test/Spring/Spring.Core.Tests/Spring.Core.Tests.2008.csproj @@ -319,6 +319,7 @@ +