public static Set<JDOPersistenceManager> getJDOPersistenceManagerCache() {
    JDOPersistenceManagerFactory jdoPmf;
    Set<JDOPersistenceManager> pmCacheObj = null;
    Field pmCache;
    try {
      Field pmf = PersistenceManagerProvider.class.getDeclaredField("pmf");
      if (pmf != null) {
        pmf.setAccessible(true);
        jdoPmf = (JDOPersistenceManagerFactory) pmf.get(null);
        pmCache = JDOPersistenceManagerFactory.class.getDeclaredField("pmCache");
        if (pmCache != null) {
          pmCache.setAccessible(true);
          pmCacheObj = (Set<JDOPersistenceManager>) pmCache.get(jdoPmf);
          return pmCacheObj;
        }
      }
    } catch (Exception e) {
      throw new RuntimeException(e);
    }
    return pmCacheObj;
  }
This method checks if persistence manager cache is cleaned up properly under some circumstances.
There is a chance that cleanup process removes elements created not only by this test, so we don't check
exact equality, instead check that no new elements can be seen in the cache (so newSet.removeAll(oldSet) should be empty).
standalone-metastore/metastore-server/src/test/java/org/apache/hadoop/hive/metastore/TestHiveMetaStore.java