Ejemplo n.º 1
0
    private void clear(Clearable c) {
      if (c instanceof Map) {
        Map m = (Map) c;
        for (Iterator i = m.values().iterator(); i.hasNext(); ) {
          ((Manageable) i.next()).__tc_managed().clearAccessed();
        }

        int numToClear = m.size();
        int cleared = c.__tc_clearReferences(numToClear);
        Assert.assertEquals(c.getClass(), numToClear, cleared);
      } else {
        throw new RuntimeException("no clear support for " + c.getClass());
      }
    }
Ejemplo n.º 2
0
    private void validateCleared(Clearable c) {
      if (c instanceof TCMap) {
        Collection local = ((TCMap) c).__tc_getAllLocalEntriesSnapshot();
        Assert.assertEquals(c.getClass(), 0, local.size());

        for (Iterator i = ((Map) c).entrySet().iterator(); i.hasNext(); ) {
          Map.Entry entry = (Entry) i.next();
          Key k = (Key) entry.getKey();
          Value v = (Value) entry.getValue();
          Assert.assertEquals(k.getI(), v.getI());
        }

      } else {
        throw new RuntimeException("no validateCleared support for " + c.getClass());
      }
    }
Ejemplo n.º 3
0
    protected void runTest() throws Throwable {
      add(new HashMap());
      add(new Hashtable());

      for (Iterator i = clearables.iterator(); i.hasNext(); ) {
        Clearable c = (Clearable) i.next();

        // At the time this test was written, all Clearable types should have eviction enabled by
        // default
        // (ie. one should not need to manually enable eviction)
        if (!c.isEvictionEnabled()) {
          throw new RuntimeException(c.getClass() + " does not have eviction enabled");
        }

        populate(c);
        clear(c);
        validateCleared(c);
      }
    }