Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Motivating example test #88

Open
wants to merge 24 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
sudo: false
language: java
jdk: oraclejdk8
jdk: openjdk8
cache:
apt: true
directories:
- $HOME/.m2
services:
- xvfb
script: mvn clean verify -Pjacoco coveralls:report
before_install:
- "export DISPLAY=:99.0"
- "sh -e /etc/init.d/xvfb start"
notifications:
slack: cunyponder:A8GuEoj0voEn2H7MJDL1eNji
4 changes: 2 additions & 2 deletions edu.cuny.hunter.streamrefactoring.tests/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
</os>
</activation>
<properties>
<ui.test.vmargs>${tycho.testArgLine} -XstartOnFirstThread</ui.test.vmargs>
<ui.test.vmargs>${tycho.testArgLine} -XstartOnFirstThread -Xmx4g -XX:MaxPermSize=1g</ui.test.vmargs>
<argLine>${ui.test.vmargs}</argLine>
</properties>
</profile>
Expand All @@ -33,7 +33,7 @@
</activation>
<properties>
<ui.test.vmargs>${tycho.testArgLine}</ui.test.vmargs>
<argLine>${ui.test.vmargs}</argLine>
<argLine>${ui.test.vmargs} -Xmx4g -XX:MaxPermSize=1g</argLine>
</properties>
</profile>
</profiles>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import java.util.regex.Pattern;
import java.util.stream.Collectors;

import p.Widget.Color;

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

class Widget {
Expand Down Expand Up @@ -59,5 +61,30 @@ void m() {
// sequentially skip the first 1000 widgets and
// collect the remaining into a list.
List<Widget> skippedWidgetList = orderedWidgets.stream().skip(1000).collect(Collectors.toList());

Collection<Widget> orderedWidgets2 = orderedWidgets;

// collect the first green widgets into a list.
List<Widget> firstGreenList = orderedWidgets2.stream().filter(w -> w.getColor() == Color.GREEN).unordered()
.limit(5).collect(Collectors.toList());

Collection<Widget> orderedWidgets3 = orderedWidgets;

// collect distinct widget weights into a set.
Set<Double> distinctWeightSet = orderedWidgets3.stream().parallel().map(Widget::getWeight).distinct()
.collect(Collectors.toCollection(TreeSet::new));

// collect distinct widget colors into a HashSet.
Set<Color> distinctColorSet = orderedWidgets2.parallelStream().map(Widget::getColor).distinct()
.collect(HashSet::new, Set::add, Set::addAll);

// collect widget colors matching a regex.
Pattern pattern = Pattern.compile(".*e[a-z]");
ArrayList<String> results = new ArrayList<>();

Collection<Widget> orderedWidgets4 = orderedWidgets;

orderedWidgets4.stream().map(w -> w.getColor()).map(c -> c.toString()).filter(s -> pattern.matcher(s).matches())
.forEach(s -> results.add(s));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -625,12 +625,32 @@ public void testMotivatingExample() throws Exception {
Collections.emptySet()),

new StreamAnalysisExpectedResult("orderedWidgets.parallelStream()", EnumSet.of(ExecutionMode.PARALLEL),
EnumSet.of(Ordering.ORDERED), false, false, false, null, null, null, RefactoringStatus.ERROR,
EnumSet.of(Ordering.ORDERED), false, false, true, null, null, null, RefactoringStatus.ERROR,
EnumSet.of(PreconditionFailure.NO_STATEFUL_INTERMEDIATE_OPERATIONS)),

new StreamAnalysisExpectedResult("orderedWidgets.stream()", EnumSet.of(ExecutionMode.SEQUENTIAL),
EnumSet.of(Ordering.ORDERED), false, true, true, null, null, null, RefactoringStatus.ERROR,
EnumSet.of(PreconditionFailure.REDUCE_ORDERING_MATTERS)));
EnumSet.of(PreconditionFailure.REDUCE_ORDERING_MATTERS)),

new StreamAnalysisExpectedResult("orderedWidgets2.stream()", EnumSet.of(ExecutionMode.SEQUENTIAL),
EnumSet.of(Ordering.UNORDERED), false, true, true,
EnumSet.of(TransformationAction.CONVERT_TO_PARALLEL), PreconditionSuccess.P1,
Refactoring.CONVERT_SEQUENTIAL_STREAM_TO_PARALLEL, RefactoringStatus.OK,
Collections.emptySet()),

new StreamAnalysisExpectedResult("orderedWidgets3.stream()", EnumSet.of(ExecutionMode.PARALLEL),
EnumSet.of(Ordering.ORDERED), false, true, true,
EnumSet.of(TransformationAction.CONVERT_TO_SEQUENTIAL), PreconditionSuccess.P5,
Refactoring.OPTIMIZE_PARALLEL_STREAM, RefactoringStatus.OK, Collections.emptySet()),

new StreamAnalysisExpectedResult("orderedWidgets2.parallelStream()", EnumSet.of(ExecutionMode.PARALLEL),
EnumSet.of(Ordering.ORDERED), false, true, false, EnumSet.of(TransformationAction.UNORDER),
PreconditionSuccess.P4, Refactoring.OPTIMIZE_PARALLEL_STREAM, RefactoringStatus.OK,
Collections.emptySet()),

new StreamAnalysisExpectedResult("orderedWidgets4.stream()", EnumSet.of(ExecutionMode.SEQUENTIAL),
EnumSet.of(Ordering.ORDERED), true, false, false, null, null, null, RefactoringStatus.ERROR,
EnumSet.of(PreconditionFailure.HAS_SIDE_EFFECTS2)));
}

public void testTerminalOp1() throws Exception {
Expand Down
10 changes: 10 additions & 0 deletions scripts/keep_alive.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/bash
set -ev
function write_visual_bells() {
for i in `seq 1 40`; do
echo -en "\a"
sleep 1m
done
}
write_visual_bells&
mvn install