You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@flink.apache.org by "ASF GitHub Bot (JIRA)" <ji...@apache.org> on 2018/10/25 21:00:01 UTC

[jira] [Commented] (FLINK-6444) Add a check that '@VisibleForTesting' methods are only used in tests

    [ https://issues.apache.org/jira/browse/FLINK-6444?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16664278#comment-16664278 ] 

ASF GitHub Bot commented on FLINK-6444:
---------------------------------------

zentol closed pull request #4705: [FLINK-6444] [build] Add a check that '@VisibleForTesting' methods ar…
URL: https://github.com/apache/flink/pull/4705
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/flink-streaming-java/src/main/java/org/apache/flink/streaming/api/environment/StreamExecutionEnvironment.java b/flink-streaming-java/src/main/java/org/apache/flink/streaming/api/environment/StreamExecutionEnvironment.java
index 46c821edfa2..eb7dc3106f6 100644
--- a/flink-streaming-java/src/main/java/org/apache/flink/streaming/api/environment/StreamExecutionEnvironment.java
+++ b/flink-streaming-java/src/main/java/org/apache/flink/streaming/api/environment/StreamExecutionEnvironment.java
@@ -439,7 +439,7 @@ public CheckpointingMode getCheckpointingMode() {
 	 * from operations on {@link org.apache.flink.streaming.api.datastream.KeyedStream}) is maintained
 	 * (heap, managed memory, externally), and where state snapshots/checkpoints are stored, both for
 	 * the key/value state, and for checkpointed functions (implementing the interface
-	 * {@link org.apache.flink.streaming.api.checkpoint.Checkpointed}).
+	 * {@link org.apache.flink.streaming.api.checkpoint.ListCheckpointed}).
 	 *
 	 * <p>The {@link org.apache.flink.runtime.state.memory.MemoryStateBackend} for example
 	 * maintains the state in heap memory, as objects. It is lightweight without extra dependencies,
diff --git a/flink-tests/src/test/java/org/apache/flink/test/manual/CheckVisibleForTestingUsage.java b/flink-tests/src/test/java/org/apache/flink/test/manual/CheckVisibleForTestingUsage.java
new file mode 100644
index 00000000000..cb5f2cbecba
--- /dev/null
+++ b/flink-tests/src/test/java/org/apache/flink/test/manual/CheckVisibleForTestingUsage.java
@@ -0,0 +1,68 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flink.test.manual;
+
+import org.apache.flink.annotation.VisibleForTesting;
+
+import org.junit.Test;
+import org.reflections.Reflections;
+import org.reflections.scanners.MemberUsageScanner;
+import org.reflections.scanners.MethodAnnotationsScanner;
+import org.reflections.util.ClasspathHelper;
+import org.reflections.util.ConfigurationBuilder;
+
+import java.lang.reflect.Member;
+import java.lang.reflect.Method;
+import java.util.Set;
+
+import static org.junit.Assert.assertEquals;
+
+/**
+ * This test check the methods are annotated with @VisibleForTesting. But still was called from the class
+ * which does not belong to the tests. These methods should only be called from tests.
+ */
+public class CheckVisibleForTestingUsage {
+
+	@Test
+	public void testCheckVisibleForTesting() throws Exception {
+		ConfigurationBuilder configurationBuilder = new ConfigurationBuilder()
+			.useParallelExecutor(Runtime.getRuntime().availableProcessors())
+			.addUrls(ClasspathHelper.forPackage("org.apache.flink.core"))
+			.addScanners(
+				new MemberUsageScanner(),
+				new MethodAnnotationsScanner());
+
+		final Reflections reflections = new Reflections(configurationBuilder);
+
+		Set<Method> methods = reflections.getMethodsAnnotatedWith(VisibleForTesting.class);
+
+		for (Method method : methods) {
+			Set<Member> usages = reflections.getMethodUsage(method);
+			for (Member member : usages) {
+				if (member instanceof Method) {
+					Method visibleForTestingUsageScope = (Method) member;
+					if (!visibleForTestingUsageScope.isAnnotationPresent(Test.class)) {
+						assertEquals("Unexpected calls: " + visibleForTestingUsageScope.getDeclaringClass() + "#" + visibleForTestingUsageScope.getName(),
+							"Only Suggest used in tests.");
+					}
+				}
+			}
+		}
+	}
+}


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


> Add a check that '@VisibleForTesting' methods are only used in tests
> --------------------------------------------------------------------
>
>                 Key: FLINK-6444
>                 URL: https://issues.apache.org/jira/browse/FLINK-6444
>             Project: Flink
>          Issue Type: Improvement
>          Components: Build System
>            Reporter: Stephan Ewen
>            Assignee: zhangminglei
>            Priority: Major
>              Labels: pull-request-available
>
> Some methods are annotated with {{@VisibleForTesting}}. These methods should only be called from tests.
> This is currently not enforced / checked during the build. We should add such a check.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)