@Override public long getInput() { return getTotalMetric(context, inputName); }
@Override public long getProcessed() { return getTotalMetric(context, processedName); }
@Override public long getProcessed() { return getTotalMetric(context, processedName); }
@Override public long getInput() { return getTotalMetric(context, inputName); }
@Override public long getException() { Preconditions.checkArgument(exceptionName != null, "exception count not supported"); return getTotalMetric(context, exceptionName); }
@Override public long getException() { Preconditions.checkArgument(exceptionName != null, "exception count not supported"); return getTotalMetric(context, exceptionName); }
/** * waitFor a metric value count for the metric identified by metricName and context. * @param tags - context identified by tags map * @param metricName * @param count - expected metric total count value * @param timeout * @param timeoutUnit * @throws TimeoutException * @throws InterruptedException */ public void waitForTotalMetricCount(Map<String, String> tags, String metricName, long count, long timeout, TimeUnit timeoutUnit) throws TimeoutException, InterruptedException { long value = getTotalMetric(tags, metricName); // Min sleep time is 10ms, max sleep time is 1 seconds long sleepMillis = Math.max(10, Math.min(timeoutUnit.toMillis(timeout) / 10, TimeUnit.SECONDS.toMillis(1))); Stopwatch stopwatch = new Stopwatch().start(); while (value < count && stopwatch.elapsedTime(timeoutUnit) < timeout) { TimeUnit.MILLISECONDS.sleep(sleepMillis); value = getTotalMetric(tags, metricName); } if (value < count) { throw new TimeoutException("Time limit reached: Expected '" + count + "' but got '" + value + "'"); } }
/** * waitFor a metric value count for the metric identified by metricName and context. * @param tags - context identified by tags map * @param metricName * @param count - expected metric total count value * @param timeout * @param timeoutUnit * @throws TimeoutException * @throws InterruptedException */ public void waitForTotalMetricCount(Map<String, String> tags, String metricName, long count, long timeout, TimeUnit timeoutUnit) throws TimeoutException, InterruptedException { long value = getTotalMetric(tags, metricName); // Min sleep time is 10ms, max sleep time is 1 seconds long sleepMillis = Math.max(10, Math.min(timeoutUnit.toMillis(timeout) / 10, TimeUnit.SECONDS.toMillis(1))); Stopwatch stopwatch = new Stopwatch().start(); while (value < count && stopwatch.elapsedTime(timeoutUnit) < timeout) { TimeUnit.MILLISECONDS.sleep(sleepMillis); value = getTotalMetric(tags, metricName); } if (value < count) { throw new TimeoutException("Time limit reached: Expected '" + count + "' but got '" + value + "'"); } }
@Test public void testMapReduceConsumer() throws Exception { testWordCountOnFileSet(new Function<ApplicationManager, ProgramManager>() { @Override public ProgramManager apply(ApplicationManager input) { return input.getMapReduceManager(AppWithPartitionConsumers.WordCountMapReduce.NAME).start(); } }, true); Map<String, String> tags = ImmutableMap.of(Constants.Metrics.Tag.NAMESPACE, "default", Constants.Metrics.Tag.APP, "AppWithPartitionConsumers", Constants.Metrics.Tag.MAPREDUCE, "WordCountMapReduce", Constants.Metrics.Tag.MR_TASK_TYPE, "r"); long totalIn = getMetricsManager().getTotalMetric(tags, "system.process.entries.in"); long totalOut = getMetricsManager().getTotalMetric(tags, "system.process.entries.out"); Assert.assertEquals(9, totalIn); Assert.assertEquals(10, totalOut); }
Constants.Metrics.Tag.SPARK, PythonSpark.class.getSimpleName()); Tasks.waitFor(100L, () -> getMetricsManager().getTotalMetric(tags, "user.body"), 5, TimeUnit.SECONDS, 100, TimeUnit.MILLISECONDS);
WorkflowAppWithLocalDatasets.LocalDatasetWriter.class.getSimpleName()); Assert.assertEquals(2, getMetricsManager().getTotalMetric(writerContext, "user.num.lines")); Assert.assertEquals(2, getMetricsManager().getTotalMetric(wfSparkMetricsContext, "user.num.lines")); sparkMetricsContext.put(Constants.Metrics.Tag.RUN_ID, nodeStateDetailMap.get("JavaSparkCSVToSpaceConverter").getRunId()); Assert.assertEquals(2, getMetricsManager().getTotalMetric(sparkMetricsContext, "user.num.lines")); appMetricsContext.put(Constants.Metrics.Tag.APP, applicationManager.getInfo().getName()); Assert.assertEquals(4, getMetricsManager().getTotalMetric(appMetricsContext, "user.num.lines")); Assert.assertEquals(7, getMetricsManager().getTotalMetric(wfMRMetricsContext, "user.num.words")); mrMetricsContext.put(Constants.Metrics.Tag.RUN_ID, nodeStateDetailMap.get("WordCount").getRunId()); Assert.assertEquals(7, getMetricsManager().getTotalMetric(mrMetricsContext, "user.num.words"));