예제 #1
0
  private void doTestPercentageAutowarm(int limit, int percentage, int[] hits, int[] misses)
      throws IOException {
    FastLRUCache<Object, Object> fastCache = new FastLRUCache<Object, Object>();
    Map<String, String> params = new HashMap<String, String>();
    params.put("size", String.valueOf(limit));
    params.put("initialSize", "10");
    params.put("autowarmCount", percentage + "%");
    CacheRegenerator cr = createCodeRegenerator();
    Object o = fastCache.init(params, null, cr);
    fastCache.setState(SolrCache.State.LIVE);
    for (int i = 1; i <= limit; i++) {
      fastCache.put(i, "" + i); // adds numbers from 1 to 100
    }

    FastLRUCache<Object, Object> fastCacheNew = new FastLRUCache<Object, Object>();
    fastCacheNew.init(params, o, cr);
    fastCacheNew.warm(null, fastCache);
    fastCacheNew.setState(SolrCache.State.LIVE);
    fastCache.close();

    for (int hit : hits) {
      assertEquals(
          "The value " + hit + " should be on new cache",
          String.valueOf(hit),
          fastCacheNew.get(hit));
    }

    for (int miss : misses) {
      assertEquals(
          "The value " + miss + " should NOT be on new cache", null, fastCacheNew.get(miss));
    }
    NamedList<Serializable> nl = fastCacheNew.getStatistics();
    assertEquals(Long.valueOf(hits.length + misses.length), nl.get("lookups"));
    assertEquals(Long.valueOf(hits.length), nl.get("hits"));
    fastCacheNew.close();
  }
예제 #2
0
  public void testSimple() throws IOException {
    FastLRUCache sc = new FastLRUCache();
    Map l = new HashMap();
    l.put("size", "100");
    l.put("initialSize", "10");
    l.put("autowarmCount", "25");
    CacheRegenerator cr = createCodeRegenerator();
    Object o = sc.init(l, null, cr);
    sc.setState(SolrCache.State.LIVE);
    for (int i = 0; i < 101; i++) {
      sc.put(i + 1, "" + (i + 1));
    }
    assertEquals("25", sc.get(25));
    assertEquals(null, sc.get(110));
    NamedList nl = sc.getStatistics();
    assertEquals(2L, nl.get("lookups"));
    assertEquals(1L, nl.get("hits"));
    assertEquals(101L, nl.get("inserts"));

    assertEquals(null, sc.get(1)); // first item put in should be the first out

    FastLRUCache scNew = new FastLRUCache();
    scNew.init(l, o, cr);
    scNew.warm(null, sc);
    scNew.setState(SolrCache.State.LIVE);
    sc.close();
    scNew.put(103, "103");
    assertEquals("90", scNew.get(90));
    assertEquals(null, scNew.get(50));
    nl = scNew.getStatistics();
    assertEquals(2L, nl.get("lookups"));
    assertEquals(1L, nl.get("hits"));
    assertEquals(1L, nl.get("inserts"));
    assertEquals(0L, nl.get("evictions"));

    assertEquals(5L, nl.get("cumulative_lookups"));
    assertEquals(2L, nl.get("cumulative_hits"));
    assertEquals(102L, nl.get("cumulative_inserts"));
    scNew.close();
  }
예제 #3
0
 public void testPercentageAutowarm() throws IOException {
   FastLRUCache<Object, Object> fastCache = new FastLRUCache<Object, Object>();
   Map<String, String> params = new HashMap<String, String>();
   params.put("size", "100");
   params.put("initialSize", "10");
   params.put("autowarmCount", "100%");
   CacheRegenerator cr = createCodeRegenerator();
   Object o = fastCache.init(params, null, cr);
   fastCache.setState(SolrCache.State.LIVE);
   for (int i = 0; i < 101; i++) {
     fastCache.put(i + 1, "" + (i + 1));
   }
   assertEquals("25", fastCache.get(25));
   assertEquals(null, fastCache.get(110));
   NamedList<Serializable> nl = fastCache.getStatistics();
   assertEquals(2L, nl.get("lookups"));
   assertEquals(1L, nl.get("hits"));
   assertEquals(101L, nl.get("inserts"));
   assertEquals(null, fastCache.get(1)); // first item put in should be the first out
   FastLRUCache<Object, Object> fastCacheNew = new FastLRUCache<Object, Object>();
   fastCacheNew.init(params, o, cr);
   fastCacheNew.warm(null, fastCache);
   fastCacheNew.setState(SolrCache.State.LIVE);
   fastCache.close();
   fastCacheNew.put(103, "103");
   assertEquals("90", fastCacheNew.get(90));
   assertEquals("50", fastCacheNew.get(50));
   nl = fastCacheNew.getStatistics();
   assertEquals(2L, nl.get("lookups"));
   assertEquals(2L, nl.get("hits"));
   assertEquals(1L, nl.get("inserts"));
   assertEquals(0L, nl.get("evictions"));
   assertEquals(5L, nl.get("cumulative_lookups"));
   assertEquals(3L, nl.get("cumulative_hits"));
   assertEquals(102L, nl.get("cumulative_inserts"));
   fastCacheNew.close();
 }
예제 #4
0
  public void testFullAutowarm() throws IOException {
    FastLRUCache<Object, Object> cache = new FastLRUCache<Object, Object>();
    Map<Object, Object> params = new HashMap<Object, Object>();
    params.put("size", "100");
    params.put("initialSize", "10");
    params.put("autowarmCount", "-1");
    CacheRegenerator cr = createCodeRegenerator();
    Object o = cache.init(params, null, cr);
    cache.setState(SolrCache.State.LIVE);
    for (int i = 0; i < 101; i++) {
      cache.put(i + 1, "" + (i + 1));
    }
    assertEquals("25", cache.get(25));
    assertEquals(null, cache.get(110));

    assertEquals(null, cache.get(1)); // first item put in should be the first out

    FastLRUCache<Object, Object> cacheNew = new FastLRUCache<Object, Object>();
    cacheNew.init(params, o, cr);
    cacheNew.warm(null, cache);
    cacheNew.setState(SolrCache.State.LIVE);
    cache.close();
    cacheNew.put(103, "103");
    assertEquals("90", cacheNew.get(90));
    assertEquals("50", cacheNew.get(50));
    assertEquals("103", cacheNew.get(103));
    cacheNew.close();
  }