Java Code Examples for org.apache.hadoop.metrics2.lib.MetricsAnnotations

Following code examples demonstrate how to use org.apache.hadoop.metrics2.lib.MetricsAnnotations from hadoop. These examples are extracted from various highly rated open source projects. You can directly use these code snippets or view their entire linked source code. These snippets are extracted to provide contextual information about how to use this class in the real world. These samples also let you understand some good practices on how to use org.apache.hadoop.metrics2.lib.MetricsAnnotations and various code implementation of this class.
Example 1
Project : hadoop Source File : TestMetricsSourceAdapter.java View Source Code on GitHub

  public void testGetMetricsAndJmx() throws Exception {
    TestSource source = new TestSource("test");
    MetricsSourceBuilder sb = MetricsAnnotations.newSourceBuilder(source);
    final MetricsSource s = sb.build();

    List<MetricsTag> injectedTags = new ArrayList<MetricsTag>();
    MetricsSourceAdapter sa = new MetricsSourceAdapter(
        "test", "test", "test desc", s, injectedTags, null, null, 1, false);

    MetricsCollectorImpl builder = new MetricsCollectorImpl();
    Iterable<MetricsRecordImpl> metricsRecords = sa.getMetrics(builder, true);

    MetricsRecordImpl metricsRecord = metricsRecords.iterator().next();
    assertEquals(0L,
        metricsRecord.metrics().iterator().next().value().longValue());

    assertEquals(0L, (Number)sa.getAttribute("C1"));

    source.incrementCnt();

    builder = new MetricsCollectorImpl();
    metricsRecords = sa.getMetrics(builder, true);
    metricsRecord = metricsRecords.iterator().next();
    assertTrue(metricsRecord.metrics().iterator().hasNext());
    assertEquals(1L, (Number)sa.getAttribute("C1"));
  }