Search in sources :

Example 26 with StatisticsType

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

the class StatArchiveWithConsecutiveResourceInstGenerator method generateStatArchiveFile.

@Test
public void generateStatArchiveFile() throws Exception {
    long sampleTimeNanos = WRITER_PREVIOUS_TIMESTAMP_NANOS + NANOS_PER_MILLI * 1000;
    // 1) create statistics
    StatisticsType type = createStatisticsType(STATS_TYPE_NAME, "description of " + STATS_TYPE_NAME);
    Statistics statistics1 = createStatistics(type, STATS_TYPE_NAME + "1", 1);
    for (int i = 0; i < 100; i++) {
        incInt(statistics1, "stat", 1);
        this.sampleCollector.sample(sampleTimeNanos += (1000 * NANOS_PER_MILLI));
    }
    // 3) close statistics
    statistics1.close();
    // 4) recreate statistics
    Statistics statistics2 = createStatistics(type, STATS_TYPE_NAME + "1", 1);
    for (int i = 0; i < 100; i++) {
        incInt(statistics2, "stat", 1);
        this.sampleCollector.sample(sampleTimeNanos += (1000 * NANOS_PER_MILLI));
    }
    // close the writer
    this.writer.close();
    // validate that stat archive file exists
    File actual = new File(this.archiveFileName);
    assertTrue(actual.exists());
    // validate content of stat archive file using StatArchiveReader
    StatArchiveReader reader = new StatArchiveReader(new File[] { actual }, null, false);
    for (final Iterator iter = reader.getResourceInstList().iterator(); iter.hasNext(); ) {
        StatArchiveReader.ResourceInst ri = (StatArchiveReader.ResourceInst) iter.next();
        String resourceName = ri.getName();
        assertNotNull(resourceName);
        String expectedStatsType = this.statisticTypes.get(resourceName);
        assertNotNull(expectedStatsType);
        assertEquals(expectedStatsType, ri.getType().getName());
        Map<String, Number> expectedStatValues = this.allStatistics.get(resourceName);
        assertNotNull(expectedStatValues);
        StatValue[] statValues = ri.getStatValues();
        for (int i = 0; i < statValues.length; i++) {
            final String statName = ri.getType().getStats()[i].getName();
            assertNotNull(statName);
            assertNotNull(expectedStatValues.get(statName));
            assertEquals(statName, statValues[i].getDescriptor().getName());
            statValues[i].setFilter(StatValue.FILTER_NONE);
            double[] rawSnapshots = statValues[i].getRawSnapshots();
            assertEquals("Value " + i + " for " + statName + " is wrong: " + expectedStatValues, expectedStatValues.get(statName).doubleValue(), statValues[i].getSnapshotsMostRecent(), 0.01);
        }
    }
    validateArchiveFile();
}
Also used : StatisticsType(org.apache.geode.StatisticsType) ResourceInst(org.apache.geode.internal.statistics.StatArchiveReader.ResourceInst) ResourceInst(org.apache.geode.internal.statistics.StatArchiveReader.ResourceInst) Statistics(org.apache.geode.Statistics) StatValue(org.apache.geode.internal.statistics.StatArchiveReader.StatValue) Iterator(java.util.Iterator) File(java.io.File) Test(org.junit.Test)

Example 27 with StatisticsType

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

the class SampleCollectorTest method testAddHandlerBeforeSample.

