diff --git a/src/main/java/org/testng/CommandLineArgs.java b/src/main/java/org/testng/CommandLineArgs.java
index fafb197afd..6a5d8e9f82 100644
--- a/src/main/java/org/testng/CommandLineArgs.java
+++ b/src/main/java/org/testng/CommandLineArgs.java
@@ -126,14 +126,6 @@ public class CommandLineArgs {
@Parameter(names = HOST, description = "The host", hidden = true)
public String host;
- public static final String MASTER = "-master";
- @Parameter(names = MASTER, description = "Host where the master is", hidden = true)
- public String master;
-
- public static final String SLAVE = "-slave";
- @Parameter(names = SLAVE, description = "Host where the slave is", hidden = true)
- public String slave;
-
public static final String METHODS = "-methods";
@Parameter(names = METHODS, description = "Comma separated of test methods",
splitter = CommaParameterSplitter.class)
diff --git a/src/main/java/org/testng/TestNG.java b/src/main/java/org/testng/TestNG.java
index 6d2cfb269f..7d20abfa84 100644
--- a/src/main/java/org/testng/TestNG.java
+++ b/src/main/java/org/testng/TestNG.java
@@ -43,8 +43,6 @@
import org.testng.internal.thread.graph.SuiteWorkerFactory;
import org.testng.junit.JUnitTestFinder;
import org.testng.log4testng.Logger;
-import org.testng.remote.SuiteDispatcher;
-import org.testng.remote.SuiteSlave;
import org.testng.reporters.EmailableReporter;
import org.testng.reporters.EmailableReporter2;
import org.testng.reporters.FailedReporter;
@@ -153,9 +151,6 @@ public class TestNG {
private int m_status;
private boolean m_hasTests= false;
- private String m_slavefileName = null;
- private String m_masterfileName = null;
-
// Command line suite parameters
private int m_threadCount = -1;
private XmlSuite.ParallelMode m_parallelMode = null;
@@ -1049,31 +1044,7 @@ public void run() {
runExecutionListeners(true /* start */);
m_start = System.currentTimeMillis();
-
- //
- // Slave mode
- //
- if (m_slavefileName != null) {
- SuiteSlave slave = new SuiteSlave( m_slavefileName, this );
- slave.waitForSuites();
- }
-
- //
- // Regular mode
- //
- else if (m_masterfileName == null) {
- suiteRunners = runSuitesLocally();
- }
-
- //
- // Master mode
- //
- else {
- SuiteDispatcher dispatcher = new SuiteDispatcher(m_masterfileName);
- suiteRunners = dispatcher.dispatch(getConfiguration(),
- m_suites, getOutputDirectory(),
- getTestListeners());
- }
+ suiteRunners = runSuites();
m_end = System.currentTimeMillis();
runExecutionListeners(false /* finish */);
@@ -1091,8 +1062,17 @@ m_suites, getOutputDirectory(),
}
}
- private void p(String string) {
- System.out.println("[TestNG] " + string);
+ /**
+ * Run the test suites.
+ *
+ * This method can be overridden by subclass.
+ * For example, DistributedTestNG to run in master/slave mode according to commandline args.
+ *
+ * @return
+ * @since 6.9.11 when moving distributed/remote classes out into separate project
+ */
+ protected List runSuites() {
+ return runSuitesLocally();
}
private void runSuiteAlterationListeners() {
@@ -1441,8 +1421,6 @@ protected void configure(CommandLineArgs cla) {
setXmlPathInJar(cla.xmlPathInJar);
setJUnit(cla.junit);
setMixed(cla.mixed);
- setMaster(cla.master);
- setSlave(cla.slave);
setSkipFailedInvocationCounts(cla.skipFailedInvocationCounts);
if (cla.parallelMode != null) {
setParallel(cla.parallelMode);
@@ -1578,8 +1556,6 @@ public void configure(Map cmdLineArgs) {
result.xmlPathInJar = (String) cmdLineArgs.get(CommandLineArgs.XML_PATH_IN_JAR);
result.junit = (Boolean) cmdLineArgs.get(CommandLineArgs.JUNIT);
result.mixed = (Boolean) cmdLineArgs.get(CommandLineArgs.MIXED);
- result.master = (String) cmdLineArgs.get(CommandLineArgs.MASTER);
- result.slave = (String) cmdLineArgs.get(CommandLineArgs.SLAVE);
result.skipFailedInvocationCounts = (Boolean) cmdLineArgs.get(
CommandLineArgs.SKIP_FAILED_INVOCATION_COUNTS);
String parallelMode = (String) cmdLineArgs.get(CommandLineArgs.PARALLEL);
@@ -1672,24 +1648,6 @@ private void addReporter(ReporterConfig reporterConfig) {
}
}
- /**
- * Specify if this run should be in Master-Slave mode as Master
- *
- * @param fileName remote.properties path
- */
- public void setMaster(String fileName) {
- m_masterfileName = fileName;
- }
-
- /**
- * Specify if this run should be in Master-Slave mode as slave
- *
- * @param fileName remote.properties path
- */
- public void setSlave(String fileName) {
- m_slavefileName = fileName;
- }
-
/**
* Specify if this run should be made in JUnit mode
*
@@ -1735,10 +1693,9 @@ protected static void validateCommandLineParameters(CommandLineArgs args) {
String testClasses = args.testClass;
List testNgXml = args.suiteFiles;
String testJar = args.testJar;
- String slave = args.slave;
List methods = args.commandLineMethods;
- if (testClasses == null && slave == null && testJar == null
+ if (testClasses == null && testJar == null
&& (testNgXml == null || testNgXml.isEmpty())
&& (methods == null || methods.isEmpty())) {
throw new ParameterException("You need to specify at least one testng.xml, one class"
@@ -1754,11 +1711,6 @@ protected static void validateCommandLineParameters(CommandLineArgs args) {
throw new ParameterException("Groups option should be used with testclass option");
}
- if (args.slave != null && args.master != null) {
- throw new ParameterException(CommandLineArgs.SLAVE + " can't be combined with "
- + CommandLineArgs.MASTER);
- }
-
Boolean junit = args.junit;
Boolean mixed = args.mixed;
if (junit && mixed) {
diff --git a/src/main/java/org/testng/internal/remote/SlavePool.java b/src/main/java/org/testng/internal/remote/SlavePool.java
deleted file mode 100755
index 03b859f862..0000000000
--- a/src/main/java/org/testng/internal/remote/SlavePool.java
+++ /dev/null
@@ -1,64 +0,0 @@
-package org.testng.internal.remote;
-
-import org.testng.collections.Maps;
-import org.testng.remote.ConnectionInfo;
-
-import java.io.IOException;
-import java.net.Socket;
-import java.util.Map;
-
-
-/**
- * This class maintains a pool of slaves (represented by sockets).
- *
- * @author cbeust
- */
-public class SlavePool {
- private static SocketLinkedBlockingQueue m_hosts = new SocketLinkedBlockingQueue();
- private static Map m_connectionInfos = Maps.newHashMap();
-
- public void addSlaves(Socket[] slaves) throws IOException {
- for (Socket s : slaves) {
- addSlave(s);
- }
- }
-
- public void addSlave(Socket s) {
- if( s==null) {
- return;
- }
- ConnectionInfo ci = new ConnectionInfo();
- ci.setSocket(s);
- addSlave(s, ci);
- }
-
- private void addSlave(Socket s, ConnectionInfo ci) {
- m_hosts.add(s);
- m_connectionInfos.put(s, ci);
- }
-
- public ConnectionInfo getSlave() {
- ConnectionInfo result = null;
- Socket host = null;
-
- try {
- host = m_hosts.take();
- result = m_connectionInfos.get(host);
- }
- catch (InterruptedException handled) {
- handled.printStackTrace();
- Thread.currentThread().interrupt();
- }
-
- return result;
- }
-
- public void returnSlave(ConnectionInfo slave) throws IOException {
- m_hosts.add(slave.getSocket());
-// ConnectionInfo ci = m_connectionInfos.remove(slave.socket);
-// ci.oos.close();
-// ci.ois.close();
-// addSlave(slave.socket);
- }
-
-}
diff --git a/src/main/java/org/testng/internal/remote/SocketLinkedBlockingQueue.java b/src/main/java/org/testng/internal/remote/SocketLinkedBlockingQueue.java
deleted file mode 100755
index bffaccbf1a..0000000000
--- a/src/main/java/org/testng/internal/remote/SocketLinkedBlockingQueue.java
+++ /dev/null
@@ -1,21 +0,0 @@
-package org.testng.internal.remote;
-
-import java.net.Socket;
-
-/**
- * SocketLinkedBlockingQueue
is a wrapper on LinkedBlockingQueue so
- * we may factor out code common to JDK14 and JDK5+ using different implementation
- * of LinkedBlockingQueue
- *
- * @author cquezel
- * @since 5.2
- */
-public class SocketLinkedBlockingQueue extends java.util.concurrent.LinkedBlockingQueue
-{
-
- /**
- *
- */
- private static final long serialVersionUID = 4548450495806527985L;
- // wrapper
-}
diff --git a/src/main/java/org/testng/remote/ConnectionInfo.java b/src/main/java/org/testng/remote/ConnectionInfo.java
deleted file mode 100755
index 882ff3df1d..0000000000
--- a/src/main/java/org/testng/remote/ConnectionInfo.java
+++ /dev/null
@@ -1,35 +0,0 @@
-package org.testng.remote;
-
-import java.io.IOException;
-import java.io.ObjectInputStream;
-import java.io.ObjectOutputStream;
-import java.net.Socket;
-
-public class ConnectionInfo {
- private Socket m_socket;
- private ObjectInputStream m_ois;
- private ObjectOutputStream m_oos;
-
- public ObjectInputStream getOis() throws IOException {
- if (m_ois == null) {
- m_ois = new ObjectInputStream(m_socket.getInputStream());
- }
- return m_ois;
- }
-
- public ObjectOutputStream getOos() throws IOException {
- if (m_oos == null) {
- m_oos = new ObjectOutputStream(m_socket.getOutputStream());
- }
- return m_oos;
- }
-
- public void setSocket(Socket s) {
- m_socket = s;
- }
-
- public Socket getSocket() {
- return m_socket;
- }
-
-}
diff --git a/src/main/java/org/testng/remote/RemoteArgs.java b/src/main/java/org/testng/remote/RemoteArgs.java
deleted file mode 100644
index af89db111e..0000000000
--- a/src/main/java/org/testng/remote/RemoteArgs.java
+++ /dev/null
@@ -1,17 +0,0 @@
-package org.testng.remote;
-
-import com.beust.jcommander.Parameter;
-
-public class RemoteArgs {
- public static final String PORT = "-serport";
- @Parameter(names = PORT, description = "The port for the serialization protocol")
- public Integer serPort;
-
- public static final String DONT_EXIT= "-dontexit";
- @Parameter(names = DONT_EXIT, description = "Do not exit the JVM once done")
- public boolean dontExit = false;
-
- public static final String ACK = "-ack";
- @Parameter(names = ACK, description = "Use ACK's")
- public boolean ack = false;
-}
diff --git a/src/main/java/org/testng/remote/RemoteSuiteWorker.java b/src/main/java/org/testng/remote/RemoteSuiteWorker.java
deleted file mode 100755
index 2beca4eec9..0000000000
--- a/src/main/java/org/testng/remote/RemoteSuiteWorker.java
+++ /dev/null
@@ -1,34 +0,0 @@
-package org.testng.remote;
-
-import org.testng.SuiteRunner;
-import org.testng.internal.remote.SlavePool;
-import org.testng.remote.adapter.RemoteResultListener;
-import org.testng.xml.XmlSuite;
-
-/**
- * A worker that will be put into an Executor and that sends a suite
- * This class
- *
- * @author cbeust
- */
-public class RemoteSuiteWorker extends RemoteWorker implements Runnable {
- private XmlSuite m_suite;
-
- public RemoteSuiteWorker(XmlSuite suite, SlavePool slavePool, RemoteResultListener listener) {
- super(listener, slavePool);
- m_suite = suite;
- }
-
- @Override
- public void run() {
- try {
- SuiteRunner result = sendSuite(getSlavePool().getSlave(), m_suite);
- m_listener.onResult(result);
- }
- catch (Exception e) {
- e.printStackTrace();
- }
-
- }
-}
-
diff --git a/src/main/java/org/testng/remote/RemoteTestNG.java b/src/main/java/org/testng/remote/RemoteTestNG.java
deleted file mode 100644
index 9bcf51acec..0000000000
--- a/src/main/java/org/testng/remote/RemoteTestNG.java
+++ /dev/null
@@ -1,271 +0,0 @@
-package org.testng.remote;
-
-import static org.testng.internal.Utils.defaultIfStringEmpty;
-
-import com.beust.jcommander.JCommander;
-import com.beust.jcommander.ParameterException;
-
-import org.testng.CommandLineArgs;
-import org.testng.IClassListener;
-import org.testng.IInvokedMethodListener;
-import org.testng.ISuite;
-import org.testng.ISuiteListener;
-import org.testng.ITestRunnerFactory;
-import org.testng.TestNG;
-import org.testng.TestNGException;
-import org.testng.TestRunner;
-import org.testng.collections.Lists;
-import org.testng.remote.strprotocol.GenericMessage;
-import org.testng.remote.strprotocol.IMessageSender;
-import org.testng.remote.strprotocol.MessageHelper;
-import org.testng.remote.strprotocol.MessageHub;
-import org.testng.remote.strprotocol.RemoteTestListener;
-import org.testng.remote.strprotocol.SerializedMessageSender;
-import org.testng.remote.strprotocol.StringMessageSender;
-import org.testng.remote.strprotocol.SuiteMessage;
-import org.testng.reporters.JUnitXMLReporter;
-import org.testng.reporters.TestHTMLReporter;
-import org.testng.xml.XmlSuite;
-import org.testng.xml.XmlTest;
-
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.List;
-
-/**
- * Extension of TestNG registering a remote TestListener.
- *
- * @author Cedric Beust
- */
-public class RemoteTestNG extends TestNG {
- private static final String LOCALHOST = "localhost";
-
- // The following constants are referenced by the Eclipse plug-in, make sure you
- // modify the plug-in as well if you change any of them.
- public static final String DEBUG_PORT = "12345";
- public static final String DEBUG_SUITE_FILE = "testng-customsuite.xml";
- public static final String DEBUG_SUITE_DIRECTORY = System.getProperty("java.io.tmpdir");
- public static final String PROPERTY_DEBUG = "testng.eclipse.debug";
- public static final String PROPERTY_VERBOSE = "testng.eclipse.verbose";
- // End of Eclipse constants.
-
- private ITestRunnerFactory m_customTestRunnerFactory;
- private String m_host;
-
- /** Port used for the string protocol */
- private Integer m_port = null;
-
- /** Port used for the serialized protocol */
- private static Integer m_serPort = null;
-
- private static boolean m_debug;
-
- private static boolean m_dontExit;
-
- private static boolean m_ack;
-
- public void setHost(String host) {
- m_host = defaultIfStringEmpty(host, LOCALHOST);
- }
-
- private void calculateAllSuites(List suites, List outSuites) {
- for (XmlSuite s : suites) {
- outSuites.add(s);
-// calculateAllSuites(s.getChildSuites(), outSuites);
- }
- }
-
- @Override
- public void run() {
- IMessageSender sender = m_serPort != null
- ? new SerializedMessageSender(m_host, m_serPort, m_ack)
- : new StringMessageSender(m_host, m_port);
- final MessageHub msh = new MessageHub(sender);
- msh.setDebug(isDebug());
- try {
- msh.connect();
- // We couldn't do this until now in debug mode since the .xml file didn't exist yet.
- // Now that we have connected with the Eclipse client, we know that it created the .xml
- // file so we can proceed with the initialization
- initializeSuitesAndJarFile();
-
- List suites = Lists.newArrayList();
- calculateAllSuites(m_suites, suites);
-// System.out.println("Suites: " + m_suites.get(0).getChildSuites().size()
-// + " and:" + suites.get(0).getChildSuites().size());
- if(suites.size() > 0) {
-
- int testCount= 0;
-
- for (XmlSuite suite : suites) {
- testCount += suite.getTests().size();
- }
-
- GenericMessage gm= new GenericMessage(MessageHelper.GENERIC_SUITE_COUNT);
- gm.setSuiteCount(suites.size());
- gm.setTestCount(testCount);
- msh.sendMessage(gm);
-
- addListener(new RemoteSuiteListener(msh));
- setTestRunnerFactory(new DelegatingTestRunnerFactory(buildTestRunnerFactory(), msh));
-
-// System.out.println("RemoteTestNG starting");
- super.run();
- }
- else {
- System.err.println("No test suite found. Nothing to run");
- }
- }
- catch(Throwable cause) {
- cause.printStackTrace(System.err);
- }
- finally {
-// System.out.println("RemoteTestNG finishing: " + (getEnd() - getStart()) + " ms");
- msh.shutDown();
- if (! m_debug && ! m_dontExit) {
- System.exit(0);
- }
- }
- }
-
- /**
- * Override by the plugin if you need to configure differently the TestRunner
- * (usually this is needed if different listeners/reporters are needed).
- * Note: you don't need to worry about the wiring listener, because it is added
- * automatically.
- */
- protected ITestRunnerFactory buildTestRunnerFactory() {
- if(null == m_customTestRunnerFactory) {
- m_customTestRunnerFactory= new ITestRunnerFactory() {
- @Override
- public TestRunner newTestRunner(ISuite suite, XmlTest xmlTest,
- Collection listeners, List classListeners) {
- TestRunner runner =
- new TestRunner(getConfiguration(), suite, xmlTest,
- false /*skipFailedInvocationCounts */,
- listeners, classListeners);
- if (m_useDefaultListeners) {
- runner.addListener(new TestHTMLReporter());
- runner.addListener(new JUnitXMLReporter());
- }
-
- return runner;
- }
- };
- }
-
- return m_customTestRunnerFactory;
- }
-
- public static void main(String[] args) throws ParameterException {
- CommandLineArgs cla = new CommandLineArgs();
- RemoteArgs ra = new RemoteArgs();
- new JCommander(Arrays.asList(cla, ra), args);
- m_dontExit = ra.dontExit;
- if (cla.port != null && ra.serPort != null) {
- throw new TestNGException("Can only specify one of " + CommandLineArgs.PORT
- + " and " + RemoteArgs.PORT);
- }
- m_debug = cla.debug;
- m_ack = ra.ack;
- initAndRun(args, cla, ra);
- }
-
- private static void initAndRun(String[] args, CommandLineArgs cla, RemoteArgs ra) {
- RemoteTestNG remoteTestNg = new RemoteTestNG();
- if (m_debug) {
- // In debug mode, override the port and the XML file to a fixed location
- cla.port = Integer.parseInt(DEBUG_PORT);
- ra.serPort = cla.port;
- cla.suiteFiles = Arrays.asList(new String[] {
- DEBUG_SUITE_DIRECTORY + DEBUG_SUITE_FILE
- });
- }
- remoteTestNg.configure(cla);
- remoteTestNg.setHost(cla.host);
- m_serPort = ra.serPort;
- remoteTestNg.m_port = cla.port;
- if (isVerbose()) {
- StringBuilder sb = new StringBuilder("Invoked with ");
- for (String s : args) {
- sb.append(s).append(" ");
- }
- p(sb.toString());
-// remoteTestNg.setVerbose(1);
-// } else {
-// remoteTestNg.setVerbose(0);
- }
- validateCommandLineParameters(cla);
- remoteTestNg.run();
-// if (m_debug) {
-// // Run in a loop if in debug mode so it is possible to run several launches
-// // without having to relauch RemoteTestNG.
-// while (true) {
-// remoteTestNg.run();
-// remoteTestNg.configure(cla);
-// }
-// } else {
-// remoteTestNg.run();
-// }
- }
-
- private static void p(String s) {
- if (isVerbose()) {
- System.out.println("[RemoteTestNG] " + s);
- }
- }
-
- public static boolean isVerbose() {
- boolean result = System.getProperty(PROPERTY_VERBOSE) != null || isDebug();
- return result;
- }
-
- public static boolean isDebug() {
- return m_debug || System.getProperty(PROPERTY_DEBUG) != null;
- }
-
- private String getHost() {
- return m_host;
- }
-
- private int getPort() {
- return m_port;
- }
-
- /** A ISuiteListener wiring the results using the internal string-based protocol. */
- private static class RemoteSuiteListener implements ISuiteListener {
- private final MessageHub m_messageSender;
-
- RemoteSuiteListener(MessageHub smsh) {
- m_messageSender= smsh;
- }
-
- @Override
- public void onFinish(ISuite suite) {
- m_messageSender.sendMessage(new SuiteMessage(suite, false /*start*/));
- }
-
- @Override
- public void onStart(ISuite suite) {
- m_messageSender.sendMessage(new SuiteMessage(suite, true /*start*/));
- }
- }
-
- private static class DelegatingTestRunnerFactory implements ITestRunnerFactory {
- private final ITestRunnerFactory m_delegateFactory;
- private final MessageHub m_messageSender;
-
- DelegatingTestRunnerFactory(ITestRunnerFactory trf, MessageHub smsh) {
- m_delegateFactory= trf;
- m_messageSender= smsh;
- }
-
- @Override
- public TestRunner newTestRunner(ISuite suite, XmlTest test,
- Collection listeners, List classListeners) {
- TestRunner tr = m_delegateFactory.newTestRunner(suite, test, listeners, classListeners);
- tr.addListener(new RemoteTestListener(suite, test, m_messageSender));
- return tr;
- }
- }
-}
diff --git a/src/main/java/org/testng/remote/RemoteWorker.java b/src/main/java/org/testng/remote/RemoteWorker.java
deleted file mode 100755
index 10abde04f8..0000000000
--- a/src/main/java/org/testng/remote/RemoteWorker.java
+++ /dev/null
@@ -1,42 +0,0 @@
-package org.testng.remote;
-
-import org.testng.SuiteRunner;
-import org.testng.internal.Utils;
-import org.testng.internal.remote.SlavePool;
-import org.testng.remote.adapter.RemoteResultListener;
-import org.testng.xml.XmlSuite;
-
-import java.io.IOException;
-
-public class RemoteWorker {
- protected RemoteResultListener m_listener;
- private SlavePool m_slavePool;
-
- public RemoteWorker(RemoteResultListener listener, SlavePool slavePool) {
- m_listener = listener;
- m_slavePool = slavePool;
- }
-
- protected SlavePool getSlavePool() {
- return m_slavePool;
- }
-
- protected SuiteRunner sendSuite(ConnectionInfo ci, XmlSuite suite)
- throws IOException, ClassNotFoundException
- {
- log("Sending " + suite.getName() + " to "
- + ci.getSocket().getInetAddress().getCanonicalHostName() + ":"
- + ci.getSocket().getRemoteSocketAddress());
- ci.getOos().writeObject(suite);
- ci.getOos().flush();
- SuiteRunner result = (SuiteRunner) ci.getOis().readObject();
- log("Received results for " + result.getName());
- return result;
- }
-
- private void log(String string) {
- Utils.log("", 2, string);
- }
-
-
-}
diff --git a/src/main/java/org/testng/remote/SuiteDispatcher.java b/src/main/java/org/testng/remote/SuiteDispatcher.java
deleted file mode 100644
index 2064792709..0000000000
--- a/src/main/java/org/testng/remote/SuiteDispatcher.java
+++ /dev/null
@@ -1,168 +0,0 @@
-package org.testng.remote;
-
-import java.util.Collection;
-import java.util.List;
-import java.util.Properties;
-
-import org.testng.ISuite;
-import org.testng.ISuiteResult;
-import org.testng.ITestListener;
-import org.testng.ITestResult;
-import org.testng.SuiteRunner;
-import org.testng.TestNGException;
-import org.testng.collections.Lists;
-import org.testng.internal.IConfiguration;
-import org.testng.internal.Invoker;
-import org.testng.internal.PropertiesFile;
-import org.testng.remote.adapter.DefaultMastertAdapter;
-import org.testng.remote.adapter.IMasterAdapter;
-import org.testng.remote.adapter.RemoteResultListener;
-import org.testng.xml.XmlSuite;
-import org.testng.xml.XmlTest;
-
-/**
- * Dispatches test suits according to the strategy defined.
- *
- *
- * @author Guy Korland
- * @since April 20, 2007
- */
-public class SuiteDispatcher
-{
- /**
- * Properties allowed in remote.properties
- */
- public static final String MASTER_STRATEGY = "testng.master.strategy";
- public static final String VERBOSE = "testng.verbose";
- public static final String MASTER_ADPATER = "testng.master.adpter";
-
- /**
- * Values allowed for STRATEGY
- */
- public static final String STRATEGY_TEST = "test";
- public static final String STRATEGY_SUITE = "suite";
-
- final private int m_verbose;
- final private boolean m_isStrategyTest;
-
- final private IMasterAdapter m_masterAdpter;
-
-
- /**
- * Creates a new suite dispatcher.
- */
- public SuiteDispatcher( String propertiesFile) throws TestNGException
- {
- try
- {
- PropertiesFile file = new PropertiesFile( propertiesFile);
- Properties properties = file.getProperties();
-
- m_verbose = Integer.parseInt( properties.getProperty(VERBOSE, "1"));
-
- String strategy = properties.getProperty(MASTER_STRATEGY, STRATEGY_SUITE);
- m_isStrategyTest = STRATEGY_TEST.equalsIgnoreCase(strategy);
-
- String adapter = properties.getProperty(MASTER_ADPATER);
- if( adapter == null)
- {
- m_masterAdpter = new DefaultMastertAdapter();
- }
- else
- {
- Class clazz = Class.forName(adapter);
- m_masterAdpter = (IMasterAdapter)clazz.newInstance();
- }
- m_masterAdpter.init(properties);
- }
- catch( Exception e)
- {
- throw new TestNGException( "Fail to initialize master mode", e);
- }
- }
-
- /**
- * Dispatch test suites
- * @return suites result
- */
- public List dispatch(IConfiguration configuration,
- List suites, String outputDir, List testListeners){
- List result = Lists.newArrayList();
- try
- {
- //
- // Dispatch the suites/tests
- //
-
- for (XmlSuite suite : suites) {
- suite.setVerbose(m_verbose);
- SuiteRunner suiteRunner = new SuiteRunner(configuration, suite, outputDir);
- RemoteResultListener listener = new RemoteResultListener( suiteRunner);
- if (m_isStrategyTest) {
- for (XmlTest test : suite.getTests()) {
- XmlSuite tmpSuite = new XmlSuite();
- tmpSuite.setXmlPackages(suite.getXmlPackages());
- tmpSuite.setJUnit(suite.isJUnit());
- tmpSuite.setSkipFailedInvocationCounts(suite.skipFailedInvocationCounts());
- tmpSuite.setName("Temporary suite for " + test.getName());
- tmpSuite.setParallel(suite.getParallel());
- tmpSuite.setParentModule(suite.getParentModule());
- tmpSuite.setGuiceStage(suite.getGuiceStage());
- tmpSuite.setParameters(suite.getParameters());
- tmpSuite.setThreadCount(suite.getThreadCount());
- tmpSuite.setDataProviderThreadCount(suite.getDataProviderThreadCount());
- tmpSuite.setVerbose(suite.getVerbose());
- tmpSuite.setObjectFactory(suite.getObjectFactory());
- XmlTest tmpTest = new XmlTest(tmpSuite);
- tmpTest.setBeanShellExpression(test.getExpression());
- tmpTest.setXmlClasses(test.getXmlClasses());
- tmpTest.setExcludedGroups(test.getExcludedGroups());
- tmpTest.setIncludedGroups(test.getIncludedGroups());
- tmpTest.setJUnit(test.isJUnit());
- tmpTest.setMethodSelectors(test.getMethodSelectors());
- tmpTest.setName(test.getName());
- tmpTest.setParallel(test.getParallel());
- tmpTest.setParameters(test.getLocalParameters());
- tmpTest.setVerbose(test.getVerbose());
- tmpTest.setXmlClasses(test.getXmlClasses());
- tmpTest.setXmlPackages(test.getXmlPackages());
-
- m_masterAdpter.runSuitesRemotely(tmpSuite, listener);
- }
- }
- else
- {
- m_masterAdpter.runSuitesRemotely(suite, listener);
- }
- result.add(suiteRunner);
- }
-
- m_masterAdpter.awaitTermination(100000);
-
- //
- // Run test listeners
- //
- for (ISuite suite : result) {
- for (ISuiteResult suiteResult : suite.getResults().values()) {
- Collection allTests[] = new Collection[] {
- suiteResult.getTestContext().getPassedTests().getAllResults(),
- suiteResult.getTestContext().getFailedTests().getAllResults(),
- suiteResult.getTestContext().getSkippedTests().getAllResults(),
- suiteResult.getTestContext().getFailedButWithinSuccessPercentageTests().getAllResults(),
- };
- for (Collection all : allTests) {
- for (ITestResult tr : all) {
- Invoker.runTestListeners(tr, testListeners);
- }
- }
- }
- }
- }
- catch( Exception ex)
- {
- //TODO add to logs
- ex.printStackTrace();
- }
- return result;
- }
-}
diff --git a/src/main/java/org/testng/remote/SuiteSlave.java b/src/main/java/org/testng/remote/SuiteSlave.java
deleted file mode 100644
index be3d15f3aa..0000000000
--- a/src/main/java/org/testng/remote/SuiteSlave.java
+++ /dev/null
@@ -1,101 +0,0 @@
-package org.testng.remote;
-
-import java.util.List;
-import java.util.Properties;
-
-import org.testng.ISuite;
-import org.testng.TestNG;
-import org.testng.TestNGException;
-import org.testng.collections.Lists;
-import org.testng.internal.PropertiesFile;
-import org.testng.internal.Utils;
-import org.testng.remote.adapter.DefaultWorkerAdapter;
-import org.testng.remote.adapter.IWorkerAdapter;
-import org.testng.xml.XmlSuite;
-
-/**
- * Run test suits sent by the dispatcher.
- *
- *
- * @author Guy Korland
- * @since April 20, 2007
- */
-public class SuiteSlave
-{
-
- /**
- * Properties allowed in remote.properties
- */
- public static final String VERBOSE = "testng.verbose";
- public static final String SLAVE_ADPATER = "testng.slave.adpter";
-
-
- final private int m_verbose;
- final private IWorkerAdapter m_slaveAdpter;
- final private TestNG m_testng;
-
- /**
- * Creates a new suite dispatcher.
- */
- public SuiteSlave( String propertiesFile, TestNG testng) throws TestNGException
- {
- try
- {
- m_testng = testng;
-
- PropertiesFile file = new PropertiesFile( propertiesFile);
- Properties properties = file.getProperties();
-
- m_verbose = Integer.parseInt( properties.getProperty(VERBOSE, "1"));
-
- String adapter = properties.getProperty(SLAVE_ADPATER);
- if( adapter == null)
- {
- m_slaveAdpter = new DefaultWorkerAdapter();
- }
- else
- {
- Class clazz = Class.forName(adapter);
- m_slaveAdpter = (IWorkerAdapter)clazz.newInstance();
- }
- m_slaveAdpter.init(properties);
- }
- catch( Exception e)
- {
- throw new TestNGException( "Fail to initialize slave mode", e);
- }
- }
-
- /**
- * Invoked in client mode. In this case, wait for a connection
- * on the given port, run the XmlSuite we received and return the SuiteRunner
- * created to run it.
- */
- public void waitForSuites() {
- try {
- while (true) {
- //TODO set timeout
- XmlSuite s = m_slaveAdpter.getSuite(Long.MAX_VALUE);
- if( s== null) {
- continue;
- }
- log("Processing " + s.getName());
- List suites = Lists.newArrayList();
- suites.add(s);
- m_testng.setXmlSuites(suites);
- List suiteRunners = m_testng.runSuitesLocally();
- ISuite sr = suiteRunners.get(0);
- log("Done processing " + s.getName());
- m_slaveAdpter.returnResult(sr);
- }
- }
- catch(Exception ex) {
- ex.printStackTrace(System.out);
- }
- }
-
- private static void log(String string) {
- Utils.log("", 2, string);
- }
-
-}
diff --git a/src/main/java/org/testng/remote/adapter/DefaultMastertAdapter.java b/src/main/java/org/testng/remote/adapter/DefaultMastertAdapter.java
deleted file mode 100755
index 70fcef7e59..0000000000
--- a/src/main/java/org/testng/remote/adapter/DefaultMastertAdapter.java
+++ /dev/null
@@ -1,84 +0,0 @@
-package org.testng.remote.adapter;
-
-import java.io.IOException;
-import java.net.Socket;
-import java.net.UnknownHostException;
-import java.util.List;
-import java.util.Properties;
-
-import org.testng.collections.Lists;
-import org.testng.internal.Utils;
-import org.testng.internal.remote.SlavePool;
-import org.testng.internal.thread.ThreadUtil;
-import org.testng.remote.RemoteSuiteWorker;
-import org.testng.xml.XmlSuite;
-
-/**
- * Default Master adapter, provides an adapter based on hosts file.
- *
- *
- * @author Guy Korland
- * @since April 20, 2007
- */
-public class DefaultMastertAdapter
-implements IMasterAdapter
-{
- public static final String HOSTS = "testng.hosts";
-
- private String[] m_hosts;
-
- final private SlavePool m_slavePool = new SlavePool();
- final private List m_workers = Lists.newArrayList();
-
- /*
- * @see org.testng.remote.adapter.IMasterAdapter#init(java.util.Properties)
- */
- @Override
- public void init(Properties properties)
- {
- String hostLine = properties.getProperty(HOSTS);
- m_hosts = hostLine.split(" ");
-
- //
- // Create one socket per host found
- //
- Socket[] sockets = new Socket[m_hosts.length];
- for (int i = 0; i < m_hosts.length; i++) {
- String host = m_hosts[i];
- String[] s = host.split(":");
- try {
- sockets[i] = new Socket(s[0], Integer.parseInt(s[1]));
- }
- catch (NumberFormatException | UnknownHostException e) {
- e.printStackTrace(System.out);
- } catch (IOException e) {
- Utils.error("Couldn't connect to " + host + ": " + e.getMessage());
- }
- }
-
- //
- // Add these hosts to the pool
- //
- try {
- m_slavePool.addSlaves(sockets);
- }
- catch (IOException e1) {
- e1.printStackTrace(System.out);
- }
- }
-
- /*
- * @see org.testng.remote.adapter.IMasterAdapter#runSuitesRemotely(java.util.List, org.testng.internal.annotations.IAnnotationFinder, org.testng.internal.annotations.IAnnotationFinder)
- */
- @Override
- public void runSuitesRemotely( XmlSuite suite, RemoteResultListener listener) throws IOException
- {
- m_workers.add(new RemoteSuiteWorker(suite, m_slavePool, listener));
- }
-
- @Override
- public void awaitTermination(long timeout) throws InterruptedException
- {
- ThreadUtil.execute(m_workers, 1, 10 * 1000L, false);
- }
-}
diff --git a/src/main/java/org/testng/remote/adapter/DefaultWorkerAdapter.java b/src/main/java/org/testng/remote/adapter/DefaultWorkerAdapter.java
deleted file mode 100644
index 4a65694c92..0000000000
--- a/src/main/java/org/testng/remote/adapter/DefaultWorkerAdapter.java
+++ /dev/null
@@ -1,88 +0,0 @@
-package org.testng.remote.adapter;
-
-import java.io.IOException;
-import java.net.ServerSocket;
-import java.net.Socket;
-import java.util.Properties;
-
-import org.testng.ISuite;
-import org.testng.internal.Utils;
-import org.testng.remote.ConnectionInfo;
-import org.testng.xml.XmlSuite;
-
-
-/**
- * Default Slave adapter, provides an adapter based on static port.
- *
- *
- * @author Guy Korland
- * @since April 20, 2007
- */
-public class DefaultWorkerAdapter implements IWorkerAdapter
-{
- public static final String SLAVE_PORT = "slave.port";
-
- private ConnectionInfo m_connectionInfo;
- private int m_clientPort;
-
- @Override
- public void init( Properties prop) throws Exception
- {
- m_clientPort = Integer.parseInt( prop.getProperty(SLAVE_PORT, "0"));
- m_connectionInfo = resetSocket( m_clientPort, null);
- }
-
- /*
- * @see org.testng.remote.adapter.IWorkerApadter#getSuite(long)
- */
- @Override
- public XmlSuite getSuite(long timeout) throws InterruptedException, IOException
- {
- try {
- return (XmlSuite) m_connectionInfo.getOis().readObject();
- }
- catch (ClassNotFoundException e) {
- e.printStackTrace(System.out);
- throw new RuntimeException( e);
- }
- catch(IOException ex) {
- log("Connection closed " + ex.getMessage());
- m_connectionInfo = resetSocket(m_clientPort, m_connectionInfo);
- throw ex;
- }
- }
-
- /*
- * @see org.testng.remote.adapter.IWorkerApadter#returnResult(org.testng.ISuite)
- */
- @Override
- public void returnResult(ISuite result) throws IOException
- {
- try
- {
- m_connectionInfo.getOos().writeObject(result);
- }
- catch(IOException ex) {
- log("Connection closed " + ex.getMessage());
- m_connectionInfo = resetSocket(m_clientPort, m_connectionInfo);
- throw ex;
- }
- }
-
- private static ConnectionInfo resetSocket(int clientPort, ConnectionInfo oldCi)
- throws IOException
- {
- ConnectionInfo result = new ConnectionInfo();
- ServerSocket serverSocket = new ServerSocket(clientPort);
- serverSocket.setReuseAddress(true);
- log("Waiting for connections on port " + clientPort);
- Socket socket = serverSocket.accept();
- result.setSocket(socket);
-
- return result;
- }
-
- private static void log(String string) {
- Utils.log("", 2, string);
- }
-}
diff --git a/src/main/java/org/testng/remote/adapter/IMasterAdapter.java b/src/main/java/org/testng/remote/adapter/IMasterAdapter.java
deleted file mode 100644
index ebddb37a06..0000000000
--- a/src/main/java/org/testng/remote/adapter/IMasterAdapter.java
+++ /dev/null
@@ -1,40 +0,0 @@
-package org.testng.remote.adapter;
-
-import java.io.IOException;
-import java.util.Properties;
-
-import org.testng.xml.XmlSuite;
-
-/**
- * This interface should be implemented by the Master-Slave transport adapter.
- * This interface is used by the Master to push suites and get results.
- *
- * @author Guy Korland
- * @since April 9, 2007
- * @see IWorkerAdapter
- */
-public interface IMasterAdapter
-{
- /**
- * Initializes the Master adapter.
- * @param prop holds the properties loaded from the remote.properties file.
- * @throws Exception adapter might throw any exception on initialization, which will abort this adapter.
- */
- void init( Properties prop) throws Exception;
-
- /**
- * Run a suite remotely.
- * @param suite the suite to send.
- * @param listener the corresponded listener, should be called when result is ready.
- * @throws IOException might be thrown on IO error.
- */
- void runSuitesRemotely( XmlSuite suite, RemoteResultListener listener) throws IOException;
-
- /**
- * A blocking wait for the remote results to return.
- *
- * @param timeout the maximum time to wait for all the suites to return a result.
- * @throws InterruptedException
- */
- public void awaitTermination(long timeout) throws InterruptedException;
-}
\ No newline at end of file
diff --git a/src/main/java/org/testng/remote/adapter/IWorkerAdapter.java b/src/main/java/org/testng/remote/adapter/IWorkerAdapter.java
deleted file mode 100644
index d1d966bf36..0000000000
--- a/src/main/java/org/testng/remote/adapter/IWorkerAdapter.java
+++ /dev/null
@@ -1,41 +0,0 @@
-package org.testng.remote.adapter;
-
-import java.io.IOException;
-import java.util.Properties;
-
-import org.testng.ISuite;
-import org.testng.xml.XmlSuite;
-
-/**
- * This interface should be implemented by the Master-Slave transport adapter.
- * This interface is used by the Slave to pull suites and return results.
- *
- * @author Guy Korland
- * @since April 9, 2007
- * @see IMasterAdapter
- */
-public interface IWorkerAdapter
-{
- /**
- * Initializes the worker adapter.
- * @param properties holds the properties loaded from the remote.properties file.
- * @throws Exception adapter might throw any exception on initialization, which will abort this adapter.
- */
- void init( Properties properties) throws Exception;
-
- /**
- * A blocking call to get the next Suite to test.
- * @param timeout the maximum time to wait for the next suite.
- * @return the next suite avaliable or null
if the timeout has reached.
- * @throws IOException might be thrown on IO error.
- * @throws InterruptedException if interrupted while waiting.
- */
- XmlSuite getSuite( long timeout) throws InterruptedException, IOException;
-
- /**
- * Return a suite result.
- * @param result the result to return
- * @throws IOException might be thrown on IO error.
- */
- void returnResult( ISuite result) throws IOException;
-}
diff --git a/src/main/java/org/testng/remote/adapter/RemoteResultListener.java b/src/main/java/org/testng/remote/adapter/RemoteResultListener.java
deleted file mode 100644
index 7895423a6a..0000000000
--- a/src/main/java/org/testng/remote/adapter/RemoteResultListener.java
+++ /dev/null
@@ -1,64 +0,0 @@
-/*
- * @(#)ResultListener.java Apr 9, 2007
- *
- * Copyright 2007 GigaSpaces Technologies Inc.
- */
-
-package org.testng.remote.adapter;
-
-import java.util.Map;
-
-import org.testng.ISuite;
-import org.testng.ISuiteResult;
-import org.testng.ITestContext;
-import org.testng.SuiteRunner;
-import org.testng.reporters.TestHTMLReporter;
-
-/**
- * This listener is called by the {@link IWorkerAdapter} implementation when a remote test result is ready.
- *
- * @author Guy Korland
- * @since April 9, 2007
- * @see IWorkerAdapter
- */
-public class RemoteResultListener
-{
- /**
- * Holds the corresponded {@link SuiteRunner} for the processed {@link org.testng.xml.XmlSuite}.
- */
- final private SuiteRunner m_runner;
-
- /**
- * Creates a listener for an {@link org.testng.xml.XmlSuite} result.
- * @param runner the corresponded {@link SuiteRunner}
- */
- public RemoteResultListener( SuiteRunner runner)
- {
- m_runner = runner;
- }
-
- /**
- * Should called by the {@link IWorkerAdapter} implementation when a remote suite result is ready.
- * @param remoteSuiteRunner remote result.
- */
- public void onResult( ISuite remoteSuiteRunner)
- {
- m_runner.setHost(remoteSuiteRunner.getHost());
- Map tmpResults = remoteSuiteRunner.getResults();
- Map suiteResults = m_runner.getResults();
- for (Map.Entry entry : tmpResults.entrySet())
- {
- ISuiteResult suiteResult = entry.getValue();
- suiteResults.put(entry.getKey(), suiteResult);
- ITestContext tc = suiteResult.getTestContext();
- TestHTMLReporter.generateLog(tc, remoteSuiteRunner.getHost(),
- m_runner.getOutputDirectory(),
- tc.getFailedConfigurations().getAllResults(),
- tc.getSkippedConfigurations().getAllResults(),
- tc.getPassedTests().getAllResults(),
- tc.getFailedTests().getAllResults(),
- tc.getSkippedTests().getAllResults(),
- tc.getFailedButWithinSuccessPercentageTests().getAllResults());
- }
- }
-}
diff --git a/src/main/java/org/testng/remote/strprotocol/AbstractRemoteTestRunnerClient.java b/src/main/java/org/testng/remote/strprotocol/AbstractRemoteTestRunnerClient.java
deleted file mode 100755
index 15170fc5a0..0000000000
--- a/src/main/java/org/testng/remote/strprotocol/AbstractRemoteTestRunnerClient.java
+++ /dev/null
@@ -1,242 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Common Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- * Julien Ruaux: jruaux@octo.com
- * Vincent Massol: vmassol@octo.com
- *
- * Adapted by:
- * Alexandru Popescu: the_mindstorm@evolva.ro
- ******************************************************************************/
-package org.testng.remote.strprotocol;
-
-
-import org.testng.TestNGException;
-
-import java.io.IOException;
-import java.net.ServerSocket;
-import java.net.Socket;
-
-/**
- * The client side of the RemoteTestRunner. Handles the
- * marshaling of the different messages.
- */
-public abstract class AbstractRemoteTestRunnerClient {
- /**
- * An array of listeners that are informed about test events.
- */
- protected IRemoteSuiteListener[] m_suiteListeners;
- protected IRemoteTestListener[] m_testListeners;
-
- /**
- * The server socket
- */
- private ServerSocket fServerSocket;
- private Socket fSocket;
- private ServerConnection m_serverConnection;
-// private PrintWriter m_outputWriter;
-// private BufferedReader m_inputReader;
-
- /**
- * Start listening to a test run. Start a server connection that
- * the RemoteTestRunner can connect to.
- */
- public synchronized void startListening(IRemoteSuiteListener[] suiteListeners,
- IRemoteTestListener[] testListeners,
- ServerConnection serverConnection) {
- m_suiteListeners= suiteListeners;
- m_testListeners= testListeners;
- m_serverConnection = serverConnection;
-
- serverConnection.start();
- }
-
- public IRemoteSuiteListener[] getSuiteListeners() {
- return m_suiteListeners;
- }
-
- public IRemoteTestListener[] getTestListeners() {
- return m_testListeners;
- }
-
- private synchronized void shutdown() {
-// if(m_outputWriter != null) {
-// m_outputWriter.close();
-// m_outputWriter = null;
-// }
-// try {
-// if(m_inputReader != null) {
-// m_inputReader.close();
-// m_inputReader = null;
-// }
-// }
-// catch(IOException e) {
-// e.printStackTrace();
-// }
- try {
- if(fSocket != null) {
- fSocket.close();
- fSocket = null;
- }
- }
- catch(IOException e) {
- e.printStackTrace();
- }
- try {
- if(fServerSocket != null) {
- fServerSocket.close();
- fServerSocket = null;
- }
- }
- catch(IOException e) {
- e.printStackTrace();
- }
- }
-
- public boolean isRunning() {
- return m_serverConnection.getMessageSender() != null;
- }
-
- /**
- * Requests to stop the remote test run.
- */
- public synchronized void stopTest() {
- if(isRunning()) {
- m_serverConnection.getMessageSender().sendStop();
- shutdown();
- }
- }
-
-// private String readMessage(BufferedReader in) throws IOException {
-// return in.readLine();
-// }
-//
-// private void receiveMessage(String message) {
-// int messageType = MessageHelper.getMessageType(message);
-//
-// try {
-// if(messageType < MessageHelper.SUITE) {
-// // Generic message
-// GenericMessage gm = MessageHelper.unmarshallGenericMessage(message);
-// notifyStart(gm);
-// }
-// else if(messageType < MessageHelper.TEST) {
-// // Suite message
-// SuiteMessage sm = MessageHelper.createSuiteMessage(message);
-// notifySuiteEvents(sm);
-// }
-// else if(messageType < MessageHelper.TEST_RESULT) {
-// // Test message
-// TestMessage tm = MessageHelper.createTestMessage(message);
-// notifyTestEvents(tm);
-// }
-// else {
-// // TestResult message
-// TestResultMessage trm = MessageHelper.unmarshallTestResultMessage(message);
-// notifyResultEvents(trm);
-// }
-// }
-// finally {
-// if(isRunning() && (null != m_outputWriter)) {
-// m_outputWriter.println(MessageHelper.ACK_MSG);
-// m_outputWriter.flush();
-// }
-// }
-// }
-
- protected abstract void notifyStart(final GenericMessage genericMessage);
-
- protected abstract void notifySuiteEvents(final SuiteMessage suiteMessage);
-
- protected abstract void notifyTestEvents(final TestMessage testMessage);
-
- protected abstract void notifyResultEvents(final TestResultMessage testResultMessage);
-
-
- /**
- * Reads the message stream from the RemoteTestRunner
- */
- public abstract class ServerConnection extends Thread {
- private MessageHub m_messageHub;
-
- public ServerConnection(IMessageSender messageMarshaller) {
- super("TestNG - ServerConnection"); //$NON-NLS-1$
- m_messageHub = new MessageHub(messageMarshaller);
- }
-
- IMessageSender getMessageSender() {
- return m_messageHub != null ? m_messageHub.getMessageSender() : null;
- }
-
- @Override
- public void run() {
- try {
- IMessage message = m_messageHub.receiveMessage();
- while (message != null) {
- if (message instanceof GenericMessage) {
- notifyStart((GenericMessage) message);
- }
- else if (message instanceof SuiteMessage) {
- notifySuiteEvents((SuiteMessage) message);
- }
- else if (message instanceof TestMessage) {
- notifyTestEvents((TestMessage) message);
- }
- else if (message instanceof TestResultMessage) {
- notifyResultEvents((TestResultMessage) message);
- }
- else {
- throw new TestNGException("Unknown message type:" + message);
- }
-// if (isRunning()) {
-// m_messageMarshaller.sendAck();
-// }
- message = m_messageHub.receiveMessage();
- }
- }
- finally {
- m_messageHub.shutDown();
- m_messageHub = null;
- }
-// try {
-// fServerSocket = new ServerSocket(fServerPort);
-// fSocket = fServerSocket.accept();
-// try {
-// m_inputReader = new BufferedReader(new InputStreamReader(fSocket.getInputStream(),
-// "UTF-8")); //$NON-NLS-1$
-// }
-// catch(UnsupportedEncodingException e) {
-// m_inputReader = new BufferedReader(new InputStreamReader(fSocket.getInputStream()));
-// }
-// try {
-// m_outputWriter = new PrintWriter(new OutputStreamWriter(fSocket.getOutputStream(), "UTF-8"),
-// true);
-// }
-// catch(UnsupportedEncodingException e1) {
-// m_outputWriter = new PrintWriter(new OutputStreamWriter(fSocket.getOutputStream()), true);
-// }
-// String message;
-// while((m_inputReader != null) && ((message = readMessage(m_inputReader)) != null)) {
-// receiveMessage(message);
-// }
-// }
-// catch(SocketException e) {
-// handleThrowable(e);
-// }
-// catch(IOException e) {
-// handleThrowable(e);
-// }
-// finally {
-// shutdown();
-// }
- }
-
- protected abstract void handleThrowable(Throwable cause);
- }
-
-}
diff --git a/src/main/java/org/testng/remote/strprotocol/BaseMessageSender.java b/src/main/java/org/testng/remote/strprotocol/BaseMessageSender.java
deleted file mode 100644
index 2a86bfff59..0000000000
--- a/src/main/java/org/testng/remote/strprotocol/BaseMessageSender.java
+++ /dev/null
@@ -1,279 +0,0 @@
-package org.testng.remote.strprotocol;
-
-import java.io.BufferedReader;
-import java.io.BufferedWriter;
-import java.io.Closeable;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.io.OutputStream;
-import java.io.OutputStreamWriter;
-import java.io.PrintWriter;
-import java.io.UnsupportedEncodingException;
-import java.net.ConnectException;
-import java.net.ServerSocket;
-import java.net.Socket;
-import java.net.SocketTimeoutException;
-
-import org.testng.TestNGException;
-
-import static org.testng.remote.RemoteTestNG.isVerbose;
-
-abstract public class BaseMessageSender implements IMessageSender {
- private boolean m_debug = false;
- protected Socket m_clientSocket;
- private String m_host;
- private int m_port;
- protected final Object m_ackLock = new Object();
-
- private boolean m_requestStopReceiver;
- /** Outgoing message stream. */
- protected OutputStream m_outStream;
- /** Used to send ACK and STOP */
- private PrintWriter m_outWriter;
-
- /** Incoming message stream. */
- protected volatile InputStream m_inStream;
- /** Used to receive ACK and STOP */
- protected volatile BufferedReader m_inReader;
-
- private ReaderThread m_readerThread;
- private boolean m_ack;
-// protected InputStream m_receiverInputStream;
-
- public BaseMessageSender(String host, int port, boolean ack) {
- m_host = host;
- m_port = port;
- m_ack = ack;
- }
-
- /**
- * Starts the connection.
- *
- * @throws TestNGException if an exception occurred while establishing the connection
- */
- @Override
- public void connect() throws IOException {
- p("Waiting for Eclipse client on " + m_host + ":" + m_port);
- while (true) {
- try {
- m_clientSocket = new Socket(m_host, m_port);
- p("Received a connection from Eclipse on " + m_host + ":" + m_port);
-
- // Output streams
- m_outStream = m_clientSocket.getOutputStream();
- m_outWriter = new PrintWriter(new BufferedWriter(new OutputStreamWriter(m_outStream)));
-
- // Input streams
- m_inStream = m_clientSocket.getInputStream();
- try {
- m_inReader = new BufferedReader(new InputStreamReader(m_inStream,
- "UTF-8")); //$NON-NLS-1$
- }
- catch(UnsupportedEncodingException ueex) {
- // Should never happen
- m_inReader = new BufferedReader(new InputStreamReader(m_inStream));
- }
-
- p("Connection established, starting reader thread");
- m_readerThread = new ReaderThread();
- m_readerThread.start();
- return;
- }
- catch(ConnectException ex) {
- // ignore and retry
- try {
- Thread.sleep(4000);
- }
- catch(InterruptedException handled) {
- Thread.currentThread().interrupt();
- }
- }
- }
- }
-
- private void sendAdminMessage(String message) {
- m_outWriter.println(message);
- m_outWriter.flush();
- }
-
- private int m_serial = 0;
-
- @Override
- public void sendAck() {
- p("Sending ACK " + m_serial);
- // Note: adding the serial at the end of this message causes a lock up if interacting
- // with TestNG 5.14 and older (reported by JetBrains). The following git commit:
- // 5730bdfb33ec7a8bf4104852cd4a5f2875ba8267
- // changed equals() to startsWith().
- // It's ok to add this serial back for debugging, but don't commit it until JetBrains
- // confirms they no longer need backward compatibility with 5.14.
- sendAdminMessage(MessageHelper.ACK_MSG); // + m_serial++);
- }
-
- @Override
- public void sendStop() {
- sendAdminMessage(MessageHelper.STOP_MSG);
- }
-
- @Override
- public void initReceiver() throws SocketTimeoutException {
- if (m_inStream != null) {
- p("Receiver already initialized");
- }
- ServerSocket serverSocket = null;
- try {
- p("initReceiver on port " + m_port);
- serverSocket = new ServerSocket(m_port);
- serverSocket.setSoTimeout(5000);
-
- Socket socket = null;
- while (!m_requestStopReceiver) {
- try {
- if (m_debug) {
- p("polling the client connection");
- }
- socket = serverSocket.accept();
- // break the loop once the first client connected
- break;
- }
- catch (IOException ioe) {
- try {
- Thread.sleep(100L);
- }
- catch (InterruptedException ie) {
- // Do nothing.
- }
- }
- }
- if (socket != null) {
- m_inStream = socket.getInputStream();
- m_inReader = new BufferedReader(new InputStreamReader(m_inStream));
- m_outStream = socket.getOutputStream();
- m_outWriter = new PrintWriter(new OutputStreamWriter(m_outStream));
- }
- }
- catch(SocketTimeoutException ste) {
- throw ste;
- }
- catch (IOException ioe) {
- closeQuietly(serverSocket);
- }
- }
-
- public void stopReceiver() {
- m_requestStopReceiver = true;
- }
-
- @Override
- public void shutDown() {
- closeQuietly(m_outStream);
- m_outStream = null;
-
- if (null != m_readerThread) {
- m_readerThread.interrupt();
- }
-
- closeQuietly(m_inReader);
- m_inReader = null;
-
- closeQuietly(m_clientSocket);
- m_clientSocket = null;
- }
-
- private void closeQuietly(Closeable c) {
- if (c != null) {
- try {
- c.close();
- } catch (IOException e) {
- if (m_debug) {
- e.printStackTrace();
- }
- }
- }
- }
-
- private String m_latestAck;
-
- protected void waitForAck() {
- if (m_ack) {
- try {
- p("Message sent, waiting for ACK...");
- synchronized(m_ackLock) {
- m_ackLock.wait();
- }
- p("... ACK received:" + m_latestAck);
- }
- catch(InterruptedException handled) {
- Thread.currentThread().interrupt();
- }
- }
- }
-
- private static void p(String msg) {
- if (isVerbose()) {
- System.out.println("[BaseMessageSender] " + msg); //$NON-NLS-1$
- }
- }
-
- /**
- * Reader thread that processes messages from the client.
- */
- private class ReaderThread extends Thread {
-
- public ReaderThread() {
- super("ReaderThread"); //$NON-NLS-1$
- }
-
- @Override
- public void run() {
- try {
- p("ReaderThread waiting for an admin message");
- String message = m_inReader.readLine();
- p("ReaderThread received admin message:" + message);
- while (message != null) {
- if (m_debug) {
- p("Admin message:" + message); //$NON-NLS-1$
- }
- boolean acknowledge = message.startsWith(MessageHelper.ACK_MSG);
- boolean stop = MessageHelper.STOP_MSG.equals(message);
- if(acknowledge || stop) {
- if (acknowledge) {
- p("Received ACK:" + message);
- m_latestAck = message;
- }
- synchronized(m_ackLock) {
- m_ackLock.notifyAll();
- }
- if (stop) {
- break;
- }
- } else {
- p("Received unknown message: '" + message + "'");
- }
- message = m_inReader != null ? m_inReader.readLine() : null;
- }
-// while((m_reader != null) && (message = m_reader.readLine()) != null) {
-// if (m_debug) {
-// p("Admin message:" + message); //$NON-NLS-1$
-// }
-// boolean acknowledge = MessageHelper.ACK_MSG.equals(message);
-// boolean stop = MessageHelper.STOP_MSG.equals(message);
-// if(acknowledge || stop) {
-// synchronized(m_lock) {
-// m_lock.notifyAll();
-// }
-// if (stop) {
-// break;
-// }
-// }
-// }
- }
- catch(IOException ioe) {
- if (isVerbose()) {
- ioe.printStackTrace();
- }
- }
- }
- }
-}
diff --git a/src/main/java/org/testng/remote/strprotocol/GenericMessage.java b/src/main/java/org/testng/remote/strprotocol/GenericMessage.java
deleted file mode 100755
index 53a2718dd1..0000000000
--- a/src/main/java/org/testng/remote/strprotocol/GenericMessage.java
+++ /dev/null
@@ -1,56 +0,0 @@
-package org.testng.remote.strprotocol;
-
-
-
-
-/**
- * A generic message to be used with remote listeners.
- * It is described by a {@link #m_messageType} and can contain a Map
- * or values.
- *
- * @author Alexandru Popescu
- */
-public class GenericMessage implements IStringMessage {
- private static final long serialVersionUID = 1440074281953763545L;
-// protected Map m_properties;
- protected final int m_messageType;
- private int m_suiteCount;
-
- private int m_testCount;
-
- public GenericMessage(final int type) {
- m_messageType = type;
- }
-
- public int getSuiteCount() {
- return m_suiteCount;
- }
-
- public void setSuiteCount(int suiteCount) {
- m_suiteCount = suiteCount;
- }
-
- public int getTestCount() {
- return m_testCount;
- }
-
- public void setTestCount(int testCount) {
- m_testCount = testCount;
- }
-
- @Override
- public String getMessageAsString() {
- StringBuffer buf = new StringBuffer();
-
- buf.append(m_messageType);
- buf.append(MessageHelper.DELIMITER).append("testCount").append(getTestCount())
- .append(MessageHelper.DELIMITER).append("suiteCount").append(getSuiteCount());
-
- return buf.toString();
- }
-
- @Override
- public String toString() {
- return "[GenericMessage suiteCount:" + m_suiteCount + " testCount:" + m_testCount + "]";
- }
-}
diff --git a/src/main/java/org/testng/remote/strprotocol/IMessage.java b/src/main/java/org/testng/remote/strprotocol/IMessage.java
deleted file mode 100755
index 3aeaa4a72f..0000000000
--- a/src/main/java/org/testng/remote/strprotocol/IMessage.java
+++ /dev/null
@@ -1,12 +0,0 @@
-package org.testng.remote.strprotocol;
-
-import java.io.Serializable;
-
-
-/**
- * Marker interface for messages exchanged between RemoteTestNG and a client.
- *
- * @author Cedric Beust
- */
-public interface IMessage extends Serializable {
-}
diff --git a/src/main/java/org/testng/remote/strprotocol/IMessageSender.java b/src/main/java/org/testng/remote/strprotocol/IMessageSender.java
deleted file mode 100644
index 8dc6c50cbd..0000000000
--- a/src/main/java/org/testng/remote/strprotocol/IMessageSender.java
+++ /dev/null
@@ -1,42 +0,0 @@
-package org.testng.remote.strprotocol;
-
-import java.io.IOException;
-import java.net.SocketException;
-import java.net.SocketTimeoutException;
-
-public interface IMessageSender {
-
- void connect() throws IOException;
-
- /**
- * Initialize the receiver.
- * the underlying socket server will be polling until a first client connect.
- *
- * @throws SocketException This exception will be thrown if a connection
- * to the remote TestNG instance could not be established after ten
- * seconds.
- */
- void initReceiver() throws SocketTimeoutException;
-
- /**
- * Stop the receiver.
- * it provides a way that allow the API invoker to stop the receiver,
- * e.g. break from a dead while loop
- */
- void stopReceiver();
-
- void sendMessage(IMessage message) throws Exception;
-
- /**
- * Will return null or throw EOFException when the connection has been severed.
- */
- IMessage receiveMessage() throws Exception;
-
- void shutDown();
-
- // These two methods should probably be in a separate class since they should all be
- // the same for implementers of this interface.
- void sendAck();
-
- void sendStop();
-}
diff --git a/src/main/java/org/testng/remote/strprotocol/IRemoteSuiteListener.java b/src/main/java/org/testng/remote/strprotocol/IRemoteSuiteListener.java
deleted file mode 100755
index 8e973081d7..0000000000
--- a/src/main/java/org/testng/remote/strprotocol/IRemoteSuiteListener.java
+++ /dev/null
@@ -1,33 +0,0 @@
-package org.testng.remote.strprotocol;
-
-
-
-/**
- * Interface replicating the ISuiteListener
used for remote listeners.
- *
- * @author Alexandru Popescu
- * @see org.testng.ISuiteListener
- */
-public interface IRemoteSuiteListener {
- /**
- * General information about the number of suites to be run.
- * This is called once before all suites.
- *
- * @param genericMessage a message containing the number of suites that will be run
- */
- void onInitialization(GenericMessage genericMessage);
-
- /**
- * @see org.testng.ISuiteListener#onStart(org.testng.ISuite)
- *
- * @param suiteMessage the suite message containing the description of the suite to be run.
- */
- void onStart(SuiteMessage suiteMessage);
-
- /**
- * @see org.testng.ISuiteListener#onFinish(org.testng.ISuite)
- *
- * @param suiteMessage the suite message containing infos about the finished suite.
- */
- void onFinish(SuiteMessage suiteMessage);
-}
diff --git a/src/main/java/org/testng/remote/strprotocol/IRemoteTestListener.java b/src/main/java/org/testng/remote/strprotocol/IRemoteTestListener.java
deleted file mode 100755
index 6e9324a503..0000000000
--- a/src/main/java/org/testng/remote/strprotocol/IRemoteTestListener.java
+++ /dev/null
@@ -1,25 +0,0 @@
-package org.testng.remote.strprotocol;
-
-
-
-/**
- * Interface replicating ITestListener
for remote listeners.
- *
- * @author Alexandru Popescu
- * @see org.testng.ITestListener
- */
-public interface IRemoteTestListener {
- void onStart(TestMessage tm);
-
- void onFinish(TestMessage tm);
-
- void onTestStart(TestResultMessage trm);
-
- void onTestSuccess(TestResultMessage trm);
-
- void onTestFailure(TestResultMessage trm);
-
- void onTestSkipped(TestResultMessage trm);
-
- void onTestFailedButWithinSuccessPercentage(TestResultMessage trm);
-}
diff --git a/src/main/java/org/testng/remote/strprotocol/IStringMessage.java b/src/main/java/org/testng/remote/strprotocol/IStringMessage.java
deleted file mode 100755
index 4e507c1dab..0000000000
--- a/src/main/java/org/testng/remote/strprotocol/IStringMessage.java
+++ /dev/null
@@ -1,11 +0,0 @@
-package org.testng.remote.strprotocol;
-
-
-/**
- * String based protocol main interface to be used with remote listeners.
- *
- * @author Alexandru Popescu
- */
-public interface IStringMessage extends IMessage {
- String getMessageAsString();
-}
diff --git a/src/main/java/org/testng/remote/strprotocol/MessageHelper.java b/src/main/java/org/testng/remote/strprotocol/MessageHelper.java
deleted file mode 100755
index 093960171b..0000000000
--- a/src/main/java/org/testng/remote/strprotocol/MessageHelper.java
+++ /dev/null
@@ -1,255 +0,0 @@
-package org.testng.remote.strprotocol;
-
-
-import org.testng.ITestResult;
-import org.testng.collections.Lists;
-
-import java.util.List;
-import java.util.regex.Pattern;
-
-
-/**
- * Marshal/unmarshal tool for IStringMessage
s.
- *
- * @author Alexandru Popescu
- */
-public class MessageHelper {
- public static final char DELIMITER = '\u0001';
- public static final char PARAM_DELIMITER = '\u0004';
- private static final char LINE_SEP_DELIMITER_1 = '\u0002';
- private static final char LINE_SEP_DELIMITER_2 = '\u0003';
-
- public static final int GENERIC_SUITE_COUNT = 1;
-
- public static final int SUITE = 10;
- public static final int SUITE_START = 11;
- public static final int SUITE_FINISH = 12;
-
- public static final int TEST = 100;
- public static final int TEST_START = 101;
- public static final int TEST_FINISH = 102;
-
- public static final int TEST_RESULT = 1000;
- public static final int PASSED_TEST = TEST_RESULT + ITestResult.SUCCESS;
- public static final int FAILED_TEST = TEST_RESULT + ITestResult.FAILURE;
- public static final int SKIPPED_TEST = TEST_RESULT + ITestResult.SKIP;
- public static final int FAILED_ON_PERCENTAGE_TEST = TEST_RESULT + ITestResult.SUCCESS_PERCENTAGE_FAILURE;
- public static final int TEST_STARTED = TEST_RESULT + ITestResult.STARTED;
-
- public static final String STOP_MSG = ">STOP";
- public static final String ACK_MSG = ">ACK";
-
- public static int getMessageType(final String message) {
- int idx = message.indexOf(DELIMITER);
-
- return idx == -1 ? Integer.parseInt(message) : Integer.parseInt(message.substring(0, idx));
- }
-
- public static GenericMessage unmarshallGenericMessage(final String message) {
- String[] messageParts = parseMessage(message);
- if(messageParts.length == 1) {
- return new GenericMessage(Integer.parseInt(messageParts[0]));
- }
- else {
- GenericMessage result = new GenericMessage(Integer.parseInt(messageParts[0]));
-
- for(int i = 1; i < messageParts.length; i+=2) {
- if ("testCount".equals(messageParts[i])) {
- result.setTestCount(Integer.parseInt(messageParts[i + 1]));
- } else if ("suiteCount".equals(messageParts[i])) {
- result.setSuiteCount(Integer.parseInt(messageParts[i + 1]));
- }
- }
-
- return result;
- }
- }
-
- public static SuiteMessage createSuiteMessage(final String message) {
- int type = getMessageType(message);
- String[] messageParts = parseMessage(message);
-
- SuiteMessage result = new SuiteMessage(messageParts[1],
- MessageHelper.SUITE_START == type,
- Integer.parseInt(messageParts[2]));
- // Any excluded methods?
- if (messageParts.length > 3) {
- int count = Integer.parseInt(messageParts[3]);
- if (count > 0) {
- List methods = Lists.newArrayList();
- int i = 4;
- while (count-- > 0) {
- methods.add(messageParts[i++]);
- }
- result.setExcludedMethods(methods);
- }
- }
-
- return result;
- }
-
- public static TestMessage createTestMessage(final String message) {
- int type = getMessageType(message);
- String[] messageParts = parseMessage(message);
-
- return new TestMessage(MessageHelper.TEST_START == type,
- messageParts[1],
- messageParts[2],
- Integer.parseInt(messageParts[3]),
- Integer.parseInt(messageParts[4]),
- Integer.parseInt(messageParts[5]),
- Integer.parseInt(messageParts[6]),
- Integer.parseInt(messageParts[7]));
- }
-
- public static TestResultMessage unmarshallTestResultMessage(final String message) {
- String[] messageParts = parseMessage(message);
-
- String parametersFragment= null;
- String startTimestampFragment= null;
- String stopTimestampFragment= null;
- String stackTraceFragment= null;
- String testDescriptor= null;
- switch(messageParts.length) {
- case 10:
- {
- parametersFragment= messageParts[5];
- startTimestampFragment= messageParts[6];
- stopTimestampFragment= messageParts[7];
- stackTraceFragment= messageParts[8];
- testDescriptor= messageParts[9];
- }
- break;
- case 9:
- {
- parametersFragment= messageParts[5];
- startTimestampFragment= messageParts[6];
- stopTimestampFragment= messageParts[7];
- stackTraceFragment= messageParts[8];
- }
- break;
- default:
- {
- // HINT: old protocol without parameters
- parametersFragment= null;
- startTimestampFragment= messageParts[5];
- stopTimestampFragment= messageParts[6];
- stackTraceFragment= messageParts[7];
- }
- }
- return new TestResultMessage(Integer.parseInt(messageParts[0]),
- messageParts[1],
- messageParts[2],
- messageParts[3],
- messageParts[4],
- replaceAsciiCharactersWithUnicode(replaceNewLineReplacer(testDescriptor)),
- replaceAsciiCharactersWithUnicode(replaceNewLineReplacer(testDescriptor)),
- parseParameters(parametersFragment),
- Long.parseLong(startTimestampFragment),
- Long.parseLong(stopTimestampFragment),
- replaceAsciiCharactersWithUnicode(replaceNewLineReplacer(stackTraceFragment)),
- 0, 0 /* invocation counts not supported by this protocol */
- );
- }
-
- public static String replaceNewLine(String message) {
- if(null == message) {
- return message;
- }
-
- return message.replace('\n', LINE_SEP_DELIMITER_1).replace('\r', LINE_SEP_DELIMITER_2);
- }
-
- public static String replaceUnicodeCharactersWithAscii(String message) {
- if(null == message) {
- return message;
- }
-
- return replace(
- replace(
- replace(
- replace(message, "\u0004", "\\u0004"),
- "\u0003", "\\u0003"),
- "\u0002", "\\u0002"),
- "\u0001", "\\u0001");
- }
-
- public static String replaceAsciiCharactersWithUnicode(String message) {
- if(null == message) {
- return message;
- }
-
- return replace(
- replace(
- replace(
- replace(message, "\\u0004", "\u0004"),
- "\\u0003", "\u0003"),
- "\\u0002", "\u0002"),
- "\\u0001", "\u0001");
- }
-
- public static String replaceNewLineReplacer(String message) {
- if(null == message) {
- return message;
- }
-
- return message.replace(LINE_SEP_DELIMITER_1, '\n').replace(LINE_SEP_DELIMITER_2, '\r');
- }
-
- private static String[] parseParameters(final String messagePart) {
- return tokenize(messagePart, PARAM_DELIMITER);
- }
-
- private static String[] parseMessage(final String message) {
- return tokenize(message, DELIMITER);
- }
-
- private static String[] tokenize(final String message, final char separator) {
- if(null == message) {
- return new String[0];
- }
-
- List tokens = Lists.newArrayList();
- int start = 0;
- for(int i = 0; i < message.length(); i++) {
- if(separator == message.charAt(i)) {
- tokens.add(message.substring(start, i));
- start = i + 1;
- }
- }
- if(start < message.length()) {
- tokens.add(message.substring(start, message.length()));
- }
-
- return tokens.toArray(new String[tokens.size()]);
- }
-
- /**
- * Implementation according to JDK5 String.replace(CharSequence,CharSequence)
- */
- private static final String replace(String original, CharSequence target, CharSequence replacement) {
- return Pattern.compile(target.toString(), Pattern.LITERAL).matcher(original)
- .replaceAll(quoteReplacement(replacement.toString()));
- }
-
- /**
- * Implementation according to JDK5 String.replace(CharSequence,CharSequence)
- */
- private static String quoteReplacement(String s) {
- if ((s.indexOf('\\') == -1) && (s.indexOf('$') == -1)) {
- return s;
- }
- StringBuffer sb = new StringBuffer();
- for (int i=0; i
- */
-public class MessageHub {
-
- private boolean m_debug = false;
-
- private IMessageSender m_messageSender;
-
- public MessageHub(IMessageSender messageSender) {
- m_messageSender = messageSender;
- }
-
- /**
- * Starts the connection.
- *
- * @throws TestNGException if an exception occurred while establishing the connection
- */
- public void connect() throws IOException {
- m_messageSender.connect();
- }
-
- /**
- * Shutsdown the connection to the remote test listener.
- */
- public void shutDown() {
- m_messageSender.shutDown();
- }
-
- public void sendMessage(IMessage message) {
- try {
- m_messageSender.sendMessage(message);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
-
- public IMessage receiveMessage() {
- IMessage result = null;
- try {
- result = m_messageSender.receiveMessage();
- m_messageSender.sendAck();
- } catch (Exception e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- return result;
- }
-
- private static void p(String msg) {
- if (RemoteTestNG.isVerbose()) {
- System.out.println("[StringMessageSenderHelper] " + msg); //$NON-NLS-1$
- }
- }
-
-
- public void setDebug(boolean debug) {
- m_debug = debug;
- }
-
- public void initReceiver() throws SocketTimeoutException {
- m_messageSender.initReceiver();
- }
-
- public IMessageSender getMessageSender() {
- return m_messageSender;
- }
-}
diff --git a/src/main/java/org/testng/remote/strprotocol/RemoteTestListener.java b/src/main/java/org/testng/remote/strprotocol/RemoteTestListener.java
deleted file mode 100755
index 0130145f1f..0000000000
--- a/src/main/java/org/testng/remote/strprotocol/RemoteTestListener.java
+++ /dev/null
@@ -1,119 +0,0 @@
-package org.testng.remote.strprotocol;
-
-import org.testng.ISuite;
-import org.testng.ITestContext;
-import org.testng.ITestResult;
-import org.testng.internal.IResultListener2;
-import org.testng.xml.XmlTest;
-
-/**
- * A special listener that remote the event with string protocol.
- *
- * @author Alexandru Popescu
- */
-public class RemoteTestListener implements IResultListener2 {
- private final MessageHub m_sender;
- private ISuite m_suite;
- private XmlTest m_xmlTest;
- private ITestContext m_currentTestContext;
-
- public RemoteTestListener(ISuite suite, XmlTest test, MessageHub msh) {
- m_sender = msh;
- m_suite= suite;
- m_xmlTest= test;
- }
-
- @Override
- public void onStart(ITestContext testCtx) {
- m_currentTestContext = testCtx;
- m_sender.sendMessage(new TestMessage(testCtx, true /*start*/));
- }
-
- @Override
- public void onFinish(ITestContext testCtx) {
- m_sender.sendMessage(new TestMessage(testCtx, false /*end*/));
- m_currentTestContext = null;
- }
-
- @Override
- public void onTestStart(ITestResult testResult) {
- TestResultMessage trm= null;
-
- if (null == m_currentTestContext) {
- trm= new TestResultMessage(m_suite.getName(), m_xmlTest.getName(), testResult);
- }
- else {
- trm= new TestResultMessage(m_currentTestContext, testResult);
- }
-
- m_sender.sendMessage(trm);
- }
-
- @Override
- public void beforeConfiguration(ITestResult tr) {
- }
-
- @Override
- public void onTestFailedButWithinSuccessPercentage(ITestResult testResult) {
- if (null == m_currentTestContext) {
- m_sender.sendMessage(new TestResultMessage(m_suite.getName(), m_xmlTest.getName(), testResult));
- }
- else {
- m_sender.sendMessage(new TestResultMessage(m_currentTestContext, testResult));
- }
- }
-
- @Override
- public void onTestFailure(ITestResult testResult) {
- if (null == m_currentTestContext) {
- m_sender.sendMessage(new TestResultMessage(m_suite.getName(), m_xmlTest.getName(), testResult));
- }
- else {
- m_sender.sendMessage(new TestResultMessage(m_currentTestContext, testResult));
- }
- }
-
- @Override
- public void onTestSkipped(ITestResult testResult) {
- if (null == m_currentTestContext) {
- m_sender.sendMessage(new TestResultMessage(m_suite.getName(), m_xmlTest.getName(), testResult));
- }
- else {
- m_sender.sendMessage(new TestResultMessage(m_currentTestContext, testResult));
- }
- }
-
- @Override
- public void onTestSuccess(ITestResult testResult) {
- if (null == m_currentTestContext) {
- m_sender.sendMessage(new TestResultMessage(m_suite.getName(), m_xmlTest.getName(), testResult));
- }
- else {
- m_sender.sendMessage(new TestResultMessage(m_currentTestContext, testResult));
- }
- }
-
- /**
- * @see org.testng.IConfigurationListener#onConfigurationFailure(org.testng.ITestResult)
- */
- @Override
- public void onConfigurationFailure(ITestResult itr) {
- // Show configuration failures in the main view for convenience
- onTestFailure(itr);
- }
-
- /**
- * @see org.testng.IConfigurationListener#onConfigurationSkip(org.testng.ITestResult)
- */
- @Override
- public void onConfigurationSkip(ITestResult itr) {
- onTestSkipped(itr);
- }
-
- /**
- * @see org.testng.IConfigurationListener#onConfigurationSuccess(org.testng.ITestResult)
- */
- @Override
- public void onConfigurationSuccess(ITestResult itr) {
- }
-}
\ No newline at end of file
diff --git a/src/main/java/org/testng/remote/strprotocol/SerializedMessageSender.java b/src/main/java/org/testng/remote/strprotocol/SerializedMessageSender.java
deleted file mode 100644
index cd6dc4106e..0000000000
--- a/src/main/java/org/testng/remote/strprotocol/SerializedMessageSender.java
+++ /dev/null
@@ -1,57 +0,0 @@
-package org.testng.remote.strprotocol;
-
-import org.testng.remote.RemoteTestNG;
-
-import java.io.IOException;
-import java.io.ObjectInputStream;
-import java.io.ObjectOutputStream;
-
-
-public class SerializedMessageSender extends BaseMessageSender {
-
- public SerializedMessageSender(String host, int port) {
- super(host, port, false /* no ack */);
- }
-
- public SerializedMessageSender(String host, int port, boolean ack) {
- super(host, port, ack);
- }
-
- @Override
- public void sendMessage(IMessage message) throws IOException {
- synchronized(m_outStream) {
- p("Sending message " + message);
- ObjectOutputStream oos = new ObjectOutputStream(m_outStream);
- oos.writeObject(message);
- oos.flush();
-
- waitForAck();
- }
- }
-
- @Override
- public IMessage receiveMessage() throws IOException, ClassNotFoundException {
-
- IMessage result = null;
- try {
- ObjectInputStream ios = new ObjectInputStream(m_inStream);
-// synchronized(m_input) {
- result = (IMessage) ios.readObject();
- p("Received message " + result);
-// sendAck();
-// }
- }
- catch(Exception ex) {
- if (RemoteTestNG.isVerbose()) {
- ex.printStackTrace();
- }
- }
- return result;
- }
-
- static void p(String s) {
- if (RemoteTestNG.isVerbose()) {
- System.out.println("[SerializedMessageSender] " + s);
- }
- }
-}
diff --git a/src/main/java/org/testng/remote/strprotocol/StringMessageSender.java b/src/main/java/org/testng/remote/strprotocol/StringMessageSender.java
deleted file mode 100644
index c924eddece..0000000000
--- a/src/main/java/org/testng/remote/strprotocol/StringMessageSender.java
+++ /dev/null
@@ -1,149 +0,0 @@
-package org.testng.remote.strprotocol;
-
-import org.testng.remote.RemoteTestNG;
-
-import java.io.BufferedReader;
-import java.io.BufferedWriter;
-import java.io.IOException;
-import java.io.InputStreamReader;
-import java.io.OutputStreamWriter;
-import java.io.PrintWriter;
-import java.io.UnsupportedEncodingException;
-import java.net.SocketException;
-
-public class StringMessageSender extends BaseMessageSender {
-
- private PrintWriter writer;
-
- public StringMessageSender(String host, int port) {
- super(host, port, false /* no ack */);
- }
-
- public StringMessageSender(String host, int port, boolean ack) {
- super(host, port, ack);
- }
-
- @Override
- public void sendMessage(IMessage message) {
- if (m_outStream == null) {
- throw new IllegalStateException("Trying to send a message on a shutdown sender");
- }
- if (writer == null) {
- try {
- writer = new PrintWriter(new BufferedWriter(
- new OutputStreamWriter(m_outStream, "UTF-8")), //$NON-NLS-1$
- false /* autoflush */);
- } catch (UnsupportedEncodingException e1) {
- writer = new PrintWriter(new BufferedWriter(
- new OutputStreamWriter(m_outStream)),
- false /* autoflush */);
- }
- }
-
- String msg = ((IStringMessage) message).getMessageAsString();
- if (RemoteTestNG.isVerbose()) {
- p("Sending message:" + message);
- p(" String version:" + msg);
-
- StringBuffer buf = new StringBuffer();
- for(int i = 0; i < msg.length(); i++) {
- if('\u0001' == msg.charAt(i)) {
- p(" word:[" + buf.toString() + "]");
- buf.delete(0, buf.length());
- }
- else {
- buf.append(msg.charAt(i));
- }
- }
- p(" word:[" + buf.toString() + "]");
- }
-
- synchronized(m_ackLock) {
- writer.println(msg);
- writer.flush();
- waitForAck();
- }
- }
-
- private static void p(String msg) {
- if (RemoteTestNG.isVerbose()) {
- System.out.println("[StringMessageSender] " + msg); //$NON-NLS-1$
- }
- }
-
- @Override
- public IMessage receiveMessage() {
- IMessage result = null;
-
- if (m_inReader == null) {
- try {
- m_inReader = new BufferedReader(new InputStreamReader(m_inStream, "UTF-8"));
- } catch (UnsupportedEncodingException e) {
- m_inReader = new BufferedReader(new InputStreamReader(m_inStream));
- }
- }
- try {
-// try {
-// m_outputWriter = new PrintWriter(new OutputStreamWriter(fSocket.getOutputStream(), "UTF-8"),
-// true);
-// }
-// catch(UnsupportedEncodingException e1) {
-// m_outputWriter = new PrintWriter(new OutputStreamWriter(fSocket.getOutputStream()), true);
-// }
- result = receiveMessage(m_inReader.readLine());
- } catch(IOException e) {
- handleThrowable(e);
- }
-
- return result;
-// finally {
-// shutDown();
-// return null;
-// }
- }
-
- protected void handleThrowable(Throwable cause) {
- if (RemoteTestNG.isVerbose()) {
- cause.printStackTrace();
- }
- }
-
-// private String readMessage(BufferedReader in) throws IOException {
-// return in.readLine();
-// }
-
- private IMessage receiveMessage(String message) {
- if (message == null) return null;
- IMessage result = null;
-
- int messageType = MessageHelper.getMessageType(message);
-
-// try {
- if(messageType < MessageHelper.SUITE) {
- // Generic message
- result = MessageHelper.unmarshallGenericMessage(message);
- }
- else if(messageType < MessageHelper.TEST) {
- // Suite message
- result = MessageHelper.createSuiteMessage(message);
- }
- else if(messageType < MessageHelper.TEST_RESULT) {
- // Test message
- result = MessageHelper.createTestMessage(message);
- }
- else {
- // TestResult message
- result = MessageHelper.unmarshallTestResultMessage(message);
- }
-// }
-// finally {
-// if(isRunning() && (null != m_outputWriter)) {
-// m_outputWriter.println(MessageHelper.ACK_MSG);
-// m_outputWriter.flush();
-// }
-// }
-
- p("receiveMessage() received:" + result);
- return result;
- }
-}
diff --git a/src/main/java/org/testng/remote/strprotocol/SuiteMessage.java b/src/main/java/org/testng/remote/strprotocol/SuiteMessage.java
deleted file mode 100755
index aae2a84dea..0000000000
--- a/src/main/java/org/testng/remote/strprotocol/SuiteMessage.java
+++ /dev/null
@@ -1,103 +0,0 @@
-package org.testng.remote.strprotocol;
-
-import java.util.Collection;
-import java.util.List;
-import java.util.Map;
-
-import org.testng.ISuite;
-import org.testng.ITestNGMethod;
-import org.testng.collections.Lists;
-import org.testng.collections.Maps;
-
-
-/**
- * A IStringMessage
implementation for suite running events.
- *
- * @author Alexandru Popescu
- */
-public class SuiteMessage implements IStringMessage {
- private static final long serialVersionUID = -4298528261942620419L;
- protected final String m_suiteName;
- protected final int m_testMethodCount;
- protected final boolean m_startSuite;
- private List m_excludedMethods = Lists.newArrayList();
- private Map m_descriptions;
-
- public SuiteMessage(final String suiteName, final boolean startSuiteRun, final int methodCount) {
- m_suiteName = suiteName;
- m_startSuite = startSuiteRun;
- m_testMethodCount = methodCount;
- }
-
- public SuiteMessage(final ISuite suite, final boolean startSuiteRun) {
- m_suiteName = suite.getName();
- m_testMethodCount =suite.getInvokedMethods().size();
- m_startSuite = startSuiteRun;
- Collection excludedMethods = suite.getExcludedMethods();
- if (excludedMethods != null && excludedMethods.size() > 0) {
- m_excludedMethods = Lists.newArrayList();
- m_descriptions = Maps.newHashMap();
- for (ITestNGMethod m : excludedMethods) {
- String methodName = m.getTestClass().getName() + "." + m.getMethodName();
- m_excludedMethods.add(methodName);
- if (m.getDescription() != null) m_descriptions.put(methodName, m.getDescription());
- }
- }
- }
-
- public void setExcludedMethods(List methods) {
- m_excludedMethods = Lists.newArrayList();
- m_excludedMethods.addAll(methods);
- }
-
- public List getExcludedMethods() {
- return m_excludedMethods;
- }
-
- public String getDescriptionForMethod(String methodName) {
- return m_descriptions.get(methodName);
- }
-
- public boolean isMessageOnStart() {
- return m_startSuite;
- }
-
- public String getSuiteName() {
- return m_suiteName;
- }
-
- public int getTestMethodCount() {
- return m_testMethodCount;
- }
-
- @Override
- public String getMessageAsString() {
- StringBuffer buf = new StringBuffer();
-
- buf.append(m_startSuite ? MessageHelper.SUITE_START : MessageHelper.SUITE_FINISH)
- .append(MessageHelper.DELIMITER)
- .append(m_suiteName)
- .append(MessageHelper.DELIMITER)
- .append(m_testMethodCount)
- ;
-
- if (m_excludedMethods != null && m_excludedMethods.size() > 0) {
- buf.append(MessageHelper.DELIMITER);
- buf.append(m_excludedMethods.size());
- for (String method : m_excludedMethods) {
- buf.append(MessageHelper.DELIMITER);
- buf.append(method);
- }
- }
- return buf.toString();
- }
-
- @Override
- public String toString() {
- return "[SuiteMessage suite:" + m_suiteName
- + (m_startSuite ? " starting" : " ending")
- + " methodCount:" + m_testMethodCount
- + "]";
- }
-
-}
diff --git a/src/main/java/org/testng/remote/strprotocol/TestMessage.java b/src/main/java/org/testng/remote/strprotocol/TestMessage.java
deleted file mode 100755
index 0a684e0154..0000000000
--- a/src/main/java/org/testng/remote/strprotocol/TestMessage.java
+++ /dev/null
@@ -1,113 +0,0 @@
-package org.testng.remote.strprotocol;
-
-import org.testng.ITestContext;
-
-
-/**
- * An IStringMessage
implementation for test events.
- *
- * @author Alexandru Popescu
- */
-public class TestMessage implements IStringMessage {
- private static final long serialVersionUID = -5039267143570559640L;
- protected final boolean m_testStart;
- protected final String m_suiteName;
- protected final String m_testName;
- protected final int m_testMethodCount;
- protected final int m_passedTestCount;
- protected final int m_failedTestCount;
- protected final int m_skippedTestCount;
- protected final int m_successPercentageFailedTestCount;
-
- public TestMessage(final boolean isTestStart,
- final String suiteName,
- final String testName,
- final int methodCount,
- final int passedCount,
- final int failedCount,
- final int skippedCount,
- final int percentageCount) {
- m_testStart = isTestStart;
- m_suiteName = suiteName;
- m_testName = testName;
- m_testMethodCount = methodCount;
- m_passedTestCount = passedCount;
- m_failedTestCount = failedCount;
- m_skippedTestCount = skippedCount;
- m_successPercentageFailedTestCount = percentageCount;
- }
-
- public TestMessage(final ITestContext testContext, final boolean isTestStart) {
- this(isTestStart,
- testContext.getSuite().getName(),
- testContext.getCurrentXmlTest().getName(),
- testContext.getAllTestMethods().length,
- testContext.getPassedTests().size(),
- testContext.getFailedTests().size(),
- testContext.getSkippedTests().size(),
- testContext.getFailedButWithinSuccessPercentageTests().size());
- }
-
- public boolean isMessageOnStart() {
- return m_testStart;
- }
-
- @Override
- public String getMessageAsString() {
- StringBuffer buf = new StringBuffer();
-
- buf.append(m_testStart ? MessageHelper.TEST_START : MessageHelper.TEST_FINISH)
- .append(MessageHelper.DELIMITER)
- .append(m_suiteName)
- .append(MessageHelper.DELIMITER)
- .append(m_testName)
- .append(MessageHelper.DELIMITER)
- .append(m_testMethodCount)
- .append(MessageHelper.DELIMITER)
- .append(m_passedTestCount)
- .append(MessageHelper.DELIMITER)
- .append(m_failedTestCount)
- .append(MessageHelper.DELIMITER)
- .append(m_skippedTestCount)
- .append(MessageHelper.DELIMITER)
- .append(m_successPercentageFailedTestCount)
- ;
-
- return buf.toString();
- }
-
- public String getSuiteName() {
- return m_suiteName;
- }
-
- public String getTestName() {
- return m_testName;
- }
-
- public boolean isTestStart() {
- return m_testStart;
- }
- public int getTestMethodCount() {
- return m_testMethodCount;
- }
- public int getSuccessPercentageFailedTestCount() {
- return m_successPercentageFailedTestCount;
- }
- public int getFailedTestCount() {
- return m_failedTestCount;
- }
- public int getPassedTestCount() {
- return m_passedTestCount;
- }
- public int getSkippedTestCount() {
- return m_skippedTestCount;
- }
-
- @Override
- public String toString() {
- return "[TestMessage suite:" + m_suiteName + " testName:" + m_testName
- + " passed:" + m_passedTestCount + " failed:" + m_failedTestCount
- + "]";
- }
-
-}
diff --git a/src/main/java/org/testng/remote/strprotocol/TestResultMessage.java b/src/main/java/org/testng/remote/strprotocol/TestResultMessage.java
deleted file mode 100755
index 5131fa55e9..0000000000
--- a/src/main/java/org/testng/remote/strprotocol/TestResultMessage.java
+++ /dev/null
@@ -1,442 +0,0 @@
-package org.testng.remote.strprotocol;
-
-import java.io.PrintWriter;
-import java.io.StringWriter;
-import java.util.List;
-
-import org.testng.ITestContext;
-import org.testng.ITestResult;
-import org.testng.SkipException;
-import org.testng.collections.Lists;
-
-import static org.testng.internal.Utils.isStringEmpty;
-
-
-/**
- * An IStringMessage
implementation for test results events.
- *
- * @author Alexandru Popescu
- */
-public class TestResultMessage implements IStringMessage {
- private static final long serialVersionUID = -4157150777889117479L;
- protected int m_messageType;
- protected String m_suiteName;
- protected String m_testName;
- protected String m_testClassName;
- protected String m_testMethodName;
- protected String m_stackTrace;
- protected long m_startMillis;
- protected long m_endMillis;
- protected String[] m_parameters= new String[0];
- protected String[] m_paramTypes= new String[0];
- private String m_testDescription;
- private int m_invocationCount;
- private int m_currentInvocationCount;
- private String m_instanceName;
-
- /**
- * This constructor is used by the Eclipse client to initialize a result message based
- * on what was received over the network.
- */
- public TestResultMessage(final int resultType,
- final String suiteName,
- final String testName,
- final String className,
- final String methodName,
- final String testDescriptor,
- String instanceName,
- final String[] params,
- final long startMillis,
- final long endMillis,
- final String stackTrace,
- int invocationCount,
- int currentInvocationCount)
- {
- init(resultType,
- suiteName,
- testName,
- className,
- methodName,
- stackTrace,
- startMillis,
- endMillis,
- extractParams(params),
- extractParamTypes(params),
- testDescriptor,
- instanceName,
- invocationCount,
- currentInvocationCount
- );
- }
-
- /**
- * This constructor is used by RemoteTestNG to initialize a result message
- * from an ITestResult.
- */
- public TestResultMessage(final String suiteName,
- final String testName,
- final ITestResult result)
- {
- Throwable throwable = result.getThrowable();
- String stackTrace = null;
-
- if((ITestResult.FAILURE == result.getStatus())
- || (ITestResult.SUCCESS_PERCENTAGE_FAILURE == result.getStatus())) {
- StringWriter sw = new StringWriter();
- PrintWriter pw = new PrintWriter(sw);
- Throwable cause= throwable;
- if (null != cause) {
- cause.printStackTrace(pw);
- stackTrace = sw.getBuffer().toString();
- }
- else {
- stackTrace= "unknown stack trace";
- }
- }
- else if(ITestResult.SKIP == result.getStatus()
- && (throwable != null && SkipException.class.isAssignableFrom(throwable.getClass()))) {
- stackTrace= throwable.getMessage();
- } else if (throwable != null) {
- StringWriter sw = new StringWriter();
- PrintWriter pw = new PrintWriter(sw);
- throwable.printStackTrace(pw);
- stackTrace = sw.toString();
- }
-
- init(MessageHelper.TEST_RESULT + result.getStatus(),
- suiteName,
- testName,
- result.getTestClass().getName(),
- result.getMethod().getMethod().getName(),
- MessageHelper.replaceUnicodeCharactersWithAscii(stackTrace),
- result.getStartMillis(),
- result.getEndMillis(),
- toString(result.getParameters(), result.getMethod().getMethod().getParameterTypes()),
- toString(result.getMethod().getMethod().getParameterTypes()),
- MessageHelper.replaceUnicodeCharactersWithAscii(result.getName()),
- MessageHelper.replaceUnicodeCharactersWithAscii(result.getInstanceName()),
- result.getMethod().getInvocationCount(),
- result.getMethod().getCurrentInvocationCount()
- );
- }
-
- public TestResultMessage(final ITestContext testCtx, final ITestResult result) {
- this(testCtx.getSuite().getName(), testCtx.getCurrentXmlTest().getName(), result);
-// this(testCtx.getSuite().getName(),
-// result.getTestName() != null ? result.getTestName() : result.getName(), result);
- }
-
- private void init(final int resultType,
- final String suiteName,
- final String testName,
- final String className,
- final String methodName,
- final String stackTrace,
- final long startMillis,
- final long endMillis,
- final String[] parameters,
- final String[] types,
- final String testDescription,
- String instanceName,
- int invocationCount,
- int currentInvocationCount) {
- m_messageType = resultType;
- m_suiteName = suiteName;
- m_testName = testName;
- m_testClassName = className;
- m_testMethodName = methodName;
- m_stackTrace = stackTrace;
- m_startMillis= startMillis;
- m_endMillis= endMillis;
- m_parameters= parameters;
- m_paramTypes= types;
- m_testDescription= testDescription;
- m_invocationCount = invocationCount;
- m_currentInvocationCount = currentInvocationCount;
- m_instanceName = instanceName;
- }
-
- public int getResult() {
- return m_messageType;
- }
-
- @Override
- public String getMessageAsString() {
- StringBuffer buf = new StringBuffer();
- StringBuffer parambuf = new StringBuffer();
-
- if(null != m_parameters && m_parameters.length > 0) {
- for (int j = 0; j < m_parameters.length; j++) {
- if (j > 0) {
- parambuf.append(MessageHelper.PARAM_DELIMITER);
- }
- parambuf.append(m_paramTypes[j] + ":" + m_parameters[j]);
- }
- }
-
- buf.append(m_messageType)
- .append(MessageHelper.DELIMITER)
- .append(m_suiteName)
- .append(MessageHelper.DELIMITER)
- .append(m_testName)
- .append(MessageHelper.DELIMITER)
- .append(m_testClassName)
- .append(MessageHelper.DELIMITER)
- .append(m_testMethodName)
- .append(MessageHelper.DELIMITER)
- .append(parambuf)
- .append(MessageHelper.DELIMITER)
- .append(m_startMillis)
- .append(MessageHelper.DELIMITER)
- .append(m_endMillis)
- .append(MessageHelper.DELIMITER)
- .append(MessageHelper.replaceNewLine(m_stackTrace))
- .append(MessageHelper.DELIMITER)
- .append(MessageHelper.replaceNewLine(m_testDescription))
- ;
-
- return buf.toString();
- }
-
- public String getSuiteName() {
- return m_suiteName;
- }
-
- public String getTestClass() {
- return m_testClassName;
- }
-
- public String getMethod() {
- return m_testMethodName;
- }
-
- public String getName() {
- return m_testName;
- }
-
- public String getStackTrace() {
- return m_stackTrace;
- }
-
- public long getEndMillis() {
- return m_endMillis;
- }
-
- public long getStartMillis() {
- return m_startMillis;
- }
-
- public String[] getParameters() {
- return m_parameters;
- }
-
- public String[] getParameterTypes() {
- return m_paramTypes;
- }
-
- public String getTestDescription() {
- return m_testDescription;
- }
-
- public String toDisplayString() {
- StringBuffer buf= new StringBuffer(m_testName != null ? m_testName : m_testMethodName);
-
- if(null != m_parameters && m_parameters.length > 0) {
- buf.append("(");
- for(int i= 0; i < m_parameters.length; i++) {
- if(i > 0) {
- buf.append(", ");
- }
- if("java.lang.String".equals(m_paramTypes[i]) && !("null".equals(m_parameters[i]) || "\"\"".equals(m_parameters[i]))) {
- buf.append("\"").append(m_parameters[i]).append("\"");
- }
- else {
- buf.append(m_parameters[i]);
- }
-
- }
- buf.append(")");
- }
-
- return buf.toString();
- }
-
- @Override
- public boolean equals(Object o) {
- if(this == o) {
- return true;
- }
- if(o == null || getClass() != o.getClass()) {
- return false;
- }
-
- final TestResultMessage that = (TestResultMessage) o;
-
- if(m_suiteName != null ? !m_suiteName.equals(that.m_suiteName) : that.m_suiteName != null) {
- return false;
- }
- if(m_testName != null ? !m_testName.equals(that.m_testName) : that.m_testName != null) {
- return false;
- }
- if(m_testClassName != null ? !m_testClassName.equals(that.m_testClassName) : that.m_testClassName != null) {
- return false;
- }
- String toDisplayString= toDisplayString();
- if(toDisplayString != null ? !toDisplayString.equals(that.toDisplayString()) : that.toDisplayString() != null) {
- return false;
- }
-
- return true;
- }
-
- @Override
- public int hashCode() {
- int result = (m_suiteName != null ? m_suiteName.hashCode() : 0);
- result = 29 * result + (m_testName != null ? m_testName.hashCode() : 0);
- result = 29 * result + m_testClassName.hashCode();
- result = 29 * result + toDisplayString().hashCode();
- return result;
- }
-
- String[] toString(Object[] objects, Class>[] objectClasses) {
- if(null == objects) {
- return new String[0];
- }
- List result= Lists.newArrayList(objects.length);
- for(Object o: objects) {
- if(null == o) {
- result.add("null");
- }
- else if (o.getClass().isArray()) {
- String[] strArray;
- if (o.getClass().getComponentType().isPrimitive()){
- strArray = primitiveArrayToString(o);
- } else {
- strArray = toString((Object[]) o, null);
- }
- StringBuilder sb = new StringBuilder("[");
- for (int i = 0; i < strArray.length; i++)
- {
- sb.append(strArray[i]);
- if (i + 1 < strArray.length)
- {
- sb.append(",");
- }
- }
- sb.append("]");
- result.add(sb.toString());
- }
- else {
- String tostring= o.toString();
- if(isStringEmpty(tostring)) {
- result.add("\"\"");
- }
- else {
- result.add(MessageHelper.replaceNewLine(tostring));
- }
- }
- }
-
- return result.toArray(new String[result.size()]);
- }
-
- private String[] primitiveArrayToString(Object o) {
- List results = Lists.newArrayList();
- if (o instanceof byte[]) {
- byte[] array = (byte[]) o;
- for (byte anArray : array) {
- results.add(String.valueOf(anArray));
- }
- } else if (o instanceof boolean[]) {
- boolean[] array = (boolean[]) o;
- for (boolean anArray : array) {
- results.add(String.valueOf(anArray));
- }
- } else if (o instanceof char[]) {
- char[] array = (char[]) o;
- for (char anArray : array) {
- results.add(String.valueOf(anArray));
- }
- } else if (o instanceof double[]) {
- double[] array = (double[]) o;
- for (double anArray : array) {
- results.add(String.valueOf(anArray));
- }
- } else if (o instanceof float[]) {
- float[] array = (float[]) o;
- for (float anArray : array) {
- results.add(String.valueOf(anArray));
- }
- } else if (o instanceof short[]) {
- short[] array = (short[]) o;
- for (short anArray : array) {
- results.add(String.valueOf(anArray));
- }
- } else if (o instanceof int[]) {
- int[] array = (int[]) o;
- for (int anArray : array) {
- results.add(String.valueOf(anArray));
- }
- } else if (o instanceof long[]) {
- long[] array = (long[]) o;
- for (long anArray : array) {
- results.add(String.valueOf(anArray));
- }
- }
- return results.toArray(new String[results.size()]);
- }
-
- private String[] toString(Class>[] classes) {
- if(null == classes) {
- return new String[0];
- }
- List result= Lists.newArrayList(classes.length);
- for(Class> cls: classes) {
- result.add(cls.getName());
- }
-
- return result.toArray(new String[result.size()]);
- }
-
- private String[] extractParamTypes(String[] params) {
- List result= Lists.newArrayList(params.length);
- for(String s: params) {
- result.add(s.substring(0, s.indexOf(':')));
- }
-
- return result.toArray(new String[result.size()]);
- }
-
- private String[] extractParams(String[] params) {
- List result= Lists.newArrayList(params.length);
- for(String s: params) {
- result.add(MessageHelper.replaceNewLineReplacer(s.substring(s.indexOf(':') + 1)));
- }
-
- return result.toArray(new String[result.size()]);
- }
-
- public int getInvocationCount() {
- return m_invocationCount;
- }
-
- public int getCurrentInvocationCount() {
- return m_currentInvocationCount;
- }
-
- @Override
- public String toString() {
- return "[TestResultMessage suite:" + m_suiteName + " test:" + m_testName
- + " method:" + m_testMethodName
- + "]";
- }
-
- public void setParameters(String[] params) {
- m_parameters = extractParams(params);
- m_paramTypes = extractParamTypes(params);
- }
-
- public String getInstanceName() {
- return m_instanceName;
- }
-}
diff --git a/src/main/java/org/testng/xml/LaunchSuite.java b/src/main/java/org/testng/xml/LaunchSuite.java
index 7f456ed03a..8100392eeb 100755
--- a/src/main/java/org/testng/xml/LaunchSuite.java
+++ b/src/main/java/org/testng/xml/LaunchSuite.java
@@ -4,9 +4,7 @@
import static org.testng.internal.Utils.isStringNotBlank;
import org.testng.collections.Lists;
-import org.testng.internal.Utils;
import org.testng.log4testng.Logger;
-import org.testng.remote.RemoteTestNG;
import org.testng.reporters.XMLStringBuffer;
import java.io.File;
@@ -90,13 +88,7 @@ public XMLStringBuffer getSuiteBuffer() {
*/
@Override
public File save(File directory) {
- if (RemoteTestNG.isDebug()) {
- File result = new File(directory, RemoteTestNG.DEBUG_SUITE_FILE);
- Utils.copyFile(m_suitePath, result);
- return result;
- } else {
- return m_suitePath;
- }
+ return m_suitePath;
}
}
diff --git a/src/main/java/org/testng/xml/ResultContentHandler.java b/src/main/java/org/testng/xml/ResultContentHandler.java
deleted file mode 100644
index e1851c3f1a..0000000000
--- a/src/main/java/org/testng/xml/ResultContentHandler.java
+++ /dev/null
@@ -1,152 +0,0 @@
-package org.testng.xml;
-
-import static org.testng.reporters.XMLReporterConfig.ATTR_DESC;
-import static org.testng.reporters.XMLReporterConfig.ATTR_DURATION_MS;
-import static org.testng.reporters.XMLReporterConfig.ATTR_NAME;
-import static org.testng.reporters.XMLReporterConfig.ATTR_STATUS;
-import static org.testng.reporters.XMLReporterConfig.TAG_CLASS;
-import static org.testng.reporters.XMLReporterConfig.TAG_PARAMS;
-import static org.testng.reporters.XMLReporterConfig.TAG_SUITE;
-import static org.testng.reporters.XMLReporterConfig.TAG_TEST;
-import static org.testng.reporters.XMLReporterConfig.TAG_TEST_METHOD;
-
-import org.testng.ITestResult;
-import org.testng.collections.Lists;
-import org.testng.remote.strprotocol.GenericMessage;
-import org.testng.remote.strprotocol.IRemoteSuiteListener;
-import org.testng.remote.strprotocol.IRemoteTestListener;
-import org.testng.remote.strprotocol.MessageHelper;
-import org.testng.remote.strprotocol.SuiteMessage;
-import org.testng.remote.strprotocol.TestMessage;
-import org.testng.remote.strprotocol.TestResultMessage;
-import org.testng.reporters.XMLReporterConfig;
-import org.xml.sax.Attributes;
-import org.xml.sax.helpers.DefaultHandler;
-
-import java.util.List;
-
-/**
- * Parses testng-result.xml, create TestResultMessages and send them back to the listener
- * as we encounter them.
- *
- * @author Cedric Beust
- */
-public class ResultContentHandler extends DefaultHandler {
- private int m_suiteMethodCount = 0;
- private int m_testMethodCount = 0;
- private SuiteMessage m_currentSuite;
- private TestMessage m_currentTest;
- private String m_className;
- private int m_passed;
- private int m_failed;
- private int m_skipped;
- private int m_invocationCount;
- private int m_currentInvocationCount;
- private TestResultMessage m_currentTestResult;
- private IRemoteSuiteListener m_suiteListener;
- private IRemoteTestListener m_testListener;
- private List m_params = null;
-
- public ResultContentHandler(IRemoteSuiteListener suiteListener,
- IRemoteTestListener testListener, boolean resolveClasses /* ignored */) {
- m_suiteListener = suiteListener;
- m_testListener = testListener;
- }
-
- @Override
- public void startElement (String uri, String localName,
- String qName, Attributes attributes) {
- p("Start " + qName);
- if (TAG_SUITE.equals(qName)) {
- m_suiteListener.onInitialization(new GenericMessage(MessageHelper.GENERIC_SUITE_COUNT));
- m_suiteMethodCount = 0;
- m_currentSuite = new SuiteMessage(attributes.getValue(ATTR_NAME),
- true /* start */, m_suiteMethodCount);
- m_suiteListener.onStart(m_currentSuite);
- } else if (TAG_TEST.equals(qName)) {
- m_passed = m_failed = m_skipped = 0;
- m_currentTest = new TestMessage(true /* start */, m_currentSuite.getSuiteName(),
- attributes.getValue(ATTR_NAME), m_testMethodCount,
- m_passed, m_failed, m_skipped, 0);
- m_testListener.onStart(m_currentTest);
- } else if (TAG_CLASS.equals(qName)) {
- m_className = attributes.getValue(ATTR_NAME);
- } else if (TAG_TEST_METHOD.equals(qName)) {
- Integer status = XMLReporterConfig.getStatus(attributes.getValue(ATTR_STATUS));
- m_currentTestResult = new TestResultMessage(status, m_currentSuite.getSuiteName(),
- m_currentTest.getTestName(), m_className, attributes.getValue(ATTR_NAME),
- attributes.getValue(ATTR_DESC),
- attributes.getValue(ATTR_DESC),
- new String[0], /* no parameters, filled later */
- 0, Long.parseLong(attributes.getValue(ATTR_DURATION_MS)),
- "" /* stack trace, filled later */,
- m_invocationCount, m_currentInvocationCount);
- m_suiteMethodCount++;
- m_testMethodCount++;
- if (status == ITestResult.SUCCESS) m_passed++;
- else if (status == ITestResult.FAILURE) m_failed++;
- else if (status == ITestResult.SKIP) m_skipped++;
- } else if (TAG_PARAMS.equals(qName)) {
- m_params = Lists.newArrayList();
- }
- }
-
- @Override
- public void characters(char[] ch, int start, int length) {
- if (m_params != null) {
- String string = new String(ch, start, length);
- String parameter = string;
- if (parameter.trim().length() != 0) {
- m_params.add(parameter);
- }
- }
- }
-
- @Override
- public void endElement (String uri, String localName, String qName) {
- if (TAG_SUITE.equals(qName)) {
- m_suiteListener.onFinish(new SuiteMessage(null, false /* end */, m_suiteMethodCount));
- m_currentSuite = null;
- } else if (TAG_TEST.equals(qName)) {
- m_currentTest = new TestMessage(false /* start */, m_currentSuite.getSuiteName(),
- null, m_testMethodCount,
- m_passed, m_failed, m_skipped, 0);
- m_testMethodCount = 0;
- m_testListener.onFinish(m_currentTest);
- } else if (TAG_CLASS.equals(qName)) {
- m_className = null;
- } else if (TAG_TEST_METHOD.equals(qName)) {
- switch(m_currentTestResult.getResult()) {
- case ITestResult.SUCCESS:
- m_testListener.onTestSuccess(m_currentTestResult);
- break;
- case ITestResult.FAILURE:
- m_testListener.onTestFailure(m_currentTestResult);
- break;
- case ITestResult.SKIP:
- m_testListener.onTestSkipped(m_currentTestResult);
- break;
- default:
- p("Ignoring test status:" + m_currentTestResult.getResult());
- }
- }
- else if (TAG_PARAMS.equals(qName)) {
- String[] params = new String[m_params.size()];
- for (int i = 0; i < m_params.size(); i++) {
- // The parameters are encoded as type:value. Since we only care about the
- // value (and we don't receive the type anyway), use a dummy character in
- // its place
- params[i] = "@:" + m_params.get(i);
- }
- m_currentTestResult.setParameters(params);
- m_params = null;
- }
- }
-
- private static void p(String string) {
- if (false) {
- System.out.println("[ResultContentHandler] " + string);
- }
- }
-}
-
diff --git a/src/main/java/org/testng/xml/ResultXMLParser.java b/src/main/java/org/testng/xml/ResultXMLParser.java
deleted file mode 100644
index b3f5d1402b..0000000000
--- a/src/main/java/org/testng/xml/ResultXMLParser.java
+++ /dev/null
@@ -1,103 +0,0 @@
-package org.testng.xml;
-
-import org.testng.TestNGException;
-import org.testng.remote.strprotocol.GenericMessage;
-import org.testng.remote.strprotocol.IRemoteSuiteListener;
-import org.testng.remote.strprotocol.IRemoteTestListener;
-import org.testng.remote.strprotocol.SuiteMessage;
-import org.testng.remote.strprotocol.TestMessage;
-import org.testng.remote.strprotocol.TestResultMessage;
-import org.xml.sax.SAXException;
-
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.IOException;
-import java.io.InputStream;
-
-/**
- * Parses testng-result.xml.
- *
- * @see ResultContentHandler
- *
- * @author Cedric Beust
- */
-public class ResultXMLParser extends XMLParser