コード例 #1
0
        private void PerformDefaultTests(TestReopen test)
        {
            DirectoryReader index1 = test.OpenReader();
            DirectoryReader index2 = test.OpenReader();

            TestDirectoryReader.AssertIndexEquals(index1, index2);

            // verify that reopen() does not return a new reader instance
            // in case the index has no changes
            ReaderCouple couple = RefreshReader(index2, false);

            Assert.IsTrue(couple.RefreshedReader == index2);

            couple = RefreshReader(index2, test, 0, true);
            index1.Dispose();
            index1 = couple.NewReader;

            DirectoryReader index2_refreshed = couple.RefreshedReader;

            index2.Dispose();

            // test if refreshed reader and newly opened reader return equal results
            TestDirectoryReader.AssertIndexEquals(index1, index2_refreshed);

            index2_refreshed.Dispose();
            AssertReaderClosed(index2, true);
            AssertReaderClosed(index2_refreshed, true);

            index2 = test.OpenReader();

            for (int i = 1; i < 4; i++)
            {
                index1.Dispose();
                couple = RefreshReader(index2, test, i, true);
                // refresh DirectoryReader
                index2.Dispose();

                index2 = couple.RefreshedReader;
                index1 = couple.NewReader;
                TestDirectoryReader.AssertIndexEquals(index1, index2);
            }

            index1.Dispose();
            index2.Dispose();
            AssertReaderClosed(index1, true);
            AssertReaderClosed(index2, true);
        }
コード例 #2
0
        internal virtual ReaderCouple RefreshReader(DirectoryReader reader, TestReopen test, int modify, bool hasChanges)
        {
            UninterruptableMonitor.Enter(createReaderMutex);
            try
            {
                DirectoryReader r = null;
                if (test != null)
                {
                    test.ModifyIndex(modify);
                    r = test.OpenReader();
                }

                DirectoryReader refreshed = null;
                try
                {
                    refreshed = DirectoryReader.OpenIfChanged(reader);
                    if (refreshed == null)
                    {
                        refreshed = reader;
                    }
                }
                finally
                {
                    if (refreshed == null && r != null)
                    {
                        // Hit exception -- close opened reader
                        r.Dispose();
                    }
                }

                if (hasChanges)
                {
                    if (refreshed == reader)
                    {
                        Assert.Fail("No new DirectoryReader instance created during refresh.");
                    }
                }
                else
                {
                    if (refreshed != reader)
                    {
                        Assert.Fail("New DirectoryReader instance created during refresh even though index had no changes.");
                    }
                }

                return(new ReaderCouple(r, refreshed));
            }
            finally
            {
                UninterruptableMonitor.Exit(createReaderMutex);
            }
        }
コード例 #3
0
		private void  PerformDefaultTests(TestReopen test)
		{
			
			IndexReader index1 = test.OpenReader();
			IndexReader index2 = test.OpenReader();
			
			TestIndexReader.AssertIndexEquals(index1, index2);
			
			// verify that reopen() does not return a new reader instance
			// in case the index has no changes
			ReaderCouple couple = RefreshReader(index2, false);
			Assert.IsTrue(couple.refreshedReader == index2);
			
			couple = RefreshReader(index2, test, 0, true);
			index1.Close();
			index1 = couple.newReader;
			
			IndexReader index2_refreshed = couple.refreshedReader;
			index2.Close();
			
			// test if refreshed reader and newly opened reader return equal results
			TestIndexReader.AssertIndexEquals(index1, index2_refreshed);
			
			index2_refreshed.Close();
			AssertReaderClosed(index2, true, true);
			AssertReaderClosed(index2_refreshed, true, true);
			
			index2 = test.OpenReader();
			
			for (int i = 1; i < 4; i++)
			{
				
				index1.Close();
				couple = RefreshReader(index2, test, i, true);
				// refresh IndexReader
				index2.Close();
				
				index2 = couple.refreshedReader;
				index1 = couple.newReader;
				TestIndexReader.AssertIndexEquals(index1, index2);
			}
			
			index1.Close();
			index2.Close();
			AssertReaderClosed(index1, true, true);
			AssertReaderClosed(index2, true, true);
		}
コード例 #4
0
		internal virtual ReaderCouple RefreshReader(IndexReader reader, TestReopen test, int modify, bool hasChanges)
		{
			lock (createReaderMutex)
			{
				IndexReader r = null;
				if (test != null)
				{
					test.ModifyIndex(modify);
					r = test.OpenReader();
				}
				
				IndexReader refreshed = null;
				try
				{
					refreshed = reader.Reopen();
				}
				finally
				{
					if (refreshed == null && r != null)
					{
						// Hit exception -- close opened reader
						r.Close();
					}
				}
				
				if (hasChanges)
				{
					if (refreshed == reader)
					{
						Assert.Fail("No new IndexReader instance created during refresh.");
					}
				}
				else
				{
					if (refreshed != reader)
					{
						Assert.Fail("New IndexReader instance created during refresh even though index had no changes.");
					}
				}
				
				return new ReaderCouple(r, refreshed);
			}
		}
コード例 #5
0
		private void  PerformTestsWithExceptionInReopen(TestReopen test)
		{
			IndexReader index1 = test.OpenReader();
			IndexReader index2 = test.OpenReader();
			
			TestIndexReader.AssertIndexEquals(index1, index2);
			
			try
			{
				RefreshReader(index1, test, 0, true);
				Assert.Fail("Expected exception not thrown.");
			}
			catch (System.Exception e)
			{
				// expected exception
			}
			
			// index2 should still be usable and unaffected by the failed reopen() call
			TestIndexReader.AssertIndexEquals(index1, index2);
			
			index1.Close();
			index2.Close();
		}