Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,12 @@ Do NOT use it.
|true
|false

.2+|dnsjava.hostsfile.max_size
Comment thread
ibauersachs marked this conversation as resolved.
Outdated
3+|Set the size of the hosts file to be loaded at a time,in bytes.
Comment thread
ibauersachs marked this conversation as resolved.
Outdated
|Integer
|16384
|1000000

.2+|dnsjava.nio.selector_timeout
3+|Set selector timeout in milliseconds. Default/Max 1000, Min 1.
|Integer
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/org/xbill/DNS/hosts/HostsFileParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@
*/
@Slf4j
public final class HostsFileParser {
private static final int MAX_FULL_CACHE_FILE_SIZE_BYTES = 16384;
private final int MAX_FULL_CACHE_FILE_SIZE_BYTES = Integer.parseInt(
System.getProperty("dnsjava.hostsfile.max_size_bytes", "16384"));

private final Map<String, InetAddress> hostsCache = new HashMap<>();
private final Path path;
Expand Down
13 changes: 13 additions & 0 deletions src/test/java/org/xbill/DNS/hosts/HostsFileParserTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,19 @@ void testBigFileIsNotCompletelyCachedA() throws IOException {
assertEquals(1, hostsFileParser.cacheSize());
}

@Test
void testBigFileCompletelyCachedA() throws IOException {
System.setProperty("dnsjava.hostsfile.max_size_bytes", 1024 * 1024 * 1024 + "");
HostsFileParser hostsFileParser = generateLargeHostsFile("testBigFileCompletelyCachedA");
Comment thread
ibauersachs marked this conversation as resolved.
Outdated
try {
hostsFileParser.getAddressForHost(Name.fromConstantString("localhost-10."), Type.A)
.orElseThrow(() -> new IllegalStateException("Host entry not found"));
assertEquals(1280, hostsFileParser.cacheSize());
} finally {
System.clearProperty("dnsjava.hostsfile.max_size_bytes");
}
}

@Test
void testBigFileIsNotCompletelyCachedAAAA() throws IOException {
HostsFileParser hostsFileParser =
Expand Down