GEODE-2386: Wait until classpath doesn't contain gradle-worker.jar Workaround for an issue with gradle and dunit where gradle does not set the java.class.path to the correct value immediately. Wait for at most 30 seconds until gradle "fixes" the value.
Review by: Hitesh Project: http://git-wip-us.apache.org/repos/asf/geode/repo Commit: http://git-wip-us.apache.org/repos/asf/geode/commit/4763a5b8 Tree: http://git-wip-us.apache.org/repos/asf/geode/tree/4763a5b8 Diff: http://git-wip-us.apache.org/repos/asf/geode/diff/4763a5b8 Branch: refs/heads/master Commit: 4763a5b8117c65fb259febb4fc51192b3b34cd56 Parents: 6ae2e17 Author: Dan Smith <[email protected]> Authored: Wed Feb 1 13:42:50 2017 -0800 Committer: Dan Smith <[email protected]> Committed: Wed Feb 1 15:04:30 2017 -0800 ---------------------------------------------------------------------- .../test/dunit/standalone/ProcessManager.java | 23 +++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/geode/blob/4763a5b8/geode-core/src/test/java/org/apache/geode/test/dunit/standalone/ProcessManager.java ---------------------------------------------------------------------- diff --git a/geode-core/src/test/java/org/apache/geode/test/dunit/standalone/ProcessManager.java b/geode-core/src/test/java/org/apache/geode/test/dunit/standalone/ProcessManager.java index b109e16..3b02b4b 100644 --- a/geode-core/src/test/java/org/apache/geode/test/dunit/standalone/ProcessManager.java +++ b/geode-core/src/test/java/org/apache/geode/test/dunit/standalone/ProcessManager.java @@ -16,6 +16,8 @@ package org.apache.geode.test.dunit.standalone; import static org.apache.geode.distributed.ConfigurationProperties.*; +import com.jayway.awaitility.Awaitility; + import java.io.BufferedReader; import java.io.File; import java.io.IOException; @@ -32,6 +34,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; import java.util.Map; +import java.util.concurrent.TimeUnit; import org.apache.commons.io.FileUtils; @@ -66,8 +69,7 @@ public class ProcessManager { public synchronized void launchVM(String version, int vmNum, boolean bouncedVM) throws IOException { if (processes.containsKey(vmNum)) { - throw new IllegalStateException( - "VM " + vmNum + " is already running."); + throw new IllegalStateException("VM " + vmNum + " is already running."); } String[] cmd = buildJavaCommand(vmNum, namingPort, version); @@ -172,7 +174,7 @@ public class ProcessManager { private String[] buildJavaCommand(int vmNum, int namingPort, String version) { String cmd = System.getProperty("java.home") + File.separator + "bin" + File.separator + "java"; - String dunitClasspath = System.getProperty("java.class.path"); + String dunitClasspath = getClasspath(); String classPath; if (!VersionManager.isCurrentVersion(version)) { classPath = versionManager.getClasspath(version) + File.pathSeparator + dunitClasspath; @@ -234,6 +236,21 @@ public class ProcessManager { return rst; } + private String getClasspath() { + String classpath = System.getProperty("java.class.path"); + // Workaround for GEODE-2386 + long endTime = System.nanoTime() + TimeUnit.SECONDS.toNanos(30); + while (classpath.contains("gradle-worker.jar") && System.nanoTime() < endTime) { + try { + Thread.sleep(100); + } catch (InterruptedException e) { + // do nothing + } + classpath = System.getProperty("java.class.path"); + } + return classpath; + } + private String removeJREJars(String classpath) { String[] jars = classpath.split(File.pathSeparator); StringBuilder sb = new StringBuilder(classpath.length());
