GlobalCachingMemoryManager { public long calculateMemorySize() { long total = 0; for(CacheRegion<? extends Comparable, ?> region: regionMap.values()) { total += region.memorySize(); } return total; } GlobalCachingMemoryManager(); static GlobalCachingMemoryManager getGlobalInstance(); void configure(Configuration configuration); static void shutdown(); void checkMemoryState(Set<CacheRegion> ignoreRegions); void registerRegion(CacheRegion<T, ? extends CacheEntry> region); long calculateMemorySize(); void unregisterRegion(String name); List<CacheRegion> getRegions();  }
@Test public void testCalculateMemorySize() { GlobalCachingMemoryManager globalCachingMemoryManager = GlobalCachingMemoryManager.getGlobalInstance(); try { assertThat(globalCachingMemoryManager.calculateMemorySize(), is(0l)); CacheRegion<Long, CacheEntry<Long>> region1 = mock(CacheRegion.class); CacheRegion<Long, CacheEntry<Long>> region2 = mock(CacheRegion.class); CacheRegion<Long, CacheEntry<Long>> region3 = mock(CacheRegion.class); when(region1.name()).thenReturn("region1"); when(region1.memorySize()).thenReturn(5000l); when(region2.memorySize()).thenReturn(10000l); when(region2.name()).thenReturn("region2"); when(region3.memorySize()).thenReturn(20000l); when(region3.name()).thenReturn("region3"); globalCachingMemoryManager.registerRegion(region1); assertThat(globalCachingMemoryManager.calculateMemorySize(), is(5000l)); globalCachingMemoryManager.registerRegion(region2); globalCachingMemoryManager.registerRegion(region3); assertThat(globalCachingMemoryManager.calculateMemorySize(), is(35000l)); } finally { GlobalCachingMemoryManager.shutdown(); } }