public virtual void  TestRandomExceptionsThreads()
        {
            random = new Random((int)(DateTime.Now.Ticks & 0x7fffffff));
            MockRAMDirectory dir    = new MockRAMDirectory();
            MockIndexWriter  writer = new MockIndexWriter(this, dir, new WhitespaceAnalyzer(), true, IndexWriter.MaxFieldLength.LIMITED);

            ((ConcurrentMergeScheduler)writer.MergeScheduler).SetSuppressExceptions();
            //writer.setMaxBufferedDocs(10);
            writer.SetRAMBufferSizeMB(0.2);

            if (DEBUG)
            {
                System.IO.StreamWriter temp_writer;
                temp_writer           = new System.IO.StreamWriter(System.Console.OpenStandardOutput(), System.Console.Out.Encoding);
                temp_writer.AutoFlush = true;
                writer.SetInfoStream(temp_writer, null);
            }

            int NUM_THREADS = 4;

            IndexerThread[] threads = new IndexerThread[NUM_THREADS];
            for (int i = 0; i < NUM_THREADS; i++)
            {
                threads[i] = new IndexerThread(this, i, writer);
                threads[i].Start();
            }

            for (int i = 0; i < NUM_THREADS; i++)
            {
                threads[i].Join();
            }

            for (int i = 0; i < NUM_THREADS; i++)
            {
                Assert.IsNull(threads[i].failure, "thread " + threads[i].Name + ": hit unexpected failure");
            }

            writer.Commit(null);

            try
            {
                writer.Close();
            }
            catch (System.Exception t)
            {
                System.Console.Out.WriteLine("exception during close:");
                System.Console.Out.WriteLine(t.StackTrace);
                writer.Rollback(null);
            }

            // Confirm that when doc hits exception partway through tokenization, it's deleted:
            IndexReader r2     = IndexReader.Open((Directory)dir, true, null);
            int         count  = r2.DocFreq(new Term("content4", "aaa"), null);
            int         count2 = r2.DocFreq(new Term("content4", "ddd"), null);

            Assert.AreEqual(count, count2);
            r2.Close();

            _TestUtil.CheckIndex(dir);
        }
Beispiel #2
0
        /*
         * Run one indexer and 2 searchers against single index as
         * stress test.
         */
        public virtual void  RunTest(Directory directory)
        {
            TimedThread[] threads = new TimedThread[4];

            IndexWriter writer = new MockIndexWriter(this, directory, true, ANALYZER, true);

            writer.SetMaxBufferedDocs(7);
            writer.SetMergeFactor(3);

            // Establish a base index of 100 docs:
            for (int i = 0; i < 100; i++)
            {
                Document d = new Document();
                d.Add(new Field("id", System.Convert.ToString(i), Field.Store.YES, Field.Index.NOT_ANALYZED));
                d.Add(new Field("contents", English.IntToEnglish(i), Field.Store.NO, Field.Index.ANALYZED));
                writer.AddDocument(d);
            }
            writer.Commit();

            IndexReader r = IndexReader.Open(directory);

            Assert.AreEqual(100, r.NumDocs());
            r.Close();

            IndexerThread indexerThread = new IndexerThread(writer, threads);

            threads[0] = indexerThread;
            indexerThread.Start();

            IndexerThread indexerThread2 = new IndexerThread(writer, threads);

            threads[1] = indexerThread2;
            indexerThread2.Start();

            SearcherThread searcherThread1 = new SearcherThread(directory, threads);

            threads[2] = searcherThread1;
            searcherThread1.Start();

            SearcherThread searcherThread2 = new SearcherThread(directory, threads);

            threads[3] = searcherThread2;
            searcherThread2.Start();

            indexerThread.Join();
            indexerThread2.Join();
            searcherThread1.Join();
            searcherThread2.Join();

            writer.Close();

            Assert.IsTrue(!indexerThread.failed, "hit unexpected exception in indexer");
            Assert.IsTrue(!indexerThread2.failed, "hit unexpected exception in indexer2");
            Assert.IsTrue(!searcherThread1.failed, "hit unexpected exception in search1");
            Assert.IsTrue(!searcherThread2.failed, "hit unexpected exception in search2");
            //System.out.println("    Writer: " + indexerThread.count + " iterations");
            //System.out.println("Searcher 1: " + searcherThread1.count + " searchers created");
            //System.out.println("Searcher 2: " + searcherThread2.count + " searchers created");
        }
Beispiel #3
0
        public virtual void  TestRandomExceptions()
        {
            MockRAMDirectory dir = new MockRAMDirectory();

            MockIndexWriter writer = new MockIndexWriter(this, dir, new WhitespaceAnalyzer(), true, IndexWriter.MaxFieldLength.LIMITED);

            ((ConcurrentMergeScheduler)writer.GetMergeScheduler()).SetSuppressExceptions();
            //writer.setMaxBufferedDocs(10);
            writer.SetRAMBufferSizeMB(0.1);

            if (DEBUG)
            {
                System.IO.StreamWriter temp_writer;
                temp_writer           = new System.IO.StreamWriter(System.Console.OpenStandardOutput(), System.Console.Out.Encoding);
                temp_writer.AutoFlush = true;
                writer.SetInfoStream(temp_writer);
            }

            IndexerThread thread = new IndexerThread(this, 0, writer);

            thread.Run();
            if (thread.failure != null)
            {
                System.Console.Out.WriteLine(thread.failure.StackTrace);
                Assert.Fail("thread " + thread.Name + ": hit unexpected failure");
            }

            writer.Commit();

            try
            {
                writer.Close();
            }
            catch (System.Exception t)
            {
                System.Console.Out.WriteLine("exception during close:");
                System.Console.Out.WriteLine(t.StackTrace);
                writer.Rollback();
            }

            // Confirm that when doc hits exception partway through tokenization, it's deleted:
            IndexReader r2     = IndexReader.Open(dir);
            int         count  = r2.DocFreq(new Term("content4", "aaa"));
            int         count2 = r2.DocFreq(new Term("content4", "ddd"));

            Assert.AreEqual(count, count2);
            r2.Close();

            _TestUtil.CheckIndex(dir);
        }
