Java 类org.apache.lucene.util.FieldCacheSanityChecker.Insanity 实例源码

项目:search    文件:LuceneTestCase.java   
/**
 * Asserts that FieldCacheSanityChecker does not detect any
 * problems with FieldCache.DEFAULT.
 * <p>
 * If any problems are found, they are logged to System.err
 * (allong with the msg) when the Assertion is thrown.
 * </p>
 * <p>
 * This method is called by tearDown after every test method,
 * however IndexReaders scoped inside test methods may be garbage
 * collected prior to this method being called, causing errors to
 * be overlooked. Tests are encouraged to keep their IndexReaders
 * scoped at the class level, or to explicitly call this method
 * directly in the same scope as the IndexReader.
 * </p>
 *
 * @see org.apache.lucene.util.FieldCacheSanityChecker
 */
protected static void assertSaneFieldCaches(final String msg) {
  final CacheEntry[] entries = FieldCache.DEFAULT.getCacheEntries();
  Insanity[] insanity = null;
  try {
    try {
      insanity = FieldCacheSanityChecker.checkSanity(entries);
    } catch (RuntimeException e) {
      dumpArray(msg + ": FieldCache", entries, System.err);
      throw e;
    }

    assertEquals(msg + ": Insane FieldCache usage(s) found",
                 0, insanity.length);
    insanity = null;
  } finally {

    // report this in the event of any exception/failure
    // if no failure, then insanity will be null anyway
    if (null != insanity) {
      dumpArray(msg + ": Insane FieldCache usage(s)", insanity, System.err);
    }
  }
}
项目:search    文件:TestFieldCacheSanityChecker.java   
public void testSanity() throws IOException {
  FieldCache cache = FieldCache.DEFAULT;
  cache.purgeAllCaches();

  cache.getDoubles(readerA, "theDouble", false);
  cache.getDoubles(readerA, "theDouble", FieldCache.DEFAULT_DOUBLE_PARSER, false);
  cache.getDoubles(readerAclone, "theDouble", FieldCache.DEFAULT_DOUBLE_PARSER, false);
  cache.getDoubles(readerB, "theDouble", FieldCache.DEFAULT_DOUBLE_PARSER, false);

  cache.getInts(readerX, "theInt", false);
  cache.getInts(readerX, "theInt", FieldCache.DEFAULT_INT_PARSER, false);

  // // // 

  Insanity[] insanity = 
    FieldCacheSanityChecker.checkSanity(cache.getCacheEntries());

  if (0 < insanity.length)
    dumpArray(getTestClass().getName() + "#" + getTestName() 
        + " INSANITY", insanity, System.err);

  assertEquals("shouldn't be any cache insanity", 0, insanity.length);
  cache.purgeAllCaches();
}
项目:search    文件:TestFieldCacheSanityChecker.java   
public void testInsanity1() throws IOException {
  FieldCache cache = FieldCache.DEFAULT;
  cache.purgeAllCaches();

  cache.getInts(readerX, "theInt", FieldCache.DEFAULT_INT_PARSER, false);
  cache.getTerms(readerX, "theInt", false);
  cache.getBytes(readerX, "theByte", false);

  // // // 

  Insanity[] insanity = 
    FieldCacheSanityChecker.checkSanity(cache.getCacheEntries());

  assertEquals("wrong number of cache errors", 1, insanity.length);
  assertEquals("wrong type of cache error", 
               InsanityType.VALUEMISMATCH,
               insanity[0].getType());
  assertEquals("wrong number of entries in cache error", 2,
               insanity[0].getCacheEntries().length);

  // we expect bad things, don't let tearDown complain about them
  cache.purgeAllCaches();
}
项目:search    文件:TestFieldCacheSanityChecker.java   
public void testInsanity2() throws IOException {
  FieldCache cache = FieldCache.DEFAULT;
  cache.purgeAllCaches();

  cache.getTerms(readerA, "theInt", false);
  cache.getTerms(readerB, "theInt", false);
  cache.getTerms(readerX, "theInt", false);

  cache.getBytes(readerX, "theByte", false);


  // // // 

  Insanity[] insanity = 
    FieldCacheSanityChecker.checkSanity(cache.getCacheEntries());

  assertEquals("wrong number of cache errors", 1, insanity.length);
  assertEquals("wrong type of cache error", 
               InsanityType.SUBREADER,
               insanity[0].getType());
  assertEquals("wrong number of entries in cache error", 3,
               insanity[0].getCacheEntries().length);

  // we expect bad things, don't let tearDown complain about them
  cache.purgeAllCaches();
}
项目:NYBC    文件:LuceneTestCase.java   
/**
 * Asserts that FieldCacheSanityChecker does not detect any
 * problems with FieldCache.DEFAULT.
 * <p>
 * If any problems are found, they are logged to System.err
 * (allong with the msg) when the Assertion is thrown.
 * </p>
 * <p>
 * This method is called by tearDown after every test method,
 * however IndexReaders scoped inside test methods may be garbage
 * collected prior to this method being called, causing errors to
 * be overlooked. Tests are encouraged to keep their IndexReaders
 * scoped at the class level, or to explicitly call this method
 * directly in the same scope as the IndexReader.
 * </p>
 *
 * @see org.apache.lucene.util.FieldCacheSanityChecker
 */
