Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 3E626200CDF for ; Sat, 1 Jul 2017 12:06:38 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 3D78B160BEA; Sat, 1 Jul 2017 10:06:38 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id E09EF160C02 for ; Sat, 1 Jul 2017 12:06:36 +0200 (CEST) Received: (qmail 28300 invoked by uid 500); 1 Jul 2017 10:06:36 -0000 Mailing-List: contact commits-help@flink.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@flink.apache.org Delivered-To: mailing list commits@flink.apache.org Received: (qmail 27963 invoked by uid 99); 1 Jul 2017 10:06:35 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 01 Jul 2017 10:06:35 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 354C1DFB30; Sat, 1 Jul 2017 10:06:34 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: chesnay@apache.org To: commits@flink.apache.org Date: Sat, 01 Jul 2017 10:06:39 -0000 Message-Id: <813a1ab8847442e98de2c88c1e1c2061@git.apache.org> In-Reply-To: <264d2d3033f84fe6a43362e72f53180d@git.apache.org> References: <264d2d3033f84fe6a43362e72f53180d@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [06/16] flink git commit: [FLINK-6785] [metrics] Fix ineffective asserts in MetricRegistryTest archived-at: Sat, 01 Jul 2017 10:06:38 -0000 [FLINK-6785] [metrics] Fix ineffective asserts in MetricRegistryTest This closes #4035. Project: http://git-wip-us.apache.org/repos/asf/flink/repo Commit: http://git-wip-us.apache.org/repos/asf/flink/commit/08580765 Tree: http://git-wip-us.apache.org/repos/asf/flink/tree/08580765 Diff: http://git-wip-us.apache.org/repos/asf/flink/diff/08580765 Branch: refs/heads/master Commit: 08580765ee0b604a2d878d3e1f06c059d6703824 Parents: daed460 Author: zentol Authored: Wed May 31 16:49:43 2017 +0200 Committer: zentol Committed: Sat Jul 1 10:02:07 2017 +0200 ---------------------------------------------------------------------- .../runtime/metrics/MetricRegistryTest.java | 63 ++++++++++++-------- 1 file changed, 38 insertions(+), 25 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/flink/blob/08580765/flink-runtime/src/test/java/org/apache/flink/runtime/metrics/MetricRegistryTest.java ---------------------------------------------------------------------- diff --git a/flink-runtime/src/test/java/org/apache/flink/runtime/metrics/MetricRegistryTest.java b/flink-runtime/src/test/java/org/apache/flink/runtime/metrics/MetricRegistryTest.java index 1de2551..0d77fbb 100644 --- a/flink-runtime/src/test/java/org/apache/flink/runtime/metrics/MetricRegistryTest.java +++ b/flink-runtime/src/test/java/org/apache/flink/runtime/metrics/MetricRegistryTest.java @@ -170,16 +170,19 @@ public class MetricRegistryTest extends TestLogger { config.setString(ConfigConstants.METRICS_REPORTER_PREFIX + "test.arg2", "world"); new MetricRegistry(MetricRegistryConfiguration.fromConfiguration(config)).shutdown(); + + Assert.assertEquals("hello", TestReporter2.mc.getString("arg1", null)); + Assert.assertEquals("world", TestReporter2.mc.getString("arg2", null)); } /** - * Reporter that verifies whether configured arguments were properly passed. + * Reporter that exposes the {@link MetricConfig} it was given. */ protected static class TestReporter2 extends TestReporter { + static MetricConfig mc; @Override public void open(MetricConfig config) { - Assert.assertEquals("hello", config.getString("arg1", null)); - Assert.assertEquals("world", config.getString("arg2", null)); + mc = config; } } @@ -246,57 +249,67 @@ public class MetricRegistryTest extends TestLogger { TaskManagerMetricGroup root = new TaskManagerMetricGroup(registry, "host", "id"); root.counter("rootCounter"); + + assertTrue(TestReporter6.addedMetric instanceof Counter); + assertEquals("rootCounter", TestReporter6.addedMetricName); + + assertTrue(TestReporter7.addedMetric instanceof Counter); + assertEquals("rootCounter", TestReporter7.addedMetricName); + root.close(); - assertTrue(TestReporter6.addCalled); - assertTrue(TestReporter6.removeCalled); - assertTrue(TestReporter7.addCalled); - assertTrue(TestReporter7.removeCalled); + assertTrue(TestReporter6.removedMetric instanceof Counter); + assertEquals("rootCounter", TestReporter6.removedMetricName); + + assertTrue(TestReporter7.removedMetric instanceof Counter); + assertEquals("rootCounter", TestReporter7.removedMetricName); registry.shutdown(); } /** - * Reporter that exposes whether it was notified of added or removed metrics. + * Reporter that exposes the name and metric instance of the last metric that was added or removed. */ protected static class TestReporter6 extends TestReporter { - public static boolean addCalled = false; - public static boolean removeCalled = false; + static Metric addedMetric; + static String addedMetricName; + + static Metric removedMetric; + static String removedMetricName; @Override public void notifyOfAddedMetric(Metric metric, String metricName, MetricGroup group) { - addCalled = true; - assertTrue(metric instanceof Counter); - assertEquals("rootCounter", metricName); + addedMetric = metric; + addedMetricName = metricName; } @Override public void notifyOfRemovedMetric(Metric metric, String metricName, MetricGroup group) { - removeCalled = true; - Assert.assertTrue(metric instanceof Counter); - Assert.assertEquals("rootCounter", metricName); + removedMetric = metric; + removedMetricName = metricName; } } /** - * Reporter that exposes whether it was notified of added or removed metrics. + * Reporter that exposes the name and metric instance of the last metric that was added or removed. */ protected static class TestReporter7 extends TestReporter { - public static boolean addCalled = false; - public static boolean removeCalled = false; + static Metric addedMetric; + static String addedMetricName; + + static Metric removedMetric; + static String removedMetricName; @Override public void notifyOfAddedMetric(Metric metric, String metricName, MetricGroup group) { - addCalled = true; - assertTrue(metric instanceof Counter); - assertEquals("rootCounter", metricName); + addedMetric = metric; + addedMetricName = metricName; } @Override public void notifyOfRemovedMetric(Metric metric, String metricName, MetricGroup group) { - removeCalled = true; - Assert.assertTrue(metric instanceof Counter); - Assert.assertEquals("rootCounter", metricName); + removedMetric = metric; + removedMetricName = metricName; } }