geode-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sai_boorlaga...@apache.org
Subject [geode] branch feature/GEODE-5787-dunit-internal updated: GEODE-5787: supporting bounce on windows
Date Thu, 04 Oct 2018 00:12:33 GMT
This is an automated email from the ASF dual-hosted git repository.

sai_boorlagadda pushed a commit to branch feature/GEODE-5787-dunit-internal
in repository https://gitbox.apache.org/repos/asf/geode.git


The following commit(s) were added to refs/heads/feature/GEODE-5787-dunit-internal by this
push:
     new 4734957  GEODE-5787: supporting bounce on windows
4734957 is described below

commit 4734957e6bdeffbad18d3d2828eec800353b25ef
Author: Kirk Lund <klund@apache.org>
AuthorDate: Wed Oct 3 17:08:59 2018 -0700

    GEODE-5787: supporting bounce on windows
    
    Signed-off-by: Sai Boorlagadda <sboorlagadda@pivotal.io>
---
 .../cli/commands/DeployWithGroupsDUnitTest.java    |   7 --
 .../java/org/apache/geode/test/dunit/Host.java     |  11 +-
 .../main/java/org/apache/geode/test/dunit/VM.java  | 129 ++++++++++-----------
 .../{ProcessHolder.java => ChildVMLauncher.java}   |  43 ++-----
 .../geode/test/dunit/standalone/DUnitHost.java     |  10 +-
 .../geode/test/dunit/standalone/ProcessHolder.java |   5 +
 .../test/dunit/standalone/ProcessManager.java      |  17 ++-
 7 files changed, 99 insertions(+), 123 deletions(-)

diff --git a/geode-core/src/distributedTest/java/org/apache/geode/management/internal/cli/commands/DeployWithGroupsDUnitTest.java
b/geode-core/src/distributedTest/java/org/apache/geode/management/internal/cli/commands/DeployWithGroupsDUnitTest.java
index d7f9223..abdff44 100644
--- a/geode-core/src/distributedTest/java/org/apache/geode/management/internal/cli/commands/DeployWithGroupsDUnitTest.java
+++ b/geode-core/src/distributedTest/java/org/apache/geode/management/internal/cli/commands/DeployWithGroupsDUnitTest.java
@@ -15,10 +15,8 @@
 package org.apache.geode.management.internal.cli.commands;
 
 import static org.apache.geode.distributed.ConfigurationProperties.GROUPS;
-import static org.apache.geode.internal.lang.SystemUtils.isWindows;
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.assertj.core.api.Assertions.assertThatThrownBy;
-import static org.junit.Assume.assumeFalse;
 
 import java.io.File;
 import java.io.Serializable;
@@ -41,7 +39,6 @@ import org.apache.geode.test.junit.rules.serializable.SerializableTemporaryFolde
  * @since GemFire 7.0
  */
 @SuppressWarnings("serial")
