Skip to content

Commit e315bd0

Browse files
add tests and document
1 parent 2d61334 commit e315bd0

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

README.adoc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,12 @@ Do NOT use it.
103103
|true
104104
|false
105105

106+
.2+|dnsjava.hostsfile.max_size
107+
3+|Set the size of the hosts file to be loaded at a time,in bytes.
108+
|Integer
109+
|16384
110+
|1000000
111+
106112
.2+|dnsjava.nio.selector_timeout
107113
3+|Set selector timeout in milliseconds. Default/Max 1000, Min 1.
108114
|Integer

src/main/java/org/xbill/DNS/hosts/HostsFileParser.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@
2929
*/
3030
@Slf4j
3131
public final class HostsFileParser {
32-
private static final int MAX_FULL_CACHE_FILE_SIZE_BYTES = Integer.parseInt(
32+
33+
private final int MAX_FULL_CACHE_FILE_SIZE_BYTES = Integer.parseInt(
3334
System.getProperty("dnsjava.hostsfile.max_size", "16384"));
3435

3536
private final Map<String, InetAddress> hostsCache = new HashMap<>();

src/test/java/org/xbill/DNS/hosts/HostsFileParserTest.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,17 @@ void testBigFileIsNotCompletelyCachedA() throws IOException {
171171
assertEquals(1, hostsFileParser.cacheSize());
172172
}
173173

174+
@Test
175+
void testBigFileCompletelyCachedA() throws IOException {
176+
System.setProperty("dnsjava.hostsfile.max_size", 1024 * 1024 * 1024 + "");
177+
HostsFileParser hostsFileParser = generateLargeHostsFile("testBigFileCompletelyCachedA");
178+
hostsFileParser
179+
.getAddressForHost(Name.fromConstantString("localhost-10."), Type.A)
180+
.orElseThrow(() -> new IllegalStateException("Host entry not found"));
181+
assertEquals(1280, hostsFileParser.cacheSize());
182+
System.clearProperty("dnsjava.hostsfile.max_size");
183+
}
184+
174185
@Test
175186
void testBigFileIsNotCompletelyCachedAAAA() throws IOException {
176187
HostsFileParser hostsFileParser =

0 commit comments

Comments
 (0)