コード例 #1
0
        public void TestNoCommits()
        {
            // Tests that if there were no commits when snapshot() is called, then
            // IllegalStateException is thrown rather than NPE.
            SnapshotDeletionPolicy sdp = new SnapshotDeletionPolicy(new KeepOnlyLastCommitDeletionPolicy());

            Assert.Throws <SystemException>(() => sdp.Snapshot(), "expected exception not hit");
        }
コード例 #2
0
 /// <summary>Example showing how to use the SnapshotDeletionPolicy
 /// to take a backup.  This method does not really do a
 /// backup; instead, it reads every byte of every file
 /// just to test that the files indeed exist and are
 /// readable even while the index is changing.
 /// </summary>
 public virtual void  BackupIndex(Directory dir, SnapshotDeletionPolicy dp)
 {
     // To backup an index we first take a snapshot:
     try
     {
         CopyFiles(dir, (IndexCommit)dp.Snapshot());
     }
     finally
     {
         // Make sure to release the snapshot, otherwise these
         // files will never be deleted during this IndexWriter
         // session:
         dp.Release();
     }
 }
コード例 #3
0
        public void TestNoCommits()
        {
            // Tests that if there were no commits when snapshot() is called, then
            // IllegalStateException is thrown rather than NPE.
            SnapshotDeletionPolicy sdp = new SnapshotDeletionPolicy(new KeepOnlyLastCommitDeletionPolicy());

            try
            {
                sdp.Snapshot();
                Assert.Fail("expected exception not hit");
            }
            catch (System.SystemException ise)
            {
                // expected
            }
        }
コード例 #4
0
        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();
        }
コード例 #5
0
        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();
        }
コード例 #6
0
		/// <summary>Example showing how to use the SnapshotDeletionPolicy
		/// to take a backup.  This method does not really do a
		/// backup; instead, it reads every byte of every file
		/// just to test that the files indeed exist and are
		/// readable even while the index is changing. 
		/// </summary>
		public virtual void  BackupIndex(Directory dir, SnapshotDeletionPolicy dp)
		{
			// To backup an index we first take a snapshot:
			try
			{
				CopyFiles(dir, (IndexCommit) dp.Snapshot());
			}
			finally
			{
				// Make sure to release the snapshot, otherwise these
				// files will never be deleted during this IndexWriter
				// session:
				dp.Release();
			}
		}
コード例 #7
0
		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();
		}
コード例 #8
0
        public void TestNoCommits()
        {
            // Tests that if there were no commits when snapshot() is called, then
            // IllegalStateException is thrown rather than NPE.
            SnapshotDeletionPolicy sdp = new SnapshotDeletionPolicy(new KeepOnlyLastCommitDeletionPolicy());

            Assert.Throws<SystemException>(() => sdp.Snapshot(), "expected exception not hit");
        }
コード例 #9
0
        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);
            // 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);
                if (i % 2 == 0)
                {
                    writer.Commit();
                }
            }
            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);
            CopyFiles(dir, cp);
            for (int i = 0; i < 7; i++)
            {
                writer.AddDocument(doc);
                if (i % 2 == 0)
                {
                    writer.Commit();
                }
            }
            CopyFiles(dir, cp);
            writer.Close();
            CopyFiles(dir, cp);
            dp.Release();
            writer = new IndexWriter(dir, new StandardAnalyzer(Util.Version.LUCENE_CURRENT), dp, IndexWriter.MaxFieldLength.UNLIMITED);
            writer.Close();

            Assert.Throws<System.IO.FileNotFoundException>(() => CopyFiles(dir, cp), "did not hit expected IOException");
            dir.Close();
        }
コード例 #10
0
		/// <summary>Example showing how to use the SnapshotDeletionPolicy
		/// to take a backup.  This method does not really do a
		/// backup; instead, it reads every byte of every file
		/// just to test that the files indeed exist and are
		/// readable even while the index is changing. 
		/// </summary>
		public virtual void  BackupIndex(Directory dir, SnapshotDeletionPolicy dp)
		{
			
			// To backup an index we first take a snapshot:
			IndexCommitPoint cp = dp.Snapshot();
			try
			{
				
				// 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.ICollection 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);
				}
			}
			finally
			{
				// Make sure to release the snapshot, otherwise these
				// files will never be deleted during this IndexWriter
				// session:
				dp.Release();
			}
		}
コード例 #11
0
 public void TestNoCommits()
 {
     // Tests that if there were no commits when snapshot() is called, then
     // IllegalStateException is thrown rather than NPE.
     SnapshotDeletionPolicy sdp = new SnapshotDeletionPolicy(new KeepOnlyLastCommitDeletionPolicy());
     try
     {
         sdp.Snapshot();
         Assert.Fail("expected exception not hit");
     }
     catch (System.SystemException ise)
     {
         // expected
     }
 }