lucenenet-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aro...@apache.org
Subject svn commit: r832486 [7/29] - in /incubator/lucene.net/trunk/C#/src: ./ Demo/DeleteFiles/ Demo/DemoLib/ Demo/IndexFiles/ Demo/IndexHtml/ Demo/SearchFiles/ Lucene.Net/ Lucene.Net/Analysis/ Lucene.Net/Document/ Lucene.Net/Index/ Lucene.Net/Search/ Lucene....
Date Tue, 03 Nov 2009 18:06:38 GMT
Modified: incubator/lucene.net/trunk/C#/src/Test/Index/TestFieldsReader.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Test/Index/TestFieldsReader.cs?rev=832486&r1=832485&r2=832486&view=diff
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Test/Index/TestFieldsReader.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Test/Index/TestFieldsReader.cs Tue Nov  3 18:06:27 2009
@@ -1,4 +1,4 @@
-/*
+/* 
  * 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.
@@ -19,23 +19,23 @@
 
 using NUnit.Framework;
 
-using LuceneTestCase = Lucene.Net.Util.LuceneTestCase;
 using WhitespaceAnalyzer = Lucene.Net.Analysis.WhitespaceAnalyzer;
 using Lucene.Net.Documents;
+using AlreadyClosedException = Lucene.Net.Store.AlreadyClosedException;
+using BufferedIndexInput = Lucene.Net.Store.BufferedIndexInput;
+using Directory = Lucene.Net.Store.Directory;
 using FSDirectory = Lucene.Net.Store.FSDirectory;
 using IndexInput = Lucene.Net.Store.IndexInput;
 using IndexOutput = Lucene.Net.Store.IndexOutput;
-using Directory = Lucene.Net.Store.Directory;
-using BufferedIndexInput = Lucene.Net.Store.BufferedIndexInput;
 using RAMDirectory = Lucene.Net.Store.RAMDirectory;
-using AlreadyClosedException = Lucene.Net.Store.AlreadyClosedException;
+using LuceneTestCase = Lucene.Net.Util.LuceneTestCase;
 using _TestUtil = Lucene.Net.Util._TestUtil;
 
 namespace Lucene.Net.Index
 {
-	
-	[TestFixture]
-	public class TestFieldsReader : LuceneTestCase
+
+    [TestFixture]
+    public class TestFieldsReader : LuceneTestCase
 	{
 		[Serializable]
 		private class AnonymousClassFieldSelector : FieldSelector
@@ -68,12 +68,17 @@
 			}
 		}
 		private RAMDirectory dir = new RAMDirectory();
-		private Lucene.Net.Documents.Document testDoc = new Lucene.Net.Documents.Document();
+		private Document testDoc = new Document();
 		private FieldInfos fieldInfos = null;
-		private System.String segmentName = null;
+		
+		private const System.String TEST_SEGMENT_NAME = "_0";
+		
+		public TestFieldsReader(System.String s):base(s)
+		{
+		}
 		
 		[SetUp]
-		public override void SetUp()
+		public override void  SetUp()
 		{
 			base.SetUp();
 			fieldInfos = new FieldInfos();
@@ -83,7 +88,6 @@
 			writer.SetUseCompoundFile(false);
 			writer.AddDocument(testDoc);
 			writer.Close();
-			segmentName = writer.NewestSegment().name;
 		}
 		
 		[Test]
@@ -91,20 +95,21 @@
 		{
 			Assert.IsTrue(dir != null);
 			Assert.IsTrue(fieldInfos != null);
-			FieldsReader reader = new FieldsReader(dir, segmentName, fieldInfos);
+			FieldsReader reader = new FieldsReader(dir, TEST_SEGMENT_NAME, fieldInfos);
 			Assert.IsTrue(reader != null);
 			Assert.IsTrue(reader.Size() == 1);
-			Lucene.Net.Documents.Document doc = reader.Doc(0, null);
+			Document doc = reader.Doc(0, null);
 			Assert.IsTrue(doc != null);
 			Assert.IsTrue(doc.GetField(DocHelper.TEXT_FIELD_1_KEY) != null);
 			
-			Field field = doc.GetField(DocHelper.TEXT_FIELD_2_KEY);
+			Fieldable field = doc.GetField(DocHelper.TEXT_FIELD_2_KEY);
 			Assert.IsTrue(field != null);
 			Assert.IsTrue(field.IsTermVectorStored() == true);
 			
 			Assert.IsTrue(field.IsStoreOffsetWithTermVector() == true);
 			Assert.IsTrue(field.IsStorePositionWithTermVector() == true);
 			Assert.IsTrue(field.GetOmitNorms() == false);
+			Assert.IsTrue(field.GetOmitTf() == false);
 			
 			field = doc.GetField(DocHelper.TEXT_FIELD_3_KEY);
 			Assert.IsTrue(field != null);
@@ -112,31 +117,39 @@
 			Assert.IsTrue(field.IsStoreOffsetWithTermVector() == false);
 			Assert.IsTrue(field.IsStorePositionWithTermVector() == false);
 			Assert.IsTrue(field.GetOmitNorms() == true);
+			Assert.IsTrue(field.GetOmitTf() == false);
 			
-			
+			field = doc.GetField(DocHelper.NO_TF_KEY);
+			Assert.IsTrue(field != null);
+			Assert.IsTrue(field.IsTermVectorStored() == false);
+			Assert.IsTrue(field.IsStoreOffsetWithTermVector() == false);
+			Assert.IsTrue(field.IsStorePositionWithTermVector() == false);
+			Assert.IsTrue(field.GetOmitNorms() == false);
+			Assert.IsTrue(field.GetOmitTf() == true);
 			reader.Close();
 		}
 		
+		
 		[Test]
 		public virtual void  TestLazyFields()
 		{
 			Assert.IsTrue(dir != null);
 			Assert.IsTrue(fieldInfos != null);
-			FieldsReader reader = new FieldsReader(dir, segmentName, fieldInfos);
+			FieldsReader reader = new FieldsReader(dir, TEST_SEGMENT_NAME, fieldInfos);
 			Assert.IsTrue(reader != null);
 			Assert.IsTrue(reader.Size() == 1);
 			System.Collections.Hashtable loadFieldNames = new System.Collections.Hashtable();
-			loadFieldNames.Add(DocHelper.TEXT_FIELD_1_KEY, DocHelper.TEXT_FIELD_1_KEY);
-			loadFieldNames.Add(DocHelper.TEXT_FIELD_UTF1_KEY, DocHelper.TEXT_FIELD_UTF1_KEY);
+			SupportClass.CollectionsHelper.AddIfNotContains(loadFieldNames, DocHelper.TEXT_FIELD_1_KEY);
+			SupportClass.CollectionsHelper.AddIfNotContains(loadFieldNames, DocHelper.TEXT_FIELD_UTF1_KEY);
 			System.Collections.Hashtable lazyFieldNames = new System.Collections.Hashtable();
 			//new String[]{DocHelper.LARGE_LAZY_FIELD_KEY, DocHelper.LAZY_FIELD_KEY, DocHelper.LAZY_FIELD_BINARY_KEY};
-			lazyFieldNames.Add(DocHelper.LARGE_LAZY_FIELD_KEY, DocHelper.LARGE_LAZY_FIELD_KEY);
-			lazyFieldNames.Add(DocHelper.LAZY_FIELD_KEY, DocHelper.LAZY_FIELD_KEY);
-			lazyFieldNames.Add(DocHelper.LAZY_FIELD_BINARY_KEY, DocHelper.LAZY_FIELD_BINARY_KEY);
-			lazyFieldNames.Add(DocHelper.TEXT_FIELD_UTF2_KEY, DocHelper.TEXT_FIELD_UTF2_KEY);
-			lazyFieldNames.Add(DocHelper.COMPRESSED_TEXT_FIELD_2_KEY, DocHelper.COMPRESSED_TEXT_FIELD_2_KEY);
+			SupportClass.CollectionsHelper.AddIfNotContains(lazyFieldNames, DocHelper.LARGE_LAZY_FIELD_KEY);
+			SupportClass.CollectionsHelper.AddIfNotContains(lazyFieldNames, DocHelper.LAZY_FIELD_KEY);
+			SupportClass.CollectionsHelper.AddIfNotContains(lazyFieldNames, DocHelper.LAZY_FIELD_BINARY_KEY);
+			SupportClass.CollectionsHelper.AddIfNotContains(lazyFieldNames, DocHelper.TEXT_FIELD_UTF2_KEY);
+			SupportClass.CollectionsHelper.AddIfNotContains(lazyFieldNames, DocHelper.COMPRESSED_TEXT_FIELD_2_KEY);
 			SetBasedFieldSelector fieldSelector = new SetBasedFieldSelector(loadFieldNames, lazyFieldNames);
-			Lucene.Net.Documents.Document doc = reader.Doc(0, fieldSelector);
+			Document doc = reader.Doc(0, fieldSelector);
 			Assert.IsTrue(doc != null, "doc is null and it shouldn't be");
 			Fieldable field = doc.GetFieldable(DocHelper.LAZY_FIELD_KEY);
 			Assert.IsTrue(field != null, "field is null and it shouldn't be");
@@ -147,7 +160,7 @@
 			field = doc.GetFieldable(DocHelper.COMPRESSED_TEXT_FIELD_2_KEY);
 			Assert.IsTrue(field != null, "field is null and it shouldn't be");
 			Assert.IsTrue(field.IsLazy(), "field is not lazy and it should be");
-            Assert.IsTrue(field.BinaryValue() == null, "binary value isn't null for lazy
string field");
+			Assert.IsTrue(field.BinaryValue() == null, "binaryValue isn't null for lazy string field");
 			value_Renamed = field.StringValue();
 			Assert.IsTrue(value_Renamed != null, "value is null and it shouldn't be");
 			Assert.IsTrue(value_Renamed.Equals(DocHelper.FIELD_2_COMPRESSED_TEXT) == true, value_Renamed
+ " is not equal to " + DocHelper.FIELD_2_COMPRESSED_TEXT);
@@ -166,8 +179,8 @@
 			
 			field = doc.GetFieldable(DocHelper.LAZY_FIELD_BINARY_KEY);
 			Assert.IsTrue(field != null, "field is null and it shouldn't be");
-            Assert.IsTrue(field.StringValue() == null, "stringValue isn't null for lazy binary
field");
-
+			Assert.IsTrue(field.StringValue() == null, "stringValue isn't null for lazy binary field");
+			
 			byte[] bytes = field.BinaryValue();
 			Assert.IsTrue(bytes != null, "bytes is null and it shouldn't be");
 			Assert.IsTrue(DocHelper.LAZY_FIELD_BINARY_BYTES.Length == bytes.Length, "");
@@ -182,18 +195,18 @@
 		{
 			Assert.IsTrue(dir != null);
 			Assert.IsTrue(fieldInfos != null);
-			FieldsReader reader = new FieldsReader(dir, segmentName, fieldInfos);
+			FieldsReader reader = new FieldsReader(dir, TEST_SEGMENT_NAME, fieldInfos);
 			Assert.IsTrue(reader != null);
 			Assert.IsTrue(reader.Size() == 1);
 			System.Collections.Hashtable loadFieldNames = new System.Collections.Hashtable();
-			loadFieldNames.Add(DocHelper.TEXT_FIELD_1_KEY, DocHelper.TEXT_FIELD_1_KEY);
-			loadFieldNames.Add(DocHelper.TEXT_FIELD_UTF1_KEY, DocHelper.TEXT_FIELD_UTF1_KEY);
+			SupportClass.CollectionsHelper.AddIfNotContains(loadFieldNames, DocHelper.TEXT_FIELD_1_KEY);
+			SupportClass.CollectionsHelper.AddIfNotContains(loadFieldNames, DocHelper.TEXT_FIELD_UTF1_KEY);
 			System.Collections.Hashtable lazyFieldNames = new System.Collections.Hashtable();
-			lazyFieldNames.Add(DocHelper.LARGE_LAZY_FIELD_KEY, DocHelper.LARGE_LAZY_FIELD_KEY);
-			lazyFieldNames.Add(DocHelper.LAZY_FIELD_KEY, DocHelper.LAZY_FIELD_KEY);
-			lazyFieldNames.Add(DocHelper.LAZY_FIELD_BINARY_KEY, DocHelper.LAZY_FIELD_BINARY_KEY);
-			lazyFieldNames.Add(DocHelper.TEXT_FIELD_UTF2_KEY, DocHelper.TEXT_FIELD_UTF2_KEY);
-			lazyFieldNames.Add(DocHelper.COMPRESSED_TEXT_FIELD_2_KEY, DocHelper.COMPRESSED_TEXT_FIELD_2_KEY);
+			SupportClass.CollectionsHelper.AddIfNotContains(lazyFieldNames, DocHelper.LARGE_LAZY_FIELD_KEY);
+			SupportClass.CollectionsHelper.AddIfNotContains(lazyFieldNames, DocHelper.LAZY_FIELD_KEY);
+			SupportClass.CollectionsHelper.AddIfNotContains(lazyFieldNames, DocHelper.LAZY_FIELD_BINARY_KEY);
+			SupportClass.CollectionsHelper.AddIfNotContains(lazyFieldNames, DocHelper.TEXT_FIELD_UTF2_KEY);
+			SupportClass.CollectionsHelper.AddIfNotContains(lazyFieldNames, DocHelper.COMPRESSED_TEXT_FIELD_2_KEY);
 			SetBasedFieldSelector fieldSelector = new SetBasedFieldSelector(loadFieldNames, lazyFieldNames);
 			Document doc = reader.Doc(0, fieldSelector);
 			Assert.IsTrue(doc != null, "doc is null and it shouldn't be");
@@ -206,7 +219,7 @@
 				field.StringValue();
 				Assert.Fail("did not hit AlreadyClosedException as expected");
 			}
-			catch (AlreadyClosedException)
+			catch (AlreadyClosedException e)
 			{
 				// expected
 			}
@@ -217,11 +230,11 @@
 		{
 			Assert.IsTrue(dir != null);
 			Assert.IsTrue(fieldInfos != null);
-			FieldsReader reader = new FieldsReader(dir, segmentName, fieldInfos);
+			FieldsReader reader = new FieldsReader(dir, TEST_SEGMENT_NAME, fieldInfos);
 			Assert.IsTrue(reader != null);
 			Assert.IsTrue(reader.Size() == 1);
 			LoadFirstFieldSelector fieldSelector = new LoadFirstFieldSelector();
-			Lucene.Net.Documents.Document doc = reader.Doc(0, fieldSelector);
+			Document doc = reader.Doc(0, fieldSelector);
 			Assert.IsTrue(doc != null, "doc is null and it shouldn't be");
 			int count = 0;
 			System.Collections.IList l = doc.GetFields();
@@ -250,14 +263,13 @@
 			System.String path = tmpIODir + System.IO.Path.DirectorySeparatorChar.ToString() + "lazyDir"
+ userName;
 			System.IO.FileInfo file = new System.IO.FileInfo(path);
 			_TestUtil.RmDir(file);
-			FSDirectory tmpDir = FSDirectory.GetDirectory(file);
+			FSDirectory tmpDir = FSDirectory.Open(file);
 			Assert.IsTrue(tmpDir != null);
-
-            IndexWriter writer = new IndexWriter(tmpDir, new WhitespaceAnalyzer(), true,
IndexWriter.MaxFieldLength.LIMITED);
+			
+			IndexWriter writer = new IndexWriter(tmpDir, new WhitespaceAnalyzer(), true, IndexWriter.MaxFieldLength.LIMITED);
 			writer.SetUseCompoundFile(false);
 			writer.AddDocument(testDoc);
 			writer.Close();
-			segmentName = writer.NewestSegment().name;
 			
 			Assert.IsTrue(fieldInfos != null);
 			FieldsReader reader;
@@ -265,16 +277,16 @@
 			long regularTime = 0;
 			int length = 50;
 			System.Collections.Hashtable lazyFieldNames = new System.Collections.Hashtable();
-			lazyFieldNames.Add(DocHelper.LARGE_LAZY_FIELD_KEY, DocHelper.LARGE_LAZY_FIELD_KEY);
+			SupportClass.CollectionsHelper.AddIfNotContains(lazyFieldNames, DocHelper.LARGE_LAZY_FIELD_KEY);
 			SetBasedFieldSelector fieldSelector = new SetBasedFieldSelector(new System.Collections.Hashtable(),
lazyFieldNames);
 			
 			for (int i = 0; i < length; i++)
 			{
-				reader = new FieldsReader(tmpDir, segmentName, fieldInfos);
+				reader = new FieldsReader(tmpDir, TEST_SEGMENT_NAME, fieldInfos);
 				Assert.IsTrue(reader != null);
 				Assert.IsTrue(reader.Size() == 1);
 				
-				Lucene.Net.Documents.Document doc;
+				Document doc;
 				doc = reader.Doc(0, null); //Load all of them
 				Assert.IsTrue(doc != null, "doc is null and it shouldn't be");
 				Fieldable field = doc.GetFieldable(DocHelper.LARGE_LAZY_FIELD_KEY);
@@ -294,7 +306,7 @@
 				doc = null;
 				//Hmmm, are we still in cache???
 				System.GC.Collect();
-				reader = new FieldsReader(tmpDir, segmentName, fieldInfos);
+				reader = new FieldsReader(tmpDir, TEST_SEGMENT_NAME, fieldInfos);
 				doc = reader.Doc(0, fieldSelector);
 				field = doc.GetFieldable(DocHelper.LARGE_LAZY_FIELD_KEY);
 				Assert.IsTrue(field.IsLazy() == true, "field is not lazy");
@@ -313,8 +325,8 @@
 		[Test]
 		public virtual void  TestLoadSize()
 		{
-			FieldsReader reader = new FieldsReader(dir, segmentName, fieldInfos);
-			Lucene.Net.Documents.Document doc;
+			FieldsReader reader = new FieldsReader(dir, TEST_SEGMENT_NAME, fieldInfos);
+			Document doc;
 			
 			doc = reader.Doc(0, new AnonymousClassFieldSelector(this));
 			Fieldable f1 = doc.GetFieldable(DocHelper.TEXT_FIELD_1_KEY);
@@ -332,150 +344,160 @@
 		
 		private void  AssertSizeEquals(int size, byte[] sizebytes)
 		{
-			Assert.AreEqual((byte) (size >> 24), sizebytes[0]);
-			Assert.AreEqual((byte) (size >> 16), sizebytes[1]);
-			Assert.AreEqual((byte) (size >> 8), sizebytes[2]);
+			Assert.AreEqual((byte) (SupportClass.Number.URShift(size, 24)), sizebytes[0]);
+			Assert.AreEqual((byte) (SupportClass.Number.URShift(size, 16)), sizebytes[1]);
+			Assert.AreEqual((byte) (SupportClass.Number.URShift(size, 8)), sizebytes[2]);
 			Assert.AreEqual((byte) size, sizebytes[3]);
 		}
-
-        public class FaultyFSDirectory : Directory
-        {
-            FSDirectory fsDir;
-            public FaultyFSDirectory(System.IO.FileInfo dir)
-            {
-                fsDir = FSDirectory.GetDirectory(dir);
-                lockFactory = fsDir.GetLockFactory();
-            }
-            public override IndexInput OpenInput(String name)
-            {
-                return new FaultyIndexInput(fsDir.OpenInput(name));
-            }
-            public override string[] List()
-            {
-                return fsDir.List();
-            }
-            public override bool FileExists(string name)
-            {
-                return fsDir.FileExists(name);
-            }
-            public override long FileModified(string name)
-            {
-                return fsDir.FileModified(name);
-            }
-            public override void TouchFile(string name)
-            {
-                fsDir.TouchFile(name);
-            }
-            public override void DeleteFile(string name)
-            {
-                fsDir.DeleteFile(name);
-            }
-            public override void RenameFile(string name, string newName)
-            {
-                fsDir.RenameFile(name, newName);
-            }
-            public override long FileLength(string name)
-            {
-                return fsDir.FileLength(name);
-            }
-            public override IndexOutput CreateOutput(string name)
-            {
-                return fsDir.CreateOutput(name);
-            }
-            public override void Close()
-            {
-                fsDir.Close();
-            }
-        }
-
-        public class FaultyIndexInput : BufferedIndexInput
-        {
-            IndexInput indexInput;
-            internal static bool doFail;
-            int count;
-            public FaultyIndexInput(IndexInput indexInput)
-            {
-                this.indexInput = indexInput;
-            }
-            private void SimOutage()
-            {
-                if (doFail && count++ % 2 == 1)
-                {
-                    throw new System.IO.IOException("Simulated network outage");
-                }
-            }
-            protected override void ReadInternal(byte[] b, int offset, int length)
-            {
-                SimOutage();
-                indexInput.ReadBytes(b, offset, length);
-            }
-            protected override void SeekInternal(long pos)
-            {
-                //simOutage();
-                indexInput.Seek(pos);
-            }
-            public override long Length()
-            {
-                return indexInput.Length();
-            }
-            public override void Close()
-            {
-                indexInput.Close();
-            }
-            public override object Clone()
-            {
-                return new FaultyIndexInput((IndexInput)indexInput.Clone());
-            }
-        }
-
-        // LUCENE-1262
-        [Test]
-        public void TestExceptions()
-        {
-            string tempDir = SupportClass.AppSettings.Get("tempDir", "");
-            if (tempDir == null)
-                throw new System.IO.IOException("java.io.tmpdir undefined, cannot run test");
-            System.IO.FileInfo indexDir = new System.IO.FileInfo(System.IO.Path.Combine(tempDir,
"testfieldswriterexceptions"));
-            try
-            {
-                Directory dir = new FaultyFSDirectory(indexDir);
-                IndexWriter writer = new IndexWriter(dir, new WhitespaceAnalyzer(), true,
IndexWriter.MaxFieldLength.LIMITED);
-                for (int i = 0; i < 2; i++)
-                    writer.AddDocument(testDoc);
-                writer.Optimize();
-                writer.Close();
-                IndexReader reader = IndexReader.Open(dir);
-                FaultyIndexInput.doFail = true;
-                bool exc = false;
-                for (int i = 0; i < 2; i++)
-                {
-                    try
-                    {
-                        reader.Document(i);
-                    }
-                    catch (System.IO.IOException)
-                    {
-                        // expected
-                        exc = true;
-                    }
-                    try
-                    {
-                        reader.Document(i);
-                    }
-                    catch (System.IO.IOException)
-                    {
-                        // expected
-                        exc = true;
-                    }
-                }
-                Assert.IsTrue(exc);
-                reader.Close();
-                dir.Close();
-            }
-            finally
-            {
-                _TestUtil.RmDir(indexDir);
-            }
-        }
-    }
+		
+		public class FaultyFSDirectory:Directory
+		{
+			
+			internal FSDirectory fsDir;
+			public FaultyFSDirectory(System.IO.FileInfo dir)
+			{
+				fsDir = FSDirectory.Open(dir);
+				lockFactory = fsDir.GetLockFactory();
+			}
+			public override IndexInput OpenInput(System.String name)
+			{
+				return new FaultyIndexInput(fsDir.OpenInput(name));
+			}
+			public override System.String[] List()
+			{
+				return fsDir.List();
+			}
+			public override System.String[] ListAll()
+			{
+				return fsDir.ListAll();
+			}
+			public override bool FileExists(System.String name)
+			{
+				return fsDir.FileExists(name);
+			}
+			public override long FileModified(System.String name)
+			{
+				return fsDir.FileModified(name);
+			}
+			public override void  TouchFile(System.String name)
+			{
+				fsDir.TouchFile(name);
+			}
+			public override void  DeleteFile(System.String name)
+			{
+				fsDir.DeleteFile(name);
+			}
+			public override void  RenameFile(System.String name, System.String newName)
+			{
+				fsDir.RenameFile(name, newName);
+			}
+			public override long FileLength(System.String name)
+			{
+				return fsDir.FileLength(name);
+			}
+			public override IndexOutput CreateOutput(System.String name)
+			{
+				return fsDir.CreateOutput(name);
+			}
+			public override void  Close()
+			{
+				fsDir.Close();
+			}
+		}
+		
+		private class FaultyIndexInput:BufferedIndexInput, System.ICloneable
+		{
+			internal IndexInput delegate_Renamed;
+			internal static bool doFail;
+			internal int count;
+			internal FaultyIndexInput(IndexInput delegate_Renamed)
+			{
+				this.delegate_Renamed = delegate_Renamed;
+			}
+			private void  SimOutage()
+			{
+				if (doFail && count++ % 2 == 1)
+				{
+					throw new System.IO.IOException("Simulated network outage");
+				}
+			}
+			public override void  ReadInternal(byte[] b, int offset, int length)
+			{
+				SimOutage();
+				delegate_Renamed.ReadBytes(b, offset, length);
+			}
+			public override void  SeekInternal(long pos)
+			{
+				//simOutage();
+				delegate_Renamed.Seek(pos);
+			}
+			public override long Length()
+			{
+				return delegate_Renamed.Length();
+			}
+			public override void  Close()
+			{
+				delegate_Renamed.Close();
+			}
+			public override System.Object Clone()
+			{
+				return new FaultyIndexInput((IndexInput) delegate_Renamed.Clone());
+			}
+		}
+		
+		// LUCENE-1262
+		[Test]
+		public virtual void  TestExceptions()
+		{
+			System.String tempDir = System.IO.Path.GetTempPath();
+			if (tempDir == null)
+				throw new System.IO.IOException("java.io.tmpdir undefined, cannot run test");
+			System.IO.FileInfo indexDir = new System.IO.FileInfo(System.IO.Path.Combine(tempDir, "testfieldswriterexceptions"));
+			
+			try
+			{
+				Directory dir = new FaultyFSDirectory(indexDir);
+				IndexWriter writer = new IndexWriter(dir, new WhitespaceAnalyzer(), true, IndexWriter.MaxFieldLength.LIMITED);
+				for (int i = 0; i < 2; i++)
+					writer.AddDocument(testDoc);
+				writer.Optimize();
+				writer.Close();
+				
+				IndexReader reader = IndexReader.Open(dir);
+				
+				FaultyIndexInput.doFail = true;
+				
+				bool exc = false;
+				
+				for (int i = 0; i < 2; i++)
+				{
+					try
+					{
+						reader.Document(i);
+					}
+					catch (System.IO.IOException ioe)
+					{
+						// expected
+						exc = true;
+					}
+					try
+					{
+						reader.Document(i);
+					}
+					catch (System.IO.IOException ioe)
+					{
+						// expected
+						exc = true;
+					}
+				}
+				Assert.IsTrue(exc);
+				reader.Close();
+				dir.Close();
+			}
+			finally
+			{
+				_TestUtil.RmDir(indexDir);
+			}
+		}
+	}
 }
\ No newline at end of file

Modified: incubator/lucene.net/trunk/C#/src/Test/Index/TestFilterIndexReader.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Test/Index/TestFilterIndexReader.cs?rev=832486&r1=832485&r2=832486&view=diff
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Test/Index/TestFilterIndexReader.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Test/Index/TestFilterIndexReader.cs Tue Nov  3 18:06:27
2009
@@ -1,4 +1,4 @@
-/*
+/* 
  * 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.
@@ -19,26 +19,25 @@
 
 using NUnit.Framework;
 
-//using TestRunner = junit.textui.TestRunner;
+using WhitespaceAnalyzer = Lucene.Net.Analysis.WhitespaceAnalyzer;
 using Document = Lucene.Net.Documents.Document;
 using Field = Lucene.Net.Documents.Field;
 using MockRAMDirectory = Lucene.Net.Store.MockRAMDirectory;
 using RAMDirectory = Lucene.Net.Store.RAMDirectory;
 using LuceneTestCase = Lucene.Net.Util.LuceneTestCase;
-using WhitespaceAnalyzer = Lucene.Net.Analysis.WhitespaceAnalyzer;
 
 namespace Lucene.Net.Index
 {
 	
-	[TestFixture]
-	public class TestFilterIndexReader : LuceneTestCase
+    [TestFixture]
+	public class TestFilterIndexReader:LuceneTestCase
 	{
 		
-		private class TestReader : FilterIndexReader
+		private class TestReader:FilterIndexReader
 		{
 			
 			/// <summary>Filter that only permits terms containing 'e'.</summary>
-			private class TestTermEnum : FilterTermEnum
+			private class TestTermEnum:FilterTermEnum
 			{
 				public TestTermEnum(TermEnum termEnum):base(termEnum)
 				{
@@ -57,9 +56,9 @@
 			}
 			
 			/// <summary>Filter that only returns odd numbered documents. </summary>
-			private class TestTermPositions : FilterTermPositions
+			private class TestTermPositions:FilterTermPositions
 			{
-				public TestTermPositions(TermPositions in_Renamed) : base(in_Renamed)
+				public TestTermPositions(TermPositions in_Renamed):base(in_Renamed)
 				{
 				}
 				
@@ -75,7 +74,7 @@
 				}
 			}
 			
-			public TestReader(IndexReader reader) : base(reader)
+			public TestReader(IndexReader reader):base(reader)
 			{
 			}
 			
@@ -97,26 +96,26 @@
 		[STAThread]
 		public static void  Main(System.String[] args)
 		{
-			// NUnit.Core.TestRunner.Run(new NUnit.Core.TestSuite(typeof(TestIndexReader)));   //
{{Aroush}} where is 'Run' in NUnit?
+			// TestRunner.run(new TestSuite(typeof(TestIndexReader))); // {{Aroush-2.9}} How do you
do this in NUnit?
 		}
 		
 		/// <summary> Tests the IndexReader.getFieldNames implementation</summary>
 		/// <throws>  Exception on error </throws>
 		[Test]
-		public virtual void  TestFilterIndexReader_Renamed_Method()
+		public virtual void  TestFilterIndexReader_Renamed()
 		{
 			RAMDirectory directory = new MockRAMDirectory();
 			IndexWriter writer = new IndexWriter(directory, new WhitespaceAnalyzer(), true, IndexWriter.MaxFieldLength.LIMITED);
 			
-			Lucene.Net.Documents.Document d1 = new Lucene.Net.Documents.Document();
+			Document d1 = new Document();
 			d1.Add(new Field("default", "one two", Field.Store.YES, Field.Index.ANALYZED));
 			writer.AddDocument(d1);
 			
-			Lucene.Net.Documents.Document d2 = new Lucene.Net.Documents.Document();
+			Document d2 = new Document();
 			d2.Add(new Field("default", "one three", Field.Store.YES, Field.Index.ANALYZED));
 			writer.AddDocument(d2);
 			
-			Lucene.Net.Documents.Document d3 = new Lucene.Net.Documents.Document();
+			Document d3 = new Document();
 			d3.Add(new Field("default", "two four", Field.Store.YES, Field.Index.ANALYZED));
 			writer.AddDocument(d3);
 			
@@ -139,6 +138,16 @@
 				Assert.IsTrue((positions.Doc() % 2) == 1);
 			}
 			
+			int NUM_DOCS = 3;
+			
+			TermDocs td = reader.TermDocs(null);
+			for (int i = 0; i < NUM_DOCS; i++)
+			{
+				Assert.IsTrue(td.Next());
+				Assert.AreEqual(i, td.Doc());
+				Assert.AreEqual(1, td.Freq());
+			}
+			td.Close();
 			reader.Close();
 			directory.Close();
 		}

Modified: incubator/lucene.net/trunk/C#/src/Test/Index/TestIndexFileDeleter.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Test/Index/TestIndexFileDeleter.cs?rev=832486&r1=832485&r2=832486&view=diff
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Test/Index/TestIndexFileDeleter.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Test/Index/TestIndexFileDeleter.cs Tue Nov  3 18:06:27
2009
@@ -1,4 +1,4 @@
-/*
+/* 
  * 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.
@@ -19,14 +19,14 @@
 
 using NUnit.Framework;
 
-using LuceneTestCase = Lucene.Net.Util.LuceneTestCase;
 using WhitespaceAnalyzer = Lucene.Net.Analysis.WhitespaceAnalyzer;
+using Document = Lucene.Net.Documents.Document;
+using Field = Lucene.Net.Documents.Field;
 using Directory = Lucene.Net.Store.Directory;
 using IndexInput = Lucene.Net.Store.IndexInput;
 using IndexOutput = Lucene.Net.Store.IndexOutput;
 using RAMDirectory = Lucene.Net.Store.RAMDirectory;
-using Document = Lucene.Net.Documents.Document;
-using Field = Lucene.Net.Documents.Field;
+using LuceneTestCase = Lucene.Net.Util.LuceneTestCase;
 
 namespace Lucene.Net.Index
 {
@@ -35,8 +35,8 @@
 	Verify we can read the pre-2.1 file format, do searches
 	against it, and add documents to it.*/
 	
