You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@geode.apache.org by kl...@apache.org on 2016/01/25 19:46:29 UTC
[03/13] 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 <code>VM</code> 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 <code>VM</code> runs
+ */
+ public Host getHost() {
+ return this.host;
+ }
+
+ /**
+ * Returns the process id of this <code>VM</code>
+ */
+ public int getPid() {
+ return this.pid;
+ }
+
+ ///////////////// Remote Method Invocation ///////////////
+
+ /**
+ * Invokes a static zero-arg method with an {@link Object} or
+ * <code>void</code> return type in this VM. If the return type of
+ * the method is <code>void</code>, <code>null</code> 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 <code>void</code> return type in this VM. If the
+ * return type of the method is <code>void</code>, <code>null</code>
+ * 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
+ * <code>void</code> return type in this VM. If the return type of
+ * the method is <code>void</code>, <code>null</code> 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
+ * <code>void</code> return type in this VM. If the return type of
+ * the method is <code>void</code>, <code>null</code> 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
+ * <code>void</code> return type in this VM. If the return type of
+ * the method is <code>void</code>, <code>null</code> 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 <code>run</code> method of a {@link Runnable} in this
+ * VM. Recall that <code>run</code> takes no arguments and has no
+ * return value.
+ *
+ * @param r
+ * The <code>Runnable</code> to be run
+ *
+ * @see SerializableRunnable
+ */
+ public AsyncInvocation invokeAsync(Runnable r) {
+ return invokeAsync(r, "run", new Object[0]);
+ }
+
+ /**
+ * Invokes the <code>call</code> method of a {@link Runnable} in this
+ * VM.
+ *
+ * @param c
+ * The <code>Callable</code> to be run
+ *
+ * @see SerializableCallable
+ */
+ public AsyncInvocation invokeAsync(Callable c) {
+ return invokeAsync(c, "call", new Object[0]);
+ }
+
+ /**
+ * Invokes the <code>run</code> method of a {@link Runnable} in this
+ * VM. Recall that <code>run</code> takes no arguments and has no
+ * return value.
+ *
+ * @param r
+ * The <code>Runnable</code> to be run
+ *
+ * @see SerializableRunnable
+ */
+ public void invoke(Runnable r) {
+ invoke(r, "run");
+ }
+
+ /**
+ * Invokes the <code>run</code> method of a {@link Runnable} in this
+ * VM. Recall that <code>run</code> takes no arguments and has no
+ * return value.
+ *
+ * @param c
+ * The <code>Callable</code> to be run
+ *
+ * @see SerializableCallable
+ */
+ public Object invoke(Callable c) {
+ return invoke(c, "call");
+ }
+
+ /**
+ * Invokes the <code>run</code method of a {@link Runnable} in this
+ * VM. If the invocation throws AssertionFailedError, and repeatTimeoutMs
+ * is >0, the <code>run</code> method is invoked repeatedly until it
+ * either succeeds, or repeatTimeoutMs has passed. The AssertionFailedError
+ * is thrown back to the sender of this method if <code>run</code> 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 <code>void</code>. If the return type
+ * of the method is <code>void</code>, <code>null</code> 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 <code>void</code>. If the return type of the method
+ * is <code>void</code>, <code>null</code> 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 <code>main</code> method of a given class
+ *
+ * @param c
+ * The class on which to invoke the <code>main</code> method
+ * @param args
+ * The "command line" arguments to pass to the
+ * <code>main</code> method
+ */
+ public void invokeMain(Class c, String[] args) {
+ Object[] stupid = new Object[] { args };
+ invoke(c, "main", stupid);
+ }
+
+ /**
+ * Asynchronously invokes the <code>main</code> method of a given
+ * class
+ *
+ * @param c
+ * The class on which to invoke the <code>main</code> method
+ * @param args
+ * The "command line" arguments to pass to the
+ * <code>main</code> method
+ */
+ public AsyncInvocation invokeMainAsync(Class c, String[] args) {
+ Object[] stupid = new Object[] { args };
+ return invokeAsync(c, "main", stupid);
+ }
+
+ /**
+ * Invokes a static method with a <code>boolean</code> 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 <code>boolean</code>
+ * @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 <code>boolean</code> 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 <code>boolean</code>
+ * @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 <code>boolean</code>.
+ *
+ * @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 <code>boolean</code>
+ * @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 <code>boolean</code>.
+ *
+ * @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 <code>boolean</code>
+ * @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 <code>char</code> 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 <code>char</code>
+ * @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 <code>char</code> 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 <code>char</code>
+ * @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 <code>char</code>.
+ *
+ * @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 <code>char</code>
+ * @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 <code>char</code>.
+ *
+ * @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 <code>char</code>
+ * @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 <code>byte</code> 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 <code>byte</code>
+ * @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 <code>byte</code> 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 <code>byte</code>
+ * @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 <code>byte</code>.
+ *
+ * @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 <code>byte</code>
+ * @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 <code>byte</code>.
+ *
+ * @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 <code>byte</code>
+ * @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 <code>short</code> 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 <code>short</code>
+ * @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 <code>short</code> 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 <code>short</code>
+ * @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 <code>short</code>.
+ *
+ * @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 <code>short</code>
+ * @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 <code>short</code>.
+ *
+ * @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 <code>short</code>
+ * @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 <code>int</code> 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 <code>int</code>
+ * @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 <code>int</code> 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 <code>int</code>
+ * @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 <code>int</code>.
+ *
+ * @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 <code>int</code>
+ * @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 <code>int</code>.
+ *
+ * @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 <code>int</code>
+ * @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 <code>long</code> 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 <code>long</code>
+ * @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 <code>long</code> 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 <code>long</code>
+ * @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 <code>long</code>.
+ *
+ * @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 <code>long</code>
+ * @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 <code>long</code>.
+ *
+ * @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 <code>long</code>
+ * @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 <code>float</code> 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 <code>float</code>
+ * @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 <code>float</code> 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 <code>float</code>
+ * @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 <code>float</code>.
+ *
+ * @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 <code>float</code>
+ * @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 <code>float</code>.
+ *
+ * @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 <code>float</code>
+ * @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 <code>double</code> 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 <code>double</code>
+ * @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 <code>double</code> 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 <code>double</code>
+ * @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 <code>double</code>.
+ *
+ * @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 <code>double</code>
+ * @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 <code>double</code>.
+ *
+ * @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 <code>double</code>
+ * @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 <code>VM</code>.
+ * 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)
-/**
- * <P>An <code>AsyncInvocation</code> represents the invocation of a
- * remote invocation that executes asynchronously from its caller. An
- * instanceof <code>AsyncInvocation</code> provides information about
- * the invocation such as any exception that it may have thrown.</P>
- *
- * <P>Because it is a <code>Thread</code>, an
- * <code>AsyncInvocation</code> can be used as follows:</P>
- *
- * <PRE>
- * 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();
- * }
- * </PRE>
- *
- * @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 <code>AsyncInvocation</code>
- *
- * @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 <code>AsyncInvocation</code> 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 <code>ThreadGroup</code> that notices when an exception occurrs
- * during an <code>AsyncInvocation</code>.
- */
- 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);
-
-}