Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
Enable user to test their project in parallel. Add "test in parallel…
…" to the Drop-down menu and tool bar. Doing this by create a new class MyJUnitCore

    extended JunitCore which can run testsuite in parallel. It will be called in JUnitParallelTestRunner  that extended JUnitTestRunner.
    JUnitParallelTestRunner is called by  JUnitParallelTestManager  that  extended JUnitTestManager.
    All the test can pass.

    The files that changed or added
    modified: drjava/build.xml
    modified: drjava/src/edu/rice/cs/drjava/CommandLineTest.java
    modified: drjava/src/edu/rice/cs/drjava/DrJavaTestCase.java
    modified: drjava/src/edu/rice/cs/drjava/config/OptionConstants.java
    modified: drjava/src/edu/rice/cs/drjava/model/DJError.java
    modified: drjava/src/edu/rice/cs/drjava/model/GlobalModelJUnitTest.java
    modified: drjava/src/edu/rice/cs/drjava/model/junit/DefaultJUnitModel.java
    modified: drjava/src/edu/rice/cs/drjava/model/junit/JUnitErrorModelTest.java
    modified: drjava/src/edu/rice/cs/drjava/model/junit/JUnitModel.java
    new file: drjava/src/edu/rice/cs/drjava/model/junit/JUnitParallelTestManager.java
    new file: drjava/src/edu/rice/cs/drjava/model/junit/JUnitParallelTestRunner.java
    modified: drjava/src/edu/rice/cs/drjava/model/junit/JUnitTestManager.java
    modified: drjava/src/edu/rice/cs/drjava/model/junit/JUnitTestRunner.java
    new file: drjava/src/edu/rice/cs/drjava/model/junit/MyJUnitCore.java
    modified: drjava/src/edu/rice/cs/drjava/model/repl/newjvm/InterpreterJVM.java
    modified: drjava/src/edu/rice/cs/drjava/model/repl/newjvm/InterpreterJVMRemoteI.java
    modified: drjava/src/edu/rice/cs/drjava/model/repl/newjvm/MainJVM.java
    modified: drjava/src/edu/rice/cs/drjava/ui/ErrorPanel.java
    modified: drjava/src/edu/rice/cs/drjava/ui/JUnitPanel.java
    modified: drjava/src/edu/rice/cs/drjava/ui/MainFrame.java
    modified: drjava/src/edu/rice/cs/drjava/ui/coverage/CoverageFrame.java
    modified: drjava/src/edu/rice/cs/util/LogTest.java
  • Loading branch information
dapanghu committed May 3, 2018
commit 00f916cb57da16826f8191b9ea792f55e40981fc
104 changes: 98 additions & 6 deletions drjava/build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,13 @@
</taskdef>
<property name="coverage-report-dir" value="coverage_report"/>
<property name="coverage-exec" value="jacoco.exec"/>

<property name="TestParallel" value="${arg1}"/>
<fileset id="libs" dir="lib" includes="*.jar" /> <!-- Only include jars that are at the top level (not in buildlib) -->
<fileset id="jrelibs" dir="${java.home}/lib" includes="*.jar" />
<echo message="libs = ${toString:libs}" />
<echo message="jrelibs = ${toString:jrelibs}" />
<echo message="libs = ${toString:libs}" level="verbose" />
<echo message="jrelibs = ${toString:jrelibs}" level="verbose"/>
<fileset id="extlibs" dir="${java.home}/lib/ext" includes="*.jar" />
<echo message="extlibs = ${toString:extlibs}" />
<echo message="extlibs = ${toString:extlibs}" level="verbose"/>
<!-- ************
Help Targets
************ -->
Expand Down Expand Up @@ -345,7 +345,19 @@
<target name="iterate-tests" depends="resolve-test-formatter-class">
<!-- Calls do-test, unless that is overridden by the caller -->
<echo message="Executing iterate-tests" />
<property name="do-test-target" value="do-test" />
<if>
<equals arg1="${TestParallel}" arg2="true" />
<then>
<echo message="Test in Parallel" />
<property name="do-test-target" value="do-test-for" />
</then>
<else>
<echo message="Test in Sequential" />
<property name="do-test-target" value="do-test" />
</else>
</if>