-	[TestFixture]
-	public class TestIndexFileDeleter : LuceneTestCase
+    [TestFixture]
+	public class TestIndexFileDeleter:LuceneTestCase
 	{
 		[Test]
 		public virtual void  TestDeleteLeftoverFiles()
@@ -70,12 +70,12 @@
 			
 			// Now, artificially create an extra .del file & extra
 			// .s0 file:
-			System.String[] files = dir.List();
+			System.String[] files = dir.ListAll();
 			
-			for(int j=0;j<files.Length;j++) {
-			System.Console.Out.WriteLine(j + ": " + files[j]);
-			}
 			/*
+			for(int j=0;j<files.length;j++) {
+			System.out.println(j + ": " + files[j]);
+			}
 			*/
 			
 			// The numbering of fields can vary depending on which
@@ -90,7 +90,7 @@
 			for (i = 0; i < fieldInfos.Size(); i++)
 			{
 				FieldInfo fi = fieldInfos.FieldInfo(i);
-				if (fi.Name_ForNUnitTest.Equals("content"))
+				if (fi.name_ForNUnit.Equals("content"))
 				{
 					contentFieldIndex = i;
 					break;
@@ -149,25 +149,61 @@
 			// Create a bogus cfs file shadowing a non-cfs segment:
 			CopyFile(dir, "_2.cfs", "_3.cfs");
 			
-			System.String[] filesPre = dir.List();
+			System.String[] filesPre = dir.ListAll();
 			
 			// Open & close a writer: it should delete the above 4
 			// files and nothing more:
-            writer = new IndexWriter(dir, new WhitespaceAnalyzer(), false, IndexWriter.MaxFieldLength.LIMITED);
+			writer = new IndexWriter(dir, new WhitespaceAnalyzer(), false, IndexWriter.MaxFieldLength.LIMITED);
 			writer.Close();
 			
-			System.String[] files2 = dir.List();
+			System.String[] files2 = dir.ListAll();
 			dir.Close();
 			
 			System.Array.Sort(files);
 			System.Array.Sort(files2);
 			
-			if (!ArrayEquals(files, files2))
+			System.Collections.Hashtable dif = DifFiles(files, files2);
+			
+			if (!SupportClass.CollectionsHelper.Equals(files, files2))
 			{
-				Assert.Fail("IndexFileDeleter failed to delete unreferenced extra files: should have
deleted " + (filesPre.Length - files.Length) + " files but only deleted " + (filesPre.Length
- files2.Length) + "; expected files:\n    " + AsString(files) + "\n  actual files:\n    "
+ AsString(files2));
+				Assert.Fail("IndexFileDeleter failed to delete unreferenced extra files: should have
deleted " + (filesPre.Length - files.Length) + " files but only deleted " + (filesPre.Length
- files2.Length) + "; expected files:\n    " + AsString(files) + "\n  actual files:\n    "
+ AsString(files2) + "\ndif: " + SupportClass.CollectionsHelper.CollectionToString(dif));
 			}
 		}
 		
