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 108A418129 for ; Fri, 29 Jan 2016 01:16:35 +0000 (UTC) Received: (qmail 34637 invoked by uid 500); 29 Jan 2016 01:16:35 -0000 Delivered-To: apmail-geode-commits-archive@geode.apache.org Received: (qmail 34597 invoked by uid 500); 29 Jan 2016 01:16:35 -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 34588 invoked by uid 99); 29 Jan 2016 01:16:34 -0000 Received: from Unknown (HELO spamd4-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 29 Jan 2016 01:16:34 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd4-us-west.apache.org (ASF Mail Server at spamd4-us-west.apache.org) with ESMTP id 6E706C17C6 for ; Fri, 29 Jan 2016 01:16:34 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd4-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: 1.227 X-Spam-Level: * X-Spam-Status: No, score=1.227 tagged_above=-999 required=6.31 tests=[KAM_ASCII_DIVIDERS=0.8, KAM_LAZY_DOMAIN_SECURITY=1, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, RP_MATCHES_RCVD=-0.554, URIBL_BLOCKED=0.001] autolearn=disabled Received: from mx1-eu-west.apache.org ([10.40.0.8]) by localhost (spamd4-us-west.apache.org [10.40.0.11]) (amavisd-new, port 10024) with ESMTP id 8J5oozdrpUV0 for ; Fri, 29 Jan 2016 01:16:22 +0000 (UTC) Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx1-eu-west.apache.org (ASF Mail Server at mx1-eu-west.apache.org) with SMTP id A8B9C31ACF for ; Fri, 29 Jan 2016 01:16:19 +0000 (UTC) Received: (qmail 31911 invoked by uid 99); 29 Jan 2016 01:16:18 -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; Fri, 29 Jan 2016 01:16:18 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id C9034E0B3A; Fri, 29 Jan 2016 01:16:18 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: dschneider@apache.org To: commits@geode.incubator.apache.org Date: Fri, 29 Jan 2016 01:16:20 -0000 Message-Id: <26edddb89f574109bc662c2254f439ec@git.apache.org> In-Reply-To: <7953555325cd412f9d6803766f987267@git.apache.org> References: <7953555325cd412f9d6803766f987267@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [03/52] [abbrv] incubator-geode git commit: GEODE-819: Move dunit to com.gemstone.gemfire.test.dunit http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/d89038db/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 new file mode 100644 index 0000000..ddc653b --- /dev/null +++ b/gemfire-core/src/test/java/com/gemstone/gemfire/test/dunit/VM.java @@ -0,0 +1,1345 @@ +/* + * 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.io.File; +import java.io.PrintWriter; +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; + +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 { + + /** The host on which this VM runs */ + private Host host; + + /** The process id of this VM */ + private int pid; + + /** The hydra client for this VM */ + private RemoteDUnitVMIF client; + + /** The state of this VM */ + private volatile boolean available; + + //////////////////// Constructors //////////////////// + + /** + * Creates a new VM that runs on a given host with a + * given process id. + */ + public VM(Host host, int pid, RemoteDUnitVMIF client) { + this.host = host; + this.pid = pid; + this.client = client; + this.available = true; + } + + ////////////////////// Accessors ////////////////////// + + /** + * Returns the host on which this VM runs + */ + public Host getHost() { + return this.host; + } + + /** + * Returns the process id of this VM + */ + public int getPid() { + return this.pid; + } + + ///////////////// Remote Method Invocation /////////////// + + /** + * Invokes a static zero-arg method with an {@link Object} or + * void return type in this VM. If the return type of + * the method is void, null is returned. + * + * @param c + * The class on which to invoke the method + * @param methodName + * The name of the method to invoke + * + * @throws RMIException + * 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]); + } + + /** + * Asynchronously invokes a static zero-arg method with an {@link + * Object} or void return type in this VM. If the + * return type of the method is void, null + * is returned. + * + * @param c + * 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); + } + + /** + * Invokes a static method with an {@link Object} or + * void return type in this VM. If the return type of + * the method is void, null is returned. + * + * @param c + * The class on which to invoke the method + * @param methodName + * The name of the method to invoke + * @param args + * Arguments passed to the method call (must be {@link + * java.io.Serializable}). + * + * @throws RMIException + * An exception occurred on while invoking the method in + * this VM + */ + public Object invoke(Class c, String methodName, Object[] args) { + if (!this.available) { + String s = "VM not available: " + this; + throw new RMIException(this, c.getName(), methodName, + new IllegalStateException(s)); + } + MethExecutorResult result = null; + int retryCount = 120; + do { + try { + result = this.client.executeMethodOnClass(c.getName(), methodName, args); + break; // out of while loop + } catch( RemoteException e ) { + boolean isWindows = false; + String os = System.getProperty("os.name"); + if (os != null) { + if (os.indexOf("Windows") != -1) { + isWindows = true; + } + } + if (isWindows && retryCount-- > 0) { + boolean interrupted = Thread.interrupted(); + try { Thread.sleep(1000); } catch (InterruptedException ignore) {interrupted = true;} + finally { + if (interrupted) { + Thread.currentThread().interrupt(); + } + } + } else { + throw new RMIException(this, c.getName(), methodName, e ); + } + } + } while (true); + + if (!result.exceptionOccurred()) { + return result.getResult(); + + } else { + Throwable thr = result.getException(); + throw new RMIException(this, c.getName(), methodName, thr, + result.getStackTrace()); + } + } + + /** + * Asynchronously invokes a static method with an {@link Object} or + * void return type in this VM. If the return type of + * the method is void, null is returned. + * + * @param c + * The class on which to invoke the method + * @param methodName + * The name of the method to invoke + * @param args + * Arguments passed to the method call (must be {@link + * java.io.Serializable}). + */ + public AsyncInvocation invokeAsync(final Class c, + final String methodName, + final Object[] args) { + AsyncInvocation ai = + new AsyncInvocation(c, methodName, new Runnable() { + public void run() { + final Object o = invoke(c, methodName, args); + AsyncInvocation.setReturnValue(o); + } + }); + ai.start(); + return ai; + } + + /** + * Asynchronously invokes an instance method with an {@link Object} or + * void return type in this VM. If the return type of + * the method is void, null is returned. + * + * @param o + * The object on which to invoke the method + * @param methodName + * The name of the method to invoke + * @param args + * Arguments passed to the method call (must be {@link + * java.io.Serializable}). + */ + public AsyncInvocation invokeAsync(final Object o, + final String methodName, + final Object[] args) { + AsyncInvocation ai = + new AsyncInvocation(o, methodName, new Runnable() { + public void run() { + final Object ret = invoke(o, methodName, args); + AsyncInvocation.setReturnValue(ret); + } + }); + ai.start(); + return ai; + } + + /** + * Invokes the run method of a {@link Runnable} in this + * VM. Recall that run takes no arguments and has no + * return value. + * + * @param r + * The Runnable to be run + * + * @see SerializableRunnable + */ + public AsyncInvocation invokeAsync(Runnable r) { + return invokeAsync(r, "run", new Object[0]); + } + + /** + * Invokes the call method of a {@link Runnable} in this + * VM. + * + * @param c + * The Callable to be run + * + * @see SerializableCallable + */ + public AsyncInvocation invokeAsync(Callable c) { + return invokeAsync(c, "call", new Object[0]); + } + + /** + * Invokes the run method of a {@link Runnable} in this + * VM. Recall that run takes no arguments and has no + * return value. + * + * @param r + * The Runnable to be run + * + * @see SerializableRunnable + */ + public void invoke(Runnable r) { + invoke(r, "run"); + } + + /** + * Invokes the run method of a {@link Runnable} in this + * VM. Recall that run takes no arguments and has no + * return value. + * + * @param c + * The Callable to be run + * + * @see SerializableCallable + */ + public Object invoke(Callable c) { + return invoke(c, "call"); + } + + /** + * Invokes the run0, 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. + */ + public void invokeRepeatingIfNecessary(RepeatableRunnable o, long repeatTimeoutMs) { + invoke(o, "runRepeatingIfNecessary", new Object[] {new Long(repeatTimeoutMs)}); + } + + /** + * Invokes an instance method with no arguments on an object that is + * serialized into this VM. The return type of the method can be + * either {@link Object} or void. If the return type + * of the method is void, null is + * returned. + * + * @param o + * The receiver of the method invocation + * @param methodName + * The name of the method to invoke + * + * @throws RMIException + * An exception occurred on while invoking the method in + * this VM + */ + public Object invoke(Object o, String methodName) { + return invoke(o, methodName, new Object[0]); + } + + /** + * Invokes an instance method on an object that is serialized into + * this VM. The return type of the method can be either {@link + * Object} or void. If the return type of the method + * is void, null is returned. + * + * @param o + * The receiver of the method invocation + * @param methodName + * The name of the method to invoke + * @param args + * Arguments passed to the method call (must be {@link + * java.io.Serializable}). + * + * @throws RMIException + * An exception occurred on while invoking the method in + * this VM + */ + public Object invoke(Object o, String methodName, Object[] args) { + if (!this.available) { + String s = "VM not available: " + this; + throw new RMIException(this, o.getClass().getName(), methodName, + new IllegalStateException(s)); + } + MethExecutorResult result = null; + int retryCount = 120; + do { + try { + if ( args == null ) + result = this.client.executeMethodOnObject(o, methodName); + else + result = this.client.executeMethodOnObject(o, methodName, args); + break; // out of while loop + } catch( RemoteException e ) { + if (retryCount-- > 0) { + boolean interrupted = Thread.interrupted(); + try { Thread.sleep(1000); } catch (InterruptedException ignore) {interrupted = true;} + finally { + if (interrupted) { + Thread.currentThread().interrupt(); + } + } + } else { + throw new RMIException(this, o.getClass().getName(), methodName, e ); + } + } + } while (true); + + if (!result.exceptionOccurred()) { + return result.getResult(); + + } else { + Throwable thr = result.getException(); + throw new RMIException(this, o.getClass().getName(), methodName, thr, + result.getStackTrace()); + } + } + + /** + * Invokes the main method of a given class + * + * @param c + * 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) { + Object[] stupid = new Object[] { args }; + invoke(c, "main", stupid); + } + + /** + * Asynchronously invokes the main method of a given + * class + * + * @param c + * The class on which to invoke the main method + * @param args + * The "command line" arguments to pass to the + * main method + */ + public AsyncInvocation invokeMainAsync(Class c, String[] args) { + Object[] stupid = new Object[] { args }; + return invokeAsync(c, "main", stupid); + } + + /** + * Invokes a static method with a boolean return type + * in this VM. + * + * @param c + * The class on which to invoke the method + * @param methodName + * The name of the method to invoke + * + * @throws IllegalArgumentException + * The method does not return a boolean + * @throws RMIException + * An exception occurred on while invoking the method in + * this VM + */ + public boolean invokeBoolean(Class c, String methodName) { + return invokeBoolean(c, methodName, new Object[0]); + } + + /** + * Invokes a static method with a boolean return type + * in this VM. + * + * @param c + * The class on which to invoke the method + * @param methodName + * The name of the method to invoke + * @param args + * Arguments passed to the method call (must be {@link + * java.io.Serializable}). + * + * @throws IllegalArgumentException + * The method does not return a boolean + * @throws RMIException + * An exception occurred on while invoking the method in + * this VM + */ + public boolean invokeBoolean(Class c, String methodName, Object[] args) { + Object result = invoke(c, methodName, args); + if (result == null) { + String s = "Method \"" + methodName + "\" in class \"" + + c.getName() + "\" returned null, expected a boolean"; + throw new IllegalArgumentException(s); + + } else if (result instanceof Boolean) { + return ((Boolean) result).booleanValue(); + + } else { + String s = "Method \"" + methodName + "\" in class \"" + + c.getName() + "\" returned a \"" + result.getClass().getName() + + "\" expected a boolean"; + throw new IllegalArgumentException(s); + } + } + + /** + * Invokes an instance method on an object that is serialized into + * this VM. The return type of the method is boolean. + * + * @param o + * The receiver of the method invocation + * @param methodName + * The name of the method to invoke + * + * @throws IllegalArgumentException + * The method does not return a boolean + * @throws RMIException + * An exception occurred on while invoking the method in + * this VM + */ + public boolean invokeBoolean(Object o, String methodName) { + return invokeBoolean(o, methodName, new Object[0]); + } + + /** + * Invokes an instance method on an object that is serialized into + * this VM. The return type of the method is boolean. + * + * @param o + * The receiver of the method invocation + * @param methodName + * The name of the method to invoke + * @param args + * Arguments passed to the method call (must be {@link + * java.io.Serializable}). + * + * @throws IllegalArgumentException + * The method does not return a boolean + * @throws RMIException + * An exception occurred on while invoking the method in + * this VM + */ + public boolean invokeBoolean(Object o, String methodName, Object[] args) { + Object result = invoke(o, methodName, args); + Class c = o.getClass(); + if (result == null) { + String s = "Method \"" + methodName + "\" in class \"" + + c.getName() + "\" returned null, expected a boolean"; + throw new IllegalArgumentException(s); + + } else if (result instanceof Boolean) { + return ((Boolean) result).booleanValue(); + + } else { + String s = "Method \"" + methodName + "\" in class \"" + + c.getName() + "\" returned a \"" + result.getClass().getName() + + "\" expected a boolean"; + throw new IllegalArgumentException(s); + } + } + + /** + * Invokes a static method with a char return type + * in this VM. + * + * @param c + * The class on which to invoke the method + * @param methodName + * The name of the method to invoke + * + * @throws IllegalArgumentException + * The method does not return a char + * @throws RMIException + * An exception occurred on while invoking the method in + * this VM + */ + public char invokeChar(Class c, String methodName) { + return invokeChar(c, methodName, new Object[0]); + } + + /** + * Invokes a static method with a char return type + * in this VM. + * + * @param c + * The class on which to invoke the method + * @param methodName + * The name of the method to invoke + * @param args + * Arguments passed to the method call (must be {@link + * java.io.Serializable}). + * + * @throws IllegalArgumentException + * The method does not return a char + * @throws RMIException + * An exception occurred on while invoking the method in + * this VM + */ + public char invokeChar(Class c, String methodName, Object[] args) { + Object result = invoke(c, methodName, args); + if (result == null) { + String s = "Method \"" + methodName + "\" in class \"" + + c.getName() + "\" returned null, expected a char"; + throw new IllegalArgumentException(s); + + } else if (result instanceof Character) { + return ((Character) result).charValue(); + + } else { + String s = "Method \"" + methodName + "\" in class \"" + + c.getName() + "\" returned a \"" + result.getClass().getName() + + "\" expected a char"; + throw new IllegalArgumentException(s); + } + } + + /** + * Invokes an instance method on an object that is serialized into + * this VM. The return type of the method is char. + * + * @param o + * The receiver of the method invocation + * @param methodName + * The name of the method to invoke + * + * @throws IllegalArgumentException + * The method does not return a char + * @throws RMIException + * An exception occurred on while invoking the method in + * this VM + */ + public char invokeChar(Object o, String methodName) { + return invokeChar(o, methodName, new Object[0]); + } + + /** + * Invokes an instance method on an object that is serialized into + * this VM. The return type of the method is char. + * + * @param o + * The receiver of the method invocation + * @param methodName + * The name of the method to invoke + * @param args + * Arguments passed to the method call (must be {@link + * java.io.Serializable}). + * + * @throws IllegalArgumentException + * The method does not return a char + * @throws RMIException + * An exception occurred on while invoking the method in + * this VM + */ + public char invokeChar(Object o, String methodName, Object[] args) { + Object result = invoke(o, methodName, args); + Class c = o.getClass(); + if (result == null) { + String s = "Method \"" + methodName + "\" in class \"" + + c.getName() + "\" returned null, expected a char"; + throw new IllegalArgumentException(s); + + } else if (result instanceof Character) { + return ((Character) result).charValue(); + + } else { + String s = "Method \"" + methodName + "\" in class \"" + + c.getName() + "\" returned a \"" + result.getClass().getName() + + "\" expected a char"; + throw new IllegalArgumentException(s); + } + } + + /** + * Invokes a static method with a byte return type + * in this VM. + * + * @param c + * The class on which to invoke the method + * @param methodName + * The name of the method to invoke + * + * @throws IllegalArgumentException + * The method does not return a byte + * @throws RMIException + * An exception occurred on while invoking the method in + * this VM + */ + public byte invokeByte(Class c, String methodName) { + return invokeByte(c, methodName, new Object[0]); + } + + /** + * Invokes a static method with a byte return type + * in this VM. + * + * @param c + * The class on which to invoke the method + * @param methodName + * The name of the method to invoke + * @param args + * Arguments passed to the method call (must be {@link + * java.io.Serializable}). + * + * @throws IllegalArgumentException + * The method does not return a byte + * @throws RMIException + * An exception occurred on while invoking the method in + * this VM + */ + public byte invokeByte(Class c, String methodName, Object[] args) { + Object result = invoke(c, methodName, args); + if (result == null) { + String s = "Method \"" + methodName + "\" in class \"" + + c.getName() + "\" returned null, expected a byte"; + throw new IllegalArgumentException(s); + + } else if (result instanceof Byte) { + return ((Byte) result).byteValue(); + + } else { + String s = "Method \"" + methodName + "\" in class \"" + + c.getName() + "\" returned a \"" + result.getClass().getName() + + "\" expected a byte"; + throw new IllegalArgumentException(s); + } + } + + /** + * Invokes an instance method on an object that is serialized into + * this VM. The return type of the method is byte. + * + * @param o + * The receiver of the method invocation + * @param methodName + * The name of the method to invoke + * + * @throws IllegalArgumentException + * The method does not return a byte + * @throws RMIException + * An exception occurred on while invoking the method in + * this VM + */ + public byte invokeByte(Object o, String methodName) { + return invokeByte(o, methodName, new Object[0]); + } + + /** + * Invokes an instance method on an object that is serialized into + * this VM. The return type of the method is byte. + * + * @param o + * The receiver of the method invocation + * @param methodName + * The name of the method to invoke + * @param args + * Arguments passed to the method call (must be {@link + * java.io.Serializable}). + * + * @throws IllegalArgumentException + * The method does not return a byte + * @throws RMIException + * An exception occurred on while invoking the method in + * this VM + */ + public byte invokeByte(Object o, String methodName, Object[] args) { + Object result = invoke(o, methodName, args); + Class c = o.getClass(); + if (result == null) { + String s = "Method \"" + methodName + "\" in class \"" + + c.getName() + "\" returned null, expected a byte"; + throw new IllegalArgumentException(s); + + } else if (result instanceof Byte) { + return ((Byte) result).byteValue(); + + } else { + String s = "Method \"" + methodName + "\" in class \"" + + c.getName() + "\" returned a \"" + result.getClass().getName() + + "\" expected a byte"; + throw new IllegalArgumentException(s); + } + } + + /** + * Invokes a static method with a short return type + * in this VM. + * + * @param c + * The class on which to invoke the method + * @param methodName + * The name of the method to invoke + * + * @throws IllegalArgumentException + * The method does not return a short + * @throws RMIException + * An exception occurred on while invoking the method in + * this VM + */ + public short invokeShort(Class c, String methodName) { + return invokeShort(c, methodName, new Object[0]); + } + + /** + * Invokes a static method with a short return type + * in this VM. + * + * @param c + * The class on which to invoke the method + * @param methodName + * The name of the method to invoke + * @param args + * Arguments passed to the method call (must be {@link + * java.io.Serializable}). + * + * @throws IllegalArgumentException + * The method does not return a short + * @throws RMIException + * An exception occurred on while invoking the method in + * this VM + */ + public short invokeShort(Class c, String methodName, Object[] args) { + Object result = invoke(c, methodName, args); + if (result == null) { + String s = "Method \"" + methodName + "\" in class \"" + + c.getName() + "\" returned null, expected a short"; + throw new IllegalArgumentException(s); + + } else if (result instanceof Short) { + return ((Short) result).shortValue(); + + } else { + String s = "Method \"" + methodName + "\" in class \"" + + c.getName() + "\" returned a \"" + result.getClass().getName() + + "\" expected a short"; + throw new IllegalArgumentException(s); + } + } + + /** + * Invokes an instance method on an object that is serialized into + * this VM. The return type of the method is short. + * + * @param o + * The receiver of the method invocation + * @param methodName + * The name of the method to invoke + * + * @throws IllegalArgumentException + * The method does not return a short + * @throws RMIException + * An exception occurred on while invoking the method in + * this VM + */ + public short invokeShort(Object o, String methodName) { + return invokeShort(o, methodName, new Object[0]); + } + + /** + * Invokes an instance method on an object that is serialized into + * this VM. The return type of the method is short. + * + * @param o + * The receiver of the method invocation + * @param methodName + * The name of the method to invoke + * @param args + * Arguments passed to the method call (must be {@link + * java.io.Serializable}). + * + * @throws IllegalArgumentException + * The method does not return a short + * @throws RMIException + * An exception occurred on while invoking the method in + * this VM + */ + public short invokeShort(Object o, String methodName, Object[] args) { + Object result = invoke(o, methodName, args); + Class c = o.getClass(); + if (result == null) { + String s = "Method \"" + methodName + "\" in class \"" + + c.getName() + "\" returned null, expected a short"; + throw new IllegalArgumentException(s); + + } else if (result instanceof Short) { + return ((Short) result).shortValue(); + + } else { + String s = "Method \"" + methodName + "\" in class \"" + + c.getName() + "\" returned a \"" + result.getClass().getName() + + "\" expected a short"; + throw new IllegalArgumentException(s); + } + } + + /** + * Invokes a static method with a int return type + * in this VM. + * + * @param c + * The class on which to invoke the method + * @param methodName + * The name of the method to invoke + * + * @throws IllegalArgumentException + * The method does not return a int + * @throws RMIException + * An exception occurred on while invoking the method in + * this VM + */ + public int invokeInt(Class c, String methodName) { + return invokeInt(c, methodName, new Object[0]); + } + + /** + * Invokes a static method with a int return type + * in this VM. + * + * @param c + * The class on which to invoke the method + * @param methodName + * The name of the method to invoke + * @param args + * Arguments passed to the method call (must be {@link + * java.io.Serializable}). + * + * @throws IllegalArgumentException + * The method does not return a int + * @throws RMIException + * An exception occurred on while invoking the method in + * this VM + */ + public int invokeInt(Class c, String methodName, Object[] args) { + Object result = invoke(c, methodName, args); + if (result == null) { + String s = "Method \"" + methodName + "\" in class \"" + + c.getName() + "\" returned null, expected a int"; + throw new IllegalArgumentException(s); + + } else if (result instanceof Integer) { + return ((Integer) result).intValue(); + + } else { + String s = "Method \"" + methodName + "\" in class \"" + + c.getName() + "\" returned a \"" + result.getClass().getName() + + "\" expected a int"; + throw new IllegalArgumentException(s); + } + } + + /** + * Invokes an instance method on an object that is serialized into + * this VM. The return type of the method is int. + * + * @param o + * The receiver of the method invocation + * @param methodName + * The name of the method to invoke + * + * @throws IllegalArgumentException + * The method does not return a int + * @throws RMIException + * An exception occurred on while invoking the method in + * this VM + */ + public int invokeInt(Object o, String methodName) { + return invokeInt(o, methodName, new Object[0]); + } + + /** + * Invokes an instance method on an object that is serialized into + * this VM. The return type of the method is int. + * + * @param o + * The receiver of the method invocation + * @param methodName + * The name of the method to invoke + * @param args + * Arguments passed to the method call (must be {@link + * java.io.Serializable}). + * + * @throws IllegalArgumentException + * The method does not return a int + * @throws RMIException + * An exception occurred on while invoking the method in + * this VM + */ + public int invokeInt(Object o, String methodName, Object[] args) { + Object result = invoke(o, methodName, args); + Class c = o.getClass(); + if (result == null) { + String s = "Method \"" + methodName + "\" in class \"" + + c.getName() + "\" returned null, expected a int"; + throw new IllegalArgumentException(s); + + } else if (result instanceof Integer) { + return ((Integer) result).intValue(); + + } else { + String s = "Method \"" + methodName + "\" in class \"" + + c.getName() + "\" returned a \"" + result.getClass().getName() + + "\" expected a int"; + throw new IllegalArgumentException(s); + } + } + + /** + * Invokes a static method with a long return type + * in this VM. + * + * @param c + * The class on which to invoke the method + * @param methodName + * The name of the method to invoke + * + * @throws IllegalArgumentException + * The method does not return a long + * @throws RMIException + * An exception occurred on while invoking the method in + * this VM + */ + public long invokeLong(Class c, String methodName) { + return invokeLong(c, methodName, new Object[0]); + } + + /** + * Invokes a static method with a long return type + * in this VM. + * + * @param c + * The class on which to invoke the method + * @param methodName + * The name of the method to invoke + * @param args + * Arguments passed to the method call (must be {@link + * java.io.Serializable}). + * + * @throws IllegalArgumentException + * The method does not return a long + * @throws RMIException + * An exception occurred on while invoking the method in + * this VM + */ + public long invokeLong(Class c, String methodName, Object[] args) { + Object result = invoke(c, methodName, args); + if (result == null) { + String s = "Method \"" + methodName + "\" in class \"" + + c.getName() + "\" returned null, expected a long"; + throw new IllegalArgumentException(s); + + } else if (result instanceof Long) { + return ((Long) result).longValue(); + + } else { + String s = "Method \"" + methodName + "\" in class \"" + + c.getName() + "\" returned a \"" + result.getClass().getName() + + "\" expected a long"; + throw new IllegalArgumentException(s); + } + } + + /** + * Invokes an instance method on an object that is serialized into + * this VM. The return type of the method is long. + * + * @param o + * The receiver of the method invocation + * @param methodName + * The name of the method to invoke + * + * @throws IllegalArgumentException + * The method does not return a long + * @throws RMIException + * An exception occurred on while invoking the method in + * this VM + */ + public long invokeLong(Object o, String methodName) { + return invokeLong(o, methodName, new Object[0]); + } + + /** + * Invokes an instance method on an object that is serialized into + * this VM. The return type of the method is long. + * + * @param o + * The receiver of the method invocation + * @param methodName + * The name of the method to invoke + * @param args + * Arguments passed to the method call (must be {@link + * java.io.Serializable}). + * + * @throws IllegalArgumentException + * The method does not return a long + * @throws RMIException + * An exception occurred on while invoking the method in + * this VM + */ + public long invokeLong(Object o, String methodName, Object[] args) { + Object result = invoke(o, methodName, args); + Class c = o.getClass(); + if (result == null) { + String s = "Method \"" + methodName + "\" in class \"" + + c.getName() + "\" returned null, expected a long"; + throw new IllegalArgumentException(s); + + } else if (result instanceof Long) { + return ((Long) result).longValue(); + + } else { + String s = "Method \"" + methodName + "\" in class \"" + + c.getName() + "\" returned a \"" + result.getClass().getName() + + "\" expected a long"; + throw new IllegalArgumentException(s); + } + } + + /** + * Invokes a static method with a float return type + * in this VM. + * + * @param c + * The class on which to invoke the method + * @param methodName + * The name of the method to invoke + * + * @throws IllegalArgumentException + * The method does not return a float + * @throws RMIException + * An exception occurred on while invoking the method in + * this VM + */ + public float invokeFloat(Class c, String methodName) { + return invokeFloat(c, methodName, new Object[0]); + } + + /** + * Invokes a static method with a float return type + * in this VM. + * + * @param c + * The class on which to invoke the method + * @param methodName + * The name of the method to invoke + * @param args + * Arguments passed to the method call (must be {@link + * java.io.Serializable}). + * + * @throws IllegalArgumentException + * The method does not return a float + * @throws RMIException + * An exception occurred on while invoking the method in + * this VM + */ + public float invokeFloat(Class c, String methodName, Object[] args) { + Object result = invoke(c, methodName, args); + if (result == null) { + String s = "Method \"" + methodName + "\" in class \"" + + c.getName() + "\" returned null, expected a float"; + throw new IllegalArgumentException(s); + + } else if (result instanceof Float) { + return ((Float) result).floatValue(); + + } else { + String s = "Method \"" + methodName + "\" in class \"" + + c.getName() + "\" returned a \"" + result.getClass().getName() + + "\" expected a float"; + throw new IllegalArgumentException(s); + } + } + + /** + * Invokes an instance method on an object that is serialized into + * this VM. The return type of the method is float. + * + * @param o + * The receiver of the method invocation + * @param methodName + * The name of the method to invoke + * + * @throws IllegalArgumentException + * The method does not return a float + * @throws RMIException + * An exception occurred on while invoking the method in + * this VM + */ + public float invokeFloat(Object o, String methodName) { + return invokeFloat(o, methodName, new Object[0]); + } + + /** + * Invokes an instance method on an object that is serialized into + * this VM. The return type of the method is float. + * + * @param o + * The receiver of the method invocation + * @param methodName + * The name of the method to invoke + * @param args + * Arguments passed to the method call (must be {@link + * java.io.Serializable}). + * + * @throws IllegalArgumentException + * The method does not return a float + * @throws RMIException + * An exception occurred on while invoking the method in + * this VM + */ + public float invokeFloat(Object o, String methodName, Object[] args) { + Object result = invoke(o, methodName, args); + Class c = o.getClass(); + if (result == null) { + String s = "Method \"" + methodName + "\" in class \"" + + c.getName() + "\" returned null, expected a float"; + throw new IllegalArgumentException(s); + + } else if (result instanceof Float) { + return ((Float) result).floatValue(); + + } else { + String s = "Method \"" + methodName + "\" in class \"" + + c.getName() + "\" returned a \"" + result.getClass().getName() + + "\" expected a float"; + throw new IllegalArgumentException(s); + } + } + + /** + * Invokes a static method with a double return type + * in this VM. + * + * @param c + * The class on which to invoke the method + * @param methodName + * The name of the method to invoke + * + * @throws IllegalArgumentException + * The method does not return a double + * @throws RMIException + * An exception occurred on while invoking the method in + * this VM + */ + public double invokeDouble(Class c, String methodName) { + return invokeDouble(c, methodName, new Object[0]); + } + + /** + * Invokes a static method with a double return type + * in this VM. + * + * @param c + * The class on which to invoke the method + * @param methodName + * The name of the method to invoke + * @param args + * Arguments passed to the method call (must be {@link + * java.io.Serializable}). + * + * @throws IllegalArgumentException + * The method does not return a double + * @throws RMIException + * An exception occurred on while invoking the method in + * this VM + */ + public double invokeDouble(Class c, String methodName, Object[] args) { + Object result = invoke(c, methodName, args); + if (result == null) { + String s = "Method \"" + methodName + "\" in class \"" + + c.getName() + "\" returned null, expected a double"; + throw new IllegalArgumentException(s); + + } else if (result instanceof Double) { + return ((Double) result).doubleValue(); + + } else { + String s = "Method \"" + methodName + "\" in class \"" + + c.getName() + "\" returned a \"" + result.getClass().getName() + + "\" expected a double"; + throw new IllegalArgumentException(s); + } + } + + /** + * Invokes an instance method on an object that is serialized into + * this VM. The return type of the method is double. + * + * @param o + * The receiver of the method invocation + * @param methodName + * The name of the method to invoke + * + * @throws IllegalArgumentException + * The method does not return a double + * @throws RMIException + * An exception occurred on while invoking the method in + * this VM + */ + public double invokeDouble(Object o, String methodName) { + return invokeDouble(o, methodName, new Object[0]); + } + + /** + * Invokes an instance method on an object that is serialized into + * this VM. The return type of the method is double. + * + * @param o + * The receiver of the method invocation + * @param methodName + * The name of the method to invoke + * @param args + * Arguments passed to the method call (must be {@link + * java.io.Serializable}). + * + * @throws IllegalArgumentException + * The method does not return a double + * @throws RMIException + * An exception occurred on while invoking the method in + * this VM + */ + public double invokeDouble(Object o, String methodName, Object[] args) { + Object result = invoke(o, methodName, args); + Class c = o.getClass(); + if (result == null) { + String s = "Method \"" + methodName + "\" in class \"" + + c.getName() + "\" returned null, expected a double"; + throw new IllegalArgumentException(s); + + } else if (result instanceof Double) { + return ((Double) result).doubleValue(); + + } else { + String s = "Method \"" + methodName + "\" in class \"" + + c.getName() + "\" returned a \"" + result.getClass().getName() + + "\" expected a double"; + throw new IllegalArgumentException(s); + } + } + + /** + * Synchronously bounces (mean kills and restarts) this VM. + * Concurrent bounce attempts are synchronized but attempts to invoke + * methods on a bouncing VM will cause test failure. Tests using bounce + * should be placed at the end of the dunit test suite, since an exception + * here will cause all tests using the unsuccessfully bounced VM to fail. + * + * This method is currently not supported by the standalone dunit + * runner. + * + * @throws RMIException if an exception occurs while bouncing this VM, for + * example a HydraTimeoutException if the VM fails to stop within {@link + * hydra.Prms#maxClientShutdownWaitSec} or restart within {@link + * hydra.Prms#maxClientStartupWaitSec}. + */ + public synchronized void bounce() { + if (!this.available) { + String s = "VM not available: " + this; + throw new RMIException(this, this.getClass().getName(), "bounceVM", + new IllegalStateException(s)); + } + this.available = false; + try { + BounceResult result = DUnitEnv.get().bounce(this.pid); + + this.pid = result.getNewPid(); + this.client = result.getNewClient(); + this.available = true; + } catch (UnsupportedOperationException e) { + this.available = true; + throw e; + } catch (RemoteException e) { + StringWriter sw = new StringWriter(); + e.printStackTrace(new PrintWriter(sw, true)); + RMIException rmie = new RMIException(this, this.getClass().getName(), + "bounceVM", e, sw.toString()); + throw rmie; + } + } + + ///////////////////// Utility Methods //////////////////// + + public String toString() { + return "VM " + this.getPid() + " running on " + this.getHost(); + } + + public static int getCurrentVMNum() { + return DUnitEnv.get().getVMID(); + } + + public File getWorkingDirectory() { + return DUnitEnv.get().getWorkingDirectory(this.getPid()); + } + +} http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/d89038db/gemfire-core/src/test/java/com/gemstone/gemfire/test/dunit/standalone/DUnitLauncher.java ---------------------------------------------------------------------- diff --git a/gemfire-core/src/test/java/com/gemstone/gemfire/test/dunit/standalone/DUnitLauncher.java b/gemfire-core/src/test/java/com/gemstone/gemfire/test/dunit/standalone/DUnitLauncher.java index 0a9d7c5..5e7fa0e 100644 --- a/gemfire-core/src/test/java/com/gemstone/gemfire/test/dunit/standalone/DUnitLauncher.java +++ b/gemfire-core/src/test/java/com/gemstone/gemfire/test/dunit/standalone/DUnitLauncher.java @@ -56,11 +56,10 @@ import com.gemstone.gemfire.distributed.Locator; import com.gemstone.gemfire.distributed.internal.membership.gms.membership.GMSJoinLeave; import com.gemstone.gemfire.internal.AvailablePortHelper; import com.gemstone.gemfire.internal.logging.LogService; - -import dunit.DUnitEnv; -import dunit.Host; -import dunit.SerializableCallable; -import dunit.VM; +import com.gemstone.gemfire.test.dunit.DUnitEnv; +import com.gemstone.gemfire.test.dunit.Host; +import com.gemstone.gemfire.test.dunit.SerializableCallable; +import com.gemstone.gemfire.test.dunit.VM; /** * A class to build a fake test configuration and launch some DUnit VMS. http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/d89038db/gemfire-core/src/test/java/com/gemstone/gemfire/test/dunit/standalone/StandAloneDUnitEnv.java ---------------------------------------------------------------------- diff --git a/gemfire-core/src/test/java/com/gemstone/gemfire/test/dunit/standalone/StandAloneDUnitEnv.java b/gemfire-core/src/test/java/com/gemstone/gemfire/test/dunit/standalone/StandAloneDUnitEnv.java index eef24fe..2975dcb 100644 --- a/gemfire-core/src/test/java/com/gemstone/gemfire/test/dunit/standalone/StandAloneDUnitEnv.java +++ b/gemfire-core/src/test/java/com/gemstone/gemfire/test/dunit/standalone/StandAloneDUnitEnv.java @@ -20,10 +20,9 @@ import java.io.File; import java.rmi.RemoteException; import java.util.Properties; +import com.gemstone.gemfire.test.dunit.DUnitEnv; import com.gemstone.gemfire.test.dunit.standalone.DUnitLauncher.MasterRemote; -import dunit.DUnitEnv; - public class StandAloneDUnitEnv extends DUnitEnv { private MasterRemote master; http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/d89038db/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 76faf93..2947f4b 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,11 +18,11 @@ package com.gemstone.gemfire.test.dunit.tests; import java.util.Properties; -import dunit.AsyncInvocation; -import dunit.DistributedTestCase; -import dunit.Host; -import dunit.RMIException; -import dunit.VM; +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.RMIException; +import com.gemstone.gemfire.test.dunit.VM; /** * This class tests the basic functionality of the distributed unit http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/d89038db/gemfire-core/src/test/java/com/gemstone/gemfire/test/dunit/tests/VMDUnitTest.java ---------------------------------------------------------------------- diff --git a/gemfire-core/src/test/java/com/gemstone/gemfire/test/dunit/tests/VMDUnitTest.java b/gemfire-core/src/test/java/com/gemstone/gemfire/test/dunit/tests/VMDUnitTest.java index 3562f86..78f7196 100644 --- a/gemfire-core/src/test/java/com/gemstone/gemfire/test/dunit/tests/VMDUnitTest.java +++ b/gemfire-core/src/test/java/com/gemstone/gemfire/test/dunit/tests/VMDUnitTest.java @@ -16,12 +16,15 @@ */ package com.gemstone.gemfire.test.dunit.tests; -import dunit.*; - import java.io.Serializable; - import java.util.concurrent.atomic.AtomicInteger; +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.RMIException; +import com.gemstone.gemfire.test.dunit.VM; + /** * This class tests the functionality of the {@link VM} class. */ http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/d89038db/gemfire-core/src/test/java/dunit/AsyncInvocation.java ---------------------------------------------------------------------- diff --git a/gemfire-core/src/test/java/dunit/AsyncInvocation.java b/gemfire-core/src/test/java/dunit/AsyncInvocation.java deleted file mode 100644 index 9177a12..0000000 --- a/gemfire-core/src/test/java/dunit/AsyncInvocation.java +++ /dev/null @@ -1,217 +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 dunit; - -import java.util.concurrent.TimeoutException; - -import junit.framework.AssertionFailedError; - -import com.gemstone.gemfire.InternalGemFireError; -import com.gemstone.gemfire.SystemFailure; - -// @todo davidw Add the ability to get a return value back from the -// async method call. (Use a static ThreadLocal field that is -// accessible from the Runnable used in VM#invoke) -/** - *

An AsyncInvocation represents the invocation of a - * remote invocation that executes asynchronously from its caller. An - * instanceof AsyncInvocation provides information about - * the invocation such as any exception that it may have thrown.

- * - *

Because it is a Thread, an - * AsyncInvocation can be used as follows:

- * - *
- *   AsyncInvocation ai1 = vm.invokeAsync(Test.class, "method1");
- *   AsyncInvocation ai2 = vm.invokeAsync(Test.class, "method2");
- *
- *   ai1.join();
- *   ai2.join();
- *
- *   assertTrue("Exception occurred while invoking " + ai1,
- *              !ai1.exceptionOccurred());
- *   if (ai2.exceptionOccurred()) {
- *     throw ai2.getException();
- *   }
- * 
- * - * @see VM#invokeAsync(Class, String) - */ -public class AsyncInvocation extends Thread { - - private static final ThreadLocal returnValue = new ThreadLocal(); - - /** The singleton the thread group */ - private static final ThreadGroup GROUP = new AsyncInvocationGroup(); - - ///////////////////// Instance Fields ///////////////////// - - /** An exception thrown while this async invocation ran */ - protected volatile Throwable exception; - - /** The object (or class) that is the receiver of this asyn method - * invocation */ - private Object receiver; - - /** The name of the method being invoked */ - private String methodName; - - /** The returned object if any */ - public volatile Object returnedObj = null; - - ////////////////////// Constructors ////////////////////// - - /** - * Creates a new AsyncInvocation - * - * @param receiver - * The object or {@link Class} on which the remote method was - * invoked - * @param methodName - * The name of the method being invoked - * @param work - * The actual invocation of the method - */ - public AsyncInvocation(Object receiver, String methodName, Runnable work) { - super(GROUP, work, getName(receiver, methodName)); - this.receiver = receiver; - this.methodName = methodName; - this.exception = null; - } - - ////////////////////// Static Methods ///////////////////// - - /** - * Returns the name of a AsyncInvocation based on its - * receiver and method name. - */ - private static String getName(Object receiver, String methodName) { - StringBuffer sb = new StringBuffer(methodName); - sb.append(" invoked on "); - if (receiver instanceof Class) { - sb.append("class "); - sb.append(((Class) receiver).getName()); - - } else { - sb.append("an instance of "); - sb.append(receiver.getClass().getName()); - } - - return sb.toString(); - } - - ///////////////////// Instance Methods //////////////////// - - /** - * Returns the receiver of this async method invocation - */ - public Object getReceiver() { - return this.receiver; - } - - /** - * Returns the name of the method being invoked remotely - */ - public String getMethodName() { - return this.methodName; - } - - /** - * Returns whether or not an exception occurred during this async - * method invocation. - */ - public boolean exceptionOccurred() { - if (this.isAlive()) { - throw new InternalGemFireError("Exception status not available while thread is alive."); - } - return this.exception != null; - } - - /** - * Returns the exception that was thrown during this async method - * invocation. - */ - public Throwable getException() { - if (this.isAlive()) { - throw new InternalGemFireError("Exception status not available while thread is alive."); - } - if (this.exception instanceof RMIException) { - return ((RMIException) this.exception).getCause(); - - } else { - return this.exception; - } - } - - ////////////////////// Inner Classes ////////////////////// - - /** - * A ThreadGroup that notices when an exception occurrs - * during an AsyncInvocation. - */ - private static class AsyncInvocationGroup extends ThreadGroup { - AsyncInvocationGroup() { - super("Async Invocations"); - } - - public void uncaughtException(Thread t, Throwable e) { - if (e instanceof VirtualMachineError) { - SystemFailure.setFailure((VirtualMachineError)e); // don't throw - } - if (t instanceof AsyncInvocation) { - ((AsyncInvocation) t).exception = e; - } - } - } - - public Object getResult() throws Throwable { - join(); - if(this.exceptionOccurred()) { - throw new Exception("An exception occured during async invocation", this.exception); - } - return this.returnedObj; - } - - public Object getResult(long waitTime) throws Throwable { - join(waitTime); - if(this.isAlive()) { - throw new TimeoutException(); - } - if(this.exceptionOccurred()) { - throw new Exception("An exception occured during async invocation", this.exception); - } - return this.returnedObj; - } - - public Object getReturnValue() { - if (this.isAlive()) { - throw new InternalGemFireError("Return value not available while thread is alive."); - } - return this.returnedObj; - } - - public void run() - { - super.run(); - this.returnedObj = returnValue.get(); - returnValue.set(null); - } - - static void setReturnValue(Object v) { - returnValue.set(v); - } -} http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/d89038db/gemfire-core/src/test/java/dunit/DUnitEnv.java ---------------------------------------------------------------------- diff --git a/gemfire-core/src/test/java/dunit/DUnitEnv.java b/gemfire-core/src/test/java/dunit/DUnitEnv.java deleted file mode 100644 index 54fe67f..0000000 --- a/gemfire-core/src/test/java/dunit/DUnitEnv.java +++ /dev/null @@ -1,80 +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 dunit; - -import java.io.File; -import java.rmi.RemoteException; -import java.util.Properties; - -import com.gemstone.gemfire.test.dunit.standalone.BounceResult; - - -/** - * This class provides an abstraction over the environment - * that is used to run dunit. This will delegate to the hydra - * or to the standalone dunit launcher as needed. - * - * Any dunit tests that rely on hydra configuration should go - * through here, so that we can separate them out from depending on hydra - * and run them on a different VM launching system. - * - * @author dsmith - * - */ -public abstract class DUnitEnv { - - public static DUnitEnv instance = null; - - public static final DUnitEnv get() { - if (instance == null) { - try { - // for tests that are still being migrated to the open-source - // distributed unit test framework we need to look for this - // old closed-source dunit environment - Class clazz = Class.forName("dunit.hydra.HydraDUnitEnv"); - instance = (DUnitEnv)clazz.newInstance(); - } catch (Exception e) { - throw new Error("Distributed unit test environment is not initialized"); - } - } - return instance; - } - - public static void set(DUnitEnv dunitEnv) { - instance = dunitEnv; - } - - public abstract String getLocatorString(); - - public abstract String getLocatorAddress(); - - public abstract int getLocatorPort(); - - public abstract Properties getDistributedSystemProperties(); - - public abstract int getPid(); - - public abstract int getVMID(); - - public abstract BounceResult bounce(int pid) throws RemoteException; - - public abstract File getWorkingDirectory(int pid); - -}