Skip to content

Commit 1c2fa74

Browse files
committed
Clean up the mocks after DnsEndpointTest
Adds an `@AfterClass` method that cleans up the custom resolver. Previously it was possible that the mocked hostname would still be associated with the same ip in another test, causing it to fail in certain cases.
1 parent f5c2583 commit 1c2fa74

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

Diff for: driver-core/src/test/java/com/datastax/driver/core/DnsEndpointTests.java renamed to driver-core/src/test/java/com/datastax/driver/core/DnsEndpointTest.java

+8-2
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,17 @@
77
import java.util.List;
88
import org.slf4j.Logger;
99
import org.slf4j.LoggerFactory;
10+
import org.testng.annotations.AfterClass;
1011
import org.testng.annotations.Test;
1112

12-
public class DnsEndpointTests {
13+
public class DnsEndpointTest {
1314

14-
private static final Logger logger = LoggerFactory.getLogger(DnsEndpointTests.class);
15+
private static final Logger logger = LoggerFactory.getLogger(DnsEndpointTest.class);
16+
17+
@AfterClass(alwaysRun = true)
18+
public void clearMocks() {
19+
MappedHostResolverProvider.unsetResolver();
20+
}
1521

1622
@Test(groups = "long")
1723
public void replace_cluster_test() {

Diff for: driver-core/src/test/java/com/datastax/driver/core/MappedHostResolverProvider.java

+9
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,15 @@ public static synchronized boolean setResolver(MappedHostResolver newResolver) {
1818
return true;
1919
}
2020

21+
public static synchronized boolean unsetResolver() {
22+
if (resolver == null) {
23+
return false;
24+
}
25+
resolver = null;
26+
HostResolutionRequestInterceptor.INSTANCE.uninstall();
27+
return true;
28+
}
29+
2130
public static synchronized void addResolverEntry(String hostname, String address) {
2231
if (resolver == null) {
2332
setResolver(new MappedHostResolver());

0 commit comments

Comments
 (0)