+		private static System.Collections.Hashtable DifFiles(System.String[] files1, System.String[]
files2)
+		{
+			System.Collections.Hashtable set1 = new System.Collections.Hashtable();
+			System.Collections.Hashtable set2 = new System.Collections.Hashtable();
+			System.Collections.Hashtable extra = new System.Collections.Hashtable();
+			for (int x = 0; x < files1.Length; x++)
+			{
+				SupportClass.CollectionsHelper.AddIfNotContains(set1, files1[x]);
+			}
+			for (int x = 0; x < files2.Length; x++)
+			{
+				SupportClass.CollectionsHelper.AddIfNotContains(set2, files2[x]);
+			}
+			System.Collections.IEnumerator i1 = set1.GetEnumerator();
+			while (i1.MoveNext())
+			{
+				System.Object o = i1.Current;
+				if (!set2.Contains(o))
+				{
+					SupportClass.CollectionsHelper.AddIfNotContains(extra, o);
+				}
+			}
+			System.Collections.IEnumerator i2 = set2.GetEnumerator();
+			while (i2.MoveNext())
+			{
+				System.Object o = i2.Current;
+				if (!set1.Contains(o))
+				{
+					SupportClass.CollectionsHelper.AddIfNotContains(extra, o);
+				}
+			}
+			return extra;
+		}
+		
 		private System.String AsString(System.String[] l)
 		{
 			System.String s = "";
@@ -201,34 +237,10 @@
 		
 		private void  AddDoc(IndexWriter writer, int id)
 		{
-			Lucene.Net.Documents.Document doc = new Lucene.Net.Documents.Document();
+			Document doc = new Document();
 			doc.Add(new Field("content", "aaa", Field.Store.NO, Field.Index.ANALYZED));
 			doc.Add(new Field("id", System.Convert.ToString(id), Field.Store.YES, Field.Index.NOT_ANALYZED));
 			writer.AddDocument(doc);
 		}
-
-		public static bool ArrayEquals(System.Array array1, System.Array array2)
-		{
-			bool result = false;
-			if ((array1 == null) && (array2 == null))
-				result = true;
-			else if ((array1 != null) && (array2 != null))
-			{
-				if (array1.Length == array2.Length)
-				{
-					int length = array1.Length;
-					result = true;
-					for (int index = 0; index < length; index++)
-					{
-						if (!(array1.GetValue(index).Equals(array2.GetValue(index))))
-						{
-							result = false;
-							break;
-						}
-					}
-				}
-			}
-			return result;
-		}
 	}
 }
