Search in sources :

Example 6 with StatisticsFactory

use of org.apache.geode.StatisticsFactory 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);
        }
    }
}
Also used : OutOfOffHeapMemoryException(org.apache.geode.OutOfOffHeapMemoryException) LocalStatisticsFactory(org.apache.geode.internal.statistics.LocalStatisticsFactory) StatisticsFactory(org.apache.geode.StatisticsFactory) LocalStatisticsFactory(org.apache.geode.internal.statistics.LocalStatisticsFactory) Test(org.junit.Test) UnitTest(org.apache.geode.test.junit.categories.UnitTest)

Example 7 with StatisticsFactory

use of org.apache.geode.StatisticsFactory in project geode by apache.

the class DiskInitFileJUnitTest method testKrfIds.

@Test
public void testKrfIds() {
    // create a mock statistics factory for creating directory holders
    final StatisticsFactory sf = context.mock(StatisticsFactory.class);
    context.checking(new Expectations() {

        {
            ignoring(sf);
        }
    });
    // Add a mock region to the init file so it doesn't
    // delete the file when the init file is closed
    final DiskRegionView drv = context.mock(DiskRegionView.class);
    context.checking(new Expectations() {

        {
            ignoring(drv);
        }
    });
    // Create a mock disk store impl. All we need to do is return
    // this init file directory.
    final DiskStoreImpl parent = context.mock(DiskStoreImpl.class);
    context.checking(new Expectations() {

        {
            allowing(parent).getInfoFileDir();
            will(returnValue(new DirectoryHolder(sf, testDirectory, 0, 0)));
            ignoring(parent);
        }
    });
    DiskInitFile dif = new DiskInitFile("testKrfIds", parent, false, Collections.<File>emptySet());
    assertEquals(false, dif.hasKrf(1));
    dif.cmnKrfCreate(1);
    assertEquals(true, dif.hasKrf(1));
    assertEquals(false, dif.hasKrf(2));
    dif.cmnKrfCreate(2);
    assertEquals(true, dif.hasKrf(2));
    dif.createRegion(drv);
    dif.forceCompaction();
    dif.close();
    dif = new DiskInitFile("testKrfIds", parent, true, Collections.<File>emptySet());
    assertEquals(true, dif.hasKrf(1));
    assertEquals(true, dif.hasKrf(2));
    dif.cmnCrfDelete(1);
    assertEquals(false, dif.hasKrf(1));
    assertEquals(true, dif.hasKrf(2));
    dif.cmnCrfDelete(2);
    assertEquals(false, dif.hasKrf(2));
    dif.createRegion(drv);
    dif.forceCompaction();
    dif.close();
    dif = new DiskInitFile("testKrfIds", parent, true, Collections.<File>emptySet());
    assertEquals(false, dif.hasKrf(1));
    assertEquals(false, dif.hasKrf(2));
    dif.destroy();
}
Also used : Expectations(org.jmock.Expectations) StatisticsFactory(org.apache.geode.StatisticsFactory) File(java.io.File) DiskRegionView(org.apache.geode.internal.cache.persistence.DiskRegionView) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 8 with StatisticsFactory

use of org.apache.geode.StatisticsFactory in project geode by apache.

the class DLockService method getOrCreateStats.

/** Get or create static dlock stats */
protected static synchronized DistributedLockStats getOrCreateStats(DistributedSystem ds) {
    if (stats == DUMMY_STATS) {
        Assert.assertTrue(ds != null, "Need an instance of InternalDistributedSystem");
        StatisticsFactory statFactory = ds;
        long statId = OSProcess.getId();
        stats = new DLockStats(statFactory, statId);
    }
    return stats;
}
Also used : StatisticsFactory(org.apache.geode.StatisticsFactory)

Example 9 with StatisticsFactory

use of org.apache.geode.StatisticsFactory in project geode by apache.

the class DiskInitFileJUnitTest method testCanonicalIds.

/**
   * Test the behavior of canonical ids in the init file.
   */
