public virtual void  TestCommitUserData()
		{
			Directory dir = new MockRAMDirectory();
			IndexWriter w = new IndexWriter(dir, new WhitespaceAnalyzer(), IndexWriter.MaxFieldLength.LIMITED);
			w.SetMaxBufferedDocs(2);
			for (int j = 0; j < 17; j++)
				AddDoc(w);
			w.Close();
			
			Assert.AreEqual(0, IndexReader.GetCommitUserData(dir).Count);
			
			IndexReader r = IndexReader.Open(dir);
			// commit(Map) never called for this index
			Assert.AreEqual(0, r.GetCommitUserData().Count);
			r.Close();
			
			w = new IndexWriter(dir, new WhitespaceAnalyzer(), IndexWriter.MaxFieldLength.LIMITED);
			w.SetMaxBufferedDocs(2);
			for (int j = 0; j < 17; j++)
				AddDoc(w);
            System.Collections.Generic.IDictionary<string, string> data = new System.Collections.Generic.Dictionary<string,string>();
			data["label"] = "test1";
			w.Commit(data);
			w.Close();
			
			Assert.AreEqual("test1", IndexReader.GetCommitUserData(dir)["label"]);
			
			r = IndexReader.Open(dir);
			Assert.AreEqual("test1", r.GetCommitUserData()["label"]);
			r.Close();
			
			w = new IndexWriter(dir, new WhitespaceAnalyzer(), IndexWriter.MaxFieldLength.LIMITED);
			w.Optimize();
			w.Close();
			
			Assert.AreEqual("test1", IndexReader.GetCommitUserData(dir)["label"]);
			
			dir.Close();
		}
		public virtual void  TestRandomIWReader()
		{
			this.r = NewRandom();
			Directory dir = new MockRAMDirectory();
			
			// TODO: verify equals using IW.getReader
			DocsAndWriter dw = IndexRandomIWReader(10, 100, 100, dir);
			IndexReader r = dw.writer.GetReader();
			dw.writer.Commit();
			VerifyEquals(r, dir, "id");
			r.Close();
			dw.writer.Close();
			dir.Close();
		}
        public void TestFutureCommit()
        {
            Directory dir = new MockRAMDirectory();

            IndexWriter w = new IndexWriter(dir, new WhitespaceAnalyzer(), new NoDeletionPolicy(), IndexWriter.MaxFieldLength.UNLIMITED);
            Document doc = new Document();
            w.AddDocument(doc);

            // commit to "first"
            System.Collections.Generic.Dictionary<string, string> commitData = new System.Collections.Generic.Dictionary<string, string>();
            commitData["tag"]="first";
            w.Commit(commitData);

            // commit to "second"
            w.AddDocument(doc);
            commitData["tag"]="second";
            w.Commit(commitData);
            w.Close();

            // open "first" with IndexWriter
            IndexCommit commit = null;
            System.Collections.IEnumerator it = IndexReader.ListCommits(dir).GetEnumerator();
            while (it.MoveNext())
            {
                IndexCommit c = (IndexCommit)it.Current;
                string tag = (String)c.GetUserData()["tag"];
                if ("first".Equals(tag))
                {
                    commit = c;
                    break;
                }
            }

            Assert.NotNull(commit);

            w = new IndexWriter(dir, new WhitespaceAnalyzer(), new NoDeletionPolicy(), IndexWriter.MaxFieldLength.UNLIMITED, commit);

            Assert.AreEqual(1, w.NumDocs());

            // commit IndexWriter to "third"
            w.AddDocument(doc);
            commitData["tag"]="third";
            w.Commit(commitData);
            w.Close();

            // make sure "second" commit is still there
            commit = null;
            it = IndexReader.ListCommits(dir).GetEnumerator();
            while (it.MoveNext())
            {
                IndexCommit c = (IndexCommit)it.Current;
                string tag = (String)c.GetUserData()["tag"];
                if ("second".Equals(tag))
                {
                    commit = c;
                    break;
                }
            }

            Assert.NotNull(commit);

            IndexReader r = IndexReader.Open(commit, true);
            Assert.AreEqual(2, r.NumDocs());
            r.Close();

            // open "second", w/ writeable IndexReader & commit
            r = IndexReader.Open(commit, new NoDeletionPolicy(), false);
            Assert.AreEqual(2, r.NumDocs());
            r.DeleteDocument(0);
            r.DeleteDocument(1);
            commitData["tag"]="fourth";
            r.Commit(commitData);
            r.Close();

            // make sure "third" commit is still there
            commit = null;
            it = IndexReader.ListCommits(dir).GetEnumerator();
            while (it.MoveNext())
            {
                IndexCommit c = (IndexCommit)it.Current;
                string tag = (String)c.GetUserData()["tag"];
                if ("third".Equals(tag))
                {
                    commit = c;
                    break;
                }
            }
            Assert.NotNull(commit);

            dir.Close();
        }