@Override public void run() { addOffHeapNotificationListener(); } });
@Override public void run() { assertCompactionTimeStat(compactionTime, op); } });
@Override public void run() { assertFragmentationStat(fragmentation,op); } });
setSystemPropertiesOnVm(vm, true, getSystemProperties()); assertNotNull(createOffHeapRegionOnVm(vm,OFF_HEAP_REGION_NAME,DataPolicy.REPLICATE)); assertOffHeapRegionAttributesOnVm(vm); assertOffHeapMetricsOnVm(vm, TOTAL_MEMORY, 0, 0, 0); setupOffHeapMonitorOnVm(vm,"OffHeapFreeMemory",TOTAL_MEMORY,TOTAL_MEMORY,false); clearNotificationListenerOnVm(vm); doPutOnVm(vm, KEY, VALUE, OFF_HEAP_REGION_NAME, false); waitForNotificationListenerOnVm(vm, 5000, 500, true); doCleanupOnVm(vm);
setSystemPropertiesOnVm(vm, true, getSystemProperties()); assertNotNull(createOffHeapRegionOnVm(vm,OFF_HEAP_REGION_NAME,DataPolicy.REPLICATE)); assertOffHeapRegionAttributesOnVm(vm); assertOffHeapMetricsOnVm(vm, TOTAL_MEMORY, 0, 0, 0); doPutOnVm(vm, KEY, VALUE, OFF_HEAP_REGION_NAME, false); assertOffHeapMetricsOnVm(vm, (TOTAL_MEMORY - OBJECT_SIZE), OBJECT_SIZE, 1, 0); doPutOnVm(vm, KEY2, VALUE, OFF_HEAP_REGION_NAME, false); assertOffHeapMetricsOnVm(vm, (TOTAL_MEMORY - (2 * OBJECT_SIZE)), (2 * OBJECT_SIZE), 2, 0); doPutOnVm(vm, KEY3, VALUE, OFF_HEAP_REGION_NAME, false); assertOffHeapMetricsOnVm(vm, (TOTAL_MEMORY - (3 * OBJECT_SIZE)), (3 * OBJECT_SIZE), 3, 0); doDestroyOnVm(vm, KEY3, OFF_HEAP_REGION_NAME); assertOffHeapMetricsOnVm(vm, (TOTAL_MEMORY - (2 * OBJECT_SIZE)), (2 * OBJECT_SIZE), 2, 0); doDestroyOnVm(vm, KEY2, OFF_HEAP_REGION_NAME); assertOffHeapMetricsOnVm(vm, (TOTAL_MEMORY - OBJECT_SIZE), OBJECT_SIZE, 1, 0); doDestroyOnVm(vm, KEY, OFF_HEAP_REGION_NAME); assertOffHeapMetricsOnVm(vm, TOTAL_MEMORY, 0, 0, 0); doCleanupOnVm(vm);
setSystemPropertiesOnVm(vm, true, getSystemProperties()); assertNotNull(createOffHeapRegionOnVm(vm,OFF_HEAP_REGION_NAME,DataPolicy.REPLICATE)); vm.invoke(new SerializableRunnable() { @Override assertOffHeapRegionAttributesOnVm(vm); assertOffHeapMetricsOnVm(vm, TOTAL_MEMORY, 0, 0, 0); doPutOnVm(vm, KEY, new byte[HALF_TOTAL_MEMORY], OFF_HEAP_REGION_NAME, false); assertFragmentationStatOnVm(vm,0,ASSERT_OP.EQUAL); doDestroyOnVm(vm, KEY, OFF_HEAP_REGION_NAME); assertFragmentationStatOnVm(vm,0,ASSERT_OP.EQUAL); int numAllocations = doConsumeOffHeapMemoryOnVm(vm,ALLOCATION_SIZE); assertTrue(numAllocations > 0); doFreeOffHeapMemoryOnVm(vm, numAllocations, 3); setupOffHeapMonitorOnVm(vm,"OffHeapFragmentation",0,0,false); clearNotificationListenerOnVm(vm); doPutOnVm(vm,KEY, new byte[NEW_ALLOCATION_SIZE], OFF_HEAP_REGION_NAME, true); assertFragmentationStatOnVm(vm, 0, ASSERT_OP.GREATER_THAN); waitForNotificationListenerOnVm(vm, 5000, 500, true);
/** * Asserts that OffHeapMetrics match input parameters. * @param freeMemory total off-heap free memory in bytes. * @param allocatedMemory allocated (or used) off-heap memory in bytes. * @param objects number of objects stored in off-heap memory. * @param fragmentation the fragmentation percentage. */ protected void assertOffHeapMetrics(long freeMemory,long allocatedMemory,long objects, int fragmentation) { ManagementService service = ManagementService.getExistingManagementService(getCache()); assertNotNull(service); assertTrue(service.isManager()); MemberMXBean memberBean = service.getMemberMXBean(); assertNotNull(memberBean); assertEquals(freeMemory,memberBean.getOffHeapFreeMemory()); assertEquals(allocatedMemory,memberBean.getOffHeapUsedMemory()); assertEquals(objects,memberBean.getOffHeapObjects()); assertEquals(fragmentation,memberBean.getOffHeapFragmentation()); }
/** * Adds an off-heap notification listener to the MemberMXBean. */ protected void addOffHeapNotificationListener() { ManagementService service = ManagementService.getExistingManagementService(getCache()); assertNotNull(service); assertTrue(service.isManager()); MemberMXBean memberBean = service.getMemberMXBean(); assertNotNull(memberBean); assertTrue(memberBean instanceof MemberMBean); ((MemberMBean) memberBean).addNotificationListener(notificationListener, null, null); }
/** * Performs a destroy operation. * @param key the region entry to destroy. * @param regionName a region name. */ protected void doDestroy(Object key, String regionName) { Region region = getCache().getRegion(regionName); assertNotNull(region); region.destroy(key); }
assertNotNull(objectName); } catch (Exception e) { e.printStackTrace(); fail(e.getMessage());
@Override public void run() { assertOffHeapMetrics(freeMemory, allocatedMemory, objects, fragmentation); } });
@Override public void run() { assertOffHeapRegionAttributes(); } });
setSystemPropertiesOnVm(vm, true, getSystemProperties()); assertNotNull(createOffHeapRegionOnVm(vm,OFF_HEAP_REGION_NAME,DataPolicy.REPLICATE)); assertOffHeapRegionAttributesOnVm(vm); assertOffHeapMetricsOnVm(vm, TOTAL_MEMORY, 0, 0, 0); setupOffHeapMonitorOnVm(vm,"OffHeapObjects",0,-1,false); clearNotificationListenerOnVm(vm); doPutOnVm(vm, KEY, VALUE, OFF_HEAP_REGION_NAME, false); waitForNotificationListenerOnVm(vm, 5000, 500, true); doCleanupOnVm(vm);
setSystemPropertiesOnVm(vm, true, getSystemProperties()); assertNotNull(createOffHeapRegionOnVm(vm,OFF_HEAP_REGION_NAME,DataPolicy.REPLICATE)); assertOffHeapRegionAttributesOnVm(vm); assertOffHeapMetricsOnVm(vm, TOTAL_MEMORY, 0, 0, 0); doPutOnVm(vm, KEY, new byte[HALF_TOTAL_MEMORY], OFF_HEAP_REGION_NAME, false); assertCompactionTimeStatOnVm(vm,0,ASSERT_OP.EQUAL); doDestroyOnVm(vm, KEY, OFF_HEAP_REGION_NAME); assertCompactionTimeStatOnVm(vm,0,ASSERT_OP.EQUAL); int numAllocations = doConsumeOffHeapMemoryOnVm(vm,ALLOCATION_SIZE); assertTrue(numAllocations > 0); doFreeOffHeapMemoryOnVm(vm, numAllocations, 3); setupOffHeapMonitorOnVm(vm,"OffHeapCompactionTime",0,0,false); clearNotificationListenerOnVm(vm); doPutOnVm(vm,KEY, new byte[NEW_ALLOCATION_SIZE], OFF_HEAP_REGION_NAME, true); waitForNotificationListenerOnVm(vm, 5000, 500, true); assertCompactionTimeStatOnVm(vm, 0, ASSERT_OP.GREATER_THAN_OR_EQUAL); } finally { doCleanupOnVm(vm);
/** * Asserts that the compactionTime stat is available and satisfies an assert operation. * @param compactionTime total off heap compaction time. * @param op an assert operation. */ protected void assertCompactionTimeStat(long compactionTime,ASSERT_OP op) { ManagementService service = ManagementService.getExistingManagementService(getCache()); assertNotNull(service); assertTrue(service.isManager()); MemberMXBean memberBean = service.getMemberMXBean(); assertNotNull(memberBean); switch(op) { case EQUAL: assertEquals(compactionTime,memberBean.getOffHeapCompactionTime()); break; case GREATER_THAN: assertTrue(compactionTime < memberBean.getOffHeapCompactionTime()); break; case GREATER_THAN_OR_EQUAL: assertTrue(compactionTime <= memberBean.getOffHeapCompactionTime()); break; case LESS_THAN: assertTrue(compactionTime > memberBean.getOffHeapCompactionTime()); break; } }
/** * Asserts that the off heap region data is available and enabled. */ protected void assertOffHeapRegionAttributes() { ManagementService service = ManagementService.getExistingManagementService(getCache()); assertNotNull(service); assertTrue(service.isManager()); RegionMXBean regionBean = service.getLocalRegionMBean(OFF_HEAP_REGION_PATH); assertNotNull(regionBean); RegionAttributesData regionData = regionBean.listRegionAttributes(); assertNotNull(regionData); assertTrue(regionData.getEnableOffHeapMemory()); }
/** * Performs a put operation. * @param key region entry key. * @param value region entry value. * @param regionName a region name. */ protected void doPut(Object key, Object value, String regionName,boolean expectException) { Region region = getCache().getRegion(regionName); assertNotNull(region); try { region.put(key, value); } catch (OutOfOffHeapMemoryException e) { if(!expectException) throw e; } }
setSystemPropertiesOnVm(vm, true, getSystemProperties()); assertNotNull(createOffHeapRegionOnVm(vm,OFF_HEAP_REGION_NAME,DataPolicy.REPLICATE)); assertOffHeapRegionAttributesOnVm(vm); assertOffHeapMetricsOnVm(vm, TOTAL_MEMORY, 0, 0, 0); setupOffHeapMonitorOnVm(vm,"OffHeapUsedMemory",0,OBJECT_SIZE,false); clearNotificationListenerOnVm(vm); doPutOnVm(vm, KEY, VALUE, OFF_HEAP_REGION_NAME, false); waitForNotificationListenerOnVm(vm, 5000, 500, true); doCleanupOnVm(vm);
/** * Asserts that the fragmentation stat is available and satisfies an assert operation. * @param fragmentation a fragmentation percentage * @param op an assertion operation */ protected void assertFragmentationStat(int fragmentation,ASSERT_OP op) { ManagementService service = ManagementService.getExistingManagementService(getCache()); assertNotNull(service); assertTrue(service.isManager()); MemberMXBean memberBean = service.getMemberMXBean(); assertNotNull(memberBean); switch(op) { case EQUAL: assertEquals(fragmentation,memberBean.getOffHeapFragmentation()); break; case GREATER_THAN: assertTrue(fragmentation < memberBean.getOffHeapFragmentation()); break; case LESS_THAN: assertTrue(fragmentation > memberBean.getOffHeapFragmentation()); break; } }
/** * Performs some destroys to free off-heap allocations. * @param numAllocations the number of previous off-heap allocations * @param numDestroys the number of destroys to perform */ protected void doFreeOffHeapMemory(int numAllocations,int numDestroys) { assertTrue(numDestroys <= numAllocations); Region region = getCache().getRegion(OFF_HEAP_REGION_NAME); assertNotNull(region); assertTrue(numDestroys <= region.size()); String key = "KEY0"; Object value = key; int destroyed = 0; while(destroyed < numDestroys) { key = "KEY" + ((int) (Math.random() * numAllocations)); value = region.get(key); if(null != value) { region.destroy(key); ++destroyed; } } }