@Test
public void testCanonicalIds() {
    // create a mock statistics factory for creating directory holders
    final StatisticsFactory sf = context.mock(StatisticsFactory.class);
    context.checking(new Expectations() {

        {
            ignoring(sf);
        }
    });
    // Create a mock disk store impl. All we need to do is return
    // this init file directory.
    final DiskStoreImpl parent = context.mock(DiskStoreImpl.class);
    context.checking(new Expectations() {

        {
            allowing(parent).getInfoFileDir();
            will(returnValue(new DirectoryHolder(sf, testDirectory, 0, 0)));
            ignoring(parent);
        }
    });
    // Create an init file and add some canonical ids
    DiskInitFile dif = new DiskInitFile("testFile", parent, false, Collections.<File>emptySet());
    assertEquals(null, dif.getCanonicalObject(5));
    assertNull(dif.getCanonicalObject(0));
    int id1 = dif.getOrCreateCanonicalId("object1");
    int id2 = dif.getOrCreateCanonicalId("object2");
    assertEquals("object1", dif.getCanonicalObject(id1));
    assertEquals("object2", dif.getCanonicalObject(id2));
    assertEquals(id2, dif.getOrCreateCanonicalId("object2"));
    // Add a mock region to the init file so it doesn't
    // delete the file when the init file is closed
    final DiskRegionView drv = context.mock(DiskRegionView.class);
    context.checking(new Expectations() {

        {
            ignoring(drv);
        }
    });
    dif.createRegion(drv);
    // close the init file
    dif.close();
    // recover the init file from disk
    dif = new DiskInitFile("testFile", parent, true, Collections.<File>emptySet());
    // make sure we can recover the ids from disk
    assertEquals("object1", dif.getCanonicalObject(id1));
    assertEquals("object2", dif.getCanonicalObject(id2));
    assertEquals(id2, dif.getOrCreateCanonicalId("object2"));
    // Make sure we can add new ids
    int id3 = dif.getOrCreateCanonicalId("object3");
    assertTrue(id3 > id2);
    assertEquals("object1", dif.getCanonicalObject(id1));
    assertEquals("object2", dif.getCanonicalObject(id2));
    assertEquals("object3", dif.getCanonicalObject(id3));
    dif.close();
}
Also used : Expectations(org.jmock.Expectations) StatisticsFactory(org.apache.geode.StatisticsFactory) File(java.io.File) DiskRegionView(org.apache.geode.internal.cache.persistence.DiskRegionView) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 10 with StatisticsFactory

use of org.apache.geode.StatisticsFactory 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();
}
Also used : InternalDistributedSystem(org.apache.geode.distributed.internal.InternalDistributedSystem) LocalStatisticsFactory(org.apache.geode.internal.statistics.LocalStatisticsFactory) StatisticsFactory(org.apache.geode.StatisticsFactory) LocalStatisticsFactory(org.apache.geode.internal.statistics.LocalStatisticsFactory) Test(org.junit.Test) UnitTest(org.apache.geode.test.junit.categories.UnitTest)

Aggregations

StatisticsFactory (org.apache.geode.StatisticsFactory)15 Test (org.junit.Test)8 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)6 File (java.io.File)3 DiskRegionView (org.apache.geode.internal.cache.persistence.DiskRegionView)3 Expectations (org.jmock.Expectations)3 Statistics (org.apache.geode.Statistics)2 StatisticsType (org.apache.geode.StatisticsType)2 LocalStatisticsFactory (org.apache.geode.internal.statistics.LocalStatisticsFactory)2 UnitTest (org.apache.geode.test.junit.categories.UnitTest)2 Before (org.junit.Before)2 HashMap (java.util.HashMap)1 OutOfOffHeapMemoryException (org.apache.geode.OutOfOffHeapMemoryException)1 StatisticDescriptor (org.apache.geode.StatisticDescriptor)1 Region (org.apache.geode.cache.Region)1 CqQueryVsdStats (org.apache.geode.cache.query.internal.CqQueryVsdStats)1 InternalDistributedSystem (org.apache.geode.distributed.internal.InternalDistributedSystem)1 LogWriterI18n (org.apache.geode.i18n.LogWriterI18n)1 BucketRegion (org.apache.geode.internal.cache.BucketRegion)1 OplogEntryIdSet (org.apache.geode.internal.cache.DiskStoreImpl.OplogEntryIdSet)1