protected internal override void DoAfterWriter(TaskScheduler es)
        {
            double minReopenSec = 0.01 + 0.05 * Random().NextDouble();
            double maxReopenSec = minReopenSec * (1.0 + 10 * Random().NextDouble());

            if (VERBOSE)
            {
                Console.WriteLine("TEST: make SearcherManager maxReopenSec=" + maxReopenSec + " minReopenSec=" + minReopenSec);
            }

            GenWriter = new TrackingIndexWriter(Writer);

            SearcherFactory sf = new SearcherFactoryAnonymousInnerClassHelper(this, es);

            NrtNoDeletes = new SearcherManager(Writer, false, sf);
            NrtDeletes   = new SearcherManager(Writer, true, sf);

            NrtDeletesThread          = new ControlledRealTimeReopenThread <>(GenWriter, NrtDeletes, maxReopenSec, minReopenSec);
            NrtDeletesThread.Name     = "NRTDeletes Reopen Thread";
            NrtDeletesThread.Priority = Math.Min(Thread.CurrentThread.Priority + 2, Thread.MAX_PRIORITY);
            NrtDeletesThread.SetDaemon(true);
            NrtDeletesThread.Start();

            NrtNoDeletesThread          = new ControlledRealTimeReopenThread <>(GenWriter, NrtNoDeletes, maxReopenSec, minReopenSec);
            NrtNoDeletesThread.Name     = "NRTNoDeletes Reopen Thread";
            NrtNoDeletesThread.Priority = Math.Min(Thread.CurrentThread.Priority + 2, Thread.MAX_PRIORITY);
            NrtNoDeletesThread.SetDaemon(true);
            NrtNoDeletesThread.Start();
        }
        protected internal override void DoAfterWriter(TaskScheduler es)
        {
            double minReopenSec = 0.01 + 0.05 * Random().NextDouble();
            double maxReopenSec = minReopenSec * (1.0 + 10 * Random().NextDouble());

            if (VERBOSE)
            {
                Console.WriteLine("TEST: make SearcherManager maxReopenSec=" + maxReopenSec + " minReopenSec=" + minReopenSec);
            }

            genWriter = new TrackingIndexWriter(writer);

            SearcherFactory sf = new SearcherFactoryAnonymousInnerClassHelper(this, es);

            nrtNoDeletes = new SearcherManager(writer, false, sf);
            nrtDeletes   = new SearcherManager(writer, true, sf);

            nrtDeletesThread      = new ControlledRealTimeReopenThread <IndexSearcher>(genWriter, nrtDeletes, maxReopenSec, minReopenSec);
            nrtDeletesThread.Name = "NRTDeletes Reopen Thread";
#if !NETSTANDARD
            nrtDeletesThread.Priority = (ThreadPriority)Math.Min((int)Thread.CurrentThread.Priority + 2, (int)ThreadPriority.Highest);
#endif
            nrtDeletesThread.SetDaemon(true);
            nrtDeletesThread.Start();

            nrtNoDeletesThread      = new ControlledRealTimeReopenThread <IndexSearcher>(genWriter, nrtNoDeletes, maxReopenSec, minReopenSec);
            nrtNoDeletesThread.Name = "NRTNoDeletes Reopen Thread";
#if !NETSTANDARD
            nrtNoDeletesThread.Priority = (ThreadPriority)Math.Min((int)Thread.CurrentThread.Priority + 2, (int)ThreadPriority.Highest);
#endif
            nrtNoDeletesThread.SetDaemon(true);
            nrtNoDeletesThread.Start();
        }
        // LUCENE-5461
        public virtual void TestCRTReopen()
        {
            //test behaving badly

            //should be high enough
            int maxStaleSecs = 20;

            //build crap data just to store it.
            string s = "        abcdefghijklmnopqrstuvwxyz     ";

            char[]        chars   = s.ToCharArray();
            StringBuilder builder = new StringBuilder(2048);

            for (int i = 0; i < 2048; i++)
            {
                builder.Append(chars[Random().Next(chars.Length)]);
            }
            string content = builder.ToString();

            SnapshotDeletionPolicy sdp = new SnapshotDeletionPolicy(new KeepOnlyLastCommitDeletionPolicy());
            Directory         dir      = new NRTCachingDirectory(NewFSDirectory(CreateTempDir("nrt")), 5, 128);
            IndexWriterConfig config   = new IndexWriterConfig(Version.LUCENE_46, new MockAnalyzer(Random()));

            config.SetIndexDeletionPolicy(sdp);
            config.SetOpenMode(IndexWriterConfig.OpenMode_e.CREATE_OR_APPEND);
            IndexWriter         iw  = new IndexWriter(dir, config);
            SearcherManager     sm  = new SearcherManager(iw, true, new SearcherFactory());
            TrackingIndexWriter tiw = new TrackingIndexWriter(iw);
            ControlledRealTimeReopenThread <IndexSearcher> controlledRealTimeReopenThread = new ControlledRealTimeReopenThread <IndexSearcher>(tiw, sm, maxStaleSecs, 0);

            controlledRealTimeReopenThread.SetDaemon(true);
            controlledRealTimeReopenThread.Start();

            IList <Thread> commitThreads = new List <Thread>();

            for (int i = 0; i < 500; i++)
            {
                if (i > 0 && i % 50 == 0)
                {
                    Thread commitThread = new Thread(new RunnableAnonymousInnerClassHelper(this, sdp, dir, iw));
                    commitThread.Start();
                    commitThreads.Add(commitThread);
                }
                Document d = new Document();
                d.Add(new TextField("count", i + "", Field.Store.NO));
                d.Add(new TextField("content", content, Field.Store.YES));
                long start = DateTime.Now.Millisecond;
                long l     = tiw.AddDocument(d);
                controlledRealTimeReopenThread.WaitForGeneration(l);
                long wait = DateTime.Now.Millisecond - start;
                Assert.IsTrue(wait < (maxStaleSecs * 1000), "waited too long for generation " + wait);
                IndexSearcher searcher = sm.Acquire();
                TopDocs       td       = searcher.Search(new TermQuery(new Term("count", i + "")), 10);
                sm.Release(searcher);
                Assert.AreEqual(1, td.TotalHits);
            }

            foreach (Thread commitThread in commitThreads)
            {
                commitThread.Join();
            }

            controlledRealTimeReopenThread.Dispose();
            sm.Dispose();
            iw.Dispose();
            dir.Dispose();
        }