lucenenet-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aro...@apache.org
Subject svn commit: r677059 [19/19] - in /incubator/lucene.net/trunk/C#/src: ./ Demo/DeleteFiles/ Demo/DemoLib/ Demo/IndexFiles/ Demo/IndexHtml/ Demo/SearchFiles/ Lucene.Net/ Lucene.Net/Analysis/ Lucene.Net/Index/ Lucene.Net/Search/ Lucene.Net/Search/Function/...
Date Tue, 15 Jul 2008 21:44:10 GMT
Modified: incubator/lucene.net/trunk/C#/src/Test/TestDemo.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Test/TestDemo.cs?rev=677059&r1=677058&r2=677059&view=diff
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Test/TestDemo.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Test/TestDemo.cs Tue Jul 15 14:44:04 2008
@@ -19,18 +19,19 @@
 
 using NUnit.Framework;
 
-using Analyzer = Lucene.Net.Analysis.Analyzer;
-using StandardAnalyzer = Lucene.Net.Analysis.Standard.StandardAnalyzer;
 using Document = Lucene.Net.Documents.Document;
 using Field = Lucene.Net.Documents.Field;
 using IndexWriter = Lucene.Net.Index.IndexWriter;
 using ParseException = Lucene.Net.QueryParsers.ParseException;
 using QueryParser = Lucene.Net.QueryParsers.QueryParser;
+using Directory = Lucene.Net.Store.Directory;
+using RAMDirectory = Lucene.Net.Store.RAMDirectory;
+using Analyzer = Lucene.Net.Analysis.Analyzer;
+using StandardAnalyzer = Lucene.Net.Analysis.Standard.StandardAnalyzer;
 using Hits = Lucene.Net.Search.Hits;
 using IndexSearcher = Lucene.Net.Search.IndexSearcher;
 using Query = Lucene.Net.Search.Query;
