Skip to content

Commit cbf83d9

Browse files
oschwaldclaude
andcommitted
Test MEMORY mode under chunkSizes matrix
The existing chunkSizes parametrized matrix in ReaderTest only routed through Reader(File, int chunkSize), which hardcodes FileMode.MEMORY_MAPPED. As a result the chunked file-MEMORY load path in BufferHolder had no integration coverage — a remainder-chunk-sized- wrong regression or an EOF-handling change could ship silently. Add a package-private Reader(File, FileMode, int chunkSize) constructor and a testMemoryMode(int chunkSize) test that mirrors test(int) but in MEMORY mode. With chunk sizes 512/2048 against the test DBs (1285 and 2794 bytes), the multi-chunk + remainder branch is now exercised end to end. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent e2be3a5 commit cbf83d9

2 files changed

Lines changed: 24 additions & 1 deletion

File tree

src/main/java/com/maxmind/db/Reader.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,12 @@ public Reader(File database) throws IOException {
5959
}
6060

6161
Reader(File database, int chunkSize) throws IOException {
62+
this(database, FileMode.MEMORY_MAPPED, chunkSize);
63+
}
64+
65+
Reader(File database, FileMode fileMode, int chunkSize) throws IOException {
6266
this(
63-
new BufferHolder(database, FileMode.MEMORY_MAPPED, chunkSize),
67+
new BufferHolder(database, fileMode, chunkSize),
6468
database.getName(),
6569
NoCache.getInstance()
6670
);

src/test/java/com/maxmind/db/ReaderTest.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import static org.junit.jupiter.api.Assertions.assertThrows;
1313
import static org.junit.jupiter.api.Assertions.assertTrue;
1414

15+
import com.maxmind.db.Reader.FileMode;
1516
import java.io.File;
1617
import java.io.IOException;
1718
import java.io.InputStream;
@@ -83,6 +84,24 @@ public void test(int chunkSize) throws IOException {
8384
}
8485
}
8586

87+
@ParameterizedTest
88+
@MethodSource("chunkSizes")
89+
public void testMemoryMode(int chunkSize) throws IOException {
90+
for (long recordSize : new long[] {24, 28, 32}) {
91+
for (int ipVersion : new int[] {4, 6}) {
92+
var file = getFile("MaxMind-DB-test-ipv" + ipVersion + "-" + recordSize + ".mmdb");
93+
try (var reader = new Reader(file, FileMode.MEMORY, chunkSize)) {
94+
this.testMetadata(reader, ipVersion, recordSize);
95+
if (ipVersion == 4) {
96+
this.testIpV4(reader, file);
97+
} else {
98+
this.testIpV6(reader, file);
99+
}
100+
}
101+
}
102+
}
103+
}
104+
86105
static class GetRecordTest {
87106
InetAddress ip;
88107
File db;

0 commit comments

Comments
 (0)