You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@geode.apache.org by ds...@apache.org on 2017/03/07 19:22:08 UTC
[45/51] [abbrv] geode git commit: GEODE-2267: Enhance server/locator
startup rules to include workingDir
GEODE-2267: Enhance server/locator startup rules to include workingDir
Project: http://git-wip-us.apache.org/repos/asf/geode/repo
Commit: http://git-wip-us.apache.org/repos/asf/geode/commit/a9f0d227
Tree: http://git-wip-us.apache.org/repos/asf/geode/tree/a9f0d227
Diff: http://git-wip-us.apache.org/repos/asf/geode/diff/a9f0d227
Branch: refs/heads/feature/GEM-1195
Commit: a9f0d2272193fdcb43ffaa5b0f06e805ad4effa5
Parents: 6d263d5
Author: Jinmei Liao <ji...@pivotal.io>
Authored: Wed Mar 1 15:12:11 2017 -0800
Committer: Jinmei Liao <ji...@pivotal.io>
Committed: Thu Mar 2 10:33:24 2017 -0800
----------------------------------------------------------------------
geode-assembly/build.gradle | 2 +-
.../management/internal/AgentUtilJUnitTest.java | 14 +---
.../web/RestSecurityIntegrationTest.java | 3 +-
.../web/RestSecurityPostProcessorTest.java | 3 +-
.../rest/internal/web/RestServersJUnitTest.java | 3 +-
.../internal/web/SwaggerVerificationTest.java | 13 +++-
.../geode/tools/pulse/PulseDataExportTest.java | 2 +-
.../geode/distributed/DistributedSystem.java | 14 ++--
.../cli/commands/DeployCommandsDUnitTest.java | 5 +-
.../CacheServerMBeanShiroJUnitTest.java | 8 ++-
.../security/CacheServerStartupRule.java | 9 +--
.../security/DeployCommandsSecurityTest.java | 11 ++-
.../security/GfshCommandsPostProcessorTest.java | 3 +-
.../security/GfshCommandsSecurityTest.java | 3 +-
.../security/JavaRmiServerNameTest.java | 11 ++-
.../security/PeerAuthenticatorDUnitTest.java | 5 +-
...eerSecurityWithEmbeddedLocatorDUnitTest.java | 8 ++-
.../apache/geode/test/dunit/rules/Locator.java | 6 +-
.../dunit/rules/LocatorServerStartupRule.java | 66 ++++++------------
.../test/dunit/rules/LocatorStarterRule.java | 69 +++++++++++++------
.../apache/geode/test/dunit/rules/Member.java | 6 +-
.../apache/geode/test/dunit/rules/Server.java | 6 +-
.../test/dunit/rules/ServerStarterRule.java | 70 ++++++++++++--------
.../commands/QueryNamesOverHttpDUnitTest.java | 25 ++++---
24 files changed, 204 insertions(+), 161 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/geode/blob/a9f0d227/geode-assembly/build.gradle
----------------------------------------------------------------------
diff --git a/geode-assembly/build.gradle b/geode-assembly/build.gradle
index 1c95927..cce5245 100755
--- a/geode-assembly/build.gradle
+++ b/geode-assembly/build.gradle
@@ -96,7 +96,7 @@ test {
}
tasks.withType(Test){
- environment 'GEODE_HOME', "$buildDir/install/${distributions.main.baseName}/lib"
+ environment 'GEODE_HOME', "$buildDir/install/${distributions.main.baseName}"
}
task defaultDistributionConfig(type: JavaExec, dependsOn: classes) {
http://git-wip-us.apache.org/repos/asf/geode/blob/a9f0d227/geode-assembly/src/test/java/org/apache/geode/management/internal/AgentUtilJUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-assembly/src/test/java/org/apache/geode/management/internal/AgentUtilJUnitTest.java b/geode-assembly/src/test/java/org/apache/geode/management/internal/AgentUtilJUnitTest.java
index 3a29e8a..fe1f777 100644
--- a/geode-assembly/src/test/java/org/apache/geode/management/internal/AgentUtilJUnitTest.java
+++ b/geode-assembly/src/test/java/org/apache/geode/management/internal/AgentUtilJUnitTest.java
@@ -14,6 +14,8 @@
*/
package org.apache.geode.management.internal;
+import static org.junit.Assert.assertNotNull;
+
import org.apache.geode.internal.GemFireVersion;
import org.apache.geode.test.junit.categories.IntegrationTest;
import org.junit.Before;
@@ -22,11 +24,7 @@ import org.junit.Test;
import org.junit.contrib.java.lang.system.RestoreSystemProperties;
import org.junit.experimental.categories.Category;
-import static org.junit.Assert.assertNotNull;
-
-import java.io.File;
import java.io.IOException;
-import java.nio.file.Path;
@Category(IntegrationTest.class)
public class AgentUtilJUnitTest {
@@ -39,14 +37,6 @@ public class AgentUtilJUnitTest {
@Before
public void setUp() throws IOException {
- // GEODE-958: We need to set gemfire.home to tell AgentUtil where to find wars in case the env
- // variable GEMFIRE is not set
- Path installDir = new File(".").getAbsoluteFile().toPath().resolve("build").resolve("install")
- .resolve("apache-geode");
- System.out.println("Current dir is " + new File(".").getCanonicalPath());
- System.out.println("Setting gemfire.home to " + installDir);
- System.setProperty("gemfire.home", installDir.toString());
-
version = GemFireVersion.getGemFireVersion();
agentUtil = new AgentUtil(version);
}
http://git-wip-us.apache.org/repos/asf/geode/blob/a9f0d227/geode-assembly/src/test/java/org/apache/geode/rest/internal/web/RestSecurityIntegrationTest.java
----------------------------------------------------------------------
diff --git a/geode-assembly/src/test/java/org/apache/geode/rest/internal/web/RestSecurityIntegrationTest.java b/geode-assembly/src/test/java/org/apache/geode/rest/internal/web/RestSecurityIntegrationTest.java
index f0b6bb3..75a3c2c 100644
--- a/geode-assembly/src/test/java/org/apache/geode/rest/internal/web/RestSecurityIntegrationTest.java
+++ b/geode-assembly/src/test/java/org/apache/geode/rest/internal/web/RestSecurityIntegrationTest.java
@@ -58,11 +58,12 @@ public class RestSecurityIntegrationTest {
};
@ClassRule
- public static ServerStarterRule serverStarter = new ServerStarterRule(properties);
+ public static ServerStarterRule serverStarter = new ServerStarterRule();
private final GeodeRestClient restClient = new GeodeRestClient("localhost", restPort);
@BeforeClass
public static void before() throws Exception {
+ serverStarter.startServer(properties);
serverStarter.cache.createRegionFactory(RegionShortcut.REPLICATE).create(REGION_NAME);
}
http://git-wip-us.apache.org/repos/asf/geode/blob/a9f0d227/geode-assembly/src/test/java/org/apache/geode/rest/internal/web/RestSecurityPostProcessorTest.java
----------------------------------------------------------------------
diff --git a/geode-assembly/src/test/java/org/apache/geode/rest/internal/web/RestSecurityPostProcessorTest.java b/geode-assembly/src/test/java/org/apache/geode/rest/internal/web/RestSecurityPostProcessorTest.java
index 160f634..933f7b2 100644
--- a/geode-assembly/src/test/java/org/apache/geode/rest/internal/web/RestSecurityPostProcessorTest.java
+++ b/geode-assembly/src/test/java/org/apache/geode/rest/internal/web/RestSecurityPostProcessorTest.java
@@ -65,11 +65,12 @@ public class RestSecurityPostProcessorTest {
};
@ClassRule
- public static ServerStarterRule serverStarter = new ServerStarterRule(properties);
+ public static ServerStarterRule serverStarter = new ServerStarterRule();
private final GeodeRestClient restClient = new GeodeRestClient("localhost", restPort);
@BeforeClass
public static void before() throws Exception {
+ serverStarter.startServer(properties);
Region region =
serverStarter.cache.createRegionFactory(RegionShortcut.REPLICATE).create("customers");
region.put("1", new Customer(1L, "John", "Doe", "555555555"));
http://git-wip-us.apache.org/repos/asf/geode/blob/a9f0d227/geode-assembly/src/test/java/org/apache/geode/rest/internal/web/RestServersJUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-assembly/src/test/java/org/apache/geode/rest/internal/web/RestServersJUnitTest.java b/geode-assembly/src/test/java/org/apache/geode/rest/internal/web/RestServersJUnitTest.java
index 10ce515..d97bede 100644
--- a/geode-assembly/src/test/java/org/apache/geode/rest/internal/web/RestServersJUnitTest.java
+++ b/geode-assembly/src/test/java/org/apache/geode/rest/internal/web/RestServersJUnitTest.java
@@ -43,11 +43,12 @@ public class RestServersJUnitTest {
};
@ClassRule
- public static ServerStarterRule serverStarter = new ServerStarterRule(properties);
+ public static ServerStarterRule serverStarter = new ServerStarterRule();
private static GeodeRestClient restClient;
@BeforeClass
public static void before() throws Exception {
+ serverStarter.startServer(properties);
restClient = new GeodeRestClient("localhost", defaultPort);
}
http://git-wip-us.apache.org/repos/asf/geode/blob/a9f0d227/geode-assembly/src/test/java/org/apache/geode/rest/internal/web/SwaggerVerificationTest.java
----------------------------------------------------------------------
diff --git a/geode-assembly/src/test/java/org/apache/geode/rest/internal/web/SwaggerVerificationTest.java b/geode-assembly/src/test/java/org/apache/geode/rest/internal/web/SwaggerVerificationTest.java
index c7d0e73..43960a8 100644
--- a/geode-assembly/src/test/java/org/apache/geode/rest/internal/web/SwaggerVerificationTest.java
+++ b/geode-assembly/src/test/java/org/apache/geode/rest/internal/web/SwaggerVerificationTest.java
@@ -24,12 +24,13 @@ import static org.junit.Assert.assertThat;
import org.apache.geode.internal.AvailablePortHelper;
import org.apache.geode.internal.i18n.LocalizedStrings;
-import org.apache.geode.test.dunit.rules.ServerStarterRule;
import org.apache.geode.security.SimpleTestSecurityManager;
+import org.apache.geode.test.dunit.rules.ServerStarterRule;
import org.apache.geode.test.junit.categories.IntegrationTest;
import org.apache.geode.test.junit.categories.RestAPITest;
import org.apache.http.HttpResponse;
import org.json.JSONObject;
+import org.junit.BeforeClass;
import org.junit.ClassRule;
import org.junit.Test;
import org.junit.experimental.categories.Category;
@@ -50,11 +51,17 @@ public class SwaggerVerificationTest {
};
@ClassRule
- public static ServerStarterRule serverStarter = new ServerStarterRule(properties);
- private final GeodeRestClient restClient = new GeodeRestClient("localhost", restPort);
+ public static ServerStarterRule serverStarter = new ServerStarterRule();
+ private GeodeRestClient restClient;
+
+ @BeforeClass
+ public static void beforeClass() throws Exception {
+ serverStarter.startServer(properties);
+ }
@Test
public void isSwaggerRunning() throws Exception {
+ GeodeRestClient restClient = new GeodeRestClient("localhost", restPort);
// Check the UI
HttpResponse response = restClient.doGetRequest("/geode/swagger-ui.html");
assertThat(GeodeRestClient.getCode(response), is(200));
http://git-wip-us.apache.org/repos/asf/geode/blob/a9f0d227/geode-assembly/src/test/java/org/apache/geode/tools/pulse/PulseDataExportTest.java
----------------------------------------------------------------------
diff --git a/geode-assembly/src/test/java/org/apache/geode/tools/pulse/PulseDataExportTest.java b/geode-assembly/src/test/java/org/apache/geode/tools/pulse/PulseDataExportTest.java
index b547290..fa98ce6 100644
--- a/geode-assembly/src/test/java/org/apache/geode/tools/pulse/PulseDataExportTest.java
+++ b/geode-assembly/src/test/java/org/apache/geode/tools/pulse/PulseDataExportTest.java
@@ -77,7 +77,7 @@ public class PulseDataExportTest {
.addIgnoredException("Failed to properly release resources held by the HTTP service:");
IgnoredException.addIgnoredException("!STOPPED");
- locator = lsRule.startLocatorVMWithPulse(0, new Properties());
+ locator = lsRule.startLocatorVM(0, new Properties());
gfshConnector.connect(locator);
assertThat(gfshConnector.isConnected()).isTrue();
http://git-wip-us.apache.org/repos/asf/geode/blob/a9f0d227/geode-core/src/main/java/org/apache/geode/distributed/DistributedSystem.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/org/apache/geode/distributed/DistributedSystem.java b/geode-core/src/main/java/org/apache/geode/distributed/DistributedSystem.java
index 20c948f..29ebf06 100644
--- a/geode-core/src/main/java/org/apache/geode/distributed/DistributedSystem.java
+++ b/geode-core/src/main/java/org/apache/geode/distributed/DistributedSystem.java
@@ -15,6 +15,8 @@
package org.apache.geode.distributed;
+import static org.apache.geode.distributed.ConfigurationProperties.CONSERVE_SOCKETS;
+
import org.apache.geode.CancelCriterion;
import org.apache.geode.LogWriter;
import org.apache.geode.StatisticsFactory;
@@ -30,17 +32,19 @@ import org.apache.geode.internal.ClassPathLoader;
import org.apache.geode.internal.i18n.LocalizedStrings;
import org.apache.geode.internal.tcp.ConnectionTable;
import org.apache.geode.internal.util.IOUtils;
-import org.apache.geode.security.GemFireSecurityException;
import java.io.File;
import java.net.InetAddress;
import java.net.MalformedURLException;
import java.net.URL;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Properties;
+import java.util.Set;
import java.util.concurrent.TimeUnit;
-import static org.apache.geode.distributed.ConfigurationProperties.*;
-
/**
* A "connection" to a GemFire distributed system. A <code>DistributedSystem</code> is created by
* invoking the {@link #connect} method with a configuration as described
@@ -685,7 +689,7 @@ public abstract class DistributedSystem implements StatisticsFactory {
}
private static URL getFileURL(String fileName) {
- File file = new File(fileName);
+ File file = new File(fileName).getAbsoluteFile();
if (file.exists()) {
try {
http://git-wip-us.apache.org/repos/asf/geode/blob/a9f0d227/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/DeployCommandsDUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/DeployCommandsDUnitTest.java b/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/DeployCommandsDUnitTest.java
index 05f2c0c..5568743 100644
--- a/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/DeployCommandsDUnitTest.java
+++ b/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/DeployCommandsDUnitTest.java
@@ -395,8 +395,9 @@ public class DeployCommandsDUnitTest extends CliCommandTestBase {
Properties properties = new Properties();
properties.setProperty("name", "Manager");
properties.setProperty("groups", groupName);
- ServerStarterRule serverStarterRule = new ServerStarterRule(properties);
- serverStarterRule.startServer(locatorPort);
+ ServerStarterRule serverStarterRule = new ServerStarterRule();
+ serverStarterRule.before();
+ serverStarterRule.startServer(properties, locatorPort);
});
// Create a JAR file
http://git-wip-us.apache.org/repos/asf/geode/blob/a9f0d227/geode-core/src/test/java/org/apache/geode/management/internal/security/CacheServerMBeanShiroJUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/management/internal/security/CacheServerMBeanShiroJUnitTest.java b/geode-core/src/test/java/org/apache/geode/management/internal/security/CacheServerMBeanShiroJUnitTest.java
index 3183aaf..3167931 100644
--- a/geode-core/src/test/java/org/apache/geode/management/internal/security/CacheServerMBeanShiroJUnitTest.java
+++ b/geode-core/src/test/java/org/apache/geode/management/internal/security/CacheServerMBeanShiroJUnitTest.java
@@ -26,6 +26,7 @@ import org.apache.geode.test.dunit.rules.ServerStarterRule;
import org.apache.geode.test.junit.categories.IntegrationTest;
import org.apache.geode.test.junit.categories.SecurityTest;
import org.junit.Before;
+import org.junit.BeforeClass;
import org.junit.ClassRule;
import org.junit.Rule;
import org.junit.Test;
@@ -46,7 +47,12 @@ public class CacheServerMBeanShiroJUnitTest {
private CacheServerMXBean bean;
@ClassRule
- public static ServerStarterRule serverStarter = new ServerStarterRule(properties);
+ public static ServerStarterRule serverStarter = new ServerStarterRule();
+
+ @BeforeClass
+ public static void beforeClass() throws Exception {
+ serverStarter.startServer(properties);
+ }
@Rule
public MBeanServerConnectionRule connectionRule = new MBeanServerConnectionRule(jmxManagerPort);
http://git-wip-us.apache.org/repos/asf/geode/blob/a9f0d227/geode-core/src/test/java/org/apache/geode/management/internal/security/CacheServerStartupRule.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/management/internal/security/CacheServerStartupRule.java b/geode-core/src/test/java/org/apache/geode/management/internal/security/CacheServerStartupRule.java
index ea72cfa..30e1df8 100644
--- a/geode-core/src/test/java/org/apache/geode/management/internal/security/CacheServerStartupRule.java
+++ b/geode-core/src/test/java/org/apache/geode/management/internal/security/CacheServerStartupRule.java
@@ -33,7 +33,8 @@ import java.util.Properties;
*/
public class CacheServerStartupRule extends ExternalResource implements Serializable {
- private ServerStarterRule serverStarter = null;
+ private ServerStarterRule serverStarter = new ServerStarterRule();
+ private Properties properties = new Properties();
public static CacheServerStartupRule withDefaultSecurityJson(int jmxManagerPort) {
return new CacheServerStartupRule(jmxManagerPort,
@@ -41,7 +42,7 @@ public class CacheServerStartupRule extends ExternalResource implements Serializ
}
public CacheServerStartupRule(int jmxManagerPort, String jsonFile) {
- Properties properties = new Properties();
+ properties = new Properties();
if (jmxManagerPort > 0) {
properties.put(JMX_MANAGER_PORT, String.valueOf(jmxManagerPort));
}
@@ -49,12 +50,12 @@ public class CacheServerStartupRule extends ExternalResource implements Serializ
properties.put(SECURITY_MANAGER, TestSecurityManager.class.getName());
properties.put(TestSecurityManager.SECURITY_JSON, jsonFile);
}
- serverStarter = new ServerStarterRule(properties);
}
@Before
public void before() throws Throwable {
- serverStarter.startServer();
+ serverStarter.before();
+ serverStarter.startServer(properties);
serverStarter.cache.createRegionFactory().create("region1");
}
http://git-wip-us.apache.org/repos/asf/geode/blob/a9f0d227/geode-core/src/test/java/org/apache/geode/management/internal/security/DeployCommandsSecurityTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/management/internal/security/DeployCommandsSecurityTest.java b/geode-core/src/test/java/org/apache/geode/management/internal/security/DeployCommandsSecurityTest.java
index e89bd62..88cbfe9 100644
--- a/geode-core/src/test/java/org/apache/geode/management/internal/security/DeployCommandsSecurityTest.java
+++ b/geode-core/src/test/java/org/apache/geode/management/internal/security/DeployCommandsSecurityTest.java
@@ -47,12 +47,7 @@ public class DeployCommandsSecurityTest {
private MemberMXBean bean;
@ClassRule
- public static ServerStarterRule serverRule = new ServerStarterRule(new Properties() {
- {
- setProperty(SECURITY_MANAGER, SimpleTestSecurityManager.class.getName());
- setProperty(JMX_MANAGER_PORT, jmxManagerPort + "");
- }
- });
+ public static ServerStarterRule serverRule = new ServerStarterRule();
@ClassRule
public static TemporaryFolder temporaryFolder = new TemporaryFolder();
@@ -61,6 +56,10 @@ public class DeployCommandsSecurityTest {
@BeforeClass
public static void beforeClass() throws Exception {
+ Properties properties = new Properties();
+ properties.setProperty(SECURITY_MANAGER, SimpleTestSecurityManager.class.getName());
+ properties.setProperty(JMX_MANAGER_PORT, jmxManagerPort + "");
+ serverRule.startServer(properties);
File zipFile = temporaryFolder.newFile(zipFileName);
deployCommand = "deploy --jar=" + zipFile.getAbsolutePath();
}
http://git-wip-us.apache.org/repos/asf/geode/blob/a9f0d227/geode-core/src/test/java/org/apache/geode/management/internal/security/GfshCommandsPostProcessorTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/management/internal/security/GfshCommandsPostProcessorTest.java b/geode-core/src/test/java/org/apache/geode/management/internal/security/GfshCommandsPostProcessorTest.java
index 0980c18..6468195 100644
--- a/geode-core/src/test/java/org/apache/geode/management/internal/security/GfshCommandsPostProcessorTest.java
+++ b/geode-core/src/test/java/org/apache/geode/management/internal/security/GfshCommandsPostProcessorTest.java
@@ -53,13 +53,14 @@ public class GfshCommandsPostProcessorTest {
@ClassRule
- public static ServerStarterRule serverStarter = new ServerStarterRule(properties);
+ public static ServerStarterRule serverStarter = new ServerStarterRule();
@Rule
public GfshShellConnectionRule gfshConnection =
new GfshShellConnectionRule(jmxPort, GfshShellConnectionRule.PortType.jmxManger);
@BeforeClass
public static void beforeClass() throws Exception {
+ serverStarter.startServer(properties);
serverStarter.cache.createRegionFactory(RegionShortcut.REPLICATE).create("region1");
}
http://git-wip-us.apache.org/repos/asf/geode/blob/a9f0d227/geode-core/src/test/java/org/apache/geode/management/internal/security/GfshCommandsSecurityTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/management/internal/security/GfshCommandsSecurityTest.java b/geode-core/src/test/java/org/apache/geode/management/internal/security/GfshCommandsSecurityTest.java
index 2d32905..d1750c3 100644
--- a/geode-core/src/test/java/org/apache/geode/management/internal/security/GfshCommandsSecurityTest.java
+++ b/geode-core/src/test/java/org/apache/geode/management/internal/security/GfshCommandsSecurityTest.java
@@ -78,10 +78,11 @@ public class GfshCommandsSecurityTest {
new GfshShellConnectionRule(jmxPort, GfshShellConnectionRule.PortType.jmxManger);
@ClassRule
- public static ServerStarterRule serverStarter = new ServerStarterRule(properties);
+ public static ServerStarterRule serverStarter = new ServerStarterRule();
@BeforeClass
public static void beforeClass() throws Exception {
+ serverStarter.startServer(properties);
serverStarter.cache.createRegionFactory(RegionShortcut.REPLICATE).create("region1");
}
http://git-wip-us.apache.org/repos/asf/geode/blob/a9f0d227/geode-core/src/test/java/org/apache/geode/management/internal/security/JavaRmiServerNameTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/management/internal/security/JavaRmiServerNameTest.java b/geode-core/src/test/java/org/apache/geode/management/internal/security/JavaRmiServerNameTest.java
index 2ae6140..070e905 100644
--- a/geode-core/src/test/java/org/apache/geode/management/internal/security/JavaRmiServerNameTest.java
+++ b/geode-core/src/test/java/org/apache/geode/management/internal/security/JavaRmiServerNameTest.java
@@ -23,6 +23,7 @@ import org.apache.geode.internal.AvailablePort;
import org.apache.geode.test.dunit.rules.ServerStarterRule;
import org.apache.geode.test.junit.categories.IntegrationTest;
import org.junit.After;
+import org.junit.BeforeClass;
import org.junit.ClassRule;
import org.junit.Test;
import org.junit.experimental.categories.Category;
@@ -34,7 +35,6 @@ public class JavaRmiServerNameTest {
private static final String JMX_HOST = "myHostname";
- private static int jmxManagerPort = AvailablePort.getRandomAvailablePort(AvailablePort.SOCKET);
static Properties properties = new Properties() {
{
setProperty(JMX_MANAGER_PORT,
@@ -44,7 +44,14 @@ public class JavaRmiServerNameTest {
};
@ClassRule
- public static ServerStarterRule serverStarter = new ServerStarterRule(properties);
+ public static ServerStarterRule serverStarter = new ServerStarterRule();
+
+ @BeforeClass
+ public static void beforeClass() throws Exception {
+ serverStarter.startServer(properties);
+ }
+
+
// https://issues.apache.org/jira/browse/GEODE-1548
@Test
http://git-wip-us.apache.org/repos/asf/geode/blob/a9f0d227/geode-core/src/test/java/org/apache/geode/security/PeerAuthenticatorDUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/security/PeerAuthenticatorDUnitTest.java b/geode-core/src/test/java/org/apache/geode/security/PeerAuthenticatorDUnitTest.java
index 52afab4..dd913c2 100644
--- a/geode-core/src/test/java/org/apache/geode/security/PeerAuthenticatorDUnitTest.java
+++ b/geode-core/src/test/java/org/apache/geode/security/PeerAuthenticatorDUnitTest.java
@@ -60,9 +60,10 @@ public class PeerAuthenticatorDUnitTest {
VM server2 = getHost(0).getVM(2);
server2.invoke(() -> {
- ServerStarterRule serverStarter = new ServerStarterRule(server2Props);
+ ServerStarterRule serverStarter = new ServerStarterRule();
+ serverStarter.before();
LocatorServerStartupRule.serverStarter = serverStarter;
- assertThatThrownBy(() -> serverStarter.startServer(locatorPort))
+ assertThatThrownBy(() -> serverStarter.startServer(server2Props, locatorPort))
.isInstanceOf(GemFireSecurityException.class).hasMessageContaining("Invalid user name");
});
http://git-wip-us.apache.org/repos/asf/geode/blob/a9f0d227/geode-core/src/test/java/org/apache/geode/security/PeerSecurityWithEmbeddedLocatorDUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/security/PeerSecurityWithEmbeddedLocatorDUnitTest.java b/geode-core/src/test/java/org/apache/geode/security/PeerSecurityWithEmbeddedLocatorDUnitTest.java
index e87a285..c4bb152 100644
--- a/geode-core/src/test/java/org/apache/geode/security/PeerSecurityWithEmbeddedLocatorDUnitTest.java
+++ b/geode-core/src/test/java/org/apache/geode/security/PeerSecurityWithEmbeddedLocatorDUnitTest.java
@@ -61,7 +61,8 @@ public class PeerSecurityWithEmbeddedLocatorDUnitTest {
VM server2 = getHost(0).getVM(2);
server2.invoke(() -> {
- ServerStarterRule serverStarter = new ServerStarterRule(server2Props);
+ ServerStarterRule serverStarter = new ServerStarterRule();
+ serverStarter.before();
LocatorServerStartupRule.serverStarter = serverStarter;
assertThatThrownBy(() -> serverStarter.startServer(locatorPort))
.isInstanceOf(GemFireSecurityException.class)
@@ -92,9 +93,10 @@ public class PeerSecurityWithEmbeddedLocatorDUnitTest {
VM server2 = getHost(0).getVM(2);
server2.invoke(() -> {
- ServerStarterRule serverStarter = new ServerStarterRule(server2Props);
+ ServerStarterRule serverStarter = new ServerStarterRule();
+ serverStarter.before();
LocatorServerStartupRule.serverStarter = serverStarter;
- assertThatThrownBy(() -> serverStarter.startServer(locatorPort))
+ assertThatThrownBy(() -> serverStarter.startServer(server2Props, locatorPort))
.isInstanceOf(GemFireSecurityException.class).hasMessageContaining("Invalid user name");
});
}
http://git-wip-us.apache.org/repos/asf/geode/blob/a9f0d227/geode-core/src/test/java/org/apache/geode/test/dunit/rules/Locator.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/test/dunit/rules/Locator.java b/geode-core/src/test/java/org/apache/geode/test/dunit/rules/Locator.java
index fe26e83..b1004b9 100644
--- a/geode-core/src/test/java/org/apache/geode/test/dunit/rules/Locator.java
+++ b/geode-core/src/test/java/org/apache/geode/test/dunit/rules/Locator.java
@@ -16,13 +16,11 @@
package org.apache.geode.test.dunit.rules;
-import org.apache.geode.test.dunit.VM;
-
import java.io.File;
public class Locator extends Member {
- public Locator(VM vm, int port, File workingDir, String name) {
- super(vm, port, workingDir, name);
+ public Locator(int port, File workingDir, String name) {
+ super(port, workingDir, name);
}
}
http://git-wip-us.apache.org/repos/asf/geode/blob/a9f0d227/geode-core/src/test/java/org/apache/geode/test/dunit/rules/LocatorServerStartupRule.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/test/dunit/rules/LocatorServerStartupRule.java b/geode-core/src/test/java/org/apache/geode/test/dunit/rules/LocatorServerStartupRule.java
index 6844720..39c13d0 100644
--- a/geode-core/src/test/java/org/apache/geode/test/dunit/rules/LocatorServerStartupRule.java
+++ b/geode-core/src/test/java/org/apache/geode/test/dunit/rules/LocatorServerStartupRule.java
@@ -76,6 +76,10 @@ public class LocatorServerStartupRule extends ExternalResource implements Serial
temporaryFolder.delete();
}
+ public Locator startLocatorVM(int index) throws IOException {
+ return startLocatorVM(index, new Properties());
+ }
+
/**
* Starts a locator instance with the given configuration properties inside
* {@code getHost(0).getVM(index)}.
@@ -86,49 +90,19 @@ public class LocatorServerStartupRule extends ExternalResource implements Serial
String name = "locator-" + index;
locatorProperties.setProperty(NAME, name);
File workingDir = createWorkingDirForMember(name);
-
- VM locatorVM = getHost(0).getVM(index);
- int locatorPort = locatorVM.invoke(() -> {
- System.setProperty("user.dir", workingDir.getCanonicalPath());
- locatorStarter = new LocatorStarterRule(locatorProperties);
- locatorStarter.startLocator();
- return locatorStarter.locator.getPort();
- });
- Locator locator = new Locator(locatorVM, locatorPort, workingDir, name);
- members[index] = locator;
- return locator;
- }
-
- public Locator startLocatorVMWithPulse(int index, Properties locatorProperties)
- throws IOException {
- String name = "locator-" + index;
- locatorProperties.setProperty(NAME, name);
- File workingDir = createWorkingDirForMember(name);
-
- // Setting gemfire.home to this value allows locators started by the rule to run Pulse
- String geodeInstallDir = new File(".").getAbsoluteFile().getParentFile().getParentFile()
- .toPath().resolve("geode-assembly").resolve("build").resolve("install")
- .resolve("apache-geode").toString();
-
- System.out.println("Current dir is " + new File(".").getCanonicalPath());
- System.out.println("Setting gemfire.home to " + geodeInstallDir);
-
VM locatorVM = getHost(0).getVM(index);
- int locatorPort = locatorVM.invoke(() -> {
- System.setProperty("user.dir", workingDir.getCanonicalPath());
- System.setProperty("gemfire.home", geodeInstallDir);
- locatorStarter = new LocatorStarterRule(locatorProperties);
- locatorStarter.startLocator();
- return locatorStarter.locator.getPort();
+ Locator locator = locatorVM.invoke(() -> {
+ locatorStarter = new LocatorStarterRule(workingDir);
+ locatorStarter.before();
+ return locatorStarter.startLocator(locatorProperties);
});
- Locator locator = new Locator(locatorVM, locatorPort, workingDir, name);
+ locator.setVM(locatorVM);
members[index] = locator;
return locator;
}
-
- public Locator startLocatorVM(int index) throws IOException {
- return startLocatorVM(index, new Properties());
+ public Server startServerVM(int index) throws IOException {
+ return startServerVM(index, new Properties(), -1);
}
/**
@@ -137,7 +111,7 @@ public class LocatorServerStartupRule extends ExternalResource implements Serial
* @return VM node vm
*/
public Server startServerVM(int index, Properties properties) throws IOException {
- return startServerVM(index, properties, 0);
+ return startServerVM(index, properties, -1);
}
public Server startServerVM(int index, int locatorPort) throws IOException {
@@ -149,18 +123,18 @@ public class LocatorServerStartupRule extends ExternalResource implements Serial
*/
public Server startServerVM(int index, Properties properties, int locatorPort)
throws IOException {
+
String name = "server-" + index;
properties.setProperty(NAME, name);
- File workingDir = createWorkingDirForMember(name);
+ File workingDir = createWorkingDirForMember(name);
VM serverVM = getHost(0).getVM(index);
- int port = serverVM.invoke(() -> {
- System.setProperty("user.dir", workingDir.getCanonicalPath());
- serverStarter = new ServerStarterRule(properties);
- serverStarter.startServer(locatorPort);
- return serverStarter.server.getPort();
+ Server server = serverVM.invoke(() -> {
+ serverStarter = new ServerStarterRule(workingDir);
+ serverStarter.before();
+ return serverStarter.startServer(properties, locatorPort);
});
- Server server = new Server(serverVM, port, workingDir, name);
+ server.setVM(serverVM);
members[index] = server;
return server;
}
@@ -188,7 +162,7 @@ public class LocatorServerStartupRule extends ExternalResource implements Serial
}
private File createWorkingDirForMember(String dirName) throws IOException {
- File workingDir = new File(temporaryFolder.getRoot(), dirName);
+ File workingDir = new File(temporaryFolder.getRoot(), dirName).getAbsoluteFile();
if (!workingDir.exists()) {
temporaryFolder.newFolder(dirName);
}
http://git-wip-us.apache.org/repos/asf/geode/blob/a9f0d227/geode-core/src/test/java/org/apache/geode/test/dunit/rules/LocatorStarterRule.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/test/dunit/rules/LocatorStarterRule.java b/geode-core/src/test/java/org/apache/geode/test/dunit/rules/LocatorStarterRule.java
index c3e493e..84c660c 100644
--- a/geode-core/src/test/java/org/apache/geode/test/dunit/rules/LocatorStarterRule.java
+++ b/geode-core/src/test/java/org/apache/geode/test/dunit/rules/LocatorStarterRule.java
@@ -18,15 +18,20 @@ package org.apache.geode.test.dunit.rules;
import static org.apache.geode.distributed.ConfigurationProperties.JMX_MANAGER;
import static org.apache.geode.distributed.ConfigurationProperties.JMX_MANAGER_PORT;
import static org.apache.geode.distributed.ConfigurationProperties.JMX_MANAGER_START;
+import static org.apache.geode.distributed.ConfigurationProperties.LOG_FILE;
import static org.apache.geode.distributed.ConfigurationProperties.MCAST_PORT;
+import static org.apache.geode.distributed.ConfigurationProperties.NAME;
import static org.junit.Assert.assertTrue;
-import org.awaitility.Awaitility;
+import org.apache.commons.io.FileUtils;
import org.apache.geode.distributed.Locator;
import org.apache.geode.distributed.internal.InternalLocator;
+import org.awaitility.Awaitility;
import org.junit.rules.ExternalResource;
+import java.io.File;
import java.io.Serializable;
+import java.nio.file.Files;
import java.util.Properties;
import java.util.concurrent.TimeUnit;
@@ -46,21 +51,55 @@ public class LocatorStarterRule extends ExternalResource implements Serializable
public InternalLocator locator;
- private Properties properties;
+ private File workingDir;
+ private String oldUserDir;
public LocatorStarterRule() {}
- public LocatorStarterRule(Properties properties) {
- this.properties = properties;
+ public LocatorStarterRule(File workingDir) {
+ this.workingDir = workingDir.getAbsoluteFile();
+ }
+
+ @Override
+ protected void before() throws Exception {
+ oldUserDir = System.getProperty("user.dir");
+ if (workingDir == null) {
+ workingDir = Files.createTempDirectory("locator").toAbsolutePath().toFile();
+ }
+ System.setProperty("user.dir", workingDir.toString());
+ }
+
+ @Override
+ protected void after() {
+ if (locator != null) {
+ locator.stop();
+ }
+ FileUtils.deleteQuietly(workingDir);
+ if (oldUserDir == null) {
+ System.clearProperty("user.dir");
+ } else {
+ System.setProperty("user.dir", oldUserDir);
+ }
}
- public void startLocator() throws Exception {
+
+ public org.apache.geode.test.dunit.rules.Locator startLocator() throws Exception {
+ return startLocator(new Properties());
+ }
+
+ public org.apache.geode.test.dunit.rules.Locator startLocator(Properties properties)
+ throws Exception {
if (properties == null)
properties = new Properties();
- startLocator(properties);
- }
+ if (!properties.containsKey(NAME)) {
+ properties.setProperty(NAME, "locator");
+ }
+
+ String name = properties.getProperty(NAME);
+ if (!properties.containsKey(LOG_FILE)) {
+ properties.setProperty(LOG_FILE, new File(name + ".log").getAbsolutePath());
+ }
- public void startLocator(Properties properties) throws Exception {
if (!properties.containsKey(MCAST_PORT)) {
properties.setProperty(MCAST_PORT, "0");
}
@@ -83,18 +122,6 @@ public class LocatorStarterRule extends ExternalResource implements Serializable
Awaitility.await().atMost(65, TimeUnit.SECONDS)
.until(() -> assertTrue(locator.isSharedConfigurationRunning()));
}
- }
-
- @Override
- protected void before() throws Throwable {
- if (properties != null)
- startLocator(properties);
- }
-
- @Override
- protected void after() {
- if (locator != null) {
- locator.stop();
- }
+ return new org.apache.geode.test.dunit.rules.Locator(locatorPort, workingDir, name);
}
}
http://git-wip-us.apache.org/repos/asf/geode/blob/a9f0d227/geode-core/src/test/java/org/apache/geode/test/dunit/rules/Member.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/test/dunit/rules/Member.java b/geode-core/src/test/java/org/apache/geode/test/dunit/rules/Member.java
index 7cc1eea..5f46da2 100644
--- a/geode-core/src/test/java/org/apache/geode/test/dunit/rules/Member.java
+++ b/geode-core/src/test/java/org/apache/geode/test/dunit/rules/Member.java
@@ -31,7 +31,7 @@ public abstract class Member implements Serializable {
private File workingDir;
private String name;
- public Member(VM vm, int port, File workingDir, String name) {
+ public Member(int port, File workingDir, String name) {
this.vm = vm;
this.port = port;
this.workingDir = workingDir;
@@ -47,6 +47,10 @@ public abstract class Member implements Serializable {
return vm;
}
+ public void setVM(VM vm) {
+ this.vm = vm;
+ }
+
public int getPort() {
return port;
}
http://git-wip-us.apache.org/repos/asf/geode/blob/a9f0d227/geode-core/src/test/java/org/apache/geode/test/dunit/rules/Server.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/test/dunit/rules/Server.java b/geode-core/src/test/java/org/apache/geode/test/dunit/rules/Server.java
index 4aa2c69..83093c4 100644
--- a/geode-core/src/test/java/org/apache/geode/test/dunit/rules/Server.java
+++ b/geode-core/src/test/java/org/apache/geode/test/dunit/rules/Server.java
@@ -16,12 +16,10 @@
package org.apache.geode.test.dunit.rules;
-import org.apache.geode.test.dunit.VM;
-
import java.io.File;
public class Server extends Member {
- public Server(VM vm, int port, File workingDir, String name) {
- super(vm, port, workingDir, name);
+ public Server(int port, File workingDir, String name) {
+ super(port, workingDir, name);
}
}
http://git-wip-us.apache.org/repos/asf/geode/blob/a9f0d227/geode-core/src/test/java/org/apache/geode/test/dunit/rules/ServerStarterRule.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/test/dunit/rules/ServerStarterRule.java b/geode-core/src/test/java/org/apache/geode/test/dunit/rules/ServerStarterRule.java
index b5ddee6..df37579 100644
--- a/geode-core/src/test/java/org/apache/geode/test/dunit/rules/ServerStarterRule.java
+++ b/geode-core/src/test/java/org/apache/geode/test/dunit/rules/ServerStarterRule.java
@@ -19,16 +19,20 @@ import static org.apache.geode.distributed.ConfigurationProperties.JMX_MANAGER;
import static org.apache.geode.distributed.ConfigurationProperties.JMX_MANAGER_PORT;
import static org.apache.geode.distributed.ConfigurationProperties.JMX_MANAGER_START;
import static org.apache.geode.distributed.ConfigurationProperties.LOCATORS;
+import static org.apache.geode.distributed.ConfigurationProperties.LOG_FILE;
import static org.apache.geode.distributed.ConfigurationProperties.MCAST_PORT;
import static org.apache.geode.distributed.ConfigurationProperties.NAME;
+import org.apache.commons.io.FileUtils;
import org.apache.geode.cache.Cache;
import org.apache.geode.cache.CacheFactory;
import org.apache.geode.cache.server.CacheServer;
import org.apache.geode.internal.cache.GemFireCacheImpl;
import org.junit.rules.ExternalResource;
+import java.io.File;
import java.io.Serializable;
+import java.nio.file.Files;
import java.util.Properties;
@@ -51,7 +55,8 @@ public class ServerStarterRule extends ExternalResource implements Serializable
public Cache cache;
public CacheServer server;
- private Properties properties;
+ private File workingDir;
+ private String oldUserDir;
/**
* Default constructor, if used, the rule won't start the server for you, you will need to
@@ -59,44 +64,58 @@ public class ServerStarterRule extends ExternalResource implements Serializable
*/
public ServerStarterRule() {}
- public ServerStarterRule(Properties properties) {
- this.properties = properties;
+ public ServerStarterRule(File workingDir) {
+ this.workingDir = workingDir;
}
- public void startServer() throws Exception {
- startServer(0, false);
+ public void before() throws Exception {
+ oldUserDir = System.getProperty("user.dir");
+ if (workingDir == null) {
+ workingDir = Files.createTempDirectory("server").toAbsolutePath().toFile();
+ }
+ System.setProperty("user.dir", workingDir.toString());
+ }
+
+ public Server startServer() throws Exception {
+ return startServer(new Properties(), -1, false);
}
- public void startServer(int locatorPort) throws Exception {
- startServer(locatorPort, false);
+ public Server startServer(int locatorPort) throws Exception {
+ return startServer(new Properties(), locatorPort, false);
}
- public void startServer(int locatorPort, boolean pdxPersistent) throws Exception {
- startServer(properties, locatorPort, pdxPersistent);
+ public Server startServer(int locatorPort, boolean pdxPersistent) throws Exception {
+ return startServer(new Properties(), locatorPort, pdxPersistent);
}
- public void startServer(Properties properties) throws Exception {
- startServer(properties, 0, false);
+ public Server startServer(Properties properties) throws Exception {
+ return startServer(properties, -1, false);
}
- public void startServer(Properties properties, int locatorPort) throws Exception {
- startServer(properties, locatorPort, false);
+ public Server startServer(Properties properties, int locatorPort) throws Exception {
+ return startServer(properties, locatorPort, false);
}
- public void startServer(Properties properties, int locatorPort, boolean pdxPersistent)
+ public Server startServer(Properties properties, int locatorPort, boolean pdxPersistent)
throws Exception {
if (properties == null) {
properties = new Properties();
}
+ if (!properties.containsKey(NAME)) {
+ properties.setProperty(NAME, "server");
+ }
+ String name = properties.getProperty(NAME);
+ if (!properties.containsKey(LOG_FILE)) {
+ properties.setProperty(LOG_FILE, new File(name + ".log").getAbsolutePath().toString());
+ }
+
if (locatorPort > 0) {
properties.setProperty(LOCATORS, "localhost[" + locatorPort + "]");
}
if (!properties.containsKey(MCAST_PORT)) {
properties.setProperty(MCAST_PORT, "0");
}
- if (!properties.containsKey(NAME)) {
- properties.setProperty(NAME, this.getClass().getName());
- }
+
if (!properties.containsKey(LOCATORS)) {
properties.setProperty(LOCATORS, "");
}
@@ -116,16 +135,7 @@ public class ServerStarterRule extends ExternalResource implements Serializable
server = cache.addCacheServer();
server.setPort(0);
server.start();
- }
-
- /**
- * if you use this class as a rule, the default startServer will be called in the before. You need
- * to make sure your properties to start the server with has the locator information it needs to
- * connect to, otherwise, this server won't connect to any locator
- */
- protected void before() throws Throwable {
- if (properties != null)
- startServer();
+ return new Server(server.getPort(), workingDir, name);
}
@Override
@@ -141,5 +151,11 @@ public class ServerStarterRule extends ExternalResource implements Serializable
server.stop();
server = null;
}
+ FileUtils.deleteQuietly(workingDir);
+ if (oldUserDir == null) {
+ System.clearProperty("user.dir");
+ } else {
+ System.setProperty("user.dir", oldUserDir);
+ }
}
}
http://git-wip-us.apache.org/repos/asf/geode/blob/a9f0d227/geode-web/src/test/java/org/apache/geode/management/internal/cli/commands/QueryNamesOverHttpDUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-web/src/test/java/org/apache/geode/management/internal/cli/commands/QueryNamesOverHttpDUnitTest.java b/geode-web/src/test/java/org/apache/geode/management/internal/cli/commands/QueryNamesOverHttpDUnitTest.java
index 1a19e5e..4ec9c0d 100644
--- a/geode-web/src/test/java/org/apache/geode/management/internal/cli/commands/QueryNamesOverHttpDUnitTest.java
+++ b/geode-web/src/test/java/org/apache/geode/management/internal/cli/commands/QueryNamesOverHttpDUnitTest.java
@@ -29,6 +29,7 @@ import org.apache.geode.management.internal.web.http.HttpMethod;
import org.apache.geode.management.internal.web.shell.RestHttpOperationInvoker;
import org.apache.geode.test.dunit.rules.LocatorStarterRule;
import org.apache.geode.test.junit.categories.IntegrationTest;
+import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.experimental.categories.Category;
@@ -43,22 +44,24 @@ import javax.management.QueryExp;
@Category(IntegrationTest.class)
public class QueryNamesOverHttpDUnitTest {
-
-
protected static int[] ports = AvailablePortHelper.getRandomAvailableTCPPorts(2);
protected static int jmxPort = ports[0];
protected static int httpPort = ports[1];
- private static Properties locatorProps = new Properties() {
- {
- setProperty(HTTP_SERVICE_BIND_ADDRESS, "localhost");
- setProperty(HTTP_SERVICE_PORT, httpPort + "");
- setProperty(JMX_MANAGER_PORT, jmxPort + "");
- }
- };
-
@Rule
- public LocatorStarterRule locatorRule = new LocatorStarterRule(locatorProps);
+ public LocatorStarterRule locatorRule = new LocatorStarterRule();
+
+ @Before
+ public void before() throws Exception {
+ Properties locatorProps = new Properties() {
+ {
+ setProperty(HTTP_SERVICE_BIND_ADDRESS, "localhost");
+ setProperty(HTTP_SERVICE_PORT, httpPort + "");
+ setProperty(JMX_MANAGER_PORT, jmxPort + "");
+ }
+ };
+ locatorRule.startLocator(locatorProps);
+ }
@Test