@Test
public void testAddHandlerBeforeSample() {
    TestSampleHandler handler = new TestSampleHandler();
    this.sampleCollector.addSampleHandler(handler);
    StatisticDescriptor[] statsST1 = new StatisticDescriptor[] { manager.createIntCounter("ST1_1_name", "ST1_1_desc", "ST1_1_units") };
    StatisticsType ST1 = manager.createType("ST1_name", "ST1_desc", statsST1);
    Statistics st1_1 = manager.createAtomicStatistics(ST1, "st1_1_text", 1);
    this.sampleCollector.sample(NanoTimer.getTime());
    assertEquals(3, handler.getNotificationCount());
    List<Info> notifications = handler.getNotifications();
    // validate the allocatedResourceType notification
    assertTrue(notifications.get(0) instanceof ResourceTypeInfo);
    ResourceTypeInfo allocatedResourceTypeInfo = (ResourceTypeInfo) notifications.get(0);
    assertNotNull(allocatedResourceTypeInfo);
    assertEquals("allocatedResourceType", allocatedResourceTypeInfo.getName());
    ResourceType resourceType = allocatedResourceTypeInfo.getResourceType();
    assertNotNull(resourceType);
    assertEquals(0, resourceType.getId());
    assertEquals(1, resourceType.getStatisticDescriptors().length);
    StatisticsType statisticsType = resourceType.getStatisticsType();
    assertNotNull(statisticsType);
    assertTrue(statisticsType == ST1);
    assertEquals("ST1_name", statisticsType.getName());
    assertEquals("ST1_desc", statisticsType.getDescription());
    assertEquals(1, statisticsType.getStatistics().length);
    // validate the allocatedResourceInstance notification
    assertTrue(notifications.get(1) instanceof ResourceInstanceInfo);
    ResourceInstanceInfo allocatedResourceInstanceInfo = (ResourceInstanceInfo) notifications.get(1);
    assertNotNull(allocatedResourceInstanceInfo);
    assertEquals("allocatedResourceInstance", allocatedResourceInstanceInfo.getName());
    ResourceInstance resourceInstance = allocatedResourceInstanceInfo.getResourceInstance();
    assertNotNull(resourceInstance);
    assertEquals(0, resourceInstance.getId());
    assertEquals(1, resourceInstance.getUpdatedStats().length);
    // TODO: is this correct?
    assertEquals(1, resourceInstance.getLatestStatValues().length);
    Statistics statistics = resourceInstance.getStatistics();
    assertNotNull(statistics);
    assertTrue(statistics == st1_1);
    assertEquals(1, statistics.getUniqueId());
    assertEquals(1, statistics.getNumericId());
    assertEquals("st1_1_text", statistics.getTextId());
    assertEquals("ST1_name", statistics.getType().getName());
    assertTrue(resourceType == resourceInstance.getResourceType());
    // validate the sampled notification
    assertTrue(notifications.get(2) instanceof SampledInfo);
    SampledInfo sampledInfo = (SampledInfo) notifications.get(2);
    assertNotNull(sampledInfo);
    assertEquals("sampled", sampledInfo.getName());
    assertEquals(1, sampledInfo.getResourceCount());
}
Also used : ResourceInstanceInfo(org.apache.geode.internal.statistics.TestSampleHandler.ResourceInstanceInfo) StatisticsType(org.apache.geode.StatisticsType) SampledInfo(org.apache.geode.internal.statistics.TestSampleHandler.SampledInfo) ResourceTypeInfo(org.apache.geode.internal.statistics.TestSampleHandler.ResourceTypeInfo) Info(org.apache.geode.internal.statistics.TestSampleHandler.Info) ResourceInstanceInfo(org.apache.geode.internal.statistics.TestSampleHandler.ResourceInstanceInfo) SampledInfo(org.apache.geode.internal.statistics.TestSampleHandler.SampledInfo) ResourceTypeInfo(org.apache.geode.internal.statistics.TestSampleHandler.ResourceTypeInfo) Statistics(org.apache.geode.Statistics) StatisticDescriptor(org.apache.geode.StatisticDescriptor) Test(org.junit.Test) UnitTest(org.apache.geode.test.junit.categories.UnitTest)

Example 28 with StatisticsType

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

the class SampleCollectorTest method testAddHandlerAfterSamples.

