Reformat / cleanup
This commit is contained in:
@@ -7,7 +7,7 @@ namespace ZB.MOM.WW.CBDD.Tests;
|
||||
public class CompactionCrashRecoveryTests
|
||||
{
|
||||
/// <summary>
|
||||
/// Verifies compaction resumes from marker phases and preserves data.
|
||||
/// Verifies compaction resumes from marker phases and preserves data.
|
||||
/// </summary>
|
||||
/// <param name="phase">The crash marker phase to resume from.</param>
|
||||
[Theory]
|
||||
@@ -16,8 +16,8 @@ public class CompactionCrashRecoveryTests
|
||||
[InlineData("Swapped")]
|
||||
public void ResumeCompaction_FromCrashMarkerPhases_ShouldFinalizeAndPreserveData(string phase)
|
||||
{
|
||||
var dbPath = NewDbPath();
|
||||
var markerPath = MarkerPath(dbPath);
|
||||
string dbPath = NewDbPath();
|
||||
string markerPath = MarkerPath(dbPath);
|
||||
|
||||
try
|
||||
{
|
||||
@@ -54,13 +54,13 @@ public class CompactionCrashRecoveryTests
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verifies corrupted compaction markers are recovered deterministically.
|
||||
/// Verifies corrupted compaction markers are recovered deterministically.
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void ResumeCompaction_WithCorruptedMarker_ShouldRecoverDeterministically()
|
||||
{
|
||||
var dbPath = NewDbPath();
|
||||
var markerPath = MarkerPath(dbPath);
|
||||
string dbPath = NewDbPath();
|
||||
string markerPath = MarkerPath(dbPath);
|
||||
|
||||
try
|
||||
{
|
||||
@@ -96,13 +96,11 @@ public class CompactionCrashRecoveryTests
|
||||
{
|
||||
var ids = new List<ObjectId>();
|
||||
for (var i = 0; i < 120; i++)
|
||||
{
|
||||
ids.Add(db.Users.Insert(new User
|
||||
{
|
||||
Name = $"user-{i:D4}-payload-{new string('x', 120)}",
|
||||
Age = i % 20
|
||||
}));
|
||||
}
|
||||
|
||||
db.SaveChanges();
|
||||
return ids;
|
||||
@@ -110,25 +108,30 @@ public class CompactionCrashRecoveryTests
|
||||
|
||||
private static void WriteMarker(string markerPath, string dbPath, string phase)
|
||||
{
|
||||
var safeDbPath = dbPath.Replace("\\", "\\\\", StringComparison.Ordinal);
|
||||
string safeDbPath = dbPath.Replace("\\", "\\\\", StringComparison.Ordinal);
|
||||
var now = DateTimeOffset.UtcNow.ToString("O");
|
||||
var json = $$"""
|
||||
{"version":1,"phase":"{{phase}}","databasePath":"{{safeDbPath}}","startedAtUtc":"{{now}}","lastUpdatedUtc":"{{now}}","onlineMode":false,"mode":"InPlace"}
|
||||
""";
|
||||
{"version":1,"phase":"{{phase}}","databasePath":"{{safeDbPath}}","startedAtUtc":"{{now}}","lastUpdatedUtc":"{{now}}","onlineMode":false,"mode":"InPlace"}
|
||||
""";
|
||||
File.WriteAllText(markerPath, json);
|
||||
}
|
||||
|
||||
private static string MarkerPath(string dbPath) => $"{dbPath}.compact.state";
|
||||
private static string MarkerPath(string dbPath)
|
||||
{
|
||||
return $"{dbPath}.compact.state";
|
||||
}
|
||||
|
||||
private static string NewDbPath()
|
||||
=> Path.Combine(Path.GetTempPath(), $"compaction_crash_{Guid.NewGuid():N}.db");
|
||||
{
|
||||
return Path.Combine(Path.GetTempPath(), $"compaction_crash_{Guid.NewGuid():N}.db");
|
||||
}
|
||||
|
||||
private static void CleanupFiles(string dbPath)
|
||||
{
|
||||
var walPath = Path.ChangeExtension(dbPath, ".wal");
|
||||
var markerPath = MarkerPath(dbPath);
|
||||
string walPath = Path.ChangeExtension(dbPath, ".wal");
|
||||
string markerPath = MarkerPath(dbPath);
|
||||
if (File.Exists(dbPath)) File.Delete(dbPath);
|
||||
if (File.Exists(walPath)) File.Delete(walPath);
|
||||
if (File.Exists(markerPath)) File.Delete(markerPath);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user