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/03/11 22:08:43 UTC
[1/2] incubator-geode git commit: Fix test method name bug that
caused hang in QueryIndexUsingXMLDUnitTest.
Repository: incubator-geode
Updated Branches:
refs/heads/feature/GEODE-1050 3543e224c -> 2fd9cc687
Fix test method name bug that caused hang in QueryIndexUsingXMLDUnitTest.
Avoid creating new cache in QueryIndexUsingXMLDUnitTest tear down.
Project: http://git-wip-us.apache.org/repos/asf/incubator-geode/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-geode/commit/e7c38749
Tree: http://git-wip-us.apache.org/repos/asf/incubator-geode/tree/e7c38749
Diff: http://git-wip-us.apache.org/repos/asf/incubator-geode/diff/e7c38749
Branch: refs/heads/feature/GEODE-1050
Commit: e7c3874997eb21011ee7ea64557cf50157a64941
Parents: 3543e22
Author: Kirk Lund <kl...@apache.org>
Authored: Fri Mar 11 12:38:38 2016 -0800
Committer: Kirk Lund <kl...@apache.org>
Committed: Fri Mar 11 12:38:38 2016 -0800
----------------------------------------------------------------------
.../dunit/QueryIndexUsingXMLDUnitTest.java | 32 +--
.../gemstone/gemfire/cache30/CacheTestCase.java | 34 +---
.../dunit/cache/internal/CacheTestFixture.java | 1 -
.../cache/internal/JUnit4CacheTestCase.java | 13 +-
.../dunit/internal/DistributedTestFixture.java | 7 +-
.../internal/JUnit3DistributedTestCase.java | 15 +-
.../internal/JUnit4DistributedTestCase.java | 7 +
.../internal/tests/JUnit3BasicDUnitTest.java | 167 ++++++++++++++++
.../JUnit3GetDefaultDiskStoreNameDUnitTest.java | 66 ++++++
.../tests/JUnit3GetTestMethodNameDUnitTest.java | 53 +++++
.../dunit/internal/tests/JUnit3VMDUnitTest.java | 192 ++++++++++++++++++
.../internal/tests/JUnit4BasicDUnitTest.java | 176 ++++++++++++++++
.../JUnit4GetDefaultDiskStoreNameDUnitTest.java | 65 ++++++
.../tests/JUnit4GetTestMethodNameDUnitTest.java | 52 +++++
.../dunit/internal/tests/JUnit4VMDUnitTest.java | 200 +++++++++++++++++++
.../test/dunit/tests/BasicDUnitTest.java | 125 ++++++------
.../tests/GetDefaultDiskStoreNameDUnitTest.java | 12 +-
.../dunit/tests/GetTestMethodNameDUnitTest.java | 8 +-
.../gemfire/test/dunit/tests/VMDUnitTest.java | 192 +++++++++---------
19 files changed, 1166 insertions(+), 251 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/e7c38749/geode-core/src/test/java/com/gemstone/gemfire/cache/query/dunit/QueryIndexUsingXMLDUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/cache/query/dunit/QueryIndexUsingXMLDUnitTest.java b/geode-core/src/test/java/com/gemstone/gemfire/cache/query/dunit/QueryIndexUsingXMLDUnitTest.java
index 0731ae2..c4d5944 100644
--- a/geode-core/src/test/java/com/gemstone/gemfire/cache/query/dunit/QueryIndexUsingXMLDUnitTest.java
+++ b/geode-core/src/test/java/com/gemstone/gemfire/cache/query/dunit/QueryIndexUsingXMLDUnitTest.java
@@ -134,46 +134,16 @@ public class QueryIndexUsingXMLDUnitTest extends CacheTestCase {
}
@Override
- public final void preSetUp() throws Exception {
- System.out.println("KIRK:preSetUp");
- }
-
- @Override
public final void postSetUp() throws Exception {
//Workaround for #52008
IgnoredException.addIgnoredException("Failed to create index");
}
@Override
- public final void preTearDownCacheTestCase() throws Exception {
- System.out.println("KIRK:preTearDownCacheTestCase");
- }
-
- @Override
public final void postTearDownCacheTestCase() throws Exception {
- resetTestHook();
Invoke.invokeInEveryVM(resetTestHook());
-
- disconnectAllFromDS();
-
+ disconnectFromDS();
FileUtil.delete(new File(GemFireCacheImpl.DEFAULT_DS_NAME).getAbsoluteFile());
- Invoke.invokeInEveryVM(()->FileUtil.delete(new File(GemFireCacheImpl.DEFAULT_DS_NAME).getAbsoluteFile()));
-
-// // Get the disk store name.
-// GemFireCacheImpl cache = (GemFireCacheImpl)getCache(); // TODO: don't create a new Cache just to get the diskStoreName
-// String diskStoreName = cache.getDefaultDiskStoreName();
-//
-// assertEquals(GemFireCacheImpl.DEFAULT_DS_NAME, diskStoreName);
-//
-// //reset TestHook
-// Invoke.invokeInEveryVM(resetTestHook());
-// // close the cache.
-// closeCache();
-// disconnectFromDS();
-//
-// // remove the disk store.
-// File diskDir = new File(diskStoreName).getAbsoluteFile();
-// com.gemstone.gemfire.internal.FileUtil.delete(diskDir);
}
/**
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/e7c38749/geode-core/src/test/java/com/gemstone/gemfire/cache30/CacheTestCase.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/cache30/CacheTestCase.java b/geode-core/src/test/java/com/gemstone/gemfire/cache30/CacheTestCase.java
index 95a861b..71bc7b8 100644
--- a/geode-core/src/test/java/com/gemstone/gemfire/cache30/CacheTestCase.java
+++ b/geode-core/src/test/java/com/gemstone/gemfire/cache30/CacheTestCase.java
@@ -21,15 +21,9 @@ import java.io.FileWriter;
import java.io.FilenameFilter;
import java.io.IOException;
import java.io.PrintWriter;
-import java.util.Iterator;
import java.util.Map;
import java.util.Properties;
-import com.gemstone.gemfire.test.dunit.cache.internal.CacheTestFixture;
-import org.apache.logging.log4j.Logger;
-
-import com.gemstone.gemfire.InternalGemFireError;
-import com.gemstone.gemfire.SystemFailure;
import com.gemstone.gemfire.cache.AttributesFactory;
import com.gemstone.gemfire.cache.Cache;
import com.gemstone.gemfire.cache.CacheException;
@@ -45,26 +39,23 @@ import com.gemstone.gemfire.cache.client.ClientCache;
import com.gemstone.gemfire.cache.client.ClientCacheFactory;
import com.gemstone.gemfire.cache.client.PoolManager;
import com.gemstone.gemfire.distributed.internal.DistributionMessageObserver;
-import com.gemstone.gemfire.distributed.internal.InternalDistributedSystem;
import com.gemstone.gemfire.internal.FileUtil;
import com.gemstone.gemfire.internal.cache.GemFireCacheImpl;
-import com.gemstone.gemfire.internal.cache.HARegion;
import com.gemstone.gemfire.internal.cache.InternalRegionArguments;
import com.gemstone.gemfire.internal.cache.LocalRegion;
-import com.gemstone.gemfire.internal.cache.PartitionedRegion;
import com.gemstone.gemfire.internal.cache.xmlcache.CacheCreation;
import com.gemstone.gemfire.internal.cache.xmlcache.CacheXmlGenerator;
import com.gemstone.gemfire.internal.logging.LogService;
import com.gemstone.gemfire.test.dunit.Assert;
-import com.gemstone.gemfire.test.dunit.DistributedTestCase;
-import com.gemstone.gemfire.test.dunit.Host;
import com.gemstone.gemfire.test.dunit.IgnoredException;
import com.gemstone.gemfire.test.dunit.Invoke;
import com.gemstone.gemfire.test.dunit.LogWriterUtils;
import com.gemstone.gemfire.test.dunit.VM;
import com.gemstone.gemfire.test.dunit.Wait;
import com.gemstone.gemfire.test.dunit.WaitCriterion;
+import com.gemstone.gemfire.test.dunit.cache.internal.CacheTestFixture;
import com.gemstone.gemfire.test.dunit.internal.JUnit3DistributedTestCase;
+import org.apache.logging.log4j.Logger;
/**
* The abstract superclass of tests that require the creation of a
@@ -73,7 +64,7 @@ import com.gemstone.gemfire.test.dunit.internal.JUnit3DistributedTestCase;
* @author David Whitlock
* @since 3.0
*/
-public abstract class CacheTestCase extends DistributedTestCase implements CacheTestFixture {
+public abstract class CacheTestCase extends JUnit3DistributedTestCase implements CacheTestFixture {
private static final Logger logger = LogService.getLogger();
/**
@@ -352,25 +343,20 @@ public abstract class CacheTestCase extends DistributedTestCase implements Cache
/** Closed the cache in all VMs. */
protected final void closeAllCache() {
closeCache();
- Invoke.invokeInEveryVM(CacheTestCase.class, "closeCache");
+ Invoke.invokeInEveryVM(()->closeCache());
}
@Override
public final void preTearDown() throws Exception {
preTearDownCacheTestCase();
-
+ tearDownCacheTestCase();
+ postTearDownCacheTestCase();
+ }
+
+ private final void tearDownCacheTestCase() throws Exception {
// locally destroy all root regions and close the cache
remoteTearDown();
- // Now invoke it in every VM
- for (int h = 0; h < Host.getHostCount(); h++) {
- Host host = Host.getHost(h);
- for (int v = 0; v < host.getVMCount(); v++) {
- VM vm = host.getVM(v);
- vm.invoke(()->remoteTearDown());
- }
- }
-
- postTearDownCacheTestCase();
+ Invoke.invokeInEveryVM(()->remoteTearDown());
}
public void preTearDownCacheTestCase() throws Exception {
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/e7c38749/geode-core/src/test/java/com/gemstone/gemfire/test/dunit/cache/internal/CacheTestFixture.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/test/dunit/cache/internal/CacheTestFixture.java b/geode-core/src/test/java/com/gemstone/gemfire/test/dunit/cache/internal/CacheTestFixture.java
index 09ee10e..f0f64d4 100644
--- a/geode-core/src/test/java/com/gemstone/gemfire/test/dunit/cache/internal/CacheTestFixture.java
+++ b/geode-core/src/test/java/com/gemstone/gemfire/test/dunit/cache/internal/CacheTestFixture.java
@@ -16,7 +16,6 @@
*/
package com.gemstone.gemfire.test.dunit.cache.internal;
-import com.gemstone.gemfire.cache30.CacheSerializableRunnable;
import com.gemstone.gemfire.test.dunit.internal.DistributedTestFixture;
/**
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/e7c38749/geode-core/src/test/java/com/gemstone/gemfire/test/dunit/cache/internal/JUnit4CacheTestCase.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/test/dunit/cache/internal/JUnit4CacheTestCase.java b/geode-core/src/test/java/com/gemstone/gemfire/test/dunit/cache/internal/JUnit4CacheTestCase.java
index a6312ed..8919aa6 100644
--- a/geode-core/src/test/java/com/gemstone/gemfire/test/dunit/cache/internal/JUnit4CacheTestCase.java
+++ b/geode-core/src/test/java/com/gemstone/gemfire/test/dunit/cache/internal/JUnit4CacheTestCase.java
@@ -40,8 +40,6 @@ import com.gemstone.gemfire.cache.client.ClientCacheFactory;
import com.gemstone.gemfire.cache.client.PoolManager;
import com.gemstone.gemfire.cache30.CacheSerializableRunnable;
import com.gemstone.gemfire.distributed.internal.DistributionMessageObserver;
-import com.gemstone.gemfire.distributed.internal.InternalDistributedSystem;
-import com.gemstone.gemfire.distributed.internal.SerialAckedMessage;
import com.gemstone.gemfire.internal.FileUtil;
import com.gemstone.gemfire.internal.cache.GemFireCacheImpl;
import com.gemstone.gemfire.internal.cache.InternalRegionArguments;
@@ -50,7 +48,6 @@ import com.gemstone.gemfire.internal.cache.xmlcache.CacheCreation;
import com.gemstone.gemfire.internal.cache.xmlcache.CacheXmlGenerator;
import com.gemstone.gemfire.internal.logging.LogService;
import com.gemstone.gemfire.test.dunit.Assert;
-import com.gemstone.gemfire.test.dunit.Host;
import com.gemstone.gemfire.test.dunit.IgnoredException;
import com.gemstone.gemfire.test.dunit.Invoke;
import com.gemstone.gemfire.test.dunit.LogWriterUtils;
@@ -376,16 +373,8 @@ public class JUnit4CacheTestCase extends JUnit4DistributedTestCase implements Ca
}
public final void tearDownCacheTestCase() { // TODO: make private
- // locally destroy all root regions and close the cache
remoteTearDown();
- // Now invoke it in every VM
- for (int h = 0; h < Host.getHostCount(); h++) { // TODO: use Invoke
- Host host = Host.getHost(h);
- for (int v = 0; v < host.getVMCount(); v++) {
- VM vm = host.getVM(v);
- vm.invoke(()->remoteTearDown());
- }
- }
+ Invoke.invokeInEveryVM(()->remoteTearDown());
}
@Override
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/e7c38749/geode-core/src/test/java/com/gemstone/gemfire/test/dunit/internal/DistributedTestFixture.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/test/dunit/internal/DistributedTestFixture.java b/geode-core/src/test/java/com/gemstone/gemfire/test/dunit/internal/DistributedTestFixture.java
index f752c01..34eadf7 100755
--- a/geode-core/src/test/java/com/gemstone/gemfire/test/dunit/internal/DistributedTestFixture.java
+++ b/geode-core/src/test/java/com/gemstone/gemfire/test/dunit/internal/DistributedTestFixture.java
@@ -20,8 +20,6 @@ package com.gemstone.gemfire.test.dunit.internal;
import java.util.Properties;
-import com.gemstone.gemfire.distributed.internal.InternalDistributedSystem;
-
/**
* Defines the {@code DistributedTestCase} methods that can be overridden by its subclasses.
*/
@@ -63,4 +61,9 @@ public interface DistributedTestFixture {
*/
public Properties getDistributedSystemProperties();
+ /**
+ * Returns the {@code name} of the test method being executed.
+ */
+ public String getName();
+
}
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/e7c38749/geode-core/src/test/java/com/gemstone/gemfire/test/dunit/internal/JUnit3DistributedTestCase.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/test/dunit/internal/JUnit3DistributedTestCase.java b/geode-core/src/test/java/com/gemstone/gemfire/test/dunit/internal/JUnit3DistributedTestCase.java
index ed514a3..92d48ce 100755
--- a/geode-core/src/test/java/com/gemstone/gemfire/test/dunit/internal/JUnit3DistributedTestCase.java
+++ b/geode-core/src/test/java/com/gemstone/gemfire/test/dunit/internal/JUnit3DistributedTestCase.java
@@ -17,18 +17,11 @@
package com.gemstone.gemfire.test.dunit.internal;
import java.io.Serializable;
-import java.text.DecimalFormat;
-import java.util.Iterator;
-import java.util.LinkedHashSet;
import java.util.Properties;
-import java.util.Set;
import com.gemstone.gemfire.cache.Cache;
-import com.gemstone.gemfire.cache.Region;
import com.gemstone.gemfire.distributed.DistributedSystem;
import com.gemstone.gemfire.distributed.internal.InternalDistributedSystem;
-import com.gemstone.gemfire.internal.cache.HARegion;
-import com.gemstone.gemfire.internal.cache.PartitionedRegion;
import com.gemstone.gemfire.internal.logging.LogService;
import com.gemstone.gemfire.test.junit.categories.DistributedTest;
import junit.framework.TestCase;
@@ -41,7 +34,7 @@ import org.junit.experimental.categories.Category;
* tests/hydra/JUnitTestTask is the main DUnit driver. It supports two
* additional public static methods if they are defined in the test case:
*
- * public static void caseSetUp() -- comparable to JUnit's BeforeClass annotation
+ * public static void caseSetUp() -- comparable to JUnit's BeforeClass annotation // TODO: are these invoked by standalone dunit?
*
* public static void caseTearDown() -- comparable to JUnit's AfterClass annotation
*/
@@ -53,8 +46,8 @@ public abstract class JUnit3DistributedTestCase extends TestCase implements Dist
private final JUnit4DistributedTestCase delegate = new JUnit4DistributedTestCase(this);
/**
- * Creates a new <code>JUnit3DistributedTestCase</code> test with the
- * given name.
+ * Constructs a new distributed test. All JUnit 3 test classes need to have a
+ * String-arg constructor.
*/
public JUnit3DistributedTestCase(final String name) {
super(name);
@@ -239,7 +232,7 @@ public abstract class JUnit3DistributedTestCase extends TestCase implements Dist
public void postTearDown() throws Exception {
}
- protected static final void destroyRegions(final Cache cache) {
+ protected static final void destroyRegions(final Cache cache) { // TODO: this should move to CacheTestCase
JUnit4DistributedTestCase.destroyRegions(cache);
}
}
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/e7c38749/geode-core/src/test/java/com/gemstone/gemfire/test/dunit/internal/JUnit4DistributedTestCase.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/test/dunit/internal/JUnit4DistributedTestCase.java b/geode-core/src/test/java/com/gemstone/gemfire/test/dunit/internal/JUnit4DistributedTestCase.java
index be15c9a..1a1309b 100755
--- a/geode-core/src/test/java/com/gemstone/gemfire/test/dunit/internal/JUnit4DistributedTestCase.java
+++ b/geode-core/src/test/java/com/gemstone/gemfire/test/dunit/internal/JUnit4DistributedTestCase.java
@@ -16,6 +16,8 @@
*/
package com.gemstone.gemfire.test.dunit.internal;
+import static org.junit.Assert.*;
+
import java.io.Serializable;
import java.text.DecimalFormat;
import java.util.Iterator;
@@ -118,6 +120,9 @@ public class JUnit4DistributedTestCase implements DistributedTestFixture, Serial
}
public final String getName() {
+ if (this.distributedTestFixture != this) {
+ return this.distributedTestFixture.getName();
+ }
return this.testName.getMethodName();
}
@@ -406,6 +411,8 @@ public class JUnit4DistributedTestCase implements DistributedTestFixture, Serial
}
private static final void setUpVM(final String methodName, final String defaultDiskStoreName) {
+ assertNotNull("methodName must not be null", methodName);
+ assertNotNull("defaultDiskStoreName must not be null", defaultDiskStoreName);
setTestMethodName(methodName);
GemFireCacheImpl.setDefaultDiskStoreName(defaultDiskStoreName);
System.setProperty(HoplogConfig.ALLOW_LOCAL_HDFS_PROP, "true");
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/e7c38749/geode-core/src/test/java/com/gemstone/gemfire/test/dunit/internal/tests/JUnit3BasicDUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/test/dunit/internal/tests/JUnit3BasicDUnitTest.java b/geode-core/src/test/java/com/gemstone/gemfire/test/dunit/internal/tests/JUnit3BasicDUnitTest.java
new file mode 100644
index 0000000..81c59c3
--- /dev/null
+++ b/geode-core/src/test/java/com/gemstone/gemfire/test/dunit/internal/tests/JUnit3BasicDUnitTest.java
@@ -0,0 +1,167 @@
+/*
+ * 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 com.gemstone.gemfire.test.dunit.internal.tests;
+
+import static com.gemstone.gemfire.test.dunit.Invoke.*;
+
+import java.util.Properties;
+
+import com.gemstone.gemfire.test.dunit.Assert;
+import com.gemstone.gemfire.test.dunit.AsyncInvocation;
+import com.gemstone.gemfire.test.dunit.DUnitEnv;
+import com.gemstone.gemfire.test.dunit.Host;
+import com.gemstone.gemfire.test.dunit.RMIException;
+import com.gemstone.gemfire.test.dunit.VM;
+import com.gemstone.gemfire.test.dunit.internal.JUnit3DistributedTestCase;
+
+/**
+ * This class tests the basic functionality of the distributed unit
+ * test framework.
+ */
+public class JUnit3BasicDUnitTest extends JUnit3DistributedTestCase {
+
+ private static Properties bindings;
+
+ public JUnit3BasicDUnitTest(String name) {
+ super(name);
+ }
+
+ @Override
+ public void postSetUp() throws Exception {
+ bindings = new Properties();
+ invokeInEveryVM(() -> bindings = new Properties());
+ }
+
+ @Override
+ public void postTearDown() throws Exception {
+ bindings = null;
+ invokeInEveryVM(() -> bindings = null);
+ }
+
+ public void testPreconditions() {
+ invokeInEveryVM(() -> assertNotNull("getUniqueName() must not return null", getUniqueName()));
+ invokeInEveryVM(() -> assertNotNull("bindings must not be null", bindings));
+ }
+
+ /**
+ * Tests how the Hydra framework handles an error
+ */
+ public void ignore_testDontCatchRemoteException() throws Exception {
+ Host host = Host.getHost(0);
+ VM vm = host.getVM(0);
+ vm.invoke(() -> remoteThrowException());
+ }
+
+ public void testRemoteInvocationWithException() throws Exception {
+ Host host = Host.getHost(0);
+ VM vm = host.getVM(0);
+ try {
+ vm.invoke(() -> remoteThrowException());
+ fail("Should have thrown a BasicTestException");
+
+ } catch (RMIException ex) {
+ assertTrue(ex.getCause() instanceof BasicTestException);
+ }
+ }
+
+ public void testInvokeWithLambda() throws Exception {
+ Host host = Host.getHost(0);
+ VM vm0 = host.getVM(0);
+ VM vm1 = host.getVM(1);
+
+ int vm0Num = vm0.invoke(() -> DUnitEnv.get().getVMID());
+ int vm1Num = vm1.invoke(() -> DUnitEnv.get().getVMID());
+
+ assertEquals(0, vm0Num);
+ assertEquals(1, vm1Num);
+ }
+
+ public void testInvokeLambdaAsync() throws Throwable {
+ Host host = Host.getHost(0);
+ VM vm0 = host.getVM(0);
+
+ AsyncInvocation<Integer> async0 = vm0.invokeAsync(() -> DUnitEnv.get().getVMID());
+ int vm0num = async0.getResult();
+
+ assertEquals(0, vm0num);
+
+ }
+
+ public void ignore_testRemoteInvocationBoolean() {
+ }
+
+ public void testRemoteInvokeAsync() throws Exception {
+ Host host = Host.getHost(0);
+ VM vm = host.getVM(0);
+ String name = getUniqueName();
+ String value = "Hello";
+
+ AsyncInvocation ai = vm.invokeAsync(() -> remoteBind(name, value));
+ ai.join();
+ // TODO shouldn't we call fail() here?
+ if (ai.exceptionOccurred()) {
+ Assert.fail("remoteBind failed", ai.getException());
+ }
+
+ ai = vm.invokeAsync(() -> remoteValidateBind(name, value ));
+ ai.join();
+ if (ai.exceptionOccurred()) {
+ Assert.fail("remoteValidateBind failed", ai.getException());
+ }
+ }
+
+ public void testRemoteInvokeAsyncWithException() throws Exception {
+ Host host = Host.getHost(0);
+ VM vm = host.getVM(0);
+
+ AsyncInvocation ai = vm.invokeAsync(() -> remoteThrowException());
+ ai.join();
+ assertTrue(ai.exceptionOccurred());
+ Throwable ex = ai.getException();
+ assertTrue(ex instanceof BasicTestException);
+ }
+
+ /**
+ * Accessed via reflection. DO NOT REMOVE
+ */
+ private static void remoteThrowException() {
+ String s = "Test exception. Please ignore.";
+ throw new BasicTestException(s);
+ }
+
+ private static void remoteBind(String name, String value) {
+ assertNotNull("name must not be null", name);
+ assertNotNull("value must not be null", value);
+ assertNotNull("bindings must not be null", bindings);
+
+ new JUnit3BasicDUnitTest("").getSystem(); // forces connection
+ bindings.setProperty(name, value);
+ }
+
+ private static void remoteValidateBind(String name, String expected) {
+ assertEquals(expected, bindings.getProperty(name));
+ }
+
+ private static class BasicTestException extends RuntimeException {
+ BasicTestException() {
+ this("Test exception. Please ignore.");
+ }
+ BasicTestException(String s) {
+ super(s);
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/e7c38749/geode-core/src/test/java/com/gemstone/gemfire/test/dunit/internal/tests/JUnit3GetDefaultDiskStoreNameDUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/test/dunit/internal/tests/JUnit3GetDefaultDiskStoreNameDUnitTest.java b/geode-core/src/test/java/com/gemstone/gemfire/test/dunit/internal/tests/JUnit3GetDefaultDiskStoreNameDUnitTest.java
new file mode 100644
index 0000000..e89f66b
--- /dev/null
+++ b/geode-core/src/test/java/com/gemstone/gemfire/test/dunit/internal/tests/JUnit3GetDefaultDiskStoreNameDUnitTest.java
@@ -0,0 +1,66 @@
+/*
+ * 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 com.gemstone.gemfire.test.dunit.internal.tests;
+
+import static org.assertj.core.api.Assertions.*;
+
+import com.gemstone.gemfire.internal.cache.GemFireCacheImpl;
+import com.gemstone.gemfire.test.dunit.Host;
+import com.gemstone.gemfire.test.dunit.internal.JUnit3DistributedTestCase;
+import com.gemstone.gemfire.test.junit.categories.DistributedTest;
+import org.junit.experimental.categories.Category;
+
+@SuppressWarnings("serial")
+@Category(DistributedTest.class)
+public class JUnit3GetDefaultDiskStoreNameDUnitTest extends JUnit3DistributedTestCase {
+
+ public JUnit3GetDefaultDiskStoreNameDUnitTest(final String name) {
+ super(name);
+ }
+
+ public void testGetTestMethodName() {
+ String expected = createDefaultDiskStoreName(0, -1, "testGetTestMethodName");
+ assertGetDefaultDiskStoreName(expected);
+ }
+
+ public void testGetTestMethodNameChanges() {
+ String expected = createDefaultDiskStoreName(0, -1, "testGetTestMethodNameChanges");
+ assertGetDefaultDiskStoreName(expected);
+ }
+
+ public void testGetTestMethodNameInAllVMs() {
+ String expected = createDefaultDiskStoreName(0, -1, "testGetTestMethodNameInAllVMs");
+ assertGetDefaultDiskStoreName(expected);
+
+ for (int vmIndex = 0; vmIndex < Host.getHost(0).getVMCount(); vmIndex++) {
+ String expectedInVM = createDefaultDiskStoreName(0, vmIndex, "testGetTestMethodNameInAllVMs");
+ Host.getHost(0).getVM(vmIndex).invoke(()->assertGetDefaultDiskStoreName(expectedInVM));
+ }
+ }
+
+ private void assertGetDefaultDiskStoreName(final String expected) {
+ assertThat(getDefaultDiskStoreName()).isEqualTo(expected);
+ }
+
+ private String createDefaultDiskStoreName(final int hostIndex, final int vmIndex, final String methodName) {
+ return "DiskStore-" + hostIndex + "-" + vmIndex + "-" + getClass().getCanonicalName() + "." + methodName;
+ }
+
+ private String getDefaultDiskStoreName() {
+ return GemFireCacheImpl.DEFAULT_DS_NAME; // TODO: not thread safe
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/e7c38749/geode-core/src/test/java/com/gemstone/gemfire/test/dunit/internal/tests/JUnit3GetTestMethodNameDUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/test/dunit/internal/tests/JUnit3GetTestMethodNameDUnitTest.java b/geode-core/src/test/java/com/gemstone/gemfire/test/dunit/internal/tests/JUnit3GetTestMethodNameDUnitTest.java
new file mode 100644
index 0000000..c77843d
--- /dev/null
+++ b/geode-core/src/test/java/com/gemstone/gemfire/test/dunit/internal/tests/JUnit3GetTestMethodNameDUnitTest.java
@@ -0,0 +1,53 @@
+/*
+ * 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 com.gemstone.gemfire.test.dunit.internal.tests;
+
+import static org.assertj.core.api.Assertions.*;
+
+import com.gemstone.gemfire.test.dunit.Host;
+import com.gemstone.gemfire.test.dunit.internal.JUnit3DistributedTestCase;
+import com.gemstone.gemfire.test.junit.categories.DistributedTest;
+import org.junit.experimental.categories.Category;
+
+@SuppressWarnings("serial")
+@Category(DistributedTest.class)
+public class JUnit3GetTestMethodNameDUnitTest extends JUnit3DistributedTestCase {
+
+ public JUnit3GetTestMethodNameDUnitTest(final String name) {
+ super(name);
+ }
+
+ public void testGetTestMethodName() {
+ assertGetTestMethodName("testGetTestMethodName");
+ }
+
+ public void testGetTestMethodNameChanges() {
+ assertGetTestMethodName("testGetTestMethodNameChanges");
+ }
+
+ public void testGetTestMethodNameInAllVMs() {
+ assertGetTestMethodName("testGetTestMethodNameInAllVMs");
+
+ for (int vmIndex = 0; vmIndex < Host.getHost(0).getVMCount(); vmIndex++) {
+ Host.getHost(0).getVM(vmIndex).invoke(()->assertGetTestMethodName("testGetTestMethodNameInAllVMs"));
+ }
+ }
+
+ private void assertGetTestMethodName(final String expected) {
+ assertThat(getTestMethodName()).isEqualTo(expected);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/e7c38749/geode-core/src/test/java/com/gemstone/gemfire/test/dunit/internal/tests/JUnit3VMDUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/test/dunit/internal/tests/JUnit3VMDUnitTest.java b/geode-core/src/test/java/com/gemstone/gemfire/test/dunit/internal/tests/JUnit3VMDUnitTest.java
new file mode 100644
index 0000000..ac2ed7e
--- /dev/null
+++ b/geode-core/src/test/java/com/gemstone/gemfire/test/dunit/internal/tests/JUnit3VMDUnitTest.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 com.gemstone.gemfire.test.dunit.internal.tests;
+
+import java.io.Serializable;
+import java.util.concurrent.atomic.AtomicInteger;
+
+import com.gemstone.gemfire.test.dunit.AsyncInvocation;
+import com.gemstone.gemfire.test.dunit.Host;
+import com.gemstone.gemfire.test.dunit.RMIException;
+import com.gemstone.gemfire.test.dunit.SerializableRunnableIF;
+import com.gemstone.gemfire.test.dunit.VM;
+import com.gemstone.gemfire.test.dunit.internal.JUnit3DistributedTestCase;
+
+/**
+ * This class tests the functionality of the {@link VM} class.
+ */
+public class JUnit3VMDUnitTest extends JUnit3DistributedTestCase {
+
+ private static final AtomicInteger COUNTER = new AtomicInteger();
+ private static final boolean BOOLEAN_VALUE = true;
+ private static final byte BYTE_VALUE = (byte) 40;
+ private static final long LONG_VALUE = 42L;
+ private static final String STRING_VALUE = "BLAH BLAH BLAH";
+
+ public JUnit3VMDUnitTest(String name) {
+ super(name);
+ }
+
+ public void testInvokeStaticBoolean() {
+ Host host = Host.getHost(0);
+ VM vm = host.getVM(0);
+ assertEquals(BOOLEAN_VALUE, (boolean) vm.invoke(() -> remoteBooleanMethod()));
+ }
+
+ public void testInvokeStaticByte() {
+ Host host = Host.getHost(0);
+ VM vm = host.getVM(0);
+ assertEquals(BYTE_VALUE, (byte) vm.invoke(() -> remoteByteMethod()));
+ }
+
+ public void testInvokeStaticLong() {
+ Host host = Host.getHost(0);
+ VM vm = host.getVM(0);
+ assertEquals(LONG_VALUE, (long) vm.invoke(() -> remoteLongMethod()));
+ }
+
+ public void testInvokeInstance() {
+ Host host = Host.getHost(0);
+ VM vm = host.getVM(0);
+ assertEquals(STRING_VALUE, vm.invoke(new ClassWithString(), "getString"));
+ }
+
+ public void testInvokeRunnableWithException() {
+ Host host = Host.getHost(0);
+ VM vm = host.getVM(0);
+ try {
+ vm.invoke(new InvokeRunnable());
+ fail("Should have thrown a BasicTestException");
+ } catch (RMIException ex) {
+ assertTrue(ex.getCause() instanceof BasicTestException);
+ }
+ }
+
+ public void testReturnValue() throws Exception {
+ final Host host = Host.getHost(0);
+ final VM vm = host.getVM(0);
+ // Assert class static invocation works
+ AsyncInvocation a1 = vm.invokeAsync(() -> getAndIncStaticCount());
+ a1.join();
+ assertEquals(new Integer(0), a1.getReturnValue());
+ // Assert class static invocation with args works
+ a1 = vm.invokeAsync(() -> incrementStaticCount(new Integer(2)));
+ a1.join();
+ assertEquals(new Integer(3), a1.getReturnValue());
+ // Assert that previous values are not returned when invoking method w/ no return val
+ a1 = vm.invokeAsync(() -> incStaticCount());
+ a1.join();
+ assertNull(a1.getReturnValue());
+ // Assert that previous null returns are over-written
+ a1 = vm.invokeAsync(() -> getAndIncStaticCount());
+ a1.join();
+ assertEquals(new Integer(4), a1.getReturnValue());
+
+ // Assert object method invocation works with zero arg method
+ final VMTestObject o = new VMTestObject(0);
+ a1 = vm.invokeAsync(o, "incrementAndGet", new Object[] {});
+ a1.join();
+ assertEquals(new Integer(1), a1.getReturnValue());
+ // Assert object method invocation works with no return
+ a1 = vm.invokeAsync(o, "set", new Object[] {new Integer(3)});
+ a1.join();
+ assertNull(a1.getReturnValue());
+ }
+
+ private static Integer getAndIncStaticCount() {
+ return new Integer(COUNTER.getAndIncrement());
+ }
+
+ private static Integer incrementStaticCount(Integer inc) {
+ return new Integer(COUNTER.addAndGet(inc.intValue()));
+ }
+
+ private static void incStaticCount() {
+ COUNTER.incrementAndGet();
+ }
+
+ /**
+ * Accessed via reflection. DO NOT REMOVE
+ */
+ private static byte remoteByteMethod() {
+ return BYTE_VALUE;
+ }
+
+ /**
+ * Accessed via reflection. DO NOT REMOVE
+ */
+ private static boolean remoteBooleanMethod() {
+ return BOOLEAN_VALUE;
+ }
+
+ /**
+ * Accessed via reflection. DO NOT REMOVE
+ */
+ private static long remoteLongMethod() {
+ return LONG_VALUE;
+ }
+
+ private static class ClassWithLong implements Serializable {
+ public long getLong() {
+ return LONG_VALUE;
+ }
+ }
+
+ private static class ClassWithByte implements Serializable {
+ public byte getByte() {
+ return BYTE_VALUE;
+ }
+ }
+
+ private static class InvokeRunnable implements SerializableRunnableIF {
+ public void run() {
+ throw new BasicTestException();
+ }
+ }
+
+ private static class ClassWithString implements Serializable {
+ public String getString() {
+ return STRING_VALUE;
+ }
+ }
+
+ private static class BasicTestException extends RuntimeException {
+ BasicTestException() {
+ this("Test exception. Please ignore.");
+ }
+ BasicTestException(String s) {
+ super(s);
+ }
+ }
+
+ private static class VMTestObject implements Serializable {
+ private static final long serialVersionUID = 1L;
+ private final AtomicInteger val;
+ public VMTestObject(int init) {
+ this.val = new AtomicInteger(init);
+ }
+ public Integer get() {
+ return new Integer(this.val.get());
+ }
+ public Integer incrementAndGet() {
+ return new Integer(this.val.incrementAndGet());
+ }
+ public void set(Integer newVal) {
+ this.val.set(newVal.intValue());
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/e7c38749/geode-core/src/test/java/com/gemstone/gemfire/test/dunit/internal/tests/JUnit4BasicDUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/test/dunit/internal/tests/JUnit4BasicDUnitTest.java b/geode-core/src/test/java/com/gemstone/gemfire/test/dunit/internal/tests/JUnit4BasicDUnitTest.java
new file mode 100644
index 0000000..5b38f67
--- /dev/null
+++ b/geode-core/src/test/java/com/gemstone/gemfire/test/dunit/internal/tests/JUnit4BasicDUnitTest.java
@@ -0,0 +1,176 @@
+/*
+ * 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 com.gemstone.gemfire.test.dunit.internal.tests;
+
+import static com.gemstone.gemfire.test.dunit.Assert.*;
+import static com.gemstone.gemfire.test.dunit.Invoke.*;
+
+import java.util.Properties;
+
+import com.gemstone.gemfire.test.dunit.AsyncInvocation;
+import com.gemstone.gemfire.test.dunit.DUnitEnv;
+import com.gemstone.gemfire.test.dunit.Host;
+import com.gemstone.gemfire.test.dunit.RMIException;
+import com.gemstone.gemfire.test.dunit.VM;
+import com.gemstone.gemfire.test.dunit.internal.JUnit4DistributedTestCase;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Ignore;
+import org.junit.Test;
+
+/**
+ * This class tests the basic functionality of the distributed unit
+ * test framework.
+ */
+public class JUnit4BasicDUnitTest extends JUnit4DistributedTestCase {
+
+ private static Properties bindings;
+
+ @BeforeClass
+ public static void setUpJUnit4BasicDUnitTest() throws Exception {
+ invokeInEveryVM(() -> bindings = new Properties());
+ }
+
+ @AfterClass
+ public static void tearDownJUnit4BasicDUnitTest() {
+ invokeInEveryVM(() -> bindings = null);
+ }
+
+ @Test
+ public void testPreconditions() {
+ invokeInEveryVM(() -> assertNotNull("getUniqueName() must not return null", getUniqueName()));
+ invokeInEveryVM(() -> assertNotNull("bindings must not be null", bindings));
+ }
+
+ /**
+ * Tests how the Hydra framework handles an error
+ */
+ @Ignore
+ @Test
+ public void testDontCatchRemoteException() throws Exception {
+ Host host = Host.getHost(0);
+ VM vm = host.getVM(0);
+ vm.invoke(() -> remoteThrowException());
+ }
+
+ @Test
+ public void testRemoteInvocationWithException() throws Exception {
+ Host host = Host.getHost(0);
+ VM vm = host.getVM(0);
+ try {
+ vm.invoke(() -> remoteThrowException());
+ fail("Should have thrown a BasicTestException");
+
+ } catch (RMIException ex) {
+ assertTrue(ex.getCause() instanceof BasicTestException);
+ }
+ }
+
+ @Test
+ public void testInvokeWithLambda() throws Exception {
+ Host host = Host.getHost(0);
+ VM vm0 = host.getVM(0);
+ VM vm1 = host.getVM(1);
+
+ int vm0Num = vm0.invoke(() -> DUnitEnv.get().getVMID());
+ int vm1Num = vm1.invoke(() -> DUnitEnv.get().getVMID());
+
+ assertEquals(0, vm0Num);
+ assertEquals(1, vm1Num);
+ }
+
+ @Test
+ public void testInvokeLambdaAsync() throws Throwable {
+ Host host = Host.getHost(0);
+ VM vm0 = host.getVM(0);
+
+ AsyncInvocation<Integer> async0 = vm0.invokeAsync(() -> DUnitEnv.get().getVMID());
+ int vm0num = async0.getResult();
+
+ assertEquals(0, vm0num);
+
+ }
+
+ @Ignore("Test was never implemented")
+ @Test
+ public void testRemoteInvocationBoolean() {
+ }
+
+ @Test
+ public void testRemoteInvokeAsync() throws Exception {
+ Host host = Host.getHost(0);
+ VM vm = host.getVM(0);
+ String name = this.getUniqueName();
+ String value = "Hello";
+
+ AsyncInvocation ai =
+ vm.invokeAsync(() -> this.remoteBind( name, value ));
+ ai.join();
+ // TODO shouldn't we call fail() here?
+ if (ai.exceptionOccurred()) {
+ fail("remoteBind failed", ai.getException());
+ }
+
+ ai = vm.invokeAsync(() -> this.remoteValidateBind(name, value ));
+ ai.join();
+ if (ai.exceptionOccurred()) {
+ fail("remoteValidateBind failed", ai.getException());
+ }
+ }
+
+ @Test
+ public void testRemoteInvokeAsyncWithException() throws Exception {
+ Host host = Host.getHost(0);
+ VM vm = host.getVM(0);
+
+ AsyncInvocation ai = vm.invokeAsync(() -> this.remoteThrowException());
+ ai.join();
+ assertTrue(ai.exceptionOccurred());
+ Throwable ex = ai.getException();
+ assertTrue(ex instanceof BasicTestException);
+ }
+
+ /**
+ * Accessed via reflection. DO NOT REMOVE
+ */
+ private static void remoteThrowException() {
+ String s = "Test exception. Please ignore.";
+ throw new BasicTestException(s);
+ }
+
+ private static void remoteBind(String name, String value) {
+ assertNotNull("name must not be null", name);
+ assertNotNull("value must not be null", value);
+ assertNotNull("bindings must not be null", bindings);
+
+ new JUnit4BasicDUnitTest().getSystem(); // forces connection
+ bindings.setProperty(name, value);
+ }
+
+ private static void remoteValidateBind(String name, String expected) {
+ assertEquals(expected, bindings.getProperty(name));
+ }
+
+ private static class BasicTestException extends RuntimeException {
+ BasicTestException() {
+ this("Test exception. Please ignore.");
+ }
+ BasicTestException(String s) {
+ super(s);
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/e7c38749/geode-core/src/test/java/com/gemstone/gemfire/test/dunit/internal/tests/JUnit4GetDefaultDiskStoreNameDUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/test/dunit/internal/tests/JUnit4GetDefaultDiskStoreNameDUnitTest.java b/geode-core/src/test/java/com/gemstone/gemfire/test/dunit/internal/tests/JUnit4GetDefaultDiskStoreNameDUnitTest.java
new file mode 100644
index 0000000..7f99bc1
--- /dev/null
+++ b/geode-core/src/test/java/com/gemstone/gemfire/test/dunit/internal/tests/JUnit4GetDefaultDiskStoreNameDUnitTest.java
@@ -0,0 +1,65 @@
+/*
+ * 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 com.gemstone.gemfire.test.dunit.internal.tests;
+
+import static org.assertj.core.api.Assertions.*;
+
+import com.gemstone.gemfire.internal.cache.GemFireCacheImpl;
+import com.gemstone.gemfire.test.dunit.Host;
+import com.gemstone.gemfire.test.dunit.internal.JUnit4DistributedTestCase;
+import com.gemstone.gemfire.test.junit.categories.DistributedTest;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+
+@Category(DistributedTest.class)
+public class JUnit4GetDefaultDiskStoreNameDUnitTest extends JUnit4DistributedTestCase {
+
+ @Test
+ public void testGetTestMethodName() {
+ String expected = createDefaultDiskStoreName(0, -1, "testGetTestMethodName");
+ assertGetDefaultDiskStoreName(expected);
+ }
+
+ @Test
+ public void testGetTestMethodNameChanges() {
+ String expected = createDefaultDiskStoreName(0, -1, "testGetTestMethodNameChanges");
+ assertGetDefaultDiskStoreName(expected);
+ }
+
+ @Test
+ public void testGetTestMethodNameInAllVMs() {
+ String expected = createDefaultDiskStoreName(0, -1, "testGetTestMethodNameInAllVMs");
+ assertGetDefaultDiskStoreName(expected);
+
+ for (int vmIndex = 0; vmIndex < Host.getHost(0).getVMCount(); vmIndex++) {
+ String expectedInVM = createDefaultDiskStoreName(0, vmIndex, "testGetTestMethodNameInAllVMs");
+ Host.getHost(0).getVM(vmIndex).invoke(()->assertGetDefaultDiskStoreName(expectedInVM));
+ }
+ }
+
+ private void assertGetDefaultDiskStoreName(final String expected) {
+ assertThat(getDefaultDiskStoreName()).isEqualTo(expected);
+ }
+
+ private String createDefaultDiskStoreName(final int hostIndex, final int vmIndex, final String methodName) {
+ return "DiskStore-" + hostIndex + "-" + vmIndex + "-" + getClass().getCanonicalName() + "." + methodName;
+ }
+
+ private String getDefaultDiskStoreName() {
+ return GemFireCacheImpl.DEFAULT_DS_NAME; // TODO: not thread safe
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/e7c38749/geode-core/src/test/java/com/gemstone/gemfire/test/dunit/internal/tests/JUnit4GetTestMethodNameDUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/test/dunit/internal/tests/JUnit4GetTestMethodNameDUnitTest.java b/geode-core/src/test/java/com/gemstone/gemfire/test/dunit/internal/tests/JUnit4GetTestMethodNameDUnitTest.java
new file mode 100644
index 0000000..93b2e86
--- /dev/null
+++ b/geode-core/src/test/java/com/gemstone/gemfire/test/dunit/internal/tests/JUnit4GetTestMethodNameDUnitTest.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 com.gemstone.gemfire.test.dunit.internal.tests;
+
+import static org.assertj.core.api.Assertions.*;
+
+import com.gemstone.gemfire.test.dunit.Host;
+import com.gemstone.gemfire.test.dunit.internal.JUnit4DistributedTestCase;
+import com.gemstone.gemfire.test.junit.categories.DistributedTest;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+
+@Category(DistributedTest.class)
+public class JUnit4GetTestMethodNameDUnitTest extends JUnit4DistributedTestCase {
+
+ @Test
+ public void testGetTestMethodName() {
+ assertGetTestMethodName("testGetTestMethodName");
+ }
+
+ @Test
+ public void testGetTestMethodNameChanges() {
+ assertGetTestMethodName("testGetTestMethodNameChanges");
+ }
+
+ @Test
+ public void testGetTestMethodNameInAllVMs() {
+ assertGetTestMethodName("testGetTestMethodNameInAllVMs");
+
+ for (int vmIndex = 0; vmIndex < Host.getHost(0).getVMCount(); vmIndex++) {
+ Host.getHost(0).getVM(vmIndex).invoke(()->assertGetTestMethodName("testGetTestMethodNameInAllVMs"));
+ }
+ }
+
+ private void assertGetTestMethodName(final String expected) {
+ assertThat(getTestMethodName()).isEqualTo(expected);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/e7c38749/geode-core/src/test/java/com/gemstone/gemfire/test/dunit/internal/tests/JUnit4VMDUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/test/dunit/internal/tests/JUnit4VMDUnitTest.java b/geode-core/src/test/java/com/gemstone/gemfire/test/dunit/internal/tests/JUnit4VMDUnitTest.java
new file mode 100644
index 0000000..c9d9d3c
--- /dev/null
+++ b/geode-core/src/test/java/com/gemstone/gemfire/test/dunit/internal/tests/JUnit4VMDUnitTest.java
@@ -0,0 +1,200 @@
+/*
+ * 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 com.gemstone.gemfire.test.dunit.internal.tests;
+
+import static com.gemstone.gemfire.test.dunit.Assert.*;
+
+import java.io.Serializable;
+import java.util.concurrent.atomic.AtomicInteger;
+
+import com.gemstone.gemfire.test.dunit.AsyncInvocation;
+import com.gemstone.gemfire.test.dunit.Host;
+import com.gemstone.gemfire.test.dunit.RMIException;
+import com.gemstone.gemfire.test.dunit.SerializableRunnableIF;
+import com.gemstone.gemfire.test.dunit.VM;
+import com.gemstone.gemfire.test.dunit.internal.JUnit4DistributedTestCase;
+import com.gemstone.gemfire.test.junit.categories.DistributedTest;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+
+/**
+ * This class tests the functionality of the {@link VM} class.
+ */
+@Category(DistributedTest.class)
+public class JUnit4VMDUnitTest extends JUnit4DistributedTestCase {
+
+ private static final AtomicInteger COUNTER = new AtomicInteger();
+ private static final boolean BOOLEAN_VALUE = true;
+ private static final byte BYTE_VALUE = (byte) 40;
+ private static final long LONG_VALUE = 42L;
+ private static final String STRING_VALUE = "BLAH BLAH BLAH";
+
+ @Test
+ public void testInvokeStaticBoolean() {
+ Host host = Host.getHost(0);
+ VM vm = host.getVM(0);
+ assertEquals(BOOLEAN_VALUE, (boolean) vm.invoke(() -> remoteBooleanMethod()));
+ }
+
+ @Test
+ public void testInvokeStaticByte() {
+ Host host = Host.getHost(0);
+ VM vm = host.getVM(0);
+ assertEquals(BYTE_VALUE, (byte) vm.invoke(() -> remoteByteMethod()));
+ }
+
+ @Test
+ public void testInvokeStaticLong() {
+ Host host = Host.getHost(0);
+ VM vm = host.getVM(0);
+ assertEquals(LONG_VALUE, (long) vm.invoke(() -> remoteLongMethod()));
+ }
+
+ @Test
+ public void testInvokeInstance() {
+ Host host = Host.getHost(0);
+ VM vm = host.getVM(0);
+ assertEquals(STRING_VALUE, vm.invoke(new ClassWithString(), "getString"));
+ }
+
+ @Test
+ public void testInvokeRunnableWithException() {
+ Host host = Host.getHost(0);
+ VM vm = host.getVM(0);
+ try {
+ vm.invoke(new InvokeRunnable());
+ fail("Should have thrown a BasicTestException");
+ } catch (RMIException ex) {
+ assertTrue(ex.getCause() instanceof BasicTestException);
+ }
+ }
+
+ @Test
+ public void testReturnValue() throws Exception {
+ final Host host = Host.getHost(0);
+ final VM vm = host.getVM(0);
+ // Assert class static invocation works
+ AsyncInvocation a1 = vm.invokeAsync(() -> getAndIncStaticCount());
+ a1.join();
+ assertEquals(new Integer(0), a1.getReturnValue());
+ // Assert class static invocation with args works
+ a1 = vm.invokeAsync(() -> incrementStaticCount(new Integer(2)));
+ a1.join();
+ assertEquals(new Integer(3), a1.getReturnValue());
+ // Assert that previous values are not returned when invoking method w/ no return val
+ a1 = vm.invokeAsync(() -> incStaticCount());
+ a1.join();
+ assertNull(a1.getReturnValue());
+ // Assert that previous null returns are over-written
+ a1 = vm.invokeAsync(() -> getAndIncStaticCount());
+ a1.join();
+ assertEquals(new Integer(4), a1.getReturnValue());
+
+ // Assert object method invocation works with zero arg method
+ final VMTestObject o = new VMTestObject(0);
+ a1 = vm.invokeAsync(o, "incrementAndGet", new Object[] {});
+ a1.join();
+ assertEquals(new Integer(1), a1.getReturnValue());
+ // Assert object method invocation works with no return
+ a1 = vm.invokeAsync(o, "set", new Object[] {new Integer(3)});
+ a1.join();
+ assertNull(a1.getReturnValue());
+ }
+
+ private static Integer getAndIncStaticCount() {
+ return new Integer(COUNTER.getAndIncrement());
+ }
+
+ private static Integer incrementStaticCount(Integer inc) {
+ return new Integer(COUNTER.addAndGet(inc.intValue()));
+ }
+
+ private static void incStaticCount() {
+ COUNTER.incrementAndGet();
+ }
+
+ /**
+ * Accessed via reflection. DO NOT REMOVE
+ */
+ private static byte remoteByteMethod() {
+ return BYTE_VALUE;
+ }
+
+ /**
+ * Accessed via reflection. DO NOT REMOVE
+ */
+ private static boolean remoteBooleanMethod() {
+ return BOOLEAN_VALUE;
+ }
+
+ /**
+ * Accessed via reflection. DO NOT REMOVE
+ */
+ private static long remoteLongMethod() {
+ return LONG_VALUE;
+ }
+
+ private static class ClassWithLong implements Serializable {
+ public long getLong() {
+ return LONG_VALUE;
+ }
+ }
+
+ private static class ClassWithByte implements Serializable {
+ public byte getByte() {
+ return BYTE_VALUE;
+ }
+ }
+
+ private static class InvokeRunnable implements SerializableRunnableIF {
+ public void run() {
+ throw new BasicTestException();
+ }
+ }
+
+ private static class ClassWithString implements Serializable {
+ public String getString() {
+ return STRING_VALUE;
+ }
+ }
+
+ private static class BasicTestException extends RuntimeException {
+ BasicTestException() {
+ this("Test exception. Please ignore.");
+ }
+ BasicTestException(String s) {
+ super(s);
+ }
+ }
+
+ private static class VMTestObject implements Serializable {
+ private static final long serialVersionUID = 1L;
+ private final AtomicInteger val;
+ public VMTestObject(int init) {
+ this.val = new AtomicInteger(init);
+ }
+ public Integer get() {
+ return new Integer(this.val.get());
+ }
+ public Integer incrementAndGet() {
+ return new Integer(this.val.incrementAndGet());
+ }
+ public void set(Integer newVal) {
+ this.val.set(newVal.intValue());
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/e7c38749/geode-core/src/test/java/com/gemstone/gemfire/test/dunit/tests/BasicDUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/test/dunit/tests/BasicDUnitTest.java b/geode-core/src/test/java/com/gemstone/gemfire/test/dunit/tests/BasicDUnitTest.java
index 068e81b..72f110b 100644
--- a/geode-core/src/test/java/com/gemstone/gemfire/test/dunit/tests/BasicDUnitTest.java
+++ b/geode-core/src/test/java/com/gemstone/gemfire/test/dunit/tests/BasicDUnitTest.java
@@ -16,6 +16,8 @@
*/
package com.gemstone.gemfire.test.dunit.tests;
+import static com.gemstone.gemfire.test.dunit.Invoke.invokeInEveryVM;
+
import java.util.Properties;
import com.gemstone.gemfire.test.dunit.Assert;
@@ -32,125 +34,134 @@ import com.gemstone.gemfire.test.dunit.VM;
*/
public class BasicDUnitTest extends DistributedTestCase {
+ private static Properties bindings;
+
public BasicDUnitTest(String name) {
super(name);
}
- //////// Test Methods
+ @Override
+ public void postSetUp() throws Exception {
+ bindings = new Properties();
+ invokeInEveryVM(() -> bindings = new Properties());
+ }
+
+ @Override
+ public void postTearDown() throws Exception {
+ bindings = null;
+ invokeInEveryVM(() -> bindings = null);
+ }
+
+ public void testPreconditions() {
+ invokeInEveryVM(() -> assertNotNull("getUniqueName() must not return null", getUniqueName()));
+ invokeInEveryVM(() -> assertNotNull("bindings must not be null", bindings));
+ }
/**
* Tests how the Hydra framework handles an error
*/
- public void _testDontCatchRemoteException() {
+ public void ignore_testDontCatchRemoteException() throws Exception {
Host host = Host.getHost(0);
VM vm = host.getVM(0);
- vm.invoke(() -> this.remoteThrowException());
+ vm.invoke(() -> remoteThrowException());
}
- public void testRemoteInvocationWithException() {
+ public void testRemoteInvocationWithException() throws Exception {
Host host = Host.getHost(0);
VM vm = host.getVM(0);
try {
- vm.invoke(() -> this.remoteThrowException());
+ vm.invoke(() -> remoteThrowException());
fail("Should have thrown a BasicTestException");
} catch (RMIException ex) {
assertTrue(ex.getCause() instanceof BasicTestException);
}
}
-
- public void testInvokeWithLambda() {
+
+ public void testInvokeWithLambda() throws Exception {
Host host = Host.getHost(0);
VM vm0 = host.getVM(0);
VM vm1 = host.getVM(1);
-
+
int vm0Num = vm0.invoke(() -> DUnitEnv.get().getVMID());
int vm1Num = vm1.invoke(() -> DUnitEnv.get().getVMID());
-
+
assertEquals(0, vm0Num);
assertEquals(1, vm1Num);
-
}
-
+
public void testInvokeLambdaAsync() throws Throwable {
Host host = Host.getHost(0);
VM vm0 = host.getVM(0);
-
+
AsyncInvocation<Integer> async0 = vm0.invokeAsync(() -> DUnitEnv.get().getVMID());
int vm0num = async0.getResult();
-
- assertEquals(0, vm0num);
-
- }
- static class BasicTestException extends RuntimeException {
- BasicTestException() {
- this("Test exception. Please ignore.");
- }
-
- BasicTestException(String s) {
- super(s);
- }
- }
+ assertEquals(0, vm0num);
- /**
- * Accessed via reflection. DO NOT REMOVE
- *
- */
- protected static void remoteThrowException() {
- String s = "Test exception. Please ignore.";
- throw new BasicTestException(s);
}
- public void _testRemoteInvocationBoolean() {
-
+ public void ignore_testRemoteInvocationBoolean() {
}
- public void testRemoteInvokeAsync() throws InterruptedException {
+ public void testRemoteInvokeAsync() throws Exception {
Host host = Host.getHost(0);
VM vm = host.getVM(0);
- String name = this.getUniqueName();
+ String name = getUniqueName();
String value = "Hello";
- AsyncInvocation ai =
- vm.invokeAsync(() -> this.remoteBind( name, value ));
+ AsyncInvocation ai = vm.invokeAsync(() -> remoteBind(name, value));
ai.join();
// TODO shouldn't we call fail() here?
if (ai.exceptionOccurred()) {
Assert.fail("remoteBind failed", ai.getException());
}
- ai = vm.invokeAsync(() -> this.remoteValidateBind(name, value ));
+ ai = vm.invokeAsync(() -> remoteValidateBind(name, value ));
ai.join();
if (ai.exceptionOccurred()) {
Assert.fail("remoteValidateBind failed", ai.getException());
}
}
- private static Properties bindings = new Properties();
- private static void remoteBind(String name, String s) {
- new BasicDUnitTest("bogus").getSystem(); // forces connection
- bindings.setProperty(name, s);
- }
-
- private static void remoteValidateBind(String name, String expected)
- {
- assertEquals(expected, bindings.getProperty(name));
- }
-
- public void testRemoteInvokeAsyncWithException()
- throws InterruptedException {
-
+ public void testRemoteInvokeAsyncWithException() throws Exception {
Host host = Host.getHost(0);
VM vm = host.getVM(0);
-// String name = this.getUniqueName();
-// String value = "Hello";
- AsyncInvocation ai =
- vm.invokeAsync(() -> this.remoteThrowException());
+ AsyncInvocation ai = vm.invokeAsync(() -> remoteThrowException());
ai.join();
assertTrue(ai.exceptionOccurred());
Throwable ex = ai.getException();
assertTrue(ex instanceof BasicTestException);
}
+
+ /**
+ * Accessed via reflection. DO NOT REMOVE
+ */
+ private static void remoteThrowException() {
+ String s = "Test exception. Please ignore.";
+ throw new BasicTestException(s);
+ }
+
+ private static void remoteBind(String name, String value) {
+ assertNotNull("name must not be null", name);
+ assertNotNull("value must not be null", value);
+ assertNotNull("bindings must not be null", bindings);
+
+ new BasicDUnitTest("").getSystem(); // forces connection
+ bindings.setProperty(name, value);
+ }
+
+ private static void remoteValidateBind(String name, String expected) {
+ assertEquals(expected, bindings.getProperty(name));
+ }
+
+ private static class BasicTestException extends RuntimeException {
+ BasicTestException() {
+ this("Test exception. Please ignore.");
+ }
+ BasicTestException(String s) {
+ super(s);
+ }
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/e7c38749/geode-core/src/test/java/com/gemstone/gemfire/test/dunit/tests/GetDefaultDiskStoreNameDUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/test/dunit/tests/GetDefaultDiskStoreNameDUnitTest.java b/geode-core/src/test/java/com/gemstone/gemfire/test/dunit/tests/GetDefaultDiskStoreNameDUnitTest.java
index 99dcc29..c92ab3d 100755
--- a/geode-core/src/test/java/com/gemstone/gemfire/test/dunit/tests/GetDefaultDiskStoreNameDUnitTest.java
+++ b/geode-core/src/test/java/com/gemstone/gemfire/test/dunit/tests/GetDefaultDiskStoreNameDUnitTest.java
@@ -37,30 +37,30 @@ public class GetDefaultDiskStoreNameDUnitTest extends DistributedTestCase {
String expected = createDefaultDiskStoreName(0, -1, "testGetTestMethodName");
assertGetDefaultDiskStoreName(expected);
}
-
+
public void testGetTestMethodNameChanges() {
String expected = createDefaultDiskStoreName(0, -1, "testGetTestMethodNameChanges");
assertGetDefaultDiskStoreName(expected);
}
-
+
public void testGetTestMethodNameInAllVMs() {
String expected = createDefaultDiskStoreName(0, -1, "testGetTestMethodNameInAllVMs");
assertGetDefaultDiskStoreName(expected);
-
+
for (int vmIndex = 0; vmIndex < Host.getHost(0).getVMCount(); vmIndex++) {
String expectedInVM = createDefaultDiskStoreName(0, vmIndex, "testGetTestMethodNameInAllVMs");
Host.getHost(0).getVM(vmIndex).invoke(()->assertGetDefaultDiskStoreName(expectedInVM));
}
}
-
+
private void assertGetDefaultDiskStoreName(final String expected) {
assertThat(getDefaultDiskStoreName()).isEqualTo(expected);
}
-
+
private String createDefaultDiskStoreName(final int hostIndex, final int vmIndex, final String methodName) {
return "DiskStore-" + hostIndex + "-" + vmIndex + "-" + getClass().getCanonicalName() + "." + methodName;
}
-
+
private String getDefaultDiskStoreName() {
return GemFireCacheImpl.DEFAULT_DS_NAME; // TODO: not thread safe
}
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/e7c38749/geode-core/src/test/java/com/gemstone/gemfire/test/dunit/tests/GetTestMethodNameDUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/test/dunit/tests/GetTestMethodNameDUnitTest.java b/geode-core/src/test/java/com/gemstone/gemfire/test/dunit/tests/GetTestMethodNameDUnitTest.java
index 9bad472..13550f6 100755
--- a/geode-core/src/test/java/com/gemstone/gemfire/test/dunit/tests/GetTestMethodNameDUnitTest.java
+++ b/geode-core/src/test/java/com/gemstone/gemfire/test/dunit/tests/GetTestMethodNameDUnitTest.java
@@ -35,19 +35,19 @@ public class GetTestMethodNameDUnitTest extends DistributedTestCase {
public void testGetTestMethodName() {
assertGetTestMethodName("testGetTestMethodName");
}
-
+
public void testGetTestMethodNameChanges() {
assertGetTestMethodName("testGetTestMethodNameChanges");
}
-
+
public void testGetTestMethodNameInAllVMs() {
assertGetTestMethodName("testGetTestMethodNameInAllVMs");
-
+
for (int vmIndex = 0; vmIndex < Host.getHost(0).getVMCount(); vmIndex++) {
Host.getHost(0).getVM(vmIndex).invoke(()->assertGetTestMethodName("testGetTestMethodNameInAllVMs"));
}
}
-
+
private void assertGetTestMethodName(final String expected) {
assertThat(getTestMethodName()).isEqualTo(expected);
}
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/e7c38749/geode-core/src/test/java/com/gemstone/gemfire/test/dunit/tests/VMDUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/test/dunit/tests/VMDUnitTest.java b/geode-core/src/test/java/com/gemstone/gemfire/test/dunit/tests/VMDUnitTest.java
index ce6cb36..c0275d2 100644
--- a/geode-core/src/test/java/com/gemstone/gemfire/test/dunit/tests/VMDUnitTest.java
+++ b/geode-core/src/test/java/com/gemstone/gemfire/test/dunit/tests/VMDUnitTest.java
@@ -31,6 +31,7 @@ import com.gemstone.gemfire.test.dunit.VM;
*/
public class VMDUnitTest extends DistributedTestCase {
+ private static final AtomicInteger COUNTER = new AtomicInteger();
private static final boolean BOOLEAN_VALUE = true;
private static final byte BYTE_VALUE = (byte) 40;
private static final long LONG_VALUE = 42L;
@@ -40,124 +41,139 @@ public class VMDUnitTest extends DistributedTestCase {
super(name);
}
- /**
- * Accessed via reflection. DO NOT REMOVE
- * @return
- */
- protected static byte remoteByteMethod() {
- return BYTE_VALUE;
+ public void testInvokeStaticBoolean() {
+ Host host = Host.getHost(0);
+ VM vm = host.getVM(0);
+ assertEquals(BOOLEAN_VALUE, (boolean) vm.invoke(() -> remoteBooleanMethod()));
}
- public void notestInvokeStaticBoolean() {
+ public void testInvokeStaticByte() {
Host host = Host.getHost(0);
VM vm = host.getVM(0);
- assertEquals(BOOLEAN_VALUE,
- (boolean) vm.invoke(() -> VMDUnitTest.remoteBooleanMethod()));
+ assertEquals(BYTE_VALUE, (byte) vm.invoke(() -> remoteByteMethod()));
}
- /**
- * Accessed via reflection. DO NOT REMOVE
- * @return
- */
- protected static boolean remoteBooleanMethod() {
- return BOOLEAN_VALUE;
+ public void testInvokeStaticLong() {
+ Host host = Host.getHost(0);
+ VM vm = host.getVM(0);
+ assertEquals(LONG_VALUE, (long) vm.invoke(() -> remoteLongMethod()));
}
- public void notestInvokeStaticBooleanNotBoolean() {
+ public void testInvokeInstance() {
Host host = Host.getHost(0);
VM vm = host.getVM(0);
- try {
- vm.invoke(() -> VMDUnitTest.remoteByteMethod());
- fail("Should have thrown an IllegalArgumentException");
-
- } catch (IllegalArgumentException ex) {
-
- }
+ assertEquals(STRING_VALUE, vm.invoke(new ClassWithString(), "getString"));
}
- public void notestInvokeStaticLong() {
+ public void testInvokeRunnableWithException() {
Host host = Host.getHost(0);
VM vm = host.getVM(0);
- assertEquals(LONG_VALUE,
- (long) vm.invoke(() -> VMDUnitTest.remoteLongMethod()));
+ try {
+ vm.invoke(new InvokeRunnable());
+ fail("Should have thrown a BasicTestException");
+ } catch (RMIException ex) {
+ assertTrue(ex.getCause() instanceof BasicTestException);
+ }
+ }
+
+ public void testReturnValue() throws Exception {
+ final Host host = Host.getHost(0);
+ final VM vm = host.getVM(0);
+ // Assert class static invocation works
+ AsyncInvocation a1 = vm.invokeAsync(() -> getAndIncStaticCount());
+ a1.join();
+ assertEquals(new Integer(0), a1.getReturnValue());
+ // Assert class static invocation with args works
+ a1 = vm.invokeAsync(() -> incrementStaticCount(new Integer(2)));
+ a1.join();
+ assertEquals(new Integer(3), a1.getReturnValue());
+ // Assert that previous values are not returned when invoking method w/ no return val
+ a1 = vm.invokeAsync(() -> incStaticCount());
+ a1.join();
+ assertNull(a1.getReturnValue());
+ // Assert that previous null returns are over-written
+ a1 = vm.invokeAsync(() -> getAndIncStaticCount());
+ a1.join();
+ assertEquals(new Integer(4), a1.getReturnValue());
+
+ // Assert object method invocation works with zero arg method
+ final VMTestObject o = new VMTestObject(0);
+ a1 = vm.invokeAsync(o, "incrementAndGet", new Object[] {});
+ a1.join();
+ assertEquals(new Integer(1), a1.getReturnValue());
+ // Assert object method invocation works with no return
+ a1 = vm.invokeAsync(o, "set", new Object[] {new Integer(3)});
+ a1.join();
+ assertNull(a1.getReturnValue());
+ }
+
+ private static Integer getAndIncStaticCount() {
+ return new Integer(COUNTER.getAndIncrement());
+ }
+
+ private static Integer incrementStaticCount(Integer inc) {
+ return new Integer(COUNTER.addAndGet(inc.intValue()));
+ }
+
+ private static void incStaticCount() {
+ COUNTER.incrementAndGet();
}
/**
* Accessed via reflection. DO NOT REMOVE
- * @return
*/
- protected static long remoteLongMethod() {
- return LONG_VALUE;
+ private static byte remoteByteMethod() {
+ return BYTE_VALUE;
}
- public void notestInvokeStaticLongNotLong() {
- Host host = Host.getHost(0);
- VM vm = host.getVM(0);
- try {
- vm.invoke(() -> VMDUnitTest.remoteByteMethod());
- fail("Should have thrown an IllegalArgumentException");
+ /**
+ * Accessed via reflection. DO NOT REMOVE
+ */
+ private static boolean remoteBooleanMethod() {
+ return BOOLEAN_VALUE;
+ }
- } catch (IllegalArgumentException ex) {
-
- }
+ /**
+ * Accessed via reflection. DO NOT REMOVE
+ */
+ private static long remoteLongMethod() {
+ return LONG_VALUE;
}
- protected static class ClassWithLong implements Serializable {
+ private static class ClassWithLong implements Serializable {
public long getLong() {
return LONG_VALUE;
}
}
- protected static class ClassWithByte implements Serializable {
+ private static class ClassWithByte implements Serializable {
public byte getByte() {
return BYTE_VALUE;
}
}
- protected static class InvokeRunnable
- implements SerializableRunnableIF {
-
+ private static class InvokeRunnable implements SerializableRunnableIF {
public void run() {
- throw new BasicDUnitTest.BasicTestException();
+ throw new BasicTestException();
}
}
- protected static class ClassWithString implements Serializable {
+ private static class ClassWithString implements Serializable {
public String getString() {
return STRING_VALUE;
}
}
- public void notestInvokeInstance() {
- Host host = Host.getHost(0);
- VM vm = host.getVM(0);
- assertEquals(STRING_VALUE,
- vm.invoke(new ClassWithString(), "getString"));
- }
-
- public void notestInvokeRunnable() {
- Host host = Host.getHost(0);
- VM vm = host.getVM(0);
- try {
- vm.invoke(new InvokeRunnable());
- fail("Should have thrown a BasicTestException");
-
- } catch (RMIException ex) {
- assertTrue(ex.getCause() instanceof BasicDUnitTest.BasicTestException);
+ private static class BasicTestException extends RuntimeException {
+ BasicTestException() {
+ this("Test exception. Please ignore.");
+ }
+ BasicTestException(String s) {
+ super(s);
}
}
-
- private static final AtomicInteger COUNTER = new AtomicInteger();
- public static Integer getAndIncStaticCount() {
- return new Integer(COUNTER.getAndIncrement());
- }
- public static Integer incrementStaticCount(Integer inc) {
- return new Integer(COUNTER.addAndGet(inc.intValue()));
- }
- public static void incStaticCount() {
- COUNTER.incrementAndGet();
- }
- public static class VMTestObject implements Serializable {
+
+ private static class VMTestObject implements Serializable {
private static final long serialVersionUID = 1L;
private final AtomicInteger val;
public VMTestObject(int init) {
@@ -173,34 +189,4 @@ public class VMDUnitTest extends DistributedTestCase {
this.val.set(newVal.intValue());
}
}
- public void testReturnValue() throws Exception {
- final Host host = Host.getHost(0);
- final VM vm = host.getVM(0);
- // Assert class static invocation works
- AsyncInvocation a1 = vm.invokeAsync(() -> getAndIncStaticCount());
- a1.join();
- assertEquals(new Integer(0), a1.getReturnValue());
- // Assert class static invocation with args works
- a1 = vm.invokeAsync(() -> incrementStaticCount(new Integer(2)));
- a1.join();
- assertEquals(new Integer(3), a1.getReturnValue());
- // Assert that previous values are not returned when invoking method w/ no return val
- a1 = vm.invokeAsync(() -> incStaticCount());
- a1.join();
- assertNull(a1.getReturnValue());
- // Assert that previous null returns are over-written
- a1 = vm.invokeAsync(() -> getAndIncStaticCount());
- a1.join();
- assertEquals(new Integer(4), a1.getReturnValue());
-
- // Assert object method invocation works with zero arg method
- final VMTestObject o = new VMTestObject(0);
- a1 = vm.invokeAsync(o, "incrementAndGet", new Object[] {});
- a1.join();
- assertEquals(new Integer(1), a1.getReturnValue());
- // Assert object method invocation works with no return
- a1 = vm.invokeAsync(o, "set", new Object[] {new Integer(3)});
- a1.join();
- assertNull(a1.getReturnValue());
- }
}
[2/2] incubator-geode git commit: Remove comments about case methods
which only applies to hydra dunit
Posted by kl...@apache.org.
Remove comments about case methods which only applies to hydra dunit
Project: http://git-wip-us.apache.org/repos/asf/incubator-geode/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-geode/commit/2fd9cc68
Tree: http://git-wip-us.apache.org/repos/asf/incubator-geode/tree/2fd9cc68
Diff: http://git-wip-us.apache.org/repos/asf/incubator-geode/diff/2fd9cc68
Branch: refs/heads/feature/GEODE-1050
Commit: 2fd9cc687ceac3a99fbab25fccd6cfc85725a43e
Parents: e7c3874
Author: Kirk Lund <kl...@apache.org>
Authored: Fri Mar 11 13:08:18 2016 -0800
Committer: Kirk Lund <kl...@apache.org>
Committed: Fri Mar 11 13:08:18 2016 -0800
----------------------------------------------------------------------
.../com/gemstone/gemfire/test/dunit/DistributedTestCase.java | 7 -------
.../test/dunit/internal/JUnit3DistributedTestCase.java | 7 -------
2 files changed, 14 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/2fd9cc68/geode-core/src/test/java/com/gemstone/gemfire/test/dunit/DistributedTestCase.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/test/dunit/DistributedTestCase.java b/geode-core/src/test/java/com/gemstone/gemfire/test/dunit/DistributedTestCase.java
index 2a5adce..b657e1e 100755
--- a/geode-core/src/test/java/com/gemstone/gemfire/test/dunit/DistributedTestCase.java
+++ b/geode-core/src/test/java/com/gemstone/gemfire/test/dunit/DistributedTestCase.java
@@ -64,13 +64,6 @@ import junit.framework.TestCase;
/**
* This class is the superclass of all distributed unit tests.
- *
- * tests/hydra/JUnitTestTask is the main DUnit driver. It supports two
- * additional public static methods if they are defined in the test case:
- *
- * public static void caseSetUp() -- comparable to JUnit's BeforeClass annotation
- *
- * public static void caseTearDown() -- comparable to JUnit's AfterClass annotation
*
* @author David Whitlock
*/
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/2fd9cc68/geode-core/src/test/java/com/gemstone/gemfire/test/dunit/internal/JUnit3DistributedTestCase.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/test/dunit/internal/JUnit3DistributedTestCase.java b/geode-core/src/test/java/com/gemstone/gemfire/test/dunit/internal/JUnit3DistributedTestCase.java
index 92d48ce..ecdbb5f 100755
--- a/geode-core/src/test/java/com/gemstone/gemfire/test/dunit/internal/JUnit3DistributedTestCase.java
+++ b/geode-core/src/test/java/com/gemstone/gemfire/test/dunit/internal/JUnit3DistributedTestCase.java
@@ -30,13 +30,6 @@ import org.junit.experimental.categories.Category;
/**
* This class is the superclass of all distributed tests using JUnit 3.
- *
- * tests/hydra/JUnitTestTask is the main DUnit driver. It supports two
- * additional public static methods if they are defined in the test case:
- *
- * public static void caseSetUp() -- comparable to JUnit's BeforeClass annotation // TODO: are these invoked by standalone dunit?
- *
- * public static void caseTearDown() -- comparable to JUnit's AfterClass annotation
*/
@Category(DistributedTest.class)
public abstract class JUnit3DistributedTestCase extends TestCase implements DistributedTestFixture, Serializable {