lucenenet-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aro...@apache.org
Subject svn commit: r832486 [6/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/TestByteSlices.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Test/Index/TestByteSlices.cs?rev=832486&r1=832485&r2=832486&view=diff
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Test/Index/TestByteSlices.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Test/Index/TestByteSlices.cs Tue Nov  3 18:06:27 2009
@@ -1,10 +1,13 @@
-/**
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
+/* 
+ * 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.
@@ -12,121 +15,129 @@
  * limitations under the License.
  */
 
+using System;
+
 using NUnit.Framework;
 
 using LuceneTestCase = Lucene.Net.Util.LuceneTestCase;
 
+using ByteBlockPool = Lucene.Net.Index.ByteBlockPool;
+
 namespace Lucene.Net.Index
 {
-    public class TestByteSlices : LuceneTestCase
-    {
-
-        private class ByteBlockAllocator : ByteBlockPool.Allocator
-        {
-            System.Collections.Generic.List<byte[]> freeByteBlocks = new System.Collections.Generic.List<byte[]>();
-
-            /* Allocate another byte[] from the shared pool */
-            override public byte[] GetByteBlock(bool trackAllocations)
-            {
-                lock (this)
-                {
-                    int size = freeByteBlocks.Count;
-                    byte[] b;
-                    if (0 == size)
-                        b = new byte[DocumentsWriter.BYTE_BLOCK_SIZE_For_NUnit_Test];
-                    else
-                    {
-                        b = freeByteBlocks[size - 1];
-                        freeByteBlocks.RemoveAt(size - 1);
-                    }
-                    return b;
-                }
-            }
-
-            /* Return a byte[] to the pool */
-            override public void RecycleByteBlocks(byte[][] blocks, int start, int end)
-            {
-                lock (this)
-                {
-                    for (int i = start; i < end; i++)
-                        freeByteBlocks.Add(blocks[i]);
-                }
-            }
-        }
-
-        [Test]
-        public void TestBasic()
-        {
-            ByteBlockPool pool = new ByteBlockPool(new ByteBlockAllocator(), false);
-
-            int NUM_STREAM = 25;
-
-            ByteSliceWriter writer = new ByteSliceWriter(pool);
-
-            int[] starts = new int[NUM_STREAM];
-            int[] uptos = new int[NUM_STREAM];
-            int[] counters = new int[NUM_STREAM];
-
-            System.Random r = new System.Random(1);
-
-            ByteSliceReader reader = new ByteSliceReader();
-
-            for (int ti = 0; ti < 100; ti++)
-            {
-
-                for (int stream = 0; stream < NUM_STREAM; stream++)
-                {
-                    starts[stream] = -1;
-                    counters[stream] = 0;
-                }
-
-                bool debug = false;
-
-                for (int iter = 0; iter < 10000; iter++)
-                {
-                    int stream = r.Next(NUM_STREAM);
-                    if (debug)
-                        System.Console.WriteLine("write stream=" + stream);
-
-                    if (starts[stream] == -1)
-                    {
-                        int spot = pool.NewSlice(ByteBlockPool.FIRST_LEVEL_SIZE_For_NUnit_Test);
-                        starts[stream] = uptos[stream] = spot + pool.byteOffset;
-                        if (debug)
-                            System.Console.WriteLine("  init to " + starts[stream]);
-                    }
-
-                    writer.Init(uptos[stream]);
-                    int numValue = r.Next(20);
-                    for (int j = 0; j < numValue; j++)
-                    {
-                        if (debug)
-                            System.Console.WriteLine("    write " + (counters[stream] + j));
-                        writer.WriteVInt(counters[stream] + j);
-                        //writer.writeVInt(ti);
-                    }
-                    counters[stream] += numValue;
-                    uptos[stream] = writer.GetAddress();
-                    if (debug)
-                        System.Console.WriteLine("    addr now " + uptos[stream]);
-                }
-
-                for (int stream = 0; stream < NUM_STREAM; stream++)
-                {
-                    if (debug)
-                        System.Console.WriteLine("  stream=" + stream + " count=" + counters[stream]);
-
-                    if (starts[stream] != uptos[stream])
-                    {
-                        reader.Init(pool, starts[stream], uptos[stream]);
-                        for (int j = 0; j < counters[stream]; j++)
-                            Assert.AreEqual(j, reader.ReadVInt());
-                        //assertEquals(ti, reader.readVInt());
-                    }
-                }
-
-                pool.Reset();
-            }
-        }
-    }
+	
+	[TestFixture]
+	public class TestByteSlices:LuceneTestCase
+	{
+		
+		private class ByteBlockAllocator:ByteBlockPool.Allocator
+		{
+			internal System.Collections.ArrayList freeByteBlocks = new System.Collections.ArrayList();
+			
+			/* Allocate another byte[] from the shared pool */
+			public /*internal*/ override byte[] GetByteBlock(bool trackAllocations)
+			{
+				lock (this)
+				{
+					int size = freeByteBlocks.Count;
+					byte[] b;
+					if (0 == size)
+						b = new byte[DocumentsWriter.BYTE_BLOCK_SIZE_ForNUnit];
+					else
+					{
+						System.Object tempObject;
+						tempObject = freeByteBlocks[size - 1];
+						freeByteBlocks.RemoveAt(size - 1);
+						b = (byte[]) tempObject;
+					}
+					return b;
+				}
+			}
+			
+			/* Return a byte[] to the pool */
+			public /*internal*/ override void  RecycleByteBlocks(byte[][] blocks, int start, int end)
+			{
+				lock (this)
+				{
+					for (int i = start; i < end; i++)
+						freeByteBlocks.Add(blocks[i]);
+				}
+			}
+		}
+		
+		[Test]
+		public virtual void  TestBasic()
+		{
+			ByteBlockPool pool = new ByteBlockPool(new ByteBlockAllocator(), false);
+			
+			int NUM_STREAM = 25;
+			
+			ByteSliceWriter writer = new ByteSliceWriter(pool);
+			
+			int[] starts = new int[NUM_STREAM];
+			int[] uptos = new int[NUM_STREAM];
+			int[] counters = new int[NUM_STREAM];
+			
+			System.Random r = NewRandom();
+			
+			ByteSliceReader reader = new ByteSliceReader();
+			
+			for (int ti = 0; ti < 100; ti++)
+			{
+				
+				for (int stream = 0; stream < NUM_STREAM; stream++)
+				{
+					starts[stream] = - 1;
+					counters[stream] = 0;
+				}
+				
+				bool debug = false;
+				
+				for (int iter = 0; iter < 10000; iter++)
+				{
+					int stream = r.Next(NUM_STREAM);
+					if (debug)
+						System.Console.Out.WriteLine("write stream=" + stream);
+					
+					if (starts[stream] == - 1)
+					{
+						int spot = pool.NewSlice(ByteBlockPool.FIRST_LEVEL_SIZE_ForNUnit);
+						starts[stream] = uptos[stream] = spot + pool.byteOffset;
+						if (debug)
+							System.Console.Out.WriteLine("  init to " + starts[stream]);
+					}
+					
+					writer.Init(uptos[stream]);
+					int numValue = r.Next(20);
+					for (int j = 0; j < numValue; j++)
+					{
+						if (debug)
+							System.Console.Out.WriteLine("    write " + (counters[stream] + j));
+						writer.WriteVInt(counters[stream] + j);
+						//writer.writeVInt(ti);
+					}
+					counters[stream] += numValue;
+					uptos[stream] = writer.GetAddress();
+					if (debug)
+						System.Console.Out.WriteLine("    addr now " + uptos[stream]);
+				}
+				
+				for (int stream = 0; stream < NUM_STREAM; stream++)
+				{
+					if (debug)
+						System.Console.Out.WriteLine("  stream=" + stream + " count=" + counters[stream]);
+					
+					if (starts[stream] != uptos[stream])
+					{
+						reader.Init(pool, starts[stream], uptos[stream]);
+						for (int j = 0; j < counters[stream]; j++)
+							Assert.AreEqual(j, reader.ReadVInt());
+						//Assert.AreEqual(ti, reader.readVInt());
+					}
+				}
+				
+				pool.Reset();
+			}
+		}
+	}
 }
\ No newline at end of file

Modified: incubator/lucene.net/trunk/C#/src/Test/Index/TestCheckIndex.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Test/Index/TestCheckIndex.cs?rev=832486&r1=832485&r2=832486&view=diff
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Test/Index/TestCheckIndex.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Test/Index/TestCheckIndex.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,18 @@
 
 using NUnit.Framework;
 
+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 Constants = Lucene.Net.Util.Constants;
 using LuceneTestCase = Lucene.Net.Util.LuceneTestCase;
-using WhitespaceAnalyzer = Lucene.Net.Analysis.WhitespaceAnalyzer;
 
 namespace Lucene.Net.Index
 {
 	
 	[TestFixture]
-	public class TestCheckIndex : LuceneTestCase
+	public class TestCheckIndex:LuceneTestCase
 	{
 		
 		[Test]
@@ -48,21 +49,64 @@
 			IndexReader reader = IndexReader.Open(dir);
 			reader.DeleteDocument(5);
 			reader.Close();
-
-            System.IO.StringWriter sw = new System.IO.StringWriter();
-            CheckIndex checker = new CheckIndex(dir);
-            checker.SetInfoStream(sw);
-            CheckIndex.Status indexStatus = checker.CheckIndex_Renamed();
-            if (!indexStatus.clean)
-            {
-                System.Console.WriteLine("CheckIndex failed");
-                System.Console.WriteLine(sw.ToString());
-                Assert.Fail();
-            }
-            System.Collections.Generic.List<object> onlySegments = new System.Collections.Generic.List<object>();
-            onlySegments.Add("_0");
-
-            Assert.IsTrue(checker.CheckIndex_Renamed(onlySegments).clean);
+			
+			System.IO.MemoryStream bos = new System.IO.MemoryStream(1024);
+			CheckIndex checker = new CheckIndex(dir);
+			checker.SetInfoStream(new System.IO.StreamWriter(bos));
+			//checker.setInfoStream(System.out);
+			CheckIndex.Status indexStatus = checker.CheckIndex_Renamed_Method();
+			if (indexStatus.clean == false)
+			{
+				System.Console.Out.WriteLine("CheckIndex failed");
+				char[] tmpChar;
+				byte[] tmpByte;
+				tmpByte = bos.GetBuffer();
+				tmpChar = new char[bos.Length];
+				System.Array.Copy(tmpByte, 0, tmpChar, 0, tmpChar.Length);
+				System.Console.Out.WriteLine(new System.String(tmpChar));
+				Assert.Fail();
+			}
+			
+			CheckIndex.Status.SegmentInfoStatus seg = (CheckIndex.Status.SegmentInfoStatus) indexStatus.segmentInfos[0];
+			Assert.IsTrue(seg.openReaderPassed);
+			
+			Assert.IsNotNull(seg.diagnostics);
+			
+			Assert.IsNotNull(seg.fieldNormStatus);
+			Assert.IsNull(seg.fieldNormStatus.error);
+			Assert.AreEqual(1, seg.fieldNormStatus.totFields);
+			
+			Assert.IsNotNull(seg.termIndexStatus);
+			Assert.IsNull(seg.termIndexStatus.error);
+			Assert.AreEqual(1, seg.termIndexStatus.termCount);
+			Assert.AreEqual(19, seg.termIndexStatus.totFreq);
+			Assert.AreEqual(18, seg.termIndexStatus.totPos);
+			
+			Assert.IsNotNull(seg.storedFieldStatus);
+			Assert.IsNull(seg.storedFieldStatus.error);
+			Assert.AreEqual(18, seg.storedFieldStatus.docCount);
+			Assert.AreEqual(18, seg.storedFieldStatus.totFields);
+			
+			Assert.IsNotNull(seg.termVectorStatus);
+			Assert.IsNull(seg.termVectorStatus.error);
+			Assert.AreEqual(18, seg.termVectorStatus.docCount);
+			Assert.AreEqual(18, seg.termVectorStatus.totVectors);
+			
+			Assert.IsTrue(seg.diagnostics.Count > 0);
+			System.Collections.IList onlySegments = new System.Collections.ArrayList();
+			onlySegments.Add("_0");
+			
+			Assert.IsTrue(checker.CheckIndex_Renamed_Method(onlySegments).clean == true);
+		}
+		
+		[Test]
+		public virtual void  TestLuceneConstantVersion()
+		{
+			// common-build.xml sets lucene.version
+			System.String version = SupportClass.AppSettings.Get("lucene.version", "");
+			Assert.IsNotNull(version);
+			Assert.IsTrue(version.Equals(Constants.LUCENE_MAIN_VERSION + "-dev") || version.Equals(Constants.LUCENE_MAIN_VERSION));
+			Assert.IsTrue(Constants.LUCENE_VERSION.StartsWith(version));
 		}
 	}
 }