Beispiel #4
0
        /*
        Run one indexer and 2 searchers against single index as
        stress test.
        */
        public virtual void  RunTest(Directory directory)
        {
            
            TimedThread[] threads = new TimedThread[4];

            IndexWriter writer = new MockIndexWriter(this, directory, ANALYZER, true, IndexWriter.MaxFieldLength.UNLIMITED);
            writer.SetMaxBufferedDocs(7);
            writer.MergeFactor = 3;
            
            // Establish a base index of 100 docs:
            for (int i = 0; i < 100; i++)
            {
                Document d = new Document();
                d.Add(new Field("id", System.Convert.ToString(i), Field.Store.YES, Field.Index.NOT_ANALYZED));
                d.Add(new Field("contents", English.IntToEnglish(i), Field.Store.NO, Field.Index.ANALYZED));
                if ((i - 1) % 7 == 0)
                {
                    writer.Commit();
                }
                writer.AddDocument(d);
            }
            writer.Commit();
            
            IndexReader r = IndexReader.Open(directory, true);
            Assert.AreEqual(100, r.NumDocs());
            r.Close();
            
            IndexerThread indexerThread = new IndexerThread(writer, threads);
            threads[0] = indexerThread;
            indexerThread.Start();
            
            IndexerThread indexerThread2 = new IndexerThread(writer, threads);
            threads[1] = indexerThread2;
            indexerThread2.Start();
            
            SearcherThread searcherThread1 = new SearcherThread(directory, threads);
            threads[2] = searcherThread1;
            searcherThread1.Start();
            
            SearcherThread searcherThread2 = new SearcherThread(directory, threads);
            threads[3] = searcherThread2;
            searcherThread2.Start();
            
            indexerThread.Join();
            indexerThread2.Join();
            searcherThread1.Join();
            searcherThread2.Join();
            
            writer.Close();
            
            Assert.IsTrue(!indexerThread.failed, "hit unexpected exception in indexer");
            Assert.IsTrue(!indexerThread2.failed, "hit unexpected exception in indexer2");
            Assert.IsTrue(!searcherThread1.failed, "hit unexpected exception in search1");
            Assert.IsTrue(!searcherThread2.failed, "hit unexpected exception in search2");
            //System.out.println("    Writer: " + indexerThread.count + " iterations");
            //System.out.println("Searcher 1: " + searcherThread1.count + " searchers created");
            //System.out.println("Searcher 2: " + searcherThread2.count + " searchers created");
        }
		public virtual void  TestRandomExceptionsThreads()
		{
			
			MockRAMDirectory dir = new MockRAMDirectory();
			MockIndexWriter writer = new MockIndexWriter(this, dir, new WhitespaceAnalyzer(), true, IndexWriter.MaxFieldLength.LIMITED);
			((ConcurrentMergeScheduler) writer.GetMergeScheduler()).SetSuppressExceptions();
			//writer.setMaxBufferedDocs(10);
			writer.SetRAMBufferSizeMB(0.2);
			
			if (DEBUG)
			{
				System.IO.StreamWriter temp_writer;
				temp_writer = new System.IO.StreamWriter(System.Console.OpenStandardOutput(), System.Console.Out.Encoding);
				temp_writer.AutoFlush = true;
				writer.SetInfoStream(temp_writer);
			}
			
			int NUM_THREADS = 4;
			
			IndexerThread[] threads = new IndexerThread[NUM_THREADS];
			for (int i = 0; i < NUM_THREADS; i++)
			{
				threads[i] = new IndexerThread(this, i, writer);
				threads[i].Start();
			}
			
			for (int i = 0; i < NUM_THREADS; i++)
				threads[i].Join();
			
			for (int i = 0; i < NUM_THREADS; i++)
				if (threads[i].failure != null)
					Assert.Fail("thread " + threads[i].Name + ": hit unexpected failure");
			
			writer.Commit();
			
			try
			{
				writer.Close();
			}
			catch (System.Exception t)
			{
				System.Console.Out.WriteLine("exception during close:");
				System.Console.Out.WriteLine(t.StackTrace);
				writer.Rollback();
			}
			
			// Confirm that when doc hits exception partway through tokenization, it's deleted:
			IndexReader r2 = IndexReader.Open(dir);
			int count = r2.DocFreq(new Term("content4", "aaa"));
			int count2 = r2.DocFreq(new Term("content4", "ddd"));
			Assert.AreEqual(count, count2);
			r2.Close();
			
			_TestUtil.CheckIndex(dir);
		}