This is an automated email from the ASF dual-hosted git repository.

aldettinger pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel-quarkus.git


The following commit(s) were added to refs/heads/master by this push:
     new 44fb006  Added JDK11 support to the Kudu container-based itests 
infrastructure #1132
44fb006 is described below

commit 44fb006bf001ca3b987d8c0c9e8db1852c405664
Author: aldettinger <aldettin...@gmail.com>
AuthorDate: Mon Apr 27 09:38:17 2020 +0200

    Added JDK11 support to the Kudu container-based itests infrastructure #1132
---
 integration-tests/kudu/pom.xml                     | 11 +++++-
 .../kudu/it/KuduInfrastructureTestHelper.java      | 46 ++++++++++++++++++----
 ...ion-config.json => reflection-config-jdk8.json} |  0
 .../resources/reflection-config-jdk9-onward.json   |  6 +++
 4 files changed, 55 insertions(+), 8 deletions(-)

diff --git a/integration-tests/kudu/pom.xml b/integration-tests/kudu/pom.xml
index c6b546f..77a1b4a 100644
--- a/integration-tests/kudu/pom.xml
+++ b/integration-tests/kudu/pom.xml
@@ -137,12 +137,21 @@
             </build>
         </profile>
         <profile>
+            <id>kudu-native-java9-onward</id>
+            <activation>
+                <jdk>[9,)</jdk>
+            </activation>
+            <properties>
+                
<quarkus.native.additional-build-args>-H:ReflectionConfigurationFiles=reflection-config-jdk9-onward.json</quarkus.native.additional-build-args>
+            </properties>
+        </profile>
+        <profile>
             <id>kudu-native-java8</id>
             <activation>
                 <jdk>1.8</jdk>
             </activation>
             <properties>
-                
<quarkus.native.additional-build-args>-H:ReflectionConfigurationFiles=reflection-config.json</quarkus.native.additional-build-args>
+                
<quarkus.native.additional-build-args>-H:ReflectionConfigurationFiles=reflection-config-jdk8.json</quarkus.native.additional-build-args>
             </properties>
         </profile>
     </profiles>
diff --git 
a/integration-tests/kudu/src/main/java/org/apache/camel/quarkus/component/kudu/it/KuduInfrastructureTestHelper.java
 
b/integration-tests/kudu/src/main/java/org/apache/camel/quarkus/component/kudu/it/KuduInfrastructureTestHelper.java
index cb45f8b..9e9625d 100644
--- 
a/integration-tests/kudu/src/main/java/org/apache/camel/quarkus/component/kudu/it/KuduInfrastructureTestHelper.java
+++ 
b/integration-tests/kudu/src/main/java/org/apache/camel/quarkus/component/kudu/it/KuduInfrastructureTestHelper.java
@@ -43,14 +43,14 @@ import org.jboss.logging.Logger;
  * camel.kudu.test.master.rpc-authority=kudu-master-hostname:7051
  * Run integration tests with mvn clean integration-test -P native
  *
- * B) How to run integration tests against the container based setup when NOT 
running on top of OpenJDK 8:
+ * B) How to run integration tests against the container based setup when NOT 
running on top of OpenJDK:
  * Comment @Disabled and @DisabledOnNativeImage annotations from {@code 
KuduTest} and {@code KuduIT}.
  * Override the ip resolution of the host "kudu-tserver" to 127.0.0.1, e.g. by 
adding an entry in /etc/hosts file as
  * below:
  * 127.0.0.1 kudu-tserver
  * Run integration tests with mvn clean integration-test -P native
  *
- * C) How to run integration tests against the container based setup when 
running on top of OpenJDK 8:
+ * C) How to run integration tests against the container based setup when 
running on top of OpenJDK:
  * Comment @Disabled and @DisabledOnNativeImage annotations from {@code 
KuduTest} and {@code KuduIT}.
  * No extra setup is needed as {@code 
overrideKuduTabletServerResolutionInInetAddressCache} takes care of redirecting
  * the Kudu tablet server traffic toward localhost
@@ -69,17 +69,49 @@ public class KuduInfrastructureTestHelper {
     }
 
     public static void overrideTabletServerHostnameResolution() {
+        int javaMajorVersion = 
Integer.parseInt(System.getProperty("java.version").replaceFirst("([0-9]+)[.].*",
 "$1"));
+
+        if (javaMajorVersion == 1) {
+            attemptOverideTabletServerHostnameResolutionOpenJdk8();
+        } else if (javaMajorVersion >= 9) {
+            attemptOverideTabletServerHostnameResolutionOpenJdk9Onward();
+        } else {
+            attemptOverideTabletServerHostnameResolutionOpenJdk8();
+            attemptOverideTabletServerHostnameResolutionOpenJdk9Onward();
+        }
+    }
+
+    public static void 
attemptOverideTabletServerHostnameResolutionOpenJdk9Onward() {
+        try {
+            // Warm up the InetAddress cache
+            InetAddress.getByName("localhost");
+            Field cacheField = InetAddress.class.getDeclaredField("cache");
+            cacheField.setAccessible(true);
+            Object cache = cacheField.get(null);
+
+            Method get = cache.getClass().getMethod("get", Object.class);
+            Object localHostCachedAddresses = get.invoke(cache, "localhost");
+
+            Method put = cache.getClass().getMethod("put", Object.class, 
Object.class);
+            put.invoke(cache, KUDU_TABLET_SERVER_HOSTNAME, 
localHostCachedAddresses);
+        } catch (Exception ex) {
+            final String msg = "An issue occurred while attempting the Open 
JDK9+ override of the kudu tablet server hostname resolution";
+            LOG.warn(msg, ex);
+        }
+    }
+
+    public static void attemptOverideTabletServerHostnameResolutionOpenJdk8() {
         try {
-            Field field = InetAddress.class.getDeclaredField("addressCache");
-            field.setAccessible(true);
-            Object addressCache = field.get(null);
+            Field addressCacheField = 
InetAddress.class.getDeclaredField("addressCache");
+            addressCacheField.setAccessible(true);
+            Object addressCache = addressCacheField.get(null);
 
             Method put = addressCache.getClass().getMethod("put", 
String.class, InetAddress[].class);
             put.setAccessible(true);
             put.invoke(addressCache, KUDU_TABLET_SERVER_HOSTNAME, (Object[]) 
InetAddress.getAllByName("localhost"));
         } catch (Exception ex) {
-            final String msg = "Can't override the kudu tablet server hostname 
resolution when not running on top of OpenJDK 8";
-            LOG.error(msg, ex);
+            final String msg = "An issue occurred while attempting the Open 
JDK8 override of the kudu tablet server hostname resolution";
+            LOG.warn(msg, ex);
         }
     }
 }
diff --git a/integration-tests/kudu/src/main/resources/reflection-config.json 
b/integration-tests/kudu/src/main/resources/reflection-config-jdk8.json
similarity index 100%
rename from integration-tests/kudu/src/main/resources/reflection-config.json
rename to integration-tests/kudu/src/main/resources/reflection-config-jdk8.json
diff --git 
a/integration-tests/kudu/src/main/resources/reflection-config-jdk9-onward.json 
b/integration-tests/kudu/src/main/resources/reflection-config-jdk9-onward.json
new file mode 100644
index 0000000..63d1df7
--- /dev/null
+++ 
b/integration-tests/kudu/src/main/resources/reflection-config-jdk9-onward.json
@@ -0,0 +1,6 @@
+[
+  {
+    "name" : "java.util.concurrent.ConcurrentHashMap",
+    "allDeclaredMethods" : true
+  }
+]
\ No newline at end of file

Reply via email to