Repository: geode Updated Branches: refs/heads/develop de819a34e -> 83141509d
refactor ServerStarterRule and LocatorStarterRule so that they can be created without a Properties first. Project: http://git-wip-us.apache.org/repos/asf/geode/repo Commit: http://git-wip-us.apache.org/repos/asf/geode/commit/83141509 Tree: http://git-wip-us.apache.org/repos/asf/geode/tree/83141509 Diff: http://git-wip-us.apache.org/repos/asf/geode/diff/83141509 Branch: refs/heads/develop Commit: 83141509d98c8ec0443235082b891fb64f33bf7a Parents: de819a3 Author: Jinmei Liao <[email protected]> Authored: Fri Feb 10 22:31:50 2017 -0800 Committer: Jinmei Liao <[email protected]> Committed: Tue Feb 14 11:06:33 2017 -0800 ---------------------------------------------------------------------- .../internal/web/RestSecurityWithSSLTest.java | 16 ++----- .../security/CacheServerStartupRule.java | 16 +++---- .../security/MemberMBeanSecurityJUnitTest.java | 16 +++---- .../security/AbstractSecureServerDUnitTest.java | 7 ++- .../ClusterConfigWithoutSecurityDUnitTest.java | 13 ++---- .../SecurityClusterConfigDUnitTest.java | 28 +++--------- .../SecurityWithoutClusterConfigDUnitTest.java | 13 ++---- .../security/StartServerAuthorizationTest.java | 18 +++----- .../dunit/rules/GfshShellConnectionRule.java | 15 ++++-- .../test/dunit/rules/LocatorStarterRule.java | 22 ++++++--- .../test/dunit/rules/ServerStarterRule.java | 48 +++++++++++++++----- .../geode/security/CQClientAuthDunitTest.java | 14 +++--- 12 files changed, 113 insertions(+), 113 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/geode/blob/83141509/geode-assembly/src/test/java/org/apache/geode/rest/internal/web/RestSecurityWithSSLTest.java ---------------------------------------------------------------------- diff --git a/geode-assembly/src/test/java/org/apache/geode/rest/internal/web/RestSecurityWithSSLTest.java b/geode-assembly/src/test/java/org/apache/geode/rest/internal/web/RestSecurityWithSSLTest.java index 2fd6771..09c3e35 100644 --- a/geode-assembly/src/test/java/org/apache/geode/rest/internal/web/RestSecurityWithSSLTest.java +++ b/geode-assembly/src/test/java/org/apache/geode/rest/internal/web/RestSecurityWithSSLTest.java @@ -35,7 +35,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.apache.http.HttpResponse; -import org.junit.After; +import org.junit.Rule; import org.junit.Test; import org.junit.experimental.categories.Category; @@ -46,7 +46,8 @@ import java.util.Properties; public class RestSecurityWithSSLTest { private static int restPort = AvailablePortHelper.getRandomAvailableTCPPort(); - ServerStarterRule serverStarter = null; + @Rule + public ServerStarterRule serverStarter = new ServerStarterRule(); @Test public void testRestSecurityWithSSL() throws Exception { @@ -66,20 +67,11 @@ public class RestSecurityWithSSLTest { properties.setProperty(SSL_TRUSTSTORE_PASSWORD, "password"); properties.setProperty(SSL_PROTOCOLS, "TLSv1.2,TLSv1.1"); - serverStarter = new ServerStarterRule(properties); - serverStarter.startServer(); + serverStarter.startServer(properties); GeodeRestClient restClient = new GeodeRestClient("localhost", restPort, true); HttpResponse response = restClient.doGet("/servers", "cluster", "cluster"); assertEquals(200, GeodeRestClient.getCode(response)); } - - @After - public void after() { - if (serverStarter != null) { - serverStarter.after(); - } - } - } http://git-wip-us.apache.org/repos/asf/geode/blob/83141509/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 07e82c3..ea72cfa 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 @@ -15,25 +15,25 @@ package org.apache.geode.management.internal.security; -import static org.apache.geode.distributed.ConfigurationProperties.*; - -import java.io.Serializable; -import java.util.Properties; +import static org.apache.geode.distributed.ConfigurationProperties.JMX_MANAGER_PORT; +import static org.apache.geode.distributed.ConfigurationProperties.SECURITY_MANAGER; +import org.apache.geode.cache.Cache; +import org.apache.geode.security.TestSecurityManager; +import org.apache.geode.test.dunit.rules.ServerStarterRule; import org.junit.After; import org.junit.Before; import org.junit.rules.ExternalResource; -import org.apache.geode.cache.Cache; -import org.apache.geode.security.TestSecurityManager; -import org.apache.geode.test.dunit.rules.ServerStarterRule; +import java.io.Serializable; +import java.util.Properties; /** * this rule would help you start up a cache server with the given properties in the current VM */ public class CacheServerStartupRule extends ExternalResource implements Serializable { - private ServerStarterRule serverStarter; + private ServerStarterRule serverStarter = null; public static CacheServerStartupRule withDefaultSecurityJson(int jmxManagerPort) { return new CacheServerStartupRule(jmxManagerPort, http://git-wip-us.apache.org/repos/asf/geode/blob/83141509/geode-core/src/test/java/org/apache/geode/management/internal/security/MemberMBeanSecurityJUnitTest.java ---------------------------------------------------------------------- diff --git a/geode-core/src/test/java/org/apache/geode/management/internal/security/MemberMBeanSecurityJUnitTest.java b/geode-core/src/test/java/org/apache/geode/management/internal/security/MemberMBeanSecurityJUnitTest.java index 33b32e9..302a4f3 100644 --- a/geode-core/src/test/java/org/apache/geode/management/internal/security/MemberMBeanSecurityJUnitTest.java +++ b/geode-core/src/test/java/org/apache/geode/management/internal/security/MemberMBeanSecurityJUnitTest.java @@ -14,13 +14,7 @@ */ package org.apache.geode.management.internal.security; -import static org.assertj.core.api.Assertions.*; - -import org.junit.Before; -import org.junit.ClassRule; -import org.junit.Rule; -import org.junit.Test; -import org.junit.experimental.categories.Category; +import static org.assertj.core.api.Assertions.assertThatThrownBy; import org.apache.geode.internal.AvailablePort; import org.apache.geode.management.MemberMXBean; @@ -28,6 +22,10 @@ import org.apache.geode.test.dunit.rules.ConnectionConfiguration; import org.apache.geode.test.dunit.rules.MBeanServerConnectionRule; import org.apache.geode.test.junit.categories.IntegrationTest; import org.apache.geode.test.junit.categories.SecurityTest; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.junit.experimental.categories.Category; @Category({IntegrationTest.class, SecurityTest.class}) public class MemberMBeanSecurityJUnitTest { @@ -36,8 +34,8 @@ public class MemberMBeanSecurityJUnitTest { private MemberMXBean bean; - @ClassRule - public static CacheServerStartupRule serverRule = + @Rule + public CacheServerStartupRule serverRule = CacheServerStartupRule.withDefaultSecurityJson(jmxManagerPort); @Rule http://git-wip-us.apache.org/repos/asf/geode/blob/83141509/geode-core/src/test/java/org/apache/geode/security/AbstractSecureServerDUnitTest.java ---------------------------------------------------------------------- diff --git a/geode-core/src/test/java/org/apache/geode/security/AbstractSecureServerDUnitTest.java b/geode-core/src/test/java/org/apache/geode/security/AbstractSecureServerDUnitTest.java index d202b76..b6d1080 100644 --- a/geode-core/src/test/java/org/apache/geode/security/AbstractSecureServerDUnitTest.java +++ b/geode-core/src/test/java/org/apache/geode/security/AbstractSecureServerDUnitTest.java @@ -35,6 +35,7 @@ import org.apache.geode.test.dunit.internal.JUnit4DistributedTestCase; import org.apache.geode.test.dunit.rules.ServerStarterRule; import org.assertj.core.api.ThrowableAssert.ThrowingCallable; import org.junit.Before; +import org.junit.Rule; import java.util.HashMap; import java.util.Map; @@ -51,6 +52,9 @@ public abstract class AbstractSecureServerDUnitTest extends JUnit4DistributedTes protected int serverPort; protected boolean pdxPersistent = false; + @Rule + public transient ServerStarterRule serverStarter = new ServerStarterRule(); + // overwrite this in child classes public Properties getProperties() { return new Properties() { @@ -73,8 +77,7 @@ public abstract class AbstractSecureServerDUnitTest extends JUnit4DistributedTes @Before public void before() throws Exception { - ServerStarterRule serverStarter = new ServerStarterRule(getProperties()); - serverStarter.startServer(0, pdxPersistent); + serverStarter.startServer(getProperties(), 0, pdxPersistent); serverPort = serverStarter.server.getPort(); Region region = serverStarter.cache.createRegionFactory(RegionShortcut.REPLICATE).create(REGION_NAME); http://git-wip-us.apache.org/repos/asf/geode/blob/83141509/geode-core/src/test/java/org/apache/geode/security/ClusterConfigWithoutSecurityDUnitTest.java ---------------------------------------------------------------------- diff --git a/geode-core/src/test/java/org/apache/geode/security/ClusterConfigWithoutSecurityDUnitTest.java b/geode-core/src/test/java/org/apache/geode/security/ClusterConfigWithoutSecurityDUnitTest.java index 23ffa9a..5d713f6 100644 --- a/geode-core/src/test/java/org/apache/geode/security/ClusterConfigWithoutSecurityDUnitTest.java +++ b/geode-core/src/test/java/org/apache/geode/security/ClusterConfigWithoutSecurityDUnitTest.java @@ -37,13 +37,13 @@ import org.junit.experimental.categories.Category; import java.util.Properties; @Category({DistributedTest.class, SecurityTest.class}) - public class ClusterConfigWithoutSecurityDUnitTest { @Rule public LocatorServerStartupRule lsRule = new LocatorServerStartupRule(); - private ServerStarterRule serverStarter = null; + @Rule + public ServerStarterRule serverStarter = new ServerStarterRule(); @Before public void before() throws Exception { @@ -57,8 +57,6 @@ public class ClusterConfigWithoutSecurityDUnitTest { @After public void after() { IgnoredException.removeAllExpectedExceptions(); - if (serverStarter != null) - serverStarter.after(); } // when locator is not secured, a secured server should be allowed to start with its own security @@ -73,8 +71,7 @@ public class ClusterConfigWithoutSecurityDUnitTest { props.setProperty("use-cluster-configuration", "false"); // initial security properties should only contain initial set of values - serverStarter = new ServerStarterRule(props); - serverStarter.startServer(lsRule.getMember(0).getPort()); + serverStarter.startServer(props, lsRule.getMember(0).getPort()); DistributedSystem ds = serverStarter.cache.getDistributedSystem(); // after cache is created, the configuration won't chagne @@ -94,9 +91,7 @@ public class ClusterConfigWithoutSecurityDUnitTest { props.setProperty("security-manager", "mySecurityManager"); props.setProperty("use-cluster-configuration", "true"); - serverStarter = new ServerStarterRule(props); - - assertThatThrownBy(() -> serverStarter.startServer(lsRule.getMember(0).getPort())) + assertThatThrownBy(() -> serverStarter.startServer(props, lsRule.getMember(0).getPort())) .isInstanceOf(GemFireConfigException.class) .hasMessage(LocalizedStrings.GEMFIRE_CACHE_SECURITY_MISCONFIGURATION.toLocalizedString()); } http://git-wip-us.apache.org/repos/asf/geode/blob/83141509/geode-core/src/test/java/org/apache/geode/security/SecurityClusterConfigDUnitTest.java ---------------------------------------------------------------------- diff --git a/geode-core/src/test/java/org/apache/geode/security/SecurityClusterConfigDUnitTest.java b/geode-core/src/test/java/org/apache/geode/security/SecurityClusterConfigDUnitTest.java index fcda2a3..12c2da3 100644 --- a/geode-core/src/test/java/org/apache/geode/security/SecurityClusterConfigDUnitTest.java +++ b/geode-core/src/test/java/org/apache/geode/security/SecurityClusterConfigDUnitTest.java @@ -33,7 +33,6 @@ import org.apache.geode.test.dunit.rules.ServerStarterRule; import org.apache.geode.test.junit.categories.DistributedTest; import org.apache.geode.test.junit.categories.FlakyTest; import org.apache.geode.test.junit.categories.SecurityTest; -import org.junit.After; import org.junit.Before; import org.junit.Rule; import org.junit.Test; @@ -47,7 +46,8 @@ public class SecurityClusterConfigDUnitTest { @Rule public LocatorServerStartupRule lsRule = new LocatorServerStartupRule(); - private ServerStarterRule serverStarter = null; + @Rule + public ServerStarterRule serverStarter = new ServerStarterRule(); @Before public void before() throws Exception { @@ -64,12 +64,6 @@ public class SecurityClusterConfigDUnitTest { lsRule.startLocatorVM(0, props); } - @After - public void after() { - if (serverStarter != null) - serverStarter.after(); - } - @Category(FlakyTest.class) // GEODE-1977 @Test public void testStartServerWithClusterConfig() throws Exception { @@ -80,8 +74,7 @@ public class SecurityClusterConfigDUnitTest { props.setProperty("use-cluster-configuration", "true"); // initial security properties should only contain initial set of values - serverStarter = new ServerStarterRule(props); - serverStarter.startServer(lsRule.getMember(0).getPort()); + serverStarter.startServer(props, lsRule.getMember(0).getPort()); DistributedSystem ds = serverStarter.cache.getDistributedSystem(); // after cache is created, we got the security props passed in by cluster config @@ -102,8 +95,7 @@ public class SecurityClusterConfigDUnitTest { props.setProperty(SECURITY_MANAGER, SimpleTestSecurityManager.class.getName()); // initial security properties should only contain initial set of values - serverStarter = new ServerStarterRule(props); - serverStarter.startServer(lsRule.getMember(0).getPort()); + serverStarter.startServer(props, lsRule.getMember(0).getPort()); DistributedSystem ds = serverStarter.cache.getDistributedSystem(); // after cache is created, we got the security props passed in by cluster config @@ -124,9 +116,7 @@ public class SecurityClusterConfigDUnitTest { props.setProperty("use-cluster-configuration", "true"); // initial security properties should only contain initial set of values - serverStarter = new ServerStarterRule(props); - - assertThatThrownBy(() -> serverStarter.startServer(lsRule.getMember(0).getPort())) + assertThatThrownBy(() -> serverStarter.startServer(props, lsRule.getMember(0).getPort())) .isInstanceOf(GemFireConfigException.class) .hasMessage(LocalizedStrings.GEMFIRE_CACHE_SECURITY_MISCONFIGURATION.toLocalizedString()); @@ -143,9 +133,7 @@ public class SecurityClusterConfigDUnitTest { props.setProperty("use-cluster-configuration", "true"); // initial security properties should only contain initial set of values - serverStarter = new ServerStarterRule(props); - - assertThatThrownBy(() -> serverStarter.startServer(lsRule.getMember(0).getPort())) + assertThatThrownBy(() -> serverStarter.startServer(props, lsRule.getMember(0).getPort())) .isInstanceOf(GemFireConfigException.class) .hasMessage(LocalizedStrings.GEMFIRE_CACHE_SECURITY_MISCONFIGURATION.toLocalizedString()); @@ -162,9 +150,7 @@ public class SecurityClusterConfigDUnitTest { props.setProperty("security-manager", "mySecurityManager"); props.setProperty("use-cluster-configuration", "false"); - serverStarter = new ServerStarterRule(props); - - assertThatThrownBy(() -> serverStarter.startServer(lsRule.getMember(0).getPort())) + assertThatThrownBy(() -> serverStarter.startServer(props, lsRule.getMember(0).getPort())) .isInstanceOf(GemFireConfigException.class) .hasMessage(LocalizedStrings.GEMFIRE_CACHE_SECURITY_MISCONFIGURATION_2.toLocalizedString()); http://git-wip-us.apache.org/repos/asf/geode/blob/83141509/geode-core/src/test/java/org/apache/geode/security/SecurityWithoutClusterConfigDUnitTest.java ---------------------------------------------------------------------- diff --git a/geode-core/src/test/java/org/apache/geode/security/SecurityWithoutClusterConfigDUnitTest.java b/geode-core/src/test/java/org/apache/geode/security/SecurityWithoutClusterConfigDUnitTest.java index 3add1ab..092e82b 100644 --- a/geode-core/src/test/java/org/apache/geode/security/SecurityWithoutClusterConfigDUnitTest.java +++ b/geode-core/src/test/java/org/apache/geode/security/SecurityWithoutClusterConfigDUnitTest.java @@ -28,7 +28,6 @@ import org.apache.geode.test.dunit.rules.LocatorServerStartupRule; import org.apache.geode.test.dunit.rules.ServerStarterRule; import org.apache.geode.test.junit.categories.DistributedTest; import org.apache.geode.test.junit.categories.SecurityTest; -import org.junit.After; import org.junit.Before; import org.junit.Rule; import org.junit.Test; @@ -43,7 +42,8 @@ public class SecurityWithoutClusterConfigDUnitTest { @Rule public LocatorServerStartupRule lsRule = new LocatorServerStartupRule(); - private ServerStarterRule serverStarter = null; + @Rule + public ServerStarterRule serverStarter = new ServerStarterRule(); @Before public void before() throws Exception { @@ -58,12 +58,6 @@ public class SecurityWithoutClusterConfigDUnitTest { lsRule.startLocatorVM(0, props); } - @After - public void after() { - if (serverStarter != null) - serverStarter.after(); - } - @Test // if a secured locator is started without cluster config service, the server is free to use any // security manager @@ -78,8 +72,7 @@ public class SecurityWithoutClusterConfigDUnitTest { props.setProperty("use-cluster-configuration", "true"); // initial security properties should only contain initial set of values - serverStarter = new ServerStarterRule(props); - serverStarter.startServer(lsRule.getMember(0).getPort()); + serverStarter.startServer(props, lsRule.getMember(0).getPort()); DistributedSystem ds = serverStarter.cache.getDistributedSystem(); assertEquals(3, ds.getSecurityProperties().size()); http://git-wip-us.apache.org/repos/asf/geode/blob/83141509/geode-core/src/test/java/org/apache/geode/security/StartServerAuthorizationTest.java ---------------------------------------------------------------------- diff --git a/geode-core/src/test/java/org/apache/geode/security/StartServerAuthorizationTest.java b/geode-core/src/test/java/org/apache/geode/security/StartServerAuthorizationTest.java index 8a79702..f5cfff6 100644 --- a/geode-core/src/test/java/org/apache/geode/security/StartServerAuthorizationTest.java +++ b/geode-core/src/test/java/org/apache/geode/security/StartServerAuthorizationTest.java @@ -23,9 +23,9 @@ import org.apache.geode.test.dunit.rules.LocatorServerStartupRule; import org.apache.geode.test.dunit.rules.ServerStarterRule; import org.apache.geode.test.junit.categories.DistributedTest; import org.apache.geode.test.junit.categories.SecurityTest; -import org.junit.After; import org.junit.BeforeClass; import org.junit.ClassRule; +import org.junit.Rule; import org.junit.Test; import org.junit.experimental.categories.Category; @@ -37,7 +37,9 @@ public class StartServerAuthorizationTest { @ClassRule public static LocatorServerStartupRule lsRule = new LocatorServerStartupRule(); private static Locator locator = null; - private ServerStarterRule serverStarter = null; + + @Rule + public ServerStarterRule serverStarter = new ServerStarterRule(); @BeforeClass public static void beforeClass() throws Exception { @@ -46,12 +48,6 @@ public class StartServerAuthorizationTest { locator = lsRule.startLocatorVM(0, props); } - @After - public void after() throws Exception { - if (serverStarter != null) - serverStarter.after(); - } - @Test public void testStartServerWithInvalidCredential() throws Exception { Properties props = new Properties(); @@ -59,8 +55,7 @@ public class StartServerAuthorizationTest { props.setProperty("security-username", "user"); props.setProperty("security-password", "wrongPswd"); - serverStarter = new ServerStarterRule(props); - assertThatThrownBy(() -> serverStarter.startServer(locator.getPort())) + assertThatThrownBy(() -> serverStarter.startServer(props, locator.getPort())) .isInstanceOf(GemFireSecurityException.class).hasMessageContaining( "Security check failed. Authentication error. Please check your credentials"); } @@ -73,8 +68,7 @@ public class StartServerAuthorizationTest { props.setProperty("security-username", "user"); props.setProperty("security-password", "user"); - serverStarter = new ServerStarterRule(props); - assertThatThrownBy(() -> serverStarter.startServer(locator.getPort())) + assertThatThrownBy(() -> serverStarter.startServer(props, locator.getPort())) .isInstanceOf(GemFireSecurityException.class) .hasMessageContaining("user not authorized for CLUSTER:MANAGE"); } http://git-wip-us.apache.org/repos/asf/geode/blob/83141509/geode-core/src/test/java/org/apache/geode/test/dunit/rules/GfshShellConnectionRule.java ---------------------------------------------------------------------- diff --git a/geode-core/src/test/java/org/apache/geode/test/dunit/rules/GfshShellConnectionRule.java b/geode-core/src/test/java/org/apache/geode/test/dunit/rules/GfshShellConnectionRule.java index 0ac459c..4729be3 100644 --- a/geode-core/src/test/java/org/apache/geode/test/dunit/rules/GfshShellConnectionRule.java +++ b/geode-core/src/test/java/org/apache/geode/test/dunit/rules/GfshShellConnectionRule.java @@ -26,9 +26,14 @@ import org.apache.geode.test.junit.rules.DescribedExternalResource; import org.junit.runner.Description; /** - * Class which eases the connection to the jmxManager {@link ConnectionConfiguration} it allows for - * the creation of per-test connections with different user/password combinations, or no username - * and password + * Class which eases the connection to the locator/jmxManager in Gfsh shell and execute gfsh + * commands. + * + * if used with {@link ConnectionConfiguration}, you will need to specify a port number when + * constructing this rule. Then this rule will do auto connect for you before running your test. + * + * otherwise, you can call connect with the specific port number yourself in your test. This rules + * handles closing your connection and gfsh instance. * * you can use this as Rule * @@ -59,14 +64,14 @@ public class GfshShellConnectionRule extends DescribedExternalResource { @Override protected void before(Description description) throws Throwable { this.gfsh = new HeadlessGfsh(getClass().getName(), 30, "gfsh_files"); - // do not connect if no port initialized + // do not auto connect if no port initialized if (port < 0) { return; } + // do not auto connect if it's not used with ConnectionConfiguration ConnectionConfiguration config = description.getAnnotation(ConnectionConfiguration.class); if (config == null) { - connect(port, portType); return; } http://git-wip-us.apache.org/repos/asf/geode/blob/83141509/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 00a0f1e..c3e493e 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 @@ -33,14 +33,13 @@ import java.util.concurrent.TimeUnit; /** * This is a rule to start up a locator in your current VM. It's useful for your Integration Tests. * + * You can create this rule with and without a Property. If the rule is created with a property, the + * locator will started automatically for you. If not, you can start the locator by using one of the + * startLocator function. Either way, the rule will handle shutting down the locator properly for + * you. + * * If you need a rule to start a server/locator in different VMs for Distributed tests, You should * use {@link LocatorServerStartupRule}. - * - * <p> - * You may choose to use this class not as a rule or use it in your own rule (see - * {@link LocatorServerStartupRule}), in which case you will need to call startLocator() and after() - * manually. - * </p> */ public class LocatorStarterRule extends ExternalResource implements Serializable { @@ -49,11 +48,19 @@ public class LocatorStarterRule extends ExternalResource implements Serializable private Properties properties; + public LocatorStarterRule() {} + public LocatorStarterRule(Properties properties) { this.properties = properties; } public void startLocator() throws Exception { + if (properties == null) + properties = new Properties(); + startLocator(properties); + } + + public void startLocator(Properties properties) throws Exception { if (!properties.containsKey(MCAST_PORT)) { properties.setProperty(MCAST_PORT, "0"); } @@ -80,7 +87,8 @@ public class LocatorStarterRule extends ExternalResource implements Serializable @Override protected void before() throws Throwable { - startLocator(); + if (properties != null) + startLocator(properties); } @Override http://git-wip-us.apache.org/repos/asf/geode/blob/83141509/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 f93498f..b5ddee6 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 @@ -35,13 +35,16 @@ import java.util.Properties; /** * This is a rule to start up a server in your current VM. It's useful for your Integration Tests. * + * You can create this rule either with a property or without a property. If created with a + * property, The rule will automatically start the server for you with the properties given. + * + * If created without a property, the rule won't start the server until you specicially call one of + * the startServer function. + * + * Either way, the rule will handle properly stopping the server for you. + * * If you need a rule to start a server/locator in different VMs for Distributed tests, You should * use {@link LocatorServerStartupRule}. - * <p> - * You may choose to use this class not as a rule or use it in your own rule (see - * {@link LocatorServerStartupRule}), in which case you will need to call startLocator() and after() - * manually. - * </p> */ public class ServerStarterRule extends ExternalResource implements Serializable { @@ -50,6 +53,12 @@ public class ServerStarterRule extends ExternalResource implements Serializable private Properties properties; + /** + * Default constructor, if used, the rule won't start the server for you, you will need to + * manually start it. The rule will handle stop the server for you. + */ + public ServerStarterRule() {} + public ServerStarterRule(Properties properties) { this.properties = properties; } @@ -63,6 +72,25 @@ public class ServerStarterRule extends ExternalResource implements Serializable } public void startServer(int locatorPort, boolean pdxPersistent) throws Exception { + startServer(properties, locatorPort, pdxPersistent); + } + + public void startServer(Properties properties) throws Exception { + startServer(properties, 0, false); + } + + public void startServer(Properties properties, int locatorPort) throws Exception { + startServer(properties, locatorPort, false); + } + + public void startServer(Properties properties, int locatorPort, boolean pdxPersistent) + throws Exception { + if (properties == null) { + properties = new Properties(); + } + if (locatorPort > 0) { + properties.setProperty(LOCATORS, "localhost[" + locatorPort + "]"); + } if (!properties.containsKey(MCAST_PORT)) { properties.setProperty(MCAST_PORT, "0"); } @@ -70,11 +98,7 @@ public class ServerStarterRule extends ExternalResource implements Serializable properties.setProperty(NAME, this.getClass().getName()); } if (!properties.containsKey(LOCATORS)) { - if (locatorPort > 0) { - properties.setProperty(LOCATORS, "localhost[" + locatorPort + "]"); - } else { - properties.setProperty(LOCATORS, ""); - } + properties.setProperty(LOCATORS, ""); } if (properties.containsKey(JMX_MANAGER_PORT)) { int jmxPort = Integer.parseInt(properties.getProperty(JMX_MANAGER_PORT)); @@ -85,7 +109,6 @@ public class ServerStarterRule extends ExternalResource implements Serializable properties.put(JMX_MANAGER_START, "true"); } } - CacheFactory cf = new CacheFactory(properties); cf.setPdxReadSerialized(pdxPersistent); cf.setPdxPersistent(pdxPersistent); @@ -101,7 +124,8 @@ public class ServerStarterRule extends ExternalResource implements Serializable * connect to, otherwise, this server won't connect to any locator */ protected void before() throws Throwable { - startServer(); + if (properties != null) + startServer(); } @Override http://git-wip-us.apache.org/repos/asf/geode/blob/83141509/geode-cq/src/test/java/org/apache/geode/security/CQClientAuthDunitTest.java ---------------------------------------------------------------------- diff --git a/geode-cq/src/test/java/org/apache/geode/security/CQClientAuthDunitTest.java b/geode-cq/src/test/java/org/apache/geode/security/CQClientAuthDunitTest.java index 1aa275d..ce1782b 100644 --- a/geode-cq/src/test/java/org/apache/geode/security/CQClientAuthDunitTest.java +++ b/geode-cq/src/test/java/org/apache/geode/security/CQClientAuthDunitTest.java @@ -15,12 +15,10 @@ package org.apache.geode.security; -import static org.apache.geode.distributed.ConfigurationProperties.*; - -import java.util.Properties; - -import org.junit.Test; -import org.junit.experimental.categories.Category; +import static org.apache.geode.distributed.ConfigurationProperties.LOCATORS; +import static org.apache.geode.distributed.ConfigurationProperties.MCAST_PORT; +import static org.apache.geode.distributed.ConfigurationProperties.SECURITY_CLIENT_AUTH_INIT; +import static org.apache.geode.distributed.ConfigurationProperties.SECURITY_POST_PROCESSOR; import org.apache.geode.cache.Region; import org.apache.geode.cache.client.ClientCache; @@ -36,6 +34,10 @@ import org.apache.geode.cache.query.QueryService; import org.apache.geode.security.templates.UserPasswordAuthInit; import org.apache.geode.test.junit.categories.DistributedTest; import org.apache.geode.test.junit.categories.SecurityTest; +import org.junit.Test; +import org.junit.experimental.categories.Category; + +import java.util.Properties; @Category({DistributedTest.class, SecurityTest.class}) public class CQClientAuthDunitTest extends AbstractSecureServerDUnitTest {
