}
@Test
public void testRollupGenerationSimple() throws Exception {
AstyanaxWriter writer = AstyanaxWriter.getInstance();
AstyanaxReader reader = AstyanaxReader.getInstance();
final long baseMillis = 1333635148000L; // some point during 5 April 2012.
int hours = 48;
final String acctId = "ac" + IntegrationTestBase.randString(8);
final String metricName = "fooService,barServer," + randString(8);
final long endMillis = baseMillis + (1000 * 60 * 60 * hours);
final Locator locator = Locator.createLocatorFromPathComponents(acctId, metricName);
writeFullData(locator, baseMillis, hours, writer);
// FULL -> 5m
ArrayList<SingleRollupWriteContext> writes = new ArrayList<SingleRollupWriteContext>();
for (Range range : Range.getRangesToRollup(Granularity.FULL, baseMillis, endMillis)) {
// each range should produce one average
Points<SimpleNumber> input = reader.getDataToRoll(SimpleNumber.class, locator, range, CassandraModel.CF_METRICS_FULL);
BasicRollup basicRollup = BasicRollup.buildRollupFromRawSamples(input);
HistogramRollup histogramRollup = HistogramRollup.buildRollupFromRawSamples(input);
writes.add(new SingleRollupWriteContext(basicRollup,
locator,
Granularity.FULL.coarser(),
CassandraModel.getColumnFamily(BasicRollup.class, Granularity.FULL.coarser()),
range.start));
writes.add(new SingleRollupWriteContext(histogramRollup,
locator,
Granularity.FULL.MIN_5,
CassandraModel.getColumnFamily(HistogramRollup.class, Granularity.MIN_5),
range.start));
}
writer.insertRollups(writes);
// 5m -> 20m
writes.clear();
for (Range range : Range.getRangesToRollup(Granularity.MIN_5, baseMillis, endMillis)) {
Points<BasicRollup> input = reader.getDataToRoll(BasicRollup.class, locator, range,
CassandraModel.getColumnFamily(BasicRollup.class, Granularity.MIN_5));
BasicRollup basicRollup = BasicRollup.buildRollupFromRollups(input);
writes.add(new SingleRollupWriteContext(basicRollup,
locator,
Granularity.MIN_5.coarser(),
CassandraModel.getColumnFamily(BasicRollup.class, Granularity.MIN_5.coarser()),
range.start));
Points<HistogramRollup> histInput = reader.getDataToRoll(HistogramRollup.class, locator, range,
CassandraModel.getColumnFamily(HistogramRollup.class, Granularity.MIN_5));
HistogramRollup histogramRollup = HistogramRollup.buildRollupFromRollups(histInput);
writes.add(new SingleRollupWriteContext(histogramRollup,
locator,
Granularity.MIN_20,
CassandraModel.getColumnFamily(HistogramRollup.class, Granularity.MIN_20),
range.start));
}
writer.insertRollups(writes);
// 20m -> 60m
writes.clear();
for (Range range : Range.getRangesToRollup(Granularity.MIN_20, baseMillis, endMillis)) {
Points<BasicRollup> input = reader.getDataToRoll(BasicRollup.class, locator, range,
CassandraModel.getColumnFamily(BasicRollup.class, Granularity.MIN_20));
BasicRollup basicRollup = BasicRollup.buildRollupFromRollups(input);
writes.add(new SingleRollupWriteContext(basicRollup,
locator,
Granularity.MIN_20.coarser(),
CassandraModel.getColumnFamily(BasicRollup.class, Granularity.MIN_20.coarser()),
range.start));
Points<HistogramRollup> histInput = reader.getDataToRoll(HistogramRollup.class, locator, range,
CassandraModel.getColumnFamily(HistogramRollup.class, Granularity.MIN_5));
HistogramRollup histogramRollup = HistogramRollup.buildRollupFromRollups(histInput);
writes.add(new SingleRollupWriteContext(histogramRollup,
locator,
Granularity.MIN_60,
CassandraModel.getColumnFamily(HistogramRollup.class, Granularity.MIN_60),
range.start));
}
writer.insertRollups(writes);
// 60m -> 240m
writes.clear();
for (Range range : Range.getRangesToRollup(Granularity.MIN_60, baseMillis, endMillis)) {
Points<BasicRollup> input = reader.getDataToRoll(BasicRollup.class, locator, range,
CassandraModel.getColumnFamily(BasicRollup.class, Granularity.MIN_60));
BasicRollup basicRollup = BasicRollup.buildRollupFromRollups(input);
writes.add(new SingleRollupWriteContext(basicRollup,
locator,
Granularity.MIN_60.coarser(),
CassandraModel.getColumnFamily(BasicRollup.class, Granularity.MIN_60.coarser()),
range.start));
Points<HistogramRollup> histInput = reader.getDataToRoll(HistogramRollup.class, locator, range,
CassandraModel.getColumnFamily(HistogramRollup.class, Granularity.MIN_5));
HistogramRollup histogramRollup = HistogramRollup.buildRollupFromRollups(histInput);
writes.add(new SingleRollupWriteContext(histogramRollup,
locator,
Granularity.MIN_240,
CassandraModel.getColumnFamily(HistogramRollup.class, Granularity.MIN_240),
range.start));
}
writer.insertRollups(writes);
// 240m -> 1440m
writes.clear();
for (Range range : Range.getRangesToRollup(Granularity.MIN_240, baseMillis, endMillis)) {
Points<BasicRollup> input = reader.getDataToRoll(BasicRollup.class, locator, range,
CassandraModel.getColumnFamily(BasicRollup.class, Granularity.MIN_240));
BasicRollup basicRollup = BasicRollup.buildRollupFromRollups(input);
writes.add(new SingleRollupWriteContext(basicRollup,
locator,
Granularity.MIN_240.coarser(),
CassandraModel.getColumnFamily(BasicRollup.class, Granularity.MIN_240.coarser()),
range.start));
Points<HistogramRollup> histInput = reader.getDataToRoll(HistogramRollup.class, locator, range,
CassandraModel.getColumnFamily(HistogramRollup.class, Granularity.MIN_5));
HistogramRollup histogramRollup = HistogramRollup.buildRollupFromRollups(histInput);
writes.add(new SingleRollupWriteContext(histogramRollup,
locator,
Granularity.MIN_1440,
CassandraModel.getColumnFamily(HistogramRollup.class, Granularity.MIN_1440),
range.start));
}
writer.insertRollups(writes);
// verify the number of points in 48h worth of rollups.
Range range = new Range(Granularity.MIN_1440.snapMillis(baseMillis), Granularity.MIN_1440.snapMillis(endMillis + Granularity.MIN_1440.milliseconds()));
Points<BasicRollup> input = reader.getDataToRoll(BasicRollup.class, locator, range,
CassandraModel.getColumnFamily(BasicRollup.class, Granularity.MIN_1440));
BasicRollup basicRollup = BasicRollup.buildRollupFromRollups(input);
Assert.assertEquals(60 * hours, basicRollup.getCount());
Points<HistogramRollup> histInput = reader.getDataToRoll(HistogramRollup.class, locator, range,
CassandraModel.getColumnFamily(HistogramRollup.class, Granularity.MIN_1440));
HistogramRollup histogramRollup = HistogramRollup.buildRollupFromRollups(histInput);
Assert.assertTrue(histogramRollup.getBins().size() > 0);
Assert.assertTrue("Number of bins is " + histogramRollup.getBins().size(),
histogramRollup.getBins().size() <= HistogramRollup.MAX_BIN_SIZE);