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
All checks were successful
NuGet Package Publish / nuget (push) Successful in 1m14s
This commit is contained in:
43
tests/ZB.MOM.WW.CBDDC.Core.Tests/DatasetAwareModelTests.cs
Normal file
43
tests/ZB.MOM.WW.CBDDC.Core.Tests/DatasetAwareModelTests.cs
Normal 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);
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user