Exemplo n.º 1
0
 private static void removeInMemoryData(Cache cache) {
   EmbeddedCacheManager mgr = cache.getCacheManager();
   Address a = mgr.getAddress();
   String str;
   if (a == null) str = "a non-clustered cache manager";
   else str = "a cache manager at address " + a;
   log.debugf("Cleaning data for cache '%s' on %s", cache.getName(), str);
   DataContainer dataContainer = TestingUtil.extractComponent(cache, DataContainer.class);
   log.debugf("removeInMemoryData(): dataContainerBefore == %s", dataContainer.entrySet());
   dataContainer.clear();
   log.debugf("removeInMemoryData(): dataContainerAfter == %s", dataContainer.entrySet());
 }
 private void commitClearCommand(
     DataContainer<Object, Object> dataContainer,
     ClearCacheEntry<Object, Object> cacheEntry,
     InvocationContext context,
     FlagAffectedCommand command) {
   List<InternalCacheEntry<Object, Object>> copyEntries =
       new ArrayList<>(dataContainer.entrySet());
   cacheEntry.commit(dataContainer, null);
   for (InternalCacheEntry entry : copyEntries) {
     notifier.notifyCacheEntryRemoved(
         entry.getKey(), entry.getValue(), entry.getMetadata(), false, context, command);
   }
 }
  public void testEntrySetWithEvictedEntriesAndFlags() {
    final int numKeys = 300;
    for (int i = 0; i < numKeys; i++) {
      cache.put(i, i);
    }

    AdvancedCache<Object, Object> flagCache =
        cache.getAdvancedCache().withFlags(Flag.SKIP_CACHE_LOAD);
    DataContainer dc = flagCache.getDataContainer();
    assertFalse("Data Container should not have all keys", numKeys == dc.size());
    Set<Map.Entry<Object, Object>> entrySet = flagCache.entrySet();
    assertEquals(dc.size(), entrySet.size());

    Set<InternalCacheEntry> entries = dc.entrySet();
    Map<Object, Object> map = new HashMap<Object, Object>(entrySet.size());
    for (Map.Entry<Object, Object> entry : entrySet) {
      map.put(entry.getKey(), entry.getValue());
    }

    for (InternalCacheEntry entry : entries) {
      assertEquals("Key/Value mismatch!", entry.getValue(), map.get(entry.getKey()));
    }
  }