Exemplo n.º 1
0
            public override void Run()
            {
                Random rnd = LuceneTestCase.Random;

                while (!stopped)
                {
                    if (index % 2 == 0)
                    {
                        // refresh reader synchronized
                        ReaderCouple c = (outerInstance.RefreshReader(r, test, index, true));
                        readersToClose.Add(c.newReader);
                        readersToClose.Add(c.refreshedReader);
                        readers.Add(c);
                        // prevent too many readers
                        break;
                    }
                    else
                    {
                        // not synchronized
                        DirectoryReader refreshed = DirectoryReader.OpenIfChanged(r);
                        if (refreshed == null)
                        {
                            refreshed = r;
                        }

                        IndexSearcher searcher =
#if FEATURE_INSTANCE_TESTDATA_INITIALIZATION
                            outerInstance.
#endif
                            NewSearcher(refreshed);
                        ScoreDoc[] hits = searcher.Search(new TermQuery(new Term("field1", "a" + rnd.Next(refreshed.MaxDoc))), null, 1000).ScoreDocs;
                        if (hits.Length > 0)
                        {
                            searcher.Doc(hits[0].Doc);
                        }
                        if (refreshed != r)
                        {
                            refreshed.Dispose();
                        }
                    }
                    UninterruptableMonitor.Enter(this);
                    try
                    {
                        UninterruptableMonitor.Wait(this, TimeSpan.FromMilliseconds(TestUtil.NextInt32(Random, 1, 100)));
                    }
                    finally
                    {
                        UninterruptableMonitor.Exit(this);
                    }
                }
            }
        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);
        }
            public override void Run()
            {
                Random rnd = LuceneTestCase.Random();

                while (!Stopped)
                {
                    int numReaders = Readers.Count;
                    if (numReaders > 0)
                    {
                        ReaderCouple c = Readers[rnd.Next(numReaders)];
                        TestDirectoryReader.AssertIndexEquals(c.NewReader, c.RefreshedReader);
                    }

                    lock (this)
                    {
                        Monitor.Wait(this, TimeSpan.FromMilliseconds(TestUtil.NextInt(Random(), 1, 100)));
                    }
                }
            }
            public override void Run()
            {
                Random rnd = LuceneTestCase.Random();

                while (!Stopped)
                {
                    if (Index % 2 == 0)
                    {
                        // refresh reader synchronized
                        ReaderCouple c = (OuterInstance.RefreshReader(r, Test, Index, true));
                        ReadersToClose.Add(c.NewReader);
                        ReadersToClose.Add(c.RefreshedReader);
                        Readers.Add(c);
                        // prevent too many readers
                        break;
                    }
                    else
                    {
                        // not synchronized
                        DirectoryReader refreshed = DirectoryReader.OpenIfChanged(r);
                        if (refreshed == null)
                        {
                            refreshed = r;
                        }

                        IndexSearcher searcher = OuterInstance.NewSearcher(refreshed);
                        ScoreDoc[]    hits     = searcher.Search(new TermQuery(new Term("field1", "a" + rnd.Next(refreshed.MaxDoc))), null, 1000).ScoreDocs;
                        if (hits.Length > 0)
                        {
                            searcher.Doc(hits[0].Doc);
                        }
                        if (refreshed != r)
                        {
                            refreshed.Dispose();
                        }
                    }
                    lock (this)
                    {
                        Monitor.Wait(this, TimeSpan.FromMilliseconds(TestUtil.NextInt(Random(), 1, 100)));
                    }
                }
            }
Exemplo n.º 5
0
            public override void Run()
            {
                Random rnd = LuceneTestCase.Random;

                while (!stopped)
                {
                    int numReaders = readers.Count;
                    if (numReaders > 0)
                    {
                        ReaderCouple c = readers[rnd.Next(numReaders)];
                        TestDirectoryReader.AssertIndexEquals(c.newReader, c.refreshedReader);
                    }

                    UninterruptableMonitor.Enter(this);
                    try
                    {
                        UninterruptableMonitor.Wait(this, TimeSpan.FromMilliseconds(TestUtil.NextInt32(Random, 1, 100)));
                    }
                    finally
                    {
                        UninterruptableMonitor.Exit(this);
                    }
                }
            }