示例#1
0
    public void testCacheSimpleReturn(String type) {

      int size = 100;
      // this test does not fill the cache
      Cache c1 = CacheManager.createCache(type, "c1", size);

      String k1 = "one";
      String k2 = k1;
      String k3 = k2;
      Integer v1 = new Integer(-1);
      Integer v2 = v1;
      Integer v3 = v2;
      c1.put(k1, v1);

      for (int i = 0; i < size; i++) {
        k1 = k2;
        v1 = v2;
        Object o = c1.get(k1);
        assertTrue("expected a hit", o != null);
        assertEquals("should be the expected object", o, v1);
        k2 = k3;
        v2 = v3;
        o = c1.get(k2);
        assertTrue("expected a hit", o != null);
        assertEquals("should be the expected object", o, v2);

        k3 = "T" + i;
        v3 = new Integer(i);
        c1.put(k3, v3);
      }
    }
示例#2
0
    public void testFillTheCache(String type) {
      final int size = 100;
      Cache c1 = CacheManager.createCache(type, "c1", size);
      String[] k = new String[size];
      String[] v = new String[size];

      for (int i = 0; i < size; i++) {
        k[i] = "K" + i;
        v[i] = "V" + i;
        c1.put(k[i], v[i]);
      }

      int count = 0;

      for (int i = 0; i < size; i++) {
        if (c1.get(k[i]) != null) {
          count++;
        }
      }

      assertTrue("too low a hit rate: " + type + " = " + count, count > size / 2);
      assertEquals("count puts", size, c1.getPuts());
      assertEquals("count gets", size, c1.getGets());
      assertEquals("count hits", count, c1.getHits());
    }