You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucenenet.apache.org by ar...@apache.org on 2009/11/14 16:52:44 UTC
svn commit: r836197 -
/incubator/lucene.net/trunk/C#/src/Test/Util/TestStringIntern.cs
Author: aroush
Date: Sat Nov 14 15:52:44 2009
New Revision: 836197
URL: http://svn.apache.org/viewvc?rev=836197&view=rev
Log:
Fixed NUnit test-cases for: TestStringIntern
Modified:
incubator/lucene.net/trunk/C#/src/Test/Util/TestStringIntern.cs
Modified: incubator/lucene.net/trunk/C#/src/Test/Util/TestStringIntern.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Test/Util/TestStringIntern.cs?rev=836197&r1=836196&r2=836197&view=diff
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Test/Util/TestStringIntern.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Test/Util/TestStringIntern.cs Sat Nov 14 15:52:44 2009
@@ -16,6 +16,7 @@
*/
using System;
+using System.Threading;
using NUnit.Framework;
@@ -29,18 +30,15 @@
{
InitBlock();
}
- private class AnonymousClassThread:SupportClass.ThreadClass
+ private class TestRun
{
- public AnonymousClassThread(System.Int32 seed, int iter, bool newStrings, TestStringIntern enclosingInstance)
- {
- InitBlock(seed, iter, newStrings, enclosingInstance);
- }
- private void InitBlock(System.Int32 seed, int iter, bool newStrings, TestStringIntern enclosingInstance)
+ public TestRun(Int32 seed, int iter, bool newStrings, TestStringIntern enclosingInstance)
{
this.seed = seed;
this.iter = iter;
this.newStrings = newStrings;
this.enclosingInstance = enclosingInstance;
+ this.Reset = new ManualResetEvent(false);
}
private System.Int32 seed;
private int iter;
@@ -54,7 +52,10 @@
}
}
- override public void Run()
+
+ public ManualResetEvent Reset;
+
+ public void Run(System.Object state)
{
System.Random rand = new Random(seed);
System.String[] myInterned = new System.String[Enclosing_Instance.testStrings.Length];
@@ -69,19 +70,20 @@
System.String otherInterned = Enclosing_Instance.internedStrings[idx];
// test against other threads
- if (otherInterned != null && (System.Object) otherInterned != (System.Object) interned)
+ if (otherInterned != null && otherInterned != interned)
{
Assert.Fail(); // TestCase.fail();
}
Enclosing_Instance.internedStrings[idx] = interned;
// test against local copy
- if (prevInterned != null && (System.Object) prevInterned != (System.Object) interned)
+ if (prevInterned != null && prevInterned != interned)
{
Assert.Fail(); // TestCase.fail();
}
myInterned[idx] = interned;
}
+ this.Reset.Set();
}
}
private void InitBlock()
@@ -125,19 +127,17 @@
// try native intern
// StringHelper.interner = new StringInterner();
- SupportClass.ThreadClass[] threads = new SupportClass.ThreadClass[nThreads];
+ TestRun[] threads = new TestRun[nThreads];
+ ManualResetEvent[] resets = new ManualResetEvent[nThreads];
for (int i = 0; i < nThreads; i++)
{
int seed = i;
- threads[i] = new AnonymousClassThread(seed, iter, newStrings, this);
-
- threads[i].Start();
- }
-
- for (int i = 0; i < nThreads; i++)
- {
- threads[i].Join();
+ threads[i] = new TestRun(seed, iter, newStrings, this);
+ resets[i] = threads[i].Reset;
+ ThreadPool.QueueUserWorkItem(new WaitCallback(threads[i].Run));
}
+
+ WaitHandle.WaitAll(resets);
}
}
}
\ No newline at end of file