Package org.apache.hadoop.metrics2

Examples of org.apache.hadoop.metrics2.MetricsRecord


  /**
   * Make sure metrics tag has a sane hashCode impl
   */
  @Test public void testNullTag() {
    MetricsCache cache = new MetricsCache();
    MetricsRecord mr = makeRecord("r",
        Arrays.asList(makeTag("t", null)),
        Arrays.asList(makeMetric("m", 0), makeMetric("m1", 1)));

    MetricsCache.Record cr = cache.update(mr);
    assertTrue("t value should be null", null == cr.getTag("t"));
View Full Code Here


    assertEquals(description, val, cr.getMetricInstance(key).value());
  }

  private MetricsRecord makeRecord(String name, Collection<MetricsTag> tags,
                                   Collection<AbstractMetric> metrics) {
    MetricsRecord mr = mock(MetricsRecord.class);
    when(mr.name()).thenReturn(name);
    when(mr.tags()).thenReturn(tags);
    when(mr.metrics()).thenReturn(metrics);
    return mr;
  }
View Full Code Here

   * @param tags List<MetricsTag> tags
   * @return MetricsRecord newly created mock
   */
  private static MetricsRecord mockMetricsRecord(String name,
      List<MetricsTag> tags) {
    MetricsRecord record = mock(MetricsRecord.class);
    when(record.name()).thenReturn(name);
    when(record.tags()).thenReturn(tags);
    return record;
  }
View Full Code Here

  }


  private void checkMetricsRecords(List<MetricsRecord> recs) {
    LOG.debug(recs);
    MetricsRecord r = recs.get(0);
    assertEquals("name", "s1rec", r.name());
    assertEquals("tags", new MetricsTag[] {
      tag(MsInfo.Context, "test"),
      tag(MsInfo.Hostname, hostname)}, r.tags());
    assertEquals("metrics", MetricsLists.builder("")
      .addCounter(info("C1", "C1 desc"), 1L)
      .addGauge(info("G1", "G1 desc"), 2L)
      .addCounter(info("S1NumOps", "Number of ops for s1"), 1L)
      .addGauge(info("S1AvgTime", "Average time for s1"), 0.0)
      .metrics(), r.metrics());

    r = recs.get(1);
    assertTrue("NumActiveSinks should be 3", Iterables.contains(r.metrics(),
               new MetricGaugeInt(MsInfo.NumActiveSinks, 3)));
  }
View Full Code Here

    checkMetricsRecords(mr3, "s3rec");
  }

  static void checkMetricsRecords(List<MetricsRecord> recs, String expected) {
    LOG.debug(recs);
    MetricsRecord r = recs.get(0);
    assertEquals("name", expected, r.name());
    assertEquals("tags", new MetricsTag[] {
      new MetricsTag("context", "Metrics context", "test"),
      new MetricsTag("hostName", "Local hostname", hostname)}, r.tags());
    assertEquals("metrics", new Metric[] {
      new MetricCounterLong("c1", "c1 desc", 1),
      new MetricGaugeLong("g1", "g1 desc", 2),
      new MetricCounterLong("s1_num_ops", "Number of ops for s1 desc", 1),
      new MetricGaugeDouble("s1_avg_time", "Average time for s1 desc", 0)},
      r.metrics());

    // Skip the system metrics for now.
    // MetricsRecord r1 = recs.get(1);
  }
View Full Code Here

public class TestMetricsCache {
  private static final Log LOG = LogFactory.getLog(TestMetricsCache.class);