protected static void assertSaneFieldCaches(final String msg) {
  final CacheEntry[] entries = FieldCache.DEFAULT.getCacheEntries();
  Insanity[] insanity = null;
  try {
    try {
      insanity = FieldCacheSanityChecker.checkSanity(entries);
    } catch (RuntimeException e) {
      dumpArray(msg + ": FieldCache", entries, System.err);
      throw e;
    }

    assertEquals(msg + ": Insane FieldCache usage(s) found",
                 0, insanity.length);
    insanity = null;
  } finally {

    // report this in the event of any exception/failure
    // if no failure, then insanity will be null anyway
    if (null != insanity) {
      dumpArray(msg + ": Insane FieldCache usage(s)", insanity, System.err);
    }
  }
}
项目:NYBC    文件:TestFieldCacheSanityChecker.java   
public void testSanity() throws IOException {
  FieldCache cache = FieldCache.DEFAULT;
  cache.purgeAllCaches();

  cache.getDoubles(readerA, "theDouble", false);
  cache.getDoubles(readerA, "theDouble", FieldCache.DEFAULT_DOUBLE_PARSER, false);
  cache.getDoubles(readerAclone, "theDouble", FieldCache.DEFAULT_DOUBLE_PARSER, false);
  cache.getDoubles(readerB, "theDouble", FieldCache.DEFAULT_DOUBLE_PARSER, false);

  cache.getInts(readerX, "theInt", false);
  cache.getInts(readerX, "theInt", FieldCache.DEFAULT_INT_PARSER, false);

  // // // 

  Insanity[] insanity = 
    FieldCacheSanityChecker.checkSanity(cache.getCacheEntries());

  if (0 < insanity.length)
    dumpArray(getTestClass().getName() + "#" + getTestName() 
        + " INSANITY", insanity, System.err);

  assertEquals("shouldn't be any cache insanity", 0, insanity.length);
  cache.purgeAllCaches();
}
项目:NYBC    文件:TestFieldCacheSanityChecker.java   
public void testInsanity1() throws IOException {
  FieldCache cache = FieldCache.DEFAULT;
  cache.purgeAllCaches();

  cache.getInts(readerX, "theInt", FieldCache.DEFAULT_INT_PARSER, false);
  cache.getTerms(readerX, "theInt");
  cache.getBytes(readerX, "theByte", false);

  // // // 

  Insanity[] insanity = 
    FieldCacheSanityChecker.checkSanity(cache.getCacheEntries());

  assertEquals("wrong number of cache errors", 1, insanity.length);
  assertEquals("wrong type of cache error", 
               InsanityType.VALUEMISMATCH,
               insanity[0].getType());
  assertEquals("wrong number of entries in cache error", 2,
               insanity[0].getCacheEntries().length);

  // we expect bad things, don't let tearDown complain about them
  cache.purgeAllCaches();
}
项目:NYBC    文件:TestFieldCacheSanityChecker.java   
public void testInsanity2() throws IOException {
  FieldCache cache = FieldCache.DEFAULT;
  cache.purgeAllCaches();

  cache.getTerms(readerA, "theInt");
  cache.getTerms(readerB, "theInt");
  cache.getTerms(readerX, "theInt");

  cache.getBytes(readerX, "theByte", false);


  // // // 

  Insanity[] insanity = 
    FieldCacheSanityChecker.checkSanity(cache.getCacheEntries());

  assertEquals("wrong number of cache errors", 1, insanity.length);
  assertEquals("wrong type of cache error", 
               InsanityType.SUBREADER,
               insanity[0].getType());
  assertEquals("wrong number of entries in cache error", 3,
               insanity[0].getCacheEntries().length);

  // we expect bad things, don't let tearDown complain about them
  cache.purgeAllCaches();
}
项目:Maskana-Gestor-de-Conocimiento    文件:LuceneTestCase.java   
/**
 * Asserts that FieldCacheSanityChecker does not detect any
 * problems with FieldCache.DEFAULT.
 * <p>
 * If any problems are found, they are logged to System.err
 * (allong with the msg) when the Assertion is thrown.
 * </p>
 * <p>
 * This method is called by tearDown after every test method,
 * however IndexReaders scoped inside test methods may be garbage
 * collected prior to this method being called, causing errors to
 * be overlooked. Tests are encouraged to keep their IndexReaders
 * scoped at the class level, or to explicitly call this method
 * directly in the same scope as the IndexReader.
 * </p>
 *
 * @see org.apache.lucene.util.FieldCacheSanityChecker
 */
