lucenenet-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dougs...@apache.org
Subject svn commit: r798995 [35/35] - in /incubator/lucene.net/trunk/C#/src: Lucene.Net/ Lucene.Net/Analysis/ Lucene.Net/Analysis/Standard/ Lucene.Net/Document/ Lucene.Net/Index/ Lucene.Net/QueryParser/ Lucene.Net/Search/ Lucene.Net/Search/Function/ Lucene.Net...
Date Wed, 29 Jul 2009 18:04:24 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=798995&r1=798994&r2=798995&view=diff
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Test/TestDemo.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Test/TestDemo.cs Wed Jul 29 18:04:12 2009
@@ -14,41 +14,35 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-
 using System;
 
 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 ScoreDoc = Lucene.Net.Search.ScoreDoc;
+using Directory = Lucene.Net.Store.Directory;
+using RAMDirectory = Lucene.Net.Store.RAMDirectory;
 using LuceneTestCase = Lucene.Net.Util.LuceneTestCase;
+using _TestUtil = Lucene.Net.Util._TestUtil;
 
 namespace Lucene.Net
 {
-	
 	/// <summary> A very simple demo used in the API documentation (src/java/overview.html).
-	/// 
 	/// </summary>
-	/// <author>  Daniel Naber
-	/// </author>
 	[TestFixture]
 	public class TestDemo : LuceneTestCase
 	{
-		
 		[Test]
 		public virtual void  TestDemo_Renamed_Method()
 		{
-			
 			Analyzer analyzer = new StandardAnalyzer();
 			
 			// Store the index in memory:
@@ -57,25 +51,26 @@
 			// parameter true will overwrite the index in that directory
 			// if one exists):
 			//Directory directory = FSDirectory.getDirectory("/tmp/testindex", true);
-			IndexWriter iwriter = new IndexWriter(directory, analyzer, true);
-			iwriter.SetMaxFieldLength(25000);
+			IndexWriter iwriter = new IndexWriter(directory, analyzer, true, new IndexWriter.MaxFieldLength(25000));
 			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));
+			doc.Add(new Field("fieldname", text, Field.Store.YES, Field.Index.ANALYZED));
 			iwriter.AddDocument(doc);
 			iwriter.Close();
-			
+
+            _TestUtil.CheckIndex(directory);
+
 			// 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);
 			Query query = parser.Parse("text");
-			Hits hits = isearcher.Search(query);
-			Assert.AreEqual(1, hits.Length());
+			ScoreDoc[] hits = isearcher.Search(query, null, 1000).scoreDocs;
+			Assert.AreEqual(1, hits.Length);
 			// Iterate through the results:
-			for (int i = 0; i < hits.Length(); i++)
+			for (int i = 0; i < hits.Length; i++)
 			{
-				Document hitDoc = hits.Doc(i);
+				Document hitDoc = isearcher.Doc(hits[i].doc);
 				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=798995&r1=798994&r2=798995&view=diff
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Test/TestHitIterator.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Test/TestHitIterator.cs Wed Jul 29 18:04:12 2009
@@ -14,7 +14,6 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-
 using System;
 
 using NUnit.Framework;
@@ -26,11 +25,13 @@
 using RAMDirectory = Lucene.Net.Store.RAMDirectory;
 using WhitespaceAnalyzer = Lucene.Net.Analysis.WhitespaceAnalyzer;
 using Hit = Lucene.Net.Search.Hit;
-using HitIterator = Lucene.Net.Search.HitIterator;
 using Hits = Lucene.Net.Search.Hits;
+using HitIterator = Lucene.Net.Search.HitIterator;
+using ScoreDoc = Lucene.Net.Search.ScoreDoc;
 using IndexSearcher = Lucene.Net.Search.IndexSearcher;
 using TermQuery = Lucene.Net.Search.TermQuery;
 using LuceneTestCase = Lucene.Net.Util.LuceneTestCase;
+using _TestUtil = Lucene.Net.Util._TestUtil;
 
 namespace Lucene.Net
 {
@@ -38,7 +39,8 @@
 	/// <summary> This test intentionally not put in the search package in order
 	/// to test HitIterator and Hit package protection.
 	/// </summary>
-	[TestFixture]
+    [System.Obsolete("Hits will be removed in Lucene 3.0.")]
+    [TestFixture]
 	public class TestHitIterator : LuceneTestCase
 	{
 		[Test]
@@ -46,17 +48,19 @@
 		{
 			RAMDirectory directory = new RAMDirectory();
 			
-			IndexWriter writer = new IndexWriter(directory, new WhitespaceAnalyzer(), true);
+			IndexWriter writer = new IndexWriter(directory, new WhitespaceAnalyzer(), true, IndexWriter.MaxFieldLength.LIMITED);
 			Lucene.Net.Documents.Document doc = new Lucene.Net.Documents.Document();
-			doc.Add(new Field("field", "iterator test doc 1", Field.Store.YES, Field.Index.TOKENIZED));
+			doc.Add(new Field("field", "iterator test doc 1", Field.Store.YES, Field.Index.ANALYZED));
 			writer.AddDocument(doc);
 			
 			doc = new Lucene.Net.Documents.Document();
-			doc.Add(new Field("field", "iterator test doc 2", Field.Store.YES, Field.Index.TOKENIZED));
+			doc.Add(new Field("field", "iterator test doc 2", Field.Store.YES, Field.Index.ANALYZED));
 			writer.AddDocument(doc);
 			
 			writer.Close();
-			
+
+            _TestUtil.CheckIndex(directory);
+
 			IndexSearcher searcher = new IndexSearcher(directory);
 			Hits hits = searcher.Search(new TermQuery(new Term("field", "iterator")));
 			

Added: incubator/lucene.net/trunk/C#/src/Test/TestMergeSchedulerExternal.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Test/TestMergeSchedulerExternal.cs?rev=798995&view=auto
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Test/TestMergeSchedulerExternal.cs (added)
+++ incubator/lucene.net/trunk/C#/src/Test/TestMergeSchedulerExternal.cs Wed Jul 29 18:04:12 2009
@@ -0,0 +1,136 @@
+/**
+ * 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 NUnit.Framework;
+
+using LuceneTestCase = Lucene.Net.Util.LuceneTestCase;
+using WhitespaceAnalyzer = Lucene.Net.Analysis.WhitespaceAnalyzer;
+using MockRAMDirectory = Lucene.Net.Store.MockRAMDirectory;
+using Directory = Lucene.Net.Store.Directory;
+using IndexWriter = Lucene.Net.Index.IndexWriter;
+using MergePolicy = Lucene.Net.Index.MergePolicy;
+using ConcurrentMergeScheduler = Lucene.Net.Index.ConcurrentMergeScheduler;
+using Document = Lucene.Net.Documents.Document;
+using Field = Lucene.Net.Documents.Field;
+
+namespace Lucene.Net.Test
+{
+    /**
+     * Holds tests cases to verify external APIs are accessible
+     * while not being in org.apache.lucene.index package.
+     */
+    [TestFixture]
+    public class TestMergeSchedulerExternal : LuceneTestCase
+    {
+
+        internal volatile bool mergeCalled;
+        internal volatile bool mergeThreadCreated;
+        internal volatile bool excCalled;
+
+        private class MyMergeException : System.Exception
+        {
+            Directory dir;
+            public MyMergeException(System.Exception exc, Directory dir)
+                : base(null, exc)
+            {
+                this.dir = dir;
+            }
+        }
+
+        private class MyMergeScheduler : ConcurrentMergeScheduler
+        {
+
+            internal TestMergeSchedulerExternal enclosingInstance;
+
+            public MyMergeScheduler(TestMergeSchedulerExternal enclosingInstance)
+                : base()
+            {
+                this.enclosingInstance = enclosingInstance;
+            }
+
+            private class MyMergeThread : ConcurrentMergeScheduler.MergeThread
+            {
+                public MyMergeThread(ConcurrentMergeScheduler scheduler, IndexWriter writer, MergePolicy.OneMerge merge)
+                    : base(scheduler, writer, merge)
+                {
+                    ((MyMergeScheduler)scheduler).enclosingInstance.mergeThreadCreated = true;
+                }
+            }
+
+            override protected MergeThread GetMergeThread(IndexWriter writer, MergePolicy.OneMerge merge)
+            {
+                MergeThread thread = new MyMergeThread(this, writer, merge);
+                thread.SetThreadPriority(GetMergeThreadPriority());
+                thread.IsBackground = true;
+                thread.Name = "MyMergeThread";
+                return thread;
+            }
+
+            override protected void HandleMergeException(System.Exception t)
+            {
+                enclosingInstance.excCalled = true;
+            }
+
+            override protected void DoMerge(MergePolicy.OneMerge merge)
+            {
+                enclosingInstance.mergeCalled = true;
+                base.DoMerge(merge);
+            }
+        }
+
+        private class FailOnlyOnMerge : MockRAMDirectory.Failure
+        {
+            override public void Eval(MockRAMDirectory dir)
+            {
+                System.Diagnostics.StackFrame[] frames = new System.Diagnostics.StackTrace().GetFrames();
+                for (int i = 0; i < frames.Length; i++)
+                {
+                    if ("DoMerge".Equals(frames[i].GetMethod().Name))
+                        throw new System.IO.IOException("now failing during merge");
+                }
+            }
+        }
+
+        [Test]
+        public void TestSubclassConcurrentMergeScheduler()
+        {
+            MockRAMDirectory dir = new MockRAMDirectory();
+            dir.FailOn(new FailOnlyOnMerge());
+
+            Document doc = new Document();
+            Field idField = new Field("id", "", Field.Store.YES, Field.Index.NOT_ANALYZED);
+            doc.Add(idField);
+
+            IndexWriter writer = new IndexWriter(dir, new WhitespaceAnalyzer(), true, IndexWriter.MaxFieldLength.LIMITED);
+            MyMergeScheduler ms = new MyMergeScheduler(this);
+            writer.SetMergeScheduler(ms);
+            writer.SetMaxBufferedDocs(2);
+            writer.SetRAMBufferSizeMB(IndexWriter.DISABLE_AUTO_FLUSH);
+            for (int i = 0; i < 20; i++)
+                writer.AddDocument(doc);
+
+            ms.Sync();
+            writer.Close();
+
+            Assert.IsTrue(mergeThreadCreated);
+            Assert.IsTrue(mergeCalled);
+            Assert.IsTrue(excCalled);
+            dir.Close();
+            Assert.IsTrue(ConcurrentMergeScheduler.AnyUnhandledExceptions());
+        }
+    }
+}

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=798995&r1=798994&r2=798995&view=diff
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Test/TestSearch.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Test/TestSearch.cs Wed Jul 29 18:04:12 2009
@@ -82,7 +82,7 @@
 		{
 			Directory directory = new RAMDirectory();
 			Analyzer analyzer = new SimpleAnalyzer();
-			IndexWriter writer = new IndexWriter(directory, analyzer, true);
+			IndexWriter writer = new IndexWriter(directory, analyzer, true, IndexWriter.MaxFieldLength.LIMITED);
 			
 			writer.SetUseCompoundFile(useCompoundFile);
 			
@@ -90,7 +90,7 @@
 			for (int j = 0; j < docs.Length; j++)
 			{
 				Lucene.Net.Documents.Document d = new Lucene.Net.Documents.Document();
-				d.Add(new Field("contents", docs[j], Field.Store.YES, Field.Index.TOKENIZED));
+				d.Add(new Field("contents", docs[j], Field.Store.YES, Field.Index.ANALYZED));
 				writer.AddDocument(d);
 			}
 			writer.Close();
@@ -98,7 +98,7 @@
 			Searcher searcher = new IndexSearcher(directory);
 			
 			System.String[] queries = new System.String[]{"a b", "\"a b\"", "\"a b c\"", "a c", "\"a c\"", "\"a c e\""};
-			Hits hits = null;
+			ScoreDoc[] hits = null;
 			
 			Lucene.Net.QueryParsers.QueryParser parser = new Lucene.Net.QueryParsers.QueryParser("contents", analyzer);
 			parser.SetPhraseSlop(4);
@@ -112,13 +112,13 @@
 				//DateFilter filter = DateFilter.Before("modified", Time(1997,00,01));
 				//System.out.println(filter);
 				
-				hits = searcher.Search(query);
+				hits = searcher.Search(query, null, 1000).scoreDocs;
 				
-				out_Renamed.WriteLine(hits.Length() + " total results");
-				for (int i = 0; i < hits.Length() && i < 10; i++)
+				out_Renamed.WriteLine(hits.Length + " total results");
+				for (int i = 0; i < hits.Length && i < 10; i++)
 				{
-					Lucene.Net.Documents.Document d = hits.Doc(i);
-					out_Renamed.WriteLine(i + " " + hits.Score(i) + " " + d.Get("contents"));
+					Lucene.Net.Documents.Document d = searcher.Doc(hits[i].doc);
+					out_Renamed.WriteLine(i + " " + hits[i].score + " " + d.Get("contents"));
 				}
 			}
 			searcher.Close();

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=798995&r1=798994&r2=798995&view=diff
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Test/TestSearchForDuplicates.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Test/TestSearchForDuplicates.cs Wed Jul 29 18:04:12 2009
@@ -91,7 +91,7 @@
 		{
 			Directory directory = new RAMDirectory();
 			Analyzer analyzer = new SimpleAnalyzer();
-			IndexWriter writer = new IndexWriter(directory, analyzer, true);
+			IndexWriter writer = new IndexWriter(directory, analyzer, true, IndexWriter.MaxFieldLength.LIMITED);
 			
 			writer.SetUseCompoundFile(useCompoundFiles);
 			
@@ -100,24 +100,23 @@
 			for (int j = 0; j < MAX_DOCS; j++)
 			{
 				Lucene.Net.Documents.Document d = new Lucene.Net.Documents.Document();
-				d.Add(new Field(PRIORITY_FIELD, HIGH_PRIORITY, Field.Store.YES, Field.Index.TOKENIZED));
-				d.Add(new Field(ID_FIELD, System.Convert.ToString(j), Field.Store.YES, Field.Index.TOKENIZED));
+				d.Add(new Field(PRIORITY_FIELD, HIGH_PRIORITY, Field.Store.YES, Field.Index.ANALYZED));
+				d.Add(new Field(ID_FIELD, System.Convert.ToString(j), Field.Store.YES, Field.Index.ANALYZED));
 				writer.AddDocument(d);
 			}
 			writer.Close();
 			
 			// try a search without OR
 			Searcher searcher = new IndexSearcher(directory);
-			Hits hits = null;
 			
 			Lucene.Net.QueryParsers.QueryParser parser = new Lucene.Net.QueryParsers.QueryParser(PRIORITY_FIELD, analyzer);
 			
 			Query query = parser.Parse(HIGH_PRIORITY);
 			out_Renamed.WriteLine("Query: " + query.ToString(PRIORITY_FIELD));
 			
-			hits = searcher.Search(query);
-			PrintHits(out_Renamed, hits);
-			CheckHits(hits, MAX_DOCS);
+			ScoreDoc[] hits = searcher.Search(query, null, MAX_DOCS).scoreDocs;
+			PrintHits(out_Renamed, hits, searcher);
+			CheckHits(hits, MAX_DOCS, searcher);
 			
 			searcher.Close();
 			
@@ -130,35 +129,35 @@
 			query = parser.Parse(HIGH_PRIORITY + " OR " + MED_PRIORITY);
 			out_Renamed.WriteLine("Query: " + query.ToString(PRIORITY_FIELD));
 			
-			hits = searcher.Search(query);
-			PrintHits(out_Renamed, hits);
-			CheckHits(hits, MAX_DOCS);
+			hits = searcher.Search(query, null, MAX_DOCS).scoreDocs;
+			PrintHits(out_Renamed, hits, searcher);
+			CheckHits(hits, MAX_DOCS, searcher);
 			
 			searcher.Close();
 		}
 		
 		
-		private void  PrintHits(System.IO.StreamWriter out_Renamed, Hits hits)
+		private void  PrintHits(System.IO.StreamWriter out_Renamed, ScoreDoc[] hits, Searcher searcher)
 		{
-			out_Renamed.WriteLine(hits.Length() + " total results\n");
-			for (int i = 0; i < hits.Length(); i++)
+			out_Renamed.WriteLine(hits.Length + " total results\n");
+			for (int i = 0; i < hits.Length; i++)
 			{
 				if (i < 10 || (i > 94 && i < 105))
 				{
-					Lucene.Net.Documents.Document d = hits.Doc(i);
+					Lucene.Net.Documents.Document d = searcher.Doc(hits[i].doc);
 					out_Renamed.WriteLine(i + " " + d.Get(ID_FIELD));
 				}
 			}
 		}
 		
-		private void  CheckHits(Hits hits, int expectedCount)
+		private void  CheckHits(ScoreDoc[] hits, int expectedCount, Searcher searcher)
 		{
-			Assert.AreEqual(expectedCount, hits.Length(), "total results");
-			for (int i = 0; i < hits.Length(); i++)
+			Assert.AreEqual(expectedCount, hits.Length, "total results");
+			for (int i = 0; i < hits.Length; i++)
 			{
 				if (i < 10 || (i > 94 && i < 105))
 				{
-					Lucene.Net.Documents.Document d = hits.Doc(i);
+					Lucene.Net.Documents.Document d = searcher.Doc(hits[i].doc);
 					Assert.AreEqual(System.Convert.ToString(i), d.Get(ID_FIELD), "check " + i);
 				}
 			}

Modified: 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=798995&r1=798994&r2=798995&view=diff
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Test/TestSnapshotDeletionPolicy.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Test/TestSnapshotDeletionPolicy.cs Wed Jul 29 18:04:12 2009
@@ -21,7 +21,7 @@
 
 using Document = Lucene.Net.Documents.Document;
 using Field = Lucene.Net.Documents.Field;
-using IndexCommitPoint = Lucene.Net.Index.IndexCommitPoint;
+using IndexCommit = Lucene.Net.Index.IndexCommit;
 using IndexWriter = Lucene.Net.Index.IndexWriter;
 using KeepOnlyLastCommitDeletionPolicy = Lucene.Net.Index.KeepOnlyLastCommitDeletionPolicy;
 using SnapshotDeletionPolicy = Lucene.Net.Index.SnapshotDeletionPolicy;
@@ -71,7 +71,7 @@
 			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));
+				doc.Add(new Field("content", "aaa", Field.Store.YES, Field.Index.ANALYZED, Field.TermVector.WITH_POSITIONS_OFFSETS));
 				while ((System.DateTime.Now.Ticks - 621355968000000000) / 10000 < stopTime)
 				{
 					for (int i = 0; i < 27; i++)
@@ -80,10 +80,10 @@
 						{
 							writer.AddDocument(doc);
 						}
-						catch (System.IO.IOException cie)
+						catch (System.Exception t)
 						{
-							System.SystemException re = new System.SystemException("addDocument failed", cie);
-							throw re;
+                            System.Console.Out.WriteLine(t.StackTrace);
+                            Assert.Fail("addDocument failed");
 						}
 					}
 					try
@@ -117,8 +117,48 @@
 			MockRAMDirectory dir2 = new MockRAMDirectory();
 			RunTest(dir2);
 		}
-		
-		private void  RunTest(Directory dir)
+
+        [Test]
+        public void TestReuseAcrossWriters()
+        {
+            Directory dir = new MockRAMDirectory();
+
+            SnapshotDeletionPolicy dp = new SnapshotDeletionPolicy(new KeepOnlyLastCommitDeletionPolicy());
+            IndexWriter writer = new IndexWriter(dir, true, new StandardAnalyzer(), dp);
+            // Force frequent commits
+            writer.SetMaxBufferedDocs(2);
+            Document doc = new Document();
+            doc.Add(new Field("content", "aaa", Field.Store.YES, Field.Index.ANALYZED, Field.TermVector.WITH_POSITIONS_OFFSETS));
+            for (int i = 0; i < 7; i++)
+                writer.AddDocument(doc);
+            IndexCommit cp = (IndexCommit)dp.Snapshot();
+            CopyFiles(dir, cp);
+            writer.Close();
+            CopyFiles(dir, cp);
+
+            writer = new IndexWriter(dir, true, new StandardAnalyzer(), dp);
+            CopyFiles(dir, cp);
+            for (int i = 0; i < 7; i++)
+                writer.AddDocument(doc);
+            CopyFiles(dir, cp);
+            writer.Close();
+            CopyFiles(dir, cp);
+            dp.Release();
+            writer = new IndexWriter(dir, true, new StandardAnalyzer(), dp);
+            writer.Close();
+            try
+            {
+                CopyFiles(dir, cp);
+                Assert.Fail("did not hit expected IOException");
+            }
+            catch (System.IO.IOException)
+            {
+                // expected
+            }
+            dir.Close();
+        }
+
+        private void RunTest(Directory dir)
 		{
 			// Run for ~7 seconds
 			long stopTime = (System.DateTime.Now.Ticks - 621355968000000000) / 10000 + 7000;
@@ -163,7 +203,7 @@
 			// 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));
+			doc.Add(new Field("content", "aaa", Field.Store.YES, Field.Index.ANALYZED, Field.TermVector.WITH_POSITIONS_OFFSETS));
 			writer.AddDocument(doc);
 			
 			// Make sure we don't have any leftover files in the
@@ -182,33 +222,35 @@
 		{
 			
 			// 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();
+            try
+            {
+                CopyFiles(dir, (IndexCommit)dp.Snapshot());
+            }
+            finally
+            {
+                // Make sure to release the snapshot, otherwise these files will never be
+                // deleted during this IndexWriter session.
+                dp.Release();
+            }
+        }
+
+        private void CopyFiles(Directory dir, IndexCommit cp)
+        {
+			// While we hold the snapshot, and no matter how long
+			// we take to do the backup, the IndexWriter will
+			// never delete the files in the snapshot:
+			System.Collections.Generic.ICollection<string> files = cp.GetFileNames();
+			System.Collections.Generic.IEnumerator<string> it = files.GetEnumerator();
+			while (it.MoveNext())
+			{
+				string fileName = 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);
 			}
 		}
 		

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=798995&r1=798994&r2=798995&view=diff
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Test/ThreadSafetyTest.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Test/ThreadSafetyTest.cs Wed Jul 29 18:04:12 2009
@@ -70,8 +70,8 @@
 					{
 						Lucene.Net.Documents.Document d = new Lucene.Net.Documents.Document();
 						int n = Lucene.Net.ThreadSafetyTest.RANDOM.Next();
-						d.Add(new Field("id", System.Convert.ToString(n), Field.Store.YES, Field.Index.UN_TOKENIZED));
-						d.Add(new Field("contents", Lucene.Net.Util.English.IntToEnglish(n), Field.Store.NO, Field.Index.TOKENIZED));
+						d.Add(new Field("id", System.Convert.ToString(n), Field.Store.YES, Field.Index.NOT_ANALYZED));
+						d.Add(new Field("contents", Lucene.Net.Util.English.IntToEnglish(n), Field.Store.NO, Field.Index.ANALYZED));
 						System.Console.Out.WriteLine("Adding " + n);
 						
 						// Switch between single and multiple file segments
@@ -83,7 +83,7 @@
 						if (i % reopenInterval == 0)
 						{
 							writer.Close();
-							writer = new IndexWriter("index", Lucene.Net.ThreadSafetyTest.ANALYZER, false);
+							writer = new IndexWriter("index", Lucene.Net.ThreadSafetyTest.ANALYZER, false, IndexWriter.MaxFieldLength.LIMITED);
 						}
 					}
 					
@@ -146,11 +146,11 @@
 			{
 				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());
-				for (int j = 0; j < System.Math.Min(3, hits.Length()); j++)
+				Lucene.Net.Search.ScoreDoc[] hits = searcher.Search(parser.Parse(Lucene.Net.Util.English.IntToEnglish(n)), null, 1000).scoreDocs;
+				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"));
+					System.Console.Out.WriteLine("Hit for " + n + ": " + searcher.Doc(hits[j].doc).Get("id"));
 				}
 			}
 		}
