Merge
authordlong
Thu, 08 Jan 2015 17:45:15 -0500
changeset 28416 a902022106d6
parent 28411 4e26bf150be8 (current diff)
parent 28415 8a8eb9fe7232 (diff)
child 28417 0cef041bf4fc
Merge
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/lib/testlibrary/jdk/testlibrary/FilterClassLoader.java	Thu Jan 08 17:45:15 2015 -0500
@@ -0,0 +1,49 @@
+/*
+ * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package jdk.testlibrary;
+
+import java.util.function.Predicate;
+/**
+ * A classloader, which using target classloader in case provided condition
+ * for class name is met, and using parent otherwise
+ */
+public class FilterClassLoader extends ClassLoader {
+
+    private final ClassLoader target;
+    private final Predicate<String> condition;
+
+    public FilterClassLoader(ClassLoader target, ClassLoader parent,
+            Predicate<String> condition) {
+        super(parent);
+        this.condition = condition;
+        this.target = target;
+    }
+
+    @Override
+    public Class<?> loadClass(String name) throws ClassNotFoundException {
+        if (condition.test(name)) {
+            return target.loadClass(name);
+        }
+        return super.loadClass(name);
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/lib/testlibrary/jdk/testlibrary/ParentLastURLClassLoader.java	Thu Jan 08 17:45:15 2015 -0500
@@ -0,0 +1,50 @@
+/*
+ * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package jdk.testlibrary;
+
+import java.net.URL;
+import java.net.URLClassLoader;
+
+/**
+ * An url classloader, which trying to load class from provided URL[] first,
+ * and using parent classloader in case it failed
+ */
+public class ParentLastURLClassLoader extends URLClassLoader {
+
+    public ParentLastURLClassLoader(URL urls[], ClassLoader parent) {
+        super(urls, parent);
+    }
+
+    @Override
+    public Class<?> loadClass(String name) throws ClassNotFoundException {
+        try {
+            Class c = findClass(name);
+            if (c != null) {
+                return c;
+            }
+        } catch (ClassNotFoundException e) {
+            // ignore
+        }
+        return super.loadClass(name);
+    }
+}
--- a/jdk/test/lib/testlibrary/jdk/testlibrary/Platform.java	Mon Dec 29 19:07:09 2014 +0100
+++ b/jdk/test/lib/testlibrary/jdk/testlibrary/Platform.java	Thu Jan 08 17:45:15 2015 -0500
@@ -28,6 +28,15 @@
     private static final String dataModel   = System.getProperty("sun.arch.data.model");
     private static final String vmVersion   = System.getProperty("java.vm.version");
     private static final String osArch      = System.getProperty("os.arch");
+    private static final String vmName      = System.getProperty("java.vm.name");
+
+    public static boolean isClient() {
+        return vmName.endsWith(" Client VM");
+    }
+
+    public static boolean isServer() {
+        return vmName.endsWith(" Server VM");
+    }
 
     public static boolean is32bit() {
         return dataModel.equals("32");
--- a/jdk/test/lib/testlibrary/jdk/testlibrary/Utils.java	Mon Dec 29 19:07:09 2014 +0100
+++ b/jdk/test/lib/testlibrary/jdk/testlibrary/Utils.java	Thu Jan 08 17:45:15 2015 -0500
@@ -39,6 +39,7 @@
 import java.util.regex.Pattern;
 import java.util.regex.Matcher;
 import java.util.concurrent.TimeUnit;
+import java.util.function.BooleanSupplier;
 
 /**
  * Common library for various test helper functions.
@@ -271,25 +272,6 @@
     }
 
     /**
-     * Returns file content as a list of strings
-     *
-     * @param file File to operate on
-     * @return List of strings
-     * @throws IOException
-     */
-    public static List<String> fileAsList(File file) throws IOException {
-        assertTrue(file.exists() && file.isFile(),
-                file.getAbsolutePath() + " does not exist or not a file");
-        List<String> output = new ArrayList<>();
-        try (BufferedReader reader = new BufferedReader(new FileReader(file.getAbsolutePath()))) {
-            while (reader.ready()) {
-                output.add(reader.readLine().replace(NEW_LINE, ""));
-            }
-        }
-        return output;
-    }
-
-    /**
      * Adjusts the provided timeout value for the TIMEOUT_FACTOR
      * @param tOut the timeout value to be adjusted
      * @return The timeout value adjusted for the value of "test.timeout.factor"
@@ -298,4 +280,50 @@
     public static long adjustTimeout(long tOut) {
         return Math.round(tOut * Utils.TIMEOUT_FACTOR);
     }
+
+    /**
+     * Wait for condition to be true
+     *
+     * @param condition, a condition to wait for
+     */
+    public static final void waitForCondition(BooleanSupplier condition) {
+        waitForCondition(condition, -1L, 100L);
+    }
+
+    /**
+     * Wait until timeout for condition to be true
+     *
+     * @param condition, a condition to wait for
+     * @param timeout a time in milliseconds to wait for condition to be true
+     * specifying -1 will wait forever
+     * @return condition value, to determine if wait was successfull
+     */
+    public static final boolean waitForCondition(BooleanSupplier condition,
+            long timeout) {
+        return waitForCondition(condition, timeout, 100L);
+    }
+
+    /**
+     * Wait until timeout for condition to be true for specified time
+     *
+     * @param condition, a condition to wait for
+     * @param timeout a time in milliseconds to wait for condition to be true,
+     * specifying -1 will wait forever
+     * @param sleepTime a time to sleep value in milliseconds
+     * @return condition value, to determine if wait was successfull
+     */
+    public static final boolean waitForCondition(BooleanSupplier condition,
+            long timeout, long sleepTime) {
+        long startTime = System.currentTimeMillis();
+        while (!(condition.getAsBoolean() || (timeout != -1L
+                && ((System.currentTimeMillis() - startTime) > timeout)))) {
+            try {
+                Thread.sleep(sleepTime);
+            } catch (InterruptedException e) {
+                Thread.currentThread().interrupt();
+                throw new Error(e);
+            }
+        }
+        return condition.getAsBoolean();
+    }
 }
--- a/jdk/test/sun/tools/jcmd/TestJcmdDefaults.java	Mon Dec 29 19:07:09 2014 +0100
+++ b/jdk/test/sun/tools/jcmd/TestJcmdDefaults.java	Thu Jan 08 17:45:15 2015 -0500
@@ -25,6 +25,9 @@
 
 import java.io.File;
 import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
 import java.util.List;
 
 import jdk.testlibrary.JcmdBase;
@@ -95,11 +98,11 @@
     }
 
     private static void verifyOutputAgainstFile(OutputAnalyzer output) throws IOException {
-        File file = new File(TEST_SRC, "usage.out");
-        List<String> fileOutput = Utils.fileAsList(file);
+        Path path = Paths.get(TEST_SRC, "usage.out");
+        List<String> fileOutput = Files.readAllLines(path);
         List<String> outputAsLines = output.asLines();
         assertTrue(outputAsLines.containsAll(fileOutput),
-                "The ouput should contain all content of " + file.getAbsolutePath());
+                "The ouput should contain all content of " + path.toAbsolutePath());
     }
 
 }
