Lucene.Net.Index.TestFieldsReader.TestExceptions C# (CSharp) Method

TestExceptions() private method

private TestExceptions ( ) : void
return void
		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.DirectoryInfo indexDir = new System.IO.DirectoryInfo(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, true);
				
				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);
			}
		}
	}