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/04/21 23:42:01 UTC
[05/51] [abbrv] geode git commit: GEODE-2730: refactor rules
http://git-wip-us.apache.org/repos/asf/geode/blob/6a88f1bc/geode-core/src/test/java/org/apache/geode/security/ClientExecuteRegionFunctionAuthDUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/security/ClientExecuteRegionFunctionAuthDUnitTest.java b/geode-core/src/test/java/org/apache/geode/security/ClientExecuteRegionFunctionAuthDUnitTest.java
index a018f4c..0763407 100644
--- a/geode-core/src/test/java/org/apache/geode/security/ClientExecuteRegionFunctionAuthDUnitTest.java
+++ b/geode-core/src/test/java/org/apache/geode/security/ClientExecuteRegionFunctionAuthDUnitTest.java
@@ -29,8 +29,7 @@ import org.apache.geode.internal.cache.functions.TestFunction;
import org.apache.geode.test.dunit.Host;
import org.apache.geode.test.dunit.VM;
import org.apache.geode.test.dunit.internal.JUnit4DistributedTestCase;
-import org.apache.geode.test.dunit.rules.LocalServerStarterRule;
-import org.apache.geode.test.dunit.rules.ServerStarterBuilder;
+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.Rule;
@@ -49,11 +48,11 @@ public class ClientExecuteRegionFunctionAuthDUnitTest extends JUnit4DistributedT
private final static Function function = new TestFunction(true, TestFunction.TEST_FUNCTION1);
@Rule
- public LocalServerStarterRule server =
- new ServerStarterBuilder().withProperty(SECURITY_MANAGER, TestSecurityManager.class.getName())
+ public ServerStarterRule server =
+ new ServerStarterRule().withProperty(SECURITY_MANAGER, TestSecurityManager.class.getName())
.withProperty(TestSecurityManager.SECURITY_JSON,
"org/apache/geode/management/internal/security/clientServer.json")
- .withRegion(RegionShortcut.REPLICATE, REGION_NAME).buildInThisVM();
+ .withRegion(RegionShortcut.REPLICATE, REGION_NAME);
@Test
public void testExecuteRegionFunction() {
@@ -61,7 +60,7 @@ public class ClientExecuteRegionFunctionAuthDUnitTest extends JUnit4DistributedT
FunctionService.registerFunction(function);
client1.invoke("logging in with dataReader", () -> {
- ClientCache cache = createClientCache("dataReader", "1234567", server.getServerPort());
+ ClientCache cache = createClientCache("dataReader", "1234567", server.getPort());
Region region = createProxyRegion(cache, REGION_NAME);
FunctionService.registerFunction(function);
@@ -71,7 +70,7 @@ public class ClientExecuteRegionFunctionAuthDUnitTest extends JUnit4DistributedT
});
client2.invoke("logging in with super-user", () -> {
- ClientCache cache = createClientCache("super-user", "1234567", server.getServerPort());
+ ClientCache cache = createClientCache("super-user", "1234567", server.getPort());
Region region = createProxyRegion(cache, REGION_NAME);
FunctionService.registerFunction(function);
http://git-wip-us.apache.org/repos/asf/geode/blob/6a88f1bc/geode-core/src/test/java/org/apache/geode/security/ClientGetAllAuthDUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/security/ClientGetAllAuthDUnitTest.java b/geode-core/src/test/java/org/apache/geode/security/ClientGetAllAuthDUnitTest.java
index 92eda18..7339c27 100644
--- a/geode-core/src/test/java/org/apache/geode/security/ClientGetAllAuthDUnitTest.java
+++ b/geode-core/src/test/java/org/apache/geode/security/ClientGetAllAuthDUnitTest.java
@@ -26,8 +26,7 @@ import org.apache.geode.cache.client.ClientCache;
import org.apache.geode.test.dunit.Host;
import org.apache.geode.test.dunit.VM;
import org.apache.geode.test.dunit.internal.JUnit4DistributedTestCase;
-import org.apache.geode.test.dunit.rules.LocalServerStarterRule;
-import org.apache.geode.test.dunit.rules.ServerStarterBuilder;
+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.Rule;
@@ -47,16 +46,16 @@ public class ClientGetAllAuthDUnitTest extends JUnit4DistributedTestCase {
final VM client2 = host.getVM(2);
@Rule
- public LocalServerStarterRule server =
- new ServerStarterBuilder().withProperty(SECURITY_MANAGER, TestSecurityManager.class.getName())
+ public ServerStarterRule server =
+ new ServerStarterRule().withProperty(SECURITY_MANAGER, TestSecurityManager.class.getName())
.withProperty(TestSecurityManager.SECURITY_JSON,
"org/apache/geode/management/internal/security/clientServer.json")
- .withRegion(RegionShortcut.REPLICATE, REGION_NAME).buildInThisVM();
+ .withRegion(RegionShortcut.REPLICATE, REGION_NAME);
@Test
public void testGetAll() {
client1.invoke("logging in Stranger", () -> {
- ClientCache cache = createClientCache("stranger", "1234567", server.getServerPort());
+ ClientCache cache = createClientCache("stranger", "1234567", server.getPort());
Region region = createProxyRegion(cache, REGION_NAME);
Map emptyMap = region.getAll(Arrays.asList("key1", "key2", "key3", "key4"));
@@ -64,7 +63,7 @@ public class ClientGetAllAuthDUnitTest extends JUnit4DistributedTestCase {
});
client2.invoke("logging in authRegionReader", () -> {
- ClientCache cache = createClientCache("authRegionReader", "1234567", server.getServerPort());
+ ClientCache cache = createClientCache("authRegionReader", "1234567", server.getPort());
Region region = createProxyRegion(cache, REGION_NAME);
Map filledMap = region.getAll(Arrays.asList("key1", "key2", "key3", "key4"));
http://git-wip-us.apache.org/repos/asf/geode/blob/6a88f1bc/geode-core/src/test/java/org/apache/geode/security/ClientGetEntryAuthDUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/security/ClientGetEntryAuthDUnitTest.java b/geode-core/src/test/java/org/apache/geode/security/ClientGetEntryAuthDUnitTest.java
index fad77f5..5aaff24 100644
--- a/geode-core/src/test/java/org/apache/geode/security/ClientGetEntryAuthDUnitTest.java
+++ b/geode-core/src/test/java/org/apache/geode/security/ClientGetEntryAuthDUnitTest.java
@@ -21,13 +21,13 @@ import static org.apache.geode.security.SecurityTestUtil.createProxyRegion;
import org.apache.geode.cache.CacheTransactionManager;
import org.apache.geode.cache.Region;
+import org.apache.geode.cache.RegionShortcut;
import org.apache.geode.cache.client.ClientCache;
import org.apache.geode.test.dunit.AsyncInvocation;
import org.apache.geode.test.dunit.Host;
import org.apache.geode.test.dunit.VM;
import org.apache.geode.test.dunit.internal.JUnit4DistributedTestCase;
-import org.apache.geode.test.dunit.rules.LocalServerStarterRule;
-import org.apache.geode.test.dunit.rules.ServerStarterBuilder;
+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.Before;
@@ -45,15 +45,16 @@ public class ClientGetEntryAuthDUnitTest extends JUnit4DistributedTestCase {
final VM client2 = host.getVM(2);
@Rule
- public LocalServerStarterRule server =
- new ServerStarterBuilder().withProperty(SECURITY_MANAGER, TestSecurityManager.class.getName())
+ public ServerStarterRule server =
+ new ServerStarterRule().withProperty(SECURITY_MANAGER, TestSecurityManager.class.getName())
.withProperty(TestSecurityManager.SECURITY_JSON,
"org/apache/geode/management/internal/security/clientServer.json")
- .buildInThisVM();
+ .withAutoStart();
@Before
public void before() throws Exception {
- Region region = server.getCache().createRegionFactory().create(REGION_NAME);
+ Region region =
+ server.getCache().createRegionFactory(RegionShortcut.REPLICATE).create(REGION_NAME);
for (int i = 0; i < 5; i++) {
region.put("key" + i, "value" + i);
}
@@ -63,7 +64,7 @@ public class ClientGetEntryAuthDUnitTest extends JUnit4DistributedTestCase {
public void testGetEntry() throws Exception {
// client1 connects to server as a user not authorized to do any operations
AsyncInvocation ai1 = client1.invokeAsync(() -> {
- ClientCache cache = createClientCache("stranger", "1234567", server.getServerPort());
+ ClientCache cache = createClientCache("stranger", "1234567", server.getPort());
CacheTransactionManager transactionManager = cache.getCacheTransactionManager();
transactionManager.begin();
@@ -77,7 +78,7 @@ public class ClientGetEntryAuthDUnitTest extends JUnit4DistributedTestCase {
});
AsyncInvocation ai2 = client2.invokeAsync(() -> {
- ClientCache cache = createClientCache("authRegionReader", "1234567", server.getServerPort());
+ ClientCache cache = createClientCache("authRegionReader", "1234567", server.getPort());
CacheTransactionManager transactionManager = cache.getCacheTransactionManager();
transactionManager.begin();
http://git-wip-us.apache.org/repos/asf/geode/blob/6a88f1bc/geode-core/src/test/java/org/apache/geode/security/ClientGetPutAuthDUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/security/ClientGetPutAuthDUnitTest.java b/geode-core/src/test/java/org/apache/geode/security/ClientGetPutAuthDUnitTest.java
index a816a12..2b933bf 100644
--- a/geode-core/src/test/java/org/apache/geode/security/ClientGetPutAuthDUnitTest.java
+++ b/geode-core/src/test/java/org/apache/geode/security/ClientGetPutAuthDUnitTest.java
@@ -27,8 +27,7 @@ import org.apache.geode.test.dunit.AsyncInvocation;
import org.apache.geode.test.dunit.Host;
import org.apache.geode.test.dunit.VM;
import org.apache.geode.test.dunit.internal.JUnit4DistributedTestCase;
-import org.apache.geode.test.dunit.rules.LocalServerStarterRule;
-import org.apache.geode.test.dunit.rules.ServerStarterBuilder;
+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.Before;
@@ -53,11 +52,11 @@ public class ClientGetPutAuthDUnitTest extends JUnit4DistributedTestCase {
final VM client3 = host.getVM(3);
@Rule
- public LocalServerStarterRule server =
- new ServerStarterBuilder().withProperty(SECURITY_MANAGER, TestSecurityManager.class.getName())
+ public ServerStarterRule server =
+ new ServerStarterRule().withProperty(SECURITY_MANAGER, TestSecurityManager.class.getName())
.withProperty(TestSecurityManager.SECURITY_JSON,
"org/apache/geode/management/internal/security/clientServer.json")
- .buildInThisVM();
+ .withAutoStart();
@Before
public void before() throws Exception {
@@ -80,7 +79,7 @@ public class ClientGetPutAuthDUnitTest extends JUnit4DistributedTestCase {
// client1 connects to server as a user not authorized to do any operations
AsyncInvocation ai1 = client1.invokeAsync(() -> {
- ClientCache cache = createClientCache("stranger", "1234567", server.getServerPort());
+ ClientCache cache = createClientCache("stranger", "1234567", server.getPort());
Region region = createProxyRegion(cache, REGION_NAME);
assertNotAuthorized(() -> region.put("key3", "value3"), "DATA:WRITE:AuthRegion:key3");
@@ -99,7 +98,7 @@ public class ClientGetPutAuthDUnitTest extends JUnit4DistributedTestCase {
// client2 connects to user as a user authorized to use AuthRegion region
AsyncInvocation ai2 = client2.invokeAsync(() -> {
- ClientCache cache = createClientCache("authRegionUser", "1234567", server.getServerPort());
+ ClientCache cache = createClientCache("authRegionUser", "1234567", server.getPort());
Region region = createProxyRegion(cache, REGION_NAME);
region.put("key3", "value3");
@@ -119,7 +118,7 @@ public class ClientGetPutAuthDUnitTest extends JUnit4DistributedTestCase {
// client3 connects to user as a user authorized to use key1 in AuthRegion region
AsyncInvocation ai3 = client3.invokeAsync(() -> {
- ClientCache cache = createClientCache("key1User", "1234567", server.getServerPort());
+ ClientCache cache = createClientCache("key1User", "1234567", server.getPort());
Region region = createProxyRegion(cache, REGION_NAME);
assertNotAuthorized(() -> region.put("key2", "value1"), "DATA:WRITE:AuthRegion:key2");
http://git-wip-us.apache.org/repos/asf/geode/blob/6a88f1bc/geode-core/src/test/java/org/apache/geode/security/ClientRegionClearAuthDUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/security/ClientRegionClearAuthDUnitTest.java b/geode-core/src/test/java/org/apache/geode/security/ClientRegionClearAuthDUnitTest.java
index 99a77b6..f512178 100644
--- a/geode-core/src/test/java/org/apache/geode/security/ClientRegionClearAuthDUnitTest.java
+++ b/geode-core/src/test/java/org/apache/geode/security/ClientRegionClearAuthDUnitTest.java
@@ -26,8 +26,7 @@ import org.apache.geode.test.dunit.Host;
import org.apache.geode.test.dunit.SerializableRunnable;
import org.apache.geode.test.dunit.VM;
import org.apache.geode.test.dunit.internal.JUnit4DistributedTestCase;
-import org.apache.geode.test.dunit.rules.LocalServerStarterRule;
-import org.apache.geode.test.dunit.rules.ServerStarterBuilder;
+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.Rule;
@@ -44,11 +43,11 @@ public class ClientRegionClearAuthDUnitTest extends JUnit4DistributedTestCase {
final VM client2 = host.getVM(2);
@Rule
- public LocalServerStarterRule server =
- new ServerStarterBuilder().withProperty(SECURITY_MANAGER, TestSecurityManager.class.getName())
+ public ServerStarterRule server =
+ new ServerStarterRule().withProperty(SECURITY_MANAGER, TestSecurityManager.class.getName())
.withProperty(TestSecurityManager.SECURITY_JSON,
"org/apache/geode/management/internal/security/clientServer.json")
- .withRegion(RegionShortcut.REPLICATE, REGION_NAME).buildInThisVM();
+ .withRegion(RegionShortcut.REPLICATE, REGION_NAME);
@Test
public void testRegionClear() throws InterruptedException {
@@ -56,7 +55,7 @@ public class ClientRegionClearAuthDUnitTest extends JUnit4DistributedTestCase {
SerializableRunnable clearUnauthorized = new SerializableRunnable() {
@Override
public void run() {
- ClientCache cache = createClientCache("stranger", "1234567", server.getServerPort());
+ ClientCache cache = createClientCache("stranger", "1234567", server.getPort());
Region region = createProxyRegion(cache, REGION_NAME);
assertNotAuthorized(() -> region.clear(), "DATA:WRITE:AuthRegion");
}
@@ -67,7 +66,7 @@ public class ClientRegionClearAuthDUnitTest extends JUnit4DistributedTestCase {
SerializableRunnable clearAuthorized = new SerializableRunnable() {
@Override
public void run() {
- ClientCache cache = createClientCache("authRegionUser", "1234567", server.getServerPort());
+ ClientCache cache = createClientCache("authRegionUser", "1234567", server.getPort());
Region region = createProxyRegion(cache, REGION_NAME);
region.clear();
}
http://git-wip-us.apache.org/repos/asf/geode/blob/6a88f1bc/geode-core/src/test/java/org/apache/geode/security/ClientRegisterInterestAuthDUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/security/ClientRegisterInterestAuthDUnitTest.java b/geode-core/src/test/java/org/apache/geode/security/ClientRegisterInterestAuthDUnitTest.java
index 9c24d42..f120723 100644
--- a/geode-core/src/test/java/org/apache/geode/security/ClientRegisterInterestAuthDUnitTest.java
+++ b/geode-core/src/test/java/org/apache/geode/security/ClientRegisterInterestAuthDUnitTest.java
@@ -27,8 +27,7 @@ import org.apache.geode.test.dunit.AsyncInvocation;
import org.apache.geode.test.dunit.Host;
import org.apache.geode.test.dunit.VM;
import org.apache.geode.test.dunit.internal.JUnit4DistributedTestCase;
-import org.apache.geode.test.dunit.rules.LocalServerStarterRule;
-import org.apache.geode.test.dunit.rules.ServerStarterBuilder;
+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.Rule;
@@ -49,31 +48,31 @@ public class ClientRegisterInterestAuthDUnitTest extends JUnit4DistributedTestCa
final VM client3 = host.getVM(3);
@Rule
- public LocalServerStarterRule server =
- new ServerStarterBuilder().withProperty(SECURITY_MANAGER, TestSecurityManager.class.getName())
+ public ServerStarterRule server =
+ new ServerStarterRule().withProperty(SECURITY_MANAGER, TestSecurityManager.class.getName())
.withProperty(TestSecurityManager.SECURITY_JSON,
"org/apache/geode/management/internal/security/clientServer.json")
- .withRegion(RegionShortcut.REPLICATE, REGION_NAME).buildInThisVM();
+ .withRegion(RegionShortcut.REPLICATE, REGION_NAME);
@Test
public void testRegisterInterest() throws Exception {
// client1 connects to server as a user not authorized to do any operations
AsyncInvocation ai1 = client1.invokeAsync(() -> {
- ClientCache cache = createClientCache("stranger", "1234567", server.getServerPort());
+ ClientCache cache = createClientCache("stranger", "1234567", server.getPort());
Region region = createProxyRegion(cache, REGION_NAME);
assertNotAuthorized(() -> region.registerInterest("key3"), "DATA:READ:AuthRegion:key3");
});
// client2 connects to user as a user authorized to use AuthRegion region
AsyncInvocation ai2 = client2.invokeAsync(() -> {
- ClientCache cache = createClientCache("authRegionUser", "1234567", server.getServerPort());
+ ClientCache cache = createClientCache("authRegionUser", "1234567", server.getPort());
Region region = createProxyRegion(cache, REGION_NAME);
region.registerInterest("key3"); // DATA:READ:AuthRegion:key3;
});
// client3 connects to user as a user authorized to use key1 in AuthRegion region
AsyncInvocation ai3 = client3.invokeAsync(() -> {
- ClientCache cache = createClientCache("key1User", "1234567", server.getServerPort());
+ ClientCache cache = createClientCache("key1User", "1234567", server.getPort());
Region region = createProxyRegion(cache, REGION_NAME);
assertNotAuthorized(() -> region.registerInterest("key2"), "DATA:READ:AuthRegion:key2");
});
@@ -87,7 +86,7 @@ public class ClientRegisterInterestAuthDUnitTest extends JUnit4DistributedTestCa
public void testRegisterInterestRegex() throws Exception {
// client1 connects to server as a user not authorized to do any operations
AsyncInvocation ai1 = client1.invokeAsync(() -> {
- ClientCache cache = createClientCache("stranger", "1234567", server.getServerPort());
+ ClientCache cache = createClientCache("stranger", "1234567", server.getPort());
Region region =
cache.createClientRegionFactory(ClientRegionShortcut.PROXY).create(REGION_NAME);
@@ -96,7 +95,7 @@ public class ClientRegisterInterestAuthDUnitTest extends JUnit4DistributedTestCa
// client2 connects to user as a user authorized to use AuthRegion region
AsyncInvocation ai2 = client2.invokeAsync(() -> {
- ClientCache cache = createClientCache("authRegionUser", "1234567", server.getServerPort());
+ ClientCache cache = createClientCache("authRegionUser", "1234567", server.getPort());
Region region =
cache.createClientRegionFactory(ClientRegionShortcut.PROXY).create(REGION_NAME);
@@ -105,7 +104,7 @@ public class ClientRegisterInterestAuthDUnitTest extends JUnit4DistributedTestCa
// client3 connects to user as a user authorized to use key1 in AuthRegion region
AsyncInvocation ai3 = client3.invokeAsync(() -> {
- ClientCache cache = createClientCache("key1User", "1234567", server.getServerPort());
+ ClientCache cache = createClientCache("key1User", "1234567", server.getPort());
Region region =
cache.createClientRegionFactory(ClientRegionShortcut.PROXY).create(REGION_NAME);
@@ -126,7 +125,7 @@ public class ClientRegisterInterestAuthDUnitTest extends JUnit4DistributedTestCa
// client1 connects to server as a user not authorized to do any operations
AsyncInvocation ai1 = client1.invokeAsync(() -> {
- ClientCache cache = createClientCache("stranger", "1234567", server.getServerPort());
+ ClientCache cache = createClientCache("stranger", "1234567", server.getPort());
Region region =
cache.createClientRegionFactory(ClientRegionShortcut.PROXY).create(REGION_NAME);
@@ -135,7 +134,7 @@ public class ClientRegisterInterestAuthDUnitTest extends JUnit4DistributedTestCa
// client2 connects to user as a user authorized to use AuthRegion region
AsyncInvocation ai2 = client2.invokeAsync(() -> {
- ClientCache cache = createClientCache("authRegionUser", "1234567", server.getServerPort());
+ ClientCache cache = createClientCache("authRegionUser", "1234567", server.getPort());
Region region =
cache.createClientRegionFactory(ClientRegionShortcut.PROXY).create(REGION_NAME);
@@ -144,7 +143,7 @@ public class ClientRegisterInterestAuthDUnitTest extends JUnit4DistributedTestCa
// client3 connects to user as a user authorized to use key1 in AuthRegion region
AsyncInvocation ai3 = client3.invokeAsync(() -> {
- ClientCache cache = createClientCache("key1User", "1234567", server.getServerPort());
+ ClientCache cache = createClientCache("key1User", "1234567", server.getPort());
Region region =
cache.createClientRegionFactory(ClientRegionShortcut.PROXY).create(REGION_NAME);
http://git-wip-us.apache.org/repos/asf/geode/blob/6a88f1bc/geode-core/src/test/java/org/apache/geode/security/ClientRemoveAllAuthDUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/security/ClientRemoveAllAuthDUnitTest.java b/geode-core/src/test/java/org/apache/geode/security/ClientRemoveAllAuthDUnitTest.java
index 44887d9..8814b09 100644
--- a/geode-core/src/test/java/org/apache/geode/security/ClientRemoveAllAuthDUnitTest.java
+++ b/geode-core/src/test/java/org/apache/geode/security/ClientRemoveAllAuthDUnitTest.java
@@ -27,8 +27,7 @@ import org.apache.geode.test.dunit.AsyncInvocation;
import org.apache.geode.test.dunit.Host;
import org.apache.geode.test.dunit.VM;
import org.apache.geode.test.dunit.internal.JUnit4DistributedTestCase;
-import org.apache.geode.test.dunit.rules.LocalServerStarterRule;
-import org.apache.geode.test.dunit.rules.ServerStarterBuilder;
+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.Rule;
@@ -47,17 +46,17 @@ public class ClientRemoveAllAuthDUnitTest extends JUnit4DistributedTestCase {
final VM client2 = host.getVM(2);
@Rule
- public LocalServerStarterRule server =
- new ServerStarterBuilder().withProperty(SECURITY_MANAGER, TestSecurityManager.class.getName())
+ public ServerStarterRule server =
+ new ServerStarterRule().withProperty(SECURITY_MANAGER, TestSecurityManager.class.getName())
.withProperty(TestSecurityManager.SECURITY_JSON,
"org/apache/geode/management/internal/security/clientServer.json")
- .withRegion(RegionShortcut.REPLICATE, REGION_NAME).buildInThisVM();
+ .withRegion(RegionShortcut.REPLICATE, REGION_NAME);
@Test
public void testRemoveAll() throws Exception {
AsyncInvocation ai1 = client1.invokeAsync(() -> {
- ClientCache cache = createClientCache("authRegionReader", "1234567", server.getServerPort());
+ ClientCache cache = createClientCache("authRegionReader", "1234567", server.getPort());
Region region = createProxyRegion(cache, REGION_NAME);
assertNotAuthorized(() -> region.removeAll(Arrays.asList("key1", "key2", "key3", "key4")),
@@ -65,7 +64,7 @@ public class ClientRemoveAllAuthDUnitTest extends JUnit4DistributedTestCase {
});
AsyncInvocation ai2 = client2.invokeAsync(() -> {
- ClientCache cache = createClientCache("authRegionWriter", "1234567", server.getServerPort());
+ ClientCache cache = createClientCache("authRegionWriter", "1234567", server.getPort());
Region region = createProxyRegion(cache, REGION_NAME);
region.removeAll(Arrays.asList("key1", "key2", "key3", "key4"));
http://git-wip-us.apache.org/repos/asf/geode/blob/6a88f1bc/geode-core/src/test/java/org/apache/geode/security/ClientUnregisterInterestAuthDUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/security/ClientUnregisterInterestAuthDUnitTest.java b/geode-core/src/test/java/org/apache/geode/security/ClientUnregisterInterestAuthDUnitTest.java
index e62aa6a..25a578d 100644
--- a/geode-core/src/test/java/org/apache/geode/security/ClientUnregisterInterestAuthDUnitTest.java
+++ b/geode-core/src/test/java/org/apache/geode/security/ClientUnregisterInterestAuthDUnitTest.java
@@ -25,8 +25,7 @@ import org.apache.geode.test.dunit.AsyncInvocation;
import org.apache.geode.test.dunit.Host;
import org.apache.geode.test.dunit.VM;
import org.apache.geode.test.dunit.internal.JUnit4DistributedTestCase;
-import org.apache.geode.test.dunit.rules.LocalServerStarterRule;
-import org.apache.geode.test.dunit.rules.ServerStarterBuilder;
+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.Rule;
@@ -43,17 +42,17 @@ public class ClientUnregisterInterestAuthDUnitTest extends JUnit4DistributedTest
final VM client2 = host.getVM(2);
@Rule
- public LocalServerStarterRule server =
- new ServerStarterBuilder().withProperty(SECURITY_MANAGER, TestSecurityManager.class.getName())
+ public ServerStarterRule server =
+ new ServerStarterRule().withProperty(SECURITY_MANAGER, TestSecurityManager.class.getName())
.withProperty(TestSecurityManager.SECURITY_JSON,
"org/apache/geode/management/internal/security/clientServer.json")
- .withRegion(RegionShortcut.REPLICATE, REGION_NAME).buildInThisVM();
+ .withRegion(RegionShortcut.REPLICATE, REGION_NAME);
@Test
public void testUnregisterInterest() throws Exception {
// client2 connects to user as a user authorized to use AuthRegion region
AsyncInvocation ai1 = client2.invokeAsync(() -> {
- ClientCache cache = createClientCache("authRegionUser", "1234567", server.getServerPort());
+ ClientCache cache = createClientCache("authRegionUser", "1234567", server.getPort());
Region region = createProxyRegion(cache, REGION_NAME);
region.registerInterest("key3");
http://git-wip-us.apache.org/repos/asf/geode/blob/6a88f1bc/geode-core/src/test/java/org/apache/geode/security/NoShowValue1PostProcessorDUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/security/NoShowValue1PostProcessorDUnitTest.java b/geode-core/src/test/java/org/apache/geode/security/NoShowValue1PostProcessorDUnitTest.java
index c6b2735..71051e2 100644
--- a/geode-core/src/test/java/org/apache/geode/security/NoShowValue1PostProcessorDUnitTest.java
+++ b/geode-core/src/test/java/org/apache/geode/security/NoShowValue1PostProcessorDUnitTest.java
@@ -32,8 +32,7 @@ import org.apache.geode.cache.query.SelectResults;
import org.apache.geode.test.dunit.Host;
import org.apache.geode.test.dunit.VM;
import org.apache.geode.test.dunit.internal.JUnit4DistributedTestCase;
-import org.apache.geode.test.dunit.rules.LocalServerStarterRule;
-import org.apache.geode.test.dunit.rules.ServerStarterBuilder;
+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.Before;
@@ -54,12 +53,12 @@ public class NoShowValue1PostProcessorDUnitTest extends JUnit4DistributedTestCas
final VM client1 = host.getVM(1);
@Rule
- public LocalServerStarterRule server =
- new ServerStarterBuilder().withProperty(SECURITY_MANAGER, TestSecurityManager.class.getName())
+ public ServerStarterRule server =
+ new ServerStarterRule().withProperty(SECURITY_MANAGER, TestSecurityManager.class.getName())
.withProperty(TestSecurityManager.SECURITY_JSON,
"org/apache/geode/management/internal/security/clientServer.json")
.withProperty(SECURITY_POST_PROCESSOR, NoShowValue1PostProcessor.class.getName())
- .buildInThisVM();
+ .withAutoStart();
@Before
public void before() throws Exception {
@@ -77,7 +76,7 @@ public class NoShowValue1PostProcessorDUnitTest extends JUnit4DistributedTestCas
keys.add("key2");
client1.invoke(() -> {
- ClientCache cache = createClientCache("super-user", "1234567", server.getServerPort());
+ ClientCache cache = createClientCache("super-user", "1234567", server.getPort());
Region region = createProxyRegion(cache, REGION_NAME);
// post process for get
http://git-wip-us.apache.org/repos/asf/geode/blob/6a88f1bc/geode-core/src/test/java/org/apache/geode/security/PDXPostProcessorDUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/security/PDXPostProcessorDUnitTest.java b/geode-core/src/test/java/org/apache/geode/security/PDXPostProcessorDUnitTest.java
index c735313..e952386 100644
--- a/geode-core/src/test/java/org/apache/geode/security/PDXPostProcessorDUnitTest.java
+++ b/geode-core/src/test/java/org/apache/geode/security/PDXPostProcessorDUnitTest.java
@@ -40,8 +40,7 @@ import org.apache.geode.test.dunit.IgnoredException;
import org.apache.geode.test.dunit.VM;
import org.apache.geode.test.dunit.internal.JUnit4DistributedTestCase;
import org.apache.geode.test.dunit.rules.GfshShellConnectionRule;
-import org.apache.geode.test.dunit.rules.LocalServerStarterRule;
-import org.apache.geode.test.dunit.rules.ServerStarterBuilder;
+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.apache.geode.test.junit.runners.CategoryWithParameterizedRunnerFactory;
@@ -81,18 +80,18 @@ public class PDXPostProcessorDUnitTest extends JUnit4DistributedTestCase {
}
@Rule
- public LocalServerStarterRule server =
- new ServerStarterBuilder().withProperty(SECURITY_MANAGER, TestSecurityManager.class.getName())
+ public ServerStarterRule server =
+ new ServerStarterRule().withProperty(SECURITY_MANAGER, TestSecurityManager.class.getName())
.withProperty(TestSecurityManager.SECURITY_JSON,
"org/apache/geode/management/internal/security/clientServer.json")
.withProperty(SECURITY_POST_PROCESSOR, PDXPostProcessor.class.getName())
.withProperty("security-pdx", pdxPersistent + "").withJMXManager()
- .withRegion(RegionShortcut.REPLICATE, REGION_NAME).buildInThisVM();
+ .withRegion(RegionShortcut.REPLICATE, REGION_NAME);
@Test
public void testRegionGet() {
client2.invoke(() -> {
- ClientCache cache = createClientCache("super-user", "1234567", server.getServerPort());
+ ClientCache cache = createClientCache("super-user", "1234567", server.getPort());
Region region = createProxyRegion(cache, REGION_NAME);
// put in a value that's a domain object
region.put("key1", new SimpleClass(1, (byte) 1));
@@ -101,7 +100,7 @@ public class PDXPostProcessorDUnitTest extends JUnit4DistributedTestCase {
});
client1.invoke(() -> {
- ClientCache cache = createClientCache("super-user", "1234567", server.getServerPort());
+ ClientCache cache = createClientCache("super-user", "1234567", server.getPort());
Region region = createProxyRegion(cache, REGION_NAME);
// post process for get the client domain object
@@ -122,7 +121,7 @@ public class PDXPostProcessorDUnitTest extends JUnit4DistributedTestCase {
@Test
public void testQuery() {
client2.invoke(() -> {
- ClientCache cache = createClientCache("super-user", "1234567", server.getServerPort());
+ ClientCache cache = createClientCache("super-user", "1234567", server.getPort());
Region region = createProxyRegion(cache, REGION_NAME);
// put in a value that's a domain object
region.put("key1", new SimpleClass(1, (byte) 1));
@@ -130,7 +129,7 @@ public class PDXPostProcessorDUnitTest extends JUnit4DistributedTestCase {
});
client1.invoke(() -> {
- ClientCache cache = createClientCache("super-user", "1234567", server.getServerPort());
+ ClientCache cache = createClientCache("super-user", "1234567", server.getPort());
Region region = createProxyRegion(cache, REGION_NAME);
// post process for query
@@ -158,7 +157,7 @@ public class PDXPostProcessorDUnitTest extends JUnit4DistributedTestCase {
public void testRegisterInterest() {
IgnoredException.addIgnoredException("NoAvailableServersException");
client1.invoke(() -> {
- ClientCache cache = createClientCache("super-user", "1234567", server.getServerPort());
+ ClientCache cache = createClientCache("super-user", "1234567", server.getPort());
ClientRegionFactory factory = cache.createClientRegionFactory(ClientRegionShortcut.PROXY);
factory.addCacheListener(new CacheListenerAdapter() {
@@ -181,7 +180,7 @@ public class PDXPostProcessorDUnitTest extends JUnit4DistributedTestCase {
});
client2.invoke(() -> {
- ClientCache cache = createClientCache("dataUser", "1234567", server.getServerPort());
+ ClientCache cache = createClientCache("dataUser", "1234567", server.getPort());
Region region = createProxyRegion(cache, REGION_NAME);
// put in a value that's a domain object
region.put("key1", new SimpleClass(1, (byte) 1));
@@ -199,7 +198,7 @@ public class PDXPostProcessorDUnitTest extends JUnit4DistributedTestCase {
public void testGfshCommand() {
// have client2 input some domain data into the region
client2.invoke(() -> {
- ClientCache cache = createClientCache("super-user", "1234567", server.getServerPort());
+ ClientCache cache = createClientCache("super-user", "1234567", server.getPort());
Region region = createProxyRegion(cache, REGION_NAME);
// put in a value that's a domain object
region.put("key1", new SimpleClass(1, (byte) 1));
http://git-wip-us.apache.org/repos/asf/geode/blob/6a88f1bc/geode-core/src/test/java/org/apache/geode/security/PostProcessorDUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/security/PostProcessorDUnitTest.java b/geode-core/src/test/java/org/apache/geode/security/PostProcessorDUnitTest.java
index 89a6752..dc924ab 100644
--- a/geode-core/src/test/java/org/apache/geode/security/PostProcessorDUnitTest.java
+++ b/geode-core/src/test/java/org/apache/geode/security/PostProcessorDUnitTest.java
@@ -34,8 +34,7 @@ import org.apache.geode.cache.util.CacheListenerAdapter;
import org.apache.geode.test.dunit.Host;
import org.apache.geode.test.dunit.VM;
import org.apache.geode.test.dunit.internal.JUnit4DistributedTestCase;
-import org.apache.geode.test.dunit.rules.LocalServerStarterRule;
-import org.apache.geode.test.dunit.rules.ServerStarterBuilder;
+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.Before;
@@ -56,11 +55,11 @@ public class PostProcessorDUnitTest extends JUnit4DistributedTestCase {
final VM client2 = host.getVM(2);
@Rule
- public LocalServerStarterRule server =
- new ServerStarterBuilder().withProperty(SECURITY_MANAGER, TestSecurityManager.class.getName())
+ public ServerStarterRule server =
+ new ServerStarterRule().withProperty(SECURITY_MANAGER, TestSecurityManager.class.getName())
.withProperty(TestSecurityManager.SECURITY_JSON,
"org/apache/geode/management/internal/security/clientServer.json")
- .withProperty(SECURITY_POST_PROCESSOR, TestPostProcessor.class.getName()).buildInThisVM();
+ .withProperty(SECURITY_POST_PROCESSOR, TestPostProcessor.class.getName()).withAutoStart();
@Before
public void before() throws Exception {
@@ -78,7 +77,7 @@ public class PostProcessorDUnitTest extends JUnit4DistributedTestCase {
keys.add("key2");
client1.invoke(() -> {
- ClientCache cache = createClientCache("super-user", "1234567", server.getServerPort());
+ ClientCache cache = createClientCache("super-user", "1234567", server.getPort());
Region region = createProxyRegion(cache, REGION_NAME);
// post process for get
@@ -96,7 +95,7 @@ public class PostProcessorDUnitTest extends JUnit4DistributedTestCase {
@Test
public void testPostProcessQuery() {
client1.invoke(() -> {
- ClientCache cache = createClientCache("super-user", "1234567", server.getServerPort());
+ ClientCache cache = createClientCache("super-user", "1234567", server.getPort());
Region region = createProxyRegion(cache, REGION_NAME);
// post process for query
@@ -123,7 +122,7 @@ public class PostProcessorDUnitTest extends JUnit4DistributedTestCase {
@Test
public void testRegisterInterestPostProcess() {
client1.invoke(() -> {
- ClientCache cache = createClientCache("super-user", "1234567", server.getServerPort());
+ ClientCache cache = createClientCache("super-user", "1234567", server.getPort());
ClientRegionFactory factory = cache.createClientRegionFactory(ClientRegionShortcut.PROXY);
factory.addCacheListener(new CacheListenerAdapter() {
@@ -140,7 +139,7 @@ public class PostProcessorDUnitTest extends JUnit4DistributedTestCase {
});
client2.invoke(() -> {
- ClientCache cache = createClientCache("dataUser", "1234567", server.getServerPort());
+ ClientCache cache = createClientCache("dataUser", "1234567", server.getPort());
Region region = createProxyRegion(cache, REGION_NAME);
region.put("key1", "value2");
});
http://git-wip-us.apache.org/repos/asf/geode/blob/6a88f1bc/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 4f84f7b..1fe4175 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
@@ -31,7 +31,6 @@ import org.apache.geode.test.dunit.IgnoredException;
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.FlakyTest;
import org.apache.geode.test.junit.categories.SecurityTest;
import org.junit.Before;
import org.junit.Rule;
@@ -64,7 +63,6 @@ public class SecurityClusterConfigDUnitTest {
lsRule.startLocatorVM(0, props);
}
- @Category(FlakyTest.class) // GEODE-1977
@Test
public void testStartServerWithClusterConfig() throws Exception {
Properties props = new Properties();
@@ -104,7 +102,6 @@ public class SecurityClusterConfigDUnitTest {
assertTrue(secProps.containsKey("security-post-processor"));
}
- @Category(FlakyTest.class) // GEODE-1975
@Test
public void serverWithDifferentSecurityManagerShouldThrowException() {
Properties props = new Properties();
@@ -139,7 +136,6 @@ public class SecurityClusterConfigDUnitTest {
}
- @Category(FlakyTest.class) // GEODE-1974
@Test
public void serverConnectingToSecuredLocatorMustUseClusterConfig() {
Properties props = new Properties();
http://git-wip-us.apache.org/repos/asf/geode/blob/6a88f1bc/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 02bad30..0a4785d 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
@@ -28,6 +28,8 @@ import org.json.JSONArray;
import org.junit.rules.TemporaryFolder;
import org.junit.runner.Description;
+import java.util.function.Supplier;
+
/**
* Class which eases the connection to the locator/jmxManager in Gfsh shell and execute gfsh
* commands.
@@ -52,7 +54,7 @@ import org.junit.runner.Description;
*/
public class GfshShellConnectionRule extends DescribedExternalResource {
- private int port = -1;
+ private Supplier<Integer> portSupplier;
private PortType portType = PortType.jmxManger;
private HeadlessGfsh gfsh = null;
private boolean connected = false;
@@ -66,10 +68,10 @@ public class GfshShellConnectionRule extends DescribedExternalResource {
}
}
- public GfshShellConnectionRule(int port, PortType portType) {
+ public GfshShellConnectionRule(Supplier<Integer> portSupplier, PortType portType) {
this();
this.portType = portType;
- this.port = port;
+ this.portSupplier = portSupplier;
}
@Override
@@ -77,7 +79,7 @@ public class GfshShellConnectionRule extends DescribedExternalResource {
this.gfsh = new HeadlessGfsh(getClass().getName(), 30,
temporaryFolder.newFolder("gfsh_files").getAbsolutePath());
// do not auto connect if no port initialized
- if (port < 0) {
+ if (portSupplier == null) {
return;
}
@@ -87,7 +89,7 @@ public class GfshShellConnectionRule extends DescribedExternalResource {
return;
}
- connect(port, portType, CliStrings.CONNECT__USERNAME, config.user(),
+ connect(portSupplier.get(), portType, CliStrings.CONNECT__USERNAME, config.user(),
CliStrings.CONNECT__PASSWORD, config.password());
}
http://git-wip-us.apache.org/repos/asf/geode/blob/6a88f1bc/geode-core/src/test/java/org/apache/geode/test/dunit/rules/LocalLocatorStarterRule.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/test/dunit/rules/LocalLocatorStarterRule.java b/geode-core/src/test/java/org/apache/geode/test/dunit/rules/LocalLocatorStarterRule.java
deleted file mode 100644
index 21be585..0000000
--- a/geode-core/src/test/java/org/apache/geode/test/dunit/rules/LocalLocatorStarterRule.java
+++ /dev/null
@@ -1,99 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more contributor license
- * agreements. See the NOTICE file distributed with this work for additional information regarding
- * copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance with the License. You may obtain a
- * copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software distributed under the License
- * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
- * or implied. See the License for the specific language governing permissions and limitations under
- * the License.
- */
-package org.apache.geode.test.dunit.rules;
-
-import static org.apache.geode.distributed.Locator.startLocatorAndDS;
-import static org.junit.Assert.assertTrue;
-
-import org.apache.geode.distributed.ConfigurationProperties;
-import org.apache.geode.distributed.internal.DistributionConfig;
-import org.apache.geode.distributed.internal.InternalLocator;
-import org.apache.geode.internal.AvailablePort;
-import org.apache.geode.internal.datasource.ConfigProperty;
-import org.awaitility.Awaitility;
-import org.junit.rules.ExternalResource;
-
-import java.io.IOException;
-import java.util.Objects;
-import java.util.Properties;
-import java.util.concurrent.TimeUnit;
-import java.util.stream.Stream;
-
-public class LocalLocatorStarterRule extends ExternalResource {
- private volatile InternalLocator internalLocator;
- private final Properties properties;
- private final AvailablePort.Keeper locatorPort;
- private final AvailablePort.Keeper jmxPort;
- private final AvailablePort.Keeper httpPort;
- private final AvailablePort.Keeper tcpPort;
-
- LocalLocatorStarterRule(LocatorStarterBuilder locatorStarterBuilder) {
- this.properties = locatorStarterBuilder.getProperties();
- this.locatorPort = locatorStarterBuilder.getLocatorPort();
- this.jmxPort = locatorStarterBuilder.getJmxPort();
- this.httpPort = locatorStarterBuilder.getHttpPort();
- this.tcpPort = locatorStarterBuilder.getTcpPort();
- }
-
- public String getHostname() {
- return "localhost";
- }
-
- public int getLocatorPort() {
- return this.locatorPort.getPort();
- }
-
- public int getHttpPort() {
- String httpPort = properties.getProperty(ConfigurationProperties.HTTP_SERVICE_PORT);
- if (httpPort == null) {
- throw new IllegalStateException("No http port specified");
- }
- return Integer.valueOf(httpPort);
- }
-
- private void releasePortKeepers() {
- Stream.of(locatorPort, jmxPort, httpPort, tcpPort).filter(Objects::nonNull)
- .forEach(AvailablePort.Keeper::release);
- }
-
- @Override
- protected void before() {
- releasePortKeepers();
- try {
- // this will start a jmx manager and admin rest service by default
- this.internalLocator =
- (InternalLocator) startLocatorAndDS(locatorPort.getPort(), null, properties);
- } catch (IOException e) {
- throw new RuntimeException("unable to start up locator.", e);
- }
-
- DistributionConfig config = this.internalLocator.getConfig();
-
- if (config.getEnableClusterConfiguration()) {
- Awaitility.await().atMost(65, TimeUnit.SECONDS)
- .until(() -> assertTrue(internalLocator.isSharedConfigurationRunning()));
- }
- }
-
- @Override
- protected void after() {
- releasePortKeepers();
-
- if (internalLocator != null) {
- internalLocator.stop();
- internalLocator = null;
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/geode/blob/6a88f1bc/geode-core/src/test/java/org/apache/geode/test/dunit/rules/LocalServerStarterRule.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/test/dunit/rules/LocalServerStarterRule.java b/geode-core/src/test/java/org/apache/geode/test/dunit/rules/LocalServerStarterRule.java
deleted file mode 100644
index 3106948..0000000
--- a/geode-core/src/test/java/org/apache/geode/test/dunit/rules/LocalServerStarterRule.java
+++ /dev/null
@@ -1,159 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more contributor license
- * agreements. See the NOTICE file distributed with this work for additional information regarding
- * copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance with the License. You may obtain a
- * copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software distributed under the License
- * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
- * or implied. See the License for the specific language governing permissions and limitations under
- * the License.
- */
-package org.apache.geode.test.dunit.rules;
-
-import static org.apache.geode.distributed.Locator.startLocatorAndDS;
-import static org.junit.Assert.assertTrue;
-
-import org.apache.geode.cache.Cache;
-import org.apache.geode.cache.CacheFactory;
-import org.apache.geode.cache.RegionShortcut;
-import org.apache.geode.cache.server.CacheServer;
-import org.apache.geode.distributed.ConfigurationProperties;
-import org.apache.geode.distributed.internal.DistributionConfig;
-import org.apache.geode.distributed.internal.InternalDistributedSystem;
-import org.apache.geode.internal.AvailablePort;
-import org.junit.rules.ExternalResource;
-import org.junit.rules.TemporaryFolder;
-
-import java.io.File;
-import java.io.Serializable;
-import java.util.Map;
-import java.util.Objects;
-import java.util.Properties;
-import java.util.stream.Stream;
-
-public class LocalServerStarterRule extends ExternalResource implements Serializable {
- private volatile transient Cache cache;
- private volatile transient CacheServer server;
- private final transient TemporaryFolder temporaryFolder;
-
- private final Properties properties;
- private final Map<String, RegionShortcut> regionsToCreate;
-
- private final AvailablePort.Keeper serverPort;
- private final AvailablePort.Keeper jmxPort;
- private final AvailablePort.Keeper httpPort;
- private final AvailablePort.Keeper tcpPort;
-
- LocalServerStarterRule(ServerStarterBuilder serverStarterBuilder) {
- this.properties = serverStarterBuilder.getProperties();
- if (serverStarterBuilder.hasAutomaticallyManagedWorkingDir()) {
- temporaryFolder = new TemporaryFolder();
- } else {
- temporaryFolder = null;
- }
-
- this.serverPort = serverStarterBuilder.getServerPort();
- this.jmxPort = serverStarterBuilder.getJmxPort();
- this.httpPort = serverStarterBuilder.getHttpPort();
- this.tcpPort = serverStarterBuilder.getTcpPort();
-
- this.regionsToCreate = serverStarterBuilder.getRegionsToCreate();
- }
-
- @Override
- public void before() throws Throwable {
- if (temporaryFolder != null) {
- temporaryFolder.create();
- this.properties.setProperty(ConfigurationProperties.DEPLOY_WORKING_DIR,
- temporaryFolder.getRoot().getAbsolutePath());
- }
-
- releasePortKeepers();
- CacheFactory cf = new CacheFactory(this.properties);
-
- cache = cf.create();
- server = cache.addCacheServer();
- server.setPort(this.serverPort.getPort());
- server.start();
-
- for (Map.Entry<String, RegionShortcut> region : regionsToCreate.entrySet()) {
- cache.createRegionFactory(region.getValue()).create(region.getKey());
- }
- }
-
- @Override
- public void after() {
- if (cache != null) {
- cache.close();
- cache = null;
- }
- if (server != null) {
- server.stop();
- server = null;
- }
-
- if (temporaryFolder != null) {
- temporaryFolder.delete();
- }
-
- releasePortKeepers();
- }
-
- private void releasePortKeepers() {
- Stream.of(serverPort, jmxPort, httpPort, tcpPort).filter(Objects::nonNull)
- .forEach(AvailablePort.Keeper::release);
- }
-
- public int getHttpPort() {
- String httpPort = properties.getProperty(ConfigurationProperties.HTTP_SERVICE_PORT);
-
- if (httpPort != null) {
- return (Integer.valueOf(httpPort));
- }
-
- if (properties.getProperty(ConfigurationProperties.START_DEV_REST_API) != null) {
- throw new IllegalStateException("No HTTP_SERVICE_PORT has been specified");
- } else {
- throw new IllegalStateException("Dev rest api not configured for this server");
- }
- }
-
- public Cache getCache() {
- return cache;
- }
-
- public CacheServer getServer() {
- return server;
- }
-
- public File getWorkingDir() {
- if (cache == null) {
- throw new IllegalStateException("Server not yet initialized");
- }
- return ((InternalDistributedSystem) cache.getDistributedSystem()).getConfig()
- .getDeployWorkingDir();
- }
-
- public String getHostname() {
- return "localhost";
- }
-
-
- public Integer getJmxPort() {
- String jmxPort = properties.getProperty(ConfigurationProperties.JMX_MANAGER_PORT);
- if (jmxPort == null) {
- return null;
- }
-
- return Integer.valueOf(jmxPort);
- }
-
- public int getServerPort() {
- return this.serverPort.getPort();
- }
-
-}
http://git-wip-us.apache.org/repos/asf/geode/blob/6a88f1bc/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 7350241..97c636b 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
@@ -95,7 +95,9 @@ public class LocatorServerStartupRule extends ExternalResource implements Serial
VM locatorVM = getHost(0).getVM(index);
Locator locator = locatorVM.invoke(() -> {
locatorStarter = new LocatorStarterRule(workingDir);
- return locatorStarter.withProperties(properties).startLocator();
+ locatorStarter.withProperties(properties).withAutoStart();
+ locatorStarter.before();
+ return locatorStarter;
});
members[index] = new MemberVM(locator, locatorVM);
return members[index];
@@ -126,7 +128,9 @@ public class LocatorServerStartupRule extends ExternalResource implements Serial
VM serverVM = getHost(0).getVM(index);
Server server = serverVM.invoke(() -> {
serverStarter = new ServerStarterRule(workingDir);
- return serverStarter.withEmbeddedLocator().withName(name).withJMXManager().startServer();
+ serverStarter.withEmbeddedLocator().withName(name).withJMXManager().withAutoStart();
+ serverStarter.before();
+ return serverStarter;
});
members[index] = new MemberVM(server, serverVM);
return members[index];
@@ -149,8 +153,9 @@ public class LocatorServerStartupRule extends ExternalResource implements Serial
VM serverVM = getHost(0).getVM(index);
Server server = serverVM.invoke(() -> {
serverStarter = new ServerStarterRule(workingDir);
- return serverStarter.withProperties(properties).withConnectionToLocator(locatorPort)
- .startServer();
+ serverStarter.withProperties(properties).withConnectionToLocator(locatorPort).withAutoStart();
+ serverStarter.before();
+ return serverStarter;
});
members[index] = new MemberVM(server, serverVM);
return members[index];
http://git-wip-us.apache.org/repos/asf/geode/blob/6a88f1bc/geode-core/src/test/java/org/apache/geode/test/dunit/rules/LocatorStarterBuilder.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/test/dunit/rules/LocatorStarterBuilder.java b/geode-core/src/test/java/org/apache/geode/test/dunit/rules/LocatorStarterBuilder.java
deleted file mode 100644
index 169d41e..0000000
--- a/geode-core/src/test/java/org/apache/geode/test/dunit/rules/LocatorStarterBuilder.java
+++ /dev/null
@@ -1,121 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more contributor license
- * agreements. See the NOTICE file distributed with this work for additional information regarding
- * copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance with the License. You may obtain a
- * copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software distributed under the License
- * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
- * or implied. See the License for the specific language governing permissions and limitations under
- * the License.
- */
-
-package org.apache.geode.test.dunit.rules;
-
-import static org.apache.geode.distributed.ConfigurationProperties.HTTP_SERVICE_BIND_ADDRESS;
-import static org.apache.geode.distributed.ConfigurationProperties.HTTP_SERVICE_PORT;
-import static org.apache.geode.distributed.ConfigurationProperties.JMX_MANAGER;
-import static org.apache.geode.distributed.ConfigurationProperties.JMX_MANAGER_HOSTNAME_FOR_CLIENTS;
-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.SECURITY_MANAGER;
-import static org.apache.geode.distributed.ConfigurationProperties.TCP_PORT;
-
-import org.apache.geode.distributed.ConfigurationProperties;
-import org.apache.geode.internal.AvailablePort;
-import org.apache.geode.internal.AvailablePortHelper;
-import org.apache.geode.security.SecurityManager;
-
-import java.util.Properties;
-
-public class LocatorStarterBuilder {
- private Properties properties = new Properties();
- private AvailablePort.Keeper locatorPort;
- private AvailablePort.Keeper jmxPort;
- private AvailablePort.Keeper httpPort;
- private AvailablePort.Keeper tcpPort;
-
- public LocatorStarterBuilder() {}
-
- public LocatorStarterBuilder withSecurityManager(
- Class<? extends SecurityManager> securityManager) {
- properties.setProperty(SECURITY_MANAGER, securityManager.getName());
- return this;
- }
-
- public LocalLocatorStarterRule buildInThisVM() {
- setDefaultProperties();
- throwIfPortsAreHardcoded();
- setPortPropertiesFromKeepers();
- return new LocalLocatorStarterRule(this);
- }
-
- Properties getProperties() {
- return this.properties;
- }
-
- private void setDefaultProperties() {
- properties.putIfAbsent(ConfigurationProperties.NAME, "locator");
- // properties.putIfAbsent(LOG_FILE, new File(properties.get(ConfigurationProperties.NAME) +
- // ".log").getAbsolutePath().toString());
-
- if (locatorPort == null) {
- this.locatorPort = AvailablePortHelper.getRandomAvailableTCPPortKeepers(1).get(0);
- }
- if (jmxPort == null) {
- this.jmxPort = AvailablePortHelper.getRandomAvailableTCPPortKeepers(1).get(0);
- }
- if (httpPort == null) {
- this.httpPort = AvailablePortHelper.getRandomAvailableTCPPortKeepers(1).get(0);
- }
- if (locatorPort == null) {
- this.tcpPort = AvailablePortHelper.getRandomAvailableTCPPortKeepers(1).get(0);
- }
-
- properties.putIfAbsent(JMX_MANAGER, "true");
- properties.putIfAbsent(JMX_MANAGER_START, "true");
- properties.putIfAbsent(HTTP_SERVICE_BIND_ADDRESS, "localhost");
- properties.putIfAbsent(JMX_MANAGER_HOSTNAME_FOR_CLIENTS, "localhost");
- }
-
- private void setPortPropertiesFromKeepers() {
- if (jmxPort != null) {
- properties.setProperty(JMX_MANAGER_PORT, Integer.toString(jmxPort.getPort()));
- }
-
- if (httpPort != null) {
- properties.setProperty(HTTP_SERVICE_PORT, Integer.toString(httpPort.getPort()));
- }
-
- if (tcpPort != null) {
- properties.setProperty(TCP_PORT, Integer.toString(tcpPort.getPort()));
- }
- }
-
- private void throwIfPortsAreHardcoded() {
- if (properties.getProperty(JMX_MANAGER_PORT) != null
- || properties.getProperty(HTTP_SERVICE_PORT) != null
- || properties.getProperty(TCP_PORT) != null) {
- throw new IllegalArgumentException("Ports cannot be hardcoded.");
- }
- }
-
- AvailablePort.Keeper getLocatorPort() {
- return locatorPort;
- }
-
- AvailablePort.Keeper getJmxPort() {
- return jmxPort;
- }
-
- AvailablePort.Keeper getHttpPort() {
- return httpPort;
- }
-
- AvailablePort.Keeper getTcpPort() {
- return tcpPort;
- }
-}
http://git-wip-us.apache.org/repos/asf/geode/blob/6a88f1bc/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 097adb7..e1c14ce 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
@@ -29,10 +29,14 @@ 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.
+ * This rules allows you to create/start a locator using any @ConfigurationProperties, you can chain
+ * the configuration of the rule like this: LocatorStarterRule locator = new LocatorStarterRule()
+ * .withProperty(key, value) .withName(name) .withProperties(properties) .withSecurityManager(class)
+ * .withJmxManager() etc, etc. If your rule calls withAutoStart(), the locator will be started
+ * before your test code.
+ *
+ * In your test code, you can use the rule to access the locator's attributes, like the port
+ * information, working dir, name, and the InternalLocator it creates.
*
* If you need a rule to start a server/locator in different VMs for Distributed tests, You should
* use {@link LocatorServerStartupRule}.
@@ -59,14 +63,19 @@ public class LocatorStarterRule extends MemberStarterRule<LocatorStarterRule> im
}
}
- public LocatorStarterRule startLocator() {
+ @Override
+ public void before() {
normalizeProperties();
- // start locator will start a jmx manager by default, if withJMXManager is not called explicitly
- // the tests will use random ports by default.
+ // always use a random jmxPort/httpPort when using the rule to start the locator
if (jmxPort < 0) {
- withJMXManager();
+ withJMXManager(false);
}
+ if (autoStart) {
+ startLocator();
+ }
+ }
+ public void startLocator() {
try {
// this will start a jmx manager and admin rest service by default
locator = (InternalLocator) startLocatorAndDS(0, null, properties);
@@ -83,6 +92,5 @@ public class LocatorStarterRule extends MemberStarterRule<LocatorStarterRule> im
Awaitility.await().atMost(65, TimeUnit.SECONDS)
.until(() -> assertTrue(locator.isSharedConfigurationRunning()));
}
- return this;
}
}
http://git-wip-us.apache.org/repos/asf/geode/blob/6a88f1bc/geode-core/src/test/java/org/apache/geode/test/dunit/rules/MBeanServerConnectionRule.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/test/dunit/rules/MBeanServerConnectionRule.java b/geode-core/src/test/java/org/apache/geode/test/dunit/rules/MBeanServerConnectionRule.java
index 9c6f81e..3addc4e 100644
--- a/geode-core/src/test/java/org/apache/geode/test/dunit/rules/MBeanServerConnectionRule.java
+++ b/geode-core/src/test/java/org/apache/geode/test/dunit/rules/MBeanServerConnectionRule.java
@@ -27,6 +27,7 @@ import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.TimeUnit;
+import java.util.function.Supplier;
import javax.management.JMX;
import javax.management.MBeanServerConnection;
import javax.management.MalformedObjectNameException;
@@ -48,7 +49,7 @@ import javax.management.remote.JMXServiceURL;
*/
public class MBeanServerConnectionRule extends DescribedExternalResource {
- private int jmxServerPort = -1;
+ private Supplier<Integer> portSupplier;
private JMXConnector jmxConnector;
private MBeanServerConnection con;
@@ -57,10 +58,10 @@ public class MBeanServerConnectionRule extends DescribedExternalResource {
/**
* Rule constructor
*
- * @param port The JMX server port to connect to
+ * @param portSupplier The JMX server port to connect to
*/
- public MBeanServerConnectionRule(int port) {
- this.jmxServerPort = port;
+ public MBeanServerConnectionRule(Supplier<Integer> portSupplier) {
+ this.portSupplier = portSupplier;
}
/**
@@ -115,7 +116,7 @@ public class MBeanServerConnectionRule extends DescribedExternalResource {
@Override
protected void before(Description description) throws Throwable {
// do not auto connect if port is not set
- if (jmxServerPort < 0)
+ if (portSupplier == null)
return;
// do not auto connect if no ConnectionConfiguration is defined.
@@ -127,7 +128,7 @@ public class MBeanServerConnectionRule extends DescribedExternalResource {
String user = config.user();
String password = config.password();
env.put(JMXConnector.CREDENTIALS, new String[] {user, password});
- connect(null, jmxServerPort, env);
+ connect(null, portSupplier.get(), env);
}
public void connect(int jmxPort) throws Exception {
http://git-wip-us.apache.org/repos/asf/geode/blob/6a88f1bc/geode-core/src/test/java/org/apache/geode/test/dunit/rules/MemberStarterRule.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/test/dunit/rules/MemberStarterRule.java b/geode-core/src/test/java/org/apache/geode/test/dunit/rules/MemberStarterRule.java
index 3fda85a..e5e598e 100644
--- a/geode-core/src/test/java/org/apache/geode/test/dunit/rules/MemberStarterRule.java
+++ b/geode-core/src/test/java/org/apache/geode/test/dunit/rules/MemberStarterRule.java
@@ -25,9 +25,10 @@ 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 static org.apache.geode.distributed.ConfigurationProperties.SECURITY_MANAGER;
import org.apache.geode.internal.AvailablePortHelper;
-import org.apache.geode.test.dunit.VM;
+import org.apache.geode.security.SecurityManager;
import org.junit.rules.ExternalResource;
import org.junit.rules.TemporaryFolder;
@@ -36,7 +37,8 @@ import java.io.IOException;
import java.util.Properties;
/**
- * A server or locator inside a DUnit {@link VM}.
+ * the abstract class that's used by LocatorStarterRule and ServerStarterRule to avoid code
+ * duplication.
*/
public abstract class MemberStarterRule<T> extends ExternalResource implements Member {
protected transient TemporaryFolder temporaryFolder;
@@ -50,6 +52,8 @@ public abstract class MemberStarterRule<T> extends ExternalResource implements M
protected String name;
protected Properties properties = new Properties();
+ protected boolean autoStart = false;
+
public MemberStarterRule() {
this(null);
}
@@ -98,6 +102,16 @@ public abstract class MemberStarterRule<T> extends ExternalResource implements M
return (T) this;
}
+ public T withSecurityManager(Class<? extends SecurityManager> securityManager) {
+ properties.setProperty(SECURITY_MANAGER, securityManager.getName());
+ return (T) this;
+ }
+
+ public T withAutoStart() {
+ this.autoStart = true;
+ return (T) this;
+ }
+
public T withName(String name) {
this.name = name;
properties.setProperty(NAME, name);
@@ -116,16 +130,19 @@ public abstract class MemberStarterRule<T> extends ExternalResource implements M
/**
* be able to start JMX manager and admin rest on default ports
*/
- public T withJMXManager(boolean useDefault) {
- // the real port numbers will be set after we started the server/locator.
- this.jmxPort = 0;
- this.httpPort = 0;
- if (!useDefault) {
+ public T withJMXManager(boolean useProductDefaultPorts) {
+ if (!useProductDefaultPorts) {
// do no override these properties if already exists
properties.putIfAbsent(JMX_MANAGER_PORT,
AvailablePortHelper.getRandomAvailableTCPPort() + "");
properties.putIfAbsent(HTTP_SERVICE_PORT,
AvailablePortHelper.getRandomAvailableTCPPort() + "");
+ this.jmxPort = Integer.parseInt(properties.getProperty(JMX_MANAGER_PORT));
+ this.httpPort = Integer.parseInt(properties.getProperty(HTTP_SERVICE_PORT));
+ } else {
+ // the real port numbers will be set after we started the server/locator.
+ this.jmxPort = 0;
+ this.httpPort = 0;
}
properties.putIfAbsent(JMX_MANAGER, "true");
properties.putIfAbsent(JMX_MANAGER_START, "true");
http://git-wip-us.apache.org/repos/asf/geode/blob/6a88f1bc/geode-core/src/test/java/org/apache/geode/test/dunit/rules/ServerStarterBuilder.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/test/dunit/rules/ServerStarterBuilder.java b/geode-core/src/test/java/org/apache/geode/test/dunit/rules/ServerStarterBuilder.java
deleted file mode 100644
index 5d8947c..0000000
--- a/geode-core/src/test/java/org/apache/geode/test/dunit/rules/ServerStarterBuilder.java
+++ /dev/null
@@ -1,185 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more contributor license
- * agreements. See the NOTICE file distributed with this work for additional information regarding
- * copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance with the License. You may obtain a
- * copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software distributed under the License
- * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
- * or implied. See the License for the specific language governing permissions and limitations under
- * the License.
- */
-
-package org.apache.geode.test.dunit.rules;
-
-import static org.apache.geode.distributed.ConfigurationProperties.DEPLOY_WORKING_DIR;
-import static org.apache.geode.distributed.ConfigurationProperties.HTTP_SERVICE_BIND_ADDRESS;
-import static org.apache.geode.distributed.ConfigurationProperties.HTTP_SERVICE_PORT;
-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.MCAST_PORT;
-import static org.apache.geode.distributed.ConfigurationProperties.SECURITY_MANAGER;
-import static org.apache.geode.distributed.ConfigurationProperties.START_DEV_REST_API;
-import static org.apache.geode.distributed.ConfigurationProperties.TCP_PORT;
-
-import org.apache.geode.cache.RegionShortcut;
-import org.apache.geode.distributed.ConfigurationProperties;
-import org.apache.geode.internal.AvailablePort;
-import org.apache.geode.internal.AvailablePortHelper;
-import org.apache.geode.security.SecurityManager;
-
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Properties;
-
-public class ServerStarterBuilder {
- private Properties properties = new Properties();
- private Map<String, RegionShortcut> regionsToCreate = new HashMap<>();
-
- private AvailablePort.Keeper serverPort;
- private AvailablePort.Keeper jmxPort;
- private AvailablePort.Keeper httpPort;
- private AvailablePort.Keeper tcpPort;
-
- /**
- * If this flag is true, the Rule will create a temporary folder and set the server's
- * DEPLOY_WORKING_DIR to that folder. Otherwise, a user must manage their own working directory.
- */
- private boolean hasAutomaticallyManagedWorkingDir;
-
- public LocalServerStarterRule buildInThisVM() {
- setDefaultProperties();
- throwIfPortsAreHardcoded();
- setPortPropertiesFromKeepers();
-
- return new LocalServerStarterRule(this);
- }
-
- public ServerStarterBuilder withJMXManager() {
- if (this.jmxPort == null) {
- this.jmxPort = AvailablePortHelper.getRandomAvailableTCPPortKeepers(1).get(0);
- }
-
- if (this.httpPort == null) {
- this.httpPort = AvailablePortHelper.getRandomAvailableTCPPortKeepers(1).get(0);
- }
-
- properties.setProperty(JMX_MANAGER, "true");
- properties.setProperty(JMX_MANAGER_START, "true");
- properties.setProperty(HTTP_SERVICE_BIND_ADDRESS, "localhost");
- return this;
- }
-
- /**
- * Enables the Dev REST API with a random http port
- */
- public ServerStarterBuilder withRestService() {
- if (this.httpPort == null) {
- this.httpPort = AvailablePortHelper.getRandomAvailableTCPPortKeepers(1).get(0);
- }
-
- properties.setProperty(START_DEV_REST_API, "true");
- properties.setProperty(HTTP_SERVICE_BIND_ADDRESS, "localhost");
- return this;
- }
-
- public ServerStarterBuilder withSecurityManager(
- Class<? extends SecurityManager> securityManager) {
- properties.setProperty(SECURITY_MANAGER, securityManager.getName());
- return this;
- }
-
- public ServerStarterBuilder withProperty(String key, String value) {
- properties.setProperty(key, value);
- return this;
- }
-
- public ServerStarterBuilder withRegion(RegionShortcut type, String name) {
- regionsToCreate.put(name, type);
- return this;
- }
-
-
- private void setDefaultProperties() {
- String workingDir = properties.getProperty(DEPLOY_WORKING_DIR);
- if (workingDir == null) {
- hasAutomaticallyManagedWorkingDir = true;
- }
-
- properties.putIfAbsent(ConfigurationProperties.NAME, "server");
-
- if (this.serverPort == null) {
- this.serverPort = AvailablePortHelper.getRandomAvailableTCPPortKeepers(1).get(0);
- }
-
- if (this.tcpPort == null) {
- this.tcpPort = AvailablePortHelper.getRandomAvailableTCPPortKeepers(1).get(0);
- }
-
- properties.putIfAbsent(MCAST_PORT, "0");
- properties.putIfAbsent(LOCATORS, "");
- }
-
- /**
- * We want to make sure that all tests use AvailablePort.Keeper rather than setting port numbers
- * manually so that we can avoid flaky tests caused by BindExceptions.
- *
- * @throws IllegalArgumentException - if ports are hardcoded.
- */
- private void throwIfPortsAreHardcoded() {
- if (properties.getProperty(JMX_MANAGER_PORT) != null
- || properties.getProperty(HTTP_SERVICE_PORT) != null
- || properties.getProperty(TCP_PORT) != null) {
- throw new IllegalArgumentException("Ports cannot be hardcoded.");
- }
- }
-
- private void setPortPropertiesFromKeepers() {
- if (jmxPort != null) {
- properties.setProperty(JMX_MANAGER_PORT, Integer.toString(jmxPort.getPort()));
- }
-
- if (httpPort != null) {
- properties.setProperty(HTTP_SERVICE_PORT, Integer.toString(httpPort.getPort()));
- }
-
- if (tcpPort != null) {
- properties.setProperty(TCP_PORT, Integer.toString(tcpPort.getPort()));
-
- }
- }
-
- AvailablePort.Keeper getServerPort() {
- return serverPort;
- }
-
- AvailablePort.Keeper getJmxPort() {
- return jmxPort;
- }
-
- AvailablePort.Keeper getHttpPort() {
- return httpPort;
- }
-
- AvailablePort.Keeper getTcpPort() {
- return tcpPort;
- }
-
- Map<String, RegionShortcut> getRegionsToCreate() {
- return this.regionsToCreate;
- }
-
- Properties getProperties() {
- return this.properties;
- }
-
- boolean hasAutomaticallyManagedWorkingDir() {
- return this.hasAutomaticallyManagedWorkingDir;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/geode/blob/6a88f1bc/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 fea2e9d..0e65354 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
@@ -30,21 +30,33 @@ import org.apache.geode.internal.cache.GemFireCacheImpl;
import java.io.File;
import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
import java.util.Properties;
/**
* This is a rule to start up a server in your current VM. It's useful for your Integration Tests.
*
+ * This rules allows you to create/start a server using any @ConfigurationProperties, you can chain
+ * the configuration of the rule like this: ServerStarterRule server = new ServerStarterRule()
+ * .withProperty(key, value) .withName(name) .withProperties(properties) .withSecurityManager(class)
+ * .withJmxManager() .withRestService() .withEmbeddedLocator() .withRegion(type, name) etc, etc. If
+ * your rule calls withAutoStart(), the server will be started before your test code.
+ *
+ * In your test code, you can use the rule to access the server's attributes, like the port
+ * information, working dir, name, and the cache and cacheServer it creates.
+ *
* If you need a rule to start a server/locator in different VMs for Distributed tests, You should
* use {@link LocatorServerStartupRule}.
*/
public class ServerStarterRule extends MemberStarterRule<ServerStarterRule> implements Server {
-
private transient Cache cache;
private transient CacheServer server;
private int embeddedLocatorPort = -1;
+ private Map<String, RegionShortcut> regions = new HashMap<>();
+
/**
* Default constructor, if used, the rule will create a temporary folder as the server's working
* dir, and will delete it when the test is done.
@@ -70,6 +82,17 @@ public class ServerStarterRule extends MemberStarterRule<ServerStarterRule> impl
}
@Override
+ public void before() {
+ normalizeProperties();
+ if (autoStart) {
+ startServer();
+ regions.forEach((regionName, regionType) -> {
+ getCache().createRegionFactory(regionType).create(regionName);
+ });
+ }
+ }
+
+ @Override
void stopMember() {
// make sure this cache is the one currently open. A server cache can be recreated due to
// importing a new set of cluster configuration.
@@ -104,21 +127,21 @@ public class ServerStarterRule extends MemberStarterRule<ServerStarterRule> impl
return this;
}
- public ServerStarterRule startServer() {
- return startServer(false);
+ public void startServer() {
+ startServer(false);
}
- public ServerStarterRule createRegion(RegionShortcut type, String name) {
- cache.createRegionFactory(type).create(name);
+ public ServerStarterRule withRegion(RegionShortcut type, String name) {
+ this.autoStart = true;
+ regions.put(name, type);
return this;
}
- public ServerStarterRule startServer(Properties properties, int locatorPort) {
- return withProperties(properties).withConnectionToLocator(locatorPort).startServer();
+ public void startServer(Properties properties, int locatorPort) {
+ withProperties(properties).withConnectionToLocator(locatorPort).startServer();
}
- public ServerStarterRule startServer(boolean pdxPersistent) {
- normalizeProperties();
+ public void startServer(boolean pdxPersistent) {
CacheFactory cf = new CacheFactory(this.properties);
cf.setPdxReadSerialized(pdxPersistent);
cf.setPdxPersistent(pdxPersistent);
@@ -135,7 +158,6 @@ public class ServerStarterRule extends MemberStarterRule<ServerStarterRule> impl
memberPort = server.getPort();
jmxPort = config.getJmxManagerPort();
httpPort = config.getHttpServicePort();
- return this;
}
public int getEmbeddedLocatorPort() {
http://git-wip-us.apache.org/repos/asf/geode/blob/6a88f1bc/geode-core/src/test/java/org/apache/geode/test/dunit/rules/test/MemberStarterRuleTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/test/dunit/rules/test/MemberStarterRuleTest.java b/geode-core/src/test/java/org/apache/geode/test/dunit/rules/test/MemberStarterRuleTest.java
new file mode 100644
index 0000000..7dada04
--- /dev/null
+++ b/geode-core/src/test/java/org/apache/geode/test/dunit/rules/test/MemberStarterRuleTest.java
@@ -0,0 +1,72 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more contributor license
+ * agreements. See the NOTICE file distributed with this work for additional information regarding
+ * copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the License. You may obtain a
+ * copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License
+ * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
+ * or implied. See the License for the specific language governing permissions and limitations under
+ * the License.
+ */
+
+package org.apache.geode.test.dunit.rules.test;
+
+import static org.apache.geode.distributed.ConfigurationProperties.JMX_MANAGER_PORT;
+import static org.assertj.core.api.Assertions.assertThat;
+
+import org.apache.geode.test.dunit.rules.LocatorStarterRule;
+import org.apache.geode.test.junit.categories.UnitTest;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+
+@Category(UnitTest.class)
+public class MemberStarterRuleTest {
+
+ @Test
+ public void testSetJMXPortWithProperty() {
+ int port = 2000;
+ LocatorStarterRule locator = new LocatorStarterRule().withProperty(JMX_MANAGER_PORT, port + "");
+ locator.before();
+ assertThat(locator.getJmxPort()).isEqualTo(port);
+ }
+
+ @Test
+ public void testSetJMXPortWithPropertyThenAPI() {
+ int port = 2000;
+ LocatorStarterRule locator = new LocatorStarterRule().withProperty(JMX_MANAGER_PORT, port + "");
+
+ // user call withJMXManager again
+ locator.withJMXManager();
+ locator.before();
+
+ assertThat(locator.getJmxPort()).isEqualTo(port);
+ }
+
+ @Test
+ public void testSetJMXPortWithAPIThenProperty() {
+ // this first one wins
+ LocatorStarterRule locator = new LocatorStarterRule().withJMXManager();
+ int port = locator.getJmxPort();
+
+ locator.withProperty(JMX_MANAGER_PORT, "9999");
+ locator.before();
+
+ assertThat(locator.getJmxPort()).isEqualTo(port);
+ }
+
+ @Test
+ public void testUseRandomPortByDefault() {
+ LocatorStarterRule locator = new LocatorStarterRule();
+ locator.before();
+
+ assertThat(locator.getJmxPort()).isNotEqualTo(1099);
+ assertThat(locator.getJmxPort()).isNotEqualTo(-1);
+
+ assertThat(locator.getHttpPort()).isNotEqualTo(7070);
+ assertThat(locator.getHttpPort()).isNotEqualTo(-1);
+ }
+}