Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TestUtil: set port for fullName and simpleName only #766

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,8 @@ public static String getPortNumber(Class<?> cls) {
return getPortNumber(cls.getName(), cls.getSimpleName());
}
public static String getPortNumber(Class<?> cls, int count) {
return getPortNumber(cls.getName() + "." + count,
cls.getSimpleName() + "." + count);
return getPortNumber(cls.getName() + '.' + count,
cls.getSimpleName() + '.' + count);
}
public static String getPortNumber(String name) {
return getPortNumber(name, name);
Expand All @@ -136,8 +136,8 @@ public static String getNewPortNumber(Class<?> cls) {
return getNewPortNumber(cls.getName(), cls.getSimpleName());
}
public static String getNewPortNumber(Class<?> cls, int count) {
return getNewPortNumber(cls.getName() + "." + count,
cls.getSimpleName() + "." + count);
return getNewPortNumber(cls.getName() + '.' + count,
cls.getSimpleName() + '.' + count);
}
public static String getNewPortNumber(String name) {
return getNewPortNumber(name, name);
Expand All @@ -148,30 +148,12 @@ private static void applyNames(String fullName, String simpleName, String p) {
ports.setProperty("testutil.ports." + simpleName, p);
System.setProperty("testutil.ports." + fullName, p);
System.setProperty("testutil.ports." + simpleName, p);
if (fullName.endsWith("." + simpleName)) {
int idx = fullName.lastIndexOf('.', fullName.lastIndexOf('.'));
while (idx != -1) {
String name = fullName.substring(idx + 1);
ports.setProperty("testutil.ports." + name, p);
System.setProperty("testutil.ports." + name, p);
idx = fullName.lastIndexOf('.', idx - 1);
}
}
}
private static void removeNames(String fullName, String simpleName) {
ports.remove("testutil.ports." + fullName);
ports.remove("testutil.ports." + simpleName);
System.clearProperty("testutil.ports." + fullName);
System.clearProperty("testutil.ports." + simpleName);
if (fullName.endsWith("." + simpleName)) {
int idx = fullName.lastIndexOf('.', fullName.lastIndexOf('.'));
while (idx != -1) {
String name = fullName.substring(idx + 1);
ports.remove("testutil.ports." + name);
System.clearProperty("testutil.ports." + name);
idx = fullName.lastIndexOf('.', idx - 1);
}
}
}

public static String getNewPortNumber(String fullName, String simpleName) {
Expand All @@ -182,10 +164,6 @@ public static String getPortNumber(String fullName, String simpleName) {
String p = ports.getProperty("testutil.ports." + fullName);
if (p == null) {
p = System.getProperty("testutil.ports." + fullName);
if (p != null) {
ports.setProperty("testutil.ports." + fullName, p);
ports.setProperty("testutil.ports." + simpleName, p);
}
}
while (p == null) {
int pn = portNum++;
Expand Down