Package org.apache.lucene.util

Examples of org.apache.lucene.util.SlowRAMDirectory$SlowIndexOutput


  }

  private void assertConsistentYoungestChild(final CategoryPath abPath,
      final int abOrd, final int abYoungChildBase1, final int abYoungChildBase2, final int retry)
      throws Exception {
    SlowRAMDirectory indexDir =  new SlowRAMDirectory(-1,null); // no slowness for intialization
    TaxonomyWriter tw = new LuceneTaxonomyWriter(indexDir);
    tw.addCategory(new CategoryPath("a", "0"));
    tw.addCategory(abPath);
    tw.commit();
   
    final TaxonomyReader tr = new LuceneTaxonomyReader(indexDir);
    for (int i=0; i < 1<<10; i++) { //1024 facets
      final CategoryPath cp = new CategoryPath("a", "b", Integer.toString(i));
      tw.addCategory(cp);
      assertEquals("Ordinal of "+cp+" must be invalid until Taxonomy Reader was refreshed", TaxonomyReader.INVALID_ORDINAL, tr.getOrdinal(cp));
    }
    tw.commit();
   
    final boolean[] stop = new boolean[] { false };
    final Throwable[] error = new Throwable[] { null };
    final int retrieval[] = { 0 };
   
    Thread thread = new Thread("Child Arrays Verifier") {
      @Override
      public void run() {
        setPriority(1+getPriority());
        try {
          while (!stop[0]) {
            int lastOrd = tr.getParentArray().length-1;
            assertNotNull("path of last-ord "+lastOrd+" is not found!",tr.getPath(lastOrd));
            assertChildrenArrays(tr.getChildrenArrays(),retry,retrieval[0]++);
          }
        } catch (Throwable e) {
          error[0] = e;
          stop[0] = true;
        }
      }

      private void assertChildrenArrays(ChildrenArrays ca, int retry, int retrieval) {
        final int abYoungChild = ca.getYoungestChildArray()[abOrd];
        assertTrue(
            "Retry "+retry+": retrieval: "+retrieval+": wrong youngest child for category "+abPath+" (ord="+abOrd+
            ") - must be either "+abYoungChildBase1+" or "+abYoungChildBase2+" but was: "+abYoungChild,
            abYoungChildBase1==abYoungChild ||
            abYoungChildBase2==ca.getYoungestChildArray()[abOrd]);
      }
    };
    thread.start();
   
    indexDir.setSleepMillis(1); // some delay for refresh
    tr.refresh();
   
    stop[0] = true;
    thread.join();
    assertNull("Unexpcted exception at retry "+retry+" retrieval "+retrieval[0]+": \n"+stackTraceStr(error[0]), error[0]);
View Full Code Here


  private void doTestGeneralSynchronization(int numThreads, int sleepMillis,
      int cacheSize) throws Exception, CorruptIndexException, IOException,
      InterruptedException {
    TFC.setCacheSize(cacheSize);
    SlowRAMDirectory slowIndexDir = new SlowRAMDirectory(-1, random);
    MockDirectoryWrapper indexDir = new MockDirectoryWrapper(random, slowIndexDir);
    SlowRAMDirectory slowTaxoDir = new SlowRAMDirectory(-1, random);
    MockDirectoryWrapper taxoDir = new MockDirectoryWrapper(random, slowTaxoDir);
   

    // Index documents without the "slowness"
    MultiCLIndexer.index(indexDir, taxoDir);

    slowIndexDir.setSleepMillis(sleepMillis);
    slowTaxoDir.setSleepMillis(sleepMillis);
   
    // Open the slow readers
    IndexReader slowIndexReader = IndexReader.open(indexDir);
    TaxonomyReader slowTaxoReader = new LuceneTaxonomyReader(taxoDir);
View Full Code Here

   * 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)));
    LuceneTaxonomyWriter tw = new LuceneTaxonomyWriter(taxoDir);
    DefaultFacetIndexingParams iParams = new DefaultFacetIndexingParams();
    // 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 = IndexReader.open(indexDir);
    LuceneTaxonomyReader tr = new LuceneTaxonomyReader(taxoDir);

    // Create and start threads. Thread1 should lock the cache and calculate