protected static void assertSaneFieldCaches(final String msg) {
  final CacheEntry[] entries = FieldCache.DEFAULT.getCacheEntries();
  Insanity[] insanity = null;
  try {
    try {
      insanity = FieldCacheSanityChecker.checkSanity(entries);
    } catch (RuntimeException e) {
      dumpArray(msg + ": FieldCache", entries, System.err);
      throw e;
    }

    assertEquals(msg + ": Insane FieldCache usage(s) found",
                 0, insanity.length);
    insanity = null;
  } finally {

    // report this in the event of any exception/failure
    // if no failure, then insanity will be null anyway
    if (null != insanity) {
      dumpArray(msg + ": Insane FieldCache usage(s)", insanity, System.err);
    }
  }
}
项目:Maskana-Gestor-de-Conocimiento    文件:TestFieldCacheSanityChecker.java   
public void testSanity() throws IOException {
  FieldCache cache = FieldCache.DEFAULT;
  cache.purgeAllCaches();

  cache.getDoubles(readerA, "theDouble", false);
  cache.getDoubles(readerA, "theDouble", FieldCache.DEFAULT_DOUBLE_PARSER, false);
  cache.getDoubles(readerAclone, "theDouble", FieldCache.DEFAULT_DOUBLE_PARSER, false);
  cache.getDoubles(readerB, "theDouble", FieldCache.DEFAULT_DOUBLE_PARSER, false);

  cache.getInts(readerX, "theInt", false);
  cache.getInts(readerX, "theInt", FieldCache.DEFAULT_INT_PARSER, false);

  // // // 

  Insanity[] insanity = 
    FieldCacheSanityChecker.checkSanity(cache.getCacheEntries());

  if (0 < insanity.length)
    dumpArray(getTestClass().getName() + "#" + getTestName() 
        + " INSANITY", insanity, System.err);

  assertEquals("shouldn't be any cache insanity", 0, insanity.length);
  cache.purgeAllCaches();
}
项目:Maskana-Gestor-de-Conocimiento    文件:TestFieldCacheSanityChecker.java   
public void testInsanity1() throws IOException {
  FieldCache cache = FieldCache.DEFAULT;
  cache.purgeAllCaches();

  cache.getInts(readerX, "theInt", FieldCache.DEFAULT_INT_PARSER, false);
  cache.getTerms(readerX, "theInt", false);
  cache.getBytes(readerX, "theByte", false);

  // // // 

  Insanity[] insanity = 
    FieldCacheSanityChecker.checkSanity(cache.getCacheEntries());

  assertEquals("wrong number of cache errors", 1, insanity.length);
  assertEquals("wrong type of cache error", 
               InsanityType.VALUEMISMATCH,
               insanity[0].getType());
  assertEquals("wrong number of entries in cache error", 2,
               insanity[0].getCacheEntries().length);

  // we expect bad things, don't let tearDown complain about them
  cache.purgeAllCaches();
}
项目:Maskana-Gestor-de-Conocimiento    文件:TestFieldCacheSanityChecker.java   
public void testInsanity2() throws IOException {
  FieldCache cache = FieldCache.DEFAULT;
  cache.purgeAllCaches();

  cache.getTerms(readerA, "theInt", false);
  cache.getTerms(readerB, "theInt", false);
  cache.getTerms(readerX, "theInt", false);

  cache.getBytes(readerX, "theByte", false);


  // // // 

  Insanity[] insanity = 
    FieldCacheSanityChecker.checkSanity(cache.getCacheEntries());

  assertEquals("wrong number of cache errors", 1, insanity.length);
  assertEquals("wrong type of cache error", 
               InsanityType.SUBREADER,
               insanity[0].getType());
  assertEquals("wrong number of entries in cache error", 3,
               insanity[0].getCacheEntries().length);

  // we expect bad things, don't let tearDown complain about them
  cache.purgeAllCaches();
}
项目:search    文件:SolrFieldCacheMBean.java   
@Override
public NamedList getStatistics() {
  NamedList stats = new SimpleOrderedMap();
  CacheEntry[] entries = FieldCache.DEFAULT.getCacheEntries();
  stats.add("entries_count", entries.length);
  for (int i = 0; i < entries.length; i++) {
    CacheEntry e = entries[i];
    stats.add("entry#" + i, e.toString());
  }

  Insanity[] insanity = checker.check(entries);

  stats.add("insanity_count", insanity.length);
  for (int i = 0; i < insanity.length; i++) {

    /** RAM estimation is both CPU and memory intensive... we don't want to do it unless asked.
    // we only estimate the size of insane entries
    for (CacheEntry e : insanity[i].getCacheEntries()) {
      // don't re-estimate if we've already done it.
      if (null == e.getEstimatedSize()) e.estimateSize();
    }
    **/

    stats.add("insanity#" + i, insanity[i].toString());
  }
  return stats;
}
项目:NYBC    文件:SolrFieldCacheMBean.java   
@Override
public NamedList getStatistics() {
  NamedList stats = new SimpleOrderedMap();
  CacheEntry[] entries = FieldCache.DEFAULT.getCacheEntries();
  stats.add("entries_count", entries.length);
  for (int i = 0; i < entries.length; i++) {
    CacheEntry e = entries[i];
    stats.add("entry#" + i, e.toString());
  }

  Insanity[] insanity = checker.check(entries);

  stats.add("insanity_count", insanity.length);
  for (int i = 0; i < insanity.length; i++) {

    /** RAM estimation is both CPU and memory intensive... we don't want to do it unless asked.
    // we only estimate the size of insane entries
    for (CacheEntry e : insanity[i].getCacheEntries()) {
      // don't re-estimate if we've already done it.
      if (null == e.getEstimatedSize()) e.estimateSize();
    }
    **/

    stats.add("insanity#" + i, insanity[i].toString());
  }
  return stats;
}
项目:search-core    文件:SolrFieldCacheMBean.java   
@Override
public NamedList getStatistics() {
  NamedList stats = new SimpleOrderedMap();
  CacheEntry[] entries = FieldCache.DEFAULT.getCacheEntries();
  stats.add("entries_count", entries.length);
  for (int i = 0; i < entries.length; i++) {
    CacheEntry e = entries[i];
    stats.add("entry#" + i, e.toString());
  }

  Insanity[] insanity = checker.check(entries);

  stats.add("insanity_count", insanity.length);
  for (int i = 0; i < insanity.length; i++) {

    /** RAM estimation is both CPU and memory intensive... we don't want to do it unless asked.
    // we only estimate the size of insane entries
    for (CacheEntry e : insanity[i].getCacheEntries()) {
      // don't re-estimate if we've already done it.
      if (null == e.getEstimatedSize()) e.estimateSize();
    }
    **/

    stats.add("insanity#" + i, insanity[i].toString());
  }
  return stats;
}
项目:read-open-source-code    文件:SolrFieldCacheMBean.java   
@Override
public NamedList getStatistics() {
  NamedList stats = new SimpleOrderedMap();
  CacheEntry[] entries = FieldCache.DEFAULT.getCacheEntries();
  stats.add("entries_count", entries.length);
  for (int i = 0; i < entries.length; i++) {
    CacheEntry e = entries[i];
    stats.add("entry#" + i, e.toString());
  }

  Insanity[] insanity = checker.check(entries);

  stats.add("insanity_count", insanity.length);
  for (int i = 0; i < insanity.length; i++) {

    /** RAM estimation is both CPU and memory intensive... we don't want to do it unless asked.
    // we only estimate the size of insane entries
    for (CacheEntry e : insanity[i].getCacheEntries()) {
      // don't re-estimate if we've already done it.
      if (null == e.getEstimatedSize()) e.estimateSize();
    }
    **/

    stats.add("insanity#" + i, insanity[i].toString());
  }
  return stats;
}
项目:read-open-source-code    文件:SolrFieldCacheMBean.java   
@Override
public NamedList getStatistics() {
  NamedList stats = new SimpleOrderedMap();
  CacheEntry[] entries = FieldCache.DEFAULT.getCacheEntries();
  stats.add("entries_count", entries.length);
  for (int i = 0; i < entries.length; i++) {
    CacheEntry e = entries[i];
    stats.add("entry#" + i, e.toString());
  }

  Insanity[] insanity = checker.check(entries);

  stats.add("insanity_count", insanity.length);
  for (int i = 0; i < insanity.length; i++) {

    /** RAM estimation is both CPU and memory intensive... we don't want to do it unless asked.
    // we only estimate the size of insane entries
    for (CacheEntry e : insanity[i].getCacheEntries()) {
      // don't re-estimate if we've already done it.
      if (null == e.getEstimatedSize()) e.estimateSize();
    }
    **/

    stats.add("insanity#" + i, insanity[i].toString());
  }
  return stats;
}