@Test
public void testAddHandlerAfterSamples() {
    StatisticDescriptor[] statsST1 = new StatisticDescriptor[] { manager.createIntCounter("ST1_1_name", "ST1_1_desc", "ST1_1_units") };
    StatisticsType ST1 = manager.createType("ST1_name", "ST1_desc", statsST1);
    Statistics st1_1 = manager.createAtomicStatistics(ST1, "st1_1_text", 1);
    Statistics st1_2 = manager.createAtomicStatistics(ST1, "st1_2_text", 1);
    StatisticDescriptor[] statsST2 = new StatisticDescriptor[] { manager.createIntCounter("ST2_1_name", "ST2_1_desc", "ST2_1_units") };
    StatisticsType ST2 = manager.createType("ST2_name", "ST2_desc", statsST2);
    Statistics st2_1 = manager.createAtomicStatistics(ST2, "st2_1_text", 1);
    st1_1.incInt("ST1_1_name", 1);
    st1_2.incInt("ST1_1_name", 1);
    st2_1.incInt("ST2_1_name", 1);
    long sampleTime = NanoTimer.getTime();
    this.sampleCollector.sample(sampleTime);
    st1_1.incInt("ST1_1_name", 2);
    st2_1.incInt("ST2_1_name", 1);
    sampleTime += NanoTimer.millisToNanos(1000);
    this.sampleCollector.sample(sampleTime);
    st1_1.incInt("ST1_1_name", 1);
    st1_1.incInt("ST1_1_name", 2);
    sampleTime += NanoTimer.millisToNanos(1000);
    this.sampleCollector.sample(sampleTime);
    TestSampleHandler handler = new TestSampleHandler();
    this.sampleCollector.addSampleHandler(handler);
    assertEquals("TestSampleHandler = " + handler, 0, handler.getNotificationCount());
    st1_2.incInt("ST1_1_name", 1);
    st2_1.incInt("ST2_1_name", 1);
    sampleTime += NanoTimer.millisToNanos(1000);
    this.sampleCollector.sample(sampleTime);
    assertEquals(6, handler.getNotificationCount());
    List<Info> notifications = handler.getNotifications();
    // validate the allocatedResourceType notification for ST1
    int notificationIdx = 0;
    assertTrue(notifications.get(notificationIdx) instanceof ResourceTypeInfo);
    ResourceTypeInfo allocatedResourceTypeInfo = (ResourceTypeInfo) notifications.get(notificationIdx);
    assertNotNull(allocatedResourceTypeInfo);
    assertEquals("allocatedResourceType", allocatedResourceTypeInfo.getName());
    ResourceType resourceType = allocatedResourceTypeInfo.getResourceType();
    assertNotNull(resourceType);
    assertEquals(0, resourceType.getId());
    assertEquals(1, resourceType.getStatisticDescriptors().length);
    StatisticsType statisticsType = resourceType.getStatisticsType();
    assertNotNull(statisticsType);
    assertTrue(statisticsType == ST1);
    assertEquals("ST1_name", statisticsType.getName());
    assertEquals("ST1_desc", statisticsType.getDescription());
    assertEquals(1, statisticsType.getStatistics().length);
    // validate the allocatedResourceInstance notification for st1_1
    notificationIdx++;
    assertTrue(notifications.get(notificationIdx) instanceof ResourceInstanceInfo);
    ResourceInstanceInfo allocatedResourceInstanceInfo = (ResourceInstanceInfo) notifications.get(notificationIdx);
    assertNotNull(allocatedResourceInstanceInfo);
    assertEquals("allocatedResourceInstance", allocatedResourceInstanceInfo.getName());
    ResourceInstance resourceInstance = allocatedResourceInstanceInfo.getResourceInstance();
    assertNotNull(resourceInstance);
    assertEquals(0, resourceInstance.getId());
    assertEquals(0, resourceInstance.getUpdatedStats().length);
    // TODO: is this correct?
    assertEquals(1, resourceInstance.getLatestStatValues().length);
    Statistics statistics = resourceInstance.getStatistics();
    assertNotNull(statistics);
    assertTrue(statistics == st1_1);
    assertEquals(1, statistics.getUniqueId());
    assertEquals(1, statistics.getNumericId());
    assertEquals("st1_1_text", statistics.getTextId());
    assertEquals("ST1_name", statistics.getType().getName());
    assertTrue(resourceType == resourceInstance.getResourceType());
    // validate the allocatedResourceInstance notification for st1_2
    notificationIdx++;
    assertTrue(notifications.get(notificationIdx) instanceof ResourceInstanceInfo);
    allocatedResourceInstanceInfo = (ResourceInstanceInfo) notifications.get(notificationIdx);
    assertNotNull(allocatedResourceInstanceInfo);
    assertEquals("allocatedResourceInstance", allocatedResourceInstanceInfo.getName());
    resourceInstance = allocatedResourceInstanceInfo.getResourceInstance();
    assertNotNull(resourceInstance);
    assertEquals(1, resourceInstance.getId());
    assertEquals(1, resourceInstance.getUpdatedStats().length);
    // TODO: is this correct?
    assertEquals(1, resourceInstance.getLatestStatValues().length);
    statistics = resourceInstance.getStatistics();
    assertNotNull(statistics);
    assertTrue(statistics == st1_2);
    assertEquals(2, statistics.getUniqueId());
    assertEquals(1, statistics.getNumericId());
    assertEquals("st1_2_text", statistics.getTextId());
    assertEquals("ST1_name", statistics.getType().getName());
    assertTrue(resourceType == resourceInstance.getResourceType());
    // validate the allocatedResourceType notification for ST2
    notificationIdx++;
    assertTrue(notifications.get(notificationIdx) instanceof ResourceTypeInfo);
    allocatedResourceTypeInfo = (ResourceTypeInfo) notifications.get(notificationIdx);
    assertNotNull(allocatedResourceTypeInfo);
    assertEquals("allocatedResourceType", allocatedResourceTypeInfo.getName());
    resourceType = allocatedResourceTypeInfo.getResourceType();
    assertNotNull(resourceType);
    assertEquals(1, resourceType.getId());
    assertEquals(1, resourceType.getStatisticDescriptors().length);
    statisticsType = resourceType.getStatisticsType();
    assertNotNull(statisticsType);
    assertTrue(statisticsType == ST2);
    assertEquals("ST2_name", statisticsType.getName());
    assertEquals("ST2_desc", statisticsType.getDescription());
    assertEquals(1, statisticsType.getStatistics().length);
    // validate the allocatedResourceInstance notification for st2_1
    notificationIdx++;
    assertTrue(notifications.get(notificationIdx) instanceof ResourceInstanceInfo);
    allocatedResourceInstanceInfo = (ResourceInstanceInfo) notifications.get(notificationIdx);
    assertNotNull(allocatedResourceInstanceInfo);
    assertEquals("allocatedResourceInstance", allocatedResourceInstanceInfo.getName());
    resourceInstance = allocatedResourceInstanceInfo.getResourceInstance();
    assertNotNull(resourceInstance);
    assertEquals(2, resourceInstance.getId());
    assertEquals(1, resourceInstance.getUpdatedStats().length);
    // TODO: is this correct?
    assertEquals(1, resourceInstance.getLatestStatValues().length);
    statistics = resourceInstance.getStatistics();
    assertNotNull(statistics);
    assertTrue(statistics == st2_1);
    assertEquals(3, statistics.getUniqueId());
    assertEquals(1, statistics.getNumericId());
    assertEquals("st2_1_text", statistics.getTextId());
    assertEquals("ST2_name", statistics.getType().getName());
    assertTrue(resourceType == resourceInstance.getResourceType());
    // validate the sampled notification
    notificationIdx++;
    assertTrue(notifications.get(notificationIdx) instanceof SampledInfo);
    SampledInfo sampledInfo = (SampledInfo) notifications.get(notificationIdx);
    assertNotNull(sampledInfo);
    assertEquals("sampled", sampledInfo.getName());
    assertEquals(3, sampledInfo.getResourceCount());
}
Also used : StatisticsType(org.apache.geode.StatisticsType) Info(org.apache.geode.internal.statistics.TestSampleHandler.Info) ResourceInstanceInfo(org.apache.geode.internal.statistics.TestSampleHandler.ResourceInstanceInfo) SampledInfo(org.apache.geode.internal.statistics.TestSampleHandler.SampledInfo) ResourceTypeInfo(org.apache.geode.internal.statistics.TestSampleHandler.ResourceTypeInfo) Statistics(org.apache.geode.Statistics) StatisticDescriptor(org.apache.geode.StatisticDescriptor) ResourceInstanceInfo(org.apache.geode.internal.statistics.TestSampleHandler.ResourceInstanceInfo) SampledInfo(org.apache.geode.internal.statistics.TestSampleHandler.SampledInfo) ResourceTypeInfo(org.apache.geode.internal.statistics.TestSampleHandler.ResourceTypeInfo) Test(org.junit.Test) UnitTest(org.apache.geode.test.junit.categories.UnitTest)

