test:concurrent query ip

This commit is contained in:
Alan 2023-07-26 21:30:34 +08:00
parent 7f5ec337d0
commit df1252345b
5 changed files with 25 additions and 683603 deletions

View File

@ -16,4 +16,11 @@
<ProjectReference Include="..\IP2Region.Net\IP2Region.Net.csproj" />
</ItemGroup>
<ItemGroup>
<Content Include="..\..\..\data\ip2region.xdb">
<Link>IP2Region/ip2region.xdb</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
</Project>

View File

@ -21,13 +21,14 @@
</ItemGroup>
<ItemGroup>
<Folder Include="TestData" />
</ItemGroup>
<ItemGroup>
<None Update="TestData\ip.merge.txt">
<Content Include="..\..\..\data\ip.merge.txt">
<Link>TestData/ip.merge.txt</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</Content>
<Content Include="..\..\..\data\ip2region.xdb">
<Link>TestData/ip2region.xdb</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
</Project>

View File

@ -5,6 +5,8 @@ namespace IP2Region.Net.Test;
[TestFixture]
public class SearcherTest
{
private readonly string _xdbPath = Path.Combine(AppContext.BaseDirectory, "TestData", "ip2region.xdb");
public static IEnumerable<string> Ips()
{
yield return "114.114.114.114";
@ -15,25 +17,28 @@ public class SearcherTest
}
[TestCaseSource(nameof(Ips))]
[Parallelizable(ParallelScope.All)]
public void TestSearchCacheContent(string ip)
{
var contentSearcher = new Searcher(CachePolicy.Content);
var contentSearcher = new Searcher(CachePolicy.Content,_xdbPath);
var region = contentSearcher.Search(ip);
Console.WriteLine(region);
}
[TestCaseSource(nameof(Ips))]
[Parallelizable(ParallelScope.All)]
public void TestSearchCacheVector(string ip)
{
var vectorSearcher = new Searcher(CachePolicy.VectorIndex);
var vectorSearcher = new Searcher(CachePolicy.VectorIndex,_xdbPath);
var region = vectorSearcher.Search(ip);
Console.WriteLine(region);
}
[TestCaseSource(nameof(Ips))]
[Parallelizable(ParallelScope.All)]
public void TestSearchCacheFile(string ip)
{
var fileSearcher = new Searcher(CachePolicy.File);
var fileSearcher = new Searcher(CachePolicy.File,_xdbPath);
var region = fileSearcher.Search(ip);
Console.WriteLine(region);
}
@ -43,7 +48,7 @@ public class SearcherTest
[TestCase(CachePolicy.File)]
public void TestBenchSearch(CachePolicy cachePolicy)
{
Searcher searcher = new Searcher(cachePolicy);
Searcher searcher = new Searcher(cachePolicy,_xdbPath);
var srcPath = Path.Combine(AppContext.BaseDirectory, "TestData", "ip.merge.txt");
foreach (var line in File.ReadLines(srcPath))

File diff suppressed because it is too large Load Diff

View File

@ -146,9 +146,9 @@ namespace IP2RegionMaker.XDB
{
Console.WriteLine($"try to write region {seg.Region}");
if (_regionPool.ContainsKey(seg.Region))
if (_regionPool.TryGetValue(seg.Region, out var value))
{
Console.WriteLine($"--[Cached] with ptr={_regionPool[seg.Region]}");
Console.WriteLine($"--[Cached] with ptr={value}");
continue;
}