Config build tests from XdbFile and XdbInputStream
This commit is contained in:
parent
9b0bedc045
commit
450fce589c
|
|
@ -23,7 +23,7 @@ public class Config {
|
||||||
public static final int VIndexCache = 1;
|
public static final int VIndexCache = 1;
|
||||||
public static final int BufferCache = 2;
|
public static final int BufferCache = 2;
|
||||||
|
|
||||||
// alias of BufferCache but easier to understand
|
// alias of BufferCache but easier to understand or Remember
|
||||||
public static final int FullCache = 2;
|
public static final int FullCache = 2;
|
||||||
|
|
||||||
// search cache policy
|
// search cache policy
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,6 @@
|
||||||
package org.lionsoul.ip2region.service;
|
package org.lionsoul.ip2region.service;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileInputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.security.CodeSource;
|
import java.security.CodeSource;
|
||||||
|
|
||||||
|
|
@ -23,13 +25,35 @@ public class ConfigTest {
|
||||||
@Test
|
@Test
|
||||||
public void testBuildV4Config() throws IOException, XdbException, InvalidConfigException {
|
public void testBuildV4Config() throws IOException, XdbException, InvalidConfigException {
|
||||||
final Config v4Config = Config.custom()
|
final Config v4Config = Config.custom()
|
||||||
.setCachePolicy(Config.BufferCache)
|
.setCachePolicy(Config.VIndexCache)
|
||||||
.setXdbPath(getDataPath("ip2region_v4.xdb"))
|
.setXdbPath(getDataPath("ip2region_v4.xdb"))
|
||||||
.setSearchers(20)
|
.setSearchers(20)
|
||||||
.asV4();
|
.asV4();
|
||||||
log.debugf("builded config: %s", v4Config);
|
log.debugf("builded config: %s", v4Config);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testBuildV4ConfigFromFile() throws IOException, XdbException, InvalidConfigException {
|
||||||
|
final Config v4Config = Config.custom()
|
||||||
|
.setCachePolicy(Config.BufferCache)
|
||||||
|
.setXdbFile(new File(getDataPath("ip2region_v4.xdb")))
|
||||||
|
.setSearchers(20)
|
||||||
|
.asV4();
|
||||||
|
log.debugf("builded config: %s", v4Config);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testBuildV4ConfigFromInputStream() throws IOException, XdbException, InvalidConfigException {
|
||||||
|
final Config v4Config = Config.custom()
|
||||||
|
.setCachePolicy(Config.BufferCache)
|
||||||
|
.setXdbInputStream(new FileInputStream(getDataPath("ip2region_v4.xdb")))
|
||||||
|
.setSearchers(20)
|
||||||
|
.asV4();
|
||||||
|
log.debugf("builded config: %s", v4Config);
|
||||||
|
}
|
||||||
|
|
||||||
|
// --- IPv6
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testBuildV6Config() throws IOException, XdbException, InvalidConfigException {
|
public void testBuildV6Config() throws IOException, XdbException, InvalidConfigException {
|
||||||
final Config v4Config = Config.custom()
|
final Config v4Config = Config.custom()
|
||||||
|
|
@ -39,4 +63,25 @@ public class ConfigTest {
|
||||||
.asV6();
|
.asV6();
|
||||||
log.debugf("builded config: %s", v4Config);
|
log.debugf("builded config: %s", v4Config);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testBuildV6ConfigFromFile() throws IOException, XdbException, InvalidConfigException {
|
||||||
|
final Config v4Config = Config.custom()
|
||||||
|
.setCachePolicy(Config.BufferCache)
|
||||||
|
.setXdbFile(new File(getDataPath("ip2region_v6.xdb")))
|
||||||
|
.setSearchers(20)
|
||||||
|
.asV6();
|
||||||
|
log.debugf("builded config: %s", v4Config);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testBuildV6ConfigFromInputStream() throws IOException, XdbException, InvalidConfigException {
|
||||||
|
final Config v4Config = Config.custom()
|
||||||
|
.setCachePolicy(Config.BufferCache)
|
||||||
|
.setXdbInputStream(new FileInputStream(getDataPath("ip2region_v6.xdb")))
|
||||||
|
.setSearchers(20)
|
||||||
|
.asV6();
|
||||||
|
log.debugf("builded config: %s", v4Config);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue