2727import java .util .Map ;
2828import java .util .Vector ;
2929import java .util .concurrent .ConcurrentHashMap ;
30+ import java .util .stream .IntStream ;
31+
3032import org .junit .jupiter .api .AfterEach ;
3133import org .junit .jupiter .api .BeforeEach ;
3234import org .junit .jupiter .api .Test ;
35+ import org .junit .jupiter .params .ParameterizedTest ;
36+ import org .junit .jupiter .params .provider .MethodSource ;
3337
3438public class ReaderTest {
3539 private Reader testReader ;
@@ -46,6 +50,20 @@ public void teardownReader() throws IOException {
4650 }
4751 }
4852
53+ static IntStream chunkSizes () {
54+ int [] sizes = new int [] {
55+ 512 ,
56+ 2048 ,
57+ // The default chunk size of the MultiBuffer is close to max int, that causes
58+ // some issues when running tests in CI as we try to allocate some byte arrays
59+ // that are too big to fit in the heap.
60+ // We use half of that just to be sure nothing breaks, but big enough that we
61+ // ensure SingleBuffer is tested too using the test MMDBs.
62+ MultiBuffer .DEFAULT_CHUNK_SIZE / 2 ,
63+ };
64+ return IntStream .of (sizes );
65+ }
66+
4967 @ Test
5068 public void test () throws IOException {
5169 for (long recordSize : new long [] {24 , 28 , 32 }) {
@@ -457,9 +475,10 @@ public void testNoIpV4SearchTreeFile() throws IOException {
457475 this .testNoIpV4SearchTree (this .testReader );
458476 }
459477
460- @ Test
461- public void testNoIpV4SearchTreeStream () throws IOException {
462- this .testReader = new Reader (getStream ("MaxMind-DB-no-ipv4-search-tree.mmdb" ), 2048 );
478+ @ ParameterizedTest
479+ @ MethodSource ("chunkSizes" )
480+ public void testNoIpV4SearchTreeStream (int chunkSizes ) throws IOException {
481+ this .testReader = new Reader (getStream ("MaxMind-DB-no-ipv4-search-tree.mmdb" ), chunkSizes );
463482 this .testNoIpV4SearchTree (this .testReader );
464483 }
465484
@@ -478,9 +497,10 @@ public void testDecodingTypesFile() throws IOException {
478497 this .testDecodingTypesIntoModelWithList (this .testReader );
479498 }
480499
481- @ Test
482- public void testDecodingTypesStream () throws IOException {
483- this .testReader = new Reader (getStream ("MaxMind-DB-test-decoder.mmdb" ), 2048 );
500+ @ ParameterizedTest
501+ @ MethodSource ("chunkSizes" )
502+ public void testDecodingTypesStream (int chunkSize ) throws IOException {
503+ this .testReader = new Reader (getStream ("MaxMind-DB-test-decoder.mmdb" ), chunkSize );
484504 this .testDecodingTypes (this .testReader , true );
485505 this .testDecodingTypesIntoModelObject (this .testReader , true );
486506 this .testDecodingTypesIntoModelObjectBoxed (this .testReader , true );
@@ -1138,9 +1158,10 @@ public void testBrokenDatabaseFile() throws IOException {
11381158 this .testBrokenDatabase (this .testReader );
11391159 }
11401160
1141- @ Test
1142- public void testBrokenDatabaseStream () throws IOException {
1143- this .testReader = new Reader (getStream ("GeoIP2-City-Test-Broken-Double-Format.mmdb" ), 2048 );
1161+ @ ParameterizedTest
1162+ @ MethodSource ("chunkSizes" )
1163+ public void testBrokenDatabaseStream (int chunkSize ) throws IOException {
1164+ this .testReader = new Reader (getStream ("GeoIP2-City-Test-Broken-Double-Format.mmdb" ), chunkSize );
11441165 this .testBrokenDatabase (this .testReader );
11451166 }
11461167
@@ -1158,9 +1179,10 @@ public void testBrokenSearchTreePointerFile() throws IOException {
11581179 this .testBrokenSearchTreePointer (this .testReader );
11591180 }
11601181
1161- @ Test
1162- public void testBrokenSearchTreePointerStream () throws IOException {
1163- this .testReader = new Reader (getStream ("MaxMind-DB-test-broken-pointers-24.mmdb" ), 2048 );
1182+ @ ParameterizedTest
1183+ @ MethodSource ("chunkSizes" )
1184+ public void testBrokenSearchTreePointerStream (int chunkSize ) throws IOException {
1185+ this .testReader = new Reader (getStream ("MaxMind-DB-test-broken-pointers-24.mmdb" ), chunkSize );
11641186 this .testBrokenSearchTreePointer (this .testReader );
11651187 }
11661188
@@ -1176,9 +1198,10 @@ public void testBrokenDataPointerFile() throws IOException {
11761198 this .testBrokenDataPointer (this .testReader );
11771199 }
11781200
1179- @ Test
1180- public void testBrokenDataPointerStream () throws IOException {
1181- this .testReader = new Reader (getStream ("MaxMind-DB-test-broken-pointers-24.mmdb" ), 2048 );
1201+ @ ParameterizedTest
1202+ @ MethodSource ("chunkSizes" )
1203+ public void testBrokenDataPointerStream (int chunkSize ) throws IOException {
1204+ this .testReader = new Reader (getStream ("MaxMind-DB-test-broken-pointers-24.mmdb" ), chunkSize );
11821205 this .testBrokenDataPointer (this .testReader );
11831206 }
11841207
0 commit comments