Skip to content

Commit

Permalink
feat: incorporate with the deprecated api cleanup per upstream (#175)
Browse files Browse the repository at this point in the history
  • Loading branch information
missedone authored Jan 15, 2024
1 parent b9834b4 commit e3d9148
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ private IMessageSender getMessageSender() {
}
}

// fall back to original behivour
// fall back to original behaviour
return m_serPort != null
? new SerializedMessageSender(m_host, m_serPort, m_ack)
: new StringMessageSender(m_host, m_port);
Expand Down
8 changes: 8 additions & 0 deletions remote/src/main/java/org/testng/remote/RemoteArgs.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@
import com.beust.jcommander.Parameter;

public class RemoteArgs {
public static final String DEBUG = "-serdebug";
@Parameter(names = DEBUG, hidden = true, description = "Used to debug TestNG")
public Boolean debug = Boolean.FALSE;

public static final String HOST = "-serhost";
@Parameter(names = HOST, description = "The host", hidden = true)
public String host;

public static final String PORT = "-serport";
@Parameter(names = PORT, description = "The port for the serialization protocol")
public Integer serPort;
Expand Down
63 changes: 52 additions & 11 deletions remote/src/main/java/org/testng/remote/RemoteTestNG.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,26 @@ public static void main(String[] args) throws ParameterException {

IRemoteTestNG remoteTestNg = factory.createRemoteTestNG();
remoteTestNg.dontExit(ra.dontExit);
if (cla.port != null && ra.serPort != null) {
throw new TestNGException("Can only specify one of " + CommandLineArgs.PORT
+ " and " + RemoteArgs.PORT);

boolean debug = ra.debug;
if (!debug) {
// use reflection below for backward compatibility of testng version < 7.10.0
try {
Field debugField = CommandLineArgs.class.getDeclaredField("debug");
Object d = debugField.get(cla);
if (d != null) {
if (Boolean.valueOf(d.toString())) {
debug = true;
}
}
} catch (NoSuchFieldException | IllegalAccessException e) {
if (isDebug()) {
e.printStackTrace();
}
}
}
m_debug = cla.debug;
remoteTestNg.setDebug(cla.debug);
m_debug = debug;
remoteTestNg.setDebug(debug);
remoteTestNg.setAck(ra.ack);

initAndRun(remoteTestNg, args, cla, ra);
Expand Down Expand Up @@ -226,17 +240,45 @@ private static Version parseVersionFromManifest() throws Exception {
private static void initAndRun(IRemoteTestNG remoteTestNg, String[] args, CommandLineArgs cla, RemoteArgs ra) {
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;
ra.serPort = Integer.parseInt(DEBUG_PORT);
cla.suiteFiles = Arrays.asList(new String[] {
DEBUG_SUITE_DIRECTORY + DEBUG_SUITE_FILE
});
}
remoteTestNg.configure(cla);
remoteTestNg.setHost(cla.host);
String host = ra.host;
if (host == null || host.isBlank()) {
// use reflection below for backward compatibility of testng version < 7.10.0
try {
Field hostField = CommandLineArgs.class.getDeclaredField("host");
Object h = hostField.get(cla);
if (h != null) {
host = (String) h;
}
} catch (NoSuchFieldException | IllegalAccessException e) {
if (isDebug()) {
e.printStackTrace();
}
}
}
remoteTestNg.setHost(host);
remoteTestNg.setSerPort(ra.serPort);
remoteTestNg.setProtocol(ra.protocol);
remoteTestNg.setPort(cla.port);

Integer port = null;
// use reflection below for backward compatibility of testng version < 7.10.0
try {
Field portField = CommandLineArgs.class.getDeclaredField("port");
Object p = portField.get(cla);
if (p != null) {
port = Integer.valueOf(p.toString());
}
} catch (NoSuchFieldException | IllegalAccessException e) {
if (isDebug()) {
e.printStackTrace();
}
}
remoteTestNg.setPort(port);
if (isVerbose()) {
StringBuilder sb = new StringBuilder("Invoked with ");
for (String s : args) {
Expand Down Expand Up @@ -280,8 +322,7 @@ static Version toVersion(String strVer) {
}

public static boolean isVerbose() {
boolean result = System.getProperty(PROPERTY_VERBOSE) != null || isDebug();
return result;
return System.getProperty(PROPERTY_VERBOSE) != null || isDebug();
}

public static boolean isDebug() {
Expand Down
29 changes: 13 additions & 16 deletions remote/src/test/java/test/remote/RemoteTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,22 +63,19 @@ public void testString() {
}

private void launchRemoteTestNG(final String portArg, final int portValue, final String protocol) {
new Thread(new Runnable() {
@Override
public void run() {
List<String> args = new ArrayList<>();
args.add(portArg);
args.add(Integer.toString(portValue));
args.add(RemoteArgs.VERSION);
args.add(getTestNGVersion());
if (protocol != null) {
args.add(RemoteArgs.PROTOCOL);
args.add(protocol);
}
args.add("-dontexit");
args.add(getPathToResource("testng-remote.xml"));
RemoteTestNG.main(args.toArray(new String[0]));
}
new Thread(() -> {
List<String> args = new ArrayList<>();
args.add(portArg);
args.add(Integer.toString(portValue));
args.add(RemoteArgs.VERSION);
args.add(getTestNGVersion());
if (protocol != null) {
args.add(RemoteArgs.PROTOCOL);
args.add(protocol);
}
args.add("-dontexit");
args.add(getPathToResource("testng-remote.xml"));
RemoteTestNG.main(args.toArray(new String[0]));
}).start();
}

Expand Down

0 comments on commit e3d9148

Please sign in to comment.