static SharedState fillDirectory(Directory directory, int termsNumber) throws IOException { CacheTestSupport.initializeDirectory(directory); SharedState state = new SharedState(0); IndexWriter iwriter = LuceneSettings.openWriter(directory, 100000); for (int i = 0; i <= termsNumber; i++) { Document doc = new Document(); String term = String.valueOf(i); //For even values of i we add to "main" field if (i % 2 == 0) { doc.add(new StringField("main", term, Store.NO)); state.addStringWrittenToIndex(term); } else { doc.add(new StringField("secondaryField", term, Store.NO)); } iwriter.addDocument(doc); } iwriter.commit(); iwriter.close(); return state; }
FSDirectory directory = FSDirectory.open(indexDir.toPath()); try { CacheTestSupport.initializeDirectory(directory); IndexWriter iwriter = LuceneSettings.openWriter(directory, 100000); try {
@BeforeMethod protected void prepare() throws IOException { cache0 = cache(0, CACHE_NAME); cache1 = cache(1, CACHE_NAME); dirA = createDirectory(cache0); dirB = createDirectory(cache1); CacheTestSupport.initializeDirectory(dirA); }
@Test(enabled=false)//to prevent invocations from some versions of TestNG private static void stressTestDirectory(Directory dirWriter, Directory dirReaders, String testLabel, long durationMs, Properties results, String currentMethod) throws InterruptedException, IOException { SharedState state = new SharedState(DICTIONARY_SIZE); CacheTestSupport.initializeDirectory(dirWriter); ExecutorService e = Executors.newFixedThreadPool(READER_THREADS + WRITER_THREADS); for (int i = 0; i < READER_THREADS; i++) { e.execute(new LuceneReaderThread(dirReaders, state)); } for (int i = 0; i < WRITER_THREADS; i++) { e.execute(INDEX_EXCLUSIVE ? new LuceneWriterExclusiveThread(dirWriter, state) : new LuceneWriterThread(dirWriter, state)); } e.shutdown(); System.out.println("Started test: " + testLabel); state.startWaitingThreads(); Thread.sleep(durationMs); long searchesCount = state.incrementIndexSearchesCount(0); long writerTaskCount = state.incrementIndexWriterTaskCount(0); state.quit(); boolean terminatedCorrectly = e.awaitTermination(20, TimeUnit.SECONDS); AssertJUnit.assertTrue(terminatedCorrectly); System.out.println("Test " + testLabel + " run in " + durationMs + "ms:\n\tSearches: " + searchesCount + "\n\t" + "Writes: " + writerTaskCount); if (results != null) { results.setProperty(currentMethod + ".label", testLabel); results.setProperty(currentMethod + ".searches", Long.toString(searchesCount)); results.setProperty(currentMethod + ".writes", Long.toString(writerTaskCount)); } }
public void testInfinispanDirectory() throws Exception { final int OPERATIONS = 100; CacheContainer cacheContainer = CacheTestSupport.createTestCacheManager(); Cache cache = cacheContainer.getCache(); Directory directory = DirectoryBuilder.newDirectoryInstance(cache, cache, cache, "indexName").create(); CacheTestSupport.initializeDirectory(directory); File document = CacheTestSupport.createDummyDocToIndex("document.lucene", 10000); for (int i = 0; i < OPERATIONS; i++) { CacheTestSupport.doWriteOperation(directory, document); CacheTestSupport.doReadOperation(directory); } IndexReader ir = DirectoryReader.open(directory); IndexSearcher search = new IndexSearcher(ir); Term t = new Term("info", "good"); Query query = new TermQuery(t); TopDocs hits = search.search(query, 1); ir.close(); assert OPERATIONS == hits.totalHits; directory.close(); cacheContainer.stop(); }
private void prepareEnvironment(final boolean useDefConstructor) throws IOException { cache0 = cache(0, CACHE_NAME); cache1 = cache(1, CACHE_NAME); if (useDefConstructor) { dirA = createDirectory(cache0); dirB = createDirectory(cache1); } else { dirA = createAdditionalDirectory(cache0); dirB = createAdditionalDirectory(cache1); } CacheTestSupport.initializeDirectory(dirA); }
Cache cache = CacheTestSupport.createTestCacheManager().getCache(); Directory directory1 = DirectoryBuilder.newDirectoryInstance(cache, cache, cache, "indexName").create(); CacheTestSupport.initializeDirectory(directory1);