flink-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From zhangminglei <...@git.apache.org>
Subject [GitHub] flink pull request #4705: [FLINK-6444] [build] Add a check that '@VisibleFor...
Date Wed, 18 Oct 2017 15:03:01 GMT
Github user zhangminglei commented on a diff in the pull request:

    https://github.com/apache/flink/pull/4705#discussion_r145443119
  
    --- 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;
    +					if (!methodHopeWithTestAnnotation.isAnnotationPresent(Test.class)) {
    --- End diff --
    
    I think it is a little bit hard to check whether the usage is in src/test path. I can
only get which invoked this method[ which modified by a @VisibleForTesting].  Like the following
picture. I can know which invoke the ```generateTablesForClass``` method. which are in usages
field. But It seems I can not figure out these classes whether come from ```src/path```. 
Only I can get belongs to it's target class path. Like: ```file:/D:/projects/flink/flink-core/target/classes/org/apache/flink/configuration/ConfigOptionsDocGenerator.class```.
That is to say, I can find where java class is loaded from. But I can not get it's source
code comes from.
    
    ![test](https://user-images.githubusercontent.com/6520673/31723324-1d529142-b451-11e7-9f85-a61d859702b0.png)



---

Mime
View raw message