/* * Copyright (c) 2019, 2021, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions.
*/
// Set to true to perform testing of attach from wrong address (expected to fail). // It's off by default as it caused significant test time increase // (tests <number_of_addresses> * <number_of_addresses> cases, each case fails by timeout). privatestaticboolean testFailedAttach = false;
// A flag to exclude testcases which can cause intermittent CI failures. privatestaticboolean testPotentiallyUnstableCases = false;
boolean ipv4EnclosedTested = false; boolean ipv6EnclosedTested = false; for (InetAddress addr: addresses) { if (testFailedAttach) { for (InetAddress connectAddr : addresses) {
attachTest(addr.getHostAddress(), connectAddr.getHostAddress(), addr.equals(connectAddr));
}
} else {
attachTest(addr.getHostAddress(), addr.getHostAddress(), true);
} // listening on "*" should accept connections from all addresses
attachTest("*", addr.getHostAddress(), true);
// also test that addresses enclosed in square brackets are supported. if (addr instanceof Inet4Address && !ipv4EnclosedTested) {
attachTest("[" + addr.getHostAddress() + "]", "[" + addr.getHostAddress() + "]", true);
ipv4EnclosedTested = true;
} if (addr instanceof Inet6Address && !ipv6EnclosedTested) {
attachTest("[" + addr.getHostAddress() + "]", "[" + addr.getHostAddress() + "]", true);
ipv6EnclosedTested = true;
}
}
// By using "localhost" or empty hostname we should be able to attach // to both IPv4 and IPv6 addresses (127.0.0.1 & ::1). // By default test verifies only "preferred" family (IPv4 or IPv6). // Need to set testPotentiallyUnstableCases to true to perform full testing.
InetAddress localAddresses[] = InetAddress.getAllByName("localhost"); for (int i = 0; i < localAddresses.length; i++) { if (testPotentiallyUnstableCases || addressIsSafeToConnectToLocalhost(localAddresses[i])) {
attachTest(localAddresses[i].getHostAddress(), "", true);
}
}
}
String actualAddress = connector.startListening(args);
String actualPort = actualAddress.substring(actualAddress.lastIndexOf(':') + 1);
String port = args.get("port").value(); // port from connector.startListening must be the same as values from arguments if (!port.equals(actualPort)) { thrownew RuntimeException("values from connector.startListening (" + actualPort
+ " is not equal to values from arguments (" + port + ")");
}
log(" Listening port: " + port);
privatestatic Connector getConnector(String name) {
List<Connector> connectors = Bootstrap.virtualMachineManager().allConnectors(); for (Iterator<Connector> iter = connectors.iterator(); iter.hasNext(); ) {
Connector connector = iter.next(); if (connector.name().equalsIgnoreCase(name)) { return connector;
}
} thrownew IllegalArgumentException("Connector " + name + " not found");
}
privatestaticvoid setConnectorArg(Map<String, Connector.Argument> args, String name, String value) {
Connector.Argument arg = args.get(name); if (arg == null) { thrownew IllegalArgumentException("Argument " + name + " is not defined");
}
arg.setValue(value);
}
// Attach to localhost tries to connect to both IPv4 and IPv6 loopback addresses. // But sometimes it causes interference with other processes which can listen // on the same port but different loopback address. // The method checks if the address is safe to test with current network config. privatestaticboolean addressIsSafeToConnectToLocalhost(InetAddress addr) { boolean ipv6 = Boolean.parseBoolean(System.getProperty("java.net.preferIPv6Addresses")); return ipv6 == (addr instanceof Inet6Address);
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.