@@ -185,7 +185,7 @@
 			
 			if (!readOnly)
 			{
-				IndexWriter writer = new IndexWriter(indexDir, ANALYZER, !add);
+				IndexWriter writer = new IndexWriter(indexDir, ANALYZER, !add, IndexWriter.MaxFieldLength.LIMITED);
 				
 				SupportClass.ThreadClass indexerThread = new IndexerThread(writer);
 				indexerThread.Start();

Added: incubator/lucene.net/trunk/C#/src/Test/Util/Cache/TestSimpleLRUCache.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Test/Util/Cache/TestSimpleLRUCache.cs?rev=798995&view=auto
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Test/Util/Cache/TestSimpleLRUCache.cs (added)
+++ incubator/lucene.net/trunk/C#/src/Test/Util/Cache/TestSimpleLRUCache.cs Wed Jul 29 18:04:12 2009
@@ -0,0 +1,71 @@
+/**
+* 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 NUnit.Framework;
+
+namespace Lucene.Net.Util.Cache
+{
+    [TestFixture]
+    public class TestSimpleLRUCache
+    {
+        [Test]
+        public void TestLRUCache()
+        {
+            int n = 100;
+            object dummy = new object();
+
+            Cache cache = new SimpleLRUCache(n);
+
+            for (int i = 0; i < n; i++)
+            {
+                cache.Put(i, dummy);
+            }
+
+            // access every 2nd item in cache
+            for (int i = 0; i < n; i += 2)
+            {
+                Assert.IsNotNull(cache.Get(i));
+            }
+
+            // add n/2 elements to cache, the ones that weren't
+            // touched in the previous loop should now be thrown away
+            for (int i = n; i < n + (n / 2); i++)
+            {
+                cache.Put(i, dummy);
+            }
+
+            // access every 4th item in cache
+            for (int i = 0; i < n; i += 4)
+            {
+                Assert.IsNotNull(cache.Get(i));
+            }
+
+            // add 3/4n elements to cache, the ones that weren't
+            // touched in the previous loops should now be thrown away
+            for (int i = n; i < n + (n * 3 / 4); i++)
+            {
+                cache.Put(i, dummy);
+            }
+
+            // access every 4th item in cache
+            for (int i = 0; i < n; i += 4)
+            {
+                Assert.IsNotNull(cache.Get(i));
+            }
+        }
+    }
+}

Modified: 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=798995&r1=798994&r2=798995&view=diff
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Test/Util/LuceneTestCase.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Test/Util/LuceneTestCase.cs Wed Jul 29 18:04:12 2009
@@ -57,6 +57,8 @@
 		{
 			if (ConcurrentMergeScheduler.AnyUnhandledExceptions())
 			{
+                // clear the failure so that we don't just keep failing subsequent test cases
+                ConcurrentMergeScheduler.ClearUnhandledExceptions();
 				Assert.Fail("ConcurrentMergeScheduler hit unhandled exceptions");
 			}
 		}

Added: incubator/lucene.net/trunk/C#/src/Test/Util/TestOpenBitSet.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Test/Util/TestOpenBitSet.cs?rev=798995&view=auto
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Test/Util/TestOpenBitSet.cs (added)
+++ incubator/lucene.net/trunk/C#/src/Test/Util/TestOpenBitSet.cs Wed Jul 29 18:04:12 2009
@@ -0,0 +1,332 @@
+/**
+ * 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 NUnit.Framework;
+
+using BitArray = System.Collections.BitArray;
+
+namespace Lucene.Net.Util
+{
+    /**
+     * @version $Id$
+     */
+    [TestFixture]
+    public class TestOpenBitSet
+    {
+        static System.Random rand = new System.Random();
+
+        void DoGet(BitArray a, OpenBitSet b)
+        {
+            int max = a.Count;
+            for (int i = 0; i < max; i++)
+            {
+                if (a.Get(i) != b.Get(i))
+                {
+                    Assert.Fail("mismatch: BitArray[" + i + "]=" + a.Get(i));
+                }
+            }
+        }
+
+        void DoNextSetBit(BitArray a, OpenBitSet b)
+        {
+            int aa = -1, bb = -1;
+            do
+            {
+                aa = SupportClass.Number.NextSetBit(a, aa + 1);
+                bb = b.NextSetBit(bb + 1);
+                Assert.AreEqual(aa, bb);
+            } while (aa >= 0);
+        }
+
+        // test interleaving different BitSetIterator.next()
+        void DoIterate(BitArray a, OpenBitSet b)
+        {
+            int aa = -1, bb = -1;
+            OpenBitSetIterator iterator = new OpenBitSetIterator(b);
+            do
+            {
+                aa = SupportClass.Number.NextSetBit(a, aa + 1);
+                if (rand.Next(2) == 0)
+                    iterator.Next();
+                else
+                    iterator.SkipTo(bb + 1);
+                bb = iterator.Doc();
+                Assert.AreEqual(aa, bb);
+            } while (aa >= 0);
+        }
+
+
+        void DoRandomSets(int maxSize, int iter)
+        {
+            BitArray a0 = null;
+            OpenBitSet b0 = null;
+
+            for (int i = 0; i < iter; i++)
+            {
+                int sz = rand.Next(maxSize);
+                BitArray a = new BitArray(sz);
+                OpenBitSet b = new OpenBitSet(sz);
+
+                // test the various ways of setting bits
+                if (sz > 0)
+                {
+                    int nOper = rand.Next(sz);
+                    for (int j = 0; j < nOper; j++)
+                    {
+                        int idx;
+
+                        idx = rand.Next(sz);
+                        a.Set(idx, true);
+                        b.FastSet(idx);
+                        idx = rand.Next(sz);
+                        a.Set(idx, false);
+                        b.FastClear(idx);
+                        idx = rand.Next(sz);
+                        a.Set(idx, !a.Get(idx));
+                        b.FastFlip(idx);
+
+                        bool val = b.FlipAndGet(idx);
+                        bool val2 = b.FlipAndGet(idx);
+                        Assert.IsTrue(val != val2);
+
+                        val = b.GetAndSet(idx);
+                        Assert.IsTrue(val2 == val);
+                        Assert.IsTrue(b.Get(idx));
+
+                        if (!val) b.FastClear(idx);
+                        Assert.IsTrue(b.Get(idx) == val);
+                    }
+                }
+
+                // test that the various ways of accessing the bits are equivalent
+                DoGet(a, b);
+
+                // {{dougsale-2.4.0}}
+                //
+                // Java's java.util.BitSet automatically grows as needed - i.e., when a bit is referenced beyond
+                // the size of the BitSet, an exception isn't thrown - rather, the set grows to the size of the 
+                // referenced bit.
+                //
+                // System.Collections.BitArray does not have this feature, and thus I've faked it here by
+                // "growing" the array explicitly when necessary (creating a new instance of the appropriate size
+                // and setting the appropriate bits).
+                //
+
+                // test ranges, including possible extension
+                int fromIndex, toIndex;
+                fromIndex = rand.Next(sz + 80);
+                toIndex = fromIndex + rand.Next((sz >> 1) + 1);
+                
+                // {{dougsale-2.4.0}}:
+                // The following commented-out, compound statement's 'for loop' implicitly grows the Java BitSets 'a'
+                // and 'aa' to the same cardinality as 'j+1' when 'a.Count < j+1' and 'fromIndex < toIndex':
+                //BitArray aa = (BitArray)a.Clone(); for (int j = fromIndex; j < toIndex; j++) aa.Set(j, !a.Get(j));
+                // So, if necessary, lets explicitly grow 'a' now; then 'a' and its clone, 'aa', will be of the required size.
+                if (a.Count < toIndex && fromIndex < toIndex)
+                {
+                    BitArray tmp = new BitArray(toIndex, false);
+                    for (int k = 0; k < a.Count; k++)
+                        tmp.Set(k, a.Get(k));
+                    a = tmp;
+                }
+                // {{dougsale-2.4.0}}: now we can invoke this statement without going 'out-of-bounds'
+                BitArray aa = (BitArray)a.Clone(); for (int j = fromIndex; j < toIndex; j++) aa.Set(j, !a.Get(j));
+                OpenBitSet bb = (OpenBitSet)b.Clone(); bb.Flip(fromIndex, toIndex);
+
+                DoIterate(aa, bb);   // a problem here is from flip or DoIterate
+
+                fromIndex = rand.Next(sz + 80);
+                toIndex = fromIndex + rand.Next((sz >> 1) + 1);
+                // {{dougsale-2.4.0}}:
+                // The following commented-out, compound statement's 'for loop' implicitly grows the Java BitSet 'aa'
+                // when 'a.Count < j+1' and 'fromIndex < toIndex'
+                //aa = (BitArray)a.Clone(); for (int j = fromIndex; j < toIndex; j++) aa.Set(j, false);
+                // So, if necessary, lets explicitly grow 'aa' now
+                if (a.Count < toIndex && fromIndex < toIndex)
+                {
+                    aa = new BitArray(toIndex);
+                    for (int k = 0; k < a.Count; k++)
+                        aa.Set(k, a.Get(k));
+                }
+                else
+                {
+                    aa = (BitArray)a.Clone();
+                }
+                for (int j = fromIndex; j < toIndex; j++) aa.Set(j, false);
+                bb = (OpenBitSet)b.Clone(); bb.Clear(fromIndex, toIndex);
+
+                DoNextSetBit(aa, bb);  // a problem here is from clear() or nextSetBit
+
+                fromIndex = rand.Next(sz + 80);
+                toIndex = fromIndex + rand.Next((sz >> 1) + 1);
+                // {{dougsale-2.4.0}}:
+                // The following commented-out, compound statement's 'for loop' implicitly grows the Java BitSet 'aa'
+                // when 'a.Count < j+1' and 'fromIndex < toIndex'
+                //aa = (BitArray)a.Clone(); for (int j = fromIndex; j < toIndex; j++) aa.Set(j, false);
+                // So, if necessary, lets explicitly grow 'aa' now
+                if (a.Count < toIndex && fromIndex < toIndex)
+                {
+                    aa = new BitArray(toIndex);
+                    for (int k = 0; k < a.Count; k++)
+                        aa.Set(k, a.Get(k));
+                }
+                else
+                {
+                    aa = (BitArray)a.Clone();
+                }
+                for (int j = fromIndex; j < toIndex; j++) aa.Set(j, true);
+                bb = (OpenBitSet)b.Clone(); bb.Set(fromIndex, toIndex);
+
+                DoNextSetBit(aa, bb);  // a problem here is from set() or nextSetBit     
+
+
+                if (a0 != null)
+                {
+                    Assert.AreEqual(a.Equals(a0), b.Equals(b0));
+
+                    Assert.AreEqual(SupportClass.Number.Cardinality(a), b.Cardinality());
+
+                    // {{dougsale-2.4.0}}
+                    //
+                    // The Java code used java.util.BitSet, which grows as needed.
+                    // When a bit, outside the dimension of the set is referenced,
+                    // the set automatically grows to the necessary size.  The
+                    // new entries default to false.
+                    //
+                    // BitArray does not grow automatically and is not growable.
+                    // Thus when BitArray instances of mismatched cardinality
+                    // interact, we must first explicitly "grow" the smaller one.
+                    //
+                    // This growth is acheived by creating a new instance of the
+                    // required size and copying the appropriate values.
+                    //
+
+                    //BitArray a_and = (BitArray)a.Clone(); a_and.And(a0);
+                    //BitArray a_or = (BitArray)a.Clone(); a_or.Or(a0);
+                    //BitArray a_xor = (BitArray)a.Clone(); a_xor.Xor(a0);
+                    //BitArray a_andn = (BitArray)a.Clone(); for (int j = 0; j < a_andn.Count; j++) if (a0.Get(j)) a_andn.Set(j, false);
+
+                    BitArray a_and;
+                    BitArray a_or;
+                    BitArray a_xor;
+                    BitArray a_andn;
+
+                    if (a.Count < a0.Count)
+                    {
+                        // the Java code would have implicitly resized 'a_and', 'a_or', 'a_xor', and 'a_andn'
+                        // in this case, so we explicitly create a resized stand-in for 'a' here, allowing for
+                        // a to keep its original size while 'a_and', 'a_or', 'a_xor', and 'a_andn' are resized
+                        BitArray tmp = new BitArray(a0.Count, false);
+                        for (int z = 0; z < a.Count; z++)
+                            tmp.Set(z, a.Get(z));
+
+                        a_and = (BitArray)tmp.Clone(); a_and.And(a0);
+                        a_or = (BitArray)tmp.Clone(); a_or.Or(a0);
+                        a_xor = (BitArray)tmp.Clone(); a_xor.Xor(a0);
+                        a_andn = (BitArray)tmp.Clone(); for (int j = 0; j < a_andn.Count; j++) if (a0.Get(j)) a_andn.Set(j, false);
+                    }
+                    else if (a.Count > a0.Count)
+                    {
+                        // the Java code would have implicitly resized 'a0' in this case, so
+                        // we explicitly do so here:
+                        BitArray tmp = new BitArray(a.Count, false);
+                        for (int z = 0; z < a0.Count; z++)
+                            tmp.Set(z, a0.Get(z));
+                        a0 = tmp;
+
+                        a_and = (BitArray)a.Clone(); a_and.And(a0);
+                        a_or = (BitArray)a.Clone(); a_or.Or(a0);
+                        a_xor = (BitArray)a.Clone(); a_xor.Xor(a0);
+                        a_andn = (BitArray)a.Clone(); for (int j = 0; j < a_andn.Count; j++) if (a0.Get(j)) a_andn.Set(j, false);
+                    }
+                    else
+                    {
+                        // 'a' and 'a0' are the same size, no explicit growing necessary
+                        a_and = (BitArray)a.Clone(); a_and.And(a0);
+                        a_or = (BitArray)a.Clone(); a_or.Or(a0);
+                        a_xor = (BitArray)a.Clone(); a_xor.Xor(a0);
+                        a_andn = (BitArray)a.Clone(); for (int j = 0; j < a_andn.Count; j++) if (a0.Get(j)) a_andn.Set(j, false);
+                    }
+
+                    OpenBitSet b_and = (OpenBitSet)b.Clone(); Assert.AreEqual(b, b_and); b_and.And(b0);
+                    OpenBitSet b_or = (OpenBitSet)b.Clone(); b_or.Or(b0);
+                    OpenBitSet b_xor = (OpenBitSet)b.Clone(); b_xor.Xor(b0);
+                    OpenBitSet b_andn = (OpenBitSet)b.Clone(); b_andn.AndNot(b0);
+
+                    DoIterate(a_and, b_and);
+                    DoIterate(a_or, b_or);
+                    DoIterate(a_xor, b_xor);
+                    DoIterate(a_andn, b_andn);
+
+                    Assert.AreEqual(SupportClass.Number.Cardinality(a_and), b_and.Cardinality());
+                    Assert.AreEqual(SupportClass.Number.Cardinality(a_or), b_or.Cardinality());
+                    Assert.AreEqual(SupportClass.Number.Cardinality(a_xor), b_xor.Cardinality());
+                    Assert.AreEqual(SupportClass.Number.Cardinality(a_andn), b_andn.Cardinality());
+
+                    // test non-mutating popcounts
+                    Assert.AreEqual(b_and.Cardinality(), OpenBitSet.IntersectionCount(b, b0));
+                    Assert.AreEqual(b_or.Cardinality(), OpenBitSet.UnionCount(b, b0));
+                    Assert.AreEqual(b_xor.Cardinality(), OpenBitSet.XorCount(b, b0));
+                    Assert.AreEqual(b_andn.Cardinality(), OpenBitSet.AndNotCount(b, b0));
+                }
+
+                a0 = a;
+                b0 = b;
+            }
+        }
+
+        // large enough to flush obvious bugs, small enough to run in <.5 sec as part of a
+        // larger testsuite.
+        [Test]
+        public void TestSmall()
+        {
+            DoRandomSets(1200, 1000);
+        }
+
+        [Test]
+        public void TestBig()
+        {
+            // uncomment to run a bigger test (~2 minutes).
+            //DoRandomSets(2000,200000);
+        }
+
+        [Test]
+        public void TestEquals()
+        {
+            OpenBitSet b1 = new OpenBitSet(1111);
+            OpenBitSet b2 = new OpenBitSet(2222);
+            Assert.IsTrue(b1.Equals(b2));
+            Assert.IsTrue(b2.Equals(b1));
+            b1.Set(10);
+            Assert.IsFalse(b1.Equals(b2));
+            Assert.IsFalse(b2.Equals(b1));
+            b2.Set(10);
+            Assert.IsTrue(b1.Equals(b2));
+            Assert.IsTrue(b2.Equals(b1));
+            b2.Set(2221);
+            Assert.IsFalse(b1.Equals(b2));
+            Assert.IsFalse(b2.Equals(b1));
+            b1.Set(2221);
+            Assert.IsTrue(b1.Equals(b2));
+            Assert.IsTrue(b2.Equals(b1));
+
+            // try different type of object
+            Assert.IsFalse(b1.Equals(new object()));
+        }
+
+    }
+}

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=798995&r1=798994&r2=798995&view=diff
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Test/Util/TestSmallFloat.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Test/Util/TestSmallFloat.cs Wed Jul 29 18:04:12 2009
@@ -22,8 +22,6 @@
 namespace Lucene.Net.Util
 {
 	
-	/// <author>  yonik
-	/// </author>
 	/// <version>  $Id$
 	/// </version>
 	[TestFixture]

Added: incubator/lucene.net/trunk/C#/src/Test/Util/TestSortedVIntList.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Test/Util/TestSortedVIntList.cs?rev=798995&view=auto
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Test/Util/TestSortedVIntList.cs (added)
+++ incubator/lucene.net/trunk/C#/src/Test/Util/TestSortedVIntList.cs Wed Jul 29 18:04:12 2009
@@ -0,0 +1,255 @@
+/**
+ * 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 NUnit.Framework;
+
+using BitArray = System.Collections.BitArray;
+
+using DocIdSetIterator = Lucene.Net.Search.DocIdSetIterator;
+
+namespace Lucene.Net.Util
+{
+    [TestFixture]
+    public class TestSortedVIntList
+    {
+
+        void tstIterator(
+                SortedVIntList vintList,
+                int[] ints)
+        {
+            for (int i = 0; i < ints.Length; i++)
+            {
+                if ((i > 0) && (ints[i - 1] == ints[i]))
+                {
+                    return; // DocNrSkipper should not skip to same document.
+                }
+            }
+            DocIdSetIterator m = vintList.Iterator();
+            for (int i = 0; i < ints.Length; i++)
+            {
+                Assert.IsTrue(m.Next(), "No end of Matcher at: " + i);
+                Assert.AreEqual(ints[i], m.Doc());
+            }
+            Assert.IsTrue((!m.Next()), "End of Matcher");
+        }
+
+        void tstVIntList(
+                SortedVIntList vintList,
+                int[] ints,
+                int expectedByteSize)
+        {
+            Assert.AreEqual(ints.Length, vintList.Size(), "Size");
+            Assert.AreEqual(expectedByteSize, vintList.GetByteSize(), "Byte size");
+            tstIterator(vintList, ints);
+        }
+
+        public void tstViaBitSet(int[] ints, int expectedByteSize)
+        {
+            int MAX_INT_FOR_BITSET = 1024 * 1024;
+            SupportClass.CollectionsSupport.BitSet bs = new SupportClass.CollectionsSupport.BitSet(ints.Length);
+            //BitArray bs = new BitArray(ints.Length);
+            for (int i = 0; i < ints.Length; i++)
+            {
+                if (ints[i] > MAX_INT_FOR_BITSET)
+                {
+                    return; // BitArray takes too much memory
+                }
+                if ((i > 0) && (ints[i - 1] == ints[i]))
+                {
+                    return; // BitArray cannot store duplicate.
+                }
+                bs.Set(ints[i]);
+            }
+            SortedVIntList svil = new SortedVIntList(bs);
+            tstVIntList(svil, ints, expectedByteSize);
+            tstVIntList(new SortedVIntList(svil.Iterator()), ints, expectedByteSize);
+        }
+
+        private static int VB1 = 0x7F;
+        private static int BIT_SHIFT = 7;
+        private static int VB2 = (VB1 << BIT_SHIFT) | VB1;
+        private static int VB3 = (VB2 << BIT_SHIFT) | VB1;
+        private static int VB4 = (VB3 << BIT_SHIFT) | VB1;
+
+        private int vIntByteSize(int i)
+        {
+            System.Diagnostics.Debug.Assert(i >= 0);
+            if (i <= VB1) return 1;
+            if (i <= VB2) return 2;
+            if (i <= VB3) return 3;
+            if (i <= VB4) return 4;
+            return 5;
+        }
+
+        private int vIntListByteSize(int[] ints)
+        {
+            int byteSize = 0;
+            int last = 0;
+            for (int i = 0; i < ints.Length; i++)
+            {
+                byteSize += vIntByteSize(ints[i] - last);
+                last = ints[i];
+            }
+            return byteSize;
+        }
+
+        public void tstInts(int[] ints)
+        {
+            int expectedByteSize = vIntListByteSize(ints);
+            try
+            {
+                tstVIntList(new SortedVIntList(ints), ints, expectedByteSize);
+                tstViaBitSet(ints, expectedByteSize);
+            }
+            catch (System.IO.IOException ioe)
+            {
+                throw new System.Exception(null, ioe);
+            }
+        }
+
+        public void tstIllegalArgExc(int[] ints)
+        {
+            try
+            {
+                new SortedVIntList(ints);
+            }
+            catch (System.ArgumentException)
+            {
+                return;
+            }
+            Assert.Fail("Expected ArgumentException");
+        }
+
+        private int[] fibArray(int a, int b, int size)
+        {
+            int[] fib = new int[size];
+            fib[0] = a;
+            fib[1] = b;
+            for (int i = 2; i < size; i++)
+            {
+                fib[i] = fib[i - 1] + fib[i - 2];
+            }
+            return fib;
+        }
+
+        private int[] reverseDiffs(int[] ints)
+        { // reverse the order of the successive differences
+            int[] res = new int[ints.Length];
+            for (int i = 0; i < ints.Length; i++)
+            {
+                res[i] = ints[ints.Length - 1] + (ints[0] - ints[ints.Length - 1 - i]);
+            }
+            return res;
+        }
+
+        [Test]
+        public void Test01()
+        {
+            tstInts(new int[] { });
+        }
+        [Test]
+        public void Test02()
+        {
+            tstInts(new int[] { 0 });
+        }
+        [Test]
+        public void Test03()
+        {
+            tstInts(new int[] { 0, int.MaxValue });
+        }
+        [Test]
+        public void Test04a()
+        {
+            tstInts(new int[] { 0, VB2 - 1 });
+        }
+        [Test]
+        public void Test04b()
+        {
+            tstInts(new int[] { 0, VB2 });
+        }
+        [Test]
+        public void Test04c()
+        {
+            tstInts(new int[] { 0, VB2 + 1 });
+        }
+        [Test]
+        public void Test05()
+        {
+            tstInts(fibArray(0, 1, 7)); // includes duplicate value 1
+        }
+        [Test]
+        public void Test05b()
+        {
+            tstInts(reverseDiffs(fibArray(0, 1, 7)));
+        }
+        [Test]
+        public void Test06()
+        {
+            tstInts(fibArray(1, 2, 45)); // no duplicates, size 46 exceeds max int.
+        }
+        [Test]
+        public void Test06b()
+        {
+            tstInts(reverseDiffs(fibArray(1, 2, 45)));
+        }
+        [Test]
+        public void Test07a()
+        {
+            tstInts(new int[] { 0, VB3 });
+        }
+        [Test]
+        public void Test07b()
+        {
+            tstInts(new int[] { 1, VB3 + 2 });
+        }
+        [Test]
+        public void Test07c()
+        {
+            tstInts(new int[] { 2, VB3 + 4 });
+        }
+        [Test]
+        public void Test08a()
+        {
+            tstInts(new int[] { 0, VB4 + 1 });
+        }
+        [Test]
+        public void Test08b()
+        {
+            tstInts(new int[] { 1, VB4 + 1 });
+        }
+        [Test]
+        public void Test08c()
+        {
+            tstInts(new int[] { 2, VB4 + 1 });
+        }
+        [Test]
+        public void Test10()
+        {
+            tstIllegalArgExc(new int[] { -1 });
+        }
+        [Test]
+        public void Test11()
+        {
+            tstIllegalArgExc(new int[] { 1, 0 });
+        }
+        [Test]
+        public void Test12()
+        {
+            tstIllegalArgExc(new int[] { 0, 1, 1, 2, 3, 5, 8, 0 });
+        }
+    }
+}

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=798995&r1=798994&r2=798995&view=diff
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Test/Util/_TestUtil.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Test/Util/_TestUtil.cs Wed Jul 29 18:04:12 2009
@@ -17,9 +17,11 @@
 
 using System;
 
+using CheckIndex = Lucene.Net.Index.CheckIndex;
 using ConcurrentMergeScheduler = Lucene.Net.Index.ConcurrentMergeScheduler;
 using IndexWriter = Lucene.Net.Index.IndexWriter;
 using MergeScheduler = Lucene.Net.Index.MergeScheduler;
+using Directory = Lucene.Net.Store.Directory;
 
 namespace Lucene.Net.Util
 {
@@ -90,14 +92,24 @@
 				((ConcurrentMergeScheduler) ms).Sync();
 		}
 
-        public static bool CheckIndex(Lucene.Net.Store.Directory dir)
+        /// <summary>
+        /// This runs the CheckIndex tool on the index in dir.
+        /// If any issues are hit, a System.Exception is thrown; else,
+        /// true is returned.
+        /// </summary>
+        /// <param name="dir"></param>
+        /// <returns></returns>
+        public static bool CheckIndex(Directory dir)
         {
-            Lucene.Net.Index.CheckIndex.out_Renamed = new System.IO.StringWriter();
-            if (!Lucene.Net.Index.CheckIndex.Check(dir, false))
+            System.IO.StringWriter sw = new System.IO.StringWriter();
+            CheckIndex checker = new CheckIndex(dir);
+            checker.SetInfoStream(sw);
+            CheckIndex.Status indexStatus = checker.CheckIndex_Renamed();
+            if (indexStatus == null || !indexStatus.clean)
             {
                 System.Console.WriteLine("CheckIndex failed");
-                System.Console.WriteLine(Lucene.Net.Index.CheckIndex.out_Renamed.ToString());
-                return false;
+                System.Console.WriteLine(sw.ToString());
+                throw new System.Exception("CheckIndex failed");
             }
             else
                 return true;



Mime
View raw message