Skip to content

Commit f6b6dbb

Browse files
committed
Implement true INTERLEAVE ordering.
Add manual gated IT to dump DEFAULT vs INTERLEAVE results. Expand unit coverage for scope mapping and core RFC comparison rules.
1 parent 3a1bd12 commit f6b6dbb

File tree

5 files changed

+666
-217
lines changed

5 files changed

+666
-217
lines changed
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
/*
2+
* ====================================================================
3+
* Licensed to the Apache Software Foundation (ASF) under one
4+
* or more contributor license agreements. See the NOTICE file
5+
* distributed with this work for additional information
6+
* regarding copyright ownership. The ASF licenses this file
7+
* to you under the Apache License, Version 2.0 (the
8+
* "License"); you may not use this file except in compliance
9+
* with the License. You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing,
14+
* software distributed under the License is distributed on an
15+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16+
* KIND, either express or implied. See the License for the
17+
* specific language governing permissions and limitations
18+
* under the License.
19+
* ====================================================================
20+
*
21+
* This software consists of voluntary contributions made by many
22+
* individuals on behalf of the Apache Software Foundation. For more
23+
* information on the Apache Software Foundation, please see
24+
* <http://www.apache.org/>.
25+
*
26+
*/
27+
28+
package org.apache.hc.client5.testing;
29+
30+
import static org.junit.jupiter.api.Assumptions.assumeTrue;
31+
32+
import java.net.Inet6Address;
33+
import java.net.InetAddress;
34+
35+
import org.apache.hc.client5.http.DnsResolver;
36+
import org.apache.hc.client5.http.Rfc6724AddressSelectingDnsResolver;
37+
import org.apache.hc.client5.http.SystemDefaultDnsResolver;
38+
import org.apache.hc.client5.http.config.ProtocolFamilyPreference;
39+
import org.junit.jupiter.api.Test;
40+
41+
class ManualRfc6724ResolverIT {
42+
43+
private static final String PROP_ENABLE = "httpclient.rfc6724.it";
44+
private static final String PROP_HOST = "httpclient.rfc6724.host";
45+
46+
@Test
47+
void resolve_and_dump_order() throws Exception {
48+
assumeTrue(Boolean.getBoolean(PROP_ENABLE),
49+
"Enable with -Dhttpclient.rfc6724.it=true");
50+
51+
final String host = System.getProperty(PROP_HOST, "localhost");
52+
53+
final DnsResolver base = SystemDefaultDnsResolver.INSTANCE;
54+
55+
System.out.println("Host: " + host);
56+
57+
dump(base, host, ProtocolFamilyPreference.DEFAULT);
58+
System.out.println();
59+
dump(base, host, ProtocolFamilyPreference.INTERLEAVE);
60+
}
61+
62+
private static void dump(
63+
final DnsResolver base,
64+
final String host,
65+
final ProtocolFamilyPreference pref) throws Exception {
66+
67+
final Rfc6724AddressSelectingDnsResolver resolver =
68+
new Rfc6724AddressSelectingDnsResolver(base, pref);
69+
70+
final InetAddress[] out = resolver.resolve(host);
71+
72+
int v4 = 0;
73+
int v6 = 0;
74+
75+
System.out.println("Preference: " + pref);
76+
for (final InetAddress a : out) {
77+
if (a instanceof Inet6Address) {
78+
v6++;
79+
System.out.println(" IPv6 " + a.getHostAddress());
80+
} else {
81+
v4++;
82+
System.out.println(" IPv4 " + a.getHostAddress());
83+
}
84+
}
85+
System.out.println("Counts: IPv4=" + v4 + " IPv6=" + v6);
86+
}
87+
}

0 commit comments

Comments
 (0)