From 708771b8802df4dfa0ecbcec72e5ab52f0b53fc5 Mon Sep 17 00:00:00 2001 From: "Anna.Kozlova" Date: Tue, 24 May 2016 16:58:22 +0200 Subject: [PATCH] pass repeat count to fork vms --- .../ForkedByModuleSplitter.java | 18 ++++++++++------- .../testFrameworks/ForkedSplitter.java | 20 +++++++++---------- .../execution/junit/JUnitForkedStarter.java | 14 +++++++++++-- .../rt/execution/junit/JUnitStarter.java | 7 +++++-- .../testng/configuration/TestNGForkTest.java | 4 ++-- .../src/org/testng/RemoteTestNGStarter.java | 3 +-- .../src/org/testng/TestNGForkedSplitter.java | 8 ++++---- 7 files changed, 45 insertions(+), 29 deletions(-) diff --git a/java/java-runtime/src/com/intellij/rt/execution/testFrameworks/ForkedByModuleSplitter.java b/java/java-runtime/src/com/intellij/rt/execution/testFrameworks/ForkedByModuleSplitter.java index e6b434cd8801..dd9e15fc794f 100644 --- a/java/java-runtime/src/com/intellij/rt/execution/testFrameworks/ForkedByModuleSplitter.java +++ b/java/java-runtime/src/com/intellij/rt/execution/testFrameworks/ForkedByModuleSplitter.java @@ -43,7 +43,8 @@ public abstract class ForkedByModuleSplitter { public int startSplitting(String[] args, String configName, - String commandLinePath) throws Exception { + String commandLinePath, + String repeatCount) throws Exception { args = myForkedDebuggerHelper.excludeDebugPortFromArgs(args); myVMParameters = new ArrayList(); @@ -60,14 +61,14 @@ public abstract class ForkedByModuleSplitter { } long time = System.currentTimeMillis(); - int result = startSplitting(args, configName); + int result = startSplitting(args, configName, repeatCount); myForkedDebuggerHelper.closeDebugSocket(); sendTime(time); return result; } //read output from wrappers - protected int startChildFork(List args, File workingDir, String classpath) throws IOException, InterruptedException { + protected int startChildFork(List args, File workingDir, String classpath, String repeatCount) throws IOException, InterruptedException { List vmParameters = new ArrayList(myVMParameters); myForkedDebuggerHelper.setupDebugger(vmParameters); @@ -94,6 +95,9 @@ public abstract class ForkedByModuleSplitter { builder.add(getStarterName()); builder.add(testOutputPath); builder.add(args); + if (repeatCount != null) { + builder.add(repeatCount); + } builder.setWorkingDir(workingDir); final Process exec = builder.createProcess(); @@ -103,7 +107,7 @@ public abstract class ForkedByModuleSplitter { } //read file with classes grouped by module - protected int splitPerModule() throws IOException { + protected int splitPerModule(String repeatCount) throws IOException { int result = 0; final BufferedReader perDirReader = new BufferedReader(new FileReader(myWorkingDirsPath)); try { @@ -126,7 +130,7 @@ public abstract class ForkedByModuleSplitter { classNames.add(className); } - final int childResult = startPerModuleFork(moduleName, classNames, packageName, workingDir, classpath, result); + final int childResult = startPerModuleFork(moduleName, classNames, packageName, workingDir, classpath, repeatCount, result); result = Math.min(childResult, result); } catch (Exception e) { @@ -140,14 +144,14 @@ public abstract class ForkedByModuleSplitter { return result; } - protected abstract int startSplitting(String[] args, String configName) throws Exception; + protected abstract int startSplitting(String[] args, String configName, String repeatCount) throws Exception; protected abstract int startPerModuleFork(String moduleName, List classNames, String packageName, String workingDir, String classpath, - int result) throws Exception; + String repeatCount, int result) throws Exception; protected abstract String getStarterName(); diff --git a/java/java-runtime/src/com/intellij/rt/execution/testFrameworks/ForkedSplitter.java b/java/java-runtime/src/com/intellij/rt/execution/testFrameworks/ForkedSplitter.java index 411d1cc618e6..3b9b8b282f78 100644 --- a/java/java-runtime/src/com/intellij/rt/execution/testFrameworks/ForkedSplitter.java +++ b/java/java-runtime/src/com/intellij/rt/execution/testFrameworks/ForkedSplitter.java @@ -31,7 +31,8 @@ public abstract class ForkedSplitter extends ForkedByModuleSplitter { } protected int startSplitting(String[] args, - String configName) throws Exception { + String configName, + String repeatCount) throws Exception { myRootDescription = createRootDescription(args, configName); if (myRootDescription == null) { return -1; @@ -40,11 +41,10 @@ public abstract class ForkedSplitter extends ForkedByModuleSplitter { if (myWorkingDirsPath == null || new File(myWorkingDirsPath).length() == 0) { final List children = getChildren(myRootDescription); final boolean forkTillMethod = myForkMode.equalsIgnoreCase("method"); - return splitChildren(children, 0, forkTillMethod, null, System.getProperty("java.class.path") - ); + return splitChildren(children, 0, forkTillMethod, null, System.getProperty("java.class.path"), repeatCount); } else { - return splitPerModule(); + return splitPerModule(repeatCount); } } @@ -53,10 +53,10 @@ public abstract class ForkedSplitter extends ForkedByModuleSplitter { String packageName, String workingDir, String classpath, - int result) throws Exception { + String repeatCount, int result) throws Exception { if (myForkMode.equals("none")) { final List childArgs = createPerModuleArgs(packageName, workingDir, classNames, myRootDescription); - return startChildFork(childArgs, new File(workingDir), classpath); + return startChildFork(childArgs, new File(workingDir), classpath, repeatCount); } else { final List children = new ArrayList(getChildren(myRootDescription)); @@ -66,7 +66,7 @@ public abstract class ForkedSplitter extends ForkedByModuleSplitter { } } final boolean forkTillMethod = myForkMode.equalsIgnoreCase("method"); - return splitChildren(children, result, forkTillMethod, new File(workingDir), classpath); + return splitChildren(children, result, forkTillMethod, new File(workingDir), classpath, repeatCount); } } @@ -74,16 +74,16 @@ public abstract class ForkedSplitter extends ForkedByModuleSplitter { int result, boolean forkTillMethod, File workingDir, - String classpath) throws IOException, InterruptedException { + String classpath, String repeatCount) throws IOException, InterruptedException { for (int i = 0, argsLength = children.size(); i < argsLength; i++) { final Object child = children.get(i); final List childTests = getChildren(child); final int childResult; if (childTests.isEmpty() || !forkTillMethod) { - childResult = startChildFork(createChildArgs(child), workingDir, classpath); + childResult = startChildFork(createChildArgs(child), workingDir, classpath, repeatCount); } else { - childResult = splitChildren(childTests, result, forkTillMethod, workingDir, classpath); + childResult = splitChildren(childTests, result, forkTillMethod, workingDir, classpath, repeatCount); } result = Math.min(childResult, result); } diff --git a/plugins/junit_rt/src/com/intellij/rt/execution/junit/JUnitForkedStarter.java b/plugins/junit_rt/src/com/intellij/rt/execution/junit/JUnitForkedStarter.java index 6aec02979bc1..2c7d2863360b 100644 --- a/plugins/junit_rt/src/com/intellij/rt/execution/junit/JUnitForkedStarter.java +++ b/plugins/junit_rt/src/com/intellij/rt/execution/junit/JUnitForkedStarter.java @@ -20,11 +20,21 @@ import com.intellij.rt.execution.testFrameworks.ChildVMStarter; import java.io.PrintStream; import java.util.ArrayList; +import java.util.List; public class JUnitForkedStarter extends ChildVMStarter { public static void main(String[] args) throws Exception { - new JUnitForkedStarter().startVM(args); + List argList = new ArrayList(); + for (int i = 0; i < args.length; i++) { + final int count = RepeatCount.getCount(args[i]); + if (count > 0) { + JUnitStarter.ourCount = count; + continue; + } + argList.add(args[i]); + } + new JUnitForkedStarter().startVM((String[])argList.toArray(new String[argList.size()])); } protected void configureFrameworkAndRun(String[] args, PrintStream out, PrintStream err) @@ -39,7 +49,7 @@ public class JUnitForkedStarter extends ChildVMStarter { IdeaTestRunner testRunner = (IdeaTestRunner)JUnitStarter.getAgentClass(argentName).newInstance(); //noinspection IOResourceOpenedButNotSafelyClosed testRunner.setStreams(new SegmentedOutputStream(out, true), new SegmentedOutputStream(err, true), lastIdx); - System.exit(testRunner.startRunnerWithArgs(childTestDescription, listeners, null, 1, false)); + System.exit(testRunner.startRunnerWithArgs(childTestDescription, listeners, null, JUnitStarter.ourCount, false)); } } diff --git a/plugins/junit_rt/src/com/intellij/rt/execution/junit/JUnitStarter.java b/plugins/junit_rt/src/com/intellij/rt/execution/junit/JUnitStarter.java index 2166410daa29..dbd1957f8f7c 100644 --- a/plugins/junit_rt/src/com/intellij/rt/execution/junit/JUnitStarter.java +++ b/plugins/junit_rt/src/com/intellij/rt/execution/junit/JUnitStarter.java @@ -21,6 +21,7 @@ import java.io.*; import java.net.InetAddress; import java.net.Socket; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import java.util.Vector; @@ -45,8 +46,9 @@ public class JUnitStarter { private static String ourForkMode; private static String ourCommandFileName; private static String ourWorkingDirs; - private static int ourCount = 1; + protected static int ourCount = 1; public static boolean SM_RUNNER = isSmRunner(); + public static String ourRepeatCount = null; private static boolean isSmRunner() { try { @@ -147,6 +149,7 @@ public class JUnitStarter { final int count = RepeatCount.getCount(arg); if (count != 0) { + ourRepeatCount = arg; ourCount = count; continue; } @@ -243,7 +246,7 @@ public class JUnitStarter { PrintStream printOutputStream = SM_RUNNER ? ((PrintStream)out) : ((SegmentedOutputStream)out).getPrintStream(); PrintStream printErrStream = SM_RUNNER ? ((PrintStream)err) : ((SegmentedOutputStream)err).getPrintStream(); return new JUnitForkedSplitter(ourWorkingDirs, ourForkMode, printOutputStream, printErrStream, newArgs) - .startSplitting(args, name, ourCommandFileName); + .startSplitting(args, name, ourCommandFileName, ourRepeatCount); } } testRunner.setStreams(out, err, 0); diff --git a/plugins/testng/testSources/com/theoryinpractice/testng/configuration/TestNGForkTest.java b/plugins/testng/testSources/com/theoryinpractice/testng/configuration/TestNGForkTest.java index 2dba33660121..809a5d0dcd10 100644 --- a/plugins/testng/testSources/com/theoryinpractice/testng/configuration/TestNGForkTest.java +++ b/plugins/testng/testSources/com/theoryinpractice/testng/configuration/TestNGForkTest.java @@ -48,7 +48,7 @@ public class TestNGForkTest { new TestNGForkedSplitter(tempFile.getCanonicalPath(), System.out, System.err, Collections.singletonList(tempFile.getCanonicalPath())) { private boolean myStarted = false; @Override - protected int startChildFork(List args, File workingDir, String classpath) throws IOException, InterruptedException { + protected int startChildFork(List args, File workingDir, String classpath, String repeatCount) throws IOException, InterruptedException { Assert.assertEquals(dynamicClasspath, myDynamicClasspath); Assert.assertArrayEquals(vmParams, myVMParameters.toArray()); Assert.assertEquals(workingDirFromFile, workingDir.getName()); @@ -68,7 +68,7 @@ public class TestNGForkTest { myStarted = true; return 0; } - }.startSplitting(ArrayUtil.EMPTY_STRING_ARRAY, "", commandLineFile.getCanonicalPath()); + }.startSplitting(ArrayUtil.EMPTY_STRING_ARRAY, "", commandLineFile.getCanonicalPath(), null); } finally { FileUtil.delete(tempDirectory); diff --git a/plugins/testng_rt/src/org/testng/RemoteTestNGStarter.java b/plugins/testng_rt/src/org/testng/RemoteTestNGStarter.java index 01ea860ac5f0..81feb74177c5 100644 --- a/plugins/testng_rt/src/org/testng/RemoteTestNGStarter.java +++ b/plugins/testng_rt/src/org/testng/RemoteTestNGStarter.java @@ -22,7 +22,6 @@ package org.testng; import com.beust.jcommander.JCommander; import com.intellij.rt.execution.testFrameworks.ForkedDebuggerHelper; -import org.testng.remote.RemoteArgs; import org.testng.remote.RemoteTestNG; import java.io.*; @@ -114,7 +113,7 @@ public class RemoteTestNGStarter { if (commandFileName != null) { if (workingDirs != null && new File(workingDirs).length() > 0) { System.exit(new TestNGForkedSplitter(workingDirs, System.out, System.err, newArgs) - .startSplitting(args, param, commandFileName)); + .startSplitting(args, param, commandFileName, null)); return; } } diff --git a/plugins/testng_rt/src/org/testng/TestNGForkedSplitter.java b/plugins/testng_rt/src/org/testng/TestNGForkedSplitter.java index 76a1225615c2..dbb9b88d9426 100644 --- a/plugins/testng_rt/src/org/testng/TestNGForkedSplitter.java +++ b/plugins/testng_rt/src/org/testng/TestNGForkedSplitter.java @@ -38,8 +38,8 @@ public class TestNGForkedSplitter extends ForkedByModuleSplitter { @Override protected int startSplitting(String[] args, - String configName) throws Exception { - return splitPerModule(); + String configName, String repeatCount) throws Exception { + return splitPerModule(repeatCount); } @Override @@ -48,7 +48,7 @@ public class TestNGForkedSplitter extends ForkedByModuleSplitter { String packageName, String workingDir, String classpath, - int result) throws Exception { + String repeatCount, int result) throws Exception { final LinkedHashMap>> classes = new LinkedHashMap>>(); for (Object className : classNames) { classes.put((String)className, null); @@ -63,7 +63,7 @@ public class TestNGForkedSplitter extends ForkedByModuleSplitter { TestNGXmlSuiteHelper.writeSuite(classes, new LinkedHashMap(), moduleName, rootPath, TestNGXmlSuiteHelper.Logger.DEAF); file.deleteOnExit(); - return Math.min(result, startChildFork(Collections.singletonList(file.getAbsolutePath()), new File(workingDir), classpath)); + return Math.min(result, startChildFork(Collections.singletonList(file.getAbsolutePath()), new File(workingDir), classpath, repeatCount)); } }