Ejemplo n.º 1
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");
        }
Ejemplo n.º 2
0
        public virtual DocsAndWriter IndexRandomIWReader(int nThreads, int iterations, int range, Directory dir)
        {
            System.Collections.Hashtable docs = new System.Collections.Hashtable();
            IndexWriter w = new MockIndexWriter(this, dir, autoCommit, new WhitespaceAnalyzer(), true);

            w.SetUseCompoundFile(false);

            /***
             * w.setMaxMergeDocs(Integer.MAX_VALUE);
             * w.setMaxFieldLength(10000);
             * w.setRAMBufferSizeMB(1);
             * w.setMergeFactor(10);
             ***/

            // force many merges
            w.SetMergeFactor(mergeFactor);
            w.SetRAMBufferSizeMB(.1);
            w.SetMaxBufferedDocs(maxBufferedDocs);

            threads = new IndexingThread[nThreads];
            for (int i = 0; i < threads.Length; i++)
            {
                IndexingThread th = new IndexingThread();
                th.w            = w;
                th.base_Renamed = 1000000 * i;
                th.range        = range;
                th.iterations   = iterations;
                threads[i]      = th;
            }

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

            // w.optimize();
            //w.close();

            for (int i = 0; i < threads.Length; i++)
            {
                IndexingThread th = threads[i];
                lock (th)
                {
                    SupportClass.CollectionsHelper.AddAllIfNotContains(docs, th.docs);
                }
            }

            _TestUtil.CheckIndex(dir);
            DocsAndWriter dw = new DocsAndWriter();

            dw.docs   = docs;
            dw.writer = w;
            return(dw);
        }
Ejemplo n.º 3
0
        public virtual System.Collections.IDictionary IndexRandom(int nThreads, int iterations, int range, Directory dir)
        {
            System.Collections.IDictionary docs = new System.Collections.Hashtable();
            for (int iter = 0; iter < 3; iter++)
            {
                IndexWriter w = new MockIndexWriter(this, dir, autoCommit, new WhitespaceAnalyzer(), true);
                w.SetUseCompoundFile(false);

                // force many merges
                w.SetMergeFactor(mergeFactor);
                w.SetRAMBufferSizeMB(.1);
                w.SetMaxBufferedDocs(maxBufferedDocs);

                threads = new IndexingThread[nThreads];
                for (int i = 0; i < threads.Length; i++)
                {
                    IndexingThread th = new IndexingThread();
                    th.w            = w;
                    th.base_Renamed = 1000000 * i;
                    th.range        = range;
                    th.iterations   = iterations;
                    threads[i]      = th;
                }

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

                // w.optimize();
                w.Close();

                for (int i = 0; i < threads.Length; i++)
                {
                    IndexingThread th = threads[i];
                    lock (th)
                    {
                        System.Collections.IEnumerator e = th.docs.Keys.GetEnumerator();
                        while (e.MoveNext())
                        {
                            docs[e.Current] = th.docs[e.Current];
                        }
                    }
                }
            }

            _TestUtil.CheckIndex(dir);

            return(docs);
        }
Ejemplo n.º 4
0
		public virtual System.Collections.IDictionary IndexRandom(int nThreads, int iterations, int range, Directory dir)
		{
			System.Collections.IDictionary docs = new System.Collections.Hashtable();
			for (int iter = 0; iter < 3; iter++)
			{
				IndexWriter w = new MockIndexWriter(this, dir, autoCommit, new WhitespaceAnalyzer(), true);
				w.SetUseCompoundFile(false);
				
				// force many merges
				w.SetMergeFactor(mergeFactor);
				w.SetRAMBufferSizeMB(.1);
				w.SetMaxBufferedDocs(maxBufferedDocs);
				
				threads = new IndexingThread[nThreads];
				for (int i = 0; i < threads.Length; i++)
				{
					IndexingThread th = new IndexingThread();
					th.w = w;
					th.base_Renamed = 1000000 * i;
					th.range = range;
					th.iterations = iterations;
					threads[i] = th;
				}
				
				for (int i = 0; i < threads.Length; i++)
				{
					threads[i].Start();
				}
				for (int i = 0; i < threads.Length; i++)
				{
					threads[i].Join();
				}
				
				// w.optimize();
				w.Close();
				
				for (int i = 0; i < threads.Length; i++)
				{
					IndexingThread th = threads[i];
					lock (th)
					{
                        System.Collections.IEnumerator e = th.docs.Keys.GetEnumerator();
                        while (e.MoveNext())
                        {
                            docs[e.Current] = th.docs[e.Current];
                        }
					}
				}
			}
			
			_TestUtil.CheckIndex(dir);
			
			return docs;
		}
Ejemplo n.º 5
0
		public virtual DocsAndWriter IndexRandomIWReader(int nThreads, int iterations, int range, Directory dir)
		{
			System.Collections.Hashtable docs = new System.Collections.Hashtable();
			IndexWriter w = new MockIndexWriter(this, dir, autoCommit, new WhitespaceAnalyzer(), true);
			w.SetUseCompoundFile(false);
			
			/***
			w.setMaxMergeDocs(Integer.MAX_VALUE);
			w.setMaxFieldLength(10000);
			w.setRAMBufferSizeMB(1);
			w.setMergeFactor(10);
			***/
			
			// force many merges
			w.SetMergeFactor(mergeFactor);
			w.SetRAMBufferSizeMB(.1);
			w.SetMaxBufferedDocs(maxBufferedDocs);
			
			threads = new IndexingThread[nThreads];
			for (int i = 0; i < threads.Length; i++)
			{
				IndexingThread th = new IndexingThread();
				th.w = w;
				th.base_Renamed = 1000000 * i;
				th.range = range;
				th.iterations = iterations;
				threads[i] = th;
			}
			
			for (int i = 0; i < threads.Length; i++)
			{
				threads[i].Start();
			}
			for (int i = 0; i < threads.Length; i++)
			{
				threads[i].Join();
			}
			
			// w.optimize();
			//w.close();    
			
			for (int i = 0; i < threads.Length; i++)
			{
				IndexingThread th = threads[i];
				lock (th)
				{
					SupportClass.CollectionsHelper.AddAllIfNotContains(docs, th.docs);
				}
			}
			
			_TestUtil.CheckIndex(dir);
			DocsAndWriter dw = new DocsAndWriter();
			dw.docs = docs;
			dw.writer = w;
			return dw;
		}
Ejemplo n.º 6
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");
		}