update the concurrent test with more tests and assert check

This commit is contained in:
lionsoul2014 2025-12-02 10:37:13 +08:00
parent 12c94cf0b6
commit b7f2ffa285
1 changed files with 9 additions and 2 deletions

View File

@ -1,5 +1,7 @@
package org.lionsoul.ip2region; package org.lionsoul.ip2region;
import static org.junit.Assert.assertEquals;
import java.io.IOException; import java.io.IOException;
import java.util.concurrent.CountDownLatch; import java.util.concurrent.CountDownLatch;
@ -110,10 +112,15 @@ public class Ip2RegionTest {
final Runnable t = new Runnable() { final Runnable t = new Runnable() {
@Override @Override
public void run() { public void run() {
for (int i = 0; i < 1000; i++) { for (int i = 0; i < 2000; i++) {
final byte[] ipBytes = i % 2 == 0 ? v4Bytes : v6Bytes; final byte[] ipBytes = i % 2 == 0 ? v4Bytes : v6Bytes;
try { try {
ip2Region.search(ipBytes); final String region = ip2Region.search(ipBytes);
if (ipBytes.length == 4) {
assertEquals("v4 region not equals", region, "中国|广东省|深圳市|电信");
} else {
assertEquals("v6 region not equals", region, "中国|广东省|深圳市|家庭宽带");
}
} catch (InetAddressException | IOException | InterruptedException e) { } catch (InetAddressException | IOException | InterruptedException e) {
log.errorf("failed to search(%s): %s", Util.ipToString(ipBytes), e.getMessage()); log.errorf("failed to search(%s): %s", Util.ipToString(ipBytes), e.getMessage());
} }