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/04/14 22:47:15 UTC
[3/8] incubator-geode git commit: GEODE-1162: convert all CLI command
DUnit tests to JUnit 4
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/f2d5969e/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 2c93ddf..d016843 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
@@ -26,6 +26,12 @@ import java.util.Map;
import java.util.Properties;
import java.util.Set;
+import org.apache.logging.log4j.Logger;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Rule;
+
import com.gemstone.gemfire.admin.internal.AdminDistributedSystemImpl;
import com.gemstone.gemfire.cache.Cache;
import com.gemstone.gemfire.cache.Region;
@@ -61,18 +67,11 @@ import com.gemstone.gemfire.test.dunit.Invoke;
import com.gemstone.gemfire.test.dunit.LogWriterUtils;
import com.gemstone.gemfire.test.dunit.standalone.DUnitLauncher;
import com.gemstone.gemfire.test.junit.rules.serializable.SerializableTestName;
-import org.apache.logging.log4j.Logger;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.BeforeClass;
-import org.junit.Rule;
/**
* This class is the base class for all distributed tests using JUnit 4.
- *
- * TODO: make this class abstract when JUnit3DistributedTestCase is deleted
*/
-public class JUnit4DistributedTestCase implements DistributedTestFixture, Serializable {
+public abstract class JUnit4DistributedTestCase implements DistributedTestFixture, Serializable {
private static final Logger logger = LogService.getLogger();
@@ -98,7 +97,7 @@ public class JUnit4DistributedTestCase implements DistributedTestFixture, Serial
* no-arg constructor.
*/
public JUnit4DistributedTestCase() {
- this((DistributedTestFixture)null);
+ this(null);
}
/**
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/f2d5969e/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
deleted file mode 100644
index 5130b5c..0000000
--- a/geode-core/src/test/java/com/gemstone/gemfire/test/dunit/internal/tests/JUnit3BasicDUnitTest.java
+++ /dev/null
@@ -1,189 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package 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 testInvokeWithNamedLambda() {
- Host host = Host.getHost(0);
- VM vm0 = host.getVM(0);
- VM vm1 = host.getVM(1);
-
- int vm0Num = vm0.invoke("getVMID", () -> DUnitEnv.get().getVMID());
- int vm1Num = vm1.invoke("getVMID", () -> DUnitEnv.get().getVMID());
-
- assertEquals(0, vm0Num);
- assertEquals(1, vm1Num);
- }
-
- public void testInvokeNamedLambdaAsync() throws Throwable {
- Host host = Host.getHost(0);
- VM vm0 = host.getVM(0);
-
- AsyncInvocation<Integer> async0 = vm0.invokeAsync("getVMID", () -> DUnitEnv.get().getVMID());
- int vm0num = async0.getResult();
-
- assertEquals(0, vm0num);
- }
-
- // Test was never implemented
- 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/f2d5969e/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
deleted file mode 100644
index e89f66b..0000000
--- a/geode-core/src/test/java/com/gemstone/gemfire/test/dunit/internal/tests/JUnit3GetDefaultDiskStoreNameDUnitTest.java
+++ /dev/null
@@ -1,66 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package 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/f2d5969e/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
deleted file mode 100644
index c77843d..0000000
--- a/geode-core/src/test/java/com/gemstone/gemfire/test/dunit/internal/tests/JUnit3GetTestMethodNameDUnitTest.java
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package 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/f2d5969e/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
deleted file mode 100644
index ac2ed7e..0000000
--- a/geode-core/src/test/java/com/gemstone/gemfire/test/dunit/internal/tests/JUnit3VMDUnitTest.java
+++ /dev/null
@@ -1,192 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package 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/f2d5969e/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
deleted file mode 100644
index 5cac3ba..0000000
--- a/geode-core/src/test/java/com/gemstone/gemfire/test/dunit/internal/tests/JUnit4BasicDUnitTest.java
+++ /dev/null
@@ -1,202 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package 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 com.gemstone.gemfire.test.junit.categories.DistributedTest;
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
-import org.junit.Ignore;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
-
-/**
- * This class tests the basic functionality of the distributed unit
- * test framework.
- */
-@Category(DistributedTest.class)
-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);
- }
-
- @Test
- public void testInvokeWithNamedLambda() {
- Host host = Host.getHost(0);
- VM vm0 = host.getVM(0);
- VM vm1 = host.getVM(1);
-
- int vm0Num = vm0.invoke("getVMID", () -> DUnitEnv.get().getVMID());
- int vm1Num = vm1.invoke("getVMID", () -> DUnitEnv.get().getVMID());
-
- assertEquals(0, vm0Num);
- assertEquals(1, vm1Num);
- }
-
- @Test
- public void testInvokeNamedLambdaAsync() throws Throwable {
- Host host = Host.getHost(0);
- VM vm0 = host.getVM(0);
-
- AsyncInvocation<Integer> async0 = vm0.invokeAsync("getVMID", () -> 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/f2d5969e/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
deleted file mode 100644
index 7f99bc1..0000000
--- a/geode-core/src/test/java/com/gemstone/gemfire/test/dunit/internal/tests/JUnit4GetDefaultDiskStoreNameDUnitTest.java
+++ /dev/null
@@ -1,65 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package 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/f2d5969e/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
deleted file mode 100644
index 93b2e86..0000000
--- a/geode-core/src/test/java/com/gemstone/gemfire/test/dunit/internal/tests/JUnit4GetTestMethodNameDUnitTest.java
+++ /dev/null
@@ -1,52 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package 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/f2d5969e/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
deleted file mode 100644
index c9d9d3c..0000000
--- a/geode-core/src/test/java/com/gemstone/gemfire/test/dunit/internal/tests/JUnit4VMDUnitTest.java
+++ /dev/null
@@ -1,200 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package 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/f2d5969e/geode-core/src/test/java/com/gemstone/gemfire/test/dunit/rules/DistributedRestoreSystemProperties.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/test/dunit/rules/DistributedRestoreSystemProperties.java b/geode-core/src/test/java/com/gemstone/gemfire/test/dunit/rules/DistributedRestoreSystemProperties.java
index 7f95fad..73e813d 100755
--- a/geode-core/src/test/java/com/gemstone/gemfire/test/dunit/rules/DistributedRestoreSystemProperties.java
+++ b/geode-core/src/test/java/com/gemstone/gemfire/test/dunit/rules/DistributedRestoreSystemProperties.java
@@ -16,8 +16,7 @@
*/
package com.gemstone.gemfire.test.dunit.rules;
-import static java.lang.System.getProperties;
-import static java.lang.System.setProperties;
+import static java.lang.System.*;
import java.util.Properties;
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/f2d5969e/geode-core/src/test/java/com/gemstone/gemfire/test/dunit/rules/RemoteInvoker.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/test/dunit/rules/RemoteInvoker.java b/geode-core/src/test/java/com/gemstone/gemfire/test/dunit/rules/RemoteInvoker.java
index 98dbc2f..789af38 100755
--- a/geode-core/src/test/java/com/gemstone/gemfire/test/dunit/rules/RemoteInvoker.java
+++ b/geode-core/src/test/java/com/gemstone/gemfire/test/dunit/rules/RemoteInvoker.java
@@ -16,8 +16,7 @@
*/
package com.gemstone.gemfire.test.dunit.rules;
-import static com.gemstone.gemfire.test.dunit.Invoke.invokeInEveryVM;
-import static com.gemstone.gemfire.test.dunit.Invoke.invokeInLocator;
+import static com.gemstone.gemfire.test.dunit.Invoke.*;
import java.io.Serializable;
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/f2d5969e/geode-core/src/test/java/com/gemstone/gemfire/test/dunit/standalone/ChildVM.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/test/dunit/standalone/ChildVM.java b/geode-core/src/test/java/com/gemstone/gemfire/test/dunit/standalone/ChildVM.java
index 06c3196..5301ffe 100644
--- a/geode-core/src/test/java/com/gemstone/gemfire/test/dunit/standalone/ChildVM.java
+++ b/geode-core/src/test/java/com/gemstone/gemfire/test/dunit/standalone/ChildVM.java
@@ -16,11 +16,10 @@
*/
package com.gemstone.gemfire.test.dunit.standalone;
-import hydra.HydraRuntimeException;
-import hydra.Log;
-
import java.rmi.Naming;
+import hydra.HydraRuntimeException;
+import hydra.Log;
import org.apache.logging.log4j.Logger;
import com.gemstone.gemfire.internal.OSProcess;
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/f2d5969e/geode-core/src/test/java/com/gemstone/gemfire/test/dunit/standalone/DUnitLauncher.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/test/dunit/standalone/DUnitLauncher.java b/geode-core/src/test/java/com/gemstone/gemfire/test/dunit/standalone/DUnitLauncher.java
index 216971a..be459b9 100644
--- a/geode-core/src/test/java/com/gemstone/gemfire/test/dunit/standalone/DUnitLauncher.java
+++ b/geode-core/src/test/java/com/gemstone/gemfire/test/dunit/standalone/DUnitLauncher.java
@@ -16,9 +16,6 @@
*/
package com.gemstone.gemfire.test.dunit.standalone;
-import hydra.Log;
-import hydra.MethExecutorResult;
-
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
@@ -41,6 +38,10 @@ import java.rmi.server.UnicastRemoteObject;
import java.util.List;
import java.util.Properties;
+import batterytest.greplogs.ExpectedStrings;
+import batterytest.greplogs.LogConsumer;
+import hydra.Log;
+import hydra.MethExecutorResult;
import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.core.LoggerContext;
@@ -49,9 +50,6 @@ import org.apache.logging.log4j.core.config.LoggerConfig;
import org.apache.logging.log4j.core.layout.PatternLayout;
import org.junit.Assert;
-import batterytest.greplogs.ExpectedStrings;
-import batterytest.greplogs.LogConsumer;
-
import com.gemstone.gemfire.distributed.Locator;
import com.gemstone.gemfire.distributed.internal.DistributionConfig;
import com.gemstone.gemfire.distributed.internal.membership.gms.membership.GMSJoinLeave;
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/f2d5969e/geode-core/src/test/java/com/gemstone/gemfire/test/dunit/standalone/RemoteDUnitVM.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/test/dunit/standalone/RemoteDUnitVM.java b/geode-core/src/test/java/com/gemstone/gemfire/test/dunit/standalone/RemoteDUnitVM.java
index 81c895e..21f35ac 100644
--- a/geode-core/src/test/java/com/gemstone/gemfire/test/dunit/standalone/RemoteDUnitVM.java
+++ b/geode-core/src/test/java/com/gemstone/gemfire/test/dunit/standalone/RemoteDUnitVM.java
@@ -20,13 +20,12 @@ import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;
import java.util.concurrent.TimeUnit;
+import hydra.MethExecutor;
+import hydra.MethExecutorResult;
import org.apache.logging.log4j.Logger;
import com.gemstone.gemfire.internal.logging.LogService;
-import hydra.MethExecutor;
-import hydra.MethExecutorResult;
-
/**
*
*/
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/f2d5969e/geode-core/src/test/java/com/gemstone/gemfire/test/dunit/standalone/RemoteDUnitVMIF.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/test/dunit/standalone/RemoteDUnitVMIF.java b/geode-core/src/test/java/com/gemstone/gemfire/test/dunit/standalone/RemoteDUnitVMIF.java
index 849e2f2..57bbee2 100644
--- a/geode-core/src/test/java/com/gemstone/gemfire/test/dunit/standalone/RemoteDUnitVMIF.java
+++ b/geode-core/src/test/java/com/gemstone/gemfire/test/dunit/standalone/RemoteDUnitVMIF.java
@@ -16,11 +16,11 @@
*/
package com.gemstone.gemfire.test.dunit.standalone;
-import hydra.MethExecutorResult;
-
import java.rmi.Remote;
import java.rmi.RemoteException;
+import hydra.MethExecutorResult;
+
public interface RemoteDUnitVMIF extends Remote {
MethExecutorResult executeMethodOnObject(Object o, String methodName) throws RemoteException;
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/f2d5969e/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 b10f610..17afcc6 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,11 +16,14 @@
*/
package com.gemstone.gemfire.test.dunit.tests;
-import static com.gemstone.gemfire.test.dunit.Invoke.invokeInEveryVM;
+import static com.gemstone.gemfire.test.dunit.Assert.*;
+import static com.gemstone.gemfire.test.dunit.Invoke.*;
+import static com.googlecode.catchexception.CatchException.*;
+import static com.googlecode.catchexception.throwable.CatchThrowable.*;
+import static org.hamcrest.Matchers.*;
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.DistributedTestCase;
@@ -32,10 +35,16 @@ import com.gemstone.gemfire.test.dunit.VM;
* This class tests the basic functionality of the distributed unit
* test framework.
*/
+@SuppressWarnings("unused")
public class BasicDUnitTest extends DistributedTestCase {
+ private static final String MESSAGE_FOR_remoteThrowException = "Test exception. Please ignore.";
+
private static Properties bindings;
+ private VM vm0;
+ private VM vm1;
+
public BasicDUnitTest(String name) {
super(name);
}
@@ -44,6 +53,8 @@ public class BasicDUnitTest extends DistributedTestCase {
public final void postSetUp() throws Exception {
bindings = new Properties();
invokeInEveryVM(() -> bindings = new Properties());
+ this.vm0 = Host.getHost(0).getVM(0);
+ this.vm1 = Host.getHost(0).getVM(1);
}
@Override
@@ -52,117 +63,121 @@ public class BasicDUnitTest extends DistributedTestCase {
invokeInEveryVM(() -> bindings = null);
}
- public void testPreconditions() {
- invokeInEveryVM(() -> assertNotNull("getUniqueName() must not return null", getUniqueName()));
- invokeInEveryVM(() -> assertNotNull("bindings must not be null", bindings));
+ public void testPreconditions() throws Exception {
+ invokeInEveryVM(() -> assertThat("getUniqueName() must not return null", getUniqueName(), notNullValue()));
+ invokeInEveryVM(() -> assertThat("bindings must not be null", bindings, notNullValue()));
}
- /**
- * 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 testInvokeOnClassTargetWithEmptyArgs() throws Exception {
+ assertThat(this.vm0.invoke(BasicDUnitTest.class, "booleanValue", new Object[] {}), is(true));
+ }
+ public void testInvokeOnObjectTargetWithEmptyArgs() throws Exception {
+ assertThat(this.vm0.invoke(new BasicDUnitTest(""), "booleanValue", new Object[] {}), is(true));
+ }
+ public void testInvokeAsyncOnClassTargetWithEmptyArgs() throws Exception {
+ AsyncInvocation<?> async = this.vm0.invokeAsync(BasicDUnitTest.class, "booleanValue", new Object[] {}).join();
+ assertThat(async.getResult(), is(true));
+ }
+ public void testInvokeAsyncOnObjectTargetWithEmptyArgs() throws Exception {
+ AsyncInvocation<?> async = this.vm0.invokeAsync(new BasicDUnitTest(""), "booleanValue", new Object[] {}).join();
+ assertThat(async.getResult(), is(true));
}
- 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 testInvokeOnClassTargetWithNullArgs() throws Exception {
+ assertThat(this.vm0.invoke(BasicDUnitTest.class, "booleanValue", null), is(true));
+ }
+ public void testInvokeOnObjectTargetWithNullArgs() throws Exception {
+ assertThat(this.vm0.invoke(new BasicDUnitTest(""), "booleanValue", null), is(true));
+ }
+ public void testInvokeAsyncOnClassTargetWithNullArgs() throws Exception {
+ AsyncInvocation<?> async = this.vm0.invokeAsync(BasicDUnitTest.class, "booleanValue", null).join();
+ assertThat(async.getResult(), is(true));
+ }
+ public void testInvokeAsyncOnObjectTargetWithNullArgs() throws Exception {
+ AsyncInvocation<?> async = this.vm0.invokeAsync(new BasicDUnitTest(""), "booleanValue", null).join();
+ assertThat(async.getResult(), is(true));
}
- public void testInvokeWithLambda() throws Exception {
- Host host = Host.getHost(0);
- VM vm0 = host.getVM(0);
- VM vm1 = host.getVM(1);
+ public void testRemoteInvocationWithException() throws Exception {
+ catchException(this.vm0).invoke(() -> remoteThrowException());
- int vm0Num = vm0.invoke(() -> DUnitEnv.get().getVMID());
- int vm1Num = vm1.invoke(() -> DUnitEnv.get().getVMID());
+ assertThat(caughtException(), instanceOf(RMIException.class));
+ assertThat(caughtException().getCause(), notNullValue());
+ assertThat(caughtException().getCause(), instanceOf(BasicTestException.class));
+ assertThat(caughtException().getCause().getMessage(), is(MESSAGE_FOR_remoteThrowException));
+ }
- assertEquals(0, vm0Num);
- assertEquals(1, vm1Num);
+ public void testInvokeWithLambda() throws Exception {
+ assertThat(this.vm0.invoke(() -> DUnitEnv.get().getVMID()), is(0));
+ assertThat(this.vm1.invoke(() -> DUnitEnv.get().getVMID()), is(1));
}
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);
+ assertThat(this.vm0.invokeAsync(() -> DUnitEnv.get().getVMID()).getResult(), is(0));
}
public void testInvokeWithNamedLambda() {
- Host host = Host.getHost(0);
- VM vm0 = host.getVM(0);
- VM vm1 = host.getVM(1);
-
- int vm0Num = vm0.invoke("getVMID", () -> DUnitEnv.get().getVMID());
- int vm1Num = vm1.invoke("getVMID", () -> DUnitEnv.get().getVMID());
-
- assertEquals(0, vm0Num);
- assertEquals(1, vm1Num);
+ assertThat(this.vm0.invoke("getVMID", () -> DUnitEnv.get().getVMID()), is(0));
+ assertThat(this.vm1.invoke("getVMID", () -> DUnitEnv.get().getVMID()), is(1));
}
public void testInvokeNamedLambdaAsync() throws Throwable {
- Host host = Host.getHost(0);
- VM vm0 = host.getVM(0);
+ assertThat(this.vm0.invokeAsync("getVMID", () -> DUnitEnv.get().getVMID()).getResult(), is(0));
+ }
- AsyncInvocation<Integer> async0 = vm0.invokeAsync("getVMID", () -> DUnitEnv.get().getVMID());
- int vm0num = async0.getResult();
+ public void testRemoteInvokeAsync() throws Exception {
+ String name = getUniqueName();
+ String value = "Hello";
- assertEquals(0, vm0num);
+ this.vm0.invokeAsync(() -> remoteBind(name, value)).join().checkException();
+ this.vm0.invokeAsync(() -> remoteValidateBind(name, value )).join().checkException();
}
- // Test was never implemented
- public void ignore_testRemoteInvocationBoolean() {
+ public void testRemoteInvokeAsyncWithException() throws Exception {
+ AsyncInvocation<?> async = this.vm0.invokeAsync(() -> remoteThrowException()).join();
+
+ assertThat(async.exceptionOccurred(), is(true));
+ assertThat(async.getException(), instanceOf(BasicTestException.class));
+
+ catchThrowable(async).checkException();
+
+ assertThat(caughtThrowable(), instanceOf(AssertionError.class));
+ assertThat(caughtThrowable().getCause(), notNullValue());
+ assertThat(caughtThrowable().getCause(), instanceOf(BasicTestException.class));
+ assertThat(caughtThrowable().getCause().getMessage(), is(MESSAGE_FOR_remoteThrowException));
}
- public void testRemoteInvokeAsync() throws Exception {
- Host host = Host.getHost(0);
- VM vm = host.getVM(0);
- String name = getUniqueName();
- String value = "Hello";
+ public void testInvokeNamedRunnableLambdaAsync() throws Exception {
+ catchThrowable(this.vm0.invokeAsync("throwSomething", () -> throwException()).join()).checkException();
- 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());
- }
+ assertThat(caughtThrowable(), notNullValue());
+ assertThat(caughtThrowable().getCause(), notNullValue());
+ assertThat(caughtThrowable().getCause(), instanceOf(BasicDUnitException.class));
+ }
- ai = vm.invokeAsync(() -> remoteValidateBind(name, value ));
- ai.join();
- if (ai.exceptionOccurred()) {
- Assert.fail("remoteValidateBind failed", ai.getException());
- }
+ public void testInvokeNamedRunnableLambda() throws Exception {
+ catchException(this.vm0).invoke("throwSomething", () -> throwException());
+
+ assertThat(caughtException(), notNullValue());
+ assertThat(caughtException().getCause(), notNullValue());
+ assertThat(caughtException().getCause(), instanceOf(BasicDUnitException.class));
+ assertThat(caughtException().getCause().getMessage(), nullValue());
}
- public void testRemoteInvokeAsyncWithException() throws Exception {
- Host host = Host.getHost(0);
- VM vm = host.getVM(0);
+ private static boolean booleanValue() { // invoked by reflection
+ return true;
+ }
- AsyncInvocation ai = vm.invokeAsync(() -> remoteThrowException());
- ai.join();
- assertTrue(ai.exceptionOccurred());
- Throwable ex = ai.getException();
- assertTrue(ex instanceof BasicTestException);
+ private static boolean booleanValue(final boolean value) { // invoked by reflection
+ return value;
}
- /**
- * Accessed via reflection. DO NOT REMOVE
- */
private static void remoteThrowException() {
- String s = "Test exception. Please ignore.";
- throw new BasicTestException(s);
+ throw new BasicTestException(MESSAGE_FOR_remoteThrowException);
+ }
+
+ private static void throwException() throws BasicDUnitException {
+ throw new BasicDUnitException();
}
private static void remoteBind(String name, String value) {
@@ -187,45 +202,8 @@ public class BasicDUnitTest extends DistributedTestCase {
}
}
- static class BasicDUnitException extends RuntimeException {
+ private static class BasicDUnitException extends RuntimeException {
public BasicDUnitException() {
}
}
-
- public static void throwException() throws BasicDUnitException {
- throw new BasicDUnitException();
- }
-
- public void testInvokeNamedRunnableLambdaAsync() throws Throwable {
- Host host = Host.getHost(0);
- VM vm0 = host.getVM(0);
-
- AsyncInvocation<Integer> async0 = vm0.invokeAsync("throwSomething", () -> BasicDUnitTest.throwException());
- try {
- async0.getResult();
- throw new Error("expected an exception to be thrown");
- } catch (Exception e) {
- Throwable cause = e.getCause();
- if (cause == null) {
- throw new Error("expected an exception with a cause to be thrown", e);
- }
- if ( !(cause.getCause() instanceof BasicDUnitException) ) {
- throw new Error("expected a BasicDUnitException to be thrown", e.getCause());
- }
- }
- }
-
- public void testInvokeNamedRunnableLambda() throws Throwable {
- Host host = Host.getHost(0);
- VM vm0 = host.getVM(0);
-
- try {
- vm0.invoke("throwSomething", () -> BasicDUnitTest.throwException());
- throw new Error("expected an exception to be thrown");
- } catch (Exception e) {
- if ( !(e.getCause() instanceof BasicDUnitException) ) {
- throw new Error("expected a BasicDUnitException to be thrown", e.getCause());
- }
- }
- }
}
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/f2d5969e/geode-core/src/test/java/com/gemstone/gemfire/test/dunit/tests/JUnit4BasicDUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/test/dunit/tests/JUnit4BasicDUnitTest.java b/geode-core/src/test/java/com/gemstone/gemfire/test/dunit/tests/JUnit4BasicDUnitTest.java
new file mode 100644
index 0000000..01ba152
--- /dev/null
+++ b/geode-core/src/test/java/com/gemstone/gemfire/test/dunit/tests/JUnit4BasicDUnitTest.java
@@ -0,0 +1,234 @@
+/*
+ * 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.tests;
+
+import static com.gemstone.gemfire.test.dunit.Assert.*;
+import static com.gemstone.gemfire.test.dunit.Invoke.*;
+import static com.googlecode.catchexception.CatchException.*;
+import static com.googlecode.catchexception.throwable.CatchThrowable.*;
+import static org.hamcrest.Matchers.*;
+
+import java.util.Properties;
+
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+
+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 com.gemstone.gemfire.test.junit.categories.DistributedTest;
+
+/**
+ * This class tests the basic functionality of the distributed unit
+ * test framework.
+ *
+ * @see JUnit4BasicDUnitTest
+ */
+@Category(DistributedTest.class)
+@SuppressWarnings("unused")
+public class JUnit4BasicDUnitTest extends JUnit4DistributedTestCase {
+
+ private static final String MESSAGE_FOR_remoteThrowException = "Test exception. Please ignore.";
+
+ private static Properties bindings;
+
+ private VM vm0;
+ private VM vm1;
+
+ @BeforeClass
+ public static void setUpJUnit4BasicDUnitTest() throws Exception {
+ invokeInEveryVM(() -> bindings = new Properties());
+ }
+
+ @Override
+ public final void postSetUp() throws Exception {
+ this.vm0 = Host.getHost(0).getVM(0);
+ this.vm1 = Host.getHost(0).getVM(1);
+ }
+
+ @AfterClass
+ public static void tearDownJUnit4BasicDUnitTest() {
+ invokeInEveryVM(() -> bindings = null);
+ }
+
+ @Test
+ public void testPreconditions() {
+ invokeInEveryVM(() -> assertThat("getUniqueName() must not return null", getUniqueName(), notNullValue()));
+ invokeInEveryVM(() -> assertThat("bindings must not be null", bindings, notNullValue()));
+ }
+
+ @Test
+ public void testInvokeOnClassTargetWithEmptyArgs() throws Exception {
+ assertThat(this.vm0.invoke(JUnit4BasicDUnitTest.class, "booleanValue", new Object[] {}), is(true));
+ }
+ @Test
+ public void testInvokeOnObjectTargetWithEmptyArgs() throws Exception {
+ assertThat(this.vm0.invoke(new JUnit4BasicDUnitTest(), "booleanValue", new Object[] {}), is(true));
+ }
+ @Test
+ public void testInvokeAsyncOnClassTargetWithEmptyArgs() throws Exception {
+ AsyncInvocation<?> async = this.vm0.invokeAsync(JUnit4BasicDUnitTest.class, "booleanValue", new Object[] {}).join();
+ assertThat(async.getResult(), is(true));
+ }
+ @Test
+ public void testInvokeAsyncOnObjectTargetWithEmptyArgs() throws Exception {
+ AsyncInvocation<?> async = this.vm0.invokeAsync(new JUnit4BasicDUnitTest(), "booleanValue", new Object[] {}).join();
+ assertThat(async.getResult(), is(true));
+ }
+
+ @Test
+ public void testInvokeOnClassTargetWithNullArgs() throws Exception {
+ assertThat(this.vm0.invoke(JUnit4BasicDUnitTest.class, "booleanValue", null), is(true));
+ }
+ @Test
+ public void testInvokeOnObjectTargetWithNullArgs() throws Exception {
+ assertThat(this.vm0.invoke(new JUnit4BasicDUnitTest(), "booleanValue", null), is(true));
+ }
+ @Test
+ public void testInvokeAsyncOnClassTargetWithNullArgs() throws Exception {
+ AsyncInvocation<?> async = this.vm0.invokeAsync(JUnit4BasicDUnitTest.class, "booleanValue", null).join();
+ assertThat(async.getResult(), is(true));
+ }
+ @Test
+ public void testInvokeAsyncOnObjectTargetWithNullArgs() throws Exception {
+ AsyncInvocation<?> async = this.vm0.invokeAsync(new JUnit4BasicDUnitTest(), "booleanValue", null).join();
+ assertThat(async.getResult(), is(true));
+ }
+
+ @Test
+ public void testRemoteInvocationWithException() throws Exception {
+ catchException(this.vm0).invoke(() -> remoteThrowException());
+
+ assertThat(caughtException(), instanceOf(RMIException.class));
+ assertThat(caughtException().getCause(), notNullValue());
+ assertThat(caughtException().getCause(), instanceOf(BasicTestException.class));
+ assertThat(caughtException().getCause().getMessage(), is(MESSAGE_FOR_remoteThrowException));
+ }
+
+ @Test
+ public void testInvokeWithLambda() throws Exception {
+ assertThat(this.vm0.invoke(() -> DUnitEnv.get().getVMID()), is(0));
+ assertThat(this.vm1.invoke(() -> DUnitEnv.get().getVMID()), is(1));
+ }
+
+ @Test
+ public void testInvokeLambdaAsync() throws Throwable {
+ assertThat(this.vm0.invokeAsync(() -> DUnitEnv.get().getVMID()).getResult(), is(0));
+ }
+
+ @Test
+ public void testInvokeWithNamedLambda() {
+ assertThat(this.vm0.invoke("getVMID", () -> DUnitEnv.get().getVMID()), is(0));
+ assertThat(this.vm1.invoke("getVMID", () -> DUnitEnv.get().getVMID()), is(1));
+ }
+
+ @Test
+ public void testInvokeNamedLambdaAsync() throws Throwable {
+ assertThat(this.vm0.invokeAsync("getVMID", () -> DUnitEnv.get().getVMID()).getResult(), is(0));
+ }
+
+ @Test
+ public void testRemoteInvokeAsync() throws Exception {
+ String name = getUniqueName();
+ String value = "Hello";
+
+ this.vm0.invokeAsync(() -> remoteBind(name, value)).join().checkException();
+ this.vm0.invokeAsync(() -> remoteValidateBind(name, value )).join().checkException();
+ }
+
+ @Test
+ public void testRemoteInvokeAsyncWithException() throws Exception {
+ AsyncInvocation<?> async = this.vm0.invokeAsync(() -> remoteThrowException()).join();
+
+ assertThat(async.exceptionOccurred(), is(true));
+ assertThat(async.getException(), instanceOf(BasicTestException.class));
+
+ catchThrowable(async).checkException();
+
+ assertThat(caughtThrowable(), instanceOf(AssertionError.class));
+ assertThat(caughtThrowable().getCause(), notNullValue());
+ assertThat(caughtThrowable().getCause(), instanceOf(BasicTestException.class));
+ assertThat(caughtThrowable().getCause().getMessage(), is(MESSAGE_FOR_remoteThrowException));
+ }
+
+ @Test
+ public void testInvokeNamedRunnableLambdaAsync() throws Exception {
+ catchThrowable(this.vm0.invokeAsync("throwSomething", () -> throwException()).join()).checkException();
+
+ assertThat(caughtThrowable(), notNullValue());
+ assertThat(caughtThrowable().getCause(), notNullValue());
+ assertThat(caughtThrowable().getCause(), instanceOf(BasicDUnitException.class));
+ }
+
+ @Test
+ public void testInvokeNamedRunnableLambda() throws Exception {
+ catchException(this.vm0).invoke("throwSomething", () -> throwException());
+
+ assertThat(caughtException(), notNullValue());
+ assertThat(caughtException().getCause(), notNullValue());
+ assertThat(caughtException().getCause(), instanceOf(BasicDUnitException.class));
+ assertThat(caughtException().getCause().getMessage(), nullValue());
+ }
+
+ private static boolean booleanValue() { // invoked by reflection
+ return true;
+ }
+
+ private static boolean booleanValue(final boolean value) { // invoked by reflection
+ return value;
+ }
+
+ private static void remoteThrowException() {
+ throw new BasicTestException(MESSAGE_FOR_remoteThrowException);
+ }
+
+ private static void throwException() throws BasicDUnitException {
+ throw new BasicDUnitException();
+ }
+
+ 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);
+ }
+ }
+
+ private static class BasicDUnitException extends RuntimeException {
+ public BasicDUnitException() {
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/f2d5969e/geode-core/src/test/java/com/gemstone/gemfire/test/dunit/tests/JUnit4GetDefaultDiskStoreNameDUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/test/dunit/tests/JUnit4GetDefaultDiskStoreNameDUnitTest.java b/geode-core/src/test/java/com/gemstone/gemfire/test/dunit/tests/JUnit4GetDefaultDiskStoreNameDUnitTest.java
new file mode 100644
index 0000000..cab5559
--- /dev/null
+++ b/geode-core/src/test/java/com/gemstone/gemfire/test/dunit/tests/JUnit4GetDefaultDiskStoreNameDUnitTest.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.tests;
+
+import static org.assertj.core.api.Assertions.*;
+
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+
+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;
+
+@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/f2d5969e/geode-core/src/test/java/com/gemstone/gemfire/test/dunit/tests/JUnit4GetTestMethodNameDUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/test/dunit/tests/JUnit4GetTestMethodNameDUnitTest.java b/geode-core/src/test/java/com/gemstone/gemfire/test/dunit/tests/JUnit4GetTestMethodNameDUnitTest.java
new file mode 100644
index 0000000..a4a9b49
--- /dev/null
+++ b/geode-core/src/test/java/com/gemstone/gemfire/test/dunit/tests/JUnit4GetTestMethodNameDUnitTest.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.tests;
+
+import static org.assertj.core.api.Assertions.*;
+
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+
+import com.gemstone.gemfire.test.dunit.Host;
+import com.gemstone.gemfire.test.dunit.internal.JUnit4DistributedTestCase;
+import com.gemstone.gemfire.test.junit.categories.DistributedTest;
+
+@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/f2d5969e/geode-core/src/test/java/com/gemstone/gemfire/test/dunit/tests/JUnit4OverridingGetPropertiesDisconnectsAllDUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/test/dunit/tests/JUnit4OverridingGetPropertiesDisconnectsAllDUnitTest.java b/geode-core/src/test/java/com/gemstone/gemfire/test/dunit/tests/JUnit4OverridingGetPropertiesDisconnectsAllDUnitTest.java
new file mode 100644
index 0000000..b03c42a
--- /dev/null
+++ b/geode-core/src/test/java/com/gemstone/gemfire/test/dunit/tests/JUnit4OverridingGetPropertiesDisconnectsAllDUnitTest.java
@@ -0,0 +1,57 @@
+/*
+ * 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.tests;
+
+import static com.gemstone.gemfire.test.dunit.Assert.*;
+import static com.gemstone.gemfire.test.dunit.Invoke.*;
+
+import java.util.Properties;
+
+import org.junit.Test;
+
+import com.gemstone.gemfire.distributed.internal.DistributionConfig;
+import com.gemstone.gemfire.test.dunit.internal.JUnit4DistributedTestCase;
+
+/**
+ * Verifies that overriding {@code getDistributedSystemProperties} results
+ * in {@code disconnectAllFromDS} during tear down.
+ */
+public class JUnit4OverridingGetPropertiesDisconnectsAllDUnitTest extends JUnit4DistributedTestCase {
+
+ @Override
+ public final void preTearDownAssertions() throws Exception {
+ invokeInEveryVM(() -> assertNotNull(basicGetSystem()));
+ }
+
+ @Override
+ public final void postTearDownAssertions() throws Exception {
+ invokeInEveryVM(() -> assertNull(basicGetSystem()));
+ }
+
+ @Override
+ public final Properties getDistributedSystemProperties() {
+ Properties props = new Properties();
+ props.setProperty(DistributionConfig.MCAST_PORT_NAME, "0");
+ return props;
+ }
+
+ @Test
+ public void testDisconnects() throws Exception {
+ invokeInEveryVM(() -> assertFalse(getDistributedSystemProperties().isEmpty()));
+ invokeInEveryVM(() -> assertNotNull(getSystem()));
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/f2d5969e/geode-core/src/test/java/com/gemstone/gemfire/test/dunit/tests/JUnit4VMDUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/test/dunit/tests/JUnit4VMDUnitTest.java b/geode-core/src/test/java/com/gemstone/gemfire/test/dunit/tests/JUnit4VMDUnitTest.java
new file mode 100644
index 0000000..3861234
--- /dev/null
+++ b/geode-core/src/test/java/com/gemstone/gemfire/test/dunit/tests/JUnit4VMDUnitTest.java
@@ -0,0 +1,201 @@
+/*
+ * 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.tests;
+
+import static com.gemstone.gemfire.test.dunit.Assert.*;
+
+import java.io.Serializable;
+import java.util.concurrent.atomic.AtomicInteger;
+
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+
+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;
+
+/**
+ * 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());
+ }
+ }
+}