--- a/jdk/test/sun/tools/jcmd/TestJcmdSanity.java	Mon Dec 29 19:07:09 2014 +0100
+++ b/jdk/test/sun/tools/jcmd/TestJcmdSanity.java	Thu Jan 08 17:45:15 2015 -0500
@@ -25,6 +25,9 @@
 
 import java.io.File;
 import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
 import java.util.List;
 
 import jdk.testlibrary.JcmdBase;
@@ -160,11 +163,11 @@
     }
 
     private static void verifyOutputAgainstFile(OutputAnalyzer output) throws IOException {
-        File file = new File(TEST_SRC, "help_help.out");
-        List<String> fileOutput = Utils.fileAsList(file);
+        Path path = Paths.get(TEST_SRC, "help_help.out");
+        List<String> fileOutput = Files.readAllLines(path);
         List<String> outputAsLines = output.asLines();
         assertTrue(outputAsLines.containsAll(fileOutput),
-                "The ouput should contain all content of " + file.getAbsolutePath());
+                "The ouput should contain all content of " + path.toAbsolutePath());
     }
 
 }
--- a/jdk/test/sun/tools/jps/JpsHelper.java	Mon Dec 29 19:07:09 2014 +0100
+++ b/jdk/test/sun/tools/jps/JpsHelper.java	Thu Jan 08 17:45:15 2015 -0500
@@ -28,6 +28,9 @@
 import java.io.File;
 import java.io.FileWriter;
 import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
@@ -189,11 +192,11 @@
      */
     public static void verifyOutputAgainstFile(OutputAnalyzer output) throws IOException {
         String testSrc = System.getProperty("test.src", "?");
-        File file = new File(testSrc, "usage.out");
-        List<String> fileOutput = Utils.fileAsList(file);
+        Path path = Paths.get(testSrc, "usage.out");
+        List<String> fileOutput = Files.readAllLines(path);
         List<String> outputAsLines = output.asLines();
         assertTrue(outputAsLines.containsAll(fileOutput),
-                "The ouput should contain all content of " + file.getAbsolutePath());
+                "The ouput should contain all content of " + path.toAbsolutePath());
     }
 
     private static File getManifest(String className) throws IOException {