示例#1
0
        public virtual void Test()
        {
            IndexReader reader = null;

            try
            {
                reader = DirectoryReader.Open(directory);
                for (int i = 1; i <= numThreads; i++)
                {
                    TestTermPositionVectors(reader, i);
                }
            }
            catch (Exception ioe) when(ioe.IsIOException())
            {
                Assert.Fail(ioe.Message);
            }
            finally
            {
                if (reader != null)
                {
                    try
                    {
                        /// <summary>
                        /// close the opened reader </summary>
                        reader.Dispose();
                    }
                    catch (Exception ioe) when(ioe.IsIOException())
                    {
                        Console.WriteLine(ioe.ToString());
                        Console.Write(ioe.StackTrace);
                    }
                }
            }
        }
示例#2
0
            public override void Run()
            {
                try
                {
                    while (!stop)
                    {
                        ctrl.WaitIfStalled();
                        if (checkPoint)
                        {
#if FEATURE_THREAD_INTERRUPT
                            try
                            {
#endif
                            Assert.IsTrue(sync.await());
#if FEATURE_THREAD_INTERRUPT
                        }
                        catch (ThreadInterruptedException /*e*/)
                        {
                            Console.WriteLine("[Waiter] got interrupted - wait count: " + sync.waiter.CurrentCount);
                            //throw new ThreadInterruptedException("Thread Interrupted Exception", e);
                            throw;     // LUCENENET: CA2200: Rethrow to preserve stack details (https://docs.microsoft.com/en-us/visualstudio/code-quality/ca2200-rethrow-to-preserve-stack-details)
                        }
#endif
                        }
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.ToString());
                    Console.Write(e.StackTrace);
                    exceptions.Add(e);
                }
            }
 public override void Run()
 {
     try
     {
         while (!stop)
         {
             ctrl.WaitIfStalled();
             if (checkPoint)
             {
                 try
                 {
                     Assert.IsTrue(sync.await());
                 }
                 catch (Exception e) when(e.IsInterruptedException())
                 {
                     Console.WriteLine("[Waiter] got interrupted - wait count: " + sync.waiter.CurrentCount);
                     throw; // LUCENENET: CA2200: Rethrow to preserve stack details (https://docs.microsoft.com/en-us/visualstudio/code-quality/ca2200-rethrow-to-preserve-stack-details)
                 }
             }
         }
     }
     catch (Exception e) when(e.IsThrowable())
     {
         Console.WriteLine(e.ToString());
         Console.Write(e.StackTrace);
         exceptions.Add(e);
     }
 }
示例#4
0
 public override void Run()
 {
     try
     {
         while (!stop)
         {
             ctrl.WaitIfStalled();
             if (checkPoint)
             {
                 try
                 {
                     Assert.IsTrue(sync.Await());
                 }
                 catch (Exception e) when(e.IsInterruptedException())
                 {
                     Console.WriteLine("[Waiter] got interrupted - wait count: " + sync.waiter.CurrentCount);
                     throw new Util.ThreadInterruptedException(e);
                 }
             }
         }
     }
     catch (Exception e) when(e.IsThrowable())
     {
         Console.WriteLine(e.ToString());
         Console.Write(e.StackTrace);
         exceptions.Add(e);
     }
 }