\ No newline at end of file

Modified: incubator/lucene.net/trunk/C#/src/Test/Index/TestIndexInput.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Test/Index/TestIndexInput.cs?rev=832486&r1=832485&r2=832486&view=diff
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Test/Index/TestIndexInput.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Test/Index/TestIndexInput.cs Tue Nov  3 18:06:27 2009
@@ -1,4 +1,4 @@
-/*
+/* 
  * 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.
@@ -24,101 +24,44 @@
 
 namespace Lucene.Net.Index
 {
-	[TestFixture]
-	public class TestIndexInput : LuceneTestCase
+	
+    [TestFixture]
+	public class TestIndexInput:LuceneTestCase
 	{
 		[Test]
-        public void TestRead()
-        {
-            IndexInput is_Renamed = new MockIndexInput(
-                new byte[] { 
-                    (byte) 0x80, 0x01,
-                    (byte) 0xFF, 0x7F,
-                    (byte) 0x80, (byte) 0x80, 0x01,
-                    (byte) 0x81, (byte) 0x80, 0x01,
-                    0x06, (byte) 'L', (byte) 'u', (byte) 'c', (byte) 'e', (byte) 'n', (byte)
'e',
-
-                    // 2-byte UTF-8 (U+00BF "INVERTED QUESTION MARK") 
-                    0x02, (byte) 0xC2, (byte) 0xBF,
-                    0x0A, (byte) 'L', (byte) 'u', (byte) 0xC2, (byte) 0xBF, 
-                        (byte) 'c', (byte) 'e', (byte) 0xC2, (byte) 0xBF, 
-                        (byte) 'n', (byte) 'e',
-
-                    // 3-byte UTF-8 (U+2620 "SKULL AND CROSSBONES") 
-                    0x03, (byte) 0xE2, (byte) 0x98, (byte) 0xA0,
-                    0x0C, (byte) 'L', (byte) 'u', (byte) 0xE2, (byte) 0x98, (byte) 0xA0,
-                        (byte) 'c', (byte) 'e', (byte) 0xE2, (byte) 0x98, (byte) 0xA0,
-                        (byte) 'n', (byte) 'e',
-
-                    // surrogate pairs
-                    // (U+1D11E "MUSICAL SYMBOL G CLEF")
-                    // (U+1D160 "MUSICAL SYMBOL EIGHTH NOTE")
-                    0x04, (byte) 0xF0, (byte) 0x9D, (byte) 0x84, (byte) 0x9E,
-                    0x08, (byte) 0xF0, (byte) 0x9D, (byte) 0x84, (byte) 0x9E, 
-                        (byte) 0xF0, (byte) 0x9D, (byte) 0x85, (byte) 0xA0, 
-                    0x0E, (byte) 'L', (byte) 'u',
-                        (byte) 0xF0, (byte) 0x9D, (byte) 0x84, (byte) 0x9E,
-                        (byte) 'c', (byte) 'e', 
-                        (byte) 0xF0, (byte) 0x9D, (byte) 0x85, (byte) 0xA0, 
-                        (byte) 'n', (byte) 'e',  
-
-                    // null bytes
-                    0x01, 0x00,
-                    0x08, (byte) 'L', (byte) 'u', 0x00, (byte) 'c', (byte) 'e', 0x00, (byte)
'n', (byte) 'e',
-
-                    // Modified UTF-8 null bytes
-                    0x02, (byte) 0xC0, (byte) 0x80,
-                    0x0A, (byte) 'L', (byte) 'u', (byte) 0xC0, (byte) 0x80, 
-                        (byte) 'c', (byte) 'e', (byte) 0xC0, (byte) 0x80, 
-                        (byte) 'n', (byte) 'e',
-                });
-
-            Assert.AreEqual(128, is_Renamed.ReadVInt());
-            Assert.AreEqual(16383, is_Renamed.ReadVInt());
-            Assert.AreEqual(16384, is_Renamed.ReadVInt());
-            Assert.AreEqual(16385, is_Renamed.ReadVInt());
-            Assert.AreEqual("Lucene", is_Renamed.ReadString());
-
-            Assert.AreEqual("\u00BF", is_Renamed.ReadString());
-            Assert.AreEqual("Lu\u00BFce\u00BFne", is_Renamed.ReadString());
-
-            Assert.AreEqual("\u2620", is_Renamed.ReadString());
-            Assert.AreEqual("Lu\u2620ce\u2620ne", is_Renamed.ReadString());
-
-            Assert.AreEqual("\uD834\uDD1E", is_Renamed.ReadString());
-            Assert.AreEqual("\uD834\uDD1E\uD834\uDD60", is_Renamed.ReadString());
-            Assert.AreEqual("Lu\uD834\uDD1Ece\uD834\uDD60ne", is_Renamed.ReadString());
-
-            Assert.AreEqual("\u0000", is_Renamed.ReadString());
-            Assert.AreEqual("Lu\u0000ce\u0000ne", is_Renamed.ReadString());
-
-            /* Modified UTF-8 in Java
-             * The Java programming language, which uses UTF-16 for its internal text representation,

-             * supports a non-standard modification of UTF-8 for string serialization. 
-             * This encoding is called modified UTF-8. There are two differences between
modified 
-             * and standard UTF-8. The first difference is that the null character (U+0000)
is 
-             * encoded with two bytes instead of one, specifically as 11000000 10000000 (0xC0
0x80). 
-             * This ensures that there are no embedded nulls in the encoded string, 
-             * presumably to address the concern that if the encoded string is processed

-             * in a language such as C where a null byte signifies the end of a string.
-             * 
-             * But .Net's UTF8 class  converts 0xc0 0x80 to \ufffd\ufffd (meaning 2 consecutive
invalid
-             * char).
-             */
-            //Assert.AreEqual("\u0000", is_Renamed.ReadString());
-            //Assert.AreEqual("Lu\u0000ce\u0000ne", is_Renamed.ReadString());
-            Assert.AreEqual("\ufffd\ufffd", is_Renamed.ReadString());
-            Assert.AreEqual("Lu\ufffd\ufffdce\ufffd\ufffdne", is_Renamed.ReadString());
-        }
-
-        /// <summary> Expert
+		public virtual void  TestRead()
+		{
+			IndexInput is_Renamed = new MockIndexInput(new byte[]{(byte) (0x80), (byte) (0x01), (byte)
(0xFF), (byte) (0x7F), (byte) (0x80), (byte) (0x80), (byte) (0x01), (byte) (0x81), (byte)
(0x80), (byte) (0x01), (byte) (0x06), (byte) 'L', (byte) 'u', (byte) 'c', (byte) 'e', (byte)
'n', (byte) 'e', (byte) (0x02), (byte) (0xC2), (byte) (0xBF), (byte) (0x0A), (byte) 'L', (byte)
'u', (byte) (0xC2), (byte) (0xBF), (byte) 'c', (byte) 'e', (byte) (0xC2), (byte) (0xBF), (byte)
'n', (byte) 'e', (byte) (0x03), (byte) (0xE2), (byte) (0x98), (byte) (0xA0), (byte) (0x0C),
(byte) 'L', (byte) 'u', (byte) (0xE2), (byte) (0x98), (byte) (0xA0), (byte) 'c', (byte) 'e',
(byte) (0xE2), (byte) (0x98), (byte) (0xA0), (byte) 'n', (byte) 'e', (byte) (0x04), (byte)
(0xF0), (byte) (0x9D), (byte) (0x84), (byte) (0x9E), (byte) (0x08), (byte) (0xF0), (byte)
(0x9D), (byte) (0x84), (byte) (0x9E), (byte) (0xF0), (byte) (0x9D), (byte) (0x85), (byte)
(0xA0), (byte) (0x0E), (byte) 'L', (byte) 'u', (byte) (0xF0), (b
 yte) (0x9D), (byte) (0x84), (byte) (0x9E), (byte) 'c', (byte) 'e', (byte) (0xF0), (byte)
(0x9D), (byte) (0x85), (byte) 
+				(0xA0), (byte) 'n', (byte) 'e', (byte) (0x01), (byte) (0x00), (byte) (0x08), (byte) 'L',
(byte) 'u', (byte) (0x00), (byte) 'c', (byte) 'e', (byte) (0x00), (byte) 'n', (byte) 'e'});
+			
+			Assert.AreEqual(128, is_Renamed.ReadVInt());
+			Assert.AreEqual(16383, is_Renamed.ReadVInt());
+			Assert.AreEqual(16384, is_Renamed.ReadVInt());
+			Assert.AreEqual(16385, is_Renamed.ReadVInt());
+			Assert.AreEqual("Lucene", is_Renamed.ReadString());
+			
+			Assert.AreEqual("\u00BF", is_Renamed.ReadString());
+			Assert.AreEqual("Lu\u00BFce\u00BFne", is_Renamed.ReadString());
+			
+			Assert.AreEqual("\u2620", is_Renamed.ReadString());
+			Assert.AreEqual("Lu\u2620ce\u2620ne", is_Renamed.ReadString());
+			
+			Assert.AreEqual("\uD834\uDD1E", is_Renamed.ReadString());
+			Assert.AreEqual("\uD834\uDD1E\uD834\uDD60", is_Renamed.ReadString());
+			Assert.AreEqual("Lu\uD834\uDD1Ece\uD834\uDD60ne", is_Renamed.ReadString());
+			
+			Assert.AreEqual("\u0000", is_Renamed.ReadString());
+			Assert.AreEqual("Lu\u0000ce\u0000ne", is_Renamed.ReadString());
+		}
+		
+		/// <summary> Expert
 		/// 
 		/// </summary>
 		/// <throws>  IOException </throws>
 		[Test]
 		public virtual void  TestSkipChars()
 		{
-			byte[] bytes = new byte[]{(byte) 0x80, (byte) 0x01, (byte) 0xFF, (byte) 0x7F, (byte) 0x80,
(byte) 0x80, (byte) 0x01, (byte) 0x81, (byte) 0x80, (byte) 0x01, (byte) 0x06, (byte) 'L',
(byte) 'u', (byte) 'c', (byte) 'e', (byte) 'n', (byte) 'e'};
+			byte[] bytes = new byte[]{(byte) (0x80), (byte) (0x01), (byte) (0xFF), (byte) (0x7F),
(byte) (0x80), (byte) (0x80), (byte) (0x01), (byte) (0x81), (byte) (0x80), (byte) (0x01),
(byte) (0x06), (byte) 'L', (byte) 'u', (byte) 'c', (byte) 'e', (byte) 'n', (byte) 'e'};
 			System.String utf8Str = "\u0634\u1ea1";
 			byte[] utf8Bytes = System.Text.Encoding.GetEncoding("UTF-8").GetBytes(utf8Str);
 			byte[] theBytes = new byte[bytes.Length + 1 + utf8Bytes.Length];

Modified: incubator/lucene.net/trunk/C#/src/Test/Index/TestIndexModifier.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Test/Index/TestIndexModifier.cs?rev=832486&r1=832485&r2=832486&view=diff
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Test/Index/TestIndexModifier.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Test/Index/TestIndexModifier.cs Tue Nov  3 18:06:27
2009
@@ -1,4 +1,4 @@
-/*
+/* 
  * 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.
@@ -19,17 +19,15 @@
 
 using NUnit.Framework;
 
+using Analyzer = Lucene.Net.Analysis.Analyzer;
+using SimpleAnalyzer = Lucene.Net.Analysis.SimpleAnalyzer;
+using StandardAnalyzer = Lucene.Net.Analysis.Standard.StandardAnalyzer;
 using Document = Lucene.Net.Documents.Document;
 using Field = Lucene.Net.Documents.Field;
-using Index = Lucene.Net.Documents.Field.Index;
-using Store = Lucene.Net.Documents.Field.Store;
 using Directory = Lucene.Net.Store.Directory;
 using FSDirectory = Lucene.Net.Store.FSDirectory;
 using RAMDirectory = Lucene.Net.Store.RAMDirectory;
 using LuceneTestCase = Lucene.Net.Util.LuceneTestCase;
-using Analyzer = Lucene.Net.Analysis.Analyzer;
-using SimpleAnalyzer = Lucene.Net.Analysis.SimpleAnalyzer;
-using StandardAnalyzer = Lucene.Net.Analysis.Standard.StandardAnalyzer;
 
 namespace Lucene.Net.Index
 {
@@ -40,8 +38,8 @@
 	/// </summary>
 	/// <deprecated>
 	/// </deprecated>
-	[TestFixture]
-	public class TestIndexModifier : LuceneTestCase
+    [TestFixture]
+	public class TestIndexModifier:LuceneTestCase
 	{
 		
 		private int docCount = 0;
@@ -68,7 +66,7 @@
 			i.AddDocument(GetDoc());
 			i.AddDocument(GetDoc());
 			i.Flush();
-			// depend on merge policy - assertEquals(3, i.docCount());
+			// depend on merge policy - Assert.AreEqual(3, i.docCount());
 			i.DeleteDocuments(allDocTerm);
 			Assert.AreEqual(0, i.DocCount());
 			i.Optimize();
@@ -111,7 +109,7 @@
 				i.DocCount();
 				Assert.Fail();
 			}
-			catch (System.SystemException)
+			catch (System.SystemException e)
 			{
 				// expected exception
 			}
@@ -132,9 +130,9 @@
 			powerIndex.Close();
 		}
 		
-		private Lucene.Net.Documents.Document GetDoc()
+		private Document GetDoc()
 		{
-			Lucene.Net.Documents.Document doc = new Lucene.Net.Documents.Document();
+			Document doc = new Document();
 			doc.Add(new Field("body", System.Convert.ToString(docCount), Field.Store.YES, Field.Index.NOT_ANALYZED));
 			doc.Add(new Field("all", "x", Field.Store.YES, Field.Index.NOT_ANALYZED));
 			docCount++;
@@ -144,12 +142,12 @@
 		[Test]
 		public virtual void  TestIndexWithThreads()
 		{
-			_TestIndexInternal(0);
-			_TestIndexInternal(10);
-			_TestIndexInternal(50);
+			TestIndexInternal(0);
+			TestIndexInternal(10);
+			TestIndexInternal(50);
 		}
 		
-		private void  _TestIndexInternal(int maxWait)
+		private void  TestIndexInternal(int maxWait)
 		{
 			bool create = true;
 			//Directory rd = new RAMDirectory();
@@ -158,7 +156,7 @@
 			if (tempDir == null)
 				throw new System.IO.IOException("java.io.tmpdir undefined, cannot run test");
 			System.IO.FileInfo indexDir = new System.IO.FileInfo(System.IO.Path.Combine(tempDir, "lucenetestindex"));
-			Directory rd = FSDirectory.GetDirectory(indexDir, create);
+			Directory rd = FSDirectory.Open(indexDir);
 			IndexThread.id = 0;
 			IndexThread.idStack.Clear();
 			IndexModifier index = new IndexModifier(rd, new StandardAnalyzer(), create);
@@ -168,14 +166,7 @@
 			thread2.Start();
 			while (thread1.IsAlive || thread2.IsAlive)
 			{
-				try
-				{
-					System.Threading.Thread.Sleep(100);
-				}
-				catch (System.Threading.ThreadInterruptedException e)
-				{
-					throw new System.SystemException(e.Message);
-				}
+				System.Threading.Thread.Sleep(new System.TimeSpan((System.Int64) 10000 * 100));
 			}
 			index.Optimize();
 			int added = thread1.added + thread2.added;
@@ -188,7 +179,7 @@
 				index.Close();
 				Assert.Fail();
 			}
-			catch (System.SystemException)
+			catch (System.SystemException e)
 			{
 				// expected exception
 			}
@@ -231,7 +222,7 @@
 			bool generatedAux2 = tmpBool2;
 		}
 		
-		private class PowerIndex : IndexModifier
+		private class PowerIndex:IndexModifier
 		{
 			private void  InitBlock(TestIndexModifier enclosingInstance)
 			{
@@ -262,15 +253,14 @@
 		}
 	}
 	
-	class IndexThread : SupportClass.ThreadClass
+	class IndexThread:SupportClass.ThreadClass
 	{
 		
-		private const int TEST_SECONDS = 3; // how many seconds to tun each test
+		private const int TEST_SECONDS = 3; // how many seconds to run each test 
 		
 		internal static int id = 0;
-		//internal static System.Collections.ArrayList idStack = new System.Collections.ArrayList();
-        internal static System.Collections.Stack idStack = new System.Collections.Stack();
-
+		internal static System.Collections.ArrayList idStack = new System.Collections.ArrayList();
+		
 		internal int added = 0;
 		internal int deleted = 0;
 		
@@ -290,11 +280,12 @@
 		
 		override public void  Run()
 		{
-            System.DateTime endTime = System.DateTime.Now.AddSeconds(3.0);
+			
+			long endTime = System.DateTime.Now.Millisecond + 1000 * TEST_SECONDS;
 			try
 			{
-                while (System.DateTime.Now < endTime)
-                {
+				while (System.DateTime.Now.Millisecond < endTime)
+				{
 					int rand = random.Next(101);
 					if (rand < 5)
 					{
@@ -302,12 +293,9 @@
 					}
 					else if (rand < 60)
 					{
-						Lucene.Net.Documents.Document doc = GetDocument();
+						Document doc = GetDocument();
 						index.AddDocument(doc);
-                        lock (idStack.SyncRoot)
-                        {
-                            idStack.Push(doc.Get("id"));
-                        }
+						idStack.Add(doc.Get("id"));
 						added++;
 					}
 					else
@@ -317,12 +305,10 @@
 						System.String delId = null;
 						try
 						{
-                            lock (idStack.SyncRoot)
-                            {
-                                delId = (string)idStack.Pop();
-                            }
+                            delId = idStack[idStack.Count - 1] as System.String;
+                            idStack.RemoveAt(idStack.Count - 1);
 						}
-						catch (System.InvalidOperationException)
+						catch (System.ArgumentOutOfRangeException e)
 						{
 							continue;
 						}
@@ -336,28 +322,29 @@
 					}
 					if (maxWait > 0)
 					{
+						rand = random.Next(maxWait);
+						//System.out.println("waiting " + rand + "ms");
 						try
 						{
-							rand = random.Next(maxWait);
-							//System.out.println("waiting " + rand + "ms");
-							System.Threading.Thread.Sleep(rand);
+							System.Threading.Thread.Sleep(new System.TimeSpan((System.Int64) 10000 * rand));
 						}
-						catch (System.Threading.ThreadInterruptedException e)
+						catch (System.Threading.ThreadInterruptedException ie)
 						{
-							throw new System.SystemException(e.Message);
+							SupportClass.ThreadClass.Current().Interrupt();
+							throw new System.SystemException("", ie);
 						}
 					}
 				}
 			}
 			catch (System.IO.IOException e)
 			{
-				throw new System.SystemException(e.Message);
+				throw new System.SystemException("", e);
 			}
 		}
 		
-		private Lucene.Net.Documents.Document GetDocument()
+		private Document GetDocument()
 		{
-			Lucene.Net.Documents.Document doc = new Lucene.Net.Documents.Document();
+			Document doc = new Document();
 			lock (GetType())
 			{
 				doc.Add(new Field("id", System.Convert.ToString(id), Field.Store.YES, Field.Index.NOT_ANALYZED));



Mime
View raw message