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);
}
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"));
}
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);
}
}
}
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);
}
Aggregations