示例#5
0
            public override void Run()
            {
                try
                {
                    while (!stop)
                    {
                        int internalIters = release && Random.NextBoolean() ? AtLeast(5) : 1;
                        for (int i = 0; i < internalIters; i++)
                        {
                            ctrl.UpdateStalled(Random.NextBoolean());
                        }
                        if (checkPoint)
                        {
                            sync.updateJoin.Signal();
                            try
                            {
                                Assert.IsTrue(sync.await());
                            }
#if FEATURE_THREAD_INTERRUPT
                            catch (ThreadInterruptedException /*e*/)
                            {
                                Console.WriteLine("[Updater] got interrupted - wait count: " + sync.waiter.CurrentCount);
                                //throw new ThreadInterruptedException("Thread Interrupted Exception", e);
                                throw; // LUCENENET: CA2200: Rethrow to preserve stack details (https://docs.microsoft.com/en-us/visualstudio/code-quality/ca2200-rethrow-to-preserve-stack-details)
                            }
#endif
                            catch (Exception e)
                            {
                                Console.Write("signal failed with : " + e);
                                throw; // LUCENENET: CA2200: Rethrow to preserve stack details (https://docs.microsoft.com/en-us/visualstudio/code-quality/ca2200-rethrow-to-preserve-stack-details)
                            }

                            sync.leftCheckpoint.Signal();
                        }
                        if (Random.NextBoolean())
                        {
                            Thread.Sleep(0);
                        }
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.ToString());
                    Console.Write(e.StackTrace);
                    exceptions.Add(e);
                }

                if (!sync.updateJoin.IsSet)
                {
                    sync.updateJoin.Signal();
                }
            }
示例#6
0
            public override void Run()
            {
                try
                {
                    while (!stop)
                    {
                        int internalIters = release && Random.NextBoolean() ? AtLeast(5) : 1;
                        for (int i = 0; i < internalIters; i++)
                        {
                            ctrl.UpdateStalled(Random.NextBoolean());
                        }
                        if (checkPoint)
                        {
                            sync.updateJoin.Signal();
                            try
                            {
                                Assert.IsTrue(sync.Await());
                            }
                            catch (Exception e) when(e.IsInterruptedException())
                            {
                                Console.WriteLine("[Updater] got interrupted - wait count: " + sync.waiter.CurrentCount);
                                throw new Util.ThreadInterruptedException(e);
                            }
                            // LUCENENET: Not sure why this catch block was added, but I suspect it was for debugging purposes. Commented it rather than removing it because
                            // there may be some value to debugging this way.
                            //catch (Exception e)
                            //{
                            //    Console.Write("signal failed with : " + e);
                            //    throw; // LUCENENET: CA2200: Rethrow to preserve stack details (https://docs.microsoft.com/en-us/visualstudio/code-quality/ca2200-rethrow-to-preserve-stack-details)
                            //}

                            sync.leftCheckpoint.Signal();
                        }
                        if (Random.NextBoolean())
                        {
                            Thread.Yield();
                        }
                    }
                }
                catch (Exception e) when(e.IsThrowable())
                {
                    Console.WriteLine(e.ToString());
                    Console.Write(e.StackTrace);
                    exceptions.Add(e);
                }

                // LUCENENET specific - possible InvalidOperationException here if Signal() is called more than what is required to decrement to zero
                if (!sync.updateJoin.IsSet)
                {
                    sync.updateJoin.Signal();
                }
            }
示例#7
0
 public void Run()
 {
     try
     {
         // run the test 100 times
         for (int i = 0; i < runsToDo; i++)
         {
             TestTermVectors();
         }
     }
     catch (Exception e)
     {
         Console.WriteLine(e.ToString());
         Console.Write(e.StackTrace);
     }
     return;
 }
 public override void Run()
 {
     try
     {
         signal.Wait();
         manager.MaybeRefresh();
         writer.DeleteDocuments(new TermQuery(new Term("foo", "barista")));
         manager.MaybeRefresh(); // kick off another reopen so we inc. the internal gen
     }
     catch (Exception e)
     {
         Console.WriteLine(e.ToString());
         Console.Write(e.StackTrace);
     }
     finally
     {
         latch.Reset(latch.CurrentCount == 0 ? 0 : latch.CurrentCount - 1); // let the add below finish
     }
 }
