Skip to content

Commit 00b793d

Browse files
committed
Officially deprecating dnsjava usage and removing DnsJavaResolver from tests
1 parent ed6f580 commit 00b793d

File tree

4 files changed

+15
-18
lines changed

4 files changed

+15
-18
lines changed

browsermob-core/src/main/java/net/lightbody/bmp/client/ClientUtil.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ public static AdvancedHostResolver createNativeResolver() {
4242
* calling {@link net.lightbody.bmp.BrowserMobProxy#setHostNameResolver(net.lightbody.bmp.proxy.dns.AdvancedHostResolver)}.
4343
*
4444
* @return a new DnsJavaResolver
45+
* @deprecated The dnsjava resolver has been deprecated in favor of the standard JVM resolver and will be removed in BMP >2.1.
4546
*/
4647
public static AdvancedHostResolver createDnsJavaResolver() {
4748
return new DnsJavaResolver();
@@ -53,6 +54,7 @@ public static AdvancedHostResolver createDnsJavaResolver() {
5354
* Can be used when calling {@link net.lightbody.bmp.BrowserMobProxy#setHostNameResolver(net.lightbody.bmp.proxy.dns.AdvancedHostResolver)}.
5455
*
5556
* @return a new ChainedHostResolver that resolves addresses first using a DnsJavaResolver, then using a NativeCacheManipulatingResolver
57+
* @deprecated The dnsjava resolver has been deprecated in favor of the standard JVM resolver and will be removed in BMP >2.1.
5658
*/
5759
public static AdvancedHostResolver createDnsJavaWithNativeFallbackResolver() {
5860
return new ChainedHostResolver(ImmutableList.of(new DnsJavaResolver(), new NativeCacheManipulatingResolver()));
@@ -74,7 +76,7 @@ public static org.openqa.selenium.Proxy createSeleniumProxy(BrowserMobProxy brow
7476
* Creates a Selenium Proxy object from the BrowserMobProxy instance, using the specified connectableAddress as the Selenium Proxy object's
7577
* proxy address. Determines the port using {@link net.lightbody.bmp.BrowserMobProxy#getPort()}. The BrowserMobProxy must be started.
7678
*
77-
* @param browserMobProxy started BrowserMobProxy instance to read the port from
79+
* @param browserMobProxy started BrowserMobProxy instance to read the port from
7880
* @param connectableAddress the network address the Selenium Proxy will use to reach this BrowserMobProxy instance
7981
* @return a Selenium Proxy instance, configured to use the BrowserMobProxy instance as its proxy server
8082
* @throws java.lang.IllegalStateException if the proxy has not been started.
@@ -105,6 +107,7 @@ public static org.openqa.selenium.Proxy createSeleniumProxy(InetSocketAddress co
105107
* Attempts to retrieve a "connectable" address for this device that other devices on the network can use to connect to a local proxy.
106108
* This is a "reasonable guess" that is suitable in many (but not all) common scenarios.
107109
* TODO: define the algorithm used to discover a "connectable" local host
110+
*
108111
* @return a "reasonable guess" at an address that can be used by other machines on the network to reach this host
109112
*/
110113
public static InetAddress getConnectableAddress() {

browsermob-core/src/main/java/net/lightbody/bmp/proxy/dns/DnsJavaResolver.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
/**
2424
* An {@link net.lightbody.bmp.proxy.dns.AdvancedHostResolver} that uses dnsjava to perform DNS lookups. This implementation provides full
2525
* cache manipulation capabilities.
26+
*
27+
* @deprecated The dnsjava resolver has been deprecated in favor of the standard JVM resolver and will be removed in BMP >2.1.
2628
*/
2729
public class DnsJavaResolver extends AbstractHostNameRemapper implements AdvancedHostResolver {
2830
private static final Logger log = LoggerFactory.getLogger(DnsJavaResolver.class);

browsermob-core/src/test/java/net/lightbody/bmp/proxy/dns/AdvancedHostResolverCacheTest.java

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import java.net.InetAddress;
1313
import java.util.Arrays;
1414
import java.util.Collection;
15+
import java.util.Collections;
1516
import java.util.Random;
1617
import java.util.concurrent.TimeUnit;
1718

@@ -29,7 +30,7 @@ public class AdvancedHostResolverCacheTest {
2930
public static Collection<Object[]> data() {
3031
return Arrays.asList(new Object[][]{
3132
// skip DNS cache operations for NativeResolver
32-
{DnsJavaResolver.class}, {NativeCacheManipulatingResolver.class}, {ChainedHostResolver.class}
33+
{NativeCacheManipulatingResolver.class}, {ChainedHostResolver.class}
3334
});
3435
}
3536

@@ -38,10 +39,7 @@ public static Collection<Object[]> data() {
3839
public AdvancedHostResolverCacheTest(Class<AdvancedHostResolver> resolverClass) throws IllegalAccessException, InstantiationException {
3940
// this is a hacky way to allow us to test the ChainedHostResolver, even though it doesn't have a no-arg constructor
4041
if (resolverClass.equals(ChainedHostResolver.class)) {
41-
// don't use the NativecacheManipulatingResolver on Windows, since it is unsupported
42-
this.resolver = new ChainedHostResolver(
43-
NewProxyServerTestUtil.isWindows() ? ImmutableList.of(new DnsJavaResolver())
44-
: ImmutableList.of(new NativeCacheManipulatingResolver(), new DnsJavaResolver()));
42+
this.resolver = new ChainedHostResolver(ImmutableList.of(new NativeCacheManipulatingResolver()));
4543
} else {
4644
this.resolver = resolverClass.newInstance();
4745
}
@@ -54,10 +52,11 @@ public void skipForTravisCi() {
5452
}
5553

5654
@Before
57-
public void skipForNativeDnsCacheOnWindows() {
58-
// the NativecacheManipulatingResolver does not work on Windows because Java seems to use to the OS-level cache
55+
public void skipOnWindows() {
56+
// DNS cache-manipulating features are not available on Windows, because the NativeCacheManipulatingResolver does
57+
// not work, since Java seems to use to the OS-level cache.
5958
assumeFalse("NativeCacheManipulatingResolver does not support cache manipulation on Windows",
60-
NewProxyServerTestUtil.isWindows() && this.resolver instanceof NativeCacheManipulatingResolver);
59+
NewProxyServerTestUtil.isWindows());
6160
}
6261

6362
@Test

browsermob-core/src/test/java/net/lightbody/bmp/proxy/dns/AdvancedHostResolverTest.java

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public class AdvancedHostResolverTest {
2828
@Parameterized.Parameters
2929
public static Collection<Object[]> data() {
3030
return Arrays.asList(new Object[][]{
31-
{DnsJavaResolver.class}, {NativeResolver.class}, {NativeCacheManipulatingResolver.class}, {ChainedHostResolver.class}
31+
{NativeResolver.class}, {NativeCacheManipulatingResolver.class}, {ChainedHostResolver.class}
3232
});
3333
}
3434

@@ -37,7 +37,7 @@ public static Collection<Object[]> data() {
3737
public AdvancedHostResolverTest(Class<AdvancedHostResolver> resolverClass) throws IllegalAccessException, InstantiationException {
3838
// this is a hacky way to allow us to test the ChainedHostResolver, even though it doesn't have a no-arg constructor
3939
if (resolverClass.equals(ChainedHostResolver.class)) {
40-
this.resolver = new ChainedHostResolver(ImmutableList.of(new DnsJavaResolver(), new NativeResolver(), new NativeCacheManipulatingResolver()));
40+
this.resolver = new ChainedHostResolver(ImmutableList.of(new NativeResolver(), new NativeCacheManipulatingResolver()));
4141
} else {
4242
this.resolver = resolverClass.newInstance();
4343
}
@@ -96,18 +96,11 @@ public void testResolveIPv4AndIPv6Addresses() {
9696

9797
// disabling this assert to prevent test failures on systems without ipv6 access, or when the DNS server does not return IPv6 addresses
9898
//assertTrue("Expected to find at least one IPv6 address for www.google.com", foundIPv6);
99-
// update: since the dnsjava resolver now returns ipv6 addresses *only if there are no ipv4 addresses*, it will generally not return
100-
// any ipv6 addresses for most hostnames
10199

102100
}
103101

104102
@Test
105103
public void testResolveLocalhost() {
106-
// DnsJavaResolver cannot resolve localhost, since it does not look up entries in the hosts file
107-
if (resolver.getClass() == DnsJavaResolver.class) {
108-
return;
109-
}
110-
111104
Collection<InetAddress> addresses = resolver.resolve("localhost");
112105

113106
assertNotNull("Collection of resolved addresses should never be null", addresses);

0 commit comments

Comments
 (0)