Ejemplo 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);
      }
    }
  protected void setUp() throws Exception {
    CacheUtils.startCache();
    cache = CacheUtils.getCache();
    AttributesFactory attributesFactory = new AttributesFactory();
    //    attributesFactory.setValueConstraint(Portfolio.class);
    RegionAttributes regionAttributes = attributesFactory.create();

    region = cache.createRegion("pos", regionAttributes);
    region.put("0", new Portfolio(0));
    region.put("1", new Portfolio(1));
    region.put("2", new Portfolio(2));
    region.put("3", new Portfolio(3));

    qs = cache.getQueryService();
  }
Ejemplo 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());
    }