Regarding 8220575: Correctly format test URI's that contain a retrieved IPv6 address
Chris Hegarty
chris.hegarty at oracle.com
Wed Mar 13 18:45:04 UTC 2019
Daniel,
On 13/03/2019 18:22, Daniel Fuchs wrote:
> Hi Chris,
>
> On 13/03/2019 17:32, Chris Hegarty wrote:
>> I think that is most cases
>> it should be possible to just replace the use of `getHostAddress` with
>> `getHostName`. This defers the actual lookup to the system configured
>> name service ( rather than trying to encode IPv6 addresses in the
>> test )
> I think I'd prefer to use getHostAddress() and one of the multi
> arg constructors for URI/URL instead, as it makes it more explicit
> that you're using the same address on both side of the connection.
>
> Are we otherwise sure that the hostname would resolve to the
> exact same address?
>
> For instance:
>
> jshell> InetAddress.getLoopbackAddress().getHostName()
> $7 ==> "localhost"
>
> jshell> InetAddress.getAllByName("localhost");
> $8 ==> InetAddress[3] {
> localhost/127.0.0.1,
> localhost/0:0:0:0:0:0:0:1,
> localhost/fe80:0:0:0:0:0:0:1%1
> }
Good point.
Many test ( that don't explicitly test binding or particulars of
encoding of the address in the URI / URL ), simply don't care about this
detail. They're likely testing something in the internal implementation
of the protocol handler, or something. But you do raise a good point,
which relates to test stability; the client and server sides of the
tests need to be using the same interface / address ).
While testing, I have observed some URIs similar to
http://[0:0:0:0:0:0:0:1]:46009/zero/xxyy, in the log files. It's
comforting to know the exact address that is in use.
What I dislike about such an approach is its verbosity in the test code,
e.g.
static URL urlFor(int port, String path) throws Exception {
return new URI("http",
null,
loopbackAddress.getHostAddress(),
port,
path,
null,
null).toURL();
}
This is a typical example of usage in tests, where the protocol being
tested is `http`. The host address here will be correctly enclosed by
square brackets if needed.
Alternative ( shorter, hack ):
String host = loopbackAddress.getHostAddress();
if (host.contains(":"))
host = "[" + host + "]";
Regardless of the outcome, the use of a test library function will
likely not help much, as it adds jtreg tag verbosity and build
complexity that is probably more verbose than either of the above.
-Chris.
More information about the net-dev
mailing list