use of org.apache.geode.StatisticsType in project geode by apache.
the class FileSystemStatsJUnitTest method createStats.
@Before
public void createStats() {
StatisticsFactory statsFactory = mock(StatisticsFactory.class);
statistics = mock(Statistics.class);
when(statsFactory.createAtomicStatistics(any(), anyString())).thenReturn(statistics);
stats = new FileSystemStats(statsFactory, "stats");
ArgumentCaptor<StatisticsType> statsTypeCaptor = ArgumentCaptor.forClass(StatisticsType.class);
verify(statsFactory).createAtomicStatistics(statsTypeCaptor.capture(), anyString());
type = statsTypeCaptor.getValue();
}
use of org.apache.geode.StatisticsType in project geode by apache.
the class LuceneIndexStatsJUnitTest method createStats.
@Before
public void createStats() {
StatisticsFactory statsFactory = mock(StatisticsFactory.class);
statistics = mock(Statistics.class);
when(statsFactory.createAtomicStatistics(any(), anyString())).thenReturn(statistics);
stats = new LuceneIndexStats(statsFactory, "region-index");
ArgumentCaptor<StatisticsType> statsTypeCaptor = ArgumentCaptor.forClass(StatisticsType.class);
verify(statsFactory).createAtomicStatistics(statsTypeCaptor.capture(), anyString());
type = statsTypeCaptor.getValue();
}
use of org.apache.geode.StatisticsType in project geode by apache.
the class DistributedSystemStatisticsIntegrationTest method setUpDoubleStatistics.
private Statistics setUpDoubleStatistics(final int count) {
String[] descriptions = new String[] { "ONE", "TWO", "THREE" };
StatisticDescriptor[] descriptors = new StatisticDescriptor[count];
for (int i = 0; i < count; i++) {
descriptors[i] = factory().createDoubleGauge(this.statNames[i], descriptions[i], "x");
}
StatisticsType type = factory().createType(getUniqueName(), "", descriptors);
Statistics stats = factory().createStatistics(type, "Display");
for (int i = 0; i < count; i++) {
stats.setDouble(this.statNames[i], 0.0);
}
return stats;
}
use of org.apache.geode.StatisticsType in project geode by apache.
the class GemFireStatSamplerIntegrationTest method testLocalStatListener.
/**
* Adds a LocalStatListener for an individual stat. Validates that it receives notifications.
* Removes the listener and validates that it was in fact removed and no longer receives
* notifications.
*/
@Test
public void testLocalStatListener() throws Exception {
connect(createGemFireProperties());
GemFireStatSampler statSampler = getGemFireStatSampler();
assertTrue(statSampler.waitForInitialization(5000));
Method getLocalListeners = getGemFireStatSampler().getClass().getMethod("getLocalListeners");
assertNotNull(getLocalListeners);
Method addLocalStatListener = getGemFireStatSampler().getClass().getMethod("addLocalStatListener", LocalStatListener.class, Statistics.class, String.class);
assertNotNull(addLocalStatListener);
Method removeLocalStatListener = getGemFireStatSampler().getClass().getMethod("removeLocalStatListener", LocalStatListener.class);
assertNotNull(removeLocalStatListener);
// validate that there are no listeners
assertTrue(statSampler.getLocalListeners().isEmpty());
// add a listener for sampleCount stat in StatSampler statistics
StatisticsType statSamplerType = getStatisticsManager().findType("StatSampler");
Statistics[] statsArray = getStatisticsManager().findStatisticsByType(statSamplerType);
assertEquals(1, statsArray.length);
final Statistics statSamplerStats = statsArray[0];
final String statName = "sampleCount";
final AtomicInteger sampleCountValue = new AtomicInteger(0);
final AtomicInteger sampleCountChanged = new AtomicInteger(0);
LocalStatListener listener = new LocalStatListener() {
public void statValueChanged(double value) {
sampleCountValue.set((int) value);
sampleCountChanged.incrementAndGet();
}
};
statSampler.addLocalStatListener(listener, statSamplerStats, statName);
assertTrue(statSampler.getLocalListeners().size() == 1);
// there's a level of indirection here and some protected member fields
LocalStatListenerImpl lsli = (LocalStatListenerImpl) statSampler.getLocalListeners().iterator().next();
assertEquals("sampleCount", lsli.stat.getName());
// wait for the listener to update 4 times
final int expectedChanges = 4;
boolean done = false;
try {
for (StopWatch time = new StopWatch(true); !done && time.elapsedTimeMillis() < 5000; done = (sampleCountChanged.get() >= expectedChanges)) {
Thread.sleep(10);
}
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
assertTrue("Waiting for sampleCountChanged >= " + expectedChanges, done);
// validate that the listener fired and updated the value
assertTrue(sampleCountValue.get() > 0);
assertTrue(sampleCountChanged.get() >= expectedChanges);
// remove the listener
statSampler.removeLocalStatListener(listener);
final int expectedSampleCountValue = sampleCountValue.get();
final int expectedSampleCountChanged = sampleCountChanged.get();
// validate that there are no listeners now
assertTrue(statSampler.getLocalListeners().isEmpty());
// wait for 2 stat samples to occur
waitForStatSample(statSamplerStats, expectedSampleCountValue, 5000, 10);
// validate that the listener did not fire
assertEquals(expectedSampleCountValue, sampleCountValue.get());
assertEquals(expectedSampleCountChanged, sampleCountChanged.get());
}
use of org.apache.geode.StatisticsType in project geode by apache.
the class StatArchiveWriterReaderIntegrationTest method testLongCounterTwoSamples.
@Test
public void testLongCounterTwoSamples() throws Exception {
final TestStatisticsManager manager = new TestStatisticsManager(1, getUniqueName(), WRITER_INITIAL_DATE_MILLIS);
final TestStatisticsSampler sampler = new TestStatisticsSampler(manager);
final SampleCollector sampleCollector = new SampleCollector(sampler);
final StatArchiveDescriptor archiveDescriptor = new StatArchiveDescriptor.Builder().setArchiveName(this.archiveFileName).setSystemId(1).setSystemStartTime(WRITER_INITIAL_DATE_MILLIS).setSystemDirectoryPath(this.testName.getMethodName()).setProductDescription(getClass().getSimpleName()).build();
final StatArchiveWriter writer = new TestStatArchiveWriter(archiveDescriptor);
sampleCollector.addSampleHandler(writer);
final StatisticDescriptor[] statsST1 = new StatisticDescriptor[] { manager.createLongCounter("long_counter_1", "d1", "u1") };
final StatisticsType ST1 = manager.createType("ST1", "ST1", statsST1);
final Statistics st1_1 = manager.createAtomicStatistics(ST1, "st1_1", 1);
final long value1 = 5;
incLong(st1_1, "long_counter_1", value1);
final long sampleIncNanos = NANOS_PER_MILLI * 1000;
long sampleTimeNanos = WRITER_PREVIOUS_TIMESTAMP_NANOS + sampleIncNanos;
sampleCollector.sample(sampleTimeNanos);
final long value2 = 15;
incLong(st1_1, "long_counter_1", value2);
sampleTimeNanos += sampleIncNanos;
sampleCollector.sample(sampleTimeNanos);
writer.close();
final StatisticDescriptor[] sds = ST1.getStatistics();
for (int i = 0; i < sds.length; i++) {
assertEquals(value1 + value2, st1_1.get(sds[i].getName()));
}
final StatArchiveReader reader = new StatArchiveReader(new File[] { new File(this.archiveFileName) }, null, false);
// compare all resourceInst values against what was printed above
final List resources = reader.getResourceInstList();
assertNotNull(resources);
assertEquals(1, resources.size());
final StatArchiveReader.ResourceInst ri = (StatArchiveReader.ResourceInst) resources.get(0);
assertNotNull(ri);
final String statsName = ri.getName();
assertNotNull(statsName);
assertEquals("st1_1", statsName);
assertEquals("ST1", ri.getType().getName());
final StatValue[] statValues = ri.getStatValues();
assertNotNull(statValues);
assertEquals(1, statValues.length);
statValues[0].setFilter(StatValue.FILTER_NONE);
final String statName = ri.getType().getStats()[0].getName();
assertNotNull(statName);
assertEquals("long_counter_1", statName);
assertEquals(statName, statValues[0].getDescriptor().getName());
assertEquals(2, statValues[0].getSnapshotsSize());
assertEquals((double) (value1 + value2), statValues[0].getSnapshotsMostRecent(), 0.01);
final long[] timeStampsMillis = statValues[0].getRawAbsoluteTimeStamps();
assertNotNull(timeStampsMillis);
assertEquals(2, timeStampsMillis.length);
final long initialPreviousTimeStampMillis = NanoTimer.nanosToMillis(WRITER_PREVIOUS_TIMESTAMP_NANOS);
final long timeStampMillis = NanoTimer.nanosToMillis(sampleTimeNanos);
final long deltaMillis = timeStampMillis - initialPreviousTimeStampMillis;
assertEquals(NanoTimer.nanosToMillis(sampleIncNanos * 2), deltaMillis);
long expectedTimeStampMillis = WRITER_INITIAL_DATE_MILLIS;
for (int i = 0; i < timeStampsMillis.length; i++) {
expectedTimeStampMillis += 1000;
assertEquals("expectedTimeStampMillis for " + i + " is wrong", expectedTimeStampMillis, timeStampsMillis[i]);
}
final double[] snapshots = statValues[0].getRawSnapshots();
assertNotNull(snapshots);
assertEquals(2, snapshots.length);
assertEquals((double) value1, snapshots[0], 0.01);
assertEquals((double) (value1 + value2), snapshots[1], 0.01);
}
Aggregations