Repository: ignite
Updated Branches:
  refs/heads/master 0829397f8 -> 6c92d4dda


IGNITE-6839 Ignite Compatibility: flaky test testFoldersReuseCompatibility_2_1 
& 2_2 & 2_3 - Fixes #3700.

Signed-off-by: dpavlov <dpav...@apache.org>


Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/6c92d4dd
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/6c92d4dd
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/6c92d4dd

Branch: refs/heads/master
Commit: 6c92d4dda095f21bc521962bfcb4180f377f314d
Parents: 0829397
Author: Vyacheslav Daradur <daradu...@gmail.com>
Authored: Fri Apr 6 20:05:41 2018 +0300
Committer: dpavlov <dpav...@apache.org>
Committed: Fri Apr 6 20:05:41 2018 +0300

----------------------------------------------------------------------
 .../junits/IgniteCompatibilityAbstractTest.java |  4 +-
 .../junits/IgniteCompatibilityNodeRunner.java   |  4 +-
 .../util/CompatibilityTestsUtils.java           | 93 ++++++++++++++++++++
 3 files changed, 97 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/6c92d4dd/modules/compatibility/src/test/java/org/apache/ignite/compatibility/testframework/junits/IgniteCompatibilityAbstractTest.java
----------------------------------------------------------------------
diff --git 
a/modules/compatibility/src/test/java/org/apache/ignite/compatibility/testframework/junits/IgniteCompatibilityAbstractTest.java
 
b/modules/compatibility/src/test/java/org/apache/ignite/compatibility/testframework/junits/IgniteCompatibilityAbstractTest.java
index 8202c1b..f1aceb5 100644
--- 
a/modules/compatibility/src/test/java/org/apache/ignite/compatibility/testframework/junits/IgniteCompatibilityAbstractTest.java
+++ 
b/modules/compatibility/src/test/java/org/apache/ignite/compatibility/testframework/junits/IgniteCompatibilityAbstractTest.java
@@ -27,11 +27,11 @@ import java.util.concurrent.TimeUnit;
 import org.apache.ignite.Ignite;
 import org.apache.ignite.IgniteLogger;
 import 
org.apache.ignite.compatibility.testframework.junits.logger.ListenedGridTestLog4jLogger;
+import 
org.apache.ignite.compatibility.testframework.util.CompatibilityTestsUtils;
 import org.apache.ignite.compatibility.testframework.util.MavenUtils;
 import org.apache.ignite.configuration.IgniteConfiguration;
 import org.apache.ignite.internal.IgniteEx;
 import 
org.apache.ignite.internal.processors.resource.GridSpringResourceContext;
-import org.apache.ignite.internal.util.IgniteUtils;
 import org.apache.ignite.internal.util.typedef.internal.U;
 import org.apache.ignite.lang.IgniteInClosure;
 import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
@@ -170,7 +170,7 @@ public abstract class IgniteCompatibilityAbstractTest 
extends GridCommonAbstract
 
                 StringBuilder pathBuilder = new StringBuilder();
 
