Skip to content

Commit 1bc31cf

Browse files
committed
IGNITE-22671 Fix dns_failure ducktape test compilation for jdk11
1 parent 91521a6 commit 1bc31cf

File tree

6 files changed

+55
-105
lines changed

6 files changed

+55
-105
lines changed

Diff for: modules/ducktests/src/main/java/java/net/BlockingDnsInet4AddressImpl.java

-34
This file was deleted.

Diff for: modules/ducktests/src/main/java/java/net/BlockingDnsInet6AddressImpl.java

-34
This file was deleted.

Diff for: modules/ducktests/src/main/java/java/net/DnsBlocker.java renamed to modules/ducktests/src/main/java/org/apache/ignite/internal/ducktest/tests/dns_failure_test/DnsBlocker.java

+48-19
Original file line numberDiff line numberDiff line change
@@ -14,46 +14,75 @@
1414
* See the License for the specific language governing permissions and
1515
* limitations under the License.
1616
*/
17-
package java.net;
17+
package org.apache.ignite.internal.ducktest.tests.dns_failure_test;
18+
19+
import org.apache.ignite.IgniteCheckedException;
20+
import org.apache.ignite.internal.util.typedef.internal.U;
21+
import org.apache.ignite.startup.cmdline.CommandLineStartup;
22+
import sun.net.spi.nameservice.NameService;
1823

1924
import java.io.File;
2025
import java.io.FileNotFoundException;
26+
import java.net.InetAddress;
27+
import java.net.UnknownHostException;
2128
import java.text.SimpleDateFormat;
2229
import java.util.Arrays;
2330
import java.util.Date;
31+
import java.util.List;
2432
import java.util.Scanner;
2533

2634
/** */
27-
public class DnsBlocker {
35+
public class DnsBlocker implements NameService {
2836
/** */
2937
private static final String BLOCK_DNS_FILE = "/tmp/block_dns";
3038

3139
/** */
32-
public static final DnsBlocker INSTANCE = new DnsBlocker();
40+
private final InetAddress loopback;
3341

34-
/** */
35-
private DnsBlocker() {
36-
// No-op.
37-
}
42+
/** Original NameService to use after unblock. */
43+
private final NameService orig;
3844

3945
/**
40-
* Check and block hostname resolve request if needed.
41-
* @param impl Implementation.
42-
* @param hostname Hostname.
46+
* @param orig Original NameService to use after unblock.
4347
*/
44-
public void onHostResolve(InetAddressImpl impl, String hostname) throws UnknownHostException {
45-
if (!impl.loopbackAddress().getHostAddress().equals(hostname))
48+
private DnsBlocker(NameService orig) {
49+
loopback = InetAddress.getLoopbackAddress();
50+
this.orig = orig;
51+
}
52+
53+
/** Installs DnsBlocker as main NameService to JVM. */
54+
private static void install() throws IgniteCheckedException {
55+
List<NameService> nameSrvc = U.staticField(InetAddress.class, "nameServices");
56+
57+
NameService ns = new DnsBlocker(nameSrvc.get(0));
58+
59+
// Put the blocking name service ahead.
60+
nameSrvc.add(0, ns);
61+
62+
System.out.println("Installed DnsBlocker as main NameService to JVM [ns=" + nameSrvc.size() + ']');
63+
}
64+
65+
/** */
66+
public static void main(String[] args) throws Exception {
67+
install();
68+
69+
CommandLineStartup.main(args);
70+
}
71+
72+
/** */
73+
@Override public InetAddress[] lookupAllHostAddr(String hostname) throws UnknownHostException {
74+
if (!loopback.getHostAddress().equals(hostname))
4675
check(hostname);
76+
77+
return orig.lookupAllHostAddr(hostname);
4778
}
4879

49-
/**
50-
* Check and block address resolve request if needed.
51-
* @param impl Implementation.
52-
* @param addr Address.
53-
*/
54-
public void onAddrResolve(InetAddressImpl impl, byte[] addr) throws UnknownHostException {
55-
if (!Arrays.equals(impl.loopbackAddress().getAddress(), addr))
80+
/** */
81+
@Override public String getHostByAddr(byte[] addr) throws UnknownHostException {
82+
if (!Arrays.equals(loopback.getAddress(), addr))
5683
check(InetAddress.getByAddress(addr).toString());
84+
85+
return orig.getHostByAddr(addr);
5786
}
5887

5988
/** */

Diff for: modules/ducktests/tests/ignitetest/services/ignite.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,6 @@ class IgniteService(IgniteAwareService):
2727
APP_SERVICE_CLASS = "org.apache.ignite.startup.cmdline.CommandLineStartup"
2828

2929
def __init__(self, context, config, num_nodes, jvm_opts=None, merge_with_default=True, startup_timeout_sec=60,
30-
shutdown_timeout_sec=60, modules=None):
31-
super().__init__(context, config, num_nodes, startup_timeout_sec, shutdown_timeout_sec, self.APP_SERVICE_CLASS,
30+
shutdown_timeout_sec=60, modules=None, main_java_class=APP_SERVICE_CLASS):
31+
super().__init__(context, config, num_nodes, startup_timeout_sec, shutdown_timeout_sec, main_java_class,
3232
modules, jvm_opts=jvm_opts, merge_with_default=merge_with_default)

Diff for: modules/ducktests/tests/ignitetest/services/utils/ignite_spec.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,9 @@ def _runcmd(self, cmd):
300300
if proc.returncode != 0:
301301
raise RuntimeError("Command '%s' returned non-zero exit status %d: %s" % (cmd, proc.returncode, stdout))
302302

303+
def envs(self):
304+
return {"MAIN_CLASS": self.service.main_java_class}
305+
303306

304307
class IgniteNodeSpec(IgniteSpec):
305308
"""
@@ -356,6 +359,3 @@ def command(self, node):
356359
def config_file_path(self):
357360
return self.service.config_file if self.service.config.service_type == IgniteServiceType.NODE \
358361
else self.service.thin_client_config_file
359-
360-
def envs(self):
361-
return {**super().envs(), **{"MAIN_CLASS": self.service.main_java_class}}

Diff for: modules/ducktests/tests/ignitetest/tests/dns_failure_test.py

+2-13
Original file line numberDiff line numberDiff line change
@@ -110,19 +110,8 @@ def __prepare_service(self, ignite_config, num_nodes=1):
110110
self.test_context,
111111
ignite_config,
112112
startup_timeout_sec=120,
113-
num_nodes=num_nodes)
114-
115-
bootclasspath = list(map(lambda lib: os.path.join(lib, "classes"), ignite.spec._module_libs("ducktests")))
116-
117-
# Note: Support of impl.prefix property was removed since java 18.
118-
ignite.spec.jvm_opts.append("-Dimpl.prefix=BlockingDns")
119-
120-
java_version = ignite.java_version()
121-
122-
if java_major_version(java_version) > 8:
123-
ignite.spec.jvm_opts.append("\"--patch-module java.base=" + ":".join(bootclasspath) + "\"")
124-
else:
125-
ignite.spec.jvm_opts.append("-Xbootclasspath/a:" + ":".join(bootclasspath))
113+
num_nodes=num_nodes,
114+
main_java_class="org.apache.ignite.internal.ducktest.tests.dns_failure_test.DnsBlocker")
126115

127116
return ignite
128117

0 commit comments

Comments
 (0)