fork tests: cleanup

This commit is contained in:
Anna Kozlova
2015-07-01 12:03:19 +03:00
parent 575d471aff
commit 9d6dbbcec9
5 changed files with 22 additions and 58 deletions
@@ -42,7 +42,7 @@ public abstract class ForkedStarter {
final PrintStream err = new PrintStream(new ForkedVMWrapper(stream, true));
System.setOut(out);
System.setErr(err);
startVM(args, out, err);
configureFrameworkAndRun(args, out, err);
}
finally {
System.setOut(oldOut);
@@ -141,18 +141,13 @@ public abstract class ForkedStarter {
return result;
}
protected abstract void startVM(String[] args, PrintStream out, PrintStream err) throws InstantiationException,
IllegalAccessException,
ClassNotFoundException;
protected int startForkedVM(String workingDirsPath,
String[] args,
String configName,
Object out,
Object err,
String forkMode,
String commandLinePath, List newArgs)
throws IOException, InstantiationException, IllegalAccessException, ClassNotFoundException, InterruptedException {
public int startForkedVM(String workingDirsPath,
String[] args,
String configName,
Object out,
Object err,
String forkMode,
String commandLinePath, List newArgs) throws Exception {
args = myForkedDebuggerStarter.excludeDebugPortFromArgs(args);
final List parameters = new ArrayList();
@@ -242,8 +237,7 @@ public abstract class ForkedStarter {
List classNames,
Object rootDescriptor) throws IOException;
protected abstract Object createRootDescription(String[] args, List newArgs, String configName, Object out, Object err)
throws InstantiationException, IllegalAccessException, ClassNotFoundException;
protected abstract Object createRootDescription(String[] args, List newArgs, String configName, Object out, Object err) throws Exception;
protected void sendTree(Object rootDescription) {}
protected void sendTime(long time) {}
@@ -261,4 +255,6 @@ public abstract class ForkedStarter {
}
protected abstract String getStarterName();
protected abstract void configureFrameworkAndRun(String[] args, PrintStream out, PrintStream err) throws Exception;
}
@@ -29,10 +29,7 @@ import java.util.List;
public class JUnitForkedStarter extends ForkedStarter {
private IdeaTestRunner myTestRunner;
JUnitForkedStarter() {
}
public static void main(String[] args) throws Exception {
new JUnitForkedStarter().startVM(args);
}
@@ -41,7 +38,7 @@ public class JUnitForkedStarter extends ForkedStarter {
return JUnitForkedStarter.class.getName();
}
protected void startVM(String[] args, PrintStream out, PrintStream err)
protected void configureFrameworkAndRun(String[] args, PrintStream out, PrintStream err)
throws InstantiationException, IllegalAccessException, ClassNotFoundException {
final int lastIdx = Integer.parseInt(args[1]);
final String[] childTestDescription = {args[2]};
@@ -56,21 +53,6 @@ public class JUnitForkedStarter extends ForkedStarter {
System.exit(testRunner.startRunnerWithArgs(childTestDescription, listeners, null, 1, false));
}
int startForkedVMs(String workingDirsPath,
String[] args,
boolean isJUnit4,
List listeners,
String configName,
Object out,
Object err,
String forkMode,
String commandLinePath) throws Exception {
List newArgs = new ArrayList();
newArgs.add(String.valueOf(isJUnit4));
newArgs.addAll(listeners);
return startForkedVM(workingDirsPath, args, configName, out, err, forkMode, commandLinePath, newArgs);
}
protected Object createRootDescription(String[] args, List newArgs, String configName, Object out, Object err)
throws InstantiationException, IllegalAccessException, ClassNotFoundException {
myTestRunner = (IdeaTestRunner)JUnitStarter.getAgentClass(Boolean.valueOf((String)newArgs.get(0)).booleanValue()).newInstance();
@@ -221,7 +221,10 @@ public class JUnitStarter {
}
if (ourCommandFileName != null) {
if (!"none".equals(ourForkMode) || ourWorkingDirs != null && new File(ourWorkingDirs).length() > 0) {
return new JUnitForkedStarter().startForkedVMs(ourWorkingDirs, args, isJUnit4, listeners, name, out, err, ourForkMode, ourCommandFileName);
final List newArgs = new ArrayList();
newArgs.add(String.valueOf(isJUnit4));
newArgs.addAll(listeners);
return new JUnitForkedStarter().startForkedVM(ourWorkingDirs, args, name, out, err, ourForkMode, ourCommandFileName, newArgs);
}
}
testRunner.setStreams(out, err, 0);
@@ -21,7 +21,6 @@
package org.testng;
import com.beust.jcommander.JCommander;
import com.intellij.rt.execution.junit.segments.SegmentedOutputStream;
import org.testng.remote.RemoteArgs;
import org.testng.remote.RemoteTestNG;
@@ -29,10 +28,7 @@ import java.io.*;
import java.lang.reflect.Method;
import java.net.InetAddress;
import java.net.Socket;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Map;
import java.util.Vector;
import java.util.*;
public class RemoteTestNGStarter {
public static boolean SM_RUNNER = System.getProperty("idea.testng.sm_runner") != null;
@@ -110,7 +106,8 @@ public class RemoteTestNGStarter {
if (SM_RUNNER) {
if (commandFileName != null) {
if (workingDirs != null && new File(workingDirs).length() > 0) {
System.exit(new TestNGForkedStarter().startForkedVMs(workingDirs, args, param, System.out, System.err, commandFileName));
System.exit(new TestNGForkedStarter()
.startForkedVM(workingDirs, args, param, System.out, System.err, "none", commandFileName, Collections.emptyList()));
return;
}
}
@@ -17,7 +17,6 @@ package org.testng;
import com.beust.jcommander.JCommander;
import com.intellij.rt.execution.junit.ForkedStarter;
import com.intellij.rt.execution.junit.segments.OutputObjectRegistry;
import org.testng.remote.RemoteArgs;
import java.io.File;
@@ -27,7 +26,6 @@ import java.util.*;
public class TestNGForkedStarter extends ForkedStarter {
public static void main(String[] args) throws Exception {
System.out.println("started");
new TestNGForkedStarter().startVM(args);
}
@@ -36,15 +34,6 @@ public class TestNGForkedStarter extends ForkedStarter {
return TestNGForkedStarter.class.getName();
}
int startForkedVMs(String workingDirsPath,
String[] args,
String configName,
Object out,
Object err,
String commandLinePath) throws Exception {
return startForkedVM(workingDirsPath, args, configName, out, err, "none", commandLinePath, Collections.emptyList());
}
@Override
protected List createChildArgsForClasses(List newArgs, String packageName, String workingDir, List classNames, Object rootDescriptor)
throws IOException {
@@ -57,14 +46,11 @@ public class TestNGForkedStarter extends ForkedStarter {
TestNGXmlSuiteHelper.Logger.DEAF);
file.deleteOnExit();
final List childArgs = new ArrayList();
childArgs.add(file.getAbsolutePath());
return childArgs;
return Collections.singletonList(file.getAbsolutePath());
}
@Override
protected void startVM(String[] args, PrintStream out, PrintStream err)
protected void configureFrameworkAndRun(String[] args, PrintStream out, PrintStream err)
throws InstantiationException, IllegalAccessException, ClassNotFoundException {
final IDEARemoteTestNG testNG = new IDEARemoteTestNG(null);
CommandLineArgs cla = new CommandLineArgs();