MetricsInvariantChecker extends InvariantsChecker { @Override public void editSchedule() { collector.clear(); queueMetrics.getMetrics(collector, false); jvmMetrics.getMetrics(collector, false); for (MetricsRecord record : collector.getRecords()) { for (AbstractMetric am : record.metrics()) { bindings.put(am.name().replace(' ', '_'), am.value()); } } try { boolean allInvHold = (boolean) combinedInvariants.eval(bindings); if (!allInvHold) { for (Map.Entry<String, CompiledScript> e : invariants.entrySet()) { boolean invariantsHold = (boolean) e.getValue().eval(bindings); if (!invariantsHold) { Map<String, Object> matchingBindings = extractMatchingBindings(e.getKey(), bindings); logOrThrow("Invariant \"" + e.getKey() + "\" is NOT holding, with bindings: " + matchingBindings); } } } } catch (ScriptException e) { logOrThrow(e.getMessage()); } }  @Override void init(Configuration config, RMContext rmContext,
      ResourceScheduler scheduler); @Override void editSchedule(); static final String INVARIANTS_FILE; }
@Test(timeout = 5000) public void testManyRuns() { QueueMetrics qm = QueueMetrics.forQueue(metricsSystem, "root", null, false, conf); qm.setAvailableResourcesToQueue(RMNodeLabelsManager.NO_LABEL, Resource.newInstance(1, 1)); int numIterations = 1000; long start = System.currentTimeMillis(); for (int i = 0; i < numIterations; i++) { ic.editSchedule(); } long end = System.currentTimeMillis(); System.out.println("Runtime per iteration (avg of " + numIterations + " iterations): " + (end - start) + " tot time"); }