示例#9
0
        public virtual void TestIsCurrentWithThreads()
        {
            Directory         dir    = NewDirectory();
            IndexWriterConfig conf   = NewIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random));
            IndexWriter       writer = new IndexWriter(dir, conf);
            ReaderHolder      holder = new ReaderHolder();

            ReaderThread[] threads      = new ReaderThread[AtLeast(3)];
            CountdownEvent latch        = new CountdownEvent(1);
            WriterThread   writerThread = new WriterThread(holder, writer, AtLeast(500), Random, latch);

            for (int i = 0; i < threads.Length; i++)
            {
                threads[i] = new ReaderThread(holder, latch);
                threads[i].Start();
            }
            writerThread.Start();

            writerThread.Join();
            bool failed = writerThread.failed != null;

            if (failed)
            {
                Console.WriteLine(writerThread.failed.ToString());
                Console.Write(writerThread.failed.StackTrace);
            }
            for (int i = 0; i < threads.Length; i++)
            {
                threads[i].Join();
                if (threads[i].failed != null)
                {
                    Console.WriteLine(threads[i].failed.ToString());
                    Console.Write(threads[i].failed.StackTrace);
                    failed = true;
                }
            }
            Assert.IsFalse(failed);
            writer.Dispose();
            dir.Dispose();
        }
示例#10
0
        public virtual void TestAccquireReleaseRace()
        {
            DocumentsWriterStallControl ctrl = new DocumentsWriterStallControl();

            ctrl.UpdateStalled(false);
            AtomicBoolean stop       = new AtomicBoolean(false);
            AtomicBoolean checkPoint = new AtomicBoolean(true);

            int numStallers              = AtLeast(1);
            int numReleasers             = AtLeast(1);
            int numWaiters               = AtLeast(1);
            var sync                     = new Synchronizer(numStallers + numReleasers, numStallers + numReleasers + numWaiters);
            var threads                  = new ThreadJob[numReleasers + numStallers + numWaiters];
            IList <Exception> exceptions = new SynchronizedList <Exception>();

            for (int i = 0; i < numReleasers; i++)
            {
                threads[i] = new Updater(stop, checkPoint, ctrl, sync, true, exceptions);
            }
            for (int i = numReleasers; i < numReleasers + numStallers; i++)
            {
                threads[i] = new Updater(stop, checkPoint, ctrl, sync, false, exceptions);
            }
            for (int i = numReleasers + numStallers; i < numReleasers + numStallers + numWaiters; i++)
            {
                threads[i] = new Waiter(stop, checkPoint, ctrl, sync, exceptions);
            }

            Start(threads);
            int   iters = AtLeast(10000);
            float checkPointProbability = TestNightly ? 0.5f : 0.1f;

            for (int i = 0; i < iters; i++)
            {
                if (checkPoint)
                {
                    Assert.IsTrue(sync.updateJoin.Wait(new TimeSpan(0, 0, 0, 10)), "timed out waiting for update threads - deadlock?");
                    if (exceptions.Count > 0)
                    {
                        foreach (Exception throwable in exceptions)
                        {
                            Console.WriteLine(throwable.ToString());
                            Console.Write(throwable.StackTrace);
                        }
                        Assert.Fail("got exceptions in threads");
                    }

                    if (ctrl.HasBlocked && ctrl.IsHealthy)
                    {
                        AssertState(numReleasers, numStallers, numWaiters, threads, ctrl);
                    }

                    checkPoint.Value = (false);
                    sync.waiter.Signal();
                    sync.leftCheckpoint.Wait();
                }
                Assert.IsFalse(checkPoint);
                Assert.AreEqual(0, sync.waiter.CurrentCount);
                if (checkPointProbability >= (float)Random.NextDouble())
                {
                    sync.Reset(numStallers + numReleasers, numStallers + numReleasers + numWaiters);
                    checkPoint.Value = (true);
                }
            }
            if (!checkPoint)
            {
                sync.Reset(numStallers + numReleasers, numStallers + numReleasers + numWaiters);
                checkPoint.Value = (true);
            }

            Assert.IsTrue(sync.updateJoin.Wait(new TimeSpan(0, 0, 0, 10)));
            AssertState(numReleasers, numStallers, numWaiters, threads, ctrl);
            checkPoint.Value = (false);
            stop.Value       = (true);
            sync.waiter.Signal();
            sync.leftCheckpoint.Wait();

            for (int i = 0; i < threads.Length; i++)
            {
                ctrl.UpdateStalled(false);
                threads[i].Join(2000);
                if (threads[i].IsAlive && threads[i] is Waiter)
                {
                    if (threads[i].State == ThreadState.WaitSleepJoin)
                    {
                        Assert.Fail("waiter is not released - anyThreadsStalled: " + ctrl.AnyStalledThreads());
                    }
                }
            }
        }
