Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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: 3 additions & 3 deletions src/test/java/com/maxmind/db/DecoderTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -257,10 +257,10 @@ private static Map<Boolean, byte[]> booleans() {
return booleans;
}

private static Map<Map, byte[]> maps() {
Map<Map, byte[]> maps = new HashMap<>();
private static Map<Map<String, ?>, byte[]> maps() {
Map<Map<String, ?>, byte[]> maps = new HashMap<>();

Map empty = new HashMap();
Map<String, Object> empty = Map.of();
maps.put(empty, new byte[] {(byte) 0xe0});

Map<String, String> one = new HashMap<>();
Expand Down
15 changes: 7 additions & 8 deletions src/test/java/com/maxmind/db/MultiThreadedTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import java.io.IOException;
import java.net.InetAddress;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
Expand All @@ -19,7 +18,7 @@ public class MultiThreadedTest {
@Test
public void multipleMmapOpens() throws InterruptedException,
ExecutionException {
Callable<Map> task = () -> {
Callable<Map<?, ?>> task = () -> {
try (Reader reader = new Reader(ReaderTest.getFile("MaxMind-DB-test-decoder.mmdb"))) {
return reader.get(InetAddress.getByName("::1.1.1.0"), Map.class);
}
Expand All @@ -45,20 +44,20 @@ public void mmapThreadTest() throws IOException, InterruptedException,

private static void threadTest(final Reader reader)
throws InterruptedException, ExecutionException {
Callable<Map> task = () -> reader.get(InetAddress.getByName("::1.1.1.0"), Map.class);
Callable<Map<?, ?>> task = () -> reader.get(InetAddress.getByName("::1.1.1.0"), Map.class);
MultiThreadedTest.runThreads(task);
}

private static void runThreads(Callable<Map> task)
private static void runThreads(Callable<Map<?, ?>> task)
throws InterruptedException, ExecutionException {
int threadCount = 256;
List<Callable<Map>> tasks = Collections.nCopies(threadCount, task);
var tasks = Collections.nCopies(threadCount, task);
ExecutorService executorService = Executors
.newFixedThreadPool(threadCount);
List<Future<Map>> futures = executorService.invokeAll(tasks);
var futures = executorService.invokeAll(tasks);

for (Future<Map> future : futures) {
Map record = future.get();
for (Future<Map<?, ?>> future : futures) {
Map<?, ?> record = future.get();
assertEquals(268435456, (long) record.get("uint32"));
assertEquals("unicode! ☯ - ♫", record.get("utf8_string"));
}
Expand Down
63 changes: 29 additions & 34 deletions src/test/java/com/maxmind/db/ReaderTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,13 @@ public void testNetworks() throws IOException, InvalidDatabaseException, Invalid
File file = getFile("MaxMind-DB-test-ipv" + ipVersion + "-" + recordSize + ".mmdb");

Reader reader = new Reader(file);
Networks networks = reader.networks(false, Map.class);
var networks = reader.networks(false, Map.class);

while(networks.hasNext()) {
DatabaseRecord<Map<String, String>> iteration = networks.next();
Map<String, String> data = iteration.getData();
var iteration = networks.next();
var data = (Map<?, ?>) iteration.getData();

InetAddress actualIPInData = InetAddress.getByName(data.get("ip"));
InetAddress actualIPInData = InetAddress.getByName((String) data.get("ip"));

assertEquals(
iteration.getNetwork().getNetworkAddress(),
Expand All @@ -110,11 +110,11 @@ public void testNetworksWithInvalidSearchTree() throws IOException, InvalidNetwo
File file = getFile("MaxMind-DB-test-broken-search-tree-24.mmdb");
Reader reader = new Reader(file);

Networks networks = reader.networks(false, Map.class);
var networks = reader.networks(false, Map.class);

Exception exception = assertThrows(RuntimeException.class, () -> {
while(networks.hasNext()){
DatabaseRecord iteration = networks.next();
assertNotNull(networks.next());
}
});

Expand Down Expand Up @@ -339,11 +339,11 @@ public void testNetworksWithin() throws IOException, InvalidNetworkException{
Network network = new Network(address, test.prefix);

boolean includeAliasedNetworks = !test.skipAliasedNetworks;
Networks networks = reader.networksWithin(network, includeAliasedNetworks, Map.class);
var networks = reader.networksWithin(network, includeAliasedNetworks, Map.class);

ArrayList<String> innerIPs = new ArrayList<>();
List<String> innerIPs = new ArrayList<>();
while(networks.hasNext()){
DatabaseRecord<Map<String,String>> iteration = networks.next();
var iteration = networks.next();
innerIPs.add(iteration.getNetwork().toString());
}

Expand Down Expand Up @@ -376,11 +376,11 @@ public void testGeoIPNetworksWithin() throws IOException, InvalidNetworkExceptio
InetAddress address = InetAddress.getByName(test.network);
Network network = new Network(address, test.prefix);

Networks networks = reader.networksWithin(network, test.skipAliasedNetworks, Map.class);
var networks = reader.networksWithin(network, test.skipAliasedNetworks, Map.class);

ArrayList<String> innerIPs = new ArrayList<>();
while(networks.hasNext()){
DatabaseRecord<Map<String,String>> iteration = networks.next();
var iteration = networks.next();
innerIPs.add(iteration.getNetwork().toString());
}

Expand Down Expand Up @@ -408,7 +408,7 @@ public void testGetRecord() throws IOException {
};
for (GetRecordTest test : mapTests) {
try (Reader reader = new Reader(test.db)) {
DatabaseRecord record = reader.getRecord(test.ip, Map.class);
DatabaseRecord<?> record = reader.getRecord(test.ip, Map.class);

assertEquals(test.network, record.getNetwork().toString());

Expand All @@ -432,7 +432,7 @@ public void testGetRecord() throws IOException {
};
for (GetRecordTest test : stringTests) {
try (Reader reader = new Reader(test.db)) {
DatabaseRecord record = reader.getRecord(test.ip, String.class);
var record = reader.getRecord(test.ip, String.class);

assertEquals(test.network, record.getNetwork().toString());

Expand Down Expand Up @@ -497,7 +497,7 @@ public void testDecodingTypesPointerDecoderFile() throws IOException {
}

private void testDecodingTypes(Reader reader, boolean booleanValue) throws IOException {
Map record = reader.get(InetAddress.getByName("::1.1.1.0"), Map.class);
var record = reader.get(InetAddress.getByName("::1.1.1.0"), Map.class);

if (booleanValue) {
assertTrue((boolean) record.get("boolean"));
Expand All @@ -510,21 +510,19 @@ private void testDecodingTypes(Reader reader, boolean booleanValue) throws IOExc

assertEquals("unicode! ☯ - ♫", record.get("utf8_string"));

@SuppressWarnings("unchecked")
List<Object> array = (List<Object>) record.get("array");
var array = (List<?>) record.get("array");
assertEquals(3, array.size());
assertEquals(1, (long) array.get(0));
assertEquals(2, (long) array.get(1));
assertEquals(3, (long) array.get(2));

Map map = (Map) record.get("map");
var map = (Map<?, ?>) record.get("map");
assertEquals(1, map.size());

Map mapX = (Map) map.get("mapX");
var mapX = (Map<?, ?>) map.get("mapX");
assertEquals(2, mapX.size());

@SuppressWarnings("unchecked")
List<Object> arrayX = (List<Object>) mapX.get("arrayX");
var arrayX = (List<?>) mapX.get("arrayX");
assertEquals(3, arrayX.size());
assertEquals(7, (long) arrayX.get(0));
assertEquals(8, (long) arrayX.get(1));
Expand Down Expand Up @@ -816,19 +814,18 @@ public void testZerosStream() throws IOException {
}

private void testZeros(Reader reader) throws IOException {
Map record = reader.get(InetAddress.getByName("::"), Map.class);
var record = reader.get(InetAddress.getByName("::"), Map.class);

assertFalse((boolean) record.get("boolean"));

assertArrayEquals(new byte[0], (byte[]) record.get("bytes"));

assertEquals("", record.get("utf8_string"));

@SuppressWarnings("unchecked")
List<Object> array = (List<Object>) record.get("array");
var array = (List<?>) record.get("array");
assertEquals(0, array.size());

Map map = (Map) record.get("map");
var map = (Map<?, ?>) record.get("map");
assertEquals(0, map.size());

assertEquals(0, (double) record.get("double"), 0.000000001);
Expand Down Expand Up @@ -1009,16 +1006,14 @@ public TestDataTypeMismatchInModel(
public void testDecodeConcurrentHashMap() throws IOException {
this.testReader = new Reader(getFile("GeoIP2-City-Test.mmdb"));

@SuppressWarnings("unchecked")
ConcurrentHashMap<String, Object> m = this.testReader.get(
var m = this.testReader.get(
InetAddress.getByName("2.125.160.216"),
ConcurrentHashMap.class
);

@SuppressWarnings("unchecked")
List<Map<String, Object>> subdivisions = (List) m.get("subdivisions");
var subdivisions = (List<?>) m.get("subdivisions");

Map<String, Object> eng = subdivisions.get(0);
var eng = (Map<?, ?>) subdivisions.get(0);

String isoCode = (String) eng.get("iso_code");
assertEquals("ENG", isoCode);
Expand Down Expand Up @@ -1100,17 +1095,17 @@ public TestModelB(
public void testCacheKey() {
Class<TestModelCacheKey> cls = TestModelCacheKey.class;

CacheKey a = new CacheKey(1, cls, getType(cls, 0));
CacheKey b = new CacheKey(1, cls, getType(cls, 0));
CacheKey<TestModelCacheKey> a = new CacheKey<>(1, cls, getType(cls, 0));
CacheKey<TestModelCacheKey> b = new CacheKey<>(1, cls, getType(cls, 0));
assertEquals(a, b);

CacheKey c = new CacheKey(2, cls, getType(cls, 0));
CacheKey<TestModelCacheKey> c = new CacheKey<>(2, cls, getType(cls, 0));
assertNotEquals(a, c);

CacheKey d = new CacheKey(1, String.class, getType(cls, 0));
CacheKey<String> d = new CacheKey<>(1, String.class, getType(cls, 0));
assertNotEquals(a, d);

CacheKey e = new CacheKey(1, cls, getType(cls, 1));
CacheKey<TestModelCacheKey> e = new CacheKey<>(1, cls, getType(cls, 1));
assertNotEquals(a, e);
}

Expand Down
Loading