\ No newline at end of file

Modified: incubator/lucene.net/trunk/C#/src/Test/Index/TestCompoundFile.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Test/Index/TestCompoundFile.cs?rev=832486&r1=832485&r2=832486&view=diff
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Test/Index/TestCompoundFile.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Test/Index/TestCompoundFile.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,11 +19,10 @@
 
 using NUnit.Framework;
 
-//using TestRunner = junit.textui.TestRunner;
 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 SimpleFSDirectory = Lucene.Net.Store.SimpleFSDirectory;
 using _TestHelper = Lucene.Net.Store._TestHelper;
 using LuceneTestCase = Lucene.Net.Util.LuceneTestCase;
 using _TestUtil = Lucene.Net.Util._TestUtil;
@@ -33,16 +32,16 @@
 	
 	
 	/// <summary> </summary>
-	/// <version>  $Id: TestCompoundFile.java 602165 2007-12-07 17:42:33Z mikemccand $
+	/// <version>  $Id: TestCompoundFile.java 780770 2009-06-01 18:34:10Z uschindler $
 	/// </version>
 	[TestFixture]
-	public class TestCompoundFile : LuceneTestCase
+	public class TestCompoundFile:LuceneTestCase
 	{
 		/// <summary>Main for running test case by itself. </summary>
 		[STAThread]
 		public static void  Main(System.String[] args)
 		{
-			// NUnit.Util.TestRunner.Run(new NUnit.Core.TestSuite(typeof(TestCompoundFile)));   // {{Aroush}} where is 'TestRunner' in NUnit?
+			// TestRunner.run(new TestSuite(typeof(TestCompoundFile))); // {{Aroush-2.9}} how is this done in NUnit?
 			//        TestRunner.run (new TestCompoundFile("testSingleFile"));
 			//        TestRunner.run (new TestCompoundFile("testTwoFiles"));
 			//        TestRunner.run (new TestCompoundFile("testRandomFiles"));
@@ -59,15 +58,23 @@
 		
 		private Directory dir;
 		
+		
 		[SetUp]
-		public override void SetUp()
+		public override void  SetUp()
 		{
-            base.SetUp();
+			base.SetUp();
 			System.IO.FileInfo file = new System.IO.FileInfo(System.IO.Path.Combine(SupportClass.AppSettings.Get("tempDir", ""), "testIndex"));
-			Lucene.Net.Util._TestUtil.RmDir(file);
-			dir = FSDirectory.GetDirectory(file);
+			_TestUtil.RmDir(file);
+			// use a simple FSDir here, to be sure to have SimpleFSInputs
+			dir = new SimpleFSDirectory(file, null);
 		}
 		
+		[TearDown]
+		public override void  TearDown()
+		{
+			dir.Close();
+			base.TearDown();
+		}
 		
 		/// <summary>Creates a file of the specified size with random data. </summary>
 		private void  CreateRandomFile(Directory dir, System.String name, int size)
@@ -101,8 +108,8 @@
 		{
 			Assert.IsNotNull(expected, msg + " null expected");
 			Assert.IsNotNull(test, msg + " null test");
-			Assert.AreEqual(test.Length(), expected.Length(), msg + " length");
-			Assert.AreEqual(test.GetFilePointer(), expected.GetFilePointer(), msg + " position");
+			Assert.AreEqual(expected.Length(), test.Length(), msg + " length");
+			Assert.AreEqual(expected.GetFilePointer(), test.GetFilePointer(), msg + " position");
 			
 			byte[] expectedBuffer = new byte[512];
 			byte[] testBuffer = new byte[expectedBuffer.Length];
@@ -302,13 +309,14 @@
 			cw.Close();
 		}
 		
+		
 		[Test]
 		public virtual void  TestReadAfterClose()
 		{
-			Demo_FSIndexInputBug((FSDirectory) dir, "test");
+			Demo_FSIndexInputBug(dir, "test");
 		}
 		
-		private void  Demo_FSIndexInputBug(FSDirectory fsdir, System.String file)
+		private void  Demo_FSIndexInputBug(Directory fsdir, System.String file)
 		{
 			// Setup the test file - we need more than 1024 bytes
 			IndexOutput os = fsdir.CreateOutput(file);
@@ -340,7 +348,7 @@
 				b = in_Renamed.ReadByte();
 				Assert.Fail("expected readByte() to throw exception");
 			}
-			catch (System.Exception)
+			catch (System.IO.IOException e)
 			{
 				// expected exception
 			}
@@ -358,7 +366,7 @@
 			{
 				CompoundFileReader.CSIndexInput cis = (CompoundFileReader.CSIndexInput) is_Renamed;
 				
-				return _TestHelper.IsFSIndexInputOpen(cis.base_Renamed);
+				return _TestHelper.IsSimpleFSIndexInputOpen(cis.base_Renamed_ForNUnit);
 			}
 			else
 			{
@@ -366,6 +374,7 @@
 			}
 		}
 		
+		
 		[Test]
 		public virtual void  TestClonedStreamsClosing()
 		{
@@ -376,50 +385,47 @@
 			IndexInput expected = dir.OpenInput("f11");
 			
 			// this test only works for FSIndexInput
-			if (_TestHelper.IsFSIndexInput(expected))
-			{
-				
-				Assert.IsTrue(_TestHelper.IsFSIndexInputOpen(expected));
-				
-				IndexInput one = cr.OpenInput("f11");
-				Assert.IsTrue(IsCSIndexInputOpen(one));
-				
-				IndexInput two = (IndexInput) one.Clone();
-				Assert.IsTrue(IsCSIndexInputOpen(two));
-				
-				AssertSameStreams("basic clone one", expected, one);
-				expected.Seek(0);
-				AssertSameStreams("basic clone two", expected, two);
-				
-				// Now close the first stream
-				one.Close();
-				Assert.IsTrue(IsCSIndexInputOpen(one), "Only close when cr is closed");
-				
-				// The following should really fail since we couldn't expect to
-				// access a file once close has been called on it (regardless of
-				// buffering and/or clone magic)
-				expected.Seek(0);
-				two.Seek(0);
-				AssertSameStreams("basic clone two/2", expected, two);
-				
-				
-				// Now close the compound reader
-				cr.Close();
-				Assert.IsFalse(IsCSIndexInputOpen(one), "Now closed one");
-				Assert.IsFalse(IsCSIndexInputOpen(two), "Now closed two");
-				
-				// The following may also fail since the compound stream is closed
-				expected.Seek(0);
-				two.Seek(0);
-				//assertSameStreams("basic clone two/3", expected, two);
-				
-				
-				// Now close the second clone
-				two.Close();
-				expected.Seek(0);
-				two.Seek(0);
-				//assertSameStreams("basic clone two/4", expected, two);
-			}
+			Assert.IsTrue(_TestHelper.IsSimpleFSIndexInput(expected));
+			Assert.IsTrue(_TestHelper.IsSimpleFSIndexInputOpen(expected));
+			
+			IndexInput one = cr.OpenInput("f11");
+			Assert.IsTrue(IsCSIndexInputOpen(one));
+			
+			IndexInput two = (IndexInput) one.Clone();
+			Assert.IsTrue(IsCSIndexInputOpen(two));
+			
+			AssertSameStreams("basic clone one", expected, one);
+			expected.Seek(0);
+			AssertSameStreams("basic clone two", expected, two);
+			
+			// Now close the first stream
+			one.Close();
+			Assert.IsTrue(IsCSIndexInputOpen(one), "Only close when cr is closed");
+			
+			// The following should really fail since we couldn't expect to
+			// access a file once close has been called on it (regardless of
+			// buffering and/or clone magic)
+			expected.Seek(0);
+			two.Seek(0);
+			AssertSameStreams("basic clone two/2", expected, two);
+			
+			
+			// Now close the compound reader
+			cr.Close();
+			Assert.IsFalse(IsCSIndexInputOpen(one), "Now closed one");
+			Assert.IsFalse(IsCSIndexInputOpen(two), "Now closed two");
+			
+			// The following may also fail since the compound stream is closed
+			expected.Seek(0);
+			two.Seek(0);
+			//assertSameStreams("basic clone two/3", expected, two);
+			
+			
+			// Now close the second clone
+			two.Close();
+			expected.Seek(0);
+			two.Seek(0);
+			//assertSameStreams("basic clone two/4", expected, two);
 			
 			expected.Close();
 		}
@@ -587,6 +593,7 @@
 			cr.Close();
 		}
 		
+		
 		[Test]
 		public virtual void  TestFileNotFound()
 		{
@@ -599,7 +606,7 @@
 				IndexInput e1 = cr.OpenInput("bogus");
 				Assert.Fail("File not found");
 			}
-			catch (System.IO.IOException)
+			catch (System.IO.IOException e)
 			{
 				/* success */
 				//System.out.println("SUCCESS: File Not Found: " + e);
@@ -608,6 +615,7 @@
 			cr.Close();
 		}
 		
+		
 		[Test]
 		public virtual void  TestReadPastEOF()
 		{
@@ -623,7 +631,7 @@
 				byte test = is_Renamed.ReadByte();
 				Assert.Fail("Single byte read past end of file");
 			}
-			catch (System.IO.IOException)
+			catch (System.IO.IOException e)
 			{
 				/* success */
 				//System.out.println("SUCCESS: single byte read past end of file: " + e);
@@ -635,7 +643,7 @@
 				is_Renamed.ReadBytes(b, 0, 50);
 				Assert.Fail("Block read past end of file");
 			}
-			catch (System.IO.IOException)
+			catch (System.IO.IOException e)
 			{
 				/* success */
 				//System.out.println("SUCCESS: block read past end of file: " + e);
@@ -644,24 +652,24 @@
 			is_Renamed.Close();
 			cr.Close();
 		}