示例#11
0
        public virtual void TestParseInt()
        {
            int test;

            try
            {
                test = ArrayUtil.ParseInt32("".ToCharArray());
                Assert.IsTrue(false);
            }
#pragma warning disable 168
            catch (FormatException e)
#pragma warning restore 168
            {
                //expected
            }
            try
            {
                test = ArrayUtil.ParseInt32("foo".ToCharArray());
                Assert.IsTrue(false);
            }
#pragma warning disable 168
            catch (FormatException e)
#pragma warning restore 168
            {
                //expected
            }
            try
            {
                test = ArrayUtil.ParseInt32(Convert.ToString(long.MaxValue).ToCharArray());
                Assert.IsTrue(false);
            }
#pragma warning disable 168
            catch (FormatException e)
#pragma warning restore 168
            {
                //expected
            }
            try
            {
                test = ArrayUtil.ParseInt32("0.34".ToCharArray());
                Assert.IsTrue(false);
            }
#pragma warning disable 168
            catch (FormatException e)
#pragma warning restore 168
            {
                //expected
            }

            try
            {
                test = ArrayUtil.ParseInt32("1".ToCharArray());
                Assert.IsTrue(test == 1, test + " does not equal: " + 1);
                test = ArrayUtil.ParseInt32("-10000".ToCharArray());
                Assert.IsTrue(test == -10000, test + " does not equal: " + -10000);
                test = ArrayUtil.ParseInt32("1923".ToCharArray());
                Assert.IsTrue(test == 1923, test + " does not equal: " + 1923);
                test = ArrayUtil.ParseInt32("-1".ToCharArray());
                Assert.IsTrue(test == -1, test + " does not equal: " + -1);
                test = ArrayUtil.ParseInt32("foo 1923 bar".ToCharArray(), 4, 4);
                Assert.IsTrue(test == 1923, test + " does not equal: " + 1923);
            }
            catch (FormatException e)
            {
                Console.WriteLine(e.ToString());
                Console.Write(e.StackTrace);
                Assert.IsTrue(false);
            }
        }
