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

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

Github user zhangminglei commented on a diff in the pull request:

    https://github.com/apache/flink/pull/4705#discussion_r145412067
  
    --- Diff: 
flink-tests/src/test/java/org/apache/flink/test/manual/CheckVisibleForTestingUsage.java
 ---
    @@ -0,0 +1,65 @@
    +/*
    + * 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 {
    +           final Reflections reflections = new Reflections(new 
ConfigurationBuilder()
    +                   
.useParallelExecutor(Runtime.getRuntime().availableProcessors())
    +                   .addUrls(ClasspathHelper.forPackage("org.apache.flink"))
    +                   .addScanners(new MemberUsageScanner(),
    +                           new MethodAnnotationsScanner()));
    +
    +           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 methodHopeWithTestAnnotation = 
(Method) member;
    --- End diff --
    
    Yeah. Thanks! I think it is an awesome name really!


> 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: mingleizhang
>
> 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
(v6.4.14#64029)

Reply via email to