-                for (URL url : IgniteUtils.classLoaderUrls(ldr)) {
+                for (URL url : CompatibilityTestsUtils.classLoaderUrls(ldr)) {
                     String path = url.getPath();
 
                     boolean excluded = false;

http://git-wip-us.apache.org/repos/asf/ignite/blob/6c92d4dd/modules/compatibility/src/test/java/org/apache/ignite/compatibility/testframework/junits/IgniteCompatibilityNodeRunner.java
----------------------------------------------------------------------
diff --git 
a/modules/compatibility/src/test/java/org/apache/ignite/compatibility/testframework/junits/IgniteCompatibilityNodeRunner.java
 
b/modules/compatibility/src/test/java/org/apache/ignite/compatibility/testframework/junits/IgniteCompatibilityNodeRunner.java
index 6c58887..2ad5544 100644
--- 
a/modules/compatibility/src/test/java/org/apache/ignite/compatibility/testframework/junits/IgniteCompatibilityNodeRunner.java
+++ 
b/modules/compatibility/src/test/java/org/apache/ignite/compatibility/testframework/junits/IgniteCompatibilityNodeRunner.java
@@ -30,9 +30,9 @@ import java.util.Arrays;
 import java.util.UUID;
 import org.apache.ignite.Ignite;
 import org.apache.ignite.Ignition;
+import 
org.apache.ignite.compatibility.testframework.util.CompatibilityTestsUtils;
 import org.apache.ignite.configuration.IgniteConfiguration;
 import org.apache.ignite.internal.util.GridJavaProcess;
-import org.apache.ignite.internal.util.IgniteUtils;
 import org.apache.ignite.internal.util.typedef.X;
 import org.apache.ignite.internal.util.typedef.internal.U;
 import org.apache.ignite.lang.IgniteInClosure;
@@ -159,7 +159,7 @@ public class IgniteCompatibilityNodeRunner extends 
IgniteNodeRunner {
     private static void dumpClasspath() {
         ClassLoader clsLdr = 
IgniteCompatibilityNodeRunner.class.getClassLoader();
 
-        for (URL url : IgniteUtils.classLoaderUrls(clsLdr))
+        for (URL url : CompatibilityTestsUtils.classLoaderUrls(clsLdr))
             X.println("Classpath url: [" + url.getPath() + ']');
     }
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/6c92d4dd/modules/compatibility/src/test/java/org/apache/ignite/compatibility/testframework/util/CompatibilityTestsUtils.java
----------------------------------------------------------------------
diff --git 
a/modules/compatibility/src/test/java/org/apache/ignite/compatibility/testframework/util/CompatibilityTestsUtils.java
 
b/modules/compatibility/src/test/java/org/apache/ignite/compatibility/testframework/util/CompatibilityTestsUtils.java
new file mode 100644
index 0000000..ce48ff8
--- /dev/null
+++ 
b/modules/compatibility/src/test/java/org/apache/ignite/compatibility/testframework/util/CompatibilityTestsUtils.java
@@ -0,0 +1,93 @@
+/*
+ * 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 org.apache.ignite.compatibility.testframework.util;
+
+import java.lang.reflect.Field;
+import java.net.URL;
+import java.net.URLClassLoader;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * Utility class for compatibility tests.
+ *
+ * May contain code duplication because of using a newly added code in the 
'core' module which absent in previous
+ * releases and which should be included in the classpath of separate JVM 
process.
+ */
+@SuppressWarnings("Duplicates")
+public class CompatibilityTestsUtils {
+    /** Empty URL array. */
+    private static final URL[] EMPTY_URL_ARR = new URL[0];
+
+    /**
+     * Builtin class loader class.
+     *
+     * Note: needs for compatibility with Java 9.
+     */
+    private static final Class bltClsLdrCls = defaultClassLoaderClass();
+
+    /**
+     * Url class loader field.
+     *
+     * Note: needs for compatibility with Java 9.
+     */
+    private static final Field urlClsLdrField = urlClassLoaderField();
+
+    /**
+     * Returns URLs of class loader
+     *
+     * @param clsLdr Class loader.
+     */
+    public static URL[] classLoaderUrls(ClassLoader clsLdr) {
+        if (clsLdr == null)
+            return EMPTY_URL_ARR;
+        else if (clsLdr instanceof URLClassLoader)
+            return ((URLClassLoader)clsLdr).getURLs();
+        else if (bltClsLdrCls != null && urlClsLdrField != null && 
bltClsLdrCls.isAssignableFrom(clsLdr.getClass())) {
+            try {
+                return ((URLClassLoader)urlClsLdrField.get(clsLdr)).getURLs();
+            }
+            catch (IllegalAccessException e) {
+                return EMPTY_URL_ARR;
+            }
+        }
+        else
+            return EMPTY_URL_ARR;
+    }
+
+    /** */
+    @Nullable private static Class defaultClassLoaderClass() {
+        try {
+            return Class.forName("jdk.internal.loader.BuiltinClassLoader");
+        }
+        catch (ClassNotFoundException e) {
+            return null;
+        }
+    }
+
+    /** */
+    @Nullable private static Field urlClassLoaderField() {
+        try {
+            Class cls = defaultClassLoaderClass();
+
+            return cls == null ? null : cls.getDeclaredField("ucp");
+        }
+        catch (NoSuchFieldException e) {
+            return null;
+        }
+    }
+}

Reply via email to