示例#12
0
        public virtual void Test()
        {
            MockDirectoryWrapper dir = NewMockFSDirectory(CreateTempDir("TestIndexWriterOutOfFileDescriptors"));

            dir.PreventDoubleWrite = false;
            double rate = Random.NextDouble() * 0.01;

            //System.out.println("rate=" + rate);
            dir.RandomIOExceptionRateOnOpen = rate;
            int                  iters       = AtLeast(20);
            LineFileDocs         docs        = new LineFileDocs(Random, DefaultCodecSupportsDocValues);
            IndexReader          r           = null;
            DirectoryReader      r2          = null;
            bool                 any         = false;
            MockDirectoryWrapper dirCopy     = null;
            int                  lastNumDocs = 0;

            for (int iter = 0; iter < iters; iter++)
            {
                IndexWriter w = null;
                if (Verbose)
                {
                    Console.WriteLine("TEST: iter=" + iter);
                }
                try
                {
                    MockAnalyzer analyzer = new MockAnalyzer(Random);
                    analyzer.MaxTokenLength = TestUtil.NextInt32(Random, 1, IndexWriter.MAX_TERM_LENGTH);
                    IndexWriterConfig iwc = NewIndexWriterConfig(TEST_VERSION_CURRENT, analyzer);

                    if (Verbose)
                    {
                        // Do this ourselves instead of relying on LTC so
                        // we see incrementing messageID:
                        iwc.SetInfoStream(new TextWriterInfoStream(Console.Out));
                    }
                    var ms = iwc.MergeScheduler;
                    if (ms is IConcurrentMergeScheduler)
                    {
                        ((IConcurrentMergeScheduler)ms).SetSuppressExceptions();
                    }
                    w = new IndexWriter(dir, iwc);
                    if (r != null && Random.Next(5) == 3)
                    {
                        if (Random.NextBoolean())
                        {
                            if (Verbose)
                            {
                                Console.WriteLine("TEST: addIndexes IR[]");
                            }
                            w.AddIndexes(new IndexReader[] { r });
                        }
                        else
                        {
                            if (Verbose)
                            {
                                Console.WriteLine("TEST: addIndexes Directory[]");
                            }
                            w.AddIndexes(new Directory[] { dirCopy });
                        }
                    }
                    else
                    {
                        if (Verbose)
                        {
                            Console.WriteLine("TEST: addDocument");
                        }
                        w.AddDocument(docs.NextDoc());
                    }
                    dir.RandomIOExceptionRateOnOpen = 0.0;
                    w.Dispose();
                    w = null;

                    // NOTE: this is O(N^2)!  Only enable for temporary debugging:
                    //dir.setRandomIOExceptionRateOnOpen(0.0);
                    //TestUtil.CheckIndex(dir);
                    //dir.setRandomIOExceptionRateOnOpen(rate);

                    // Verify numDocs only increases, to catch IndexWriter
                    // accidentally deleting the index:
                    dir.RandomIOExceptionRateOnOpen = 0.0;
                    Assert.IsTrue(DirectoryReader.IndexExists(dir));
                    if (r2 == null)
                    {
                        r2 = DirectoryReader.Open(dir);
                    }
                    else
                    {
                        DirectoryReader r3 = DirectoryReader.OpenIfChanged(r2);
                        if (r3 != null)
                        {
                            r2.Dispose();
                            r2 = r3;
                        }
                    }
                    Assert.IsTrue(r2.NumDocs >= lastNumDocs, "before=" + lastNumDocs + " after=" + r2.NumDocs);
                    lastNumDocs = r2.NumDocs;
                    //System.out.println("numDocs=" + lastNumDocs);
                    dir.RandomIOExceptionRateOnOpen = rate;

                    any = true;
                    if (Verbose)
                    {
                        Console.WriteLine("TEST: iter=" + iter + ": success");
                    }
                }
                catch (IOException ioe)
                {
                    if (Verbose)
                    {
                        Console.WriteLine("TEST: iter=" + iter + ": exception");
                        Console.WriteLine(ioe.ToString());
                        Console.Write(ioe.StackTrace);
                    }
                    if (w != null)
                    {
                        // NOTE: leave random IO exceptions enabled here,
                        // to verify that rollback does not try to write
                        // anything:
                        w.Rollback();
                    }
                }

                if (any && r == null && Random.NextBoolean())
                {
                    // Make a copy of a non-empty index so we can use
                    // it to addIndexes later:
                    dir.RandomIOExceptionRateOnOpen = 0.0;
                    r       = DirectoryReader.Open(dir);
                    dirCopy = NewMockFSDirectory(CreateTempDir("TestIndexWriterOutOfFileDescriptors.copy"));
                    ISet <string> files = new JCG.HashSet <string>();
                    foreach (string file in dir.ListAll())
                    {
                        dir.Copy(dirCopy, file, file, IOContext.DEFAULT);
                        files.Add(file);
                    }
                    dirCopy.Sync(files);
                    // Have IW kiss the dir so we remove any leftover
                    // files ... we can easily have leftover files at
                    // the time we take a copy because we are holding
                    // open a reader:
                    (new IndexWriter(dirCopy, NewIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random)))).Dispose();
                    dirCopy.RandomIOExceptionRate   = rate;
                    dir.RandomIOExceptionRateOnOpen = rate;
                }
            }

            if (r2 != null)
            {
                r2.Dispose();
            }
            if (r != null)
            {
                r.Dispose();
                dirCopy.Dispose();
            }
            dir.Dispose();
        }