Lucene.Net.Index.TestIndexReader.TestReadOnly C# (CSharp) Method

TestReadOnly() private method

private TestReadOnly ( ) : void
return void
		public virtual void  TestReadOnly()
		{
			RAMDirectory d = new MockRAMDirectory();
			IndexWriter writer = new IndexWriter(d, new StandardAnalyzer(Util.Version.LUCENE_CURRENT), true, IndexWriter.MaxFieldLength.LIMITED);
			AddDocumentWithFields(writer);
			writer.Commit();
			AddDocumentWithFields(writer);
			writer.Close();
			
			IndexReader r = IndexReader.Open(d, true);
            Assert.Throws<System.NotSupportedException>(() => r.DeleteDocument(0));
			
			writer = new IndexWriter(d, new StandardAnalyzer(Util.Version.LUCENE_CURRENT), false, IndexWriter.MaxFieldLength.LIMITED);
			AddDocumentWithFields(writer);
			writer.Close();
			
			// Make sure reopen is still readonly:
			IndexReader r2 = r.Reopen();
			r.Close();
			
			Assert.IsFalse(r == r2);
			Assert.Throws<System.NotSupportedException>(() => r2.DeleteDocument(0));

            writer = new IndexWriter(d, new StandardAnalyzer(Util.Version.LUCENE_CURRENT), false, IndexWriter.MaxFieldLength.LIMITED);
			writer.Optimize();
			writer.Close();
			
			// Make sure reopen to a single segment is still readonly:
			IndexReader r3 = r2.Reopen();
			r2.Close();
			
			Assert.IsFalse(r == r2);
            Assert.Throws<System.NotSupportedException>(() => r3.DeleteDocument(0));
			
			// Make sure write lock isn't held
            writer = new IndexWriter(d, new StandardAnalyzer(Util.Version.LUCENE_CURRENT), false, IndexWriter.MaxFieldLength.LIMITED);
			writer.Close();
			
			r3.Close();
		}