Package org.apache.lucene.facet

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


    IOUtils.close(indexWriter, taxoWriter);
  }
 
  private void doTestGeneralSynchronization(int numThreads, int sleepMillis, int cacheSize) throws Exception {
    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"
    index(indexDir, taxoDir);

    slowIndexDir.setSleepMillis(sleepMillis);
    slowTaxoDir.setSleepMillis(sleepMillis);
   
    // Open the slow readers
    IndexReader slowIndexReader = DirectoryReader.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);
    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
View Full Code Here

  }

  private void assertConsistentYoungestChild(final CategoryPath abPath,
      final int abOrd, final int abYoungChildBase1, final int abYoungChildBase2, final int retry, int numCategories)
      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 DirectoryTaxonomyReader tr = new DirectoryTaxonomyReader(indexDir);
    for (int i = 0; i < numCategories; i++) {
      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.close();
   
    final AtomicBoolean stop = new AtomicBoolean(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.get()) {
            int lastOrd = tr.getParallelTaxonomyArrays().parents().length - 1;
            assertNotNull("path of last-ord " + lastOrd + " is not found!", tr.getPath(lastOrd));
            assertChildrenArrays(tr.getParallelTaxonomyArrays(), retry, retrieval[0]++);
            sleep(10); // don't starve refresh()'s CPU, which sleeps every 50 bytes for 1 ms
          }
        } catch (Throwable e) {
          error[0] = e;
          stop.set(true);
        }
      }

      private void assertChildrenArrays(ParallelTaxonomyArrays ca, int retry, int retrieval) {
        final int abYoungChild = ca.children()[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.children()[abOrd]);
      }
    };
    thread.start();
   
    indexDir.setSleepMillis(1); // some delay for refresh
    TaxonomyReader newTaxoReader = TaxonomyReader.openIfChanged(tr);
    if (newTaxoReader != null) {
      newTaxoReader.close();
    }
   
View Full Code Here

  }

  private void assertConsistentYoungestChild(final FacetLabel abPath,
      final int abOrd, final int abYoungChildBase1, final int abYoungChildBase2, final int retry, int numCategories)
      throws Exception {
    SlowRAMDirectory indexDir = new SlowRAMDirectory(-1, null); // no slowness for intialization
    TaxonomyWriter tw = new DirectoryTaxonomyWriter(indexDir);
    tw.addCategory(new FacetLabel("a", "0"));
    tw.addCategory(abPath);
    tw.commit();
   
    final DirectoryTaxonomyReader tr = new DirectoryTaxonomyReader(indexDir);
    for (int i = 0; i < numCategories; i++) {
      final FacetLabel cp = new FacetLabel("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.close();
   
    final AtomicBoolean stop = new AtomicBoolean(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.get()) {
            int lastOrd = tr.getParallelTaxonomyArrays().parents().length - 1;
            assertNotNull("path of last-ord " + lastOrd + " is not found!", tr.getPath(lastOrd));
            assertChildrenArrays(tr.getParallelTaxonomyArrays(), retry, retrieval[0]++);
            sleep(10); // don't starve refresh()'s CPU, which sleeps every 50 bytes for 1 ms
          }
        } catch (Throwable e) {
          error[0] = e;
          stop.set(true);
        }
      }

      private void assertChildrenArrays(ParallelTaxonomyArrays ca, int retry, int retrieval) {
        final int abYoungChild = ca.children()[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.children()[abOrd]);
      }
    };
    thread.start();
   
    indexDir.setSleepMillis(1); // some delay for refresh
    TaxonomyReader newTaxoReader = TaxonomyReader.openIfChanged(tr);
    if (newTaxoReader != null) {
      newTaxoReader.close();
    }
   
View Full Code Here

  }

  private void assertConsistentYoungestChild(final CategoryPath abPath,
      final int abOrd, final int abYoungChildBase1, final int abYoungChildBase2, final int retry, int numCategories)
      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 DirectoryTaxonomyReader tr = new DirectoryTaxonomyReader(indexDir);
    for (int i = 0; i < numCategories; i++) {
      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.close();
   
    final AtomicBoolean stop = new AtomicBoolean(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.get()) {
            int lastOrd = tr.getParallelTaxonomyArrays().parents().length - 1;
            assertNotNull("path of last-ord " + lastOrd + " is not found!", tr.getPath(lastOrd));
            assertChildrenArrays(tr.getParallelTaxonomyArrays(), retry, retrieval[0]++);
            sleep(10); // don't starve refresh()'s CPU, which sleeps every 50 bytes for 1 ms
          }
        } catch (Throwable e) {
          error[0] = e;
          stop.set(true);
        }
      }

      private void assertChildrenArrays(ParallelTaxonomyArrays ca, int retry, int retrieval) {
        final int abYoungChild = ca.children()[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.children()[abOrd]);
      }
    };
    thread.start();
   
    indexDir.setSleepMillis(1); // some delay for refresh
    TaxonomyReader newTaxoReader = TaxonomyReader.openIfChanged(tr);
    if (newTaxoReader != null) {
      newTaxoReader.close();
    }
   
View Full Code Here

  }

  private void assertConsistentYoungestChild(final FacetLabel abPath,
      final int abOrd, final int abYoungChildBase1, final int abYoungChildBase2, final int retry, int numCategories)
      throws Exception {
    SlowRAMDirectory indexDir = new SlowRAMDirectory(-1, null); // no slowness for intialization
    TaxonomyWriter tw = new DirectoryTaxonomyWriter(indexDir);
    tw.addCategory(new FacetLabel("a", "0"));
    tw.addCategory(abPath);
    tw.commit();
   
    final DirectoryTaxonomyReader tr = new DirectoryTaxonomyReader(indexDir);
    for (int i = 0; i < numCategories; i++) {
      final FacetLabel cp = new FacetLabel("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.close();
   
    final AtomicBoolean stop = new AtomicBoolean(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.get()) {
            int lastOrd = tr.getParallelTaxonomyArrays().parents().length - 1;
            assertNotNull("path of last-ord " + lastOrd + " is not found!", tr.getPath(lastOrd));
            assertChildrenArrays(tr.getParallelTaxonomyArrays(), retry, retrieval[0]++);
            sleep(10); // don't starve refresh()'s CPU, which sleeps every 50 bytes for 1 ms
          }
        } catch (Throwable e) {
          error[0] = e;
          stop.set(true);
        }
      }

      private void assertChildrenArrays(ParallelTaxonomyArrays ca, int retry, int retrieval) {
        final int abYoungChild = ca.children()[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.children()[abOrd]);
      }
    };
    thread.start();
   
    indexDir.setSleepMillis(1); // some delay for refresh
    TaxonomyReader newTaxoReader = TaxonomyReader.openIfChanged(tr);
    if (newTaxoReader != null) {
      newTaxoReader.close();
    }
   
View Full Code Here

TOP

Related Classes of org.apache.lucene.facet.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.