use of com.twitter.heron.common.basics.NIOLooper in project heron by twitter.
the class MetricsCacheTest method testMetricCache.
@Test
public void testMetricCache() throws IOException {
// prepare config files
SystemConfig systemConfig = SystemConfig.newBuilder(true).putAll(CONFIG_SYSTEM_PATH, true).build();
MetricsSinksConfig sinksConfig = new MetricsSinksConfig(CONFIG_SINK_PATH);
// initialize metric cache, except looper
MetricsCache mc = new MetricsCache(systemConfig, sinksConfig, new NIOLooper());
mc.addMetrics(TopologyMaster.PublishMetrics.newBuilder().addMetrics(TopologyMaster.MetricDatum.newBuilder().setComponentName("c1").setInstanceId("i1").setName("__jvm-uptime-secs").setTimestamp(System.currentTimeMillis()).setValue("0.1")).addExceptions(TopologyMaster.TmasterExceptionLog.newBuilder().setComponentName("c1").setHostname("h1").setInstanceId("i1").setStacktrace("s1").setLogging("l1").setCount(1).setFirsttime(String.valueOf(System.currentTimeMillis())).setLasttime(String.valueOf(System.currentTimeMillis()))).build());
// query last 10 seconds
TopologyMaster.MetricResponse response = mc.getMetrics(TopologyMaster.MetricRequest.newBuilder().setComponentName("c1").addInstanceId("i1").setInterval(10).addMetric("__jvm-uptime-secs").build());
assertEquals(response.getMetricCount(), 1);
assertEquals(response.getMetric(0).getInstanceId(), "i1");
assertEquals(response.getMetric(0).getMetricCount(), 1);
assertEquals(response.getMetric(0).getMetric(0).getName(), "__jvm-uptime-secs");
assertEquals(response.getMetric(0).getMetric(0).getValue(), "0.1");
}
Aggregations