Example 29 with StatisticsType

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

the class SimpleStatSamplerIntegrationTest method testStop.

/**
   * Invokes stop() and then validates that the sampler did in fact stop.
   */
@Test
public void testStop() throws Exception {
    initStatisticsFactory();
    SimpleStatSampler statSampler = getSimpleStatSampler();
    assertTrue(statSampler.waitForInitialization(5000));
    // validate the stat sampler is running
    StatisticsType statSamplerType = getStatisticsManager().findType("StatSampler");
    Statistics[] statsArray = getStatisticsManager().findStatisticsByType(statSamplerType);
    assertEquals(1, statsArray.length);
    final Statistics statSamplerStats = statsArray[0];
    final int initialSampleCount = statSamplerStats.getInt("sampleCount");
    final int expectedSampleCount = initialSampleCount + 2;
    waitForStatSample(statSamplerStats, expectedSampleCount, 20000, 10);
    // stop the stat sampler
    statSampler.stop();
    // validate the stat sampler has stopped
    final int stoppedSampleCount = statSamplerStats.getInt("sampleCount");
    // the following should timeout without completing
    assertStatValueDoesNotChange(statSamplerStats, "sampleCount", stoppedSampleCount, 5000, 10);
    assertEquals(stoppedSampleCount, statSamplerStats.getInt("sampleCount"));
}
Also used : StatisticsType(org.apache.geode.StatisticsType) Statistics(org.apache.geode.Statistics) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 30 with StatisticsType

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

