private void  CopyFiles(Directory dir, IndexCommit cp)
 {
     // While we hold the snapshot, and nomatter how long
     // we take to do the backup, the IndexWriter will
     // never delete the files in the snapshot:
     System.Collections.Generic.ICollection <string> files = cp.FileNames;
     foreach (string fileName in files)
     {
         // NOTE: in a real backup you would not use
         // readFile; you would need to use something else
         // that copies the file to a backup location.  This
         // could even be a spawned shell process (eg "tar",
         // "zip") that takes the list of files and builds a
         // backup.
         ReadFile(dir, fileName);
     }
 }
        public virtual void  TestReuseAcrossWriters()
        {
            Directory dir = new MockRAMDirectory();

            SnapshotDeletionPolicy dp     = new SnapshotDeletionPolicy(new KeepOnlyLastCommitDeletionPolicy());
            IndexWriter            writer = new IndexWriter(dir, new StandardAnalyzer(Util.Version.LUCENE_CURRENT), dp, IndexWriter.MaxFieldLength.UNLIMITED, null);

            // Force frequent flushes
            writer.SetMaxBufferedDocs(2);
            Document doc = new Document();

            doc.Add(new Field("content", "aaa", Field.Store.YES, Field.Index.ANALYZED, Field.TermVector.WITH_POSITIONS_OFFSETS));
            for (int i = 0; i < 7; i++)
            {
                writer.AddDocument(doc, null);
                if (i % 2 == 0)
                {
                    writer.Commit(null);
                }
            }
            IndexCommit cp = dp.Snapshot();

            CopyFiles(dir, cp);
            writer.Close();
            CopyFiles(dir, cp);

            writer = new IndexWriter(dir, new StandardAnalyzer(Util.Version.LUCENE_CURRENT), dp, IndexWriter.MaxFieldLength.UNLIMITED, null);
            CopyFiles(dir, cp);
            for (int i = 0; i < 7; i++)
            {
                writer.AddDocument(doc, null);
                if (i % 2 == 0)
                {
                    writer.Commit(null);
                }
            }
            CopyFiles(dir, cp);
            writer.Close();
            CopyFiles(dir, cp);
            dp.Release();
            writer = new IndexWriter(dir, new StandardAnalyzer(Util.Version.LUCENE_CURRENT), dp, IndexWriter.MaxFieldLength.UNLIMITED, null);
            writer.Close();

            Assert.Throws <System.IO.FileNotFoundException>(() => CopyFiles(dir, cp), "did not hit expected IOException");
            dir.Close();
        }
        public virtual void  TestReuseAcrossWriters()
        {
            Directory dir = new MockRAMDirectory();

            SnapshotDeletionPolicy dp     = new SnapshotDeletionPolicy(new KeepOnlyLastCommitDeletionPolicy());
            IndexWriter            writer = new IndexWriter(dir, true, new StandardAnalyzer(), dp);

            // Force frequent commits
            writer.SetMaxBufferedDocs(2);
            Document doc = new Document();

            doc.Add(new Field("content", "aaa", Field.Store.YES, Field.Index.ANALYZED, Field.TermVector.WITH_POSITIONS_OFFSETS));
            for (int i = 0; i < 7; i++)
            {
                writer.AddDocument(doc);
            }
            IndexCommit cp = (IndexCommit)dp.Snapshot();

            CopyFiles(dir, cp);
            writer.Close();
            CopyFiles(dir, cp);

            writer = new IndexWriter(dir, true, new StandardAnalyzer(), dp);
            CopyFiles(dir, cp);
            for (int i = 0; i < 7; i++)
            {
                writer.AddDocument(doc);
            }
            CopyFiles(dir, cp);
            writer.Close();
            CopyFiles(dir, cp);
            dp.Release();
            writer = new IndexWriter(dir, true, new StandardAnalyzer(), dp);
            writer.Close();
            try
            {
                CopyFiles(dir, cp);
                Assert.Fail("did not hit expected IOException");
            }
            catch (System.IO.IOException ioe)
            {
                // expected
            }
            dir.Close();
        }
		private void  CopyFiles(Directory dir, IndexCommit cp)
		{
			
			// While we hold the snapshot, and nomatter how long
			// we take to do the backup, the IndexWriter will
			// never delete the files in the snapshot:
			System.Collections.Generic.ICollection<string> files = cp.GetFileNames();
			System.Collections.IEnumerator it = files.GetEnumerator();
			while (it.MoveNext())
			{
				System.String fileName = (System.String) it.Current;
				// NOTE: in a real backup you would not use
				// readFile; you would need to use something else
				// that copies the file to a backup location.  This
				// could even be a spawned shell process (eg "tar",
				// "zip") that takes the list of files and builds a
				// backup.
				ReadFile(dir, fileName);
			}
		}