use of org.apache.geode.internal.statistics.LocalStatisticsFactory in project geode by apache.
the class OffHeapStorageJUnitTest method testCreateOffHeapStorage.
@Test
public void testCreateOffHeapStorage() {
StatisticsFactory localStatsFactory = new LocalStatisticsFactory(null);
OutOfOffHeapMemoryListener ooohml = mock(OutOfOffHeapMemoryListener.class);
MemoryAllocator ma = OffHeapStorage.basicCreateOffHeapStorage(localStatsFactory, 1024 * 1024, ooohml);
try {
OffHeapMemoryStats stats = ma.getStats();
assertNotNull(stats.getStats());
assertEquals(1024 * 1024, stats.getFreeMemory());
assertEquals(1024 * 1024, stats.getMaxMemory());
assertEquals(0, stats.getUsedMemory());
assertEquals(0, stats.getDefragmentations());
assertEquals(0, stats.getDefragmentationsInProgress());
assertEquals(0, stats.getDefragmentationTime());
assertEquals(0, stats.getFragmentation());
assertEquals(1, stats.getFragments());
assertEquals(1024 * 1024, stats.getLargestFragment());
assertEquals(0, stats.getObjects());
assertEquals(0, stats.getReads());
stats.incFreeMemory(100);
assertEquals(1024 * 1024 + 100, stats.getFreeMemory());
stats.incFreeMemory(-100);
assertEquals(1024 * 1024, stats.getFreeMemory());
stats.incMaxMemory(100);
assertEquals(1024 * 1024 + 100, stats.getMaxMemory());
stats.incMaxMemory(-100);
assertEquals(1024 * 1024, stats.getMaxMemory());
stats.incUsedMemory(100);
assertEquals(100, stats.getUsedMemory());
stats.incUsedMemory(-100);
assertEquals(0, stats.getUsedMemory());
stats.incObjects(100);
assertEquals(100, stats.getObjects());
stats.incObjects(-100);
assertEquals(0, stats.getObjects());
stats.incReads();
assertEquals(1, stats.getReads());
stats.setFragmentation(100);
assertEquals(100, stats.getFragmentation());
stats.setFragmentation(0);
assertEquals(0, stats.getFragmentation());
stats.setFragments(2);
assertEquals(2, stats.getFragments());
stats.setFragments(1);
assertEquals(1, stats.getFragments());
stats.setLargestFragment(100);
assertEquals(100, stats.getLargestFragment());
stats.setLargestFragment(1024 * 1024);
assertEquals(1024 * 1024, stats.getLargestFragment());
boolean originalEnableClockStats = DistributionStats.enableClockStats;
DistributionStats.enableClockStats = true;
try {
long start = stats.startDefragmentation();
assertEquals(1, stats.getDefragmentationsInProgress());
while (DistributionStats.getStatTime() == start) {
Thread.yield();
}
stats.endDefragmentation(start);
assertEquals(1, stats.getDefragmentations());
assertEquals(0, stats.getDefragmentationsInProgress());
assertTrue(stats.getDefragmentationTime() > 0);
} finally {
DistributionStats.enableClockStats = originalEnableClockStats;
}
stats.incObjects(100);
stats.incUsedMemory(100);
stats.setFragmentation(100);
OffHeapStorage ohs = (OffHeapStorage) stats;
ohs.initialize(new NullOffHeapMemoryStats());
assertEquals(0, stats.getFreeMemory());
assertEquals(0, stats.getMaxMemory());
assertEquals(0, stats.getUsedMemory());
assertEquals(0, stats.getDefragmentations());
assertEquals(0, stats.getDefragmentationsInProgress());
assertEquals(0, stats.getDefragmentationTime());
assertEquals(0, stats.getFragmentation());
assertEquals(0, stats.getFragments());
assertEquals(0, stats.getLargestFragment());
assertEquals(0, stats.getObjects());
assertEquals(0, stats.getReads());
OutOfOffHeapMemoryException ex = null;
try {
ma.allocate(1024 * 1024 + 1);
fail("expected OutOfOffHeapMemoryException");
} catch (OutOfOffHeapMemoryException expected) {
ex = expected;
}
verify(ooohml).outOfOffHeapMemory(ex);
try {
ma.allocate(1024 * 1024 + 1);
fail("expected OutOfOffHeapMemoryException");
} catch (OutOfOffHeapMemoryException expected) {
ex = expected;
}
verify(ooohml).outOfOffHeapMemory(ex);
} finally {
System.setProperty(MemoryAllocatorImpl.FREE_OFF_HEAP_MEMORY_PROPERTY, "true");
try {
ma.close();
} finally {
System.clearProperty(MemoryAllocatorImpl.FREE_OFF_HEAP_MEMORY_PROPERTY);
}
}
}
use of org.apache.geode.internal.statistics.LocalStatisticsFactory in project geode by apache.
the class OffHeapStorageJUnitTest method createOffHeapStorageWorks.
@Test
public void createOffHeapStorageWorks() {
StatisticsFactory localStatsFactory = new LocalStatisticsFactory(null);
InternalDistributedSystem ids = mock(InternalDistributedSystem.class);
MemoryAllocator ma = OffHeapStorage.createOffHeapStorage(localStatsFactory, OffHeapStorage.MIN_SLAB_SIZE, ids);
System.setProperty(MemoryAllocatorImpl.FREE_OFF_HEAP_MEMORY_PROPERTY, "true");
ma.close();
}
Aggregations