/** * Expect a list of metrics with specific values. * Fail if not all metrics are received, or some metric has the wrong value. * @param report MetricReport. * @param expected map of expected metric names and their values * @throws IOException */ private void expectMetricsWithValues(MetricReport report, Map<String, Double> expected) throws IOException { List<Metric> metricIterator = report.getMetrics(); for (Metric metric : metricIterator) { if (expected.containsKey(metric.getName())) { Assert.assertEquals(expected.get(metric.getName()), metric.getValue()); expected.remove(metric.getName()); } } Assert.assertTrue(expected.isEmpty()); }
/** * Expect a set of metric names. Will fail if not all of these metrics are received. * @param report MetricReport * @param expected set of expected metric names * @param strict if set to true, will fail if receiving any metric that is not expected * @throws IOException */ private void expectMetrics(MetricReport report, Set<String> expected, boolean strict) throws IOException { List<Metric> metricIterator = report.getMetrics(); for (Metric metric : metricIterator) { //System.out.println(String.format("expectedSet.add(\"%s\")", metric.name)); if (expected.contains(metric.getName())) { expected.remove(metric.getName()); } else if (strict && !metric.getName().contains(MetricContext.GOBBLIN_METRICS_NOTIFICATIONS_TIMER_NAME)) { Assert.assertTrue(false, "Metric present in report not expected: " + metric.toString()); } } Assert.assertTrue(expected.isEmpty()); }