Skip to content

IGNITE-22671 Fix ducktape dns_failure test under JDK11 #11429

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jul 11, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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>

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -14,46 +14,96 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package java.net;
package org.apache.ignite.internal.ducktest.tests.dns_failure_test;

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.Scanner;
import org.apache.ignite.startup.cmdline.CommandLineStartup;

/** */
public class DnsBlocker {
public class DnsBlocker implements NameServiceHandler {
/** */
private static final String BLOCK_DNS_FILE = "/tmp/block_dns";

/** */
public static final DnsBlocker INSTANCE = new DnsBlocker();
/** Private class {@code java.net.InetAddress$NameService} to proxy. */
private static Class<?> nameSrvcCls;

/** */
private DnsBlocker() {
// No-op.
}
private final InetAddress loopback;

/** Original {@code NameService}. */
private final Object origNameSrvc;

/**
* Check and block hostname resolve request if needed.
* @param impl Implementation.
* @param hostname Hostname.
* @param origNameSrvc Original NameService.
*/
public void onHostResolve(InetAddressImpl impl, String hostname) throws UnknownHostException {
if (!impl.loopbackAddress().getHostAddress().equals(hostname))
private DnsBlocker(Object origNameSrvc) {
loopback = InetAddress.getLoopbackAddress();
this.origNameSrvc = origNameSrvc;
}

/** 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");

DnsBlocker blkNameSrvc = new DnsBlocker(nameSrvcFld.get(InetAddress.class));

nameSrvcFld.set(
InetAddress.class,
Proxy.newProxyInstance(nameSrvcCls.getClassLoader(), new Class<?>[] { nameSrvcCls }, blkNameSrvc));

System.out.println("Installed DnsBlocker as main NameService to JVM");
}

/** */
public static void main(String[] args) throws Exception {
install();

CommandLineStartup.main(args);
}

/** */
@Override public InetAddress[] lookupAllHostAddr(String hostname) throws UnknownHostException {
if (!loopback.getHostAddress().equals(hostname))
check(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);
}
}

/**
* Check and block address resolve request if needed.
* @param impl Implementation.
* @param addr Address.
*/
public void onAddrResolve(InetAddressImpl impl, byte[] addr) throws UnknownHostException {
if (!Arrays.equals(impl.loopbackAddress().getAddress(), addr))
/** */
@Override public String getHostByAddr(byte[] addr) throws UnknownHostException {
if (!Arrays.equals(loopback.getAddress(), addr))
check(InetAddress.getByAddress(addr).toString());

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
4 changes: 2 additions & 2 deletions modules/ducktests/tests/ignitetest/services/ignite.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@ class IgniteService(IgniteAwareService):
APP_SERVICE_CLASS = "org.apache.ignite.startup.cmdline.CommandLineStartup"

def __init__(self, context, config, num_nodes, jvm_opts=None, merge_with_default=True, startup_timeout_sec=60,
shutdown_timeout_sec=60, modules=None):
super().__init__(context, config, num_nodes, startup_timeout_sec, shutdown_timeout_sec, self.APP_SERVICE_CLASS,
shutdown_timeout_sec=60, modules=None, main_java_class=APP_SERVICE_CLASS):
super().__init__(context, config, num_nodes, startup_timeout_sec, shutdown_timeout_sec, main_java_class,
modules, jvm_opts=jvm_opts, merge_with_default=merge_with_default)
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,8 @@ def envs(self):
return {
'EXCLUDE_TEST_CLASSES': 'true',
'IGNITE_LOG_DIR': self.service.log_dir,
'USER_LIBS': ":".join(self.libs())
'USER_LIBS': ":".join(self.libs()),
"MAIN_CLASS": self.service.main_java_class
}

def config_file_path(self):
Expand Down Expand Up @@ -356,6 +357,3 @@ def command(self, node):
def config_file_path(self):
return self.service.config_file if self.service.config.service_type == IgniteServiceType.NODE \
else self.service.thin_client_config_file

def envs(self):
return {**super().envs(), **{"MAIN_CLASS": self.service.main_java_class}}
17 changes: 2 additions & 15 deletions modules/ducktests/tests/ignitetest/tests/dns_failure_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
"""
Module contains DNS service failure test.
"""
import os
import socket

from ducktape.mark import defaults
Expand All @@ -27,7 +26,6 @@
from ignitetest.services.utils.ignite_configuration import IgniteConfiguration, DataStorageConfiguration
from ignitetest.services.utils.ignite_configuration.data_storage import DataRegionConfiguration
from ignitetest.services.utils.ignite_configuration.discovery import from_ignite_cluster
from ignitetest.services.utils.jvm_utils import java_major_version
from ignitetest.utils import ignite_versions
from ignitetest.utils.ignite_test import IgniteTest
from ignitetest.utils.version import IgniteVersion, DEV_BRANCH
Expand Down Expand Up @@ -110,19 +108,8 @@ def __prepare_service(self, ignite_config, num_nodes=1):
self.test_context,
ignite_config,
startup_timeout_sec=120,
num_nodes=num_nodes)

bootclasspath = list(map(lambda lib: os.path.join(lib, "classes"), ignite.spec._module_libs("ducktests")))

# Note: Support of impl.prefix property was removed since java 18.
ignite.spec.jvm_opts.append("-Dimpl.prefix=BlockingDns")

java_version = ignite.java_version()

if java_major_version(java_version) > 8:
ignite.spec.jvm_opts.append("\"--patch-module java.base=" + ":".join(bootclasspath) + "\"")
else:
ignite.spec.jvm_opts.append("-Xbootclasspath/a:" + ":".join(bootclasspath))
num_nodes=num_nodes,
main_java_class="org.apache.ignite.internal.ducktest.tests.dns_failure_test.DnsBlocker")

return ignite

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
Loading