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

GEODE-9872 DRAFT #7174

Closed
Show file tree
Hide file tree
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 @@ -23,6 +23,7 @@
import static org.apache.geode.distributed.ConfigurationProperties.MCAST_PORT;
import static org.apache.geode.distributed.ConfigurationProperties.USE_CLUSTER_CONFIGURATION;
import static org.apache.geode.distributed.ConfigurationProperties.VALIDATE_SERIALIZABLE_OBJECTS;
import static org.apache.geode.internal.AvailablePortHelper.getRandomAvailableTCPPort;
import static org.apache.geode.util.internal.GeodeGlossary.GEMFIRE_PREFIX;

import java.io.BufferedReader;
Expand Down Expand Up @@ -57,7 +58,6 @@
import org.apache.geode.distributed.internal.DistributionConfig;
import org.apache.geode.distributed.internal.InternalLocator;
import org.apache.geode.distributed.internal.membership.gms.membership.GMSJoinLeave;
import org.apache.geode.internal.AvailablePortHelper;
import org.apache.geode.logging.internal.spi.LoggingProvider;
import org.apache.geode.test.dunit.DUnitEnv;
import org.apache.geode.test.dunit.Host;
Expand Down Expand Up @@ -205,7 +205,7 @@ private static void launch(boolean launchLocator) throws AlreadyBoundException,
deleteDunitSuspectFiles();

// create an RMI registry and add an object to share our tests config
int namingPort = AvailablePortHelper.getRandomAvailableTCPPort();
int namingPort = getRandomAvailableTCPPort();
Registry registry = LocateRegistry.createRegistry(namingPort);
System.setProperty(RMI_PORT_PARAM, "" + namingPort);

Expand Down Expand Up @@ -301,6 +301,7 @@ private static void addSuspectFileAppender(final String workspaceDir) {

private static int startLocator(Registry registry) throws IOException, NotBoundException {
RemoteDUnitVMIF remote = (RemoteDUnitVMIF) registry.lookup("vm" + LOCATOR_VM_NUM);
locatorPort = getRandomAvailableTCPPort();
final File locatorLogFile =
LOCATOR_LOG_TO_DISK ? new File("locator-" + locatorPort + ".log") : new File("");
MethodInvokerResult result = remote.executeMethodOnObject(new SerializableCallable() {
Expand All @@ -322,9 +323,7 @@ public Object call() throws IOException {
p.setProperty(DISABLE_AUTO_RECONNECT, "true");

try {
Locator.startLocatorAndDS(0, locatorLogFile, p);
InternalLocator internalLocator = (InternalLocator) Locator.getLocator();
locatorPort = internalLocator.getPort();
Locator.startLocatorAndDS(locatorPort, locatorLogFile, p);
} finally {
System.getProperties().remove(GMSJoinLeave.BYPASS_DISCOVERY_PROPERTY);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import static org.apache.commons.lang3.SystemUtils.isJavaVersionAtLeast;
import static org.apache.geode.distributed.ConfigurationProperties.GROUPS;
import static org.apache.geode.internal.AvailablePortHelper.getRandomAvailableTCPPort;
import static org.apache.geode.test.dunit.Host.getHost;
import static org.apache.geode.test.dunit.internal.DUnitLauncher.NUM_VMS;
import static org.apache.geode.test.dunit.internal.DUnitLauncher.closeAndCheckForSuspects;
Expand Down Expand Up @@ -207,12 +208,19 @@ public MemberVM startLocatorVM(int index, int port, Properties properties, int..
}

public MemberVM startLocatorVM(int index, String version) {
return startLocatorVM(index, 0, version, x -> x);
int port = getRandomAvailableTCPPort();
return startLocatorVM(index, port, version, x -> x);
}

public MemberVM startLocatorVM(int index,
SerializableFunction<LocatorStarterRule> ruleOperator) {
return startLocatorVM(index, 0, VersionManager.CURRENT_VERSION, ruleOperator);
int port = getRandomAvailableTCPPort();
// Use compose() to put our action at the front of the operator. That way, if the ruleOperator
// also sets a port, that action will override ours, and the locator will use the port specified
// by ruleOperator.
SerializableFunction<LocatorStarterRule> ruleOperatorWithPort =
ruleOperator.compose(x -> x.withPort(port));
return startLocatorVM(index, 0, VersionManager.CURRENT_VERSION, ruleOperatorWithPort);
}

public MemberVM startLocatorVM(int index, int port, String version,
Expand Down