<condition property="test-iteration-message">
<not>
<equals arg1="${test-repeat}" arg2="1" />
Expand Down Expand Up @@ -425,8 +437,50 @@
</if>

</target>




<target name="do-test-for" depends="resolve-jvm-args">
<echo message="Running all tests matching '${test-filter-string}' with command '${test-jvm}', using '${junit-jar}' and '${test-tools}'" />
<for param="fileFullName" parallel= "true" threadCount="16">
<path>
<fileset dir="classes/test">
<!--include name="**/*${test-filter-string}*/**" /-->
<include name="**/*Test.class" />
</fileset>
</path>
<sequential>
<echo message="file= @{fileFullName}" level="verbose"/>
<antcall target="execute-one-test" inheritRefs="true" inheritall="true">
<param name="fileFullName" value="@{fileFullName}"/>
</antcall>
</sequential>
</for>
<antcall target="generate-cover" />
</target>

<target name="do-test-foreach" depends="resolve-jvm-args">
<echo message="Running all tests matching '${test-filter-string}' with command '${test-jvm}', using '${junit-jar}' and '${test-tools}'" />
<foreach
target="execute-one-test"
maxthreads="16"
inheritall="true"
inheritrefs="true"
parallel="true"
param="fileFullName">
<path>
<fileset dir="classes/test">
<!--include name="**/*${test-filter-string}*/**" /-->
<include name="**/*Test.class" />
</fileset>
</path>
</foreach>
<antcall target="generate-cover" />
</target>



<target name="do-test" depends="resolve-jvm-args">
<echo message="Running all tests matching '${test-filter-string}' with command '${test-jvm}', using '${junit-jar}' and '${test-tools}'" />
<jacoco:coverage xmlns:jacoco="antlib:org.jacoco.ant">
Expand Down Expand Up @@ -463,6 +517,44 @@
<antcall target="generate-cover" />
</target>

<target name="execute-one-test">
<sequential>
<basename property="filename" file="${fileFullName}"/>
<echo message="In execute-one-test, we are running '${fileFullName}' with testname ${filename}" level="verbose" />
<jacoco:coverage xmlns:jacoco="antlib:org.jacoco.ant">
<junit haltonfailure="${test-halt}" failureproperty="test-failed"
fork="yes" forkmode="perTest" maxmemory="2G" jvm="${test-jvm}" dir="${basedir}">
<classpath>
<pathelement location="${test-tools}" />
<pathelement location="${junit-jar}" />
<pathelement location="lib/buildlib/plt-ant.jar" /> <!-- required for custom formatter -->
<pathelement location="lib/buildlib/netbeans-memory-leak-utils.jar" />
<pathelement location="classes/test" />
<pathelement location="classes/base" />
<pathelement location="classes/lib" />
</classpath>
<assertions>
<enable />
</assertions>
<syspropertyset>
<propertyref prefix="plt." />
<propertyref prefix="drjava." />
<!-- Add any properties that should be passed on -->
</syspropertyset>
<jvmarg line="${jvm-args}" />
<formatter classname="${test-formatter-class}" usefile="${test-output-to-file}" />
<!--test name="${test.source.absolute}"/-->
<batchtest fork="true">
<fileset dir="classes/test">
<include name="**/${filename}*" />
</fileset>
</batchtest>
</junit>
</jacoco:coverage>
<fail if="test-failed" message="One unit test failed."/>
</sequential>
</target>

<target name = "generate-cover" xmlns:jacoco="antlib:org.jacoco.ant">
<jacoco:report>

