Skip to content

Commit

Permalink
Stabilize replicaiton test case.
Browse files Browse the repository at this point in the history
  • Loading branch information
koculu committed Oct 15, 2024
1 parent c683e02 commit 7c97c3d
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions src/ZoneTree.UnitTests/ReplicatorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,15 @@ namespace Tenray.ZoneTree.UnitTests;

public sealed class ReplicatorTests
{
[Test]
public void TestReplicator2()
{
for (int i = 0; i < 100; i++)
{
TestReplicator();
}
}

[Test]
public void TestReplicator()
{
Expand All @@ -12,28 +21,25 @@ public void TestReplicator()
Directory.Delete(dataPath, true);
var recordCount = 50_000;
var keyCount = 15_000;
var maxMemory = 10_000;
void CreateData()
{
using var zoneTree = new ZoneTreeFactory<int, int>()
.SetDataDirectory(dataPath + "/source")
.SetMutableSegmentMaxItemCount(maxMemory)
.OpenOrCreate();

using var replica = new ZoneTreeFactory<int, int>()
.SetDataDirectory(dataPath + "/replica")
.SetMutableSegmentMaxItemCount(maxMemory)
.OpenOrCreate();

using var replicator = new Replicator<int, int>(replica, dataPath + "/replica-op-index");
using var maintainer1 = zoneTree.CreateMaintainer();
using var maintainer2 = replica.CreateMaintainer();
var random = new Random();
int replicated = 0;
var k = 0;
Parallel.For(0, recordCount, (i) =>
{
var key = i % keyCount;
var value = random.Next();
var value = Interlocked.Increment(ref k);
var opIndex = zoneTree.Upsert(key, value);
Task.Run(() =>
{
Expand All @@ -60,14 +66,17 @@ void TestEqual()

using var iterator1 = zoneTree.CreateIterator();
using var iterator2 = replica.CreateIterator();
var i = 0;
while (true)
{
var n1 = iterator1.Next();
var n2 = iterator2.Next();
Assert.That(n2, Is.EqualTo(n1));
if (!n1) break;
Assert.That(iterator2.Current, Is.EqualTo(iterator1.Current));
++i;
}
Assert.That(i, Is.EqualTo(keyCount));
zoneTree.Maintenance.Drop();
replica.Maintenance.Drop();
}
Expand Down

0 comments on commit 7c97c3d

Please sign in to comment.