  @Test public void testUpdate() {
    MetricsCache cache = new MetricsCache();
    MetricsRecord mr = makeRecord("r",
        Arrays.asList(makeTag("t", "tv")),
        Arrays.asList(makeMetric("m", 0), makeMetric("m1", 1)));

    MetricsCache.Record cr = cache.update(mr);
    verify(mr).name();
    verify(mr).tags();
    verify(mr).metrics();
    assertEquals("same record size", cr.metrics.size(),
                 ((Collection<Metric>)mr.metrics()).size());
    assertEquals("same metric value", 0, cr.getMetric("m"));
    assertNotNull("metric not null", cr.getMetricInstance("m"));
    assertEquals("new metric value", 0, cr.getMetricInstance("m").value());


    MetricsRecord mr2 = makeRecord("r",
        Arrays.asList(makeTag("t", "tv")),
        Arrays.asList(makeMetric("m", 2), makeMetric("m2", 42)));
    cr = cache.update(mr2);
    assertEquals("contains 3 metric", 3, cr.metrics.size());
    assertEquals("updated metric value", 2, cr.getMetric("m"));
    assertNotNull("metric not null", cr.getMetricInstance("m"));
    assertEquals("new metric value", 2, cr.getMetricInstance("m").value());

    assertEquals("old metric value", 1, cr.getMetric("m1"));
    assertNotNull("metric not null", cr.getMetricInstance("m1"));
    assertEquals("new metric value", 1, cr.getMetricInstance("m1").value());

    assertEquals("new metric value", 42, cr.getMetric("m2"));
    assertNotNull("metric not null", cr.getMetricInstance("m2"));
    assertEquals("new metric value", 42, cr.getMetricInstance("m2").value());

    MetricsRecord mr3 = makeRecord("r",
        Arrays.asList(makeTag("t", "tv3")), // different tag value
        Arrays.asList(makeMetric("m3", 3)));
    cr = cache.update(mr3); // should get a new record
    assertEquals("contains 1 metric", 1, cr.metrics.size());
    assertEquals("updated metric value", 3, cr.getMetric("m3"));
View Full Code Here

  }

  @Test public void testGet() {
    MetricsCache cache = new MetricsCache();
    assertNull("empty", cache.get("r", Arrays.asList(makeTag("t", "t"))));
    MetricsRecord mr = makeRecord("r",
        Arrays.asList(makeTag("t", "t")),
        Arrays.asList(makeMetric("m", 1)));
    cache.update(mr);
    MetricsCache.Record cr = cache.get("r", (Collection<MetricsTag>)mr.tags());
    LOG.debug("tags="+ (Collection<MetricsTag>)mr.tags() +" cr="+ cr);

    assertNotNull("Got record", cr);
    assertEquals("contains 1 metric", 1, cr.metrics.size());
    assertEquals("new metric value", 1, cr.getMetric("m"));
    assertNotNull("metric not null", cr.getMetricInstance("m"));
View Full Code Here

    assertEquals("new metric value", 1, cr.getMetricInstance("m").value());
  }

  private MetricsRecord makeRecord(String name, Collection<MetricsTag> tags,
                                   Collection<Metric> metrics) {
    MetricsRecord mr = mock(MetricsRecord.class);
    when(mr.name()).thenReturn(name);
    when(mr.tags()).thenReturn(tags);
    when(mr.metrics()).thenReturn(metrics);
    return mr;
  }
View Full Code Here

abstract class AbstractMetricsRecord implements MetricsRecord {

  @Override public boolean equals(Object obj) {
    if (obj instanceof MetricsRecord) {
      final MetricsRecord other = (MetricsRecord) obj;
      return Objects.equal(timestamp(), other.timestamp()) &&
             Objects.equal(name(), other.name()) &&
             Objects.equal(description(), other.description()) &&
             Objects.equal(tags(), other.tags()) &&
             Iterables.elementsEqual(metrics(), other.metrics());
    }
    return false;
  }
View Full Code Here

   * @param tags List<MetricsTag> tags
   * @return MetricsRecord newly created mock
   */
  private static MetricsRecord mockMetricsRecord(String name,
      List<MetricsTag> tags) {
    MetricsRecord record = mock(MetricsRecord.class);
    when(record.name()).thenReturn(name);
    when(record.tags()).thenReturn(tags);
    return record;
  }
View Full Code Here

TOP

Related Classes of org.apache.hadoop.metrics2.MetricsRecord

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.