本文整理汇总了Java中org.apache.lucene.facet.SlowRAMDirectory类的典型用法代码示例。如果您正苦于以下问题:Java SlowRAMDirectory类的具体用法?Java SlowRAMDirectory怎么用?Java SlowRAMDirectory使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
SlowRAMDirectory类属于org.apache.lucene.facet包,在下文中一共展示了SlowRAMDirectory类的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testMemoryCacheSynchronization
import org.apache.lucene.facet.SlowRAMDirectory; //导入依赖的package包/类
/**
* Test that a new TFC is only calculated and placed in memory (by two
* threads who want it at the same time) only once.
*/
@Test
public void testMemoryCacheSynchronization() throws Exception {
SlowRAMDirectory indexDir = new SlowRAMDirectory(-1, null);
SlowRAMDirectory taxoDir = new SlowRAMDirectory(-1, null);
// Write index using 'normal' directories
IndexWriter w = new IndexWriter(indexDir, new IndexWriterConfig(
TEST_VERSION_CURRENT, new MockAnalyzer(random(), MockTokenizer.WHITESPACE, false)));
DirectoryTaxonomyWriter tw = new DirectoryTaxonomyWriter(taxoDir);
FacetIndexingParams iParams = FacetIndexingParams.DEFAULT;
// Add documents and facets
for (int i = 0; i < 1000; i++) {
addFacets(iParams, w, tw, "facet", Integer.toString(i));
}
w.close();
tw.close();
indexDir.setSleepMillis(1);
taxoDir.setSleepMillis(1);
IndexReader r = DirectoryReader.open(indexDir);
DirectoryTaxonomyReader tr = new DirectoryTaxonomyReader(taxoDir);
// Create and start threads. Thread1 should lock the cache and calculate
// the TFC array. The second thread should block until the first is
// done, then successfully retrieve from the cache without recalculating
// or reading from disk.
TFCThread tfcCalc1 = new TFCThread(r, tr, iParams);
TFCThread tfcCalc2 = new TFCThread(r, tr, iParams);
tfcCalc1.start();
// Give thread 1 a head start to ensure correct sequencing for testing
Thread.sleep(5);
tfcCalc2.start();
tfcCalc1.join();
tfcCalc2.join();
// Since this test ends up with references to the same TFC object, we
// can only test the times to make sure that they are the same.
assertRecomputed(tfcCalc1.tfc, 0, "thread 1 should recompute");
assertRecomputed(tfcCalc2.tfc, 0, "thread 2 should recompute");
assertTrue("Both results should be the same (as their inputs are the same objects)",
tfcCalc1.tfc == tfcCalc2.tfc);
r.close();
tr.close();
}