Implement in-process multi-dataset sync isolation across core, network, persistence, and tests
All checks were successful
NuGet Package Publish / nuget (push) Successful in 1m14s

This commit is contained in:
Joseph Doherty
2026-02-22 11:58:34 -05:00
parent c06b56172a
commit 8e97061ab8
60 changed files with 4519 additions and 559 deletions

View File

@@ -0,0 +1,43 @@
using System.Text.Json;
using ZB.MOM.WW.CBDDC.Core.Storage;
namespace ZB.MOM.WW.CBDDC.Core.Tests;
public class DatasetAwareModelTests
{
[Fact]
public void DocumentMetadata_ShouldDefaultDatasetId_ToPrimary()
{
var metadata = new DocumentMetadata("Users", "42", new HlcTimestamp(100, 0, "node"));
metadata.DatasetId.ShouldBe(DatasetId.Primary);
}
[Fact]
public void DocumentMetadata_SerializationRoundTrip_ShouldPreserveDatasetId()
{
var original = new DocumentMetadata("Users", "42", new HlcTimestamp(100, 0, "node"), false, "logs");
string json = JsonSerializer.Serialize(original);
var restored = JsonSerializer.Deserialize<DocumentMetadata>(json);
restored.ShouldNotBeNull();
restored.DatasetId.ShouldBe("logs");
}
[Fact]
public void SnapshotMetadata_ShouldDefaultDatasetId_ToPrimary()
{
var metadata = new SnapshotMetadata();
metadata.DatasetId.ShouldBe(DatasetId.Primary);
}
[Fact]
public void PeerOplogConfirmation_ShouldDefaultDatasetId_ToPrimary()
{
var confirmation = new PeerOplogConfirmation();
confirmation.DatasetId.ShouldBe(DatasetId.Primary);
}
}

View File

@@ -63,11 +63,35 @@ public class OplogEntryTests
/// Verifies that an entry is valid when its stored hash matches computed content.
/// </summary>
[Fact]
public void IsValid_ShouldReturnTrue_WhenHashMatches()
{
var timestamp = new HlcTimestamp(100, 0, "node-1");
var entry = new OplogEntry("col", "key", OperationType.Put, null, timestamp, "prev");
entry.IsValid().ShouldBeTrue();
}
}
public void IsValid_ShouldReturnTrue_WhenHashMatches()
{
var timestamp = new HlcTimestamp(100, 0, "node-1");
var entry = new OplogEntry("col", "key", OperationType.Put, null, timestamp, "prev");
entry.IsValid().ShouldBeTrue();
}
/// <summary>
/// Verifies that entries default to the primary dataset when dataset is omitted.
/// </summary>
[Fact]
public void Constructor_ShouldDefaultDatasetId_ToPrimary()
{
var entry = new OplogEntry("col", "key", OperationType.Put, null, new HlcTimestamp(1, 0, "node"), "prev");
entry.DatasetId.ShouldBe(DatasetId.Primary);
}
/// <summary>
/// Verifies that hash computation includes dataset identity to prevent cross-dataset collisions.
/// </summary>
[Fact]
public void ComputeHash_ShouldDiffer_WhenDatasetDiffers()
{
var timestamp = new HlcTimestamp(100, 0, "node-1");
var primary = new OplogEntry("col", "key", OperationType.Put, null, timestamp, "prev", datasetId: "primary");
var logs = new OplogEntry("col", "key", OperationType.Put, null, timestamp, "prev", datasetId: "logs");
logs.Hash.ShouldNotBe(primary.Hash);
}
}