Search in sources :

Example 71 with Statistics

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

the class GemFireStatSamplerIntegrationTest method testSampleRate.

/**
   * Tests the statistics sample rate within an acceptable margin of error.
   */
@Test
public void testSampleRate() throws Exception {
    connect(createGemFireProperties());
    GemFireStatSampler statSampler = getGemFireStatSampler();
    assertTrue(statSampler.waitForInitialization(5000));
    assertEquals(STAT_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;
    waitForExpectedStatValue(statSamplerStats, "sampleCount", expectedSampleCount, 5000, 10);
}
Also used : StatisticsType(org.apache.geode.StatisticsType) Statistics(org.apache.geode.Statistics) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 72 with Statistics

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

the class GemFireStatSamplerIntegrationTest method testStop.

/**
   * Invokes stop() and then validates that the sampler did in fact stop.
   */
@Test
public void testStop() throws Exception {
    connect(createGemFireProperties());
    GemFireStatSampler statSampler = getGemFireStatSampler();
    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 rather than complete
    assertStatValueDoesNotChange(statSamplerStats, "sampleCount", stoppedSampleCount, 5000, 10);
    assertEquals(stoppedSampleCount, statSamplerStats.getInt("sampleCount"));
}
Also used : StatisticsType(org.apache.geode.StatisticsType) Statistics(org.apache.geode.Statistics) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 73 with Statistics

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

the class DistributedSystemStatisticsIntegrationTest method testIntStatistics.

/**
   * Tests {@code int} statistics
   */
@Test
public void testIntStatistics() {
    Statistics stats = setUpIntStatistics(3);
    for (int j = 0; j < this.statNames.length; j++) {
        String statName = this.statNames[j];
        for (int i = 0; i < 10; i++) {
            stats.setInt(statName, i);
            stats.incInt(statName, 1);
            assertThat(stats.getInt(statName)).isEqualTo(i + 1);
        }
    }
}
Also used : Statistics(org.apache.geode.Statistics) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 74 with Statistics

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

the class DistributedSystemStatisticsIntegrationTest method testAccessingLongStat.

/**
   * Tests that accessing a {@code long} stat throws the appropriate exceptions.
   */
@Test
public void testAccessingLongStat() {
    Statistics stats = setUpLongStatistics(1);
    assertThat(stats.getLong(this.statName1)).isEqualTo(0L);
    assertThatThrownBy(() -> stats.getDouble(this.statName1)).isExactlyInstanceOf(IllegalArgumentException.class);
    assertThatThrownBy(() -> stats.getInt(this.statName1)).isExactlyInstanceOf(IllegalArgumentException.class);
    stats.setLong(this.statName1, 4L);
    assertThatThrownBy(() -> stats.setDouble(this.statName1, 4.0)).isExactlyInstanceOf(IllegalArgumentException.class);
    assertThatThrownBy(() -> stats.setInt(this.statName1, 4)).isExactlyInstanceOf(IllegalArgumentException.class);
    stats.incLong(this.statName1, 4L);
    assertThatThrownBy(() -> stats.incDouble(this.statName1, 4.0)).isExactlyInstanceOf(IllegalArgumentException.class);
    assertThatThrownBy(() -> stats.incInt(this.statName1, 4)).isExactlyInstanceOf(IllegalArgumentException.class);
}
Also used : Statistics(org.apache.geode.Statistics) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Aggregations

Statistics (org.apache.geode.Statistics)74 StatisticsType (org.apache.geode.StatisticsType)36 Test (org.junit.Test)34 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)29 StatisticDescriptor (org.apache.geode.StatisticDescriptor)18 File (java.io.File)17 ArrayList (java.util.ArrayList)12 List (java.util.List)12 StatValue (org.apache.geode.internal.statistics.StatArchiveReader.StatValue)11 TestStatArchiveWriter (org.apache.geode.internal.statistics.TestStatArchiveWriter)10 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)6 LRUStatistics (org.apache.geode.internal.cache.lru.LRUStatistics)6 HashMap (java.util.HashMap)5 LinuxProcFsStatistics (org.apache.geode.internal.statistics.platform.LinuxProcFsStatistics)5 Iterator (java.util.Iterator)4 Map (java.util.Map)4 FlakyTest (org.apache.geode.test.junit.categories.FlakyTest)4 MainWithChildrenRollingFileHandler (org.apache.geode.internal.io.MainWithChildrenRollingFileHandler)3 Before (org.junit.Before)3 IOException (java.io.IOException)2