Skip to content

Commit

Permalink
IGNITE-22671 Fix ducktape jdk11 build
Browse files Browse the repository at this point in the history
  • Loading branch information
timoninmaxim committed Jul 10, 2024
1 parent 1bc31cf commit bc20e53
Show file tree
Hide file tree
Showing 7 changed files with 96 additions and 39 deletions.
10 changes: 0 additions & 10 deletions modules/ducktests/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -163,16 +163,6 @@
</execution>
</executions>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>${maven.javadoc.plugin.version}</version>
<configuration>
<excludePackageNames>java:java.*</excludePackageNames>
</configuration>
</plugin>

</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -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<NameService> 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");
}

/** */
Expand All @@ -74,15 +79,31 @@ 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);
}
}

/** */
@Override public String getHostByAddr(byte[] addr) throws UnknownHostException {
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);
}
}

/** */
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
}
}
2 changes: 1 addition & 1 deletion modules/ducktests/tests/docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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 [email protected]
Expand Down
2 changes: 1 addition & 1 deletion modules/ducktests/tests/docker/ducker-ignite
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions modules/ducktests/tests/docker/run_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"

###
Expand Down Expand Up @@ -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.
Expand Down
10 changes: 6 additions & 4 deletions parent/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@
<packaging>pom</packaging>

<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>

<revision>2.17.0-SNAPSHOT</revision>
<!-- Ignite version will be substituted with the flatten-maven-plugin and used as
Expand Down Expand Up @@ -913,7 +913,7 @@
<jdk>[1.9,15)</jdk>
</activation>
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
</properties>
<dependencies/>
Expand All @@ -933,6 +933,8 @@
<arg>java.management/com.sun.jmx.mbeanserver=ALL-UNNAMED</arg>
<arg>--add-exports</arg>
<arg>jdk.internal.jvmstat/sun.jvmstat.monitor=ALL-UNNAMED</arg>
<arg>--add-exports</arg>
<arg>java.base/sun.net.util=ALL-UNNAMED</arg>
</compilerArgs>
</configuration>
</plugin>
Expand Down Expand Up @@ -1002,7 +1004,7 @@
<jdk>[15,)</jdk>
</activation>
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>15</maven.compiler.target>
<scala.library.version>2.12.15</scala.library.version>
</properties>
Expand Down

0 comments on commit bc20e53

Please sign in to comment.