You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@geode.apache.org by kl...@apache.org on 2016/12/12 22:36:37 UTC
[34/46] geode git commit: Convert from ManagementTestCase to
ManagementTestRule
http://git-wip-us.apache.org/repos/asf/geode/blob/c3586a96/geode-core/src/test/java/org/apache/geode/management/bean/stats/DistributedSystemStatsDUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/management/bean/stats/DistributedSystemStatsDUnitTest.java b/geode-core/src/test/java/org/apache/geode/management/bean/stats/DistributedSystemStatsDUnitTest.java
index d2e797e..92d685a 100644
--- a/geode-core/src/test/java/org/apache/geode/management/bean/stats/DistributedSystemStatsDUnitTest.java
+++ b/geode-core/src/test/java/org/apache/geode/management/bean/stats/DistributedSystemStatsDUnitTest.java
@@ -14,98 +14,66 @@
*/
package org.apache.geode.management.bean.stats;
-import org.junit.experimental.categories.Category;
-import org.junit.Test;
-
+import static com.jayway.awaitility.Awaitility.*;
import static org.junit.Assert.*;
-import org.apache.geode.test.dunit.cache.internal.JUnit4CacheTestCase;
-import org.apache.geode.test.dunit.internal.JUnit4DistributedTestCase;
-import org.apache.geode.test.junit.categories.DistributedTest;
-
+import java.lang.management.ManagementFactory;
import java.util.Set;
+import java.util.concurrent.TimeUnit;
import javax.management.ObjectName;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+
import org.apache.geode.distributed.DistributedMember;
-import org.apache.geode.internal.cache.DiskStoreStats;
import org.apache.geode.internal.cache.GemFireCacheImpl;
import org.apache.geode.management.DistributedSystemMXBean;
-import org.apache.geode.management.ManagementTestBase;
+import org.apache.geode.management.ManagementService;
+import org.apache.geode.management.ManagementTestRule;
+import org.apache.geode.management.Manager;
+import org.apache.geode.management.Member;
import org.apache.geode.management.MemberMXBean;
import org.apache.geode.management.internal.SystemManagementService;
-import org.apache.geode.management.internal.beans.MemberMBean;
-import org.apache.geode.management.internal.beans.MemberMBeanBridge;
-import org.apache.geode.test.dunit.Assert;
-import org.apache.geode.test.dunit.SerializableRunnable;
import org.apache.geode.test.dunit.VM;
+import org.apache.geode.test.junit.categories.DistributedTest;
-/**
- */
@Category(DistributedTest.class)
-public class DistributedSystemStatsDUnitTest extends ManagementTestBase {
+@SuppressWarnings("serial")
+public class DistributedSystemStatsDUnitTest {
- private static final long serialVersionUID = 1L;
+ @Manager
+ private VM manager;
- public DistributedSystemStatsDUnitTest() {
- super();
- }
+ @Member
+ private VM[] members;
+
+ @Rule
+ public ManagementTestRule managementTestRule = ManagementTestRule.builder().build();
@Test
public void testDistributedSystemStats() throws Exception {
- initManagement(true);
-
- for (VM vm : managedNodeList) {
- setDiskStats(vm);
- }
- verifyDiskStats(managingNode);
- }
+ this.manager.invoke("verifyMBeans", () -> {
+ GemFireCacheImpl cache = GemFireCacheImpl.getInstance();
+ assertNotNull(cache);
- @SuppressWarnings("serial")
- public void setDiskStats(VM vm1) throws Exception {
- vm1.invoke(new SerializableRunnable("Set Member Stats") {
- public void run() {
- MemberMBean bean = (MemberMBean) managementService.getMemberMXBean();
- MemberMBeanBridge bridge = bean.getBridge();
- DiskStoreStats diskStoreStats = new DiskStoreStats(basicGetSystem(), "test");
- bridge.addDiskStoreStats(diskStoreStats);
- diskStoreStats.startRead();
- diskStoreStats.startWrite();
- diskStoreStats.startBackup();
- diskStoreStats.startRecovery();
- diskStoreStats.incWrittenBytes(20, true);
- diskStoreStats.startFlush();
- diskStoreStats.setQueueSize(10);
- }
- });
- }
+ SystemManagementService service = (SystemManagementService) ManagementService.getManagementService(cache);
+ DistributedSystemMXBean distributedSystemMXBean = service.getDistributedSystemMXBean();
+ assertNotNull(distributedSystemMXBean);
- @SuppressWarnings("serial")
- public void verifyDiskStats(VM vm1) throws Exception {
- vm1.invoke(new SerializableRunnable("Set Member Stats") {
- public void run() {
- GemFireCacheImpl cache = GemFireCacheImpl.getInstance();
+ Set<DistributedMember> otherMemberSet = cache.getDistributionManager().getOtherNormalDistributionManagerIds();
+ assertEquals(3, otherMemberSet.size());
- SystemManagementService service = (SystemManagementService) getManagementService();
- DistributedSystemMXBean bean = service.getDistributedSystemMXBean();
- assertNotNull(bean);
- Set<DistributedMember> otherMemberSet =
- cache.getDistributionManager().getOtherNormalDistributionManagerIds();
+ for (DistributedMember member : otherMemberSet) {
+ ObjectName memberMXBeanName = service.getMemberMBeanName(member);
+ await().atMost(2, TimeUnit.MINUTES).until(() -> assertTrue(ManagementFactory.getPlatformMBeanServer().isRegistered(memberMXBeanName)));
- for (DistributedMember member : otherMemberSet) {
- ObjectName memberMBeanName;
- try {
- memberMBeanName = service.getMemberMBeanName(member);
- waitForProxy(memberMBeanName, MemberMXBean.class);
- MemberMXBean memberBean = service.getMBeanProxy(memberMBeanName, MemberMXBean.class);
- waitForRefresh(2, memberMBeanName);
- } catch (NullPointerException e) {
- Assert.fail("FAILED WITH EXCEPION", e);
- } catch (Exception e) {
- Assert.fail("FAILED WITH EXCEPION", e);
- }
- }
+ MemberMXBean memberMXBean = service.getMBeanProxy(memberMXBeanName, MemberMXBean.class);
+ assertNotNull(memberMXBean);
+ final long lastRefreshTime = service.getLastUpdateTime(memberMXBeanName);
+ await().atMost(1, TimeUnit.MINUTES).until(() -> assertTrue(service.getLastUpdateTime(memberMXBeanName) > lastRefreshTime));
}
});
}
http://git-wip-us.apache.org/repos/asf/geode/blob/c3586a96/geode-core/src/test/java/org/apache/geode/management/internal/beans/QueryDataFunctionApplyLimitClauseTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/management/internal/beans/QueryDataFunctionApplyLimitClauseTest.java b/geode-core/src/test/java/org/apache/geode/management/internal/beans/QueryDataFunctionApplyLimitClauseTest.java
index f4ca239..128280e 100644
--- a/geode-core/src/test/java/org/apache/geode/management/internal/beans/QueryDataFunctionApplyLimitClauseTest.java
+++ b/geode-core/src/test/java/org/apache/geode/management/internal/beans/QueryDataFunctionApplyLimitClauseTest.java
@@ -24,7 +24,6 @@ import org.junit.experimental.categories.Category;
import org.apache.geode.test.junit.categories.UnitTest;
-
@Category(UnitTest.class)
public class QueryDataFunctionApplyLimitClauseTest {
@@ -45,9 +44,7 @@ public class QueryDataFunctionApplyLimitClauseTest {
public void applyLimitClauseDoesNothingIfLimitClauseSpecified() {
String limitClause = " LIMIT 50";
String selectQueryWithLimit = selectQuery + limitClause;
- assertThat(
- QueryDataFunction.applyLimitClause(selectQueryWithLimit, limit_10, queryResultSetLimit_100))
- .isEqualTo(selectQueryWithLimit);
+ assertThat(QueryDataFunction.applyLimitClause(selectQueryWithLimit, limit_10, queryResultSetLimit_100)).isEqualTo(selectQueryWithLimit);
}
@Test
@@ -65,16 +62,13 @@ public class QueryDataFunctionApplyLimitClauseTest {
@Test // GEODE-1907
public void applyLimitClauseAddsQueryResultSetLimitIfMissingSpaceAfterFrom() {
String selectQueryMissingSpaceAfterFrom = "SELECT * FROM/MyRegion";
- assertThat(QueryDataFunction.applyLimitClause(selectQueryMissingSpaceAfterFrom, limit_0,
- queryResultSetLimit_100))
- .isEqualTo(selectQueryMissingSpaceAfterFrom + " LIMIT " + queryResultSetLimit_100);
+ assertThat(QueryDataFunction.applyLimitClause(selectQueryMissingSpaceAfterFrom, limit_0, queryResultSetLimit_100)).isEqualTo(selectQueryMissingSpaceAfterFrom + " LIMIT " + queryResultSetLimit_100);
}
@Test
public void applyLimitClauseDoesNotAddQueryResultSetLimitIfMissingSpaceAfterFromButLimitIsPresent() {
String selectQueryMissingSpaceAfterFromWithLimit = "SELECT * FROM/MyRegion LIMIT " + limit_10;
- assertThat(QueryDataFunction.applyLimitClause(selectQueryMissingSpaceAfterFromWithLimit,
- limit_0, queryResultSetLimit_100)).isEqualTo(selectQueryMissingSpaceAfterFromWithLimit);
+ assertThat(QueryDataFunction.applyLimitClause(selectQueryMissingSpaceAfterFromWithLimit, limit_0, queryResultSetLimit_100)).isEqualTo(selectQueryMissingSpaceAfterFromWithLimit);
}
}
http://git-wip-us.apache.org/repos/asf/geode/blob/c3586a96/geode-core/src/test/java/org/apache/geode/management/internal/pulse/TestClientIdsDUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/management/internal/pulse/TestClientIdsDUnitTest.java b/geode-core/src/test/java/org/apache/geode/management/internal/pulse/TestClientIdsDUnitTest.java
index 9416616..9e98024 100644
--- a/geode-core/src/test/java/org/apache/geode/management/internal/pulse/TestClientIdsDUnitTest.java
+++ b/geode-core/src/test/java/org/apache/geode/management/internal/pulse/TestClientIdsDUnitTest.java
@@ -56,67 +56,49 @@ import org.apache.geode.test.junit.categories.DistributedTest;
* This is for testing client IDs
*/
@Category(DistributedTest.class)
-public class TestClientIdsDUnitTest extends JUnit4DistributedTestCase {
+@SuppressWarnings("serial")
+public class TestClientIdsDUnitTest extends ManagementTestBase {
private static final String k1 = "k1";
private static final String k2 = "k2";
-
private static final String client_k1 = "client-k1";
-
private static final String client_k2 = "client-k2";
-
- /** name of the test region */
private static final String REGION_NAME = "ClientHealthStatsDUnitTest_Region";
private static VM server = null;
-
private static VM client = null;
-
private static VM client2 = null;
- private static VM managingNode = null;
-
- private ManagementTestBase helper;
-
- @Override
- public final void preSetUp() throws Exception {
- this.helper = new ManagementTestBase() {};
- }
-
@Override
- public final void postSetUp() throws Exception {
- final Host host = Host.getHost(0);
- managingNode = host.getVM(0);
- server = host.getVM(1);
- client = host.getVM(2);
- client2 = host.getVM(3);
+ public final void postSetUpManagementTestBase() throws Exception {
+ server = Host.getHost(0).getVM(1);
+ client = Host.getHost(0).getVM(2);
+ client2 = Host.getHost(0).getVM(3);
}
@Override
- public final void preTearDown() throws Exception {
- helper.closeCache(managingNode);
- helper.closeCache(server);
- helper.closeCache(client);
- helper.closeCache(client2);
+ public final void postTearDownManagementTestBase() throws Exception {
+ closeCache(server);
+ closeCache(client);
+ closeCache(client2);
disconnectFromDS();
}
@Test
public void testClientIds() throws Exception {
- helper.createManagementCache(managingNode);
- helper.startManagingNode(managingNode);
+ createManagementCache(managingNode);
+ startManagingNode(managingNode);
int port = (Integer) createServerCache(server);
- DistributedMember serverMember = helper.getMember(server);
+ DistributedMember serverMember = getMember(server);
createClientCache(client, NetworkUtils.getServerHostName(server.getHost()), port);
createClientCache(client2, NetworkUtils.getServerHostName(server.getHost()), port);
put(client);
put(client2);
verifyClientIds(managingNode, serverMember, port);
- helper.stopManagingNode(managingNode);
+ stopManagingNode(managingNode);
}
- @SuppressWarnings("serial")
private Object createServerCache(VM vm) {
return vm.invoke(new SerializableCallable("Create Server Cache") {
public Object call() {
@@ -130,7 +112,6 @@ public class TestClientIdsDUnitTest extends JUnit4DistributedTestCase {
});
}
- @SuppressWarnings("serial")
private void createClientCache(VM vm, final String host, final Integer port1) {
vm.invoke(new SerializableCallable("Create Client Cache") {
@@ -156,7 +137,7 @@ public class TestClientIdsDUnitTest extends JUnit4DistributedTestCase {
}
private Integer createServerCache(DataPolicy dataPolicy) throws Exception {
- Cache cache = helper.createCache(false);
+ Cache cache = createCache(false);
AttributesFactory factory = new AttributesFactory();
factory.setScope(Scope.DISTRIBUTED_ACK);
factory.setDataPolicy(dataPolicy);
@@ -199,7 +180,6 @@ public class TestClientIdsDUnitTest extends JUnit4DistributedTestCase {
/**
* get member id
*/
- @SuppressWarnings("serial")
protected static DistributedMember getMember() throws Exception {
GemFireCacheImpl cache = GemFireCacheImpl.getInstance();
return cache.getDistributedSystem().getDistributedMember();
@@ -210,27 +190,22 @@ public class TestClientIdsDUnitTest extends JUnit4DistributedTestCase {
*
* @param vm
*/
- @SuppressWarnings("serial")
- protected void verifyClientIds(final VM vm, final DistributedMember serverMember,
- final int serverPort) {
- SerializableRunnable verifyCacheServerRemote =
- new SerializableRunnable("Verify Cache Server Remote") {
- public void run() {
- try {
- final WaitCriterion waitCriteria = new WaitCriterion() {
- @Override
- public boolean done() {
- CacheServerMXBean bean = null;
- try {
- bean = MBeanUtil.getCacheServerMbeanProxy(serverMember, serverPort);
- if (bean != null) {
- if (bean.getClientIds().length > 0) {
- return true;
- }
- }
- } catch (Exception e) {
- LogWriterUtils.getLogWriter().info("exception occured " + e.getMessage()
- + CliUtil.stackTraceAsString((Throwable) e));
+ protected void verifyClientIds(final VM vm,
+ final DistributedMember serverMember, final int serverPort) {
+ SerializableRunnable verifyCacheServerRemote = new SerializableRunnable(
+ "Verify Cache Server Remote") {
+ public void run() {
+ try {
+ final WaitCriterion waitCriteria = new WaitCriterion() {
+ @Override
+ public boolean done() {
+ CacheServerMXBean bean = null;
+ try {
+ bean = MBeanUtil.getCacheServerMbeanProxy(
+ serverMember, serverPort);
+ if (bean != null) {
+ if( bean.getClientIds().length > 0){
+ return true;
}
return false;
}
@@ -259,7 +234,6 @@ public class TestClientIdsDUnitTest extends JUnit4DistributedTestCase {
*
* @param vm
*/
- @SuppressWarnings("serial")
protected void put(final VM vm) {
SerializableRunnable put = new SerializableRunnable("put") {
public void run() {
http://git-wip-us.apache.org/repos/asf/geode/blob/c3586a96/geode-core/src/test/java/org/apache/geode/management/internal/pulse/TestSubscriptionsDUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/management/internal/pulse/TestSubscriptionsDUnitTest.java b/geode-core/src/test/java/org/apache/geode/management/internal/pulse/TestSubscriptionsDUnitTest.java
index 7d96517..f09e7c9 100644
--- a/geode-core/src/test/java/org/apache/geode/management/internal/pulse/TestSubscriptionsDUnitTest.java
+++ b/geode-core/src/test/java/org/apache/geode/management/internal/pulse/TestSubscriptionsDUnitTest.java
@@ -15,6 +15,9 @@
package org.apache.geode.management.internal.pulse;
import static org.apache.geode.distributed.ConfigurationProperties.*;
+import static org.apache.geode.test.dunit.Host.*;
+import static org.apache.geode.test.dunit.NetworkUtils.*;
+import static org.apache.geode.test.dunit.Wait.*;
import static org.junit.Assert.*;
import java.util.Properties;
@@ -32,268 +35,175 @@ import org.apache.geode.cache.Scope;
import org.apache.geode.cache.client.PoolManager;
import org.apache.geode.cache.client.internal.PoolImpl;
import org.apache.geode.cache.server.CacheServer;
-import org.apache.geode.distributed.DistributedMember;
import org.apache.geode.distributed.DistributedSystem;
-import org.apache.geode.internal.AvailablePort;
import org.apache.geode.internal.cache.GemFireCacheImpl;
import org.apache.geode.management.DistributedSystemMXBean;
import org.apache.geode.management.ManagementService;
import org.apache.geode.management.ManagementTestBase;
-import org.apache.geode.test.dunit.Assert;
-import org.apache.geode.test.dunit.Host;
-import org.apache.geode.test.dunit.LogWriterUtils;
-import org.apache.geode.test.dunit.NetworkUtils;
-import org.apache.geode.test.dunit.SerializableCallable;
-import org.apache.geode.test.dunit.SerializableRunnable;
import org.apache.geode.test.dunit.VM;
-import org.apache.geode.test.dunit.Wait;
import org.apache.geode.test.dunit.WaitCriterion;
-import org.apache.geode.test.dunit.internal.JUnit4DistributedTestCase;
import org.apache.geode.test.junit.categories.DistributedTest;
/**
* This is for testing subscriptions
*/
@Category(DistributedTest.class)
-public class TestSubscriptionsDUnitTest extends JUnit4DistributedTestCase {
+@SuppressWarnings("serial")
+public class TestSubscriptionsDUnitTest extends ManagementTestBase {
- private static final String k1 = "k1";
- private static final String k2 = "k2";
- private static final String client_k1 = "client-k1";
+ private static final String REGION_NAME = TestSubscriptionsDUnitTest.class.getSimpleName() + "_Region";
+
+ private static final String KEY1 = "k1";
+ private static final String KEY2 = "k2";
+ private static final String CLIENT_VALUE1 = "client-k1";
+ private static final String CLIENT_VALUE2 = "client-k2";
- private static final String client_k2 = "client-k2";
- private static final String REGION_NAME =
- TestSubscriptionsDUnitTest.class.getSimpleName() + "_Region";
private static VM server = null;
private static VM client = null;
private static VM client2 = null;
- private static VM managingNode = null;
- private ManagementTestBase helper;
-
- @Override
- public final void preSetUp() throws Exception {
- this.helper = new ManagementTestBase() {};
- }
-
- @Override
- public final void postSetUp() throws Exception {
- final Host host = Host.getHost(0);
- managingNode = host.getVM(0);
- server = host.getVM(1);
- client = host.getVM(2);
- client2 = host.getVM(3);
- }
@Override
- public final void preTearDown() throws Exception {
- helper.closeCache(managingNode);
- helper.closeCache(server);
- helper.closeCache(client);
- helper.closeCache(client2);
- disconnectFromDS();
+ public final void postSetUpManagementTestBase() throws Exception {
+ server = getHost(0).getVM(1);
+ client = getHost(0).getVM(2);
+ client2 = getHost(0).getVM(3);
}
@Test
- public void testNoOfSubscription() throws Exception {
+ public void testNumSubscriptions() throws Exception {
+ createManagementCache(managingNode);
+ startManagingNode(managingNode);
+
+ int port = createServerCache(server);
+ getMember(server);
- helper.createManagementCache(managingNode);
- helper.startManagingNode(managingNode);
+ createClientCache(client, getServerHostName(server.getHost()), port);
+ createClientCache(client2, getServerHostName(server.getHost()), port);
- int port = (Integer) createServerCache(server);
- DistributedMember serverMember = helper.getMember(server);
- createClientCache(client, NetworkUtils.getServerHostName(server.getHost()), port);
- createClientCache(client2, NetworkUtils.getServerHostName(server.getHost()), port);
put(client);
put(client2);
+
registerInterest(client);
registerInterest(client2);
- verifyClientStats(managingNode, serverMember, port);
- helper.stopManagingNode(managingNode);
- }
- @SuppressWarnings("serial")
- private Object createServerCache(VM vm) {
- return vm.invoke(new SerializableCallable("Create Server Cache in TestSubscriptionsDUnitTest") {
+ verifyNumSubscriptions(managingNode);
- public Object call() {
- try {
- return createServerCache();
- } catch (Exception e) {
- fail("Error while createServerCache in TestSubscriptionsDUnitTest" + e);
- }
- return null;
- }
- });
+ stopManagingNode(managingNode);
}
- @SuppressWarnings("serial")
- private void createClientCache(VM vm, final String host, final Integer port1) {
- vm.invoke(new SerializableCallable("Create Client Cache in TestSubscriptionsDUnitTest") {
+ private int createServerCache(VM vm) {
+ return vm.invoke("Create Server Cache in TestSubscriptionsDUnitTest", () -> {
+ return createServerCache();
+ });
+ }
- public Object call() {
- try {
- createClientCache(host, port1);
- } catch (Exception e) {
- fail("Error while createClientCache in TestSubscriptionsDUnitTest " + e);
- }
- return null;
- }
+ private void createClientCache(VM vm, final String host, final int port1) {
+ vm.invoke("Create Client Cache in TestSubscriptionsDUnitTest", () -> {
+ createClientCache(host, port1);
});
}
private Cache createCache(Properties props) throws Exception {
DistributedSystem ds = getSystem(props);
- ds.disconnect();
- ds = getSystem(props);
- assertNotNull(ds);
- Cache cache = (GemFireCacheImpl) CacheFactory.create(ds);
- assertNotNull(cache);
+ Cache cache = CacheFactory.create(ds);
return cache;
}
- private Integer createServerCache(DataPolicy dataPolicy) throws Exception {
- Cache cache = helper.createCache(false);
+ private int createServerCache(DataPolicy dataPolicy) throws Exception {
+ Cache cache = createCache(false);
+
AttributesFactory factory = new AttributesFactory();
factory.setScope(Scope.DISTRIBUTED_ACK);
factory.setDataPolicy(dataPolicy);
- RegionAttributes attrs = factory.create();
- cache.createRegion(REGION_NAME, attrs);
- int port = AvailablePort.getRandomAvailablePort(AvailablePort.SOCKET);
+
+ cache.createRegion(REGION_NAME, factory.create());
+
CacheServer server1 = cache.addCacheServer();
- server1.setPort(port);
+ server1.setPort(0);
server1.setNotifyBySubscription(true);
server1.start();
- return new Integer(server1.getPort());
+
+ return server1.getPort();
}
- public Integer createServerCache() throws Exception {
+ private int createServerCache() throws Exception {
return createServerCache(DataPolicy.REPLICATE);
}
- public Cache createClientCache(String host, Integer port1) throws Exception {
-
+ private Cache createClientCache(String host, int port1) throws Exception {
Properties props = new Properties();
props.setProperty(MCAST_PORT, "0");
props.setProperty(LOCATORS, "");
+
Cache cache = createCache(props);
- PoolImpl p = (PoolImpl) PoolManager.createFactory().addServer(host, port1.intValue())
- .setSubscriptionEnabled(true).setThreadLocalConnections(true).setMinConnections(1)
- .setReadTimeout(20000).setPingInterval(10000).setRetryAttempts(1)
- .setSubscriptionEnabled(true).setStatisticInterval(1000)
- .create("TestSubscriptionsDUnitTest");
+
+ PoolImpl p = (PoolImpl) PoolManager.createFactory()
+ .addServer(host, port1)
+ .setSubscriptionEnabled(true)
+ .setThreadLocalConnections(true)
+ .setMinConnections(1)
+ .setReadTimeout(20000)
+ .setPingInterval(10000)
+ .setRetryAttempts(1)
+ .setSubscriptionEnabled(true)
+ .setStatisticInterval(1000)
+ .create("TestSubscriptionsDUnitTest");
AttributesFactory factory = new AttributesFactory();
factory.setScope(Scope.DISTRIBUTED_ACK);
factory.setPoolName(p.getName());
RegionAttributes attrs = factory.create();
- Region region = cache.createRegion(REGION_NAME, attrs);
- return cache;
+ cache.createRegion(REGION_NAME, attrs);
+ return cache;
}
- /**
- * get member id
- */
- @SuppressWarnings("serial")
- protected static DistributedMember getMember() throws Exception {
- GemFireCacheImpl cache = GemFireCacheImpl.getInstance();
- return cache.getDistributedSystem().getDistributedMember();
- }
+ private void verifyNumSubscriptions(final VM vm) {
+ vm.invoke("TestSubscriptionsDUnitTest Verify Cache Server Remote", () -> {
+ final GemFireCacheImpl cache = GemFireCacheImpl.getInstance();
- /**
- * Verify the Cache Server details
- *
- * @param vm
- */
- @SuppressWarnings("serial")
- protected void verifyClientStats(final VM vm, final DistributedMember serverMember,
- final int serverPort) {
- SerializableRunnable verifyCacheServerRemote =
- new SerializableRunnable("TestSubscriptionsDUnitTest Verify Cache Server Remote") {
- public void run() {
- final GemFireCacheImpl cache = GemFireCacheImpl.getInstance();
- try {
- final WaitCriterion waitCriteria = new WaitCriterion() {
- @Override
- public boolean done() {
- ManagementService service = ManagementService.getExistingManagementService(cache);
- final DistributedSystemMXBean dsBean = service.getDistributedSystemMXBean();
- if (dsBean != null) {
- if (dsBean.getNumSubscriptions() > 1) {
- return true;
- }
- }
- return false;
- }
-
- @Override
- public String description() {
- return "TestSubscriptionsDUnitTest wait for getDistributedSystemMXBean to complete and get results";
- }
- };
- Wait.waitForCriterion(waitCriteria, 2 * 60 * 1000, 3000, true);
- final DistributedSystemMXBean dsBean = ManagementService
- .getExistingManagementService(cache).getDistributedSystemMXBean();
- assertNotNull(dsBean);
- LogWriterUtils.getLogWriter()
- .info("TestSubscriptionsDUnitTest dsBean.getNumSubscriptions() ="
- + dsBean.getNumSubscriptions());
- assertTrue(dsBean.getNumSubscriptions() == 2 ? true : false);
- } catch (Exception e) {
- fail("TestSubscriptionsDUnitTest Error while verifying subscription "
- + e.getMessage());
- }
-
- }
- };
- vm.invoke(verifyCacheServerRemote);
- }
+ waitForCriterion(new WaitCriterion() {
+ @Override
+ public boolean done() {
+ ManagementService service = ManagementService.getExistingManagementService(cache);
+ DistributedSystemMXBean distributedSystemMXBean = service.getDistributedSystemMXBean();
+ return distributedSystemMXBean != null & distributedSystemMXBean.getNumSubscriptions() > 1;
+ }
+ @Override
+ public String description() {
+ return "TestSubscriptionsDUnitTest wait for getDistributedSystemMXBean to complete and get results";
+ }
+ }, 2 * 60 * 1000, 3000, true);
- /**
- * Verify the Cache Server details
- *
- * @param vm
- */
- @SuppressWarnings("serial")
- protected void registerInterest(final VM vm) {
- SerializableRunnable put =
- new SerializableRunnable("TestSubscriptionsDUnitTest registerInterest") {
- public void run() {
- try {
- Cache cache = GemFireCacheImpl.getInstance();
- Region<Object, Object> r1 = cache.getRegion(Region.SEPARATOR + REGION_NAME);
- assertNotNull(r1);
- r1.registerInterest(k1);
- r1.registerInterest(k2);
- } catch (Exception ex) {
- Assert.fail("TestSubscriptionsDUnitTest failed while register Interest", ex);
- }
- }
-
- };
- vm.invoke(put);
+ DistributedSystemMXBean distributedSystemMXBean = ManagementService.getExistingManagementService(cache).getDistributedSystemMXBean();
+ assertNotNull(distributedSystemMXBean);
+ assertEquals(2, distributedSystemMXBean.getNumSubscriptions());
+ });
}
- @SuppressWarnings("serial")
- protected void put(final VM vm) {
- SerializableRunnable put = new SerializableRunnable("put") {
- public void run() {
- try {
- Cache cache = GemFireCacheImpl.getInstance();
- Region r1 = cache.getRegion(Region.SEPARATOR + REGION_NAME);
- assertNotNull(r1);
- r1.put(k1, client_k1);
- assertEquals(r1.getEntry(k1).getValue(), client_k1);
- r1.put(k2, client_k2);
- assertEquals(r1.getEntry(k2).getValue(), client_k2);
- } catch (Exception ex) {
- Assert.fail("failed while put", ex);
- }
- }
+ private void registerInterest(final VM vm) {
+ vm.invoke("TestSubscriptionsDUnitTest registerInterest", () -> {
+ Cache cache = GemFireCacheImpl.getInstance();
+ Region<Object, Object> region = cache.getRegion(Region.SEPARATOR + REGION_NAME);
+ assertNotNull(region);
- };
- vm.invoke(put);
+ region.registerInterest(KEY1);
+ region.registerInterest(KEY2);
+ });
}
+ private void put(final VM vm) {
+ vm.invoke("put", () -> {
+ Cache cache = GemFireCacheImpl.getInstance();
+ Region region = cache.getRegion(Region.SEPARATOR + REGION_NAME);
+ assertNotNull(region);
+
+ region.put(KEY1, CLIENT_VALUE1);
+ assertEquals(CLIENT_VALUE1, region.getEntry(KEY1).getValue());
+
+ region.put(KEY2, CLIENT_VALUE2);
+ assertEquals(CLIENT_VALUE2, region.getEntry(KEY2).getValue());
+ });
+ }
}
http://git-wip-us.apache.org/repos/asf/geode/blob/c3586a96/geode-core/src/test/java/org/apache/geode/test/dunit/AsyncInvocation.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/test/dunit/AsyncInvocation.java b/geode-core/src/test/java/org/apache/geode/test/dunit/AsyncInvocation.java
index 460b562..88168af 100644
--- a/geode-core/src/test/java/org/apache/geode/test/dunit/AsyncInvocation.java
+++ b/geode-core/src/test/java/org/apache/geode/test/dunit/AsyncInvocation.java
@@ -316,8 +316,63 @@ public class AsyncInvocation<V> implements Future<V> {
}
/**
- * Waits if necessary for the work to complete, and then returns the result of this
- * {@code AsyncInvocation}.
+ * Waits if necessary for at most the given time for the computation
+ * to complete.
+ *
+ * @param timeout the maximum time to wait
+ * @param unit the time unit of the timeout argument
+ *
+ * @return this {@code AsyncInvocation}
+ *
+ * @throws AssertionError wrapping any {@code Exception} thrown by this
+ * {@code AsyncInvocation}.
+ *
+ * @throws CancellationException if the computation was cancelled
+ *
+ * @throws ExecutionException if the computation threw an exception
+ *
+ * @throws InterruptedException if the current thread is interrupted.
+ *
+ * @throws TimeoutException if the wait timed out
+ */
+ public AsyncInvocation<V> await(final long timeout, final TimeUnit unit) throws ExecutionException, InterruptedException, TimeoutException {
+ long millis = unit.toMillis(timeout);
+ join(millis);
+ timeoutIfAlive(millis);
+ checkException();
+ return this;
+ }
+
+ /**
+ * Waits if necessary for at most the given time for the computation
+ * to complete.
+ *
+ * @return this {@code AsyncInvocation}
+ *
+ * @throws AssertionError wrapping any {@code Exception} thrown by this
+ * {@code AsyncInvocation}.
+ *
+ * @throws AssertionError wrapping a {@code TimeoutException} if this
+ * {@code AsyncInvocation} fails to complete within the default
+ * timeout of 60 seconds as defined by {@link #DEFAULT_JOIN_MILLIS}.
+ *
+ * @throws CancellationException if the computation was cancelled
+ *
+ * @throws ExecutionException if the computation threw an exception
+ *
+ * @throws InterruptedException if the current thread is interrupted.
+ */
+ public AsyncInvocation<V> await() throws ExecutionException, InterruptedException {
+ try {
+ return await(DEFAULT_JOIN_MILLIS, TimeUnit.MILLISECONDS);
+ } catch (TimeoutException timeoutException) {
+ throw new AssertionError(timeoutException);
+ }
+ }
+
+ /**
+ * Waits if necessary for the work to complete, and then returns the result
+ * of this {@code AsyncInvocation}.
*
* @return the result of this {@code AsyncInvocation}
*
@@ -353,10 +408,6 @@ public class AsyncInvocation<V> implements Future<V> {
*
* @throws AssertionError wrapping any {@code Exception} thrown by this {@code AsyncInvocation}.
*
- * @throws AssertionError wrapping a {@code TimeoutException} if this {@code AsyncInvocation}
- * fails to complete within the default timeout of 60 seconds as defined by
- * {@link #DEFAULT_JOIN_MILLIS}.
- *
* @throws CancellationException if the computation was cancelled
*
* @throws ExecutionException if the computation threw an exception
http://git-wip-us.apache.org/repos/asf/geode/blob/c3586a96/geode-core/src/test/java/org/apache/geode/test/dunit/Invoke.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/test/dunit/Invoke.java b/geode-core/src/test/java/org/apache/geode/test/dunit/Invoke.java
index a09f5ff..af7e217 100755
--- a/geode-core/src/test/java/org/apache/geode/test/dunit/Invoke.java
+++ b/geode-core/src/test/java/org/apache/geode/test/dunit/Invoke.java
@@ -22,13 +22,13 @@ import java.util.Map;
* invoke a <code>SerializableRunnable</code> or <code>SerializableCallable</code> in a remote test
* <code>VM</code>.
*
- * These methods can be used directly: <code>Invoke.invokeInEveryVM(...)</code>, however, they are
- * intended to be referenced through static import:
+ * These methods can be used directly: <code>Invoke.invokeInEveryVMAndController(...)</code>,
+ * however, they are intended to be referenced through static import:
*
* <pre>
* import static org.apache.geode.test.dunit.Invoke.*;
* ...
- * invokeInEveryVM(...);
+ * invokeInEveryVMAndController(...);
* </pre>
*
* Extracted from DistributedTestCase.
http://git-wip-us.apache.org/repos/asf/geode/blob/c3586a96/geode-core/src/test/java/org/apache/geode/test/dunit/VM.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/test/dunit/VM.java b/geode-core/src/test/java/org/apache/geode/test/dunit/VM.java
index 04d2951..375deed 100644
--- a/geode-core/src/test/java/org/apache/geode/test/dunit/VM.java
+++ b/geode-core/src/test/java/org/apache/geode/test/dunit/VM.java
@@ -24,6 +24,7 @@ import java.util.concurrent.Callable;
import com.jayway.awaitility.Awaitility;
import hydra.MethExecutorResult;
+import org.apache.geode.internal.process.PidUnavailableException;
import org.apache.geode.internal.process.ProcessUtils;
import org.apache.geode.test.dunit.standalone.BounceResult;
import org.apache.geode.test.dunit.standalone.RemoteDUnitVMIF;
@@ -91,7 +92,11 @@ public class VM implements Serializable {
* Returns the process id of this {@code VM}.
*/
public int getPid() {
- return this.pid;
+// try {
+ return invoke(() -> ProcessUtils.identifyPid());
+// } catch (PidUnavailableException e) {
+// return this.pid;
+// }
}
/**
http://git-wip-us.apache.org/repos/asf/geode/blob/c3586a96/geode-core/src/test/java/org/apache/geode/test/dunit/Wait.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/test/dunit/Wait.java b/geode-core/src/test/java/org/apache/geode/test/dunit/Wait.java
index f25810e..7d4e6d5 100755
--- a/geode-core/src/test/java/org/apache/geode/test/dunit/Wait.java
+++ b/geode-core/src/test/java/org/apache/geode/test/dunit/Wait.java
@@ -17,6 +17,8 @@ package org.apache.geode.test.dunit;
import static org.apache.geode.test.dunit.Jitter.*;
import static org.junit.Assert.*;
+import java.io.Serializable;
+
import org.apache.logging.log4j.Logger;
import org.apache.geode.internal.cache.LocalRegion;
http://git-wip-us.apache.org/repos/asf/geode/blob/c3586a96/geode-core/src/test/java/org/apache/geode/test/dunit/cache/internal/JUnit4CacheTestCase.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/test/dunit/cache/internal/JUnit4CacheTestCase.java b/geode-core/src/test/java/org/apache/geode/test/dunit/cache/internal/JUnit4CacheTestCase.java
index 037d73c..a511995 100644
--- a/geode-core/src/test/java/org/apache/geode/test/dunit/cache/internal/JUnit4CacheTestCase.java
+++ b/geode-core/src/test/java/org/apache/geode/test/dunit/cache/internal/JUnit4CacheTestCase.java
@@ -245,6 +245,11 @@ public abstract class JUnit4CacheTestCase extends JUnit4DistributedTestCase
return getCache(false, factory);
}
+ public final Cache getCache(final Properties properties) {
+ getSystem(properties);
+ return getCache();
+ }
+
public final Cache getCache(final boolean client) {
return getCache(client, null);
}
http://git-wip-us.apache.org/repos/asf/geode/blob/c3586a96/geode-core/src/test/java/org/apache/geode/test/dunit/internal/JUnit4DistributedTestCase.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/test/dunit/internal/JUnit4DistributedTestCase.java b/geode-core/src/test/java/org/apache/geode/test/dunit/internal/JUnit4DistributedTestCase.java
index ebbb2fd..a7640f2 100644
--- a/geode-core/src/test/java/org/apache/geode/test/dunit/internal/JUnit4DistributedTestCase.java
+++ b/geode-core/src/test/java/org/apache/geode/test/dunit/internal/JUnit4DistributedTestCase.java
@@ -111,7 +111,7 @@ public abstract class JUnit4DistributedTestCase implements DistributedTestFixtur
}
@Rule
- public SerializableTestName testName = new SerializableTestName();
+ public SerializableTestName testNameForDistributedTestCase = new SerializableTestName();
@BeforeClass
public static final void initializeDistributedTestCase() {
@@ -122,7 +122,7 @@ public abstract class JUnit4DistributedTestCase implements DistributedTestFixtur
if (this.distributedTestFixture != this) {
return this.distributedTestFixture.getName();
}
- return this.testName.getMethodName();
+ return this.testNameForDistributedTestCase.getMethodName();
}
public final Class<? extends DistributedTestFixture> getTestClass() {
http://git-wip-us.apache.org/repos/asf/geode/blob/c3586a96/geode-core/src/test/java/org/apache/geode/test/dunit/rules/DistributedDisconnectRule.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/test/dunit/rules/DistributedDisconnectRule.java b/geode-core/src/test/java/org/apache/geode/test/dunit/rules/DistributedDisconnectRule.java
index ddf37c5..9107d4d 100755
--- a/geode-core/src/test/java/org/apache/geode/test/dunit/rules/DistributedDisconnectRule.java
+++ b/geode-core/src/test/java/org/apache/geode/test/dunit/rules/DistributedDisconnectRule.java
@@ -43,14 +43,14 @@ public class DistributedDisconnectRule extends DistributedExternalResource {
@Override
protected void before() throws Throwable {
if (this.disconnectBefore) {
- invoker().invokeEverywhere(serializableRunnable());
+ invoker().invokeInEveryVMAndController(serializableRunnable());
}
}
@Override
protected void after() {
if (this.disconnectAfter) {
- invoker().invokeEverywhere(serializableRunnable());
+ invoker().invokeInEveryVMAndController(serializableRunnable());
}
}
http://git-wip-us.apache.org/repos/asf/geode/blob/c3586a96/geode-core/src/test/java/org/apache/geode/test/dunit/rules/DistributedRestoreSystemProperties.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/test/dunit/rules/DistributedRestoreSystemProperties.java b/geode-core/src/test/java/org/apache/geode/test/dunit/rules/DistributedRestoreSystemProperties.java
index 221b52a..1f2134a 100755
--- a/geode-core/src/test/java/org/apache/geode/test/dunit/rules/DistributedRestoreSystemProperties.java
+++ b/geode-core/src/test/java/org/apache/geode/test/dunit/rules/DistributedRestoreSystemProperties.java
@@ -46,7 +46,7 @@ public class DistributedRestoreSystemProperties extends RestoreSystemProperties
@Override
protected void before() throws Throwable {
super.before();
- this.invoker.remoteInvokeInEveryVMAndLocator(new SerializableRunnable() {
+ this.invoker.invokeInEveryVMAndController(new SerializableRunnable() {
@Override
public void run() {
originalProperties = getProperties();
@@ -58,7 +58,7 @@ public class DistributedRestoreSystemProperties extends RestoreSystemProperties
@Override
protected void after() {
super.after();
- this.invoker.remoteInvokeInEveryVMAndLocator(new SerializableRunnable() {
+ this.invoker.invokeInEveryVMAndController(new SerializableRunnable() {
@Override
public void run() {
setProperties(originalProperties);
http://git-wip-us.apache.org/repos/asf/geode/blob/c3586a96/geode-core/src/test/java/org/apache/geode/test/dunit/rules/DistributedRule.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/test/dunit/rules/DistributedRule.java b/geode-core/src/test/java/org/apache/geode/test/dunit/rules/DistributedRule.java
new file mode 100644
index 0000000..5ab479b
--- /dev/null
+++ b/geode-core/src/test/java/org/apache/geode/test/dunit/rules/DistributedRule.java
@@ -0,0 +1,68 @@
+/*
+ * 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 java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+import org.junit.Rule;
+
+/**
+ * Annotates a field or method as a type of {@link Rule} that can be invoked
+ * across multiple VMs in a {@code DistributedTest}.
+ *
+ * If there are multiple annotated {@code DistributedRule}s on a class, they
+ * will be applied in order of fields first, then methods. Furthermore, if
+ * there are multiple fields (or methods) they will be applied in an order that
+ * depends on your JVM's implementation of the reflection API, which is
+ * undefined. Rules defined by fields will always be applied before Rules
+ * defined by methods. You can use a {@link org.junit.rules.RuleChain} or
+ * {@link org.apache.geode.test.junit.rules.RuleList} if you want to have
+ * control over the order in which the Rules are applied.
+ *
+ * <p>
+ * For example, here is a test class that makes a unique
+ * {@link org.junit.rules.TemporaryFolder} available to each DUnit VM:
+ * <pre>
+ * {@literal @}Category(DistributedTest.class)
+ * public class EachVMHasItsOwnTemporaryFolder {
+ *
+ * {@literal @}DistributedRule
+ * public TemporaryFolder folder = new TemporaryFolder();
+ *
+ * {@literal @}Rule
+ * public DistributedTestRule distributedTestRule = DistributedTestRule.builder().build();
+ *
+ * {@literal @}Test
+ * public void eachVMHasItsOwnTemporaryFolder() throws Exception {
+ * Host.getHost(0).getVM(0).invoke(() -> {
+ * File gemfireProps = folder.newFile({@literal "}gemfire.properties{@literal "});
+ * File diskDirs = folder.newFolder({@literal "}diskDirs{@literal "});
+ * ...
+ * }
+ * }
+ * }
+ * </pre>
+ *
+ * @see org.apache.geode.test.junit.rules.serializable.SerializableTestRule
+ */
+@Retention(RetentionPolicy.RUNTIME)
+@Target({ElementType.FIELD, ElementType.METHOD})
+public @interface DistributedRule {
+}
http://git-wip-us.apache.org/repos/asf/geode/blob/c3586a96/geode-core/src/test/java/org/apache/geode/test/dunit/rules/DistributedRunRules.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/test/dunit/rules/DistributedRunRules.java b/geode-core/src/test/java/org/apache/geode/test/dunit/rules/DistributedRunRules.java
new file mode 100644
index 0000000..7490acd
--- /dev/null
+++ b/geode-core/src/test/java/org/apache/geode/test/dunit/rules/DistributedRunRules.java
@@ -0,0 +1,76 @@
+/*
+ * 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 java.io.Serializable;
+
+import org.junit.rules.TestRule;
+import org.junit.runner.Description;
+import org.junit.runners.model.Statement;
+
+import org.apache.geode.test.dunit.Host;
+import org.apache.geode.test.dunit.SerializableRunnable;
+
+/**
+ * Runs Rules in specified DUnit VMs.
+ */
+public class DistributedRunRules extends Statement implements Serializable {
+ private final Statement statement;
+ private final WhichVMs whichVMs;
+
+ public DistributedRunRules(final Statement base, final Iterable<TestRule> rules, final Description description, final WhichVMs whichVMs) {
+ this.statement = applyAll(base, rules, description);
+ this.whichVMs = whichVMs;
+ }
+
+ @Override
+ public void evaluate() throws Throwable {
+ if (this.whichVMs.controllerVM()) {
+ this.statement.evaluate();
+ }
+ if (this.whichVMs.everyVM()) {
+ for (int i = 0; i < Host.getHost(0).getVMCount(); i++) {
+ Host.getHost(0).getVM(i).invoke(runnable());
+ }
+ }
+ if (this.whichVMs.locatorVM()) {
+ Host.getHost(0).getLocator().invoke(runnable());
+ }
+ }
+
+ private Statement applyAll(Statement result, final Iterable<TestRule> rules, final Description description) {
+ for (TestRule each : rules) {
+ result = each.apply(result, description);
+ }
+ return result;
+ }
+
+ private SerializableRunnable runnable() {
+ return new SerializableRunnable() {
+ @Override
+ public void run() {
+ try {
+ DistributedRunRules.this.statement.evaluate();
+ } catch (Error | RuntimeException e) {
+ throw e;
+ } catch (Throwable t) {
+ throw new RuntimeException(t);
+ }
+ }
+ };
+ }
+}
http://git-wip-us.apache.org/repos/asf/geode/blob/c3586a96/geode-core/src/test/java/org/apache/geode/test/dunit/rules/DistributedStatement.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/test/dunit/rules/DistributedStatement.java b/geode-core/src/test/java/org/apache/geode/test/dunit/rules/DistributedStatement.java
new file mode 100644
index 0000000..1c78d00
--- /dev/null
+++ b/geode-core/src/test/java/org/apache/geode/test/dunit/rules/DistributedStatement.java
@@ -0,0 +1,76 @@
+/*
+ * 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 java.io.Serializable;
+
+import org.junit.runners.model.Statement;
+
+import org.apache.geode.test.dunit.Host;
+import org.apache.geode.test.dunit.SerializableRunnable;
+import org.apache.geode.test.junit.rules.serializable.SerializableStatement;
+
+/**
+ * Invokes Statement in specified DUnit VMs.
+ */
+public class DistributedStatement extends SerializableStatement {
+ private final SerializableStatement next;
+ private final WhichVMs whichVMs;
+
+ /**
+ * Construct a new {@code DistributedStatement} statement.
+ * @param next the next {@code Statement} in the execution chain
+ * @param whichVMs specifies which VMs should invoke the statement
+ */
+ public DistributedStatement(final SerializableStatement next, final WhichVMs whichVMs) {
+ this.next = next;
+ this.whichVMs = whichVMs;
+ }
+
+ /**
+ * Invoke the {@link Statement} in the specified VMs.
+ */
+ @Override
+ public void evaluate() throws Throwable {
+ if (this.whichVMs.controllerVM()) {
+ this.next.evaluate();
+ }
+ if (this.whichVMs.everyVM()) {
+ for (int i = 0; i < Host.getHost(0).getVMCount(); i++) {
+ Host.getHost(0).getVM(i).invoke(runnable());
+ }
+ }
+ if (this.whichVMs.locatorVM()) {
+ Host.getHost(0).getLocator().invoke(runnable());
+ }
+ }
+
+ private SerializableRunnable runnable() {
+ return new SerializableRunnable() {
+ @Override
+ public void run() {
+ try {
+ next.evaluate();
+ } catch (Error | RuntimeException e) {
+ throw e;
+ } catch (Throwable t) {
+ throw new RuntimeException(t);
+ }
+ }
+ };
+ }
+}
http://git-wip-us.apache.org/repos/asf/geode/blob/c3586a96/geode-core/src/test/java/org/apache/geode/test/dunit/rules/DistributedTestRule.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/test/dunit/rules/DistributedTestRule.java b/geode-core/src/test/java/org/apache/geode/test/dunit/rules/DistributedTestRule.java
new file mode 100644
index 0000000..9516cb3
--- /dev/null
+++ b/geode-core/src/test/java/org/apache/geode/test/dunit/rules/DistributedTestRule.java
@@ -0,0 +1,192 @@
+/*
+ * 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 java.io.Serializable;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.junit.rules.MethodRule;
+import org.junit.rules.TestRule;
+import org.junit.runner.Description;
+import org.junit.runners.model.FrameworkMethod;
+import org.junit.runners.model.Statement;
+import org.junit.runners.model.TestClass;
+
+import org.apache.geode.test.dunit.standalone.DUnitLauncher;
+
+/**
+ * Launches the DUnit framework for a {@code DistributedTest}.
+ *
+ * <p>Enables use of {@link DistributedRule} annotations on any Rules.
+ *
+ * <pre>
+ * {@literal @}Category(DistributedTest.class)
+ * public class QueryDataDUnitTest {
+ *
+ * {@literal @}DistributedRule
+ * public UseJacksonForJsonPathRule useJacksonForJsonPathRule = new UseJacksonForJsonPathRule();
+ *
+ * {@literal @}Rule
+ * public DistributedTestRule distributedTestRule = DistributedTestRule.builder().build();
+ *
+ * ...
+ * }
+ * </pre>
+ * <p>Use the {@code Builder} to specify which {@code VM}s should invoke any
+ * {@code Rule} annotated with {@literal @}DistributedRule. By default,
+ * {@code controllerVM} is {@code true}, {@code everyVM} is {@code true} and
+ * {@code locatorVM} is {@code false}.
+ */
+public class DistributedTestRule implements MethodRule, Serializable {
+
+ public static Builder builder() {
+ return new Builder();
+ }
+
+ private TestClass testClass;
+
+ private final List<?> rules = new ArrayList<>(); // types are TestRule or MethodRule
+
+ private final RemoteInvoker invoker;
+
+ private final WhichVMs whichVMs;
+
+ // TODO: add ability to specify ordering of DistributedRules
+
+ protected DistributedTestRule(final Builder builder) {
+ this(new RemoteInvoker(), builder);
+ }
+
+ protected DistributedTestRule(final RemoteInvoker invoker, final Builder builder) {
+ this.invoker = invoker;
+
+ this.whichVMs = new WhichVMs();
+ if (builder.controllerVM) {
+ this.whichVMs.addControllerVM();
+ }
+ if (builder.everyVM) {
+ this.whichVMs.addEveryVM();
+ }
+ if (builder.locatorVM) {
+ this.whichVMs.addLocatorVM();
+ }
+ }
+
+ @Override
+ public Statement apply(final Statement base, final FrameworkMethod method, final Object target) {
+ this.testClass = new TestClass(target.getClass());
+ Statement statement = base;
+ statement = withRules(method, target, statement);
+ statement = withDUnit(method, target, statement);
+ return statement;
+ }
+
+ protected Statement withDUnit(final FrameworkMethod method, final Object target, final Statement statement) {
+ return new Statement() {
+ @Override
+ public void evaluate() throws Throwable {
+ setUpDUnit();
+ try {
+ statement.evaluate();
+ } finally {
+ tearDownDUnit();
+ }
+ }
+ };
+ }
+
+ protected void setUpDUnit() throws Exception {
+ DUnitLauncher.launchIfNeeded();
+ // TODO: customize based on fields
+ }
+
+ protected void tearDownDUnit() throws Exception {
+ }
+
+ protected Statement withRules(final FrameworkMethod method, final Object target, final Statement statement) {
+ List<TestRule> testRules = this.testRules(target);
+ Statement result = statement;
+// result = withMethodRules(method, testRules, target, result);
+ result = withTestRules(method, testRules, result);
+
+ return result;
+ }
+
+// protected Statement withMethodRules(final FrameworkMethod method, final List<TestRule> testRules, final Object target, final Statement result) {
+// Statement statement = result;
+// for (MethodRule rule : methodRules(target)) {
+// if (!testRules.contains(rule)) {
+// statement = new DistributedStatement(rule.apply((result, method, target), this.whichVMs);
+// }
+// }
+// return statement;
+// }
+
+ protected Statement withTestRules(final FrameworkMethod method, final List<TestRule> testRules, final Statement statement) {
+ Description description = Description.createTestDescription(this.testClass.getJavaClass(), method.getName(), method.getAnnotations());
+ return testRules.isEmpty() ? statement : new DistributedRunRules(statement, testRules, description, this.whichVMs);
+ }
+
+ protected List<MethodRule> methodRules(final Object target) {
+ List<MethodRule> rules = this.testClass.getAnnotatedMethodValues(target, DistributedRule.class, MethodRule.class);
+ rules.addAll(this.testClass.getAnnotatedFieldValues(target, DistributedRule.class, MethodRule.class));
+ return rules;
+ }
+
+ protected List<TestRule> testRules(final Object target) {
+ List<TestRule> result = this.testClass.getAnnotatedMethodValues(target, DistributedRule.class, TestRule.class);
+ result.addAll(this.testClass.getAnnotatedFieldValues(target, DistributedRule.class, TestRule.class));
+ return result;
+ }
+
+ /**
+ * Builds an instance of {@link DistributedTestRule}.
+ *
+ * <p>By default, {@code controllerVM} is {@code true}, {@code everyVM} is
+ * {@code true} and {@code locatorVM} is {@code false}.
+ */
+ public static class Builder {
+
+ private boolean everyVM = true;
+ private boolean locatorVM = false;
+ private boolean controllerVM = true;
+
+ protected Builder() {
+ }
+
+ public Builder everyVM(final boolean everyVM) {
+ this.everyVM = everyVM;
+ return this;
+ }
+
+ public Builder locatorVM(final boolean locatorVM) {
+ this.locatorVM = locatorVM;
+ return this;
+ }
+
+ public Builder controllerVM(final boolean locatorVM) {
+ this.locatorVM = locatorVM;
+ return this;
+ }
+
+ public DistributedTestRule build() {
+ return new DistributedTestRule(this);
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/geode/blob/c3586a96/geode-core/src/test/java/org/apache/geode/test/dunit/rules/DistributedUseJacksonForJsonPathRule.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/test/dunit/rules/DistributedUseJacksonForJsonPathRule.java b/geode-core/src/test/java/org/apache/geode/test/dunit/rules/DistributedUseJacksonForJsonPathRule.java
new file mode 100644
index 0000000..78841fc
--- /dev/null
+++ b/geode-core/src/test/java/org/apache/geode/test/dunit/rules/DistributedUseJacksonForJsonPathRule.java
@@ -0,0 +1,51 @@
+/*
+ * 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 org.apache.geode.test.junit.rules.UseJacksonForJsonPathRule;
+
+public class DistributedUseJacksonForJsonPathRule extends UseJacksonForJsonPathRule {
+
+ private static UseJacksonForJsonPathRule instance = new UseJacksonForJsonPathRule();
+
+ private final RemoteInvoker invoker;
+
+ public DistributedUseJacksonForJsonPathRule() {
+ this(new RemoteInvoker());
+ }
+
+ public DistributedUseJacksonForJsonPathRule(final RemoteInvoker invoker) {
+ this.invoker = invoker;
+ }
+
+ @Override
+ public void before() {
+ this.invoker.invokeInEveryVMAndController(DistributedUseJacksonForJsonPathRule::invokeBefore);
+ }
+
+ @Override
+ public void after() {
+ this.invoker.invokeInEveryVMAndController(DistributedUseJacksonForJsonPathRule::invokeAfter);
+ }
+
+ private static void invokeBefore() {
+ instance.before();
+ }
+ private static void invokeAfter() {
+ instance.after();
+ }
+}
http://git-wip-us.apache.org/repos/asf/geode/blob/c3586a96/geode-core/src/test/java/org/apache/geode/test/dunit/rules/DistributedWrapperRule.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/test/dunit/rules/DistributedWrapperRule.java b/geode-core/src/test/java/org/apache/geode/test/dunit/rules/DistributedWrapperRule.java
new file mode 100644
index 0000000..45311e1
--- /dev/null
+++ b/geode-core/src/test/java/org/apache/geode/test/dunit/rules/DistributedWrapperRule.java
@@ -0,0 +1,52 @@
+/*
+ * 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 org.junit.runner.Description;
+import org.junit.runners.model.Statement;
+
+import org.apache.geode.test.junit.rules.UseJacksonForJsonPathRule;
+import org.apache.geode.test.junit.rules.serializable.SerializableExternalResource;
+import org.apache.geode.test.junit.rules.serializable.SerializableStatement;
+import org.apache.geode.test.junit.rules.serializable.SerializableTestRule;
+
+public class DistributedWrapperRule implements SerializableTestRule {
+
+ private static SerializableTestRule instance;
+
+ private final RemoteInvoker invoker;
+ private final WhichVMs whichVMs;
+
+ public DistributedWrapperRule(final SerializableTestRule testRule) {
+ this(testRule, new WhichVMs().addControllerVM().addEveryVM());
+ }
+
+ public DistributedWrapperRule(final SerializableTestRule testRule, final WhichVMs whichVMs) {
+ this(new RemoteInvoker(), testRule, whichVMs);
+ }
+
+ public DistributedWrapperRule(final RemoteInvoker invoker, final SerializableTestRule testRule, final WhichVMs whichVMs) {
+ this.invoker = invoker;
+ instance = testRule;
+ this.whichVMs = whichVMs;
+ }
+
+ @Override
+ public Statement apply(Statement base, Description description){
+ return new DistributedStatement((SerializableStatement) base, whichVMs);
+ }
+}
http://git-wip-us.apache.org/repos/asf/geode/blob/c3586a96/geode-core/src/test/java/org/apache/geode/test/dunit/rules/RemoteInvoker.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/test/dunit/rules/RemoteInvoker.java b/geode-core/src/test/java/org/apache/geode/test/dunit/rules/RemoteInvoker.java
index 6398e45..866a0d5 100755
--- a/geode-core/src/test/java/org/apache/geode/test/dunit/rules/RemoteInvoker.java
+++ b/geode-core/src/test/java/org/apache/geode/test/dunit/rules/RemoteInvoker.java
@@ -18,7 +18,8 @@ import static org.apache.geode.test.dunit.Invoke.*;
import java.io.Serializable;
-import org.apache.geode.test.dunit.SerializableRunnable;
+import org.apache.geode.test.dunit.Invoke;
+import org.apache.geode.test.dunit.SerializableRunnableIF;
/**
* Provides remote invocation support to a {@code TestRule}. These methods will invoke a
@@ -28,18 +29,21 @@ class RemoteInvoker implements Serializable {
private static final long serialVersionUID = -1759722991299584649L;
- public void invokeEverywhere(final SerializableRunnable runnable) {
+ // controller VM
+ // dunit VMs
+ // locator VM
+
+ public void invokeInEveryVMAndController(final SerializableRunnableIF runnable) {
try {
runnable.run();
} catch (Exception e) {
throw new RuntimeException(e);
}
- invokeInEveryVM(runnable);
- invokeInLocator(runnable);
+ Invoke.invokeInEveryVM(runnable);
}
- public void remoteInvokeInEveryVMAndLocator(final SerializableRunnable runnable) {
- invokeInEveryVM(runnable);
+ public void invokeInEveryVMAndLocator(final SerializableRunnableIF runnable) {
+ Invoke.invokeInEveryVM(runnable);
invokeInLocator(runnable);
}
}
http://git-wip-us.apache.org/repos/asf/geode/blob/c3586a96/geode-core/src/test/java/org/apache/geode/test/dunit/rules/WhichVMs.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/test/dunit/rules/WhichVMs.java b/geode-core/src/test/java/org/apache/geode/test/dunit/rules/WhichVMs.java
new file mode 100644
index 0000000..4ee6020
--- /dev/null
+++ b/geode-core/src/test/java/org/apache/geode/test/dunit/rules/WhichVMs.java
@@ -0,0 +1,58 @@
+/*
+ * 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 java.io.Serializable;
+
+/**
+ * Specifies which DUnit VMs will invoke a Rule.
+ *
+ * TODO: add ability to specify specific VMs
+ *
+ * TODO: add ability to specify order
+ */
+public class WhichVMs implements Serializable{
+ private boolean controllerVM;
+ private boolean everyVM;
+ private boolean locatorVM;
+
+ public WhichVMs() {
+ }
+
+ public WhichVMs addControllerVM() {
+ this.controllerVM = true;
+ return this;
+ }
+ public WhichVMs addEveryVM() {
+ this.everyVM = true;
+ return this;
+ }
+ public WhichVMs addLocatorVM() {
+ this.locatorVM = true;
+ return this;
+ }
+
+ public boolean controllerVM() {
+ return this.controllerVM;
+ }
+ public boolean everyVM() {
+ return this.everyVM;
+ }
+ public boolean locatorVM() {
+ return this.locatorVM;
+ }
+}
http://git-wip-us.apache.org/repos/asf/geode/blob/c3586a96/geode-core/src/test/java/org/apache/geode/test/dunit/rules/tests/DistributedTestRuleTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/test/dunit/rules/tests/DistributedTestRuleTest.java b/geode-core/src/test/java/org/apache/geode/test/dunit/rules/tests/DistributedTestRuleTest.java
new file mode 100644
index 0000000..8352db2
--- /dev/null
+++ b/geode-core/src/test/java/org/apache/geode/test/dunit/rules/tests/DistributedTestRuleTest.java
@@ -0,0 +1,54 @@
+/*
+ * 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.tests;
+
+import java.io.Serializable;
+
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExternalResource;
+
+import org.apache.geode.test.dunit.rules.DistributedRule;
+import org.apache.geode.test.dunit.rules.DistributedTestRule;
+import org.apache.geode.test.junit.rules.serializable.SerializableExternalResource;
+
+public class DistributedTestRuleTest {
+
+ @DistributedRule
+ public SimpleRule simpleRule = new SimpleRule();
+
+ @Rule
+ public DistributedTestRule distributedTestRule = DistributedTestRule.builder().build();
+
+ @Test
+ public void test() throws Exception {
+ System.out.println("KIRK:test");
+ }
+
+ private static class SimpleRule extends SerializableExternalResource {
+ @Override
+ protected void before() throws Throwable {
+ System.out.println("KIRK:before");
+ }
+
+ @Override
+ protected void after() {
+ System.out.println("KIRK:after");
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/geode/blob/c3586a96/geode-core/src/test/java/org/apache/geode/test/dunit/standalone/DUnitLauncher.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/test/dunit/standalone/DUnitLauncher.java b/geode-core/src/test/java/org/apache/geode/test/dunit/standalone/DUnitLauncher.java
index 5a80a64..5c0bbdb 100644
--- a/geode-core/src/test/java/org/apache/geode/test/dunit/standalone/DUnitLauncher.java
+++ b/geode-core/src/test/java/org/apache/geode/test/dunit/standalone/DUnitLauncher.java
@@ -14,41 +14,51 @@
*/
package org.apache.geode.test.dunit.standalone;
-import batterytest.greplogs.ExpectedStrings;
-import batterytest.greplogs.LogConsumer;
-import org.apache.geode.distributed.Locator;
-import org.apache.geode.distributed.internal.DistributionConfig;
-import org.apache.geode.distributed.internal.InternalLocator;
-import org.apache.geode.distributed.internal.membership.gms.membership.GMSJoinLeave;
-import org.apache.geode.internal.AvailablePortHelper;
-import org.apache.geode.internal.logging.LogService;
-import org.apache.geode.test.dunit.DUnitEnv;
-import org.apache.geode.test.dunit.Host;
-import org.apache.geode.test.dunit.SerializableCallable;
-import org.apache.geode.test.dunit.VM;
-import hydra.MethExecutorResult;
-import org.apache.logging.log4j.Level;
-import org.apache.logging.log4j.LogManager;
-import org.apache.logging.log4j.core.LoggerContext;
-import org.apache.logging.log4j.core.appender.FileAppender;
-import org.apache.logging.log4j.core.config.LoggerConfig;
-import org.apache.logging.log4j.core.layout.PatternLayout;
-import org.junit.Assert;
+import static org.apache.geode.distributed.ConfigurationProperties.*;
-import java.io.*;
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.FileReader;
+import java.io.IOException;
import java.lang.reflect.Method;
import java.net.InetAddress;
import java.net.URISyntaxException;
import java.nio.channels.FileChannel;
import java.nio.charset.Charset;
-import java.rmi.*;
+import java.rmi.AccessException;
+import java.rmi.AlreadyBoundException;
+import java.rmi.NotBoundException;
+import java.rmi.Remote;
+import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import java.rmi.server.UnicastRemoteObject;
import java.util.List;
import java.util.Properties;
-import static org.apache.geode.distributed.ConfigurationProperties.*;
+import batterytest.greplogs.ExpectedStrings;
+import batterytest.greplogs.LogConsumer;
+import hydra.MethExecutorResult;
+import org.apache.logging.log4j.Level;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.core.LoggerContext;
+import org.apache.logging.log4j.core.appender.FileAppender;
+import org.apache.logging.log4j.core.config.LoggerConfig;
+import org.apache.logging.log4j.core.layout.PatternLayout;
+import org.junit.Assert;
+
+import org.apache.geode.distributed.Locator;
+import org.apache.geode.distributed.internal.DistributionConfig;
+import org.apache.geode.distributed.internal.InternalLocator;
+import org.apache.geode.distributed.internal.membership.gms.membership.GMSJoinLeave;
+import org.apache.geode.internal.AvailablePortHelper;
+import org.apache.geode.internal.logging.LogService;
+import org.apache.geode.test.dunit.DUnitEnv;
+import org.apache.geode.test.dunit.Host;
+import org.apache.geode.test.dunit.SerializableCallable;
+import org.apache.geode.test.dunit.VM;
/**
* A class to build a fake test configuration and launch some DUnit VMS.
@@ -73,6 +83,8 @@ public class DUnitLauncher {
private static final int LOCATOR_VM_NUM = -2;
static final long STARTUP_TIMEOUT = 120 * 1000;
+ private static final String STARTUP_TIMEOUT_MESSAGE = "VMs did not start up within " + (STARTUP_TIMEOUT/1000) + " seconds";
+
private static final String SUSPECT_FILENAME = "dunit_suspect.log";
private static File DUNIT_SUSPECT_FILE;
@@ -189,9 +201,9 @@ public class DUnitLauncher {
// Create a VM for the locator
processManager.launchVM(LOCATOR_VM_NUM);
- // wait for the VM to start up
- if (!processManager.waitForVMs(STARTUP_TIMEOUT)) {
- throw new RuntimeException("VMs did not start up with 30 seconds");
+ //wait for the VM to start up
+ if(!processManager.waitForVMs(STARTUP_TIMEOUT)) {
+ throw new RuntimeException("VMs did not start up within 30 seconds");
}
locatorPort = startLocator(registry);
@@ -204,9 +216,9 @@ public class DUnitLauncher {
processManager.launchVM(i);
}
- // wait for the VMS to start up
- if (!processManager.waitForVMs(STARTUP_TIMEOUT)) {
- throw new RuntimeException("VMs did not start up with 30 seconds");
+ //wait for the VMS to start up
+ if(!processManager.waitForVMs(STARTUP_TIMEOUT)) {
+ throw new RuntimeException("VMs did not start up within 30 seconds");
}
// populate the Host class with our stubs. The tests use this host class
http://git-wip-us.apache.org/repos/asf/geode/blob/c3586a96/geode-junit/build.gradle
----------------------------------------------------------------------
diff --git a/geode-junit/build.gradle b/geode-junit/build.gradle
index f7e5e46..e47095f 100755
--- a/geode-junit/build.gradle
+++ b/geode-junit/build.gradle
@@ -16,6 +16,7 @@
*/
dependencies {
+ compile 'com.jayway.jsonpath:json-path:' + project.'json-path.version'
testCompile 'commons-lang:commons-lang:' + project.'commons-lang.version'
testCompile 'com.google.guava:guava:' + project.'guava.version'
testCompile 'org.assertj:assertj-core:' + project.'assertj-core.version'
http://git-wip-us.apache.org/repos/asf/geode/blob/c3586a96/geode-junit/src/main/java/org/apache/geode/test/junit/rules/UseJacksonForJsonPathRule.java
----------------------------------------------------------------------
diff --git a/geode-junit/src/main/java/org/apache/geode/test/junit/rules/UseJacksonForJsonPathRule.java b/geode-junit/src/main/java/org/apache/geode/test/junit/rules/UseJacksonForJsonPathRule.java
new file mode 100644
index 0000000..03d5a60
--- /dev/null
+++ b/geode-junit/src/main/java/org/apache/geode/test/junit/rules/UseJacksonForJsonPathRule.java
@@ -0,0 +1,128 @@
+/*
+ * 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.junit.rules;
+
+import java.util.EnumSet;
+import java.util.Set;
+
+import com.jayway.jsonpath.Configuration;
+import com.jayway.jsonpath.Configuration.Defaults;
+import com.jayway.jsonpath.Option;
+import com.jayway.jsonpath.spi.json.JacksonJsonProvider;
+import com.jayway.jsonpath.spi.json.JsonProvider;
+import com.jayway.jsonpath.spi.mapper.JacksonMappingProvider;
+import com.jayway.jsonpath.spi.mapper.MappingProvider;
+
+import org.apache.geode.test.junit.rules.serializable.SerializableExternalResource;
+
+/**
+ * JUnit Rule that configures json-path to use the {@code JacksonJsonProvider}
+ *
+ * <p>UseJacksonForJsonPathRule can be used in tests that need to use json-path-assert:
+ * <pre>
+ * {@literal @}ClassRule
+ * public static UseJacksonForJsonPathRule useJacksonForJsonPathRule = new UseJacksonForJsonPathRule();
+ *
+ * {@literal @}Test
+ * public void hasAssertionsUsingJsonPathMatchers() {
+ * ...
+ * assertThat(json, isJson());
+ * assertThat(json, hasJsonPath("$.result"));
+ * }
+ * </pre>
+ */
+@SuppressWarnings({ "serial", "unused" })
+public class UseJacksonForJsonPathRule extends SerializableExternalResource {
+
+ private boolean hadDefaults;
+ private JsonProvider jsonProvider;
+ private MappingProvider mappingProvider;
+ private Set<Option> options;
+
+ /**
+ * Override to set up your specific external resource.
+ */
+ @Override
+ public void before() {
+ saveDefaults();
+ Configuration.setDefaults(new Defaults() {
+
+ private final JsonProvider jsonProvider = new JacksonJsonProvider();
+ private final MappingProvider mappingProvider = new JacksonMappingProvider();
+
+ @Override
+ public JsonProvider jsonProvider() {
+ return jsonProvider;
+ }
+
+ @Override
+ public MappingProvider mappingProvider() {
+ return mappingProvider;
+ }
+
+ @Override
+ public Set<Option> options() {
+ return EnumSet.noneOf(Option.class);
+ }
+
+ });
+ }
+
+ /**
+ * Override to tear down your specific external resource.
+ */
+ @Override
+ public void after() {
+ restoreDefaults();
+ }
+
+ private void saveDefaults() {
+ try {
+ Configuration defaultConfiguration = Configuration.defaultConfiguration();
+ this.jsonProvider = defaultConfiguration.jsonProvider();
+ this.mappingProvider = defaultConfiguration.mappingProvider();
+ this.options = defaultConfiguration.getOptions();
+ this.hadDefaults = true;
+ } catch (NoClassDefFoundError ignore) {
+ this.hadDefaults = false;
+ }
+ }
+
+ private void restoreDefaults() {
+ if (!this.hadDefaults) {
+ return;
+ }
+ Configuration.setDefaults(new Defaults() {
+
+ @Override
+ public JsonProvider jsonProvider() {
+ return jsonProvider;
+ }
+
+ @Override
+ public MappingProvider mappingProvider() {
+ return mappingProvider;
+ }
+
+ @Override
+ public Set<Option> options() {
+ return options;
+ }
+
+ });
+ }
+}
http://git-wip-us.apache.org/repos/asf/geode/blob/c3586a96/geode-junit/src/main/java/org/apache/geode/test/junit/rules/serializable/SerializableExternalResource.java
----------------------------------------------------------------------
diff --git a/geode-junit/src/main/java/org/apache/geode/test/junit/rules/serializable/SerializableExternalResource.java b/geode-junit/src/main/java/org/apache/geode/test/junit/rules/serializable/SerializableExternalResource.java
index c76ed19..75f4575 100755
--- a/geode-junit/src/main/java/org/apache/geode/test/junit/rules/serializable/SerializableExternalResource.java
+++ b/geode-junit/src/main/java/org/apache/geode/test/junit/rules/serializable/SerializableExternalResource.java
@@ -14,11 +14,32 @@
*/
package org.apache.geode.test.junit.rules.serializable;
+import java.io.Serializable;
+
import org.junit.rules.ExternalResource;
+import org.junit.runner.Description;
+import org.junit.runners.model.Statement;
/**
* Serializable subclass of {@link org.junit.rules.ExternalResource ExternalResource}.
*/
-public abstract class SerializableExternalResource extends ExternalResource
- implements SerializableTestRule {
+public abstract class SerializableExternalResource extends ExternalResource implements SerializableTestRule {
+
+ public Statement apply(Statement base, Description description) {
+ return statement(base);
+ }
+
+ private Statement statement(final Statement base) {
+ return new SerializableStatement() {
+ @Override
+ public void evaluate() throws Throwable {
+ before();
+ try {
+ base.evaluate();
+ } finally {
+ after();
+ }
+ }
+ };
+ }
}
http://git-wip-us.apache.org/repos/asf/geode/blob/c3586a96/geode-junit/src/main/java/org/apache/geode/test/junit/rules/serializable/SerializableStatement.java
----------------------------------------------------------------------
diff --git a/geode-junit/src/main/java/org/apache/geode/test/junit/rules/serializable/SerializableStatement.java b/geode-junit/src/main/java/org/apache/geode/test/junit/rules/serializable/SerializableStatement.java
new file mode 100644
index 0000000..3f07421
--- /dev/null
+++ b/geode-junit/src/main/java/org/apache/geode/test/junit/rules/serializable/SerializableStatement.java
@@ -0,0 +1,27 @@
+/*
+ * 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.junit.rules.serializable;
+
+import java.io.Serializable;
+
+import org.junit.runners.model.Statement;
+
+/**
+ * Serializable subclass of {@link Statement}.
+ */
+public abstract class SerializableStatement extends Statement implements Serializable {
+}
http://git-wip-us.apache.org/repos/asf/geode/blob/c3586a96/geode-lucene/src/test/java/org/apache/geode/cache/lucene/internal/management/LuceneManagementDUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-lucene/src/test/java/org/apache/geode/cache/lucene/internal/management/LuceneManagementDUnitTest.java b/geode-lucene/src/test/java/org/apache/geode/cache/lucene/internal/management/LuceneManagementDUnitTest.java
index 634ea2f..27582a7 100644
--- a/geode-lucene/src/test/java/org/apache/geode/cache/lucene/internal/management/LuceneManagementDUnitTest.java
+++ b/geode-lucene/src/test/java/org/apache/geode/cache/lucene/internal/management/LuceneManagementDUnitTest.java
@@ -143,13 +143,12 @@ public class LuceneManagementDUnitTest extends ManagementTestBase {
}
}
- private static void verifyMBean() {
+ private void verifyMBean() {
getMBean();
}
- private static LuceneServiceMXBean getMBean() {
- ObjectName objectName =
- MBeanJMXAdapter.getCacheServiceMBeanName(ds.getDistributedMember(), "LuceneService");
+ private LuceneServiceMXBean getMBean() {
+ ObjectName objectName = MBeanJMXAdapter.getCacheServiceMBeanName(getSystem().getDistributedMember(), "LuceneService");
assertNotNull(getManagementService().getMBeanInstance(objectName, LuceneServiceMXBean.class));
return getManagementService().getMBeanInstance(objectName, LuceneServiceMXBean.class);
}
@@ -178,15 +177,14 @@ public class LuceneManagementDUnitTest extends ManagementTestBase {
createPartitionRegion(vm, regionName);
}
- private static void createIndexes(String regionName, int numIndexes) {
- LuceneService luceneService = LuceneServiceProvider.get(cache);
- for (int i = 0; i < numIndexes; i++) {
- luceneService.createIndex(INDEX_NAME + "_" + i, regionName, "field" + i);
+ private void createIndexes(String regionName, int numIndexes) {
+ LuceneService luceneService = LuceneServiceProvider.get(getCache());
+ for (int i=0; i<numIndexes; i++) {
+ luceneService.createIndex(INDEX_NAME+"_"+i, regionName, "field"+i);
}
}
- private static void verifyAllMBeanIndexMetrics(String regionName, int numRegionIndexes,
- int numTotalIndexes) {
+ private void verifyAllMBeanIndexMetrics(String regionName, int numRegionIndexes, int numTotalIndexes) {
LuceneServiceMXBean mbean = getMBean();
verifyMBeanIndexMetrics(mbean, regionName, numRegionIndexes, numTotalIndexes);
}
@@ -210,20 +208,18 @@ public class LuceneManagementDUnitTest extends ManagementTestBase {
}
}
- private static void putEntries(String regionName, int numEntries) {
- for (int i = 0; i < numEntries; i++) {
- Region region = cache.getRegion(regionName);
+ private void putEntries(String regionName, int numEntries) {
+ for (int i=0; i<numEntries; i++) {
+ Region region = getCache().getRegion(regionName);
String key = String.valueOf(i);
Object value = new TestObject(key);
region.put(key, value);
}
}
- private static void queryEntries(String regionName, String indexName)
- throws LuceneQueryException {
- LuceneService service = LuceneServiceProvider.get(cache);
- LuceneQuery query =
- service.createLuceneQueryFactory().create(indexName, regionName, "field0:0", null);
+ private void queryEntries(String regionName, String indexName) throws LuceneQueryException {
+ LuceneService service = LuceneServiceProvider.get(getCache());
+ LuceneQuery query = service.createLuceneQueryFactory().create(indexName, regionName, "field0:0", null);
query.findValues();
}
http://git-wip-us.apache.org/repos/asf/geode/blob/c3586a96/gradle/dependency-versions.properties
----------------------------------------------------------------------
diff --git a/gradle/dependency-versions.properties b/gradle/dependency-versions.properties
index 828b088..05d7124 100644
--- a/gradle/dependency-versions.properties
+++ b/gradle/dependency-versions.properties
@@ -68,7 +68,8 @@ jline.version = 2.12
jmock.version = 2.8.2
jna.version = 4.0.0
jopt-simple.version = 5.0.1
-json-path.version = 1.2.0
+json-path.version = 2.2.0
+json-path-assert.version = 2.2.0
json4s.version = 3.2.4
jsr305.version = 3.0.1
junit.version = 4.12