-
 public class DeployWithGroupsDUnitTest implements Serializable {
   private static final String GROUP1 = "Group1";
   private static final String GROUP2 = "Group2";
@@ -201,8 +198,6 @@ public class DeployWithGroupsDUnitTest implements Serializable {
 
   @Test
   public void deployJarToAllServersWithRestart() {
-    // TODO: Ignore on windows until GEODE-5787
-    assumeFalse(isWindows());
     // Deploy a jar to all servers
     gfshConnector.executeAndAssertThat("deploy --jar=" + jar1).statusIsSuccess();
     String resultString = gfshConnector.getGfshOutput();
@@ -231,8 +226,6 @@ public class DeployWithGroupsDUnitTest implements Serializable {
 
   @Test
   public void undeployJarFromAllServersWithRestart() throws Exception {
-    // TODO: Ignore on windows until GEODE-5787
-    assumeFalse(isWindows());
     // Deploy a jar to all servers
     gfshConnector.executeAndAssertThat("deploy --jar=" + jar1).statusIsSuccess();
     String resultString = gfshConnector.getGfshOutput();
diff --git a/geode-dunit/src/main/java/org/apache/geode/test/dunit/Host.java b/geode-dunit/src/main/java/org/apache/geode/test/dunit/Host.java
index 283ee33..776ed17 100755
--- a/geode-dunit/src/main/java/org/apache/geode/test/dunit/Host.java
+++ b/geode-dunit/src/main/java/org/apache/geode/test/dunit/Host.java
@@ -18,6 +18,7 @@ import java.io.Serializable;
 import java.util.ArrayList;
 import java.util.List;
 
+import org.apache.geode.test.dunit.standalone.ChildVMLauncher;
 import org.apache.geode.test.dunit.standalone.ProcessHolder;
 import org.apache.geode.test.dunit.standalone.RemoteDUnitVMIF;
 import org.apache.geode.test.dunit.standalone.VersionManager;
@@ -163,8 +164,9 @@ public abstract class Host implements Serializable {
   /**
    * Adds a VM to this {@code Host} with the given process id and client record.
    */
-  protected void addVM(int vmid, RemoteDUnitVMIF client, ProcessHolder processHolder) {
-    VM vm = new VM(this, vmid, client, processHolder);
+  protected void addVM(int vmid, RemoteDUnitVMIF client, ProcessHolder processHolder,
+      ChildVMLauncher childVMLauncher) {
+    VM vm = new VM(this, vmid, client, processHolder, childVMLauncher);
     vms.add(vm);
   }
 
@@ -176,8 +178,9 @@ public abstract class Host implements Serializable {
     locator = l;
   }
 
-  protected void addLocator(int vmid, RemoteDUnitVMIF client, ProcessHolder processHolder)
{
-    setLocator(new VM(this, vmid, client, processHolder));
+  protected void addLocator(int vmid, RemoteDUnitVMIF client, ProcessHolder processHolder,
+      ChildVMLauncher childVMLauncher) {
+    setLocator(new VM(this, vmid, client, processHolder, childVMLauncher));
   }
 
   @Override
diff --git a/geode-dunit/src/main/java/org/apache/geode/test/dunit/VM.java b/geode-dunit/src/main/java/org/apache/geode/test/dunit/VM.java
index 51726bd..77bdb02 100644
--- a/geode-dunit/src/main/java/org/apache/geode/test/dunit/VM.java
+++ b/geode-dunit/src/main/java/org/apache/geode/test/dunit/VM.java
@@ -17,15 +17,16 @@ package org.apache.geode.test.dunit;
 import static org.apache.geode.test.dunit.standalone.DUnitLauncher.NUM_VMS;
 
 import java.io.File;
-import java.io.PrintWriter;
+import java.io.IOException;
 import java.io.Serializable;
-import java.io.StringWriter;
+import java.rmi.NotBoundException;
 import java.rmi.RemoteException;
 import java.util.List;
 import java.util.concurrent.Callable;
+import java.util.concurrent.TimeUnit;
 
 import org.apache.geode.internal.process.ProcessUtils;
-import org.apache.geode.test.dunit.standalone.BounceResult;
+import org.apache.geode.test.dunit.standalone.ChildVMLauncher;
 import org.apache.geode.test.dunit.standalone.MethExecutorResult;
 import org.apache.geode.test.dunit.standalone.ProcessHolder;
 import org.apache.geode.test.dunit.standalone.RemoteDUnitVMIF;
@@ -59,6 +60,8 @@ public class VM implements Serializable {
 
   private transient volatile ProcessHolder processHolder;
 
+  private transient ChildVMLauncher childVMLauncher;
+
   /**
    * Returns the {@code VM} identity. For {@link StandAloneDUnitEnv} the number returned
is a
    * zero-based sequence representing the order in with the DUnit {@code VM}s were launched.
@@ -150,17 +153,18 @@ public class VM implements Serializable {
    * Creates a new {@code VM} that runs on a given host with a given process id.
    */
   public VM(final Host host, final int id, final RemoteDUnitVMIF client,
-      final ProcessHolder processHolder) {
-    this(host, VersionManager.CURRENT_VERSION, id, client, processHolder);
+      final ProcessHolder processHolder, final ChildVMLauncher childVMLauncher) {
+    this(host, VersionManager.CURRENT_VERSION, id, client, processHolder, childVMLauncher);
   }
 
   public VM(final Host host, final String version, final int id, final RemoteDUnitVMIF client,
-      final ProcessHolder processHolder) {
+      final ProcessHolder processHolder, final ChildVMLauncher childVMLauncher) {
     this.host = host;
     this.id = id;
     this.version = version;
     this.client = client;
     this.processHolder = processHolder;
+    this.childVMLauncher = childVMLauncher;
     available = true;
   }
 
@@ -208,7 +212,8 @@ public class VM implements Serializable {
    */
   @Deprecated
   public <V> V invoke(final Class<?> targetClass, final String methodName) {
-    return invoke(targetClass, methodName, new Object[0]);
+    checkAvailability(targetClass.getName(), methodName);
+    return executeMethodOnClass(targetClass, methodName, new Object[0]);
   }
 
   /**
@@ -240,20 +245,8 @@ public class VM implements Serializable {
    */
   @Deprecated
   public <V> V invoke(final Class<?> targetClass, final String methodName, final
Object[] args) {
-    if (!available) {
-      throw new RMIException(this, targetClass.getName(), methodName,
-          new IllegalStateException("VM not available: " + this));
-    }
-
-    MethExecutorResult result = execute(targetClass, methodName, args);
-
-    if (!result.exceptionOccurred()) {
-      return (V) result.getResult();
-
-    } else {
-      throw new RMIException(this, targetClass.getName(), methodName, result.getException(),
-          result.getStackTrace());
-    }
+    checkAvailability(targetClass.getName(), methodName);
+    return executeMethodOnClass(targetClass, methodName, args);
   }
 
   /**
@@ -351,7 +344,8 @@ public class VM implements Serializable {
    * @see SerializableRunnable
    */
   public void invoke(final String name, final SerializableRunnableIF runnable) {
-    invoke(new NamedRunnable(name, runnable), "run");
+    checkAvailability(NamedRunnable.class.getName(), "run");
+    executeMethodOnObject(new NamedRunnable(name, runnable), "run", new Object[0]);
   }
 
   /**
@@ -363,7 +357,8 @@ public class VM implements Serializable {
    * @see SerializableRunnable
    */
   public void invoke(final SerializableRunnableIF runnable) {
-    invoke(runnable, "run");
+    checkAvailability(runnable.getClass().getName(), "run");
+    executeMethodOnObject(runnable, "run", new Object[0]);
   }
 
   /**
@@ -375,7 +370,8 @@ public class VM implements Serializable {
    * @see SerializableCallable
    */
   public <V> V invoke(final String name, final SerializableCallableIF<V> callable)
{
-    return invoke(new NamedCallable<>(name, callable), "call");
+    checkAvailability(NamedCallable.class.getName(), "call");
+    return executeMethodOnObject(new NamedCallable<>(name, callable), "call", new Object[0]);
   }
 
   /**
@@ -386,7 +382,8 @@ public class VM implements Serializable {
    * @see SerializableCallable
    */
   public <V> V invoke(final SerializableCallableIF<V> callable) {
-    return invoke(callable, "call");
+    checkAvailability(callable.getClass().getName(), "call");
+    return executeMethodOnObject(callable, "call", new Object[0]);
   }
 
   /**
@@ -404,7 +401,8 @@ public class VM implements Serializable {
    */
   @Deprecated
   public <V> V invoke(final Object targetObject, final String methodName) {
-    return invoke(targetObject, methodName, new Object[0]);
+    checkAvailability(targetObject.getClass().getName(), methodName);
+    return executeMethodOnObject(targetObject, methodName, new Object[0]);
   }
 
   /**
@@ -423,20 +421,8 @@ public class VM implements Serializable {
    */
   @Deprecated
   public <V> V invoke(final Object targetObject, final String methodName, final Object[]
args) {
-    if (!available) {
-      throw new RMIException(this, targetObject.getClass().getName(), methodName,
-          new IllegalStateException("VM not available: " + this));
-    }
-
-    MethExecutorResult result = execute(targetObject, methodName, args);
-
-    if (!result.exceptionOccurred()) {
-      return (V) result.getResult();
-
-    } else {
-      throw new RMIException(this, targetObject.getClass().getName(), methodName,
-          result.getException(), result.getStackTrace());
-    }
+    checkAvailability(targetObject.getClass().getName(), methodName);
+    return executeMethodOnObject(targetObject, methodName, args);
   }
 
   /**
@@ -487,28 +473,31 @@ public class VM implements Serializable {
   }
 
   private synchronized void bounce(final String targetVersion, boolean force) {
-    if (!available) {
-      throw new RMIException(this, getClass().getName(), "bounceVM",
-          new IllegalStateException("VM not available: " + this));
-    }
+    checkAvailability(getClass().getName(), "bounceVM");
 
+    System.out.println(">>>>>> Bouncing " + id + " old pid is " + getPid());
     available = false;
-
     try {
-      BounceResult result = DUnitEnv.get().bounce(targetVersion, id, force);
-      id = result.getNewId();
-      client = result.getNewClient();
-      version = targetVersion;
-      available = true;
-
-    } catch (UnsupportedOperationException e) {
+      if (force) {
+        processHolder.killForcibly();
+      } else {
+        SerializableRunnableIF runnable = () -> new Thread(() -> System.exit(0)).start();
+        executeMethodOnObject(runnable, "run", new Object[0]);
+      }
+      processHolder.waitFor(5, TimeUnit.MINUTES); // TODO: delete timeout or make longer
+      childVMLauncher.launchVM(version, id, true);
+      client = childVMLauncher.getStub(id);
       available = true;
-      throw e;
+      System.out.println(">>>>>> Bounced " + id + " new pid is " + getPid());
+    } catch (InterruptedException | IOException | NotBoundException e) {
+      throw new RuntimeException("Unable to restart VM " + id, e);
+    }
+  }
 
-    } catch (RemoteException e) {
-      StringWriter sw = new StringWriter();
-      e.printStackTrace(new PrintWriter(sw, true));
-      throw new RMIException(this, getClass().getName(), "bounceVM", e, sw.toString());
+  private void checkAvailability(String className, String methodName) {
+    if (!available) {
+      throw new RMIException(this, className, methodName,
+          new IllegalStateException("VM not available: " + this));
     }
   }
 
@@ -522,26 +511,32 @@ public class VM implements Serializable {
         + (VersionManager.isCurrentVersion(version) ? "" : (" with version " + version));
   }
 
-  private MethExecutorResult execute(final Class<?> targetClass, final String methodName,
+  private <V> V executeMethodOnObject(final Object targetObject, final String methodName,
       final Object[] args) {
     try {
-      return client.executeMethodOnClass(targetClass.getName(), methodName, args);
+      MethExecutorResult result = client.executeMethodOnObject(targetObject, methodName,
args);
+      if (result.exceptionOccurred()) {
+        throw new RMIException(this, targetObject.getClass().getName(), methodName,
+            result.getException(), result.getStackTrace());
+      }
+      return (V) result.getResult();
     } catch (RemoteException exception) {
-      throw new RMIException(this, targetClass.getName(), methodName, exception);
+      throw new RMIException(this, targetObject.getClass().getName(), methodName, exception);
     }
   }
 
-  private MethExecutorResult execute(final Object targetObject, final String methodName,
+  private <V> V executeMethodOnClass(final Class<?> targetClass, final String
methodName,
       final Object[] args) {
     try {
-      if (args == null) {
-        return client.executeMethodOnObject(targetObject, methodName);
-      } else {
-        return client.executeMethodOnObject(targetObject, methodName, args);
+      MethExecutorResult result =
+          client.executeMethodOnClass(targetClass.getName(), methodName, args);
+      if (result.exceptionOccurred()) {
+        throw new RMIException(this, targetClass.getName(), methodName, result.getException(),
+            result.getStackTrace());
       }
+      return (V) result.getResult();
     } catch (RemoteException exception) {
-      throw new RMIException(this, targetObject.getClass().getName(), methodName, exception);
+      throw new RMIException(this, targetClass.getName(), methodName, exception);
     }
   }
-
 }
diff --git a/geode-dunit/src/main/java/org/apache/geode/test/dunit/standalone/ProcessHolder.java
b/geode-dunit/src/main/java/org/apache/geode/test/dunit/standalone/ChildVMLauncher.java
similarity index 53%
copy from geode-dunit/src/main/java/org/apache/geode/test/dunit/standalone/ProcessHolder.java
copy to geode-dunit/src/main/java/org/apache/geode/test/dunit/standalone/ChildVMLauncher.java
index ebc0530..5e028b1 100644
--- a/geode-dunit/src/main/java/org/apache/geode/test/dunit/standalone/ProcessHolder.java
+++ b/geode-dunit/src/main/java/org/apache/geode/test/dunit/standalone/ChildVMLauncher.java
@@ -14,43 +14,14 @@
  */
 package org.apache.geode.test.dunit.standalone;
 
-import java.io.InputStream;
+import java.io.IOException;
+import java.rmi.NotBoundException;
+import java.rmi.RemoteException;
 
-public class ProcessHolder {
-  private final Process process;
-  private volatile boolean killed = false;
+public interface ChildVMLauncher {
 
-  public ProcessHolder(Process process) {
-    this.process = process;
-  }
+  void launchVM(String version, int vmNum, boolean bouncedVM)
+      throws IOException;
 
-  public void kill() {
-    this.killed = true;
-    process.destroy();
-  }
-
-  public void killForcibly() {
-    this.killed = true;
-    process.destroyForcibly();
-  }
-
-  public void waitFor() throws InterruptedException {
-    process.waitFor();
-  }
-
-  public InputStream getErrorStream() {
-    return process.getErrorStream();
-  }
-
-  public InputStream getInputStream() {
-    return process.getInputStream();
-  }
-
-  public boolean isKilled() {
-    return killed;
-  }
-
-  public boolean isAlive() {
-    return !killed && process.isAlive();
-  }
+  RemoteDUnitVMIF getStub(int i) throws RemoteException, NotBoundException, InterruptedException;
 }
diff --git a/geode-dunit/src/main/java/org/apache/geode/test/dunit/standalone/DUnitHost.java
b/geode-dunit/src/main/java/org/apache/geode/test/dunit/standalone/DUnitHost.java
index 94f5f04..85d2f3b 100644
--- a/geode-dunit/src/main/java/org/apache/geode/test/dunit/standalone/DUnitHost.java
+++ b/geode-dunit/src/main/java/org/apache/geode/test/dunit/standalone/DUnitHost.java
@@ -18,7 +18,7 @@ class DUnitHost extends Host {
 
   public DUnitHost(String hostName, ProcessManager processManager) throws RemoteException
{
     super(hostName);
-    this.debuggingVM = new VM(this, -1, new RemoteDUnitVM(), null);
+    this.debuggingVM = new VM(this, -1, new RemoteDUnitVM(), null, null);
     this.processManager = processManager;
   }
 
@@ -27,11 +27,11 @@ class DUnitHost extends Host {
     for (int i = 0; i < numVMs; i++) {
       RemoteDUnitVMIF remote = processManager.getStub(i);
       ProcessHolder processHolder = processManager.getProcessHolder(i);
-      addVM(i, remote, processHolder);
+      addVM(i, remote, processHolder, processManager);
     }
 
     addLocator(DUnitLauncher.LOCATOR_VM_NUM, processManager.getStub(DUnitLauncher.LOCATOR_VM_NUM),
-        processManager.getProcessHolder(DUnitLauncher.LOCATOR_VM_NUM));
+        processManager.getProcessHolder(DUnitLauncher.LOCATOR_VM_NUM), processManager);
 
     addHost(this);
   }
@@ -83,13 +83,13 @@ class DUnitHost extends Host {
         processManager.waitForVMs(DUnitLauncher.STARTUP_TIMEOUT);
 
         for (int i = oldVMCount; i < n; i++) {
-          addVM(i, processManager.getStub(i), processManager.getProcessHolder(i));
+          addVM(i, processManager.getStub(i), processManager.getProcessHolder(i), processManager);
         }
 
         // now create the one we really want
         processManager.launchVM(version, n, false);
         processManager.waitForVMs(DUnitLauncher.STARTUP_TIMEOUT);
-        addVM(n, processManager.getStub(n), processManager.getProcessHolder(n));
+        addVM(n, processManager.getStub(n), processManager.getProcessHolder(n), processManager);
 
       } catch (IOException | InterruptedException | NotBoundException e) {
         throw new RuntimeException("Could not dynamically launch vm + " + n, e);
diff --git a/geode-dunit/src/main/java/org/apache/geode/test/dunit/standalone/ProcessHolder.java
b/geode-dunit/src/main/java/org/apache/geode/test/dunit/standalone/ProcessHolder.java
index ebc0530..1898c39 100644
--- a/geode-dunit/src/main/java/org/apache/geode/test/dunit/standalone/ProcessHolder.java
+++ b/geode-dunit/src/main/java/org/apache/geode/test/dunit/standalone/ProcessHolder.java
@@ -15,6 +15,7 @@
 package org.apache.geode.test.dunit.standalone;
 
 import java.io.InputStream;
+import java.util.concurrent.TimeUnit;
 
 public class ProcessHolder {
   private final Process process;
@@ -38,6 +39,10 @@ public class ProcessHolder {
     process.waitFor();
   }
 
+  public void waitFor(long timeout, TimeUnit unit) throws InterruptedException {
+    process.waitFor(timeout, unit);
+  }
+
   public InputStream getErrorStream() {
     return process.getErrorStream();
   }
diff --git a/geode-dunit/src/main/java/org/apache/geode/test/dunit/standalone/ProcessManager.java
b/geode-dunit/src/main/java/org/apache/geode/test/dunit/standalone/ProcessManager.java
index c4ba4d8..c6c7e85 100755
--- a/geode-dunit/src/main/java/org/apache/geode/test/dunit/standalone/ProcessManager.java
+++ b/geode-dunit/src/main/java/org/apache/geode/test/dunit/standalone/ProcessManager.java
@@ -25,7 +25,6 @@ import java.io.InputStreamReader;
 import java.io.PrintStream;
 import java.lang.management.ManagementFactory;
 import java.lang.management.RuntimeMXBean;
-import java.rmi.AccessException;
 import java.rmi.NotBoundException;
 import java.rmi.RemoteException;
 import java.rmi.registry.Registry;
@@ -41,7 +40,7 @@ import org.apache.geode.distributed.internal.DistributionConfig;
 import org.apache.geode.distributed.internal.InternalLocator;
 import org.apache.geode.test.dunit.VM;
 
-class ProcessManager {
+class ProcessManager implements ChildVMLauncher {
   private int namingPort;
   private Map<Integer, ProcessHolder> processes = new HashMap<>();
   private File log4jConfig;
@@ -61,8 +60,12 @@ class ProcessManager {
     launchVM(VersionManager.CURRENT_VERSION, vmNum, false);
   }
 
+  @Override
   public synchronized void launchVM(String version, int vmNum, boolean bouncedVM)
       throws IOException {
+    if (bouncedVM) {
+      processes.remove(vmNum);
+    }
     if (processes.containsKey(vmNum)) {
       throw new IllegalStateException("VM " + vmNum + " is already running.");
     }
@@ -154,6 +157,7 @@ class ProcessManager {
     final String vmName = "[" + VM.getVMName(version, vmNum) + "] ";
     System.out.println("linking IO streams for " + vmName);
     Thread ioTransport = new Thread() {
+      @Override
       public void run() {
         BufferedReader reader = new BufferedReader(new InputStreamReader(in));
         try {
@@ -315,6 +319,10 @@ class ProcessManager {
     this.notifyAll();
   }
 
+  public synchronized boolean waitForVMs() throws InterruptedException {
+    return waitForVMs(DUnitLauncher.STARTUP_TIMEOUT);
+  }
+
   public synchronized boolean waitForVMs(long timeout) throws InterruptedException {
     long end = System.currentTimeMillis() + timeout;
     while (pendingVMs > 0) {
@@ -328,13 +336,14 @@ class ProcessManager {
     return true;
   }
 
+  @Override
   public RemoteDUnitVMIF getStub(int i)
-      throws AccessException, RemoteException, NotBoundException, InterruptedException {
+      throws RemoteException, NotBoundException, InterruptedException {
     return getStub(VersionManager.CURRENT_VERSION, i);
   }
 
   public RemoteDUnitVMIF getStub(String version, int i)
-      throws AccessException, RemoteException, NotBoundException, InterruptedException {
+      throws RemoteException, NotBoundException, InterruptedException {
     waitForVMs(DUnitLauncher.STARTUP_TIMEOUT);
     return (RemoteDUnitVMIF) registry.lookup("vm" + i);
   }


Mime
View raw message