ponder-lab / Optimize-Java-8-Streams-Refactoring

Refactorings for optimizing Java 8 stream client code for greater parallelism and efficiency.
http://cuny.is/streams
Eclipse Public License 1.0
8 stars 7 forks source link

Generate entry_points.txt #175

Closed yiming-tang-cs closed 6 years ago

yiming-tang-cs commented 6 years ago

Related to #172.

khatchad commented 6 years ago

We need some test cases:

khatchad commented 6 years ago

img_20180205_102911823

yiming-tang-cs commented 6 years ago
  1. The above copy except that you add @EntryPoint to m(). This should pass because you now have an entry point. Done.

image

Remove @EntryPoint but add entry_points.txt to https://github.com/ponder-lab/Java-8-Stream-Refactoring/tree/master/edu.cuny.hunter.streamrefactoring.tests/resources/ConvertStreamToParallel/testEntryPointFile. The entry_points.txt file has the signature of the method, e.g., p.A.m();V (please check if it fails). This would should pass just like the first test.

It fails. The project directory is C:/Users/tangy/junit-workspace/TestProject1517962660629.

WARNING: Project: TestProject1517962660629 has no entry points.

yiming-tang-cs commented 6 years ago

It seems that the JUnit uses the different workspace instead of the default workspace. The project directory which is detected by the tool is under junit-workspace. Should we add a method to copy entry_points.txt into junit-workspace?

khatchad commented 6 years ago

Let's start with the project directory and add the workspace file later.

khatchad commented 6 years ago

Ok I see what you mean. It's not copying the txt file. We'll need to add some code to do that. Can you look into the testing infrastructure code and see where the source code is copied and see if you can also include the txt file? Otherwise, for now, you can debug the test by playing a breakpoint in the appropriate place and manually copy the txt file.

yiming-tang-cs commented 6 years ago

Ok I see what you mean. It's not copying the txt file. We'll need to add some code to do that. Can you look into the testing infrastructure code and see where the source code is copied and see if you can also include the txt file? Otherwise, for now, you can debug the test by playing a breakpoint in the appropriate place and manually copy the txt file.

I will look into the code tonight.

yiming-tang-cs commented 6 years ago

This is the way to copy source code:

https://github.com/ponder-lab/Java-8-Stream-Refactoring/blob/3cc5b1ec43da410a974fa20ee6b9c8979f85419e/edu.cuny.hunter.streamrefactoring.tests/test%20cases/edu/cuny/hunter/streamrefactoring/ui/tests/ConvertStreamToParallelRefactoringTest.java#L252

It is not just copying. The source code is from the method getPackageP() which is from org.eclipse.jdt.ui.tests and I cannot see its code.

yiming-tang-cs commented 6 years ago

Remove @EntryPoint but add entry_points.txt to https://github.com/ponder-lab/Java-8-Stream-Refactoring/tree/master/edu.cuny.hunter.streamrefactoring.tests/resources/ConvertStreamToParallel/testEntryPointFile. The entry_points.txt file has the signature of the method, e.g., p.A.m();V (please check if it fails). This would should pass just like the first test.

DONE. image

Same as test 2 but use q.A.m();V in entry_points.txt instead of p.A.m();V. This one should fail with no entry point error. There's no annotation and no match in the file.

DONE.

WARNING: Project: TestProject1518133667868 has no entry points.

After I changed the test code into

    public void testEntryPointFile() throws Exception {
        helper(new StreamAnalysisExpectedResult("h1.stream()", null, null, false, false, false, null, null, null,
                RefactoringStatus.ERROR, EnumSet.of(PreconditionFailure.NO_ENTRY_POINT)));
    }

, it could pass. image

Same as test 2 but move entry_points.txt to https://github.com/ponder-lab/Java-8-Stream-Refactoring/tree/master/edu.cuny.hunter.streamrefactoring.tests/resources/ConvertStreamToParallel. It should pass just the same as test 2.

DONE. image

yiming-tang-cs commented 6 years ago

After I investigate, the problem is from that the tool will scan the entry_points.txt regardless of this TXT file belongs to the project which the tool is evaluating.

I found that the each test cases shared a same project space while multiple projects were evaluating. In #415 (d395867), they all shared the space of TestProject1518139267942. When the tool tested testEntryPointFile, it copied a file entry_points.txt into TestProject1518139267942, but the junit did not delete the txt file after the test testEntryPointFile is finished. Then, when the following test cases start, the tool still scan the existed entry_points.txt and import explicit entry points from the file. For the most test cases, it is fine, because the most test cases only contain a package named p and a method names m. However, for the test case testCollectionFromParameter (code is shown below),

package p;

import java.util.HashSet;
import java.util.stream.*;

import edu.cuny.hunter.streamrefactoring.annotations.*;

class A {
    @EntryPoint
    void n() {
        m(new HashSet<Object>());
    }

    void m(HashSet<Object> h) {
        Stream<Object> stream = h.parallelStream();
        stream.distinct().count();
    }
}

, the old entry_points.txt is not enough. The tool thinks that old entry_points.txt belongs to this test case too and the tool imports explicit entry points from the old txt file, but those imported explicit entry points are not enough to evaluate this test case, that is why I got the error.

In addition, I've tested testCollectionFromParameter independently in my local computer. It past, which means my understanding is correct.

My suggestion, create a new fold for entry_points.txt and the name of fold is project name. Then, the tool can know which project the entry_points.txt belongs to.