Reformat / cleanup
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
using System.IO.Compression;
|
||||
using System.Text;
|
||||
using ZB.MOM.WW.CBDD.Bson;
|
||||
using ZB.MOM.WW.CBDD.Core.Compression;
|
||||
using ZB.MOM.WW.CBDD.Core.Storage;
|
||||
using ZB.MOM.WW.CBDD.Shared;
|
||||
@@ -8,12 +10,12 @@ namespace ZB.MOM.WW.CBDD.Tests;
|
||||
public class MaintenanceDiagnosticsAndMigrationTests
|
||||
{
|
||||
/// <summary>
|
||||
/// Verifies diagnostics APIs return page usage, compression, and fragmentation data.
|
||||
/// Verifies diagnostics APIs return page usage, compression, and fragmentation data.
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void DiagnosticsApis_ShouldReturnPageUsageCompressionAndFragmentationData()
|
||||
{
|
||||
var dbPath = NewDbPath();
|
||||
string dbPath = NewDbPath();
|
||||
|
||||
try
|
||||
{
|
||||
@@ -28,13 +30,11 @@ public class MaintenanceDiagnosticsAndMigrationTests
|
||||
|
||||
using var db = new TestDbContext(dbPath, options);
|
||||
for (var i = 0; i < 40; i++)
|
||||
{
|
||||
db.Users.Insert(new User
|
||||
{
|
||||
Name = BuildPayload(i, 9000),
|
||||
Age = i
|
||||
});
|
||||
}
|
||||
|
||||
db.SaveChanges();
|
||||
db.ForceCheckpoint();
|
||||
@@ -47,7 +47,8 @@ public class MaintenanceDiagnosticsAndMigrationTests
|
||||
byCollection.Any(x => x.CollectionName.Equals("users", StringComparison.OrdinalIgnoreCase)).ShouldBeTrue();
|
||||
|
||||
var compressionByCollection = db.GetCompressionRatioByCollection();
|
||||
var usersCompression = compressionByCollection.First(x => x.CollectionName.Equals("users", StringComparison.OrdinalIgnoreCase));
|
||||
var usersCompression = compressionByCollection.First(x =>
|
||||
x.CollectionName.Equals("users", StringComparison.OrdinalIgnoreCase));
|
||||
usersCompression.DocumentCount.ShouldBeGreaterThan(0);
|
||||
usersCompression.BytesBeforeCompression.ShouldBeGreaterThan(0);
|
||||
usersCompression.BytesAfterCompression.ShouldBeGreaterThan(0);
|
||||
@@ -65,26 +66,24 @@ public class MaintenanceDiagnosticsAndMigrationTests
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verifies compression migration dry-run and apply modes return deterministic stats and preserve data.
|
||||
/// Verifies compression migration dry-run and apply modes return deterministic stats and preserve data.
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void MigrateCompression_DryRunAndApply_ShouldReturnDeterministicStatsAndPreserveData()
|
||||
{
|
||||
var dbPath = NewDbPath();
|
||||
string dbPath = NewDbPath();
|
||||
|
||||
try
|
||||
{
|
||||
using var db = new TestDbContext(dbPath, CompressionOptions.Default);
|
||||
var ids = new List<ZB.MOM.WW.CBDD.Bson.ObjectId>();
|
||||
var ids = new List<ObjectId>();
|
||||
|
||||
for (var i = 0; i < 60; i++)
|
||||
{
|
||||
ids.Add(db.Users.Insert(new User
|
||||
{
|
||||
Name = BuildPayload(i, 12000),
|
||||
Age = i % 17
|
||||
}));
|
||||
}
|
||||
|
||||
db.SaveChanges();
|
||||
db.ForceCheckpoint();
|
||||
@@ -132,7 +131,7 @@ public class MaintenanceDiagnosticsAndMigrationTests
|
||||
|
||||
private static string BuildPayload(int seed, int approxLength)
|
||||
{
|
||||
var builder = new System.Text.StringBuilder(approxLength + 128);
|
||||
var builder = new StringBuilder(approxLength + 128);
|
||||
var i = 0;
|
||||
while (builder.Length < approxLength)
|
||||
{
|
||||
@@ -148,11 +147,13 @@ public class MaintenanceDiagnosticsAndMigrationTests
|
||||
}
|
||||
|
||||
private static string NewDbPath()
|
||||
=> Path.Combine(Path.GetTempPath(), $"maint_diag_migrate_{Guid.NewGuid():N}.db");
|
||||
{
|
||||
return Path.Combine(Path.GetTempPath(), $"maint_diag_migrate_{Guid.NewGuid():N}.db");
|
||||
}
|
||||
|
||||
private static void CleanupFiles(string dbPath)
|
||||
{
|
||||
var walPath = Path.ChangeExtension(dbPath, ".wal");
|
||||
string walPath = Path.ChangeExtension(dbPath, ".wal");
|
||||
var markerPath = $"{dbPath}.compact.state";
|
||||
var tempPath = $"{dbPath}.compact.tmp";
|
||||
var backupPath = $"{dbPath}.compact.bak";
|
||||
@@ -163,4 +164,4 @@ public class MaintenanceDiagnosticsAndMigrationTests
|
||||
if (File.Exists(tempPath)) File.Delete(tempPath);
|
||||
if (File.Exists(backupPath)) File.Delete(backupPath);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user