@Test
public void testAggregateProfileSample() throws Exception {
final String name = "sample";
ProfileCollector collector = getCollector(serverNode);
ProfileConsumer cons1 = collector.getConsumer("c1");
final AggregateProfileSample samp =
(AggregateProfileSample)
cons1.createSample(name, testType, ProfileLevel.MIN);
assertEquals(0, samp.getNumSamples());
for (Long sample : samp.getSamples()) {
assertNull(sample);
}
final long[] testData = {4, 8, 2, -1, 5, 9, 11, 14};
// capacity defaults to zero, so size should be zero
samp.addSample(3);
testStatistics(samp, /*size*/0, /*min*/3, /*max*/3, testData);
samp.setCapacity(100);
samp.addSample(testData[0]);
testStatistics(samp, /*size*/1, /*min*/3, /*max*/4, testData);
samp.addSample(testData[1]);
testStatistics(samp, 2, 3, 8, testData);
samp.addSample(testData[2]);
testStatistics(samp, 3, 2, 8, testData);
samp.addSample(testData[3]);
testStatistics(samp, 4, -1, 8, testData);
samp.addSample(testData[4]);
testStatistics(samp, 5, -1, 8, testData);
samp.addSample(testData[5]);
testStatistics(samp, 6, -1, 9, testData);
samp.addSample(testData[6]);
testStatistics(samp, 7, -1, 11, testData);
samp.addSample(testData[7]);
testStatistics(samp, 8, -1, 14, testData);
samp.clearSamples();
assertEquals(0, samp.getNumSamples());
for (Long sample : samp.getSamples()) {
assertNull(sample);
}
// Add all the data back in, check that min, max, values what we expect
for (long data : testData) {
samp.addSample(data);
}
testStatistics(samp, 8, -1, 14, testData);
}