-using Directory = Lucene.Net.Store.Directory;
-using RAMDirectory = Lucene.Net.Store.RAMDirectory;
+using LuceneTestCase = Lucene.Net.Util.LuceneTestCase;
 
 namespace Lucene.Net
 {
@@ -41,8 +42,9 @@
 	/// <author>  Daniel Naber
 	/// </author>
 	[TestFixture]
-    public class TestDemo
+	public class TestDemo : LuceneTestCase
 	{
+		
 		[Test]
 		public virtual void  TestDemo_Renamed_Method()
 		{
@@ -57,7 +59,7 @@
 			//Directory directory = FSDirectory.getDirectory("/tmp/testindex", true);
 			IndexWriter iwriter = new IndexWriter(directory, analyzer, true);
 			iwriter.SetMaxFieldLength(25000);
-			Lucene.Net.Documents.Document doc = new Lucene.Net.Documents.Document();
+			Document doc = new Document();
 			System.String text = "This is the text to be indexed.";
 			doc.Add(new Field("fieldname", text, Field.Store.YES, Field.Index.TOKENIZED));
 			iwriter.AddDocument(doc);
@@ -66,14 +68,14 @@
 			// Now search the index:
 			IndexSearcher isearcher = new IndexSearcher(directory);
 			// Parse a simple query that searches for "text":
-            Lucene.Net.QueryParsers.QueryParser parser = new Lucene.Net.QueryParsers.QueryParser("fieldname",
analyzer);
-            Lucene.Net.Search.Query query = parser.Parse("text");
-            Hits hits = isearcher.Search(query);
+			Lucene.Net.QueryParsers.QueryParser parser = new Lucene.Net.QueryParsers.QueryParser("fieldname",
analyzer);
+			Query query = parser.Parse("text");
+			Hits hits = isearcher.Search(query);
 			Assert.AreEqual(1, hits.Length());
 			// Iterate through the results:
 			for (int i = 0; i < hits.Length(); i++)
 			{
-				Lucene.Net.Documents.Document hitDoc = hits.Doc(i);
+				Document hitDoc = hits.Doc(i);
 				Assert.AreEqual("This is the text to be indexed.", hitDoc.Get("fieldname"));
 			}
 			isearcher.Close();

Modified: incubator/lucene.net/trunk/C#/src/Test/TestHitIterator.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Test/TestHitIterator.cs?rev=677059&r1=677058&r2=677059&view=diff
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Test/TestHitIterator.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Test/TestHitIterator.cs Tue Jul 15 14:44:04 2008
@@ -19,17 +19,18 @@
 
 using NUnit.Framework;
 
-using RAMDirectory = Lucene.Net.Store.RAMDirectory;
+using Document = Lucene.Net.Documents.Document;
+using Field = Lucene.Net.Documents.Field;
 using IndexWriter = Lucene.Net.Index.IndexWriter;
 using Term = Lucene.Net.Index.Term;
+using RAMDirectory = Lucene.Net.Store.RAMDirectory;
 using WhitespaceAnalyzer = Lucene.Net.Analysis.WhitespaceAnalyzer;
-using Document = Lucene.Net.Documents.Document;
-using Field = Lucene.Net.Documents.Field;
-using IndexSearcher = Lucene.Net.Search.IndexSearcher;
-using TermQuery = Lucene.Net.Search.TermQuery;
-using Hits = Lucene.Net.Search.Hits;
 using Hit = Lucene.Net.Search.Hit;
 using HitIterator = Lucene.Net.Search.HitIterator;
+using Hits = Lucene.Net.Search.Hits;
+using IndexSearcher = Lucene.Net.Search.IndexSearcher;
+using TermQuery = Lucene.Net.Search.TermQuery;
+using LuceneTestCase = Lucene.Net.Util.LuceneTestCase;
 
 namespace Lucene.Net
 {
@@ -38,9 +39,9 @@
 	/// to test HitIterator and Hit package protection.
 	/// </summary>
 	[TestFixture]
-    public class TestHitIterator
+	public class TestHitIterator : LuceneTestCase
 	{
-        [Test]
+		[Test]
 		public virtual void  TestIterator()
 		{
 			RAMDirectory directory = new RAMDirectory();
@@ -76,7 +77,7 @@
 			{
 				System.Object generatedAux = iterator.Current;
 			}
-			catch (System.ArgumentOutOfRangeException e)
+			catch (System.ArgumentOutOfRangeException)
 			{
 				Assert.IsTrue(true);
 				caughtException = true;

Modified: incubator/lucene.net/trunk/C#/src/Test/TestSearch.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Test/TestSearch.cs?rev=677059&r1=677058&r2=677059&view=diff
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Test/TestSearch.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Test/TestSearch.cs Tue Jul 15 14:44:04 2008
@@ -19,24 +19,25 @@
 
 using NUnit.Framework;
 
-using Lucene.Net.Store;
 using Lucene.Net.Documents;
-using Lucene.Net.Analysis;
 using Lucene.Net.Index;
+using Lucene.Net.QueryParsers;
+using Lucene.Net.Store;
+using Lucene.Net.Analysis;
 using Lucene.Net.Search;
 using Searchable = Lucene.Net.Search.Searchable;
-using Lucene.Net.QueryParsers;
+using LuceneTestCase = Lucene.Net.Util.LuceneTestCase;
 
 namespace Lucene.Net
 {
 	
-	/// <summary>JUnit adaptation of an older test case SearchTest.</summary>
-	/// <author>  dmitrys@earthlink.net
-	/// </author>
-	/// <version>  $Id: TestSearch.java 150494 2004-09-06 22:29:22Z dnaber $
+	/// <summary>JUnit adaptation of an older test case SearchTest.
+	/// 
+	/// </summary>
+	/// <version>  $Id: TestSearch.java 583534 2007-10-10 16:46:35Z mikemccand $
 	/// </version>
 	[TestFixture]
-    public class TestSearch
+	public class TestSearch : LuceneTestCase
 	{
 		
 		/// <summary>Main for running test case by itself. </summary>
@@ -56,10 +57,10 @@
 		/// single-file formats, even if the results are wrong.
 		/// </summary>
 		[Test]
-        public virtual void  TestSearch_Renamed_Method()
+		public virtual void  TestSearch_Renamed_Method()
 		{
-            System.IO.MemoryStream sw = new System.IO.MemoryStream();
-            System.IO.StreamWriter pw = new System.IO.StreamWriter(sw);
+			System.IO.MemoryStream sw = new System.IO.MemoryStream();
+			System.IO.StreamWriter pw = new System.IO.StreamWriter(sw);
 			DoTestSearch(pw, false);
 			pw.Close();
 			sw.Close();
@@ -125,8 +126,8 @@
 		
 		internal static long Time(int year, int month, int day)
 		{
-            System.DateTime calendar = new System.DateTime(year, month, day, 0, 0, 0, 0,
new System.Globalization.GregorianCalendar());
-            return calendar.Ticks;
+			System.DateTime calendar = new System.DateTime(year, month, day, 0, 0, 0, 0, new System.Globalization.GregorianCalendar());
+			return calendar.Ticks;
 		}
 	}
 }
\ No newline at end of file

Modified: incubator/lucene.net/trunk/C#/src/Test/TestSearchForDuplicates.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Test/TestSearchForDuplicates.cs?rev=677059&r1=677058&r2=677059&view=diff
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Test/TestSearchForDuplicates.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Test/TestSearchForDuplicates.cs Tue Jul 15 14:44:04
2008
@@ -19,25 +19,26 @@
 
 using NUnit.Framework;
 
-using Lucene.Net.Store;
 using Lucene.Net.Documents;
-using Lucene.Net.Analysis;
 using Lucene.Net.Index;
+using Lucene.Net.QueryParsers;
+using Lucene.Net.Store;
+using Lucene.Net.Analysis;
 using Lucene.Net.Search;
 using Searchable = Lucene.Net.Search.Searchable;
-using Lucene.Net.QueryParsers;
+using LuceneTestCase = Lucene.Net.Util.LuceneTestCase;
 
 namespace Lucene.Net
 {
 	
 	
-	/// <summary>JUnit adaptation of an older test case DocTest.</summary>
-	/// <author>  dmitrys@earthlink.net
-	/// </author>
-	/// <version>  $Id: TestSearchForDuplicates.java 150494 2004-09-06 22:29:22Z dnaber
$
+	/// <summary>JUnit adaptation of an older test case DocTest.
+	/// 
+	/// </summary>
+	/// <version>  $Id: TestSearchForDuplicates.java 583534 2007-10-10 16:46:35Z mikemccand
$
 	/// </version>
 	[TestFixture]
-    public class TestSearchForDuplicates
+	public class TestSearchForDuplicates : LuceneTestCase
 	{
 		
 		/// <summary>Main for running test case by itself. </summary>
@@ -65,25 +66,25 @@
 		/// validate this output and make any changes to the checkHits method.
 		/// </summary>
 		[Test]
-        public virtual void  TestRun()
+		public virtual void  TestRun()
 		{
-            System.IO.MemoryStream sw = new System.IO.MemoryStream();
-            System.IO.StreamWriter pw = new System.IO.StreamWriter(sw);
-            DoTest(pw, false);
-            pw.Close();
-            sw.Close();
-            System.String multiFileOutput = System.Text.ASCIIEncoding.ASCII.GetString(sw.ToArray());
-            //System.out.println(multiFileOutput);
-			
-            sw = new System.IO.MemoryStream();
-            pw = new System.IO.StreamWriter(sw);
-            DoTest(pw, true);
-            pw.Close();
-            sw.Close();
-            System.String singleFileOutput = System.Text.ASCIIEncoding.ASCII.GetString(sw.ToArray());
+			System.IO.MemoryStream sw = new System.IO.MemoryStream();
+			System.IO.StreamWriter pw = new System.IO.StreamWriter(sw);
+			DoTest(pw, false);
+			pw.Close();
+			sw.Close();
+			System.String multiFileOutput = System.Text.ASCIIEncoding.ASCII.GetString(sw.ToArray());
+			//System.out.println(multiFileOutput);
+			
+			sw = new System.IO.MemoryStream();
+			pw = new System.IO.StreamWriter(sw);
+			DoTest(pw, true);
+			pw.Close();
+			sw.Close();
+			System.String singleFileOutput = System.Text.ASCIIEncoding.ASCII.GetString(sw.ToArray());
 			
-            Assert.AreEqual(multiFileOutput, singleFileOutput);
-        }
+			Assert.AreEqual(multiFileOutput, singleFileOutput);
+		}
 		
 		
 		private void  DoTest(System.IO.StreamWriter out_Renamed, bool useCompoundFiles)

Added: incubator/lucene.net/trunk/C#/src/Test/TestSnapshotDeletionPolicy.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Test/TestSnapshotDeletionPolicy.cs?rev=677059&view=auto
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Test/TestSnapshotDeletionPolicy.cs (added)
+++ incubator/lucene.net/trunk/C#/src/Test/TestSnapshotDeletionPolicy.cs Tue Jul 15 14:44:04
2008
@@ -0,0 +1,254 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.
+ */
+
+using System;
+
+using NUnit.Framework;
+
+using Document = Lucene.Net.Documents.Document;
+using Field = Lucene.Net.Documents.Field;
+using IndexCommitPoint = Lucene.Net.Index.IndexCommitPoint;
+using IndexWriter = Lucene.Net.Index.IndexWriter;
+using KeepOnlyLastCommitDeletionPolicy = Lucene.Net.Index.KeepOnlyLastCommitDeletionPolicy;
+using SnapshotDeletionPolicy = Lucene.Net.Index.SnapshotDeletionPolicy;
+using Directory = Lucene.Net.Store.Directory;
+using FSDirectory = Lucene.Net.Store.FSDirectory;
+using IndexInput = Lucene.Net.Store.IndexInput;
+using MockRAMDirectory = Lucene.Net.Store.MockRAMDirectory;
+using LuceneTestCase = Lucene.Net.Util.LuceneTestCase;
+using _TestUtil = Lucene.Net.Util._TestUtil;
+using StandardAnalyzer = Lucene.Net.Analysis.Standard.StandardAnalyzer;
+using TestIndexWriter = Lucene.Net.Index.TestIndexWriter;
+
+namespace Lucene.Net
+{
+	
+	//
+	// This was developed for Lucene In Action,
+	// http://lucenebook.com
+	//
+	
+	[TestFixture]
+	public class TestSnapshotDeletionPolicy : LuceneTestCase
+	{
+		private class AnonymousClassThread : SupportClass.ThreadClass
+		{
+			public AnonymousClassThread(long stopTime, Lucene.Net.Index.IndexWriter writer, TestSnapshotDeletionPolicy
enclosingInstance)
+			{
+				InitBlock(stopTime, writer, enclosingInstance);
+			}
+			private void  InitBlock(long stopTime, Lucene.Net.Index.IndexWriter writer, TestSnapshotDeletionPolicy
enclosingInstance)
+			{
+				this.stopTime = stopTime;
+				this.writer = writer;
+				this.enclosingInstance = enclosingInstance;
+			}
+			private long stopTime;
+			private Lucene.Net.Index.IndexWriter writer;
+			private TestSnapshotDeletionPolicy enclosingInstance;
+			public TestSnapshotDeletionPolicy Enclosing_Instance
+			{
+				get
+				{
+					return enclosingInstance;
+				}
+				
+			}
+			override public void  Run()
+			{
+				Document doc = new Document();
+				doc.Add(new Field("content", "aaa", Field.Store.YES, Field.Index.TOKENIZED, Field.TermVector.WITH_POSITIONS_OFFSETS));
+				while ((System.DateTime.Now.Ticks - 621355968000000000) / 10000 < stopTime)
+				{
+					for (int i = 0; i < 27; i++)
+					{
+						try
+						{
+							writer.AddDocument(doc);
+						}
+						catch (System.IO.IOException cie)
+						{
+							System.SystemException re = new System.SystemException("addDocument failed", cie);
+							throw re;
+						}
+					}
+					try
+					{
+						System.Threading.Thread.Sleep(new System.TimeSpan((System.Int64) 10000 * 1));
+					}
+					catch (System.Threading.ThreadInterruptedException)
+					{
+						SupportClass.ThreadClass.Current().Interrupt();
+					}
+				}
+			}
+		}
+		public const System.String INDEX_PATH = "test.snapshots";
+		
+		[Test]
+		public virtual void  TestSnapshotDeletionPolicy_Renamed_Method()
+		{
+			System.IO.FileInfo dir = new System.IO.FileInfo(System.IO.Path.Combine(SupportClass.AppSettings.Get("tempDir",
""), INDEX_PATH));
+			try
+			{
+				Directory fsDir = FSDirectory.GetDirectory(dir);
+				RunTest(fsDir);
+				fsDir.Close();
+			}
+			finally
+			{
+				_TestUtil.RmDir(dir);
+			}
+			
+			MockRAMDirectory dir2 = new MockRAMDirectory();
+			RunTest(dir2);
+		}
+		
+		private void  RunTest(Directory dir)
+		{
+			// Run for ~7 seconds
+			long stopTime = (System.DateTime.Now.Ticks - 621355968000000000) / 10000 + 7000;
+			
+			SnapshotDeletionPolicy dp = new SnapshotDeletionPolicy(new KeepOnlyLastCommitDeletionPolicy());
+			IndexWriter writer = new IndexWriter(dir, true, new StandardAnalyzer(), dp);
+			
+			// Force frequent commits
+			writer.SetMaxBufferedDocs(2);
+			
+			SupportClass.ThreadClass t = new AnonymousClassThread(stopTime, writer, this);
+			
+			t.Start();
+			
+			// While the above indexing thread is running, take many
+			// backups:
+			while ((System.DateTime.Now.Ticks - 621355968000000000) / 10000 < stopTime)
+			{
+				BackupIndex(dir, dp);
+				try
+				{
+					System.Threading.Thread.Sleep(new System.TimeSpan((System.Int64) 10000 * 20));
+				}
+				catch (System.Threading.ThreadInterruptedException)
+				{
+					SupportClass.ThreadClass.Current().Interrupt();
+				}
+				if (!t.IsAlive)
+					break;
+			}
+			
+			try
+			{
+				t.Join();
+			}
+			catch (System.Threading.ThreadInterruptedException)
+			{
+				SupportClass.ThreadClass.Current().Interrupt();
+			}
+			
+			// Add one more document to force writer to commit a
+			// final segment, so deletion policy has a chance to
+			// delete again:
+			Document doc = new Document();
+			doc.Add(new Field("content", "aaa", Field.Store.YES, Field.Index.TOKENIZED, Field.TermVector.WITH_POSITIONS_OFFSETS));
+			writer.AddDocument(doc);
+			
+			// Make sure we don't have any leftover files in the
+			// directory:
+			writer.Close();
+			TestIndexWriter.AssertNoUnreferencedFiles(dir, "some files were not deleted but should
have been");
+		}
+		
+		/// <summary>Example showing how to use the SnapshotDeletionPolicy
+		/// to take a backup.  This method does not really do a
+		/// backup; instead, it reads every byte of every file
+		/// just to test that the files indeed exist and are
+		/// readable even while the index is changing. 
+		/// </summary>
+		public virtual void  BackupIndex(Directory dir, SnapshotDeletionPolicy dp)
+		{
+			
+			// To backup an index we first take a snapshot:
+			IndexCommitPoint cp = dp.Snapshot();
+			try
+			{
+				
+				// While we hold the snapshot, and nomatter how long
+				// we take to do the backup, the IndexWriter will
+				// never delete the files in the snapshot:
+				System.Collections.ICollection files = cp.GetFileNames();
+				System.Collections.IEnumerator it = files.GetEnumerator();
+				while (it.MoveNext())
+				{
+					System.String fileName = (System.String) it.Current;
+					// NOTE: in a real backup you would not use
+					// readFile; you would need to use something else
+					// that copies the file to a backup location.  This
+					// could even be a spawned shell process (eg "tar",
+					// "zip") that takes the list of files and builds a
+					// backup.
+					ReadFile(dir, fileName);
+				}
+			}
+			finally
+			{
+				// Make sure to release the snapshot, otherwise these
+				// files will never be deleted during this IndexWriter
+				// session:
+				dp.Release();
+			}
+		}
+		
+		internal byte[] buffer = new byte[4096];
+		
+		private void  ReadFile(Directory dir, System.String name)
+		{
+			IndexInput input = dir.OpenInput(name);
+			try
+			{
+				long size = dir.FileLength(name);
+				long bytesLeft = size;
+				while (bytesLeft > 0)
+				{
+					int numToRead;
+					if (bytesLeft < buffer.Length)
+						numToRead = (int) bytesLeft;
+					else
+						numToRead = buffer.Length;
+					input.ReadBytes(buffer, 0, numToRead, false);
+					bytesLeft -= numToRead;
+				}
+				// Don't do this in your real backups!  This is just
+				// to force a backup to take a somewhat long time, to
+				// make sure we are exercising the fact that the
+				// IndexWriter should not delete this file even when I
+				// take my time reading it.
+				try
+				{
+					System.Threading.Thread.Sleep(new System.TimeSpan((System.Int64) 10000 * 1));
+				}
+				catch (System.Threading.ThreadInterruptedException)
+				{
+					SupportClass.ThreadClass.Current().Interrupt();
+				}
+			}
+			finally
+			{
+				input.Close();
+			}
+		}
+	}
+}
\ No newline at end of file

Modified: incubator/lucene.net/trunk/C#/src/Test/ThreadSafetyTest.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Test/ThreadSafetyTest.cs?rev=677059&r1=677058&r2=677059&view=diff
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Test/ThreadSafetyTest.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Test/ThreadSafetyTest.cs Tue Jul 15 14:44:04 2008
@@ -23,8 +23,8 @@
 using Lucene.Net.Analysis;
 using Lucene.Net.Index;
 using Lucene.Net.Search;
-using Searchable = Lucene.Net.Search.Searchable;
 using Lucene.Net.QueryParsers;
+using Searchable = Lucene.Net.Search.Searchable;
 
 namespace Lucene.Net
 {
@@ -145,9 +145,9 @@
 			private void  searchFor(int n, Searcher searcher)
 			{
 				System.Console.Out.WriteLine("Searching for " + n);
-                Lucene.Net.QueryParsers.QueryParser parser = new Lucene.Net.QueryParsers.QueryParser("contents",
Lucene.Net.ThreadSafetyTest.ANALYZER);
-                Lucene.Net.Search.Hits hits = searcher.Search(parser.Parse(Lucene.Net.Util.English.IntToEnglish(n)));
-                System.Console.Out.WriteLine("Search for " + n + ": total=" + hits.Length());
+				Lucene.Net.QueryParsers.QueryParser parser = new Lucene.Net.QueryParsers.QueryParser("contents",
Lucene.Net.ThreadSafetyTest.ANALYZER);
+				Lucene.Net.Search.Hits hits = searcher.Search(parser.Parse(Lucene.Net.Util.English.IntToEnglish(n)));
+				System.Console.Out.WriteLine("Search for " + n + ": total=" + hits.Length());
 				for (int j = 0; j < System.Math.Min(3, hits.Length()); j++)
 				{
 					System.Console.Out.WriteLine("Hit for " + n + ": " + hits.Doc(j).Get("id"));

Added: incubator/lucene.net/trunk/C#/src/Test/Util/LuceneTestCase.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Test/Util/LuceneTestCase.cs?rev=677059&view=auto
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Test/Util/LuceneTestCase.cs (added)
+++ incubator/lucene.net/trunk/C#/src/Test/Util/LuceneTestCase.cs Tue Jul 15 14:44:04 2008
@@ -0,0 +1,64 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.
+ */
+
+using System;
+
+using NUnit.Framework;
+
+using ConcurrentMergeScheduler = Lucene.Net.Index.ConcurrentMergeScheduler;
+
+namespace Lucene.Net.Util
+{
+	
+	/// <summary>Base class for all Lucene unit tests.  Currently the
+	/// only added functionality over JUnit's TestCase is
+	/// asserting that no unhandled exceptions occurred in
+	/// threads launched by ConcurrentMergeScheduler.  If you
+	/// override either <code>setUp()</code> or
+	/// <code>tearDown()</code> in your unit test, make sure you
+	/// call <code>super.setUp()</code> and
+	/// <code>super.tearDown()</code>.
+	/// </summary>
+	
+	[TestFixture]
+	public abstract class LuceneTestCase
+	{
+		
+		public LuceneTestCase() : base()
+		{
+		}
+		
+		public LuceneTestCase(System.String name) : base()
+		{
+		}
+		
+		[SetUp]
+		public virtual void  SetUp()
+		{
+			ConcurrentMergeScheduler.SetTestMode();
+		}
+		
+		[TearDown]
+		public virtual void  TearDown()
+		{
+			if (ConcurrentMergeScheduler.AnyUnhandledExceptions())
+			{
+				Assert.Fail("ConcurrentMergeScheduler hit unhandled exceptions");
+			}
+		}
+	}
+}
\ No newline at end of file

Added: incubator/lucene.net/trunk/C#/src/Test/Util/StringHelperTest.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Test/Util/StringHelperTest.cs?rev=677059&view=auto
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Test/Util/StringHelperTest.cs (added)
+++ incubator/lucene.net/trunk/C#/src/Test/Util/StringHelperTest.cs Tue Jul 15 14:44:04 2008
@@ -0,0 +1,58 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.
+ */
+
+// {{Aroush-2.3.1}} Remove from 2.3.1
+
+/*
+using System;
+using NUnit.Framework;
+namespace Lucene.Net.Util
+{
+	[TestFixture]
+	public class StringHelperTest
+	{
+		[TestFixtureSetUp]
+		protected virtual void  SetUp()
+		{
+		}
+		
+        [TestFixtureTearDown]
+		protected virtual void  TearDown()
+		{
+			
+		}
+		
+        [Test]
+		public virtual void  TestStringDifference()
+		{
+			System.String test1 = "test";
+			System.String test2 = "testing";
+			
+			int result = StringHelper.StringDifference(test1, test2);
+			Assert.IsTrue(result == 4);
+			
+			test2 = "foo";
+			result = StringHelper.StringDifference(test1, test2);
+			Assert.IsTrue(result == 0);
+			
+			test2 = "test";
+			result = StringHelper.StringDifference(test1, test2);
+			Assert.IsTrue(result == 4);
+		}
+	}
+}
+*/
\ No newline at end of file

Modified: incubator/lucene.net/trunk/C#/src/Test/Util/TestBitVector.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Test/Util/TestBitVector.cs?rev=677059&r1=677058&r2=677059&view=diff
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Test/Util/TestBitVector.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Test/Util/TestBitVector.cs Tue Jul 15 14:44:04 2008
@@ -27,19 +27,18 @@
 	
 	/// <summary> <code>TestBitVector</code> tests the <code>BitVector</code>,
obviously.
 	/// 
+	/// 
 	/// </summary>
-	/// <author>  "Peter Mularien" <pmularien@deploy.com>
-	/// </author>
-    /// <version>  $Id: TestBitVector.java 485463 2006-12-11 02:03:38Z yonik $
-    /// </version>
+	/// <version>  $Id: TestBitVector.java 583534 2007-10-10 16:46:35Z mikemccand $
+	/// </version>
 	[TestFixture]
-    public class TestBitVector
+	public class TestBitVector : LuceneTestCase
 	{
 		
 		/// <summary> Test the default constructor on BitVectors of various sizes.</summary>
 		/// <throws>  Exception </throws>
 		[Test]
-        public virtual void  TestConstructSize()
+		public virtual void  TestConstructSize()
 		{
 			DoTestConstructOfSize(8);
 			DoTestConstructOfSize(20);
@@ -56,7 +55,7 @@
 		/// <summary> Test the get() and set() methods on BitVectors of various sizes.</summary>
 		/// <throws>  Exception </throws>
 		[Test]
-        public virtual void  TestGetSet()
+		public virtual void  TestGetSet()
 		{
 			DoTestGetSetVectorOfSize(8);
 			DoTestGetSetVectorOfSize(20);
@@ -79,7 +78,7 @@
 		/// <summary> Test the clear() method on BitVectors of various sizes.</summary>
 		/// <throws>  Exception </throws>
 		[Test]
-        public virtual void  TestClear()
+		public virtual void  TestClear()
 		{
 			DoTestClearVectorOfSize(8);
 			DoTestClearVectorOfSize(20);
@@ -104,7 +103,7 @@
 		/// <summary> Test the count() method on BitVectors of various sizes.</summary>
 		/// <throws>  Exception </throws>
 		[Test]
-        public virtual void  TestCount()
+		public virtual void  TestCount()
 		{
 			DoTestCountVectorOfSize(8);
 			DoTestCountVectorOfSize(20);
@@ -143,7 +142,7 @@
 		/// <summary> Test writing and construction to/from Directory.</summary>
 		/// <throws>  Exception </throws>
 		[Test]
-        public virtual void  TestWriteRead()
+		public virtual void  TestWriteRead()
 		{
 			DoTestWriteRead(8);
 			DoTestWriteRead(20);
@@ -171,53 +170,53 @@
 			}
 		}
 		
-        /// <summary> Test r/w when size/count cause switching between bit-set and
d-gaps file formats.  </summary>
-        /// <throws>  Exception </throws>
-        [Test]
-        public virtual void  TestDgaps()
-        {
-            DoTestDgaps(1, 0, 1);
-            DoTestDgaps(10, 0, 1);
-            DoTestDgaps(100, 0, 1);
-            DoTestDgaps(1000, 4, 7);
-            DoTestDgaps(10000, 40, 43);
-            DoTestDgaps(100000, 415, 418);
-            DoTestDgaps(1000000, 3123, 3126);
-        }
-		
-        private void  DoTestDgaps(int size, int count1, int count2)
-        {
-            Directory d = new RAMDirectory();
-            BitVector bv = new BitVector(size);
-            for (int i = 0; i < count1; i++)
-            {
-                bv.Set(i);
-                Assert.AreEqual(i + 1, bv.Count());
-            }
-            bv.Write(d, "TESTBV");
-            // gradually increase number of set bits
-            for (int i = count1; i < count2; i++)
-            {
-                BitVector bv2 = new BitVector(d, "TESTBV");
-                Assert.IsTrue(DoCompare(bv, bv2));
-                bv = bv2;
-                bv.Set(i);
-                Assert.AreEqual(i + 1, bv.Count());
-                bv.Write(d, "TESTBV");
-            }
-            // now start decreasing number of set bits
-            for (int i = count2 - 1; i >= count1; i--)
-            {
-                BitVector bv2 = new BitVector(d, "TESTBV");
-                Assert.IsTrue(DoCompare(bv, bv2));
-                bv = bv2;
-                bv.Clear(i);
-                Assert.AreEqual(i, bv.Count());
-                bv.Write(d, "TESTBV");
-            }
-        }
+		/// <summary> Test r/w when size/count cause switching between bit-set and d-gaps
file formats.  </summary>
+		/// <throws>  Exception </throws>
+		[Test]
+		public virtual void  TestDgaps()
+		{
+			DoTestDgaps(1, 0, 1);
+			DoTestDgaps(10, 0, 1);
+			DoTestDgaps(100, 0, 1);
+			DoTestDgaps(1000, 4, 7);
+			DoTestDgaps(10000, 40, 43);
+			DoTestDgaps(100000, 415, 418);
+			DoTestDgaps(1000000, 3123, 3126);
+		}
+		
+		private void  DoTestDgaps(int size, int count1, int count2)
+		{
+			Directory d = new RAMDirectory();
+			BitVector bv = new BitVector(size);
+			for (int i = 0; i < count1; i++)
+			{
+				bv.Set(i);
+				Assert.AreEqual(i + 1, bv.Count());
+			}
+			bv.Write(d, "TESTBV");
+			// gradually increase number of set bits
+			for (int i = count1; i < count2; i++)
+			{
+				BitVector bv2 = new BitVector(d, "TESTBV");
+				Assert.IsTrue(DoCompare(bv, bv2));
+				bv = bv2;
+				bv.Set(i);
+				Assert.AreEqual(i + 1, bv.Count());
+				bv.Write(d, "TESTBV");
+			}
+			// now start decreasing number of set bits
+			for (int i = count2 - 1; i >= count1; i--)
+			{
+				BitVector bv2 = new BitVector(d, "TESTBV");
+				Assert.IsTrue(DoCompare(bv, bv2));
+				bv = bv2;
+				bv.Clear(i);
+				Assert.AreEqual(i, bv.Count());
+				bv.Write(d, "TESTBV");
+			}
+		}
 
-        /// <summary> Compare two BitVectors.
+		/// <summary> Compare two BitVectors.
 		/// This should really be an equals method on the BitVector itself.
 		/// </summary>
 		/// <param name="bv">One bit vector

Modified: incubator/lucene.net/trunk/C#/src/Test/Util/TestPriorityQueue.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Test/Util/TestPriorityQueue.cs?rev=677059&r1=677058&r2=677059&view=diff
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Test/Util/TestPriorityQueue.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Test/Util/TestPriorityQueue.cs Tue Jul 15 14:44:04 2008
@@ -22,8 +22,11 @@
 namespace Lucene.Net.Util
 {
 	[TestFixture]
-	public class TestPriorityQueue
+	public class TestPriorityQueue : LuceneTestCase
 	{
+		//public TestPriorityQueue(System.String name) : base(name)
+		//{
+		//}
 		
 		private class IntegerQueue : PriorityQueue
 		{
@@ -39,12 +42,12 @@
 		}
 		
 		[Test]
-        public virtual void  TestPQ()
+		public virtual void  TestPQ()
 		{
-			_TestPQ2(10000);
+			TestPQ(10000);
 		}
 		
-        public static void  _TestPQ2(int count)
+		public static void  TestPQ(int count)
 		{
 			PriorityQueue pq = new IntegerQueue(count);
 			System.Random gen = new System.Random();
@@ -81,7 +84,7 @@
 		}
 		
 		[Test]
-        public virtual void  TestClear()
+		public virtual void  TestClear()
 		{
 			PriorityQueue pq = new IntegerQueue(3);
 			pq.Put((System.Object) 2);
@@ -93,7 +96,7 @@
 		}
 		
 		[Test]
-        public virtual void  TestFixedSize()
+		public virtual void  TestFixedSize()
 		{
 			PriorityQueue pq = new IntegerQueue(3);
 			pq.Insert((System.Object) 2);
@@ -105,5 +108,27 @@
 			Assert.AreEqual(3, pq.Size());
 			Assert.AreEqual(3, ((System.Int32) pq.Top()));
 		}
+		
+		[Test]
+		public virtual void  TestInsertWithOverflow()
+		{
+			int size = 4;
+			PriorityQueue pq = new IntegerQueue(size);
+			System.Int32 i1 = 2;
+			System.Int32 i2 = 3;
+			System.Int32 i3 = 1;
+			System.Int32 i4 = 5;
+			System.Int32 i5 = 7;
+			System.Int32 i6 = 1;
+			
+			Assert.IsNull(pq.InsertWithOverflow((System.Object) i1));
+			Assert.IsNull(pq.InsertWithOverflow((System.Object) i2));
+			Assert.IsNull(pq.InsertWithOverflow((System.Object) i3));
+			Assert.IsNull(pq.InsertWithOverflow((System.Object) i4));
+			Assert.IsTrue((int)pq.InsertWithOverflow((System.Object)i5) == i3); // i3 should have
been dropped
+			Assert.IsTrue((int)pq.InsertWithOverflow((System.Object)i6) == i6); // i6 should not have
been inserted
+			Assert.AreEqual(size, pq.Size());
+			Assert.AreEqual(2, ((System.Int32) pq.Top()));
+		}
 	}
 }
\ No newline at end of file

Modified: incubator/lucene.net/trunk/C#/src/Test/Util/TestSmallFloat.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Test/Util/TestSmallFloat.cs?rev=677059&r1=677058&r2=677059&view=diff
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Test/Util/TestSmallFloat.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Test/Util/TestSmallFloat.cs Tue Jul 15 14:44:04 2008
@@ -27,7 +27,7 @@
 	/// <version>  $Id$
 	/// </version>
 	[TestFixture]
-    public class TestSmallFloat
+	public class TestSmallFloat : LuceneTestCase
 	{
 		
 		// original lucene byteToFloat
@@ -74,7 +74,7 @@
 			return (sbyte) ((exponent << 3) | mantissa); // pack into a byte
 		}
 		
-        [Test]
+		[Test]
 		public virtual void  TestByteToFloat()
 		{
 			for (int i = 0; i < 256; i++)
@@ -92,7 +92,7 @@
 		}
 		
 		[Test]
-        public virtual void  TestFloatToByte()
+		public virtual void  TestFloatToByte()
 		{
 			System.Random rand = new System.Random((System.Int32) 0);
 			// up iterations for more exhaustive test after changing something

Modified: incubator/lucene.net/trunk/C#/src/Test/Util/TestStringHelper.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Test/Util/TestStringHelper.cs?rev=677059&r1=677058&r2=677059&view=diff
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Test/Util/TestStringHelper.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Test/Util/TestStringHelper.cs Tue Jul 15 14:44:04 2008
@@ -22,7 +22,7 @@
 namespace Lucene.Net.Util
 {
 	[TestFixture]
-	public class TestStringHelper
+	public class TestStringHelper : LuceneTestCase
 	{
 		
 		[Test]

Modified: incubator/lucene.net/trunk/C#/src/Test/Util/_TestUtil.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Test/Util/_TestUtil.cs?rev=677059&r1=677058&r2=677059&view=diff
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Test/Util/_TestUtil.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Test/Util/_TestUtil.cs Tue Jul 15 14:44:04 2008
@@ -17,6 +17,10 @@
 
 using System;
 
+using ConcurrentMergeScheduler = Lucene.Net.Index.ConcurrentMergeScheduler;
+using IndexWriter = Lucene.Net.Index.IndexWriter;
+using MergeScheduler = Lucene.Net.Index.MergeScheduler;
+
 namespace Lucene.Net.Util
 {
 	
@@ -74,5 +78,16 @@
 		{
 			RmDir(new System.IO.FileInfo(dir));
 		}
+		
+		public static void  SyncConcurrentMerges(IndexWriter writer)
+		{
+			SyncConcurrentMerges(writer.GetMergeScheduler());
+		}
+		
+		public static void  SyncConcurrentMerges(MergeScheduler ms)
+		{
+			if (ms is ConcurrentMergeScheduler)
+				((ConcurrentMergeScheduler) ms).Sync();
+		}
 	}
 }
\ No newline at end of file



Mime
View raw message