Esempio n. 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);
      }
    }
Esempio n. 2
0
  /**
   * Answer an enhanced node that wraps the given node and conforms to the given interface type.
   *
   * @param n A node (assumed to be in this graph)
   * @param interf A type denoting the enhanced facet desired
   * @return An enhanced node
   */
  public EnhNode getNodeAs(Node n, Class interf) {
    // We use a cache to avoid reconstructing the same Node too many times.
    EnhNode eh = (EnhNode) enhNodes.get(n);
    if (eh != null) return eh.viewAs(interf);

    // not in the cache, so build a new one
    eh = (EnhNode) ((GraphPersonality) personality).nodePersonality().newInstance(interf, n, this);
    enhNodes.put(n, eh);
    return eh;
  }
Esempio n. 3
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());
    }