View Full Code Here

  }

  private void assertConsistentYoungestChild(final CategoryPath abPath,
      final int abOrd, final int abYoungChildBase1, final int abYoungChildBase2, final int retry)
      throws Exception {
    SlowRAMDirectory indexDir =  new SlowRAMDirectory(-1,null); // no slowness for intialization
    TaxonomyWriter tw = new DirectoryTaxonomyWriter(indexDir);
    tw.addCategory(new CategoryPath("a", "0"));
    tw.addCategory(abPath);
    tw.commit();
   
    final TaxonomyReader tr = new DirectoryTaxonomyReader(indexDir);
    for (int i=0; i < 1<<10; i++) { //1024 facets
      final CategoryPath cp = new CategoryPath("a", "b", Integer.toString(i));
      tw.addCategory(cp);
      assertEquals("Ordinal of "+cp+" must be invalid until Taxonomy Reader was refreshed", TaxonomyReader.INVALID_ORDINAL, tr.getOrdinal(cp));
    }
    tw.commit();
   
    final boolean[] stop = new boolean[] { false };
    final Throwable[] error = new Throwable[] { null };
    final int retrieval[] = { 0 };
   
    Thread thread = new Thread("Child Arrays Verifier") {
      @Override
      public void run() {
        setPriority(1+getPriority());
        try {
          while (!stop[0]) {
            int lastOrd = tr.getParentArray().length-1;
            assertNotNull("path of last-ord "+lastOrd+" is not found!",tr.getPath(lastOrd));
            assertChildrenArrays(tr.getChildrenArrays(),retry,retrieval[0]++);
          }
        } catch (Throwable e) {
          error[0] = e;
          stop[0] = true;
        }
      }

      private void assertChildrenArrays(ChildrenArrays ca, int retry, int retrieval) {
        final int abYoungChild = ca.getYoungestChildArray()[abOrd];
        assertTrue(
            "Retry "+retry+": retrieval: "+retrieval+": wrong youngest child for category "+abPath+" (ord="+abOrd+
            ") - must be either "+abYoungChildBase1+" or "+abYoungChildBase2+" but was: "+abYoungChild,
            abYoungChildBase1==abYoungChild ||
            abYoungChildBase2==ca.getYoungestChildArray()[abOrd]);
      }
    };
    thread.start();
   
    indexDir.setSleepMillis(1); // some delay for refresh
    tr.refresh();
   
    stop[0] = true;
    thread.join();
    assertNull("Unexpcted exception at retry "+retry+" retrieval "+retrieval[0]+": \n"+stackTraceStr(error[0]), error[0]);
View Full Code Here

  private void doTestGeneralSynchronization(int numThreads, int sleepMillis,
      int cacheSize) throws Exception, CorruptIndexException, IOException,
      InterruptedException {
    TFC.setCacheSize(cacheSize);
    SlowRAMDirectory slowIndexDir = new SlowRAMDirectory(-1, random);
    MockDirectoryWrapper indexDir = new MockDirectoryWrapper(random, slowIndexDir);
    SlowRAMDirectory slowTaxoDir = new SlowRAMDirectory(-1, random);
    MockDirectoryWrapper taxoDir = new MockDirectoryWrapper(random, slowTaxoDir);
   

    // Index documents without the "slowness"
    MultiCLIndexer.index(indexDir, taxoDir);

    slowIndexDir.setSleepMillis(sleepMillis);
    slowTaxoDir.setSleepMillis(sleepMillis);
   
    // Open the slow readers
    IndexReader slowIndexReader = IndexReader.open(indexDir);
    TaxonomyReader slowTaxoReader = new DirectoryTaxonomyReader(taxoDir);
View Full Code Here

   * 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);
    DefaultFacetIndexingParams iParams = new DefaultFacetIndexingParams();
    // 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 = IndexReader.open(indexDir);
    DirectoryTaxonomyReader tr = new DirectoryTaxonomyReader(taxoDir);

    // Create and start threads. Thread1 should lock the cache and calculate
View Full Code Here

TOP

Related Classes of org.apache.lucene.util.SlowRAMDirectory$SlowIndexOutput

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.