本文整理汇总了Java中org.apache.hadoop.metrics2.MetricsSystem.publishMetricsNow方法的典型用法代码示例。如果您正苦于以下问题:Java MetricsSystem.publishMetricsNow方法的具体用法?Java MetricsSystem.publishMetricsNow怎么用?Java MetricsSystem.publishMetricsNow使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.hadoop.metrics2.MetricsSystem
的用法示例。
在下文中一共展示了MetricsSystem.publishMetricsNow方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testFailedWrite
import org.apache.hadoop.metrics2.MetricsSystem; //导入方法依赖的package包/类
/**
* Test that writing fails when the directory isn't writable.
*/
@Test
public void testFailedWrite() {
String path = methodDir.getAbsolutePath();
MetricsSystem ms = initMetricsSystem(path, false, false);
new MyMetrics1().registerWith(ms);
methodDir.setWritable(false);
MockSink.errored = false;
try {
// publish the metrics
ms.publishMetricsNow();
assertTrue("No exception was generated while writing metrics "
+ "even though the target directory was not writable",
MockSink.errored);
ms.stop();
ms.shutdown();
} finally {
// Make sure the dir is writable again so we can delete it at the end
methodDir.setWritable(true);
}
}
示例2: doWriteTest
import org.apache.hadoop.metrics2.MetricsSystem; //导入方法依赖的package包/类
/**
* Helper method that writes metrics files to a target path, reads those
* files, and returns the contents of all files as a single string. This
* method will assert that the correct number of files is found.
*
* @param ms an initialized MetricsSystem to use
* @param path the target path from which to read the logs
* @param count the number of log files to expect
* @return the contents of the log files
* @throws IOException when the log file can't be read
* @throws URISyntaxException when the target path is an invalid URL
*/
protected String doWriteTest(MetricsSystem ms, String path, int count)
throws IOException, URISyntaxException {
final String then = DATE_FORMAT.format(new Date());
MyMetrics1 mm1 = new MyMetrics1().registerWith(ms);
new MyMetrics2().registerWith(ms);
mm1.testMetric1.incr();
mm1.testMetric2.incr(2);
ms.publishMetricsNow(); // publish the metrics
ms.stop();
ms.shutdown();
return readLogFile(path, then, count);
}
示例3: testSilentFailedWrite
import org.apache.hadoop.metrics2.MetricsSystem; //导入方法依赖的package包/类
/**
* Test that writing fails silently when the directory is not writable.
*/
@Test
public void testSilentFailedWrite() {
String path = methodDir.getAbsolutePath();
MetricsSystem ms = initMetricsSystem(path, true, false);
new MyMetrics1().registerWith(ms);
methodDir.setWritable(false);
MockSink.errored = false;
try {
// publish the metrics
ms.publishMetricsNow();
assertFalse("An exception was generated while writing metrics "
+ "when the target directory was not writable, even though the "
+ "sink is set to ignore errors",
MockSink.errored);
ms.stop();
ms.shutdown();
} finally {
// Make sure the dir is writable again so we can delete it at the end
methodDir.setWritable(true);
}
}