diff --git a/modules/ducktests/pom.xml b/modules/ducktests/pom.xml index 6d01a9c726847..e5756e7487298 100644 --- a/modules/ducktests/pom.xml +++ b/modules/ducktests/pom.xml @@ -163,16 +163,6 @@ - - - org.apache.maven.plugins - maven-javadoc-plugin - ${maven.javadoc.plugin.version} - - java:java.* - - - diff --git a/modules/ducktests/src/main/java/org/apache/ignite/internal/ducktest/tests/dns_failure_test/DnsBlocker.java b/modules/ducktests/src/main/java/org/apache/ignite/internal/ducktest/tests/dns_failure_test/DnsBlocker.java index 9b14268446909..7121e51a51ac6 100644 --- a/modules/ducktests/src/main/java/org/apache/ignite/internal/ducktest/tests/dns_failure_test/DnsBlocker.java +++ b/modules/ducktests/src/main/java/org/apache/ignite/internal/ducktest/tests/dns_failure_test/DnsBlocker.java @@ -16,50 +16,55 @@ */ package org.apache.ignite.internal.ducktest.tests.dns_failure_test; -import org.apache.ignite.IgniteCheckedException; -import org.apache.ignite.internal.util.typedef.internal.U; -import org.apache.ignite.startup.cmdline.CommandLineStartup; -import sun.net.spi.nameservice.NameService; - import java.io.File; import java.io.FileNotFoundException; +import java.lang.reflect.Field; +import java.lang.reflect.Method; +import java.lang.reflect.Proxy; import java.net.InetAddress; import java.net.UnknownHostException; import java.text.SimpleDateFormat; import java.util.Arrays; import java.util.Date; -import java.util.List; import java.util.Scanner; +import org.apache.ignite.startup.cmdline.CommandLineStartup; /** */ -public class DnsBlocker implements NameService { +public class DnsBlocker implements NameServiceHandler { /** */ private static final String BLOCK_DNS_FILE = "/tmp/block_dns"; + /** Private class {@code java.net.InetAddress$NameService} to proxy. */ + private static Class nameSrvcCls; + /** */ private final InetAddress loopback; - /** Original NameService to use after unblock. */ - private final NameService orig; + /** Original {@code NameService}. */ + private final Object origNameSrvc; /** - * @param orig Original NameService to use after unblock. + * @param origNameSrvc Original NameService. */ - private DnsBlocker(NameService orig) { + private DnsBlocker(Object origNameSrvc) { loopback = InetAddress.getLoopbackAddress(); - this.orig = orig; + this.origNameSrvc = origNameSrvc; } - /** Installs DnsBlocker as main NameService to JVM. */ - private static void install() throws IgniteCheckedException { - List nameSrvc = U.staticField(InetAddress.class, "nameServices"); + /** Installs {@code DnsBlocker} as main {@code NameService} to JVM. */ + private static void install() throws Exception { + Field nameSrvcFld = InetAddress.class.getDeclaredField("nameService"); + nameSrvcFld.setAccessible(true); + + nameSrvcCls = Class.forName("java.net.InetAddress$NameService"); - NameService ns = new DnsBlocker(nameSrvc.get(0)); + DnsBlocker blkNameSrvc = new DnsBlocker(nameSrvcFld.get(InetAddress.class)); - // Put the blocking name service ahead. - nameSrvc.add(0, ns); + nameSrvcFld.set( + InetAddress.class, + Proxy.newProxyInstance(nameSrvcCls.getClassLoader(), new Class[] { nameSrvcCls }, blkNameSrvc)); - System.out.println("Installed DnsBlocker as main NameService to JVM [ns=" + nameSrvc.size() + ']'); + System.out.println("Installed DnsBlocker as main NameService to JVM"); } /** */ @@ -74,7 +79,15 @@ public static void main(String[] args) throws Exception { if (!loopback.getHostAddress().equals(hostname)) check(hostname); - return orig.lookupAllHostAddr(hostname); + try { + Method lookupAllHostAddr = nameSrvcCls.getDeclaredMethod("lookupAllHostAddr", String.class); + lookupAllHostAddr.setAccessible(true); + + return (InetAddress[])lookupAllHostAddr.invoke(origNameSrvc, hostname); + } + catch (Exception e) { + throw new RuntimeException(e); + } } /** */ @@ -82,7 +95,15 @@ public static void main(String[] args) throws Exception { if (!Arrays.equals(loopback.getAddress(), addr)) check(InetAddress.getByAddress(addr).toString()); - return orig.getHostByAddr(addr); + try { + Method getHostByAddr = nameSrvcCls.getDeclaredMethod("getHostByAddr", byte[].class); + getHostByAddr.setAccessible(true); + + return (String)getHostByAddr.invoke(origNameSrvc, addr); + } + catch (Exception e) { + throw new RuntimeException(e); + } } /** */ diff --git a/modules/ducktests/src/main/java/org/apache/ignite/internal/ducktest/tests/dns_failure_test/NameServiceHandler.java b/modules/ducktests/src/main/java/org/apache/ignite/internal/ducktest/tests/dns_failure_test/NameServiceHandler.java new file mode 100644 index 0000000000000..f5ecf10b6627f --- /dev/null +++ b/modules/ducktests/src/main/java/org/apache/ignite/internal/ducktest/tests/dns_failure_test/NameServiceHandler.java @@ -0,0 +1,44 @@ +/* + * 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.internal.ducktest.tests.dns_failure_test; + +import java.lang.reflect.InvocationHandler; +import java.lang.reflect.Method; +import java.net.InetAddress; +import java.net.UnknownHostException; + +/** Handler for {@code java.net.InetAddress$NameService}. */ +interface NameServiceHandler extends InvocationHandler { + /** Intercepts {@code NameService#lookupAllHostAddr}. */ + public InetAddress[] lookupAllHostAddr(String host) throws UnknownHostException; + + /** Intercepts {@code NameService#getHostByAddr}. */ + public String getHostByAddr(byte[] addr) throws UnknownHostException; + + /** Delegate {@code NameService} methods to {@link DnsBlocker}. */ + @Override public default Object invoke(Object proxy, Method method, Object[] args) throws Throwable { + String name = method.getName(); + + if ("lookupAllHostAddr".equals(name)) + return lookupAllHostAddr((String)args[0]); + else if ("getHostByAddr".equals(name)) + return getHostByAddr((byte[])args[0]); + else + throw new UnsupportedOperationException("Unsupported method: " + name); + } +} diff --git a/modules/ducktests/tests/docker/Dockerfile b/modules/ducktests/tests/docker/Dockerfile index b09e8d00b70a5..84c5e9129d815 100644 --- a/modules/ducktests/tests/docker/Dockerfile +++ b/modules/ducktests/tests/docker/Dockerfile @@ -13,7 +13,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -ARG jdk_version=openjdk:8 +ARG jdk_version=openjdk:11 FROM $jdk_version MAINTAINER Apache Ignite dev@ignite.apache.org diff --git a/modules/ducktests/tests/docker/ducker-ignite b/modules/ducktests/tests/docker/ducker-ignite index 4b8b589c6f6ca..8872f61dd195b 100755 --- a/modules/ducktests/tests/docker/ducker-ignite +++ b/modules/ducktests/tests/docker/ducker-ignite @@ -42,7 +42,7 @@ docker_run_memory_limit="8000m" default_num_nodes=4 # The default OpenJDK base image. -default_jdk="openjdk:8" +default_jdk="openjdk:11" # The default ducker-ignite image name. default_image_name="ducker-ignite" diff --git a/modules/ducktests/tests/docker/run_tests.sh b/modules/ducktests/tests/docker/run_tests.sh index fb8d3b92f5928..d06215bdaad0a 100755 --- a/modules/ducktests/tests/docker/run_tests.sh +++ b/modules/ducktests/tests/docker/run_tests.sh @@ -24,7 +24,7 @@ SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" IGNITE_NUM_CONTAINERS=${IGNITE_NUM_CONTAINERS:-13} # Image name to run nodes -JDK_VERSION="${JDK_VERSION:-8}" +JDK_VERSION="${JDK_VERSION:-11}" IMAGE_PREFIX="ducker-ignite-openjdk" ### @@ -79,7 +79,7 @@ The options are as follows: Subnet to assign nodes IP addresses, like --subnet 172.20.0.0/16 --jdk - Set jdk version to build, default is 8 + Set jdk version to build, default is 11 --image Set custom docker image to run tests on. diff --git a/parent/pom.xml b/parent/pom.xml index b624cced27f24..30e8f44c73c7b 100644 --- a/parent/pom.xml +++ b/parent/pom.xml @@ -46,8 +46,8 @@ pom - 1.8 - 1.8 + 11 + 11 2.17.0-SNAPSHOT