Skip to content

Commit

Permalink
feat: incorporate with the deprecated api cleanup per upstream
Browse files Browse the repository at this point in the history
  • Loading branch information
missedone committed Jan 15, 2024
1 parent 35d7b9b commit 0cb4164
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 20 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
2 changes: 1 addition & 1 deletion remote/src/main/java/org/testng/remote/RemoteArgs.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class RemoteArgs {
public String host;

public static final String PORT = "-serport";
@Parameter(names = PORT, required = true, description = "The port for the serialization protocol")
@Parameter(names = PORT, description = "The port for the serialization protocol")
public Integer serPort;

public static final String PROTOCOL = "-protocol";
Expand Down
22 changes: 20 additions & 2 deletions remote/src/main/java/org/testng/remote/RemoteTestNG.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,11 @@ public static void main(String[] args) throws ParameterException {
// use reflection below for backward compatibility of testng version < 7.10.0
try {
Field debugField = CommandLineArgs.class.getDeclaredField("debug");
if (debugField.getBoolean(cla)) {
debug = true;
Object d = debugField.get(cla);
if (d != null) {
if (Boolean.valueOf(d.toString())) {
debug = true;
}
}
} catch (NoSuchFieldException | IllegalAccessException e) {
if (isDebug()) {
Expand Down Expand Up @@ -261,6 +264,21 @@ private static void initAndRun(IRemoteTestNG remoteTestNg, String[] args, Comman
remoteTestNg.setHost(host);
remoteTestNg.setSerPort(ra.serPort);
remoteTestNg.setProtocol(ra.protocol);

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
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 0cb4164

Please sign in to comment.