Return-Path: X-Original-To: apmail-geode-commits-archive@minotaur.apache.org Delivered-To: apmail-geode-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 5351D18C39 for ; Tue, 9 Feb 2016 18:44:43 +0000 (UTC) Received: (qmail 62053 invoked by uid 500); 9 Feb 2016 18:44:43 -0000 Delivered-To: apmail-geode-commits-archive@geode.apache.org Received: (qmail 62023 invoked by uid 500); 9 Feb 2016 18:44:43 -0000 Mailing-List: contact commits-help@geode.incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@geode.incubator.apache.org Delivered-To: mailing list commits@geode.incubator.apache.org Received: (qmail 62012 invoked by uid 99); 9 Feb 2016 18:44:43 -0000 Received: from Unknown (HELO spamd2-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 09 Feb 2016 18:44:43 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd2-us-west.apache.org (ASF Mail Server at spamd2-us-west.apache.org) with ESMTP id A26311A01A4 for ; Tue, 9 Feb 2016 18:44:42 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd2-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: -3.453 X-Spam-Level: X-Spam-Status: No, score=-3.453 tagged_above=-999 required=6.31 tests=[KAM_ASCII_DIVIDERS=0.8, KAM_LAZY_DOMAIN_SECURITY=1, RCVD_IN_DNSWL_HI=-5, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, RP_MATCHES_RCVD=-0.233] autolearn=disabled Received: from mx1-us-east.apache.org ([10.40.0.8]) by localhost (spamd2-us-west.apache.org [10.40.0.9]) (amavisd-new, port 10024) with ESMTP id qNUXWafGWB3u for ; Tue, 9 Feb 2016 18:44:17 +0000 (UTC) Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx1-us-east.apache.org (ASF Mail Server at mx1-us-east.apache.org) with SMTP id 429FB43F6E for ; Tue, 9 Feb 2016 18:44:12 +0000 (UTC) Received: (qmail 57324 invoked by uid 99); 9 Feb 2016 18:44:12 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 09 Feb 2016 18:44:12 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id DE2C4E6999; Tue, 9 Feb 2016 18:44:11 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: klund@apache.org To: commits@geode.incubator.apache.org Date: Tue, 09 Feb 2016 18:44:21 -0000 Message-Id: In-Reply-To: <0d0ea98460444feb979efa764ed9f510@git.apache.org> References: <0d0ea98460444feb979efa764ed9f510@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [11/51] [partial] incubator-geode git commit: GEODE-773: Extract static methods from DistributedTestCase http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/820cfd63/gemfire-core/src/test/java/com/gemstone/gemfire/test/dunit/NetworkUtils.java ---------------------------------------------------------------------- diff --git a/gemfire-core/src/test/java/com/gemstone/gemfire/test/dunit/NetworkUtils.java b/gemfire-core/src/test/java/com/gemstone/gemfire/test/dunit/NetworkUtils.java new file mode 100755 index 0000000..d83aecd --- /dev/null +++ b/gemfire-core/src/test/java/com/gemstone/gemfire/test/dunit/NetworkUtils.java @@ -0,0 +1,69 @@ +/* + * 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; + +import java.net.UnknownHostException; + +import com.gemstone.gemfire.internal.SocketCreator; + +/** + * NetworkUtils provides static utility methods to perform + * network DNS lookups or similar actions. + * + * These methods can be used directly: NetworkUtils.getIPLiteral(), + * however, they are intended to be referenced through static import: + * + *
+ * import static com.gemstone.gemfire.test.dunit.NetworkUtils.*;
+ *    ...
+ *    String hostName = getIPLiteral();
+ * 
+ * + * Extracted from DistributedTestCase. + */ +public class NetworkUtils { + + protected NetworkUtils() { + } + + /** + * Get the IP literal name for the current host. Use this instead of + * "localhost" to avoid IPv6 name resolution bugs in the JDK/machine config. + * This method honors java.net.preferIPvAddresses + * + * @return an IP literal which honors java.net.preferIPvAddresses + */ + public static String getIPLiteral() { + try { + return SocketCreator.getLocalHost().getHostAddress(); + } catch (UnknownHostException e) { + throw new Error("Problem determining host IP address", e); + } + } + + /** + * Get the host name to use for a server cache in client/server dunit + * testing. + * + * @param host the dunit Host to get a machine host name for + * @return the host name + */ + public static String getServerHostName(final Host host) { + String serverBindAddress = System.getProperty("gemfire.server-bind-address"); + return serverBindAddress != null ? serverBindAddress : host.getHostName(); + } +} http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/820cfd63/gemfire-core/src/test/java/com/gemstone/gemfire/test/dunit/RMIException.java ---------------------------------------------------------------------- diff --git a/gemfire-core/src/test/java/com/gemstone/gemfire/test/dunit/RMIException.java b/gemfire-core/src/test/java/com/gemstone/gemfire/test/dunit/RMIException.java index 8a555d2..1a5fac4 100644 --- a/gemfire-core/src/test/java/com/gemstone/gemfire/test/dunit/RMIException.java +++ b/gemfire-core/src/test/java/com/gemstone/gemfire/test/dunit/RMIException.java @@ -42,8 +42,8 @@ import com.gemstone.gemfire.GemFireException; * see hydra.RemoteTestModuleIF * * @author David Whitlock - * */ +@SuppressWarnings("serial") public class RMIException extends GemFireException { /** SHADOWED FIELD that holds the cause exception (as opposed to the http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/820cfd63/gemfire-core/src/test/java/com/gemstone/gemfire/test/dunit/RepeatableRunnable.java ---------------------------------------------------------------------- diff --git a/gemfire-core/src/test/java/com/gemstone/gemfire/test/dunit/RepeatableRunnable.java b/gemfire-core/src/test/java/com/gemstone/gemfire/test/dunit/RepeatableRunnable.java index 32e4369..9695c32 100644 --- a/gemfire-core/src/test/java/com/gemstone/gemfire/test/dunit/RepeatableRunnable.java +++ b/gemfire-core/src/test/java/com/gemstone/gemfire/test/dunit/RepeatableRunnable.java @@ -20,8 +20,10 @@ package com.gemstone.gemfire.test.dunit; * A RepeatableRunnable is an object that implements a method that * can be invoked repeatably without causing any side affects. * - * @author dmonnie + * @author dmonnie + * @deprecated Please use SerializableRunnable with {@link com.jayway.awaitility.Awaitility} instead. */ +@Deprecated public interface RepeatableRunnable { public void runRepeatingIfNecessary(long repeatTimeoutMs); http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/820cfd63/gemfire-core/src/test/java/com/gemstone/gemfire/test/dunit/SerializableCallableIF.java ---------------------------------------------------------------------- diff --git a/gemfire-core/src/test/java/com/gemstone/gemfire/test/dunit/SerializableCallableIF.java b/gemfire-core/src/test/java/com/gemstone/gemfire/test/dunit/SerializableCallableIF.java index c3d3ae7..ddeb71e 100644 --- a/gemfire-core/src/test/java/com/gemstone/gemfire/test/dunit/SerializableCallableIF.java +++ b/gemfire-core/src/test/java/com/gemstone/gemfire/test/dunit/SerializableCallableIF.java @@ -19,6 +19,8 @@ package com.gemstone.gemfire.test.dunit; import java.io.Serializable; import java.util.concurrent.Callable; +/** + * Interface for {@link SerializableCallable} to enable use with lambdas. + */ public interface SerializableCallableIF extends Serializable, Callable { - } http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/820cfd63/gemfire-core/src/test/java/com/gemstone/gemfire/test/dunit/SerializableRunnable.java ---------------------------------------------------------------------- diff --git a/gemfire-core/src/test/java/com/gemstone/gemfire/test/dunit/SerializableRunnable.java b/gemfire-core/src/test/java/com/gemstone/gemfire/test/dunit/SerializableRunnable.java index 658924a..353cdc7 100644 --- a/gemfire-core/src/test/java/com/gemstone/gemfire/test/dunit/SerializableRunnable.java +++ b/gemfire-core/src/test/java/com/gemstone/gemfire/test/dunit/SerializableRunnable.java @@ -46,8 +46,7 @@ import java.io.Serializable; * } * */ -public abstract class SerializableRunnable - implements SerializableRunnableIF { +public abstract class SerializableRunnable implements SerializableRunnableIF { private static final long serialVersionUID = 7584289978241650456L; http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/820cfd63/gemfire-core/src/test/java/com/gemstone/gemfire/test/dunit/SerializableRunnableIF.java ---------------------------------------------------------------------- diff --git a/gemfire-core/src/test/java/com/gemstone/gemfire/test/dunit/SerializableRunnableIF.java b/gemfire-core/src/test/java/com/gemstone/gemfire/test/dunit/SerializableRunnableIF.java index 648e4f8..5e5467d 100644 --- a/gemfire-core/src/test/java/com/gemstone/gemfire/test/dunit/SerializableRunnableIF.java +++ b/gemfire-core/src/test/java/com/gemstone/gemfire/test/dunit/SerializableRunnableIF.java @@ -18,6 +18,8 @@ package com.gemstone.gemfire.test.dunit; import java.io.Serializable; +/** + * Interface for {@link SerializableRunnable} to enable use with lambdas. + */ public interface SerializableRunnableIF extends Serializable, Runnable { - } http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/820cfd63/gemfire-core/src/test/java/com/gemstone/gemfire/test/dunit/StoppableWaitCriterion.java ---------------------------------------------------------------------- diff --git a/gemfire-core/src/test/java/com/gemstone/gemfire/test/dunit/StoppableWaitCriterion.java b/gemfire-core/src/test/java/com/gemstone/gemfire/test/dunit/StoppableWaitCriterion.java new file mode 100755 index 0000000..b7be9c5 --- /dev/null +++ b/gemfire-core/src/test/java/com/gemstone/gemfire/test/dunit/StoppableWaitCriterion.java @@ -0,0 +1,35 @@ +/* + * 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; + +/** + * Defines an asynchronous criterion with an optional method to fail early + * before timeout. + * + * Extracted from DistributedTestCase. + * + * @deprecated Use {@link com.jayway.awaitility.Awaitility} instead. + */ +public interface StoppableWaitCriterion extends WaitCriterion { + + /** + * If this method returns true then quit waiting even if we are not done. + * This allows a wait to fail early. + */ + public boolean stopWaiting(); + +} http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/820cfd63/gemfire-core/src/test/java/com/gemstone/gemfire/test/dunit/ThreadUtils.java ---------------------------------------------------------------------- diff --git a/gemfire-core/src/test/java/com/gemstone/gemfire/test/dunit/ThreadUtils.java b/gemfire-core/src/test/java/com/gemstone/gemfire/test/dunit/ThreadUtils.java new file mode 100755 index 0000000..6ba87ed --- /dev/null +++ b/gemfire-core/src/test/java/com/gemstone/gemfire/test/dunit/ThreadUtils.java @@ -0,0 +1,155 @@ +/* + * 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; + +import static org.junit.Assert.fail; +import static com.gemstone.gemfire.test.dunit.Jitter.*; + +import org.apache.logging.log4j.Logger; + +import com.gemstone.gemfire.internal.OSProcess; +import com.gemstone.gemfire.internal.logging.LogService; + +/** + * ThreadUtils provides static utility methods to perform thread + * related actions such as dumping thread stacks. + * + * These methods can be used directly: ThreadUtils.dumpAllStacks(), + * however, they are intended to be referenced through static import: + * + *
+ * import static com.gemstone.gemfire.test.dunit.ThreadUtils.*;
+ *    ...
+ *    dumpAllStacks();
+ * 
+ * + * Extracted from DistributedTestCase. + */ +public class ThreadUtils { + + private static final Logger logger = LogService.getLogger(); + + protected ThreadUtils() { + } + + /** + * Print stack dumps for all vms. + * + * @author bruce + * @since 5.0 + */ + public static void dumpAllStacks() { + for (int h=0; h < Host.getHostCount(); h++) { + dumpStack(Host.getHost(h)); + } + } + + /** + * Dump all thread stacks + */ + public static void dumpMyThreads() { + OSProcess.printStacks(0, false); + } + + /** + * Print a stack dump for this vm. + * + * @author bruce + * @since 5.0 + */ + public static void dumpStack() { + OSProcess.printStacks(0, false); + } + + /** + * Print stack dumps for all vms on the given host. + * + * @author bruce + * @since 5.0 + */ + public static void dumpStack(final Host host) { + for (int v=0; v < host.getVMCount(); v++) { + host.getVM(v).invoke(com.gemstone.gemfire.test.dunit.DistributedTestCase.class, "dumpStack"); + } + } + + /** + * Print a stack dump for the given vm. + * + * @author bruce + * @since 5.0 + */ + public static void dumpStack(final VM vm) { + vm.invoke(com.gemstone.gemfire.test.dunit.DistributedTestCase.class, "dumpStack"); + } + + public static void dumpStackTrace(final Thread thread, final StackTraceElement[] stackTrace) { + StringBuilder msg = new StringBuilder(); + msg.append("Thread=<") + .append(thread) + .append("> stackDump:\n"); + for (int i=0; i < stackTrace.length; i++) { + msg.append("\t") + .append(stackTrace[i]) + .append("\n"); + } + logger.info(msg.toString()); + } + + /** + * Wait for a thread to join. + * + * @param thread thread to wait on + * @param timeoutMilliseconds maximum time to wait + * @throws AssertionError if the thread does not terminate + */ + public static void join(final Thread thread, final long timeoutMilliseconds) { + final long tilt = System.currentTimeMillis() + timeoutMilliseconds; + final long incrementalWait = jitterInterval(timeoutMilliseconds); + final long start = System.currentTimeMillis(); + for (;;) { + // I really do *not* understand why this check is necessary + // but it is, at least with JDK 1.6. According to the source code + // and the javadocs, one would think that join() would exit immediately + // if the thread is dead. However, I can tell you from experimentation + // that this is not the case. :-( djp 2008-12-08 + if (!thread.isAlive()) { + break; + } + try { + thread.join(incrementalWait); + } catch (InterruptedException e) { + fail("interrupted"); + } + if (System.currentTimeMillis() >= tilt) { + break; + } + } // for + if (thread.isAlive()) { + logger.info("HUNG THREAD"); + ThreadUtils.dumpStackTrace(thread, thread.getStackTrace()); + ThreadUtils.dumpMyThreads(); + thread.interrupt(); // We're in trouble! + fail("Thread did not terminate after " + timeoutMilliseconds + " ms: " + thread); + } + long elapsedMs = (System.currentTimeMillis() - start); + if (elapsedMs > 0) { + String msg = "Thread " + thread + " took " + elapsedMs + " ms to exit."; + logger.info(msg); + } + } +} http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/820cfd63/gemfire-core/src/test/java/com/gemstone/gemfire/test/dunit/VM.java ---------------------------------------------------------------------- diff --git a/gemfire-core/src/test/java/com/gemstone/gemfire/test/dunit/VM.java b/gemfire-core/src/test/java/com/gemstone/gemfire/test/dunit/VM.java index 0d16196..db3e302 100644 --- a/gemfire-core/src/test/java/com/gemstone/gemfire/test/dunit/VM.java +++ b/gemfire-core/src/test/java/com/gemstone/gemfire/test/dunit/VM.java @@ -18,9 +18,9 @@ package com.gemstone.gemfire.test.dunit; import java.io.File; import java.io.PrintWriter; +import java.io.Serializable; import java.io.StringWriter; import java.rmi.RemoteException; -import java.util.concurrent.Callable; import com.gemstone.gemfire.test.dunit.standalone.BounceResult; import com.gemstone.gemfire.test.dunit.standalone.RemoteDUnitVMIF; @@ -31,9 +31,9 @@ import hydra.MethExecutorResult; * This class represents a Java Virtual Machine that runs on a host. * * @author David Whitlock - * */ -public class VM implements java.io.Serializable { +@SuppressWarnings("serial") +public class VM implements Serializable { /** The host on which this VM runs */ private Host host; @@ -53,7 +53,7 @@ public class VM implements java.io.Serializable { * Creates a new VM that runs on a given host with a * given process id. */ - public VM(Host host, int pid, RemoteDUnitVMIF client) { + public VM(final Host host, final int pid, final RemoteDUnitVMIF client) { this.host = host; this.pid = pid; this.client = client; @@ -83,7 +83,7 @@ public class VM implements java.io.Serializable { * void return type in this VM. If the return type of * the method is void, null is returned. * - * @param c + * @param targetClass * The class on which to invoke the method * @param methodName * The name of the method to invoke @@ -92,8 +92,8 @@ public class VM implements java.io.Serializable { * An exception occurred on while invoking the method in * this VM */ - public Object invoke(Class c, String methodName) { - return invoke(c, methodName, new Object[0]); + public Object invoke(final Class targetClass, final String methodName) { + return invoke(targetClass, methodName, new Object[0]); } /** @@ -102,13 +102,13 @@ public class VM implements java.io.Serializable { * return type of the method is void, null * is returned. * - * @param c + * @param targetClass * The class on which to invoke the method * @param methodName * The name of the method to invoke */ - public AsyncInvocation invokeAsync(Class c, String methodName) { - return invokeAsync(c, methodName, null); + public AsyncInvocation invokeAsync(final Class targetClass, final String methodName) { + return invokeAsync(targetClass, methodName, null); } /** @@ -116,7 +116,7 @@ public class VM implements java.io.Serializable { * void return type in this VM. If the return type of * the method is void, null is returned. * - * @param c + * @param targetClass * The class on which to invoke the method * @param methodName * The name of the method to invoke @@ -128,17 +128,17 @@ public class VM implements java.io.Serializable { * An exception occurred on while invoking the method in * this VM */ - public Object invoke(Class c, String methodName, Object[] args) { + public Object invoke(Class targetClass, String methodName, Object[] args) { if (!this.available) { String s = "VM not available: " + this; - throw new RMIException(this, c.getName(), methodName, + throw new RMIException(this, targetClass.getName(), methodName, new IllegalStateException(s)); } MethExecutorResult result = null; int retryCount = 120; do { try { - result = this.client.executeMethodOnClass(c.getName(), methodName, args); + result = this.client.executeMethodOnClass(targetClass.getName(), methodName, args); break; // out of while loop } catch( RemoteException e ) { boolean isWindows = false; @@ -157,7 +157,7 @@ public class VM implements java.io.Serializable { } } } else { - throw new RMIException(this, c.getName(), methodName, e ); + throw new RMIException(this, targetClass.getName(), methodName, e ); } } } while (true); @@ -167,7 +167,7 @@ public class VM implements java.io.Serializable { } else { Throwable thr = result.getException(); - throw new RMIException(this, c.getName(), methodName, thr, + throw new RMIException(this, targetClass.getName(), methodName, thr, result.getStackTrace()); } } @@ -177,7 +177,7 @@ public class VM implements java.io.Serializable { * void return type in this VM. If the return type of * the method is void, null is returned. * - * @param c + * @param targetClass * The class on which to invoke the method * @param methodName * The name of the method to invoke @@ -185,13 +185,13 @@ public class VM implements java.io.Serializable { * Arguments passed to the method call (must be {@link * java.io.Serializable}). */ - public AsyncInvocation invokeAsync(final Class c, + public AsyncInvocation invokeAsync(final Class targetClass, final String methodName, final Object[] args) { AsyncInvocation ai = - new AsyncInvocation(c, methodName, new Runnable() { + new AsyncInvocation(targetClass, methodName, new Runnable() { public void run() { - final Object o = invoke(c, methodName, args); + final Object o = invoke(targetClass, methodName, args); AsyncInvocation.setReturnValue(o); } }); @@ -282,12 +282,14 @@ public class VM implements java.io.Serializable { } /** - * Invokes the runrun method of a {@link Runnable} in this * VM. If the invocation throws AssertionFailedError, and repeatTimeoutMs * is >0, the run method is invoked repeatedly until it * either succeeds, or repeatTimeoutMs has passed. The AssertionFailedError * is thrown back to the sender of this method if run has not * completed successfully before repeatTimeoutMs has passed. + * + * @deprecated Please use {@link com.jayway.awaitility.Awaitility} with {@link #invoke(SerializableCallableIF)} instead. */ public void invokeRepeatingIfNecessary(RepeatableRunnable o, long repeatTimeoutMs) { invoke(o, "runRepeatingIfNecessary", new Object[] {new Long(repeatTimeoutMs)}); @@ -374,15 +376,15 @@ public class VM implements java.io.Serializable { /** * Invokes the main method of a given class * - * @param c + * @param targetClass * The class on which to invoke the main method * @param args * The "command line" arguments to pass to the * main method */ - public void invokeMain(Class c, String[] args) { + public void invokeMain(Class targetClass, String[] args) { Object[] stupid = new Object[] { args }; - invoke(c, "main", stupid); + invoke(targetClass, "main", stupid); } /** @@ -1342,4 +1344,14 @@ public class VM implements java.io.Serializable { return DUnitEnv.get().getWorkingDirectory(this.getPid()); } + /** Return the total number of VMs on all hosts */ + public static int getVMCount() { + int count = 0; + for (int h = 0; h < Host.getHostCount(); h++) { + Host host = Host.getHost(h); + count += host.getVMCount(); + } + return count; + } + } http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/820cfd63/gemfire-core/src/test/java/com/gemstone/gemfire/test/dunit/Wait.java ---------------------------------------------------------------------- diff --git a/gemfire-core/src/test/java/com/gemstone/gemfire/test/dunit/Wait.java b/gemfire-core/src/test/java/com/gemstone/gemfire/test/dunit/Wait.java new file mode 100755 index 0000000..3e218df --- /dev/null +++ b/gemfire-core/src/test/java/com/gemstone/gemfire/test/dunit/Wait.java @@ -0,0 +1,204 @@ +/* + * 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; + +import static org.junit.Assert.fail; +import static com.gemstone.gemfire.test.dunit.Jitter.*; + +import org.apache.logging.log4j.Logger; + +import com.gemstone.gemfire.internal.cache.LocalRegion; +import com.gemstone.gemfire.internal.logging.LogService; + +/** + * Wait provides static utility methods to wait for some + * asynchronous action with intermittent polling. + * + * These methods can be used directly: Wait.waitForCriterion(...), + * however, they are intended to be referenced through static import: + * + *
+ * import static com.gemstone.gemfire.test.dunit.Wait.*;
+ *    ...
+ *    waitForCriterion(...);
+ * 
+ * + * Extracted from DistributedTestCase. + * + * @deprecated Use {@link com.jayway.awaitility.Awaitility} instead. + */ +@Deprecated +public class Wait { + + private static final Logger logger = LogService.getLogger(); + + protected Wait() { + } + + /** + * Pause for a default interval (250 milliseconds). + * + * @deprecated Please use {@link com.jayway.awaitility.Awaitility} instead. + */ + public static void pause() { + pause(250); + } + + /** + * Pause for the specified milliseconds. Make sure system clock has advanced + * by the specified number of millis before returning. + * + * @deprecated Please use {@link com.jayway.awaitility.Awaitility} instead. + */ + public static final void pause(final int milliseconds) { + if (milliseconds >= 1000 || logger.isDebugEnabled()) { // check for debug but log at info + logger.info("Pausing for {} ms...", milliseconds); + } + final long target = System.currentTimeMillis() + milliseconds; + try { + for (;;) { + long msLeft = target - System.currentTimeMillis(); + if (msLeft <= 0) { + break; + } + Thread.sleep(msLeft); + } + } + catch (InterruptedException e) { + Assert.fail("interrupted", e); + } + } + + /** + * Wait until given criterion is met + * + * @param waitCriterion criterion to wait on + * @param timeoutMillis total time to wait, in milliseconds + * @param pollingInterval pause interval between waits + * @param throwOnTimeout if false, don't generate an error + * @deprecated Please use {@link com.jayway.awaitility.Awaitility} instead. + */ + @Deprecated + public static void waitForCriterion(final WaitCriterion waitCriterion, final long timeoutMillis, final long pollingInterval, final boolean throwOnTimeout) { + long waitThisTime = jitterInterval(pollingInterval); + final long tilt = System.currentTimeMillis() + timeoutMillis; + for (;;) { + if (waitCriterion.done()) { + return; // success + } + if (waitCriterion instanceof StoppableWaitCriterion) { + StoppableWaitCriterion ev2 = (StoppableWaitCriterion)waitCriterion; + if (ev2.stopWaiting()) { + if (throwOnTimeout) { + fail("stopWaiting returned true: " + waitCriterion.description()); + } + return; + } + } + + // Calculate time left + long timeLeft = tilt - System.currentTimeMillis(); + if (timeLeft <= 0) { + if (!throwOnTimeout) { + return; // not an error, but we're done + } + fail("Event never occurred after " + timeoutMillis + " ms: " + waitCriterion.description()); + } + + if (waitThisTime > timeLeft) { + waitThisTime = timeLeft; + } + + // Wait a little bit + Thread.yield(); + try { + Thread.sleep(waitThisTime); + } catch (InterruptedException e) { + fail("interrupted"); + } + } + } + + /** + * Blocks until the clock used for expiration moves forward. + * + * @param cacheTimeMillisSource region that provides cacheTimeMillis + * @return the last time stamp observed + * @deprecated Please use {@link com.jayway.awaitility.Awaitility} instead. + */ + public static final long waitForExpiryClockToChange(final LocalRegion cacheTimeMillisSource) { + return waitForExpiryClockToChange(cacheTimeMillisSource, cacheTimeMillisSource.cacheTimeMillis()); + } + + /** + * Blocks until the clock used for expiration moves forward. + * + * @param cacheTimeMillisSource region that provides cacheTimeMillis + * @param baseTime the timestamp that the clock must exceed + * @return the last time stamp observed + * @deprecated Please use {@link com.jayway.awaitility.Awaitility} instead. + */ + public static final long waitForExpiryClockToChange(final LocalRegion cacheTimeMillisSource, final long baseTime) { + long nowTime; + do { + Thread.yield(); + nowTime = cacheTimeMillisSource.cacheTimeMillis(); + } while ((nowTime - baseTime) <= 0L); + return nowTime; + } + + /** + * Wait on a mutex. This is done in a loop in order to address the + * "spurious wakeup" "feature" in Java. + * + * @param waitCriterion condition to test + * @param mutex object to lock and wait on + * @param milliseconds total amount of time to wait + * @param pollingInterval interval to pause for the wait + * @param throwOnTimeout if false, no error is thrown. + * @deprecated Please use {@link com.jayway.awaitility.Awaitility} instead. + */ + public static void waitMutex(final WaitCriterion waitCriterion, final Object mutex, final long milliseconds, final long pollingInterval, final boolean throwOnTimeout) { + final long tilt = System.currentTimeMillis() + milliseconds; + long waitThisTime = jitterInterval(pollingInterval); + synchronized (mutex) { + for (;;) { + if (waitCriterion.done()) { + break; + } + + long timeLeft = tilt - System.currentTimeMillis(); + if (timeLeft <= 0) { + if (!throwOnTimeout) { + return; // not an error, but we're done + } + fail("Event never occurred after " + milliseconds + " ms: " + waitCriterion.description()); + } + + if (waitThisTime > timeLeft) { + waitThisTime = timeLeft; + } + + try { + mutex.wait(waitThisTime); + } catch (InterruptedException e) { + fail("interrupted"); + } + } // for + } // synchronized + } +} http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/820cfd63/gemfire-core/src/test/java/com/gemstone/gemfire/test/dunit/WaitCriterion.java ---------------------------------------------------------------------- diff --git a/gemfire-core/src/test/java/com/gemstone/gemfire/test/dunit/WaitCriterion.java b/gemfire-core/src/test/java/com/gemstone/gemfire/test/dunit/WaitCriterion.java new file mode 100755 index 0000000..7575f8c --- /dev/null +++ b/gemfire-core/src/test/java/com/gemstone/gemfire/test/dunit/WaitCriterion.java @@ -0,0 +1,33 @@ +/* + * 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; + +/** + * Defines an asynchronous criterion to wait for by invoking a method in + * {@link Wait}. + * + * Extracted from DistributedTestCase. + * + * @deprecated Use {@link com.jayway.awaitility.Awaitility} instead. + */ +public interface WaitCriterion { + + public boolean done(); + + public String description(); + +} http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/820cfd63/gemfire-core/src/test/java/com/gemstone/gemfire/test/dunit/rules/DistributedDisconnectRule.java ---------------------------------------------------------------------- diff --git a/gemfire-core/src/test/java/com/gemstone/gemfire/test/dunit/rules/DistributedDisconnectRule.java b/gemfire-core/src/test/java/com/gemstone/gemfire/test/dunit/rules/DistributedDisconnectRule.java new file mode 100755 index 0000000..125fc06 --- /dev/null +++ b/gemfire-core/src/test/java/com/gemstone/gemfire/test/dunit/rules/DistributedDisconnectRule.java @@ -0,0 +1,121 @@ +/* + * 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.rules; + +// TODO: import static com.gemstone.gemfire.test.dunit.DistributedTestRule.*; + +import com.gemstone.gemfire.test.dunit.SerializableRunnable; + +@SuppressWarnings("serial") +public class DistributedDisconnectRule extends DistributedExternalResource { + + private final boolean disconnectBefore; + private final boolean disconnectAfter; + private final boolean disconnectBeforeClass; + private final boolean disconnectAfterClass; + + public static Builder builder() { + return new Builder(); + } + + public DistributedDisconnectRule(final Builder builder) { + this(new RemoteInvoker(), builder); + } + + public DistributedDisconnectRule(final RemoteInvoker invoker, final Builder builder) { + super(invoker); + this.disconnectBeforeClass = builder.disconnectBeforeClass; + this.disconnectAfterClass = builder.disconnectAfterClass; + this.disconnectBefore = builder.disconnectBefore; + this.disconnectAfter = builder.disconnectAfter; + } + + @Override + protected void before() throws Throwable { + if (this.disconnectBefore) { + invoker().invokeEverywhere(serializableRunnable()); + } + } + + @Override + protected void after() throws Throwable { + if (this.disconnectAfter) { + invoker().invokeEverywhere(serializableRunnable()); + } + } + + @Override + protected void beforeClass() throws Throwable { + if (this.disconnectBeforeClass) { + invoker().invokeEverywhere(serializableRunnable()); + } + } + + @Override + protected void afterClass() throws Throwable { + if (this.disconnectAfterClass) { + invoker().invokeEverywhere(serializableRunnable()); + } + } + + private static SerializableRunnable serializableRunnable() { + return new SerializableRunnable() { + @Override + public void run() { + // TODO: disconnectFromDS(); + } + }; + } + + /** + * Builds an instance of DistributedDisconnectRule + * + * @author Kirk Lund + */ + public static class Builder { + private boolean disconnectBeforeClass; + private boolean disconnectAfterClass; + private boolean disconnectBefore; + private boolean disconnectAfter; + + public Builder() {} + + public Builder disconnectBeforeClass(final boolean disconnectBeforeClass) { + this.disconnectBeforeClass = disconnectBeforeClass; + return this; + } + + public Builder disconnectBefore(final boolean disconnectBefore) { + this.disconnectBefore = disconnectBefore; + return this; + } + + public Builder disconnectAfterClass(final boolean disconnectAfterClass) { + this.disconnectAfterClass = disconnectAfterClass; + return this; + } + + public Builder disconnectAfter(final boolean disconnectAfter) { + this.disconnectAfter = disconnectAfter; + return this; + } + + public DistributedDisconnectRule build() { + return new DistributedDisconnectRule(this); + } + } +} http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/820cfd63/gemfire-core/src/test/java/com/gemstone/gemfire/test/dunit/rules/DistributedExternalResource.java ---------------------------------------------------------------------- diff --git a/gemfire-core/src/test/java/com/gemstone/gemfire/test/dunit/rules/DistributedExternalResource.java b/gemfire-core/src/test/java/com/gemstone/gemfire/test/dunit/rules/DistributedExternalResource.java new file mode 100755 index 0000000..d3b7319 --- /dev/null +++ b/gemfire-core/src/test/java/com/gemstone/gemfire/test/dunit/rules/DistributedExternalResource.java @@ -0,0 +1,58 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.gemstone.gemfire.test.dunit.rules; + +import com.gemstone.gemfire.test.junit.rules.SerializableExternalResource; + +@SuppressWarnings("serial") +public class DistributedExternalResource extends SerializableExternalResource { + + private final RemoteInvoker invoker; + + public DistributedExternalResource() { + this(new RemoteInvoker()); + } + + public DistributedExternalResource(final RemoteInvoker invoker) { + super(); + this.invoker = invoker; + } + + protected RemoteInvoker invoker() { + return this.invoker; + } + + @Override + protected void before() throws Throwable { + // do nothing + } + + @Override + protected void after() throws Throwable { + // do nothing + } + + @Override + protected void beforeClass() throws Throwable { + // do nothing + } + + @Override + protected void afterClass() throws Throwable { + // do nothing + } +} http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/820cfd63/gemfire-core/src/test/java/com/gemstone/gemfire/test/dunit/rules/DistributedRestoreSystemProperties.java ---------------------------------------------------------------------- diff --git a/gemfire-core/src/test/java/com/gemstone/gemfire/test/dunit/rules/DistributedRestoreSystemProperties.java b/gemfire-core/src/test/java/com/gemstone/gemfire/test/dunit/rules/DistributedRestoreSystemProperties.java new file mode 100755 index 0000000..1711b21 --- /dev/null +++ b/gemfire-core/src/test/java/com/gemstone/gemfire/test/dunit/rules/DistributedRestoreSystemProperties.java @@ -0,0 +1,74 @@ +/* + * 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.rules; + +import static java.lang.System.getProperties; +import static java.lang.System.setProperties; + +import java.util.Properties; + +import org.junit.contrib.java.lang.system.RestoreSystemProperties; + +import com.gemstone.gemfire.test.dunit.SerializableRunnable; +import com.gemstone.gemfire.test.junit.rules.SerializableTestRule; + +/** + * Distributed version of RestoreSystemProperties which affects all DUnit + * JVMs including the Locator JVM. + * + * @author Kirk Lund + */ +@SuppressWarnings("serial") +public class DistributedRestoreSystemProperties extends RestoreSystemProperties implements SerializableTestRule { + + private static volatile Properties originalProperties; + + private final RemoteInvoker invoker; + + public DistributedRestoreSystemProperties() { + this(new RemoteInvoker()); + } + + public DistributedRestoreSystemProperties(final RemoteInvoker invoker) { + super(); + this.invoker = invoker; + } + + @Override + protected void before() throws Throwable { + super.before(); + this.invoker.remoteInvokeInEveryVMAndLocator(new SerializableRunnable() { + @Override + public void run() { + originalProperties = getProperties(); + setProperties(new Properties(originalProperties)); + } + }); + } + + @Override + protected void after() { + super.after(); + this.invoker.remoteInvokeInEveryVMAndLocator(new SerializableRunnable() { + @Override + public void run() { + setProperties(originalProperties); + originalProperties = null; + } + }); + } +} http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/820cfd63/gemfire-core/src/test/java/com/gemstone/gemfire/test/dunit/rules/RemoteInvoker.java ---------------------------------------------------------------------- diff --git a/gemfire-core/src/test/java/com/gemstone/gemfire/test/dunit/rules/RemoteInvoker.java b/gemfire-core/src/test/java/com/gemstone/gemfire/test/dunit/rules/RemoteInvoker.java new file mode 100755 index 0000000..e7e523f --- /dev/null +++ b/gemfire-core/src/test/java/com/gemstone/gemfire/test/dunit/rules/RemoteInvoker.java @@ -0,0 +1,39 @@ +/* + * 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.rules; + +import static com.gemstone.gemfire.test.dunit.Invoke.invokeInEveryVM; +import static com.gemstone.gemfire.test.dunit.Invoke.invokeInLocator; + +import java.io.Serializable; + +import com.gemstone.gemfire.test.dunit.SerializableRunnable; + +@SuppressWarnings("serial") +public class RemoteInvoker implements Serializable { + + public void invokeEverywhere(final SerializableRunnable runnable) { + runnable.run(); + invokeInEveryVM(runnable); + invokeInLocator(runnable); + } + + public void remoteInvokeInEveryVMAndLocator(final SerializableRunnable runnable) { + invokeInEveryVM(runnable); + invokeInLocator(runnable); + } +} http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/820cfd63/gemfire-core/src/test/java/com/gemstone/gemfire/test/dunit/tests/BasicDUnitTest.java ---------------------------------------------------------------------- diff --git a/gemfire-core/src/test/java/com/gemstone/gemfire/test/dunit/tests/BasicDUnitTest.java b/gemfire-core/src/test/java/com/gemstone/gemfire/test/dunit/tests/BasicDUnitTest.java index 18e5f72..f9d033c 100644 --- a/gemfire-core/src/test/java/com/gemstone/gemfire/test/dunit/tests/BasicDUnitTest.java +++ b/gemfire-core/src/test/java/com/gemstone/gemfire/test/dunit/tests/BasicDUnitTest.java @@ -18,6 +18,7 @@ package com.gemstone.gemfire.test.dunit.tests; 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; @@ -117,14 +118,14 @@ public class BasicDUnitTest extends DistributedTestCase { ai.join(); // TODO shouldn't we call fail() here? if (ai.exceptionOccurred()) { - fail("remoteBind failed", ai.getException()); + Assert.fail("remoteBind failed", ai.getException()); } ai = vm.invokeAsync(this.getClass(), "remoteValidateBind", new Object[] {name, value }); ai.join(); if (ai.exceptionOccurred()) { - fail("remoteValidateBind failed", ai.getException()); + Assert.fail("remoteValidateBind failed", ai.getException()); } } http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/820cfd63/gemfire-core/src/test/java/com/gemstone/gemfire/test/dunit/tests/GetDefaultDiskStoreNameDUnitTest.java ---------------------------------------------------------------------- diff --git a/gemfire-core/src/test/java/com/gemstone/gemfire/test/dunit/tests/GetDefaultDiskStoreNameDUnitTest.java b/gemfire-core/src/test/java/com/gemstone/gemfire/test/dunit/tests/GetDefaultDiskStoreNameDUnitTest.java new file mode 100755 index 0000000..99dcc29 --- /dev/null +++ b/gemfire-core/src/test/java/com/gemstone/gemfire/test/dunit/tests/GetDefaultDiskStoreNameDUnitTest.java @@ -0,0 +1,67 @@ +/* + * 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.experimental.categories.Category; + +import com.gemstone.gemfire.internal.cache.GemFireCacheImpl; +import com.gemstone.gemfire.test.dunit.DistributedTestCase; +import com.gemstone.gemfire.test.dunit.Host; +import com.gemstone.gemfire.test.junit.categories.DistributedTest; + +@SuppressWarnings("serial") +@Category(DistributedTest.class) +public class GetDefaultDiskStoreNameDUnitTest extends DistributedTestCase { + + public GetDefaultDiskStoreNameDUnitTest(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/820cfd63/gemfire-core/src/test/java/com/gemstone/gemfire/test/dunit/tests/GetTestMethodNameDUnitTest.java ---------------------------------------------------------------------- diff --git a/gemfire-core/src/test/java/com/gemstone/gemfire/test/dunit/tests/GetTestMethodNameDUnitTest.java b/gemfire-core/src/test/java/com/gemstone/gemfire/test/dunit/tests/GetTestMethodNameDUnitTest.java new file mode 100755 index 0000000..9bad472 --- /dev/null +++ b/gemfire-core/src/test/java/com/gemstone/gemfire/test/dunit/tests/GetTestMethodNameDUnitTest.java @@ -0,0 +1,54 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.gemstone.gemfire.test.dunit.tests; + +import static org.assertj.core.api.Assertions.*; + +import org.junit.experimental.categories.Category; + +import com.gemstone.gemfire.test.dunit.DistributedTestCase; +import com.gemstone.gemfire.test.dunit.Host; +import com.gemstone.gemfire.test.junit.categories.DistributedTest; + +@SuppressWarnings("serial") +@Category(DistributedTest.class) +public class GetTestMethodNameDUnitTest extends DistributedTestCase { + + public GetTestMethodNameDUnitTest(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/820cfd63/gemfire-core/src/test/java/hydra/MethExecutor.java ---------------------------------------------------------------------- diff --git a/gemfire-core/src/test/java/hydra/MethExecutor.java b/gemfire-core/src/test/java/hydra/MethExecutor.java index c38a803..8aaf3dc 100644 --- a/gemfire-core/src/test/java/hydra/MethExecutor.java +++ b/gemfire-core/src/test/java/hydra/MethExecutor.java @@ -147,6 +147,7 @@ public class MethExecutor { } sb.append("] in class "); sb.append(c.getName()); + sb.append(" methods=" + matchingMethods); throw new NoSuchMethodException(sb.toString()); } else return (Method) matchingMethods.get(0); http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/820cfd63/gemfire-cq/src/test/java/com/gemstone/gemfire/cache/query/cq/dunit/CqDataDUnitTest.java ---------------------------------------------------------------------- diff --git a/gemfire-cq/src/test/java/com/gemstone/gemfire/cache/query/cq/dunit/CqDataDUnitTest.java b/gemfire-cq/src/test/java/com/gemstone/gemfire/cache/query/cq/dunit/CqDataDUnitTest.java index c26282c..5850e6f 100644 --- a/gemfire-cq/src/test/java/com/gemstone/gemfire/cache/query/cq/dunit/CqDataDUnitTest.java +++ b/gemfire-cq/src/test/java/com/gemstone/gemfire/cache/query/cq/dunit/CqDataDUnitTest.java @@ -38,11 +38,17 @@ import com.gemstone.gemfire.cache30.CacheSerializableRunnable; import com.gemstone.gemfire.cache30.CacheTestCase; import com.gemstone.gemfire.cache30.CertifiableTestCacheListener; import com.gemstone.gemfire.internal.AvailablePortHelper; +import com.gemstone.gemfire.test.dunit.Assert; import com.gemstone.gemfire.test.dunit.AsyncInvocation; -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.NetworkUtils; import com.gemstone.gemfire.test.dunit.SerializableRunnable; +import com.gemstone.gemfire.test.dunit.ThreadUtils; import com.gemstone.gemfire.test.dunit.VM; +import com.gemstone.gemfire.test.dunit.Wait; /** * This class tests the ContiunousQuery mechanism in GemFire. @@ -64,7 +70,7 @@ public class CqDataDUnitTest extends CacheTestCase { // avoid IllegalStateException from HandShake by connecting all vms tor // system before creating ConnectionPools getSystem(); - invokeInEveryVM(new SerializableRunnable("getSystem") { + Invoke.invokeInEveryVM(new SerializableRunnable("getSystem") { public void run() { getSystem(); } @@ -90,7 +96,7 @@ public class CqDataDUnitTest extends CacheTestCase { final int port = server.invokeInt(CqQueryDUnitTest.class, "getCacheServerPort"); - final String host0 = getServerHostName(server.getHost()); + final String host0 = NetworkUtils.getServerHostName(server.getHost()); // Create client. cqDUnitTest.createClient(client, port, host0); @@ -132,11 +138,11 @@ public class CqDataDUnitTest extends CacheTestCase { VM client = host.getVM(3); //Killing servers can cause this message on the client side. - addExpectedException("Could not find any server"); + IgnoredException.addIgnoredException("Could not find any server"); cqDUnitTest.createServer(server1); final int port1 = server1.invokeInt(CqQueryDUnitTest.class, "getCacheServerPort"); - final String host0 = getServerHostName(server1.getHost()); + final String host0 = NetworkUtils.getServerHostName(server1.getHost()); final int[] ports = AvailablePortHelper.getRandomAvailableTCPPorts(2); @@ -156,7 +162,7 @@ public class CqDataDUnitTest extends CacheTestCase { cqDUnitTest.executeCQ(client, "testCQHAWithState_" + i, false, null); } - pause(1 * 1000); + Wait.pause(1 * 1000); int size = 10; @@ -178,7 +184,7 @@ public class CqDataDUnitTest extends CacheTestCase { // Close server1. // To maintain the redundancy; it will make connection to endpoint-3. cqDUnitTest.closeServer(server1); - pause(3 * 1000); + Wait.pause(3 * 1000); // UPDATE-1. @@ -196,12 +202,12 @@ public class CqDataDUnitTest extends CacheTestCase { //Stop cq. cqDUnitTest.stopCQ(client, "testCQHAWithState_0"); - pause(2 * 1000); + Wait.pause(2 * 1000); // UPDATE with stop. cqDUnitTest.createServer(server3, ports[1]); server3.invokeInt(CqQueryDUnitTest.class, "getCacheServerPort"); - pause(2 * 1000); + Wait.pause(2 * 1000); cqDUnitTest.clearCQListenerEvents(client, "testCQHAWithState_0"); @@ -217,7 +223,7 @@ public class CqDataDUnitTest extends CacheTestCase { } cqDUnitTest.executeCQ(client, "testCQHAWithState_0", false, null); - pause(2 * 1000); + Wait.pause(2 * 1000); // Update - 2 cqDUnitTest.createValues(server3, cqDUnitTest.regions[0], 10); @@ -253,7 +259,7 @@ public class CqDataDUnitTest extends CacheTestCase { cqDUnitTest.createServer(server, 0, true); final int port = server.invokeInt(CqQueryDUnitTest.class, "getCacheServerPort"); - final String host0 = getServerHostName(server.getHost()); + final String host0 = NetworkUtils.getServerHostName(server.getHost()); // Create client. cqDUnitTest.createClient(client, port, host0); @@ -328,7 +334,7 @@ public class CqDataDUnitTest extends CacheTestCase { /* Create Server and Client */ cqDUnitTest.createServer(server); final int port = server.invokeInt(CqQueryDUnitTest.class, "getCacheServerPort"); - final String host0 = getServerHostName(server.getHost()); + final String host0 = NetworkUtils.getServerHostName(server.getHost()); cqDUnitTest.createClient(client1, port, host0); cqDUnitTest.createClient(client2, port, host0); @@ -397,7 +403,7 @@ public class CqDataDUnitTest extends CacheTestCase { cqDUnitTest.createServer(server2, 0, false, MirrorType.KEYS); final int port1 = server1.invokeInt(CqQueryDUnitTest.class, "getCacheServerPort"); - final String host0 = getServerHostName(server1.getHost()); + final String host0 = NetworkUtils.getServerHostName(server1.getHost()); cqDUnitTest.createClient(client, port1, host0); @@ -405,7 +411,7 @@ public class CqDataDUnitTest extends CacheTestCase { cqDUnitTest.createCQ(client, "testCQWithLoad_0", cqDUnitTest.cqs[0]); cqDUnitTest.executeCQ(client, "testCQWithLoad_0", false, null); - pause(2 * 1000); + Wait.pause(2 * 1000); final int size = 10; @@ -445,7 +451,7 @@ public class CqDataDUnitTest extends CacheTestCase { final int evictionThreshold = 1; server1.invoke(new CacheSerializableRunnable("Create Cache Server") { public void run2() throws CacheException { - getLogWriter().info("### Create Cache Server. ###"); + LogWriterUtils.getLogWriter().info("### Create Cache Server. ###"); AttributesFactory factory = new AttributesFactory(); factory.setScope(Scope.DISTRIBUTED_ACK); factory.setDataPolicy(DataPolicy.REPLICATE); @@ -458,22 +464,22 @@ public class CqDataDUnitTest extends CacheTestCase { for (int i = 0; i < cqDUnitTest.regions.length; i++) { Region region = createRegion(cqDUnitTest.regions[i], factory.createRegionAttributes()); // Set CacheListener. - region.getAttributesMutator().setCacheListener(new CertifiableTestCacheListener(getLogWriter())); + region.getAttributesMutator().setCacheListener(new CertifiableTestCacheListener(LogWriterUtils.getLogWriter())); } - pause(2000); + Wait.pause(2000); try { cqDUnitTest.startBridgeServer(0, true); } catch (Exception ex) { - fail("While starting CacheServer", ex); + Assert.fail("While starting CacheServer", ex); } - pause(2000); + Wait.pause(2000); } }); final int port1 = server1.invokeInt(CqQueryDUnitTest.class, "getCacheServerPort"); - final String host0 = getServerHostName(server1.getHost()); + final String host0 = NetworkUtils.getServerHostName(server1.getHost()); cqDUnitTest.createClient(client, port1, host0); @@ -487,7 +493,7 @@ public class CqDataDUnitTest extends CacheTestCase { cqDUnitTest.executeCQ(client, "testCQWithEviction_0", false, "CqException"); - pause(1 * 1000); + Wait.pause(1 * 1000); // Update VALUES. cqDUnitTest.createValues(server1, cqDUnitTest.regions[0], size); @@ -515,7 +521,7 @@ public class CqDataDUnitTest extends CacheTestCase { cqDUnitTest.createServer(server1, 0, false, MirrorType.KEYS_VALUES); final int port1 = server1.invokeInt(CqQueryDUnitTest.class, "getCacheServerPort"); - final String serverHost = getServerHostName(server1.getHost()); + final String serverHost = NetworkUtils.getServerHostName(server1.getHost()); final String[] regions = cqDUnitTest.regions; final int[] serverPorts = new int[] {port1}; @@ -524,7 +530,7 @@ public class CqDataDUnitTest extends CacheTestCase { SerializableRunnable createClientWithPool = new CacheSerializableRunnable("createClientWithPool") { public void run2() throws CacheException { - getLogWriter().info("### Create Client. ###"); + LogWriterUtils.getLogWriter().info("### Create Client. ###"); // Initialize CQ Service. try { getCache().getQueryService(); @@ -538,7 +544,7 @@ public class CqDataDUnitTest extends CacheTestCase { ClientServerTestCase.configureConnectionPool(regionFactory, serverHost, serverPorts[0], -1, false, -1, -1, null); for (int i=0; i < regions.length; i++) { createRegion(regions[i], regionFactory.create() ); - getLogWriter().info("### Successfully Created Region on Client :" + regions[i]); + LogWriterUtils.getLogWriter().info("### Successfully Created Region on Client :" + regions[i]); } } }; @@ -573,7 +579,7 @@ public class CqDataDUnitTest extends CacheTestCase { cqDUnitTest.createServer(server1, 0, false, MirrorType.KEYS_VALUES); final int port1 = server1.invokeInt(CqQueryDUnitTest.class, "getCacheServerPort"); - final String serverHost = getServerHostName(server1.getHost()); + final String serverHost = NetworkUtils.getServerHostName(server1.getHost()); final String[] regions = cqDUnitTest.regions; final int[] serverPorts = new int[] {port1}; @@ -582,7 +588,7 @@ public class CqDataDUnitTest extends CacheTestCase { SerializableRunnable createClientWithPool = new CacheSerializableRunnable("createClientWithPool") { public void run2() throws CacheException { - getLogWriter().info("### Create Client. ###"); + LogWriterUtils.getLogWriter().info("### Create Client. ###"); //Region region1 = null; // Initialize CQ Service. try { @@ -598,7 +604,7 @@ public class CqDataDUnitTest extends CacheTestCase { for (int i=0; i < regions.length; i++) { createRegion(regions[i], regionFactory.createRegionAttributes()); - getLogWriter().info("### Successfully Created Region on Client :" + regions[i]); + LogWriterUtils.getLogWriter().info("### Successfully Created Region on Client :" + regions[i]); } } }; @@ -628,7 +634,7 @@ public class CqDataDUnitTest extends CacheTestCase { cqDUnitTest.createServer(server1, 0, false, MirrorType.KEYS_VALUES); final int port1 = server1.invokeInt(CqQueryDUnitTest.class, "getCacheServerPort"); - final String serverHost = getServerHostName(server1.getHost()); + final String serverHost = NetworkUtils.getServerHostName(server1.getHost()); final String[] regions = cqDUnitTest.regions; final int[] serverPorts = new int[] {port1}; @@ -637,7 +643,7 @@ public class CqDataDUnitTest extends CacheTestCase { SerializableRunnable createClientWithConnectionPool = new CacheSerializableRunnable("createClientWithConnectionPool") { public void run2() throws CacheException { - getLogWriter().info("### Create Client. ###"); + LogWriterUtils.getLogWriter().info("### Create Client. ###"); //Region region1 = null; // Initialize CQ Service. try { @@ -652,7 +658,7 @@ public class CqDataDUnitTest extends CacheTestCase { ClientServerTestCase.configureConnectionPool(regionFactory, serverHost, serverPorts[0], -1, true, -1, -1, null); for (int i=0; i < regions.length; i++) { createRegion(regions[i], regionFactory.createRegionAttributes()); - getLogWriter().info("### Successfully Created Region on Client :" + regions[i]); + LogWriterUtils.getLogWriter().info("### Successfully Created Region on Client :" + regions[i]); } } }; @@ -682,7 +688,7 @@ public class CqDataDUnitTest extends CacheTestCase { cqDUnitTest.createServer(server1, 0, false, MirrorType.KEYS_VALUES); final int port1 = server1.invokeInt(CqQueryDUnitTest.class, "getCacheServerPort"); - final String serverHost = getServerHostName(server1.getHost()); + final String serverHost = NetworkUtils.getServerHostName(server1.getHost()); final String[] regions = cqDUnitTest.regions; final int[] serverPorts = new int[] {port1}; @@ -691,7 +697,7 @@ public class CqDataDUnitTest extends CacheTestCase { SerializableRunnable createClientWithPool = new CacheSerializableRunnable("createClientWithPool") { public void run2() throws CacheException { - getLogWriter().info("### Create Client. ###"); + LogWriterUtils.getLogWriter().info("### Create Client. ###"); //Region region1 = null; // Initialize CQ Service. try { @@ -708,7 +714,7 @@ public class CqDataDUnitTest extends CacheTestCase { for (int i=0; i < regions.length; i++) { createRegion(regions[i], regionFactory.createRegionAttributes()); - getLogWriter().info("### Successfully Created Region on Client :" + regions[i]); + LogWriterUtils.getLogWriter().info("### Successfully Created Region on Client :" + regions[i]); } } }; @@ -747,7 +753,7 @@ public class CqDataDUnitTest extends CacheTestCase { cqDUnitTest.createServer(server); final int port = server.invokeInt(CqQueryDUnitTest.class, "getCacheServerPort"); - final String host0 = getServerHostName(server.getHost()); + final String host0 = NetworkUtils.getServerHostName(server.getHost()); cqDUnitTest.createClient(client, port, host0); @@ -762,7 +768,7 @@ public class CqDataDUnitTest extends CacheTestCase { // Test for Event on Region Clear. server.invoke(new CacheSerializableRunnable("testRegionEvents"){ public void run2()throws CacheException { - getLogWriter().info("### Clearing the region on the server ###"); + LogWriterUtils.getLogWriter().info("### Clearing the region on the server ###"); Region region = getCache().getRegion("/root/" + cqDUnitTest.regions[0]); for (int i = 1; i <=5; i++) { region.put(CqQueryDUnitTest.KEY+i, new Portfolio(i)); @@ -776,7 +782,7 @@ public class CqDataDUnitTest extends CacheTestCase { // Test for Event on Region invalidate. server.invoke(new CacheSerializableRunnable("testRegionEvents"){ public void run2()throws CacheException { - getLogWriter().info("### Invalidate the region on the server ###"); + LogWriterUtils.getLogWriter().info("### Invalidate the region on the server ###"); Region region = getCache().getRegion("/root/" + cqDUnitTest.regions[0]); for (int i = 1; i <=5; i++) { region.put(CqQueryDUnitTest.KEY+i, new Portfolio(i)); @@ -790,7 +796,7 @@ public class CqDataDUnitTest extends CacheTestCase { // Test for Event on Region destroy. server.invoke(new CacheSerializableRunnable("testRegionEvents"){ public void run2()throws CacheException { - getLogWriter().info("### Destroying the region on the server ###"); + LogWriterUtils.getLogWriter().info("### Destroying the region on the server ###"); Region region = getCache().getRegion("/root/" + cqDUnitTest.regions[1]); for (int i = 1; i <=5; i++) { region.put(CqQueryDUnitTest.KEY+i, new Portfolio(i)); @@ -800,7 +806,7 @@ public class CqDataDUnitTest extends CacheTestCase { } }); - pause(1000); // wait for cq to close becuse of region destroy on server. + Wait.pause(1000); // wait for cq to close becuse of region destroy on server. //cqDUnitTest.waitForClose(client,"testRegionEvents_1"); cqDUnitTest.validateCQCount(client,1); @@ -828,7 +834,7 @@ public class CqDataDUnitTest extends CacheTestCase { final String cqName = "testEventsDuringQueryExecution_0"; cqDUnitTest.createServer(server); final int port = server.invokeInt(CqQueryDUnitTest.class, "getCacheServerPort"); - final String host0 = getServerHostName(server.getHost()); + final String host0 = NetworkUtils.getServerHostName(server.getHost()); // Initialize Client. cqDUnitTest.createClient(client, port, host0); @@ -937,7 +943,7 @@ public class CqDataDUnitTest extends CacheTestCase { }); //wait for 60 seconds for test to complete - DistributedTestCase.join(processCqs, 60 * 1000, getLogWriter()); + ThreadUtils.join(processCqs, 60 * 1000); // Close. cqDUnitTest.closeClient(client); @@ -968,7 +974,7 @@ public class CqDataDUnitTest extends CacheTestCase { cqDUnitTest.createServer(server); final int port = server.invokeInt(CqQueryDUnitTest.class, "getCacheServerPort"); - final String host0 = getServerHostName(server.getHost()); + final String host0 = NetworkUtils.getServerHostName(server.getHost()); // Initialize Client. cqDUnitTest.createClient(client, port, host0); @@ -1113,7 +1119,7 @@ public class CqDataDUnitTest extends CacheTestCase { }); //wait for 60 seconds for test to complete - DistributedTestCase.join(processCqs, 60 * 1000, getLogWriter()); + ThreadUtils.join(processCqs, 60 * 1000); // Close. cqDUnitTest.closeClient(client); cqDUnitTest.closeServer(server); http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/820cfd63/gemfire-cq/src/test/java/com/gemstone/gemfire/cache/query/cq/dunit/CqDataOptimizedExecuteDUnitTest.java ---------------------------------------------------------------------- diff --git a/gemfire-cq/src/test/java/com/gemstone/gemfire/cache/query/cq/dunit/CqDataOptimizedExecuteDUnitTest.java b/gemfire-cq/src/test/java/com/gemstone/gemfire/cache/query/cq/dunit/CqDataOptimizedExecuteDUnitTest.java index 45f61f8..e185af1 100644 --- a/gemfire-cq/src/test/java/com/gemstone/gemfire/cache/query/cq/dunit/CqDataOptimizedExecuteDUnitTest.java +++ b/gemfire-cq/src/test/java/com/gemstone/gemfire/cache/query/cq/dunit/CqDataOptimizedExecuteDUnitTest.java @@ -18,6 +18,8 @@ package com.gemstone.gemfire.cache.query.cq.dunit; import com.gemstone.gemfire.cache.query.internal.cq.CqServiceImpl; +import com.gemstone.gemfire.test.dunit.IgnoredException; +import com.gemstone.gemfire.test.dunit.Invoke; import com.gemstone.gemfire.test.dunit.SerializableRunnable; /** @@ -34,8 +36,8 @@ public class CqDataOptimizedExecuteDUnitTest extends CqDataDUnitTest{ super.setUp(); //We're seeing this on the server when the client //disconnects. - addExpectedException("Connection reset"); - invokeInEveryVM(new SerializableRunnable("getSystem") { + IgnoredException.addIgnoredException("Connection reset"); + Invoke.invokeInEveryVM(new SerializableRunnable("getSystem") { public void run() { CqServiceImpl.EXECUTE_QUERY_DURING_INIT = false; } @@ -43,12 +45,11 @@ public class CqDataOptimizedExecuteDUnitTest extends CqDataDUnitTest{ } @Override - public void tearDown2() throws Exception { - invokeInEveryVM(new SerializableRunnable("getSystem") { + protected final void preTearDownCacheTestCase() throws Exception { + Invoke.invokeInEveryVM(new SerializableRunnable("getSystem") { public void run() { CqServiceImpl.EXECUTE_QUERY_DURING_INIT = true; } }); - super.tearDown2(); } }