@RunWith(CassandraRunner.class)
public class GaugeDataStoreTest {
@Test
public void gauges() throws InterruptedException, IllegalAccessException {
final CassandraGaugeDataStore store = IoCs.processInstance(new CassandraGaugeDataStore() {
@Created
protected void forceMarker() {
marker = "test";
}
@Override
protected int getPeriod(final String prefix) {
return 100;
}
});
assertEquals(0, store.gauges().size());
final Gauge gauge = new Gauge() {
@Override
public Role role() {
return Role.FAILURES;
}
@Override
public double value() {
return 5;
}
};
store.createOrNoopGauge(gauge.role());
store.addGauge(gauge);
Thread.sleep(250);
store.shutdown();
final Collection<Role> gauges = store.gauges();
assertEquals(1, gauges.size());
assertEquals(gauge.role(), gauges.iterator().next());
final SortedMap<Long,Double> gaugeValues = store.getGaugeValues(new GaugeValuesRequest(0, System.currentTimeMillis(), Role.FAILURES));
assertTrue(gaugeValues.size() > 0);
assertEquals(5., gaugeValues.values().iterator().next(), 0.);
store.gaugeStopped(gauge.role());
}