factory.setAttribute("mapred.class",
"org.apache.hadoop.metrics.spi.NoEmitMetricsContext");
TaskTracker tt = new TaskTracker();
tt.setConf(conf);
ShuffleServerMetrics shuffleMetrics = tt.new ShuffleServerMetrics(conf);
// first test with only MsgRegex set but doesn't match
String exceptionMsgRegex = "Broken pipe";
String exceptionStackRegex = null;
IOException ie = new IOException("EOFException");
testServlet.checkException(ie, exceptionMsgRegex, exceptionStackRegex,
shuffleMetrics);
MetricsContext context = factory.getContext("mapred");
shuffleMetrics.doUpdates(context);
Map<String, Collection<OutputRecord>> records = context.getAllRecords();
Collection<OutputRecord> col = records.get("shuffleOutput");
OutputRecord outputRecord = col.iterator().next();
assertEquals(0, outputRecord.getMetric("shuffle_exceptions_caught")
.intValue());
// test with only MsgRegex set that does match
ie = new IOException("Broken pipe");
testServlet.checkException(ie, exceptionMsgRegex, exceptionStackRegex,
shuffleMetrics);
shuffleMetrics.doUpdates(context);
assertEquals(1, outputRecord.getMetric("shuffle_exceptions_caught")
.intValue());
// test with neither set, make sure incremented
exceptionStackRegex = null;
exceptionMsgRegex = null;
testServlet.checkException(ie, exceptionMsgRegex, exceptionStackRegex,
shuffleMetrics);
shuffleMetrics.doUpdates(context);
assertEquals(2, outputRecord.getMetric("shuffle_exceptions_caught")
.intValue());
// test with only StackRegex set doesn't match
exceptionStackRegex = ".*\\.doesnt\\$SelectSet\\.wakeup.*";
exceptionMsgRegex = null;
ie.setStackTrace(constructStackTrace());
testServlet.checkException(ie, exceptionMsgRegex, exceptionStackRegex,
shuffleMetrics);
shuffleMetrics.doUpdates(context);
assertEquals(2, outputRecord.getMetric("shuffle_exceptions_caught")
.intValue());
// test with only StackRegex set does match
exceptionStackRegex = ".*\\.SelectorManager\\$SelectSet\\.wakeup.*";
testServlet.checkException(ie, exceptionMsgRegex, exceptionStackRegex,
shuffleMetrics);
shuffleMetrics.doUpdates(context);
assertEquals(3, outputRecord.getMetric("shuffle_exceptions_caught")
.intValue());
// test with both regex set and matches
exceptionMsgRegex = "Broken pipe";
ie.setStackTrace(constructStackTraceTwo());
testServlet.checkException(ie, exceptionMsgRegex, exceptionStackRegex,
shuffleMetrics);
shuffleMetrics.doUpdates(context);
assertEquals(4, outputRecord.getMetric("shuffle_exceptions_caught")
.intValue());
// test with both regex set and only msg matches
exceptionStackRegex = ".*[1-9]+BOGUSREGEX";
testServlet.checkException(ie, exceptionMsgRegex, exceptionStackRegex,
shuffleMetrics);
shuffleMetrics.doUpdates(context);
assertEquals(4, outputRecord.getMetric("shuffle_exceptions_caught")
.intValue());
// test with both regex set and only stack matches
exceptionStackRegex = ".*\\.SelectorManager\\$SelectSet\\.wakeup.*";
exceptionMsgRegex = "EOFException";
testServlet.checkException(ie, exceptionMsgRegex, exceptionStackRegex,
shuffleMetrics);
shuffleMetrics.doUpdates(context);
assertEquals(4, outputRecord.getMetric("shuffle_exceptions_caught")
.intValue());
}