当前位置: 首页>>代码示例>>Java>>正文


Java MetricsVisitor类代码示例

本文整理汇总了Java中org.apache.hadoop.metrics2.MetricsVisitor的典型用法代码示例。如果您正苦于以下问题:Java MetricsVisitor类的具体用法?Java MetricsVisitor怎么用?Java MetricsVisitor使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


MetricsVisitor类属于org.apache.hadoop.metrics2包,在下文中一共展示了MetricsVisitor类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testCommon

import org.apache.hadoop.metrics2.MetricsVisitor; //导入依赖的package包/类
/**
 * Test the common use cases
 */
@Test public void testCommon() {
  MetricsVisitor visitor = mock(MetricsVisitor.class);
  MetricsRegistry registry = new MetricsRegistry("test");
  List<AbstractMetric> metrics = MetricsLists.builder("test")
      .addCounter(info("c1", "int counter"), 1)
      .addCounter(info("c2", "long counter"), 2L)
      .addGauge(info("g1", "int gauge"), 5)
      .addGauge(info("g2", "long gauge"), 6L)
      .addGauge(info("g3", "float gauge"), 7f)
      .addGauge(info("g4", "double gauge"), 8d)
      .metrics();

  for (AbstractMetric metric : metrics) {
    metric.visit(visitor);
  }

  verify(visitor).counter(c1.capture(), eq(1));
  assertEquals("c1 name", "c1", c1.getValue().name());
  assertEquals("c1 description", "int counter", c1.getValue().description());
  verify(visitor).counter(c2.capture(), eq(2L));
  assertEquals("c2 name", "c2", c2.getValue().name());
  assertEquals("c2 description", "long counter", c2.getValue().description());
  verify(visitor).gauge(g1.capture(), eq(5));
  assertEquals("g1 name", "g1", g1.getValue().name());
  assertEquals("g1 description", "int gauge", g1.getValue().description());
  verify(visitor).gauge(g2.capture(), eq(6L));
  assertEquals("g2 name", "g2", g2.getValue().name());
  assertEquals("g2 description", "long gauge", g2.getValue().description());
  verify(visitor).gauge(g3.capture(), eq(7f));
  assertEquals("g3 name", "g3", g3.getValue().name());
  assertEquals("g3 description", "float gauge", g3.getValue().description());
  verify(visitor).gauge(g4.capture(), eq(8d));
  assertEquals("g4 name", "g4", g4.getValue().name());
  assertEquals("g4 description", "double gauge", g4.getValue().description());
}
 
开发者ID:nucypher,项目名称:hadoop-oss,代码行数:39,代码来源:TestMetricsVisitor.java

示例2: testCommon

import org.apache.hadoop.metrics2.MetricsVisitor; //导入依赖的package包/类
/**
 * Test the common use cases
 */
@Test public void testCommon() {
  MetricsVisitor visitor = mock(MetricsVisitor.class);
  List<Metric> metrics = Arrays.asList(
      new MetricCounterInt("c1", "int counter", 1),
      new MetricCounterLong("c2", "long counter", 2L),
      new MetricGaugeInt("g1", "int gauge", 5),
      new MetricGaugeLong("g2", "long gauge", 6L),
      new MetricGaugeFloat("g3", "float gauge", 7f),
      new MetricGaugeDouble("g4", "double gauge", 8d));

  for (Metric metric : metrics) {
    metric.visit(visitor);
  }

  verify(visitor).counter(c1.capture(), eq(1));
  assertEquals("c1 name", "c1", c1.getValue().name());
  assertEquals("c1 description", "int counter", c1.getValue().description());
  verify(visitor).counter(c2.capture(), eq(2L));
  assertEquals("c2 name", "c2", c2.getValue().name());
  assertEquals("c2 description", "long counter", c2.getValue().description());
  verify(visitor).gauge(g1.capture(), eq(5));
  assertEquals("g1 name", "g1", g1.getValue().name());
  assertEquals("g1 description", "int gauge", g1.getValue().description());
  verify(visitor).gauge(g2.capture(), eq(6L));
  assertEquals("g2 name", "g2", g2.getValue().name());
  assertEquals("g2 description", "long gauge", g2.getValue().description());
  verify(visitor).gauge(g3.capture(), eq(7f));
  assertEquals("g3 name", "g3", g3.getValue().name());
  assertEquals("g3 description", "float gauge", g3.getValue().description());
  verify(visitor).gauge(g4.capture(), eq(8d));
  assertEquals("g4 name", "g4", g4.getValue().name());
  assertEquals("g4 description", "double gauge", g4.getValue().description());
}
 