-
+		
 		/// <summary>This test that writes larger than the size of the buffer output
 		/// will correctly increment the file pointer.
 		/// </summary>
 		[Test]
 		public virtual void  TestLargeWrites()
-											   {
+		{
 			IndexOutput os = dir.CreateOutput("testBufferStart.txt");
-
+			
 			byte[] largeBuf = new byte[2048];
-			for (int i=0; i<largeBuf.Length; i++)
+			for (int i = 0; i < largeBuf.Length; i++)
 			{
 				largeBuf[i] = (byte) ((new System.Random().NextDouble()) * 256);
 			}
-
+			
 			long currentPos = os.GetFilePointer();
 			os.WriteBytes(largeBuf, largeBuf.Length);
-
+			
 			try
 			{
 				Assert.AreEqual(currentPos + largeBuf.Length, os.GetFilePointer());

Modified: incubator/lucene.net/trunk/C#/src/Test/Index/TestConcurrentMergeScheduler.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Test/Index/TestConcurrentMergeScheduler.cs?rev=832486&r1=832485&r2=832486&view=diff
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Test/Index/TestConcurrentMergeScheduler.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Test/Index/TestConcurrentMergeScheduler.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,45 +19,49 @@
 
 using NUnit.Framework;
 
+using Analyzer = Lucene.Net.Analysis.Analyzer;
+using SimpleAnalyzer = Lucene.Net.Analysis.SimpleAnalyzer;
 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 Analyzer = Lucene.Net.Analysis.Analyzer;
-using SimpleAnalyzer = Lucene.Net.Analysis.SimpleAnalyzer;
 
 namespace Lucene.Net.Index
 {
 	
 	[TestFixture]
-	public class TestConcurrentMergeScheduler : LuceneTestCase
+	public class TestConcurrentMergeScheduler:LuceneTestCase
 	{
 		
 		private static readonly Analyzer ANALYZER = new SimpleAnalyzer();
 		
-		private class FailOnlyOnFlush : MockRAMDirectory.Failure
+		private class FailOnlyOnFlush:MockRAMDirectory.Failure
 		{
-			new internal bool doFail = false;
+			internal bool doFail = false;
 			
-			public override void  SetDoFail()
+			public virtual void  SetDoFail()
 			{
 				this.doFail = true;
 			}
-			public override void  ClearDoFail()
+			public virtual void  ClearDoFail()
 			{
 				this.doFail = false;
 			}
-
-			public override void Eval(MockRAMDirectory dir)
+			
+			public virtual void  Eval(MockRAMDirectory dir)
 			{
 				if (doFail)
 				{
-					System.Diagnostics.StackTrace st = new System.Diagnostics.StackTrace();
-					foreach (System.Diagnostics.StackFrame f in st.GetFrames())
+					System.Diagnostics.StackTrace trace = new System.Diagnostics.StackTrace();
+					for (int i = 0; i < trace.FrameCount; i++)
 					{
-						if ("DoFlush" == f.GetMethod().Name)
+						System.Diagnostics.StackFrame sf = trace.GetFrame(i);
+						if ("DoFlush".Equals(sf.GetMethod()))
+						{
+							//new RuntimeException().printStackTrace(System.out);
 							throw new System.IO.IOException("now failing during flush");
+						}
 					}
 				}
 			}
@@ -96,7 +100,7 @@
 					writer.Flush();
 					Assert.Fail("failed to hit IOException");
 				}
-				catch (System.IO.IOException)
+				catch (System.IO.IOException ioe)
 				{
 					failure.ClearDoFail();
 				}
@@ -114,13 +118,14 @@
 		[Test]
 		public virtual void  TestDeleteMerging()
 		{
+			
 			RAMDirectory directory = new MockRAMDirectory();
 			
 			IndexWriter writer = new IndexWriter(directory, true, ANALYZER, true);
 			ConcurrentMergeScheduler cms = new ConcurrentMergeScheduler();
 			writer.SetMergeScheduler(cms);
 			
-			LogDocMergePolicy mp = new LogDocMergePolicy();
+			LogDocMergePolicy mp = new LogDocMergePolicy(writer);
 			writer.SetMergePolicy(mp);
 			
 			// Force degenerate merging so we can get a mix of

Modified: incubator/lucene.net/trunk/C#/src/Test/Index/TestCrash.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Test/Index/TestCrash.cs?rev=832486&r1=832485&r2=832486&view=diff
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Test/Index/TestCrash.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Test/Index/TestCrash.cs Tue Nov  3 18:06:27 2009
@@ -1,201 +1,204 @@
-/**
- * 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.
- */
+/* 
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+using System;
 
 using NUnit.Framework;
 
-using LuceneTestCase = Lucene.Net.Util.LuceneTestCase;
-using WhitespaceAnalyzer = Lucene.Net.Analysis.WhitespaceAnalyzer;
-using MockRAMDirectory = Lucene.Net.Store.MockRAMDirectory;
-using NoLockFactory = Lucene.Net.Store.NoLockFactory;
-using Document = Lucene.Net.Documents.Document;
+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 NoLockFactory = Lucene.Net.Store.NoLockFactory;
+using LuceneTestCase = Lucene.Net.Util.LuceneTestCase;
 
 namespace Lucene.Net.Index
 {
-    [TestFixture]
-    public class TestCrash : LuceneTestCase
-    {
-
-        private IndexWriter InitIndex()
-        {
-            return InitIndex(new MockRAMDirectory());
-        }
-
-        private IndexWriter InitIndex(MockRAMDirectory dir)
-        {
-            dir.SetLockFactory(NoLockFactory.GetNoLockFactory());
-
-            IndexWriter writer = new IndexWriter(dir, new WhitespaceAnalyzer());
-            //writer.setMaxBufferedDocs(2);
-            writer.SetMaxBufferedDocs(10);
-            ((ConcurrentMergeScheduler)writer.GetMergeScheduler()).SetSuppressExceptions_ForNUnitTest();
-
-            Document doc = new Document();
-            doc.Add(new Field("content", "aaa", Field.Store.YES, Field.Index.ANALYZED));
-            doc.Add(new Field("id", "0", Field.Store.YES, Field.Index.ANALYZED));
-            for (int i = 0; i < 157; i++)
-                writer.AddDocument(doc);
-
-            return writer;
-        }
-
-        private void Crash(IndexWriter writer)
-        {
-            MockRAMDirectory dir = (MockRAMDirectory)writer.GetDirectory();
-            ConcurrentMergeScheduler cms = (ConcurrentMergeScheduler)writer.GetMergeScheduler();
-            dir.Crash();
-            cms.Sync();
-            dir.ClearCrash();
-        }
-
-        [Test]
-        public void TestCrashWhileIndexing()
-        {
-            IndexWriter writer = InitIndex();
-            MockRAMDirectory dir = (MockRAMDirectory)writer.GetDirectory();
-            Crash(writer);
-            IndexReader reader = IndexReader.Open(dir);
-            Assert.IsTrue(reader.NumDocs() < 157);
-        }
-
-        [Test]
-        public void TestWriterAfterCrash()
-        {
-            IndexWriter writer = InitIndex();
-            MockRAMDirectory dir = (MockRAMDirectory)writer.GetDirectory();
-            dir.SetPreventDoubleWrite(false);
-            Crash(writer);
-            writer = InitIndex(dir);
-            writer.Close();
-
-            IndexReader reader = IndexReader.Open(dir);
-            Assert.IsTrue(reader.NumDocs() < 314);
-        }
-
-        [Test]
-        public void TestCrashAfterReopen()
-        {
-            IndexWriter writer = InitIndex();
-            MockRAMDirectory dir = (MockRAMDirectory)writer.GetDirectory();
-            writer.Close();
-            writer = InitIndex(dir);
-            Assert.AreEqual(314, writer.DocCount());
-            Crash(writer);
-
-            /*
-            System.out.println("\n\nTEST: open reader");
-            String[] l = dir.list();
-            Arrays.sort(l);
-            for(int i=0;i<l.length;i++)
-              System.out.println("file " + i + " = " + l[i] + " " +
-            dir.fileLength(l[i]) + " bytes");
-            */
-
-            IndexReader reader = IndexReader.Open(dir);
-            Assert.IsTrue(reader.NumDocs() >= 157);
-        }
-
-        [Test]
-        public void TestCrashAfterClose()
-        {
-
-            IndexWriter writer = InitIndex();
-            MockRAMDirectory dir = (MockRAMDirectory)writer.GetDirectory();
-
-            writer.Close();
-            dir.Crash();
-
-            /*
-            String[] l = dir.list();
-            Arrays.sort(l);
-            for(int i=0;i<l.length;i++)
-              System.out.println("file " + i + " = " + l[i] + " " + dir.fileLength(l[i]) + " bytes");
-            */
-
-            IndexReader reader = IndexReader.Open(dir);
-            Assert.AreEqual(157, reader.NumDocs());
-        }
-
-        [Test]
-        public void TestCrashAfterCloseNoWait()
-        {
-
-            IndexWriter writer = InitIndex();
-            MockRAMDirectory dir = (MockRAMDirectory)writer.GetDirectory();
-
-            writer.Close(false);
-
-            dir.Crash();
-
-            /*
-            String[] l = dir.list();
-            Arrays.sort(l);
-            for(int i=0;i<l.length;i++)
-              System.out.println("file " + i + " = " + l[i] + " " + dir.fileLength(l[i]) + " bytes");
-            */
-            IndexReader reader = IndexReader.Open(dir);
-            Assert.AreEqual(157, reader.NumDocs());
-        }
-
-        [Test]
-        public void TestCrashReaderDeletes()
-        {
-
-            IndexWriter writer = InitIndex();
-            MockRAMDirectory dir = (MockRAMDirectory)writer.GetDirectory();
-
-            writer.Close(false);
-            IndexReader reader = IndexReader.Open(dir);
-            reader.DeleteDocument(3);
-
-            dir.Crash();
-
-            /*
-            String[] l = dir.list();
-            Arrays.sort(l);
-            for(int i=0;i<l.length;i++)
-              System.out.println("file " + i + " = " + l[i] + " " + dir.fileLength(l[i]) + " bytes");
-            */
-            reader = IndexReader.Open(dir);
-            Assert.AreEqual(157, reader.NumDocs());
-        }
-
-        [Test]
-        public void TestCrashReaderDeletesAfterClose()
-        {
-
-            IndexWriter writer = InitIndex();
-            MockRAMDirectory dir = (MockRAMDirectory)writer.GetDirectory();
-
-            writer.Close(false);
-            IndexReader reader = IndexReader.Open(dir);
-            reader.DeleteDocument(3);
-            reader.Close();
-
-            dir.Crash();
-
-            /*
-            String[] l = dir.list();
-            Arrays.sort(l);
-            for(int i=0;i<l.length;i++)
-              System.out.println("file " + i + " = " + l[i] + " " + dir.fileLength(l[i]) + " bytes");
-            */
-            reader = IndexReader.Open(dir);
-            Assert.AreEqual(156, reader.NumDocs());
-        }
-    }
+	
+	[TestFixture]
+	public class TestCrash:LuceneTestCase
+	{
+		
+		private IndexWriter InitIndex()
+		{
+			return InitIndex(new MockRAMDirectory());
+		}
+		
+		private IndexWriter InitIndex(MockRAMDirectory dir)
+		{
+			dir.SetLockFactory(NoLockFactory.GetNoLockFactory());
+			
+			IndexWriter writer = new IndexWriter(dir, new WhitespaceAnalyzer());
+			//writer.setMaxBufferedDocs(2);
+			writer.SetMaxBufferedDocs(10);
+			((ConcurrentMergeScheduler) writer.GetMergeScheduler()).SetSuppressExceptions();
+			
+			Document doc = new Document();
+			doc.Add(new Field("content", "aaa", Field.Store.YES, Field.Index.ANALYZED));
+			doc.Add(new Field("id", "0", Field.Store.YES, Field.Index.ANALYZED));
+			for (int i = 0; i < 157; i++)
+				writer.AddDocument(doc);
+			
+			return writer;
+		}
+		
+		private void  Crash(IndexWriter writer)
+		{
+			MockRAMDirectory dir = (MockRAMDirectory) writer.GetDirectory();
+			ConcurrentMergeScheduler cms = (ConcurrentMergeScheduler) writer.GetMergeScheduler();
+			dir.Crash();
+			cms.Sync();
+			dir.ClearCrash();
+		}
+		
+		[Test]
+		public virtual void  TestCrashWhileIndexing()
+		{
+			IndexWriter writer = InitIndex();
+			MockRAMDirectory dir = (MockRAMDirectory) writer.GetDirectory();
+			Crash(writer);
+			IndexReader reader = IndexReader.Open(dir);
+			Assert.IsTrue(reader.NumDocs() < 157);
+		}
+		
+		[Test]
+		public virtual void  TestWriterAfterCrash()
+		{
+			IndexWriter writer = InitIndex();
+			MockRAMDirectory dir = (MockRAMDirectory) writer.GetDirectory();
+			dir.SetPreventDoubleWrite(false);
+			Crash(writer);
+			writer = InitIndex(dir);
+			writer.Close();
+			
+			IndexReader reader = IndexReader.Open(dir);
+			Assert.IsTrue(reader.NumDocs() < 314);
+		}
+		
+		[Test]
+		public virtual void  TestCrashAfterReopen()
+		{
+			IndexWriter writer = InitIndex();
+			MockRAMDirectory dir = (MockRAMDirectory) writer.GetDirectory();
+			writer.Close();
+			writer = InitIndex(dir);
+			Assert.AreEqual(314, writer.DocCount());
+			Crash(writer);
+			
+			/*
+			System.out.println("\n\nTEST: open reader");
+			String[] l = dir.list();
+			Arrays.sort(l);
+			for(int i=0;i<l.length;i++)
+			System.out.println("file " + i + " = " + l[i] + " " +
+			dir.fileLength(l[i]) + " bytes");
+			*/
+			
+			IndexReader reader = IndexReader.Open(dir);
+			Assert.IsTrue(reader.NumDocs() >= 157);
+		}
+		
+		[Test]
+		public virtual void  TestCrashAfterClose()
+		{
+			
+			IndexWriter writer = InitIndex();
+			MockRAMDirectory dir = (MockRAMDirectory) writer.GetDirectory();
+			
+			writer.Close();
+			dir.Crash();
+			
+			/*
+			String[] l = dir.list();
+			Arrays.sort(l);
+			for(int i=0;i<l.length;i++)
+			System.out.println("file " + i + " = " + l[i] + " " + dir.fileLength(l[i]) + " bytes");
+			*/
+			
+			IndexReader reader = IndexReader.Open(dir);
+			Assert.AreEqual(157, reader.NumDocs());
+		}
+		
+		[Test]
+		public virtual void  TestCrashAfterCloseNoWait()
+		{
+			
+			IndexWriter writer = InitIndex();
+			MockRAMDirectory dir = (MockRAMDirectory) writer.GetDirectory();
+			
+			writer.Close(false);
+			
+			dir.Crash();
+			
+			/*
+			String[] l = dir.list();
+			Arrays.sort(l);
+			for(int i=0;i<l.length;i++)
+			System.out.println("file " + i + " = " + l[i] + " " + dir.fileLength(l[i]) + " bytes");
+			*/
+			IndexReader reader = IndexReader.Open(dir);
+			Assert.AreEqual(157, reader.NumDocs());
+		}
+		
+		[Test]
+		public virtual void  TestCrashReaderDeletes()
+		{
+			
+			IndexWriter writer = InitIndex();
+			MockRAMDirectory dir = (MockRAMDirectory) writer.GetDirectory();
+			
+			writer.Close(false);
+			IndexReader reader = IndexReader.Open(dir);
+			reader.DeleteDocument(3);
+			
+			dir.Crash();
+			
+			/*
+			String[] l = dir.list();
+			Arrays.sort(l);
+			for(int i=0;i<l.length;i++)
+			System.out.println("file " + i + " = " + l[i] + " " + dir.fileLength(l[i]) + " bytes");
+			*/
+			reader = IndexReader.Open(dir);
+			Assert.AreEqual(157, reader.NumDocs());
+		}
+		
+		[Test]
+		public virtual void  TestCrashReaderDeletesAfterClose()
+		{
+			
+			IndexWriter writer = InitIndex();
+			MockRAMDirectory dir = (MockRAMDirectory) writer.GetDirectory();
+			
+			writer.Close(false);
+			IndexReader reader = IndexReader.Open(dir);
+			reader.DeleteDocument(3);
+			reader.Close();
+			
+			dir.Crash();
+			
+			/*
+			String[] l = dir.list();
+			Arrays.sort(l);
+			for(int i=0;i<l.length;i++)
+			System.out.println("file " + i + " = " + l[i] + " " + dir.fileLength(l[i]) + " bytes");
+			*/
+			reader = IndexReader.Open(dir);
+			Assert.AreEqual(156, reader.NumDocs());
+		}
+	}
 }
\ No newline at end of file

Modified: incubator/lucene.net/trunk/C#/src/Test/Index/TestDeletionPolicy.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Test/Index/TestDeletionPolicy.cs?rev=832486&r1=832485&r2=832486&view=diff
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Test/Index/TestDeletionPolicy.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Test/Index/TestDeletionPolicy.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.
@@ -22,12 +22,13 @@
 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 MockRAMDirectory = Lucene.Net.Store.MockRAMDirectory;
+using RAMDirectory = Lucene.Net.Store.RAMDirectory;
 using IndexSearcher = Lucene.Net.Search.IndexSearcher;
 using Query = Lucene.Net.Search.Query;
 using ScoreDoc = Lucene.Net.Search.ScoreDoc;
 using TermQuery = Lucene.Net.Search.TermQuery;
-using Directory = Lucene.Net.Store.Directory;
-using RAMDirectory = Lucene.Net.Store.RAMDirectory;
 using LuceneTestCase = Lucene.Net.Util.LuceneTestCase;
 
 namespace Lucene.Net.Index
@@ -38,28 +39,28 @@
 	against it, and add documents to it.*/
 	
 	[TestFixture]
-	public class TestDeletionPolicy : LuceneTestCase
+	public class TestDeletionPolicy:LuceneTestCase
 	{
 		private void  VerifyCommitOrder(System.Collections.IList commits)
 		{
-            IndexCommit firstCommit = (IndexCommit)commits[0];
+			IndexCommit firstCommit = ((IndexCommit) commits[0]);
 			long last = SegmentInfos.GenerationFromSegmentsFileName(firstCommit.GetSegmentsFileName());
-            Assert.AreEqual(last, firstCommit.GetGeneration());
-            long lastVersion = firstCommit.GetVersion();
-            long lastTimestamp = firstCommit.GetTimestamp();
+			Assert.AreEqual(last, firstCommit.GetGeneration());
+			long lastVersion = firstCommit.GetVersion();
+			long lastTimestamp = firstCommit.GetTimestamp();
 			for (int i = 1; i < commits.Count; i++)
 			{
-                IndexCommit commit = (IndexCommit)commits[i];
-                long now = SegmentInfos.GenerationFromSegmentsFileName(commit.GetSegmentsFileName());
-                long nowVersion = commit.GetVersion();
-                long nowTimestamp = commit.GetTimestamp();
-                Assert.IsTrue(now > last, "SegmentInfos commits are out-of-order");
-                Assert.IsTrue(nowVersion > lastVersion, "SegmentInfos versions are out-of-order");
-                Assert.IsTrue(nowTimestamp >= lastTimestamp, "SegmentInfos timestamps are out-of-order: now=" + nowTimestamp + " vs last=" + lastTimestamp);
-                Assert.AreEqual(now, commit.GetGeneration());
+				IndexCommit commit = ((IndexCommit) commits[i]);
+				long now = SegmentInfos.GenerationFromSegmentsFileName(commit.GetSegmentsFileName());
+				long nowVersion = commit.GetVersion();
+				long nowTimestamp = commit.GetTimestamp();
+				Assert.IsTrue(now > last, "SegmentInfos commits are out-of-order");
+				Assert.IsTrue(nowVersion > lastVersion, "SegmentInfos versions are out-of-order");
+				Assert.IsTrue(nowTimestamp >= lastTimestamp, "SegmentInfos timestamps are out-of-order: now=" + nowTimestamp + " vs last=" + lastTimestamp);
+				Assert.AreEqual(now, commit.GetGeneration());
 				last = now;
-                lastVersion = nowVersion;
-                lastTimestamp = nowTimestamp;
+				lastVersion = nowVersion;
+				lastTimestamp = nowTimestamp;
 			}
 		}
 		
@@ -80,21 +81,22 @@
 				{
 					return enclosingInstance;
 				}
+				
 			}
 			internal int numOnInit;
 			internal int numOnCommit;
-            internal Directory dir;
-			public virtual void  OnInit(System.Collections.Generic.List<IndexCommitPoint> commits)
+			internal Directory dir;
+			public virtual void  OnInit(System.Collections.IList commits)
 			{
 				Enclosing_Instance.VerifyCommitOrder(commits);
 				numOnInit++;
 			}
-            public virtual void OnCommit(System.Collections.Generic.List<IndexCommitPoint> commits)
+			public virtual void  OnCommit(System.Collections.IList commits)
 			{
-                IndexCommit lastCommit = (IndexCommit) commits[commits.Count - 1];
-                IndexReader r = IndexReader.Open(dir);
-                Assert.AreEqual(r.IsOptimized(), lastCommit.IsOptimized(), "lastCommit.IsOptimized()=" + lastCommit.IsOptimized() + " vs IndexReader.IsOptimized()=" + r.IsOptimized());
-                r.Close();
+				IndexCommit lastCommit = (IndexCommit) commits[commits.Count - 1];
+				IndexReader r = IndexReader.Open(dir);
+				Assert.AreEqual(r.IsOptimized(), lastCommit.IsOptimized(), "lastCommit.isOptimized()=" + lastCommit.IsOptimized() + " vs IndexReader.isOptimized=" + r.IsOptimized());
+				r.Close();
 				Enclosing_Instance.VerifyCommitOrder(commits);
 				numOnCommit++;
 			}
@@ -124,20 +126,20 @@
 			}
 			internal int numOnInit;
 			internal int numOnCommit;
-            public virtual void OnInit(System.Collections.Generic.List<IndexCommitPoint> commits)
+			public virtual void  OnInit(System.Collections.IList commits)
 			{
 				Enclosing_Instance.VerifyCommitOrder(commits);
 				numOnInit++;
 				// On init, delete all commit points:
-				System.Collections.Generic.IEnumerator<IndexCommitPoint> it = commits.GetEnumerator();
+				System.Collections.IEnumerator it = commits.GetEnumerator();
 				while (it.MoveNext())
 				{
-                    IndexCommit commit = (IndexCommit)it.Current;
-                    commit.Delete();
-                    Assert.IsTrue(commit.IsDeleted());
+					IndexCommit commit = (IndexCommit) it.Current;
+					commit.Delete();
+					Assert.IsTrue(commit.IsDeleted());
 				}
 			}
-            public virtual void OnCommit(System.Collections.Generic.List<IndexCommitPoint> commits)
+			public virtual void  OnCommit(System.Collections.IList commits)
 			{
 				Enclosing_Instance.VerifyCommitOrder(commits);
 				int size = commits.Count;
@@ -176,16 +178,16 @@
 				InitBlock(enclosingInstance);
 				this.numToKeep = numToKeep;
 			}
-
-            public virtual void OnInit(System.Collections.Generic.List<IndexCommitPoint> commits)
+			
+			public virtual void  OnInit(System.Collections.IList commits)
 			{
 				Enclosing_Instance.VerifyCommitOrder(commits);
 				numOnInit++;
 				// do no deletions on init
 				DoDeletes(commits, false);
 			}
-
-            public virtual void OnCommit(System.Collections.Generic.List<IndexCommitPoint> commits)
+			
+			public virtual void  OnCommit(System.Collections.IList commits)
 			{
 				Enclosing_Instance.VerifyCommitOrder(commits);
 				DoDeletes(commits, true);
@@ -245,14 +247,14 @@
 				this.dir = dir;
 				this.expirationTimeSeconds = seconds;
 			}
-
-            public virtual void OnInit(System.Collections.Generic.List<IndexCommitPoint> commits)
+			
+			public virtual void  OnInit(System.Collections.IList commits)
 			{
 				Enclosing_Instance.VerifyCommitOrder(commits);
 				OnCommit(commits);
 			}
-
-            public virtual void OnCommit(System.Collections.Generic.List<IndexCommitPoint> commits)
+			
+			public virtual void  OnCommit(System.Collections.IList commits)
 			{
 				Enclosing_Instance.VerifyCommitOrder(commits);
 				
@@ -261,7 +263,7 @@
 				// Any commit older than expireTime should be deleted:
 				double expireTime = dir.FileModified(lastCommit.GetSegmentsFileName()) / 1000.0 - expirationTimeSeconds;
 				
-				System.Collections.Generic.IEnumerator<IndexCommitPoint> it = commits.GetEnumerator();
+				System.Collections.IEnumerator it = commits.GetEnumerator();
 				
 				while (it.MoveNext())
 				{
@@ -299,7 +301,7 @@
 			{
 				// Record last time when writer performed deletes of
 				// past commits
-				lastDeleteTime = (System.DateTime.Now.Ticks - 621355968000000000) / 10000;
+				lastDeleteTime = System.DateTime.Now.Millisecond;
 				writer = new IndexWriter(dir, autoCommit, new WhitespaceAnalyzer(), false, policy);
 				writer.SetUseCompoundFile(useCompoundFile);
 				for (int j = 0; j < 17; j++)
@@ -334,7 +336,7 @@
 					long modTime = dir.FileModified(fileName);
 					Assert.IsTrue(lastDeleteTime - modTime <= (SECONDS * 1000), "commit point was older than " + SECONDS + " seconds (" + (lastDeleteTime - modTime) + " msec) but did not get deleted");
 				}
-				catch (System.IO.IOException)
+				catch (System.IO.IOException e)
 				{
 					// OK
 					break;
@@ -360,20 +362,21 @@
 				bool autoCommit = pass < 2;
 				bool useCompoundFile = (pass % 2) > 0;
 				
+				// Never deletes a commit
 				KeepAllDeletionPolicy policy = new KeepAllDeletionPolicy(this);
 				
 				Directory dir = new RAMDirectory();
-                policy.dir = dir;
+				policy.dir = dir;
 				
 				IndexWriter writer = new IndexWriter(dir, autoCommit, new WhitespaceAnalyzer(), true, policy);
 				writer.SetMaxBufferedDocs(10);
 				writer.SetUseCompoundFile(useCompoundFile);
-                writer.SetMergeScheduler(new SerialMergeScheduler());
+				writer.SetMergeScheduler(new SerialMergeScheduler());
 				for (int i = 0; i < 107; i++)
 				{
 					AddDoc(writer);
-                    if (autoCommit && i % 10 == 0)
-                        writer.Commit();
+					if (autoCommit && i % 10 == 0)
+						writer.Commit();
 				}
 				writer.Close();
 				
@@ -384,28 +387,28 @@
 				
 				Assert.AreEqual(2, policy.numOnInit);
 				if (!autoCommit)
-					// If we are not auto committing then there should
-					// be exactly 2 commits (one per close above):
+				// If we are not auto committing then there should
+				// be exactly 2 commits (one per close above):
 					Assert.AreEqual(2, policy.numOnCommit);
-
-                // Test: ListCommits(Directory)
-                System.Collections.Generic.ICollection<IndexCommitPoint> commits = IndexReader.ListCommits(dir);
-                if (!autoCommit)
-                    // 1 from opening writer + 2 from closing writer
-                    Assert.AreEqual(3, commits.Count);
-                else
-                    // 1 from opening writer + 2 from closing writer
-                    // + 11 from calling writer.Commit() explicitly
-                    Assert.AreEqual(14, commits.Count);
-
-                System.Collections.Generic.IEnumerator<IndexCommitPoint> it = commits.GetEnumerator();
-                // Make sure we can open a reader on each commit
-                while (it.MoveNext())
-                {
-                    IndexCommit commit = (IndexCommit)it.Current;
-                    IndexReader r = IndexReader.Open(commit, null);
-                    r.Close();
-                }
+				
+				// Test listCommits
+				System.Collections.ICollection commits = IndexReader.ListCommits(dir);
+				if (!autoCommit)
+				// 1 from opening writer + 2 from closing writer
+					Assert.AreEqual(3, commits.Count);
+				// 1 from opening writer + 2 from closing writer +
+				// 11 from calling writer.commit() explicitly above
+				else
+					Assert.AreEqual(14, commits.Count);
+				
+				System.Collections.IEnumerator it = commits.GetEnumerator();
+				// Make sure we can open a reader on each commit:
+				while (it.MoveNext())
+				{
+					IndexCommit commit = (IndexCommit) it.Current;
+					IndexReader r = IndexReader.Open(commit, null);
+					r.Close();
+				}
 				
 				// Simplistic check: just verify all segments_N's still
 				// exist, and, I can open a reader on each:
@@ -424,10 +427,10 @@
 						// should have orphan'd at least one index file.
 						// Open & close a writer and assert that it
 						// actually removed something:
-						int preCount = dir.List().Length;
+						int preCount = dir.ListAll().Length;
 						writer = new IndexWriter(dir, new WhitespaceAnalyzer(), false, policy, IndexWriter.MaxFieldLength.LIMITED);
 						writer.Close();
-						int postCount = dir.List().Length;
+						int postCount = dir.ListAll().Length;
 						Assert.IsTrue(postCount < preCount);
 					}
 				}
@@ -436,6 +439,112 @@
 			}
 		}
 		
+		/* Uses KeepAllDeletionPolicy to keep all commits around,
+		* then, opens a new IndexWriter on a previous commit
+		* point. */
+		[Test]
+		public virtual void  TestOpenPriorSnapshot()
+		{
+			
+			// Never deletes a commit
+			KeepAllDeletionPolicy policy = new KeepAllDeletionPolicy(this);
+			
+			Directory dir = new MockRAMDirectory();
+			policy.dir = dir;
+			
+			IndexWriter writer = new IndexWriter(dir, new WhitespaceAnalyzer(), policy, IndexWriter.MaxFieldLength.LIMITED);
+			writer.SetMaxBufferedDocs(2);
+			for (int i = 0; i < 10; i++)
+			{
+				AddDoc(writer);
+				if ((1 + i) % 2 == 0)
+					writer.Commit();
+			}
+			writer.Close();
+			
+			System.Collections.ICollection commits = IndexReader.ListCommits(dir);
+			Assert.AreEqual(6, commits.Count);
+			IndexCommit lastCommit = null;
+			System.Collections.IEnumerator it = commits.GetEnumerator();
+			while (it.MoveNext())
+			{
+				IndexCommit commit = (IndexCommit) it.Current;
+				if (lastCommit == null || commit.GetGeneration() > lastCommit.GetGeneration())
+					lastCommit = commit;
+			}
+			Assert.IsTrue(lastCommit != null);
+			
+			// Now add 1 doc and optimize
+			writer = new IndexWriter(dir, new WhitespaceAnalyzer(), policy, IndexWriter.MaxFieldLength.LIMITED);
+			AddDoc(writer);
+			Assert.AreEqual(11, writer.NumDocs());
+			writer.Optimize();
+			writer.Close();
+			
+			Assert.AreEqual(7, IndexReader.ListCommits(dir).Count);
+			
+			// Now open writer on the commit just before optimize:
+			writer = new IndexWriter(dir, new WhitespaceAnalyzer(), policy, IndexWriter.MaxFieldLength.LIMITED, lastCommit);
+			Assert.AreEqual(10, writer.NumDocs());
+			
+			// Should undo our rollback:
+			writer.Rollback();
+			
+			IndexReader r = IndexReader.Open(dir);
+			// Still optimized, still 11 docs
+			Assert.IsTrue(r.IsOptimized());
+			Assert.AreEqual(11, r.NumDocs());
+			r.Close();
+			
+			writer = new IndexWriter(dir, new WhitespaceAnalyzer(), policy, IndexWriter.MaxFieldLength.LIMITED, lastCommit);
+			Assert.AreEqual(10, writer.NumDocs());
+			// Commits the rollback:
+			writer.Close();
+			
+			// Now 8 because we made another commit
+			Assert.AreEqual(8, IndexReader.ListCommits(dir).Count);
+			
+			r = IndexReader.Open(dir);
+			// Not optimized because we rolled it back, and now only
+			// 10 docs
+			Assert.IsTrue(!r.IsOptimized());
+			Assert.AreEqual(10, r.NumDocs());
+			r.Close();
+			
+			// Reoptimize
+			writer = new IndexWriter(dir, new WhitespaceAnalyzer(), policy, IndexWriter.MaxFieldLength.LIMITED);
+			writer.Optimize();
+			writer.Close();
+			
+			r = IndexReader.Open(dir);
+			Assert.IsTrue(r.IsOptimized());
+			Assert.AreEqual(10, r.NumDocs());
+			r.Close();
+			
+			// Now open writer on the commit just before optimize,
+			// but this time keeping only the last commit:
+			writer = new IndexWriter(dir, new WhitespaceAnalyzer(), new KeepOnlyLastCommitDeletionPolicy(), IndexWriter.MaxFieldLength.LIMITED, lastCommit);
+			Assert.AreEqual(10, writer.NumDocs());
+			
+			// Reader still sees optimized index, because writer
+			// opened on the prior commit has not yet committed:
+			r = IndexReader.Open(dir);
+			Assert.IsTrue(r.IsOptimized());
+			Assert.AreEqual(10, r.NumDocs());
+			r.Close();
+			
+			writer.Close();
+			
+			// Now reader sees unoptimized index:
+			r = IndexReader.Open(dir);
+			Assert.IsTrue(!r.IsOptimized());
+			Assert.AreEqual(10, r.NumDocs());
+			r.Close();
+			
+			dir.Close();
+		}
+		
+		
 		/* Test keeping NO commit points.  This is a viable and
 		* useful case eg where you want to build a big index with
 		* autoCommit false and you know there are no readers.
@@ -470,8 +579,8 @@
 				
 				Assert.AreEqual(2, policy.numOnInit);
 				if (!autoCommit)
-					// If we are not auto committing then there should
-					// be exactly 2 commits (one per close above):
+				// If we are not auto committing then there should
+				// be exactly 2 commits (one per close above):
 					Assert.AreEqual(2, policy.numOnCommit);
 				
 				// Simplistic check: just verify the index is in fact
@@ -732,7 +841,7 @@
 				
 				Assert.AreEqual(1 + 3 * (N + 1), policy.numOnInit);
 				if (!autoCommit)
-					Assert.AreEqual(2 * (N + 1), policy.numOnCommit);
+					Assert.AreEqual(3 * (N + 1), policy.numOnCommit);
 				
 				IndexSearcher searcher2 = new IndexSearcher(dir);
 				ScoreDoc[] hits2 = searcher2.Search(query, null, 1000).scoreDocs;

Added: incubator/lucene.net/trunk/C#/src/Test/Index/TestDirectoryReader.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Test/Index/TestDirectoryReader.cs?rev=832486&view=auto
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Test/Index/TestDirectoryReader.cs (added)
+++ incubator/lucene.net/trunk/C#/src/Test/Index/TestDirectoryReader.cs Tue Nov  3 18:06:27 2009
@@ -0,0 +1,228 @@
+/* 
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+using System;
+
+using NUnit.Framework;
+
+using StandardAnalyzer = Lucene.Net.Analysis.Standard.StandardAnalyzer;
+using Document = Lucene.Net.Documents.Document;
+using Field = Lucene.Net.Documents.Field;
+using Directory = Lucene.Net.Store.Directory;
+using RAMDirectory = Lucene.Net.Store.RAMDirectory;
+using LuceneTestCase = Lucene.Net.Util.LuceneTestCase;
+
+namespace Lucene.Net.Index
+{
+	
+    [TestFixture]
+	public class TestDirectoryReader:LuceneTestCase
+	{
+		protected internal Directory dir;
+		private Document doc1;
+		private Document doc2;
+		protected internal SegmentReader[] readers = new SegmentReader[2];
+		protected internal SegmentInfos sis;
+		
+		
+		public TestDirectoryReader(System.String s):base(s)
+		{
+		}
+		
+		[SetUp]
+		public override void  SetUp()
+		{
+			base.SetUp();
+			dir = new RAMDirectory();
+			doc1 = new Document();
+			doc2 = new Document();
+			DocHelper.SetupDoc(doc1);
+			DocHelper.SetupDoc(doc2);
+			DocHelper.WriteDoc(dir, doc1);
+			DocHelper.WriteDoc(dir, doc2);
+			sis = new SegmentInfos();
+			sis.Read(dir);
+		}
+		
+		protected internal virtual IndexReader OpenReader()
+		{
+			IndexReader reader;
+			reader = IndexReader.Open(dir);
+			Assert.IsTrue(reader is DirectoryReader);
+			
+			Assert.IsTrue(dir != null);
+			Assert.IsTrue(sis != null);
+			Assert.IsTrue(reader != null);
+			
+			return reader;
+		}
+		
+        [Test]
+		public virtual void  Test()
+		{
+			SetUp();
+			DoTestDocument();
+			DoTestUndeleteAll();
+		}
+		
+		public virtual void  DoTestDocument()
+		{
+			sis.Read(dir);
+			IndexReader reader = OpenReader();
+			Assert.IsTrue(reader != null);
+			Document newDoc1 = reader.Document(0);
+			Assert.IsTrue(newDoc1 != null);
+			Assert.IsTrue(DocHelper.NumFields(newDoc1) == DocHelper.NumFields(doc1) - DocHelper.unstored.Count);
+			Document newDoc2 = reader.Document(1);
+			Assert.IsTrue(newDoc2 != null);
+			Assert.IsTrue(DocHelper.NumFields(newDoc2) == DocHelper.NumFields(doc2) - DocHelper.unstored.Count);
+			TermFreqVector vector = reader.GetTermFreqVector(0, DocHelper.TEXT_FIELD_2_KEY);
+			Assert.IsTrue(vector != null);
+			TestSegmentReader.CheckNorms(reader);
+		}
+		
+		public virtual void  DoTestUndeleteAll()
+		{
+			sis.Read(dir);
+			IndexReader reader = OpenReader();
+			Assert.IsTrue(reader != null);
+			Assert.AreEqual(2, reader.NumDocs());
+			reader.DeleteDocument(0);
+			Assert.AreEqual(1, reader.NumDocs());
+			reader.UndeleteAll();
+			Assert.AreEqual(2, reader.NumDocs());
+			
+			// Ensure undeleteAll survives commit/close/reopen:
+			reader.Commit();
+			reader.Close();
+			
+			if (reader is MultiReader)
+			// MultiReader does not "own" the directory so it does
+			// not write the changes to sis on commit:
+				sis.Commit(dir);
+			
+			sis.Read(dir);
+			reader = OpenReader();
+			Assert.AreEqual(2, reader.NumDocs());
+			
+			reader.DeleteDocument(0);
+			Assert.AreEqual(1, reader.NumDocs());
+			reader.Commit();
+			reader.Close();
+			if (reader is MultiReader)
+			// MultiReader does not "own" the directory so it does
+			// not write the changes to sis on commit:
+				sis.Commit(dir);
+			sis.Read(dir);
+			reader = OpenReader();
+			Assert.AreEqual(1, reader.NumDocs());
+		}
+		
+		
+        [Test]
+		public virtual void  _testTermVectors()
+		{
+			MultiReader reader = new MultiReader(readers);
+			Assert.IsTrue(reader != null);
+		}
+		
+		
+        [Test]
+		public virtual void  TestIsCurrent()
+		{
+			RAMDirectory ramDir1 = new RAMDirectory();
+			AddDoc(ramDir1, "test foo", true);
+			RAMDirectory ramDir2 = new RAMDirectory();
+			AddDoc(ramDir2, "test blah", true);
+			IndexReader[] readers = new IndexReader[]{IndexReader.Open(ramDir1), IndexReader.Open(ramDir2)};
+			MultiReader mr = new MultiReader(readers);
+			Assert.IsTrue(mr.IsCurrent()); // just opened, must be current
+			AddDoc(ramDir1, "more text", false);
+			Assert.IsFalse(mr.IsCurrent()); // has been modified, not current anymore
+			AddDoc(ramDir2, "even more text", false);
+			Assert.IsFalse(mr.IsCurrent()); // has been modified even more, not current anymore
+			try
+			{
+				mr.GetVersion();
+				Assert.Fail();
+			}
+			catch (System.NotSupportedException e)
+			{
+				// expected exception
+			}
+			mr.Close();
+		}
+		
+        [Test]
+		public virtual void  TestMultiTermDocs()
+		{
+			RAMDirectory ramDir1 = new RAMDirectory();
+			AddDoc(ramDir1, "test foo", true);
+			RAMDirectory ramDir2 = new RAMDirectory();
+			AddDoc(ramDir2, "test blah", true);
+			RAMDirectory ramDir3 = new RAMDirectory();
+			AddDoc(ramDir3, "test wow", true);
+			
+			IndexReader[] readers1 = new IndexReader[]{IndexReader.Open(ramDir1), IndexReader.Open(ramDir3)};
+			IndexReader[] readers2 = new IndexReader[]{IndexReader.Open(ramDir1), IndexReader.Open(ramDir2), IndexReader.Open(ramDir3)};
+			MultiReader mr2 = new MultiReader(readers1);
+			MultiReader mr3 = new MultiReader(readers2);
+			
+			// test mixing up TermDocs and TermEnums from different readers.
+			TermDocs td2 = mr2.TermDocs();
+			TermEnum te3 = mr3.Terms(new Term("body", "wow"));
+			td2.Seek(te3);
+			int ret = 0;
+			
+			// This should blow up if we forget to check that the TermEnum is from the same
+			// reader as the TermDocs.
+			while (td2.Next())
+				ret += td2.Doc();
+			td2.Close();
+			te3.Close();
+			
+			// really a dummy assert to ensure that we got some docs and to ensure that
+			// nothing is optimized out.
+			Assert.IsTrue(ret > 0);
+		}
+		
+        [Test]
+		public virtual void  TestAllTermDocs()
+		{
+			IndexReader reader = OpenReader();
+			int NUM_DOCS = 2;
+			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();
+		}
+		
+		private void  AddDoc(RAMDirectory ramDir1, System.String s, bool create)
+		{
+			IndexWriter iw = new IndexWriter(ramDir1, new StandardAnalyzer(), create, IndexWriter.MaxFieldLength.LIMITED);
+			Document doc = new Document();
+			doc.Add(new Field("body", s, Field.Store.YES, Field.Index.ANALYZED));
+			iw.AddDocument(doc);
+			iw.Close();
+		}
+	}
+}
\ No newline at end of file

Modified: incubator/lucene.net/trunk/C#/src/Test/Index/TestDoc.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Test/Index/TestDoc.cs?rev=832486&r1=832485&r2=832486&view=diff
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Test/Index/TestDoc.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Test/Index/TestDoc.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,12 @@
 
 using NUnit.Framework;
 
-using LuceneTestCase = Lucene.Net.Util.LuceneTestCase;
-
 using SimpleAnalyzer = Lucene.Net.Analysis.SimpleAnalyzer;
-using FSDirectory = Lucene.Net.Store.FSDirectory;
-using Directory = Lucene.Net.Store.Directory;
-using Document = Lucene.Net.Documents.Document;
-using Field = Lucene.Net.Documents.Field;
 using FileDocument = Lucene.Net.Demo.FileDocument;
+using Document = Lucene.Net.Documents.Document;
+using Directory = Lucene.Net.Store.Directory;
+using FSDirectory = Lucene.Net.Store.FSDirectory;
+using LuceneTestCase = Lucene.Net.Util.LuceneTestCase;
 
 namespace Lucene.Net.Index
 {
@@ -35,17 +33,17 @@
 	/// <summary>JUnit adaptation of an older test case DocTest.
 	/// 
 	/// </summary>
-	/// <version>  $Id: TestDoc.java 583534 2007-10-10 16:46:35Z mikemccand $
+	/// <version>  $Id: TestDoc.java 780770 2009-06-01 18:34:10Z uschindler $
 	/// </version>
 	[TestFixture]
-	public class TestDoc
+	public class TestDoc:LuceneTestCase
 	{
 		
 		/// <summary>Main for running test case by itself. </summary>
 		[STAThread]
 		public static void  Main(System.String[] args)
 		{
-			// NUnit.Core.TestRunner.Run(new NUnit.Core.TestSuite(typeof(TestDoc)));    // {{Aroush}} where is 'TestRunner' in NUnit
+			// TestRunner.run(new TestSuite(typeof(TestDoc))); // {{Aroush-2.9}} how is this done in NUnit?
 		}
 		
 		
@@ -58,15 +56,16 @@
 		/// a few text files created in the current working directory.
 		/// </summary>
 		[SetUp]
-		public virtual void  SetUp()
+		public override void  SetUp()
 		{
-			workDir = new System.IO.FileInfo(System.IO.Path.Combine(SupportClass.AppSettings.Get("tempDir", "tempDir"), "TestDoc"));
+			base.SetUp();
+			workDir = new System.IO.FileInfo(System.IO.Path.Combine(SupportClass.AppSettings.Get("tempDir", ""), "TestDoc"));
 			System.IO.Directory.CreateDirectory(workDir.FullName);
 			
 			indexDir = new System.IO.FileInfo(System.IO.Path.Combine(workDir.FullName, "testIndex"));
 			System.IO.Directory.CreateDirectory(indexDir.FullName);
 			
-			Directory directory = FSDirectory.GetDirectory(indexDir, true);
+			Directory directory = FSDirectory.Open(indexDir);
 			directory.Close();
 			
 			files = new System.Collections.ArrayList();
@@ -117,8 +116,8 @@
 				{
 					pw.Close();
 				}
-				// if (fw != null)
-				//	fw.Close();     // No need to close fw in .NET as it is clased when pw is cloased
+				if (fw != null)
+					fw.Close();
 			}
 		}
 		
@@ -137,7 +136,7 @@
 			System.IO.MemoryStream sw = new System.IO.MemoryStream();
 			System.IO.StreamWriter out_Renamed = new System.IO.StreamWriter(sw);
 			
-			Directory directory = FSDirectory.GetDirectory(indexDir);
+			Directory directory = FSDirectory.Open(indexDir);
 			IndexWriter writer = new IndexWriter(directory, new SimpleAnalyzer(), true, IndexWriter.MaxFieldLength.LIMITED);
 			
 			SegmentInfo si1 = IndexDoc(writer, "test.txt");
@@ -155,8 +154,8 @@
 			
 			SegmentInfo siMerge3 = Merge(siMerge, siMerge2, "merge3", false);
 			PrintSegment(out_Renamed, siMerge3);
-
-            directory.Close();
+			
+			directory.Close();
 			out_Renamed.Close();
 			sw.Close();
 			System.String multiFileOutput = System.Text.ASCIIEncoding.ASCII.GetString(sw.ToArray());
@@ -165,7 +164,7 @@
 			sw = new System.IO.MemoryStream();
 			out_Renamed = new System.IO.StreamWriter(sw);
 			
-			directory = FSDirectory.GetDirectory(indexDir);
+			directory = FSDirectory.Open(indexDir);
 			writer = new IndexWriter(directory, new SimpleAnalyzer(), true, IndexWriter.MaxFieldLength.LIMITED);
 			
 			si1 = IndexDoc(writer, "test.txt");
@@ -183,15 +182,15 @@
 			
 			siMerge3 = Merge(siMerge, siMerge2, "merge3", true);
 			PrintSegment(out_Renamed, siMerge3);
-
-            directory.Close();
-            out_Renamed.Close();
+			
+			directory.Close();
+			out_Renamed.Close();
 			sw.Close();
 			System.String singleFileOutput = System.Text.ASCIIEncoding.ASCII.GetString(sw.ToArray());
 			
 			Assert.AreEqual(multiFileOutput, singleFileOutput);
 		}
-				
+		
 		private SegmentInfo IndexDoc(IndexWriter writer, System.String fileName)
 		{
 			System.IO.FileInfo file = new System.IO.FileInfo(System.IO.Path.Combine(workDir.FullName, fileName));
@@ -204,12 +203,10 @@
 		
 		private SegmentInfo Merge(SegmentInfo si1, SegmentInfo si2, System.String merged, bool useCompoundFile)
 		{
-			Directory directory = FSDirectory.GetDirectory(indexDir, false);
-			
 			SegmentReader r1 = SegmentReader.Get(si1);
 			SegmentReader r2 = SegmentReader.Get(si2);
 			
-			SegmentMerger merger = new SegmentMerger(directory, merged);
+			SegmentMerger merger = new SegmentMerger(si1.dir, merged);
 			
 			merger.Add(r1);
 			merger.Add(r2);
@@ -218,21 +215,19 @@
 			
 			if (useCompoundFile)
 			{
-				System.Collections.ArrayList filesToDelete = merger.CreateCompoundFile(merged + ".cfs");
+				System.Collections.IList filesToDelete = merger.CreateCompoundFile(merged + ".cfs");
 				for (System.Collections.IEnumerator iter = filesToDelete.GetEnumerator(); iter.MoveNext(); )
 				{
-					directory.DeleteFile((System.String) iter.Current);
+					si1.dir.DeleteFile((System.String) iter.Current);
 				}
 			}
 			
-			directory.Close();
-			return new SegmentInfo(merged, si1.docCount + si2.docCount, directory, useCompoundFile, true);
+			return new SegmentInfo(merged, si1.docCount + si2.docCount, si1.dir, useCompoundFile, true);
 		}
 		
 		
 		private void  PrintSegment(System.IO.StreamWriter out_Renamed, SegmentInfo si)
 		{
-			Directory directory = FSDirectory.GetDirectory(indexDir, false);
 			SegmentReader reader = SegmentReader.Get(si);
 			
 			for (int i = 0; i < reader.NumDocs(); i++)
@@ -267,7 +262,6 @@
 			}
 			tis.Close();
 			reader.Close();
-			directory.Close();
 		}
 	}
 }
\ No newline at end of file

Modified: incubator/lucene.net/trunk/C#/src/Test/Index/TestDocumentWriter.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Test/Index/TestDocumentWriter.cs?rev=832486&r1=832485&r2=832486&view=diff
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Test/Index/TestDocumentWriter.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Test/Index/TestDocumentWriter.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.
@@ -21,12 +21,14 @@
 
 using Analyzer = Lucene.Net.Analysis.Analyzer;
 using SimpleAnalyzer = Lucene.Net.Analysis.SimpleAnalyzer;
-using Token = Lucene.Net.Analysis.Token;
 using TokenFilter = Lucene.Net.Analysis.TokenFilter;
 using TokenStream = Lucene.Net.Analysis.TokenStream;
 using WhitespaceAnalyzer = Lucene.Net.Analysis.WhitespaceAnalyzer;
 using WhitespaceTokenizer = Lucene.Net.Analysis.WhitespaceTokenizer;
 using StandardAnalyzer = Lucene.Net.Analysis.Standard.StandardAnalyzer;
+using PayloadAttribute = Lucene.Net.Analysis.Tokenattributes.PayloadAttribute;
+using PositionIncrementAttribute = Lucene.Net.Analysis.Tokenattributes.PositionIncrementAttribute;
+using TermAttribute = Lucene.Net.Analysis.Tokenattributes.TermAttribute;
 using Document = Lucene.Net.Documents.Document;
 using Field = Lucene.Net.Documents.Field;
 using Fieldable = Lucene.Net.Documents.Fieldable;
@@ -34,16 +36,17 @@
 using Store = Lucene.Net.Documents.Field.Store;
 using TermVector = Lucene.Net.Documents.Field.TermVector;
 using RAMDirectory = Lucene.Net.Store.RAMDirectory;
-using LuceneTestCase = Lucene.Net.Util.LuceneTestCase;
+using AttributeSource = Lucene.Net.Util.AttributeSource;
+using BaseTokenStreamTestCase = Lucene.Net.Analysis.BaseTokenStreamTestCase;
 using _TestUtil = Lucene.Net.Util._TestUtil;
 
 namespace Lucene.Net.Index
 {
 	
 	[TestFixture]
-	public class TestDocumentWriter : LuceneTestCase
+	public class TestDocumentWriter:BaseTokenStreamTestCase
 	{
-		private class AnonymousClassAnalyzer : Analyzer
+		private class AnonymousClassAnalyzer:Analyzer
 		{
 			public AnonymousClassAnalyzer(TestDocumentWriter enclosingInstance)
 			{
@@ -72,19 +75,20 @@
 				return 500;
 			}
 		}
-		
-		private class AnonymousClassAnalyzer1 : Analyzer
+		private class AnonymousClassAnalyzer1:Analyzer
 		{
 			public AnonymousClassAnalyzer1(TestDocumentWriter enclosingInstance)
 			{
 				InitBlock(enclosingInstance);
 			}
-			
 			private class AnonymousClassTokenFilter:TokenFilter
 			{
 				private void  InitBlock(AnonymousClassAnalyzer1 enclosingInstance)
 				{
 					this.enclosingInstance = enclosingInstance;
+					termAtt = (TermAttribute) AddAttribute(typeof(TermAttribute));
+					payloadAtt = (PayloadAttribute) AddAttribute(typeof(PayloadAttribute));
+					posIncrAtt = (PositionIncrementAttribute) AddAttribute(typeof(PositionIncrementAttribute));
 				}
 				private AnonymousClassAnalyzer1 enclosingInstance;
 				public AnonymousClassAnalyzer1 Enclosing_Instance
@@ -100,43 +104,42 @@
 					InitBlock(enclosingInstance);
 				}
 				internal bool first = true;
-				internal Token buffered;
-				
-				public override Token Next()
-				{
-					return input.Next();
-				}
+				internal AttributeSource.State state;
 				
-				public override Token Next(Token reusableToken)
+				public override bool IncrementToken()
 				{
-					if (buffered != null)
+					if (state != null)
 					{
-						Token nextToken = buffered;
-						buffered = null;
-						return nextToken;
+						RestoreState(state);
+						payloadAtt.SetPayload(null);
+						posIncrAtt.SetPositionIncrement(0);
+						termAtt.SetTermBuffer(new char[]{'b'}, 0, 1);
+						state = null;
+						return true;
 					}
-					Token nextToken2 = input.Next(reusableToken);
-					if (nextToken2 == null)
-						return null;
-					if (System.Char.IsDigit(nextToken2.TermBuffer()[0]))
+					
+					bool hasNext = input.IncrementToken();
+					if (!hasNext)
+						return false;
+					if (System.Char.IsDigit(termAtt.TermBuffer()[0]))
 					{
-						nextToken2.SetPositionIncrement(nextToken2.TermBuffer()[0] - '0');
+						posIncrAtt.SetPositionIncrement(termAtt.TermBuffer()[0] - '0');
 					}
 					if (first)
 					{
 						// set payload on first position only
-						nextToken2.SetPayload(new Payload(new byte[]{100}));
+						payloadAtt.SetPayload(new Payload(new byte[]{100}));
 						first = false;
 					}
 					
 					// index a "synonym" for every token
-					buffered = (Token) nextToken2.Clone();
-					buffered.SetPayload(null);
-					buffered.SetPositionIncrement(0);
-					buffered.SetTermBuffer(new char[]{'b'}, 0, 1);
-					
-					return nextToken2;
+					state = CaptureState();
+					return true;
 				}
+				
+				internal TermAttribute termAtt;
+				internal PayloadAttribute payloadAtt;
+				internal PositionIncrementAttribute posIncrAtt;
 			}
 			private void  InitBlock(TestDocumentWriter enclosingInstance)
 			{
@@ -156,8 +159,7 @@
 				return new AnonymousClassTokenFilter(this, new WhitespaceTokenizer(reader));
 			}
 		}
-		
-		private class AnonymousClassTokenStream : TokenStream
+		private class AnonymousClassTokenStream:TokenStream
 		{
 			public AnonymousClassTokenStream(TestDocumentWriter enclosingInstance)
 			{
@@ -166,6 +168,7 @@
 			private void  InitBlock(TestDocumentWriter enclosingInstance)
 			{
 				this.enclosingInstance = enclosingInstance;
+				termAtt = (TermAttribute) AddAttribute(typeof(TermAttribute));
 			}
 			private TestDocumentWriter enclosingInstance;
 			public TestDocumentWriter Enclosing_Instance
@@ -179,25 +182,31 @@
 			private System.String[] tokens = new System.String[]{"term1", "term2", "term3", "term2"};
 			private int index = 0;
 			
-			public override Token Next(Token reusableToken)
+			private TermAttribute termAtt;
+			
+			public override bool IncrementToken()
 			{
-                System.Diagnostics.Debug.Assert(reusableToken != null);
 				if (index == tokens.Length)
 				{
-					return null;
+					return false;
 				}
 				else
 				{
-					return reusableToken.Reinit(tokens[index++], 0, 0);
+					termAtt.SetTermBuffer(tokens[index++]);
+					return true;
 				}
 			}
 		}
 		private RAMDirectory dir;
 		
+		public TestDocumentWriter(System.String s):base(s)
+		{
+		}
+		
 		[SetUp]
 		public override void  SetUp()
 		{
-            base.SetUp();
+			base.SetUp();
 			dir = new RAMDirectory();
 		}
 		
@@ -249,12 +258,12 @@
 			
 			// test that the norms are not present in the segment if
 			// omitNorms is true
-			for (int i = 0; i < reader.FieldInfos().Size(); i++)
+			for (int i = 0; i < reader.core_ForNUnit.fieldInfos_ForNUnit.Size(); i++)
 			{
-				FieldInfo fi = reader.FieldInfos().FieldInfo(i);
-                if (fi.IsIndexed_ForNUnitTest())
+				FieldInfo fi = reader.core_ForNUnit.fieldInfos_ForNUnit.FieldInfo(i);
+				if (fi.isIndexed_ForNUnit)
 				{
-					Assert.IsTrue(fi.omitNorms == !reader.HasNorms(fi.Name_ForNUnitTest));
+					Assert.IsTrue(fi.omitNorms_ForNUnit == !reader.HasNorms(fi.name_ForNUnit));
 				}
 			}
 		}
@@ -263,8 +272,8 @@
 		public virtual void  TestPositionIncrementGap()
 		{
 			Analyzer analyzer = new AnonymousClassAnalyzer(this);
-
-            IndexWriter writer = new IndexWriter(dir, analyzer, true, IndexWriter.MaxFieldLength.LIMITED);
+			
+			IndexWriter writer = new IndexWriter(dir, analyzer, true, IndexWriter.MaxFieldLength.LIMITED);
 			
 			Document doc = new Document();
 			doc.Add(new Field("repeated", "repeated one", Field.Store.YES, Field.Index.ANALYZED));
@@ -288,8 +297,8 @@
 		public virtual void  TestTokenReuse()
 		{
 			Analyzer analyzer = new AnonymousClassAnalyzer1(this);
-
-            IndexWriter writer = new IndexWriter(dir, analyzer, true, IndexWriter.MaxFieldLength.LIMITED);
+			
+			IndexWriter writer = new IndexWriter(dir, analyzer, true, IndexWriter.MaxFieldLength.LIMITED);
 			
 			Document doc = new Document();
 			doc.Add(new Field("f1", "a 5 a a", Field.Store.YES, Field.Index.ANALYZED));
@@ -316,7 +325,7 @@
 		[Test]
 		public virtual void  TestPreAnalyzedField()
 		{
-            IndexWriter writer = new IndexWriter(dir, new SimpleAnalyzer(), true, IndexWriter.MaxFieldLength.LIMITED);
+			IndexWriter writer = new IndexWriter(dir, new SimpleAnalyzer(), true, IndexWriter.MaxFieldLength.LIMITED);
 			Document doc = new Document();
 			
 			doc.Add(new Field("preanalyzed", new AnonymousClassTokenStream(this), TermVector.NO));
@@ -358,14 +367,13 @@
 			doc.Add(new Field("f2", "v1", Field.Store.YES, Field.Index.NOT_ANALYZED, TermVector.WITH_POSITIONS_OFFSETS));
 			doc.Add(new Field("f2", "v2", Field.Store.YES, Field.Index.NOT_ANALYZED, TermVector.NO));
 			
-			RAMDirectory ram = new RAMDirectory();
-            IndexWriter writer = new IndexWriter(ram, new StandardAnalyzer(), true, IndexWriter.MaxFieldLength.LIMITED);
+			IndexWriter writer = new IndexWriter(dir, new StandardAnalyzer(), true, IndexWriter.MaxFieldLength.LIMITED);
 			writer.AddDocument(doc);
 			writer.Close();
-
-            _TestUtil.CheckIndex(ram);
 			
-			IndexReader reader = IndexReader.Open(ram);
+			_TestUtil.CheckIndex(dir);
+			
+			IndexReader reader = IndexReader.Open(dir);
 			// f1
 			TermFreqVector tfv1 = reader.GetTermFreqVector(0, "f1");
 			Assert.IsNotNull(tfv1);
@@ -375,5 +383,39 @@
 			Assert.IsNotNull(tfv2);
 			Assert.AreEqual(2, tfv2.GetTerms().Length, "the 'with_tv' setting should rule!");
 		}
+		
+		/// <summary> Test adding two fields with the same name, one indexed
+		/// the other stored only. The omitNorms and omitTermFreqAndPositions setting
+		/// of the stored field should not affect the indexed one (LUCENE-1590)
+		/// </summary>
+		[Test]
+		public virtual void  TestLUCENE_1590()
+		{
+			Document doc = new Document();
+			// f1 has no norms
+			doc.Add(new Field("f1", "v1", Field.Store.NO, Field.Index.ANALYZED_NO_NORMS));
+			doc.Add(new Field("f1", "v2", Field.Store.YES, Field.Index.NO));
+			// f2 has no TF
+			Field f = new Field("f2", "v1", Field.Store.NO, Field.Index.ANALYZED);
+			f.SetOmitTermFreqAndPositions(true);
+			doc.Add(f);
+			doc.Add(new Field("f2", "v2", Field.Store.YES, Field.Index.NO));
+			
+			IndexWriter writer = new IndexWriter(dir, new StandardAnalyzer(), true, IndexWriter.MaxFieldLength.LIMITED);
+			writer.AddDocument(doc);
+			writer.Optimize(); // be sure to have a single segment
+			writer.Close();
+			
+			_TestUtil.CheckIndex(dir);
+			
+			SegmentReader reader = SegmentReader.GetOnlySegmentReader(dir);
+			FieldInfos fi = reader.FieldInfos();
+			// f1
+			Assert.IsFalse(reader.HasNorms("f1"), "f1 should have no norms");
+			Assert.IsFalse(fi.FieldInfo("f1").omitTermFreqAndPositions_ForNUnit, "omitTermFreqAndPositions field bit should not be set for f1");
+			// f2
+			Assert.IsTrue(reader.HasNorms("f2"), "f2 should have norms");
+			Assert.IsTrue(fi.FieldInfo("f2").omitTermFreqAndPositions_ForNUnit, "omitTermFreqAndPositions field bit should be set for f2");
+		}
 	}
 }
\ No newline at end of file

Modified: incubator/lucene.net/trunk/C#/src/Test/Index/TestFieldInfos.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Test/Index/TestFieldInfos.cs?rev=832486&r1=832485&r2=832486&view=diff
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Test/Index/TestFieldInfos.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Test/Index/TestFieldInfos.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.
@@ -27,22 +27,22 @@
 namespace Lucene.Net.Index
 {
 	
-	
 	//import org.cnlp.utils.properties.ResourceBundleHelper;
+	
 	[TestFixture]
-	public class TestFieldInfos : LuceneTestCase
+	public class TestFieldInfos:LuceneTestCase
 	{
 		
-		private Lucene.Net.Documents.Document testDoc = new Lucene.Net.Documents.Document();
+		private Document testDoc = new Document();
 		
-		// public TestFieldInfos(System.String s)
-		// {
-		// }
+		public TestFieldInfos(System.String s):base(s)
+		{
+		}
 		
 		[SetUp]
-		public override void SetUp()
+		public override void  SetUp()
 		{
-            base.SetUp();
+			base.SetUp();
 			DocHelper.SetupDoc(testDoc);
 		}
 		
@@ -54,7 +54,7 @@
 			FieldInfos fieldInfos = new FieldInfos();
 			fieldInfos.Add(testDoc);
 			//Since the complement is stored as well in the fields map
-			Assert.IsTrue(fieldInfos.Size() == ((System.Collections.Hashtable) DocHelper.all).Count); //this is all b/c we are using the no-arg constructor
+			Assert.IsTrue(fieldInfos.Size() == DocHelper.all.Count); //this is all b/c we are using the no-arg constructor
 			RAMDirectory dir = new RAMDirectory();
 			System.String name = "testFile";
 			IndexOutput output = dir.CreateOutput(name);
@@ -70,27 +70,27 @@
 				Assert.IsTrue(fieldInfos.Size() == readIn.Size());
 				FieldInfo info = readIn.FieldInfo("textField1");
 				Assert.IsTrue(info != null);
-				Assert.IsTrue(info.storeTermVector == false);
-				Assert.IsTrue(info.omitNorms == false);
+				Assert.IsTrue(info.storeTermVector_ForNUnit == false);
+				Assert.IsTrue(info.omitNorms_ForNUnit == false);
 				
 				info = readIn.FieldInfo("textField2");
 				Assert.IsTrue(info != null);
-				Assert.IsTrue(info.storeTermVector == true);
-				Assert.IsTrue(info.omitNorms == false);
+				Assert.IsTrue(info.storeTermVector_ForNUnit == true);
+				Assert.IsTrue(info.omitNorms_ForNUnit == false);
 				
 				info = readIn.FieldInfo("textField3");
 				Assert.IsTrue(info != null);
-				Assert.IsTrue(info.storeTermVector == false);
-				Assert.IsTrue(info.omitNorms == true);
+				Assert.IsTrue(info.storeTermVector_ForNUnit == false);
+				Assert.IsTrue(info.omitNorms_ForNUnit == true);
 				
 				info = readIn.FieldInfo("omitNorms");
 				Assert.IsTrue(info != null);
-				Assert.IsTrue(info.storeTermVector == false);
-				Assert.IsTrue(info.omitNorms == true);
+				Assert.IsTrue(info.storeTermVector_ForNUnit == false);
+				Assert.IsTrue(info.omitNorms_ForNUnit == true);
 				
 				dir.Close();
 			}
-			catch (System.IO.IOException)
+			catch (System.IO.IOException e)
 			{
 				Assert.IsTrue(false);
 			}



Mime
View raw message