the class SimpleStatSamplerIntegrationTest method testSampleRate.

/**
   * Tests the statistics sample rate within an acceptable margin of error.
   */
@Test
public void testSampleRate() throws Exception {
    initStatisticsFactory();
    SimpleStatSampler statSampler = getSimpleStatSampler();
    assertTrue(statSampler.waitForInitialization(5000));
    assertEquals(SimpleStatSampler.DEFAULT_SAMPLE_RATE, statSampler.getSampleRate());
    assertTrue(getStatisticsManager().getStatListModCount() > 0);
    List<Statistics> statistics = getStatisticsManager().getStatsList();
    assertNotNull(statistics);
    assertTrue(statistics.size() > 0);
    StatisticsType statSamplerType = getStatisticsManager().findType("StatSampler");
    Statistics[] statsArray = getStatisticsManager().findStatisticsByType(statSamplerType);
    assertEquals(1, statsArray.length);
    final Statistics statSamplerStats = statsArray[0];
    final int initialSampleCount = statSamplerStats.getInt("sampleCount");
    final int expectedSampleCount = initialSampleCount + 2;
    waitForStatSample(statSamplerStats, expectedSampleCount, 20000, 10);
}
Also used : StatisticsType(org.apache.geode.StatisticsType) Statistics(org.apache.geode.Statistics) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Aggregations

StatisticsType (org.apache.geode.StatisticsType)36 Statistics (org.apache.geode.Statistics)34 Test (org.junit.Test)24 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)20 StatisticDescriptor (org.apache.geode.StatisticDescriptor)18 File (java.io.File)13 List (java.util.List)11 StatValue (org.apache.geode.internal.statistics.StatArchiveReader.StatValue)11 TestStatArchiveWriter (org.apache.geode.internal.statistics.TestStatArchiveWriter)10 Iterator (java.util.Iterator)4 ArrayList (java.util.ArrayList)3 FlakyTest (org.apache.geode.test.junit.categories.FlakyTest)3 Properties (java.util.Properties)2 StatisticsFactory (org.apache.geode.StatisticsFactory)2 Connection (org.apache.geode.cache.client.internal.Connection)2 ConfigurationProperties (org.apache.geode.distributed.ConfigurationProperties)2 InternalDistributedSystem (org.apache.geode.distributed.internal.InternalDistributedSystem)2 ResourceInst (org.apache.geode.internal.statistics.StatArchiveReader.ResourceInst)2 Info (org.apache.geode.internal.statistics.TestSampleHandler.Info)2 ResourceInstanceInfo (org.apache.geode.internal.statistics.TestSampleHandler.ResourceInstanceInfo)2