开发者ID:Seagate,项目名称:hadoop-on-lustre,代码行数:37,代码来源:TestMetricsVisitor.java

示例3: visit

import org.apache.hadoop.metrics2.MetricsVisitor; //导入依赖的package包/类
@Override
public void visit(MetricsVisitor visitor) {
  visitor.counter(this, value);
}
 
开发者ID:nucypher,项目名称:hadoop-oss,代码行数:5,代码来源:MetricCounterInt.java

示例4: visit

import org.apache.hadoop.metrics2.MetricsVisitor; //导入依赖的package包/类
@Override
public void visit(MetricsVisitor visitor) {
  visitor.gauge(this, value);
}
 
开发者ID:nucypher,项目名称:hadoop-oss,代码行数:5,代码来源:MetricGaugeDouble.java

示例5: testPutMetrics

import org.apache.hadoop.metrics2.MetricsVisitor; //导入依赖的package包/类
@Test
@SuppressWarnings({ "unchecked", "rawtypes" })
public void testPutMetrics() throws Exception {
  // Create a record by mocking MetricsRecord class.
  MetricsRecord record = mock(MetricsRecord.class);
  when(record.tags()).thenReturn(Lists
      .newArrayList(new MetricsTag(KafkaMetricsInfo.KafkaTag, "test_tag")));
  when(record.timestamp()).thenReturn(System.currentTimeMillis());

  // Create a metric using AbstractMetric class.
  AbstractMetric metric = new AbstractMetric(KafkaMetricsInfo.KafkaCounter) {
    @Override
    public Number value() {
      return new Integer(123);
    }

    @Override
    public MetricType type() {
      return null;
    }

    @Override
    public void visit(MetricsVisitor visitor) {

    }
  };

  // Create a list of metrics.
  Iterable<AbstractMetric> metrics = Lists.newArrayList(metric);
  when(record.name()).thenReturn("Kafka record name");
  when(record.metrics()).thenReturn(metrics);
  SubsetConfiguration conf = mock(SubsetConfiguration.class);
  when(conf.getString(KafkaSink.BROKER_LIST)).thenReturn("localhost:9092");
  String topic = "myTestKafkaTopic";
  when(conf.getString(KafkaSink.TOPIC)).thenReturn(topic);

  // Create the KafkaSink object and initialize it.
  kafkaSink = new KafkaSink();
  kafkaSink.init(conf);

  // Create a mock KafkaProducer as a producer for KafkaSink.
  Producer<Integer, byte[]> mockProducer = mock(KafkaProducer.class);
  kafkaSink.setProducer(mockProducer);

  // Create the json object from the record.
  StringBuilder jsonLines = recordToJson(record);
  if (LOG.isDebugEnabled()) {
    LOG.debug("kafka message: " + jsonLines.toString());
  }

  // Send the record and store the result in a mock Future.
  Future<RecordMetadata> f = mock(Future.class);
  when(mockProducer.send((ProducerRecord) anyObject())).thenReturn(f);
  kafkaSink.putMetrics(record);

  // Get the argument and verity it.
  ArgumentCaptor<ProducerRecord> argument =
      ArgumentCaptor.forClass(ProducerRecord.class);
  verify(mockProducer).send(argument.capture());

  // Compare the received data with the original one.
  ProducerRecord<Integer, byte[]> data = (argument.getValue());
  String jsonResult = new String(data.value());
  if (LOG.isDebugEnabled()) {
    LOG.debug("kafka result: " + jsonResult);
  }
  assertEquals(jsonLines.toString(), jsonResult);
}
 
开发者ID:aliyun-beta,项目名称:aliyun-oss-hadoop-fs,代码行数:69,代码来源:TestKafkaMetrics.java


注:本文中的org.apache.hadoop.metrics2.MetricsVisitor类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。