Expand Down
2 changes: 1 addition & 1 deletion drjava/src/edu/rice/cs/drjava/CommandLineTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -435,4 +435,4 @@ private void checkFile(File relativeFile, String funnyName)
// Close this doc to clean up after ourselves for the next check.
_mf.getModel().closeFile(doc);
}
}
}
2 changes: 1 addition & 1 deletion drjava/src/edu/rice/cs/drjava/DrJavaTestCase.java
Original file line number Diff line number Diff line change
Expand Up @@ -114,4 +114,4 @@ public void run() {
});
Utilities.clearEventQueue(); // ensure that all listener actions triggered by this document update have completed
}
}
}
16 changes: 16 additions & 0 deletions drjava/src/edu/rice/cs/drjava/config/OptionConstants.java
Original file line number Diff line number Diff line change
Expand Up @@ -431,10 +431,16 @@ public static Vector<KeyStroke> vector(KeyStroke... ks) {
public static final VectorOption<KeyStroke> KEY_COMPILE_PROJECT =
new VectorOption<KeyStroke>("key.compile.project", new KeyStrokeOption("",null), to.vector());

/** The key binding for testing a project in parallel. */
public static final VectorOption<KeyStroke> KEY_JUNIT_PROJECT_PARALLEL =
new VectorOption<KeyStroke>("key.junit.project", new KeyStrokeOption("",null), to.vector());


/** The key binding for testing a project. */
public static final VectorOption<KeyStroke> KEY_JUNIT_PROJECT =
new VectorOption<KeyStroke>("key.junit.project", new KeyStrokeOption("",null), to.vector());


/** The key binding for running a project. */
public static final VectorOption<KeyStroke> KEY_RUN_PROJECT =
new VectorOption<KeyStroke>("key.run.project", new KeyStrokeOption("",null), to.vector());
Expand Down Expand Up @@ -764,12 +770,20 @@ public static Vector<KeyStroke> vector(KeyStroke... ks) {
new VectorOption<KeyStroke>("key.test",
new KeyStrokeOption("",null),
to.vector(KeyStroke.getKeyStroke(KeyEvent.VK_T, MASK|SHIFT_MASK)));
/** The key binding for testing the current document in parallel. */
public static final VectorOption<KeyStroke> KEY_TEST_PARALLEL =
new VectorOption<KeyStroke>("key.reset.interactions", new KeyStrokeOption("",null), to.vector());


/** The key binding for testing all open JUnit test cases. */
public static final VectorOption<KeyStroke> KEY_TEST_ALL =
new VectorOption<KeyStroke>("key.test.all",
new KeyStrokeOption("",null),
to.vector(KeyStroke.getKeyStroke(KeyEvent.VK_T, MASK)));
/** The key binding for testing all open JUnit test cases in parallel. */
public static final VectorOption<KeyStroke> KEY_TEST_ALL_PARALLEL =
new VectorOption<KeyStroke>("key.reset.interactions", new KeyStrokeOption("",null), to.vector());


/** The key binding for generating javadoc for all documents */
public static final VectorOption<KeyStroke> KEY_JAVADOC_ALL =
Expand Down Expand Up @@ -807,6 +821,8 @@ public static Vector<KeyStroke> vector(KeyStroke... ks) {
public static final VectorOption<KeyStroke> KEY_RESET_INTERACTIONS =
new VectorOption<KeyStroke>("key.reset.interactions", new KeyStrokeOption("",null), to.vector());



/** The key binding for viewing the interactions classpath. */
public static final VectorOption<KeyStroke> KEY_VIEW_INTERACTIONS_CLASSPATH =
new VectorOption<KeyStroke>("key.view.interactions.classpath", new KeyStrokeOption("",null), to.vector());
Expand Down
14 changes: 13 additions & 1 deletion drjava/src/edu/rice/cs/drjava/model/DJError.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import java.io.Serializable;

import edu.rice.cs.util.FileOps;
import edu.rice.cs.util.Log;
import edu.rice.cs.util.UnexpectedException;


Expand All @@ -48,6 +49,10 @@
* @version $Id$
*/
public class DJError implements Comparable<DJError>, Serializable {

/** Debugging log. */
public static Log _log = new Log("DJError.txt", false);

private volatile File _file;

/** zero-based line number. */
Expand Down Expand Up @@ -78,6 +83,9 @@ public DJError(File file, int lineNumber, int startColumn, String message, boole
_startColumn = startColumn;
_message = message;
_isWarning = isWarning;
//TODO
_log.log("_lineNumber= "+_lineNumber);
_log.log("_file= "+_file);
if (lineNumber < 0) _noLocation = true;
}

Expand Down Expand Up @@ -127,7 +135,11 @@ public String fileName() {
/** Sets the line number.
* @param ln line number
*/
public void setLineNumber(int ln) { _lineNumber = ln; }
public void setLineNumber(int ln) {
//TODO
_log.log("in setLineNumber _lineNumber= "+_lineNumber);
_lineNumber = ln;
}

/** Gets the column where the error begins.
* @return the starting column
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -937,4 +937,3 @@ public void testJUnit4TwoMethod1Test_NOJOIN() throws Exception {
_log.log("testJUnit4TwoMethod1Test completed");
}
}

20 changes: 16 additions & 4 deletions drjava/src/edu/rice/cs/drjava/model/junit/DefaultJUnitModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,15 @@
* @version $Id$
*/
public class DefaultJUnitModel implements JUnitModel, JUnitModelCallback {

/**Set whether we should run the test in parallel, whenever use it, set it back to false*/
public static boolean runTestParallel=false;

private CoverageMetadata coverageMetadata = new CoverageMetadata(false, "");

/** log for use in debugging */
private static Log _log = new Log("GlobalModel.txt", false);
//needtodo
private static Log _log = new Log("DefaultJUnitModel.txt", true);

/** Manages listeners to this model. */
private final JUnitEventNotifier _notifier = new JUnitEventNotifier();
Expand Down Expand Up @@ -136,6 +140,11 @@ public DefaultJUnitModel(MainJVM jvm, CompilerModel compilerModel, SingleDisplay

//-------------------------- Field Setters --------------------------------//

public void setRunTestParallel(boolean testParallel) {
_log.log("setRunTestParallel= "+testParallel);
runTestParallel=testParallel;
}

public void setCoverage(boolean coverage, String outdirPath) {
this.coverageMetadata = new CoverageMetadata(coverage, outdirPath);
}
Expand Down Expand Up @@ -344,7 +353,8 @@ private void _rawJUnitOpenDefDocs(List<OpenDefinitionsDocument> lod, final boole
File sourceDir =
(buildDir == FileOps.NULL_FILE) ? classFileDir :
new File(IOUtil.attemptCanonicalFile(sourceRoot), packagePath);

_log.log("classFileDir= " + classFileDir + " sourceDir= " + sourceDir + " sourceRoot= "+sourceRoot);
_log.log("classDirsAndRoots= " + classDirsAndRoots);
if (! classDirsAndRoots.containsKey(classFileDir)) {
classDirsAndRoots.put(classFileDir, sourceDir);
_log.log("Adding " + classFileDir + " with source root " + sourceRoot + " to list of class directories");
Expand Down Expand Up @@ -429,7 +439,7 @@ public void visitEnd() { }

/** The canonical pathname for the file (including the file name) */
String javaSourceFileName = getCanonicalPath(rootDir) + File.separator + sourceName.value();

_log.log("javaSourceFileName= " + javaSourceFileName);
// System.err.println("Full java source fileName = " + javaSourceFileName);

/* The index in fileName of the dot preceding the extension ".java", ".dj", ".dj0*, ".dj1", or ".dj2" */
Expand Down Expand Up @@ -500,7 +510,9 @@ public void run() {
try {
_notifyJUnitStarted();
// The false return value could be changed to an exception.
boolean testsPresent = _jvm.runTestSuite();
_log.log("runTestParallel= "+runTestParallel);
boolean testsPresent = _jvm.runTestSuite(runTestParallel);
runTestParallel=false;
if (!testsPresent) {
throw new RemoteException("No unit test classes were passed to the slave JVM");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -426,5 +426,4 @@ public void run() {
debug.logEnd();
_log.log("testErrorInSuperClass_NOJOIN complete");
}
}

}
5 changes: 5 additions & 0 deletions drjava/src/edu/rice/cs/drjava/model/junit/JUnitModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,13 @@

public interface JUnitModel {


//-------------------------- Field Setters --------------------------------//

/** @param runTestParallel true if we run the test in parallel
*/
public void setRunTestParallel(boolean testParallel);

/** @param c true if a coverage report is desired; false otherwise
* @param p value to set the outdir path to
*/
Expand Down
Loading