use of org.apache.hadoop.metrics2.util.MetricsCache.Record in project hadoop by apache.
the class TestGraphiteMetrics method testPutMetrics2.
@Test
public void testPutMetrics2() {
GraphiteSink sink = new GraphiteSink();
List<MetricsTag> tags = new ArrayList<MetricsTag>();
tags.add(new MetricsTag(MsInfo.Context, "all"));
tags.add(new MetricsTag(MsInfo.Hostname, null));
Set<AbstractMetric> metrics = new HashSet<AbstractMetric>();
metrics.add(makeMetric("foo1", 1));
metrics.add(makeMetric("foo2", 2));
MetricsRecord record = new MetricsRecordImpl(MsInfo.Context, (long) 10000, tags, metrics);
ArgumentCaptor<String> argument = ArgumentCaptor.forClass(String.class);
final GraphiteSink.Graphite mockGraphite = makeGraphite();
Whitebox.setInternalState(sink, "graphite", mockGraphite);
sink.putMetrics(record);
try {
verify(mockGraphite).write(argument.capture());
} catch (IOException e) {
e.printStackTrace();
}
String result = argument.getValue();
assertEquals(true, result.equals("null.all.Context.Context=all.foo1 1 10\n" + "null.all.Context.Context=all.foo2 2 10\n") || result.equals("null.all.Context.Context=all.foo2 2 10\n" + "null.all.Context.Context=all.foo1 1 10\n"));
}
use of org.apache.hadoop.metrics2.util.MetricsCache.Record in project hadoop by apache.
the class MetricsRecords method assertTag.
public static void assertTag(MetricsRecord record, String tagName, String expectedValue) {
MetricsTag processIdTag = getFirstTagByName(record, tagName);
assertNotNull(processIdTag);
assertEquals(expectedValue, processIdTag.value());
}
use of org.apache.hadoop.metrics2.util.MetricsCache.Record in project hadoop by apache.
the class MetricsRecords method assertMetric.
public static void assertMetric(MetricsRecord record, String metricName, Number expectedValue) {
AbstractMetric resourceLimitMetric = getFirstMetricByName(record, metricName);
assertNotNull(resourceLimitMetric);
assertEquals(expectedValue, resourceLimitMetric.value());
}
use of org.apache.hadoop.metrics2.util.MetricsCache.Record in project hadoop by apache.
the class MetricsRecords method getMetricValueByName.
public static Number getMetricValueByName(MetricsRecord record, String metricName) {
AbstractMetric resourceLimitMetric = getFirstMetricByName(record, metricName);
assertNotNull(resourceLimitMetric);
return resourceLimitMetric.value();
}
use of org.apache.hadoop.metrics2.util.MetricsCache.Record in project hadoop by apache.
the class TestNameNodeMetrics method waitForDnMetricValue.
/**
* Wait for the named gauge value from the metrics source to reach the
* desired value.
*
* There's an initial delay then a spin cycle of sleep and poll. Because
* all the tests use a shared FS instance, these tests are not independent;
* that's why the initial sleep is in there.
*
* @param source metrics source
* @param name gauge name
* @param expected expected value
* @return the last metrics record polled
* @throws Exception if something went wrong.
*/
private MetricsRecordBuilder waitForDnMetricValue(String source, String name, long expected) throws Exception {
MetricsRecordBuilder rb;
long gauge;
//initial wait.
waitForDeletion();
//lots of retries are allowed for slow systems; fast ones will still
//exit early
int retries = (DATANODE_COUNT + 1) * WAIT_GAUGE_VALUE_RETRIES;
rb = getMetrics(source);
gauge = MetricsAsserts.getLongGauge(name, rb);
while (gauge != expected && (--retries > 0)) {
Thread.sleep(DFS_REDUNDANCY_INTERVAL * 500);
rb = getMetrics(source);
gauge = MetricsAsserts.getLongGauge(name, rb);
}
//at this point the assertion is valid or the retry count ran out
assertGauge(name, expected, rb);
return rb;
}
Aggregations