Exemplo n.º 1
0
  @Test
  public void testLookup() {
    Lookup<IPriorityFoo> lookup = Lookups.getPriority(IPriorityFoo.class);

    // This should only be ImplB, which has the highest priority.
    IFoo myFoo = lookup.lookup();
    LOG.info("Got foo implementation: " + myFoo.getClass().getName());
    assertTrue(myFoo instanceof Providers.PriorityImplB);

    String result = myFoo.getMessage();
    LOG.info("Got result string: " + result);
    assertEquals("priorityimplB", result);
  }
Exemplo n.º 2
0
 private void _benchmark(Lookup lookup, Map<String, Integer> ref, boolean estimate, Bench bench)
     throws Exception {
   long start = System.currentTimeMillis();
   lookup.build(getTFIT());
   long buildTime = System.currentTimeMillis() - start;
   TermFreqIterator tfit = getTFIT();
   long elapsed = 0;
   while (tfit.hasNext()) {
     String key = tfit.next();
     // take only the first part of the key
     int len = key.length() > 4 ? key.length() / 3 : 2;
     String prefix = key.substring(0, len);
     start = System.nanoTime();
     List<LookupResult> res = lookup.lookup(prefix, true, 10);
     elapsed += System.nanoTime() - start;
     assertTrue(res.size() > 0);
     for (LookupResult lr : res) {
       assertTrue(lr.key.startsWith(prefix));
     }
     if (ref != null) { // verify the counts
       Integer Cnt = ref.get(key);
       if (Cnt == null) { // first pass
         ref.put(key, res.size());
       } else {
         assertEquals(key + ", prefix: " + prefix, Cnt.intValue(), res.size());
       }
     }
   }
   if (estimate) {
     RamUsageEstimator rue = new RamUsageEstimator();
     long size = rue.estimateRamUsage(lookup);
     System.err.println(lookup.getClass().getSimpleName() + " - size=" + size);
   }
   if (bench != null) {
     bench.buildTime += buildTime;
     bench.lookupTime += elapsed;
   }
 }