Repository: incubator-beam Updated Branches: refs/heads/master bfd21d72f -> 98543e96f
Enable and fix DirectRunnerTest case missing @Test Improve MetricMatchers mismatch description Project: http://git-wip-us.apache.org/repos/asf/incubator-beam/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-beam/commit/cfb71e74 Tree: http://git-wip-us.apache.org/repos/asf/incubator-beam/tree/cfb71e74 Diff: http://git-wip-us.apache.org/repos/asf/incubator-beam/diff/cfb71e74 Branch: refs/heads/master Commit: cfb71e741d12544112f72a2a950204a07672bc25 Parents: bfd21d7 Author: bchambers <[email protected]> Authored: Fri Dec 9 14:05:30 2016 -0800 Committer: bchambers <[email protected]> Committed: Mon Dec 12 12:47:52 2016 -0800 ---------------------------------------------------------------------- .../beam/runners/direct/DirectRunnerTest.java | 7 ++- .../apache/beam/sdk/metrics/MetricMatchers.java | 45 +++++++++++++++++--- 2 files changed, 45 insertions(+), 7 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-beam/blob/cfb71e74/runners/direct-java/src/test/java/org/apache/beam/runners/direct/DirectRunnerTest.java ---------------------------------------------------------------------- diff --git a/runners/direct-java/src/test/java/org/apache/beam/runners/direct/DirectRunnerTest.java b/runners/direct-java/src/test/java/org/apache/beam/runners/direct/DirectRunnerTest.java index 3c860b1..eb0f344 100644 --- a/runners/direct-java/src/test/java/org/apache/beam/runners/direct/DirectRunnerTest.java +++ b/runners/direct-java/src/test/java/org/apache/beam/runners/direct/DirectRunnerTest.java @@ -467,6 +467,7 @@ public class DirectRunnerTest implements Serializable { } } + @Test public void testMetrics() throws Exception { Pipeline pipeline = getPipeline(); pipeline @@ -485,10 +486,12 @@ public class DirectRunnerTest implements Serializable { MetricQueryResults metrics = result.metrics().queryMetrics(MetricsFilter.builder() .addNameFilter(MetricNameFilter.inNamespace(DirectRunnerTest.class)) .build()); + + final String stepName = "MyStep/AnonymousParDo/AnonymousParMultiDo"; assertThat(metrics.counters(), contains( - metricResult(DirectRunnerTest.class.getName(), "count", "MyStep", 3L, 3L))); + metricResult(DirectRunnerTest.class.getName(), "count", stepName, 3L, 3L))); assertThat(metrics.distributions(), contains( - metricResult(DirectRunnerTest.class.getName(), "input", "MyStep", + metricResult(DirectRunnerTest.class.getName(), "input", stepName, DistributionResult.create(26L, 3L, 5L, 13L), DistributionResult.create(26L, 3L, 5L, 13L)))); } http://git-wip-us.apache.org/repos/asf/incubator-beam/blob/cfb71e74/sdks/java/core/src/test/java/org/apache/beam/sdk/metrics/MetricMatchers.java ---------------------------------------------------------------------- diff --git a/sdks/java/core/src/test/java/org/apache/beam/sdk/metrics/MetricMatchers.java b/sdks/java/core/src/test/java/org/apache/beam/sdk/metrics/MetricMatchers.java index bdcb94f..6cd4c52 100644 --- a/sdks/java/core/src/test/java/org/apache/beam/sdk/metrics/MetricMatchers.java +++ b/sdks/java/core/src/test/java/org/apache/beam/sdk/metrics/MetricMatchers.java @@ -72,15 +72,15 @@ public class MetricMatchers { public static <T> Matcher<MetricResult<T>> metricResult( final String namespace, final String name, final String step, - final T logical, final T physical) { + final T committed, final T attempted) { return new TypeSafeMatcher<MetricResult<T>>() { @Override protected boolean matchesSafely(MetricResult<T> item) { return Objects.equals(namespace, item.name().namespace()) && Objects.equals(name, item.name().name()) && Objects.equals(step, item.step()) - && Objects.equals(logical, item.committed()) - && Objects.equals(physical, item.attempted()); + && Objects.equals(committed, item.committed()) + && Objects.equals(attempted, item.attempted()); } @Override @@ -89,10 +89,45 @@ public class MetricMatchers { .appendText("MetricResult{inNamespace=").appendValue(namespace) .appendText(", name=").appendValue(name) .appendText(", step=").appendValue(step) - .appendText(", logical=").appendValue(logical) - .appendText(", physical=").appendValue(physical) + .appendText(", committed=").appendValue(committed) + .appendText(", attempted=").appendValue(attempted) .appendText("}"); } + + @Override + protected void describeMismatchSafely(MetricResult<T> item, Description mismatchDescription) { + mismatchDescription.appendText("MetricResult{"); + if (!Objects.equals(namespace, item.name().namespace())) { + mismatchDescription + .appendText("inNamespace: ").appendValue(namespace) + .appendText(" != ").appendValue(item.name().namespace()); + } + + if (!Objects.equals(name, item.name().name())) { + mismatchDescription + .appendText("name: ").appendValue(name) + .appendText(" != ").appendValue(item.name().name()); + } + + if (!Objects.equals(step, item.step())) { + mismatchDescription + .appendText("step: ").appendValue(step) + .appendText(" != ").appendValue(item.step()); + } + + if (!Objects.equals(committed, item.committed())) { + mismatchDescription + .appendText("committed: ").appendValue(committed) + .appendText(" != ").appendValue(item.committed()); + } + + if (!Objects.equals(attempted, item.attempted())) { + mismatchDescription + .appendText("attempted: ").appendValue(attempted) + .appendText(" != ").appendValue(item.attempted()); + } + mismatchDescription.appendText("}"); + } }; }
