Fix audit findings for coverage, architecture checks, and XML docs
This commit is contained in:
@@ -8,6 +8,9 @@ namespace ZB.MOM.WW.CBDD.Tests;
|
||||
|
||||
public class CompactionOfflineTests
|
||||
{
|
||||
/// <summary>
|
||||
/// Tests offline compact should preserve logical data equivalence.
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void OfflineCompact_ShouldPreserveLogicalDataEquivalence()
|
||||
{
|
||||
@@ -72,6 +75,9 @@ public class CompactionOfflineTests
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tests offline compact should keep index results consistent.
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void OfflineCompact_ShouldKeepIndexResultsConsistent()
|
||||
{
|
||||
@@ -127,6 +133,83 @@ public class CompactionOfflineTests
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tests offline compact should rebuild hash index metadata and preserve results.
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void OfflineCompact_ShouldRebuildHashIndexMetadataAndPreserveResults()
|
||||
{
|
||||
var dbPath = NewDbPath();
|
||||
|
||||
try
|
||||
{
|
||||
using var db = new TestDbContext(dbPath);
|
||||
|
||||
for (var i = 0; i < 300; i++)
|
||||
{
|
||||
db.People.Insert(new Person
|
||||
{
|
||||
Name = $"hash-person-{i:D4}",
|
||||
Age = i % 12
|
||||
});
|
||||
}
|
||||
|
||||
db.SaveChanges();
|
||||
db.ForceCheckpoint();
|
||||
|
||||
var expectedByAge = db.People.FindAll()
|
||||
.GroupBy(p => p.Age)
|
||||
.ToDictionary(g => g.Key, g => g.Select(x => x.Name).OrderBy(x => x).ToArray());
|
||||
|
||||
var metadata = db.Storage.GetCollectionMetadata("people_collection");
|
||||
metadata.ShouldNotBeNull();
|
||||
|
||||
var targetIndex = metadata!.Indexes
|
||||
.FirstOrDefault(index => index.PropertyPaths.Any(path => path.Equals("Age", StringComparison.OrdinalIgnoreCase)));
|
||||
targetIndex.ShouldNotBeNull();
|
||||
|
||||
targetIndex!.Type = IndexType.Hash;
|
||||
db.Storage.SaveCollectionMetadata(metadata);
|
||||
db.SaveChanges();
|
||||
|
||||
var stats = db.Compact(new CompactionOptions
|
||||
{
|
||||
DefragmentSlottedPages = true,
|
||||
NormalizeFreeList = true,
|
||||
EnableTailTruncation = true
|
||||
});
|
||||
stats.PrePageCount.ShouldBeGreaterThanOrEqualTo(stats.PostPageCount);
|
||||
|
||||
var reloadedMetadata = db.Storage.GetCollectionMetadata("people_collection");
|
||||
reloadedMetadata.ShouldNotBeNull();
|
||||
var rebuiltIndex = reloadedMetadata!.Indexes.FirstOrDefault(index => index.Name == targetIndex.Name);
|
||||
rebuiltIndex.ShouldNotBeNull();
|
||||
rebuiltIndex!.Type.ShouldBe(IndexType.Hash);
|
||||
rebuiltIndex.RootPageId.ShouldBeGreaterThan(0u);
|
||||
|
||||
var runtimeIndex = db.People.GetIndexes().FirstOrDefault(index => index.Name == targetIndex.Name);
|
||||
runtimeIndex.ShouldNotBeNull();
|
||||
runtimeIndex!.Type.ShouldBe(IndexType.Hash);
|
||||
|
||||
foreach (var age in expectedByAge.Keys.OrderBy(x => x))
|
||||
{
|
||||
var actual = db.People.FindAll(p => p.Age == age)
|
||||
.Select(x => x.Name)
|
||||
.OrderBy(x => x)
|
||||
.ToArray();
|
||||
|
||||
actual.ShouldBe(expectedByAge[age]);
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
CleanupFiles(dbPath);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tests offline compact when tail is reclaimable should reduce file size.
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void OfflineCompact_WhenTailIsReclaimable_ShouldReduceFileSize()
|
||||
{
|
||||
@@ -178,6 +261,9 @@ public class CompactionOfflineTests
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tests offline compact with invalid primary root metadata should fail validation.
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void OfflineCompact_WithInvalidPrimaryRootMetadata_ShouldFailValidation()
|
||||
{
|
||||
@@ -208,6 +294,9 @@ public class CompactionOfflineTests
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tests offline compact with invalid secondary root metadata should fail validation.
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void OfflineCompact_WithInvalidSecondaryRootMetadata_ShouldFailValidation()
|
||||
{
|
||||
@@ -239,6 +328,9 @@ public class CompactionOfflineTests
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tests offline compact should report live bytes relocation and throughput telemetry.
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void OfflineCompact_ShouldReportLiveBytesRelocationAndThroughputTelemetry()
|
||||
{
|
||||
@@ -290,6 +382,9 @@ public class CompactionOfflineTests
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tests offline compact when primary index points to deleted slot should fail validation.
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void OfflineCompact_WhenPrimaryIndexPointsToDeletedSlot_ShouldFailValidation()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user