Reformat / cleanup
This commit is contained in:
@@ -1,33 +1,29 @@
|
||||
using ZB.MOM.WW.CBDD.Bson;
|
||||
using ZB.MOM.WW.CBDD.Core.Collections;
|
||||
using ZB.MOM.WW.CBDD.Core.Compression;
|
||||
using ZB.MOM.WW.CBDD.Core.Storage;
|
||||
using ZB.MOM.WW.CBDD.Core.Transactions;
|
||||
using ZB.MOM.WW.CBDD.Shared;
|
||||
using ZB.MOM.WW.CBDD.Shared.TestDbContext_TestDbContext_Mappers;
|
||||
using System.IO.Compression;
|
||||
using System.IO.MemoryMappedFiles;
|
||||
using Xunit;
|
||||
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;
|
||||
|
||||
namespace ZB.MOM.WW.CBDD.Tests;
|
||||
|
||||
public class DocumentOverflowTests : IDisposable
|
||||
{
|
||||
private readonly TestDbContext _db;
|
||||
private readonly string _dbPath;
|
||||
private readonly Shared.TestDbContext _db;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="DocumentOverflowTests"/> class.
|
||||
/// Initializes a new instance of the <see cref="DocumentOverflowTests" /> class.
|
||||
/// </summary>
|
||||
public DocumentOverflowTests()
|
||||
{
|
||||
_dbPath = Path.Combine(Path.GetTempPath(), $"test_overflow_{Guid.NewGuid()}.db");
|
||||
// Use default PageSize (16KB)
|
||||
_db = new Shared.TestDbContext(_dbPath);
|
||||
_db = new TestDbContext(_dbPath);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Releases test resources.
|
||||
/// Releases test resources.
|
||||
/// </summary>
|
||||
public void Dispose()
|
||||
{
|
||||
@@ -36,7 +32,7 @@ public class DocumentOverflowTests : IDisposable
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verifies inserting a medium-sized document succeeds.
|
||||
/// Verifies inserting a medium-sized document succeeds.
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void Insert_MediumDoc_64KB_ShouldSucceed()
|
||||
@@ -60,7 +56,7 @@ public class DocumentOverflowTests : IDisposable
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verifies inserting a large document succeeds.
|
||||
/// Verifies inserting a large document succeeds.
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void Insert_LargeDoc_100KB_ShouldSucceed()
|
||||
@@ -83,7 +79,7 @@ public class DocumentOverflowTests : IDisposable
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verifies inserting a very large document succeeds.
|
||||
/// Verifies inserting a very large document succeeds.
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void Insert_HugeDoc_3MB_ShouldSucceed()
|
||||
@@ -109,7 +105,7 @@ public class DocumentOverflowTests : IDisposable
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verifies updating from a small payload to a huge payload succeeds.
|
||||
/// Verifies updating from a small payload to a huge payload succeeds.
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void Update_SmallToHuge_ShouldSucceed()
|
||||
@@ -123,7 +119,7 @@ public class DocumentOverflowTests : IDisposable
|
||||
var hugeString = new string('U', 3 * 1024 * 1024);
|
||||
user.Name = hugeString;
|
||||
|
||||
var updated = _db.Users.Update(user);
|
||||
bool updated = _db.Users.Update(user);
|
||||
_db.SaveChanges();
|
||||
updated.ShouldBeTrue();
|
||||
|
||||
@@ -133,17 +129,17 @@ public class DocumentOverflowTests : IDisposable
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verifies bulk inserts with mixed payload sizes succeed.
|
||||
/// Verifies bulk inserts with mixed payload sizes succeed.
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void InsertBulk_MixedSizes_ShouldSucceed()
|
||||
{
|
||||
var users = new List<User>
|
||||
{
|
||||
new User { Id = ObjectId.NewObjectId(), Name = "Small 1", Age = 1 },
|
||||
new User { Id = ObjectId.NewObjectId(), Name = new string('M', 100 * 1024), Age = 2 }, // 100KB
|
||||
new User { Id = ObjectId.NewObjectId(), Name = "Small 2", Age = 3 },
|
||||
new User { Id = ObjectId.NewObjectId(), Name = new string('H', 3 * 1024 * 1024), Age = 4 } // 3MB
|
||||
new() { Id = ObjectId.NewObjectId(), Name = "Small 1", Age = 1 },
|
||||
new() { Id = ObjectId.NewObjectId(), Name = new string('M', 100 * 1024), Age = 2 }, // 100KB
|
||||
new() { Id = ObjectId.NewObjectId(), Name = "Small 2", Age = 3 },
|
||||
new() { Id = ObjectId.NewObjectId(), Name = new string('H', 3 * 1024 * 1024), Age = 4 } // 3MB
|
||||
};
|
||||
|
||||
var ids = _db.Users.InsertBulk(users);
|
||||
@@ -158,12 +154,12 @@ public class DocumentOverflowTests : IDisposable
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verifies huge inserts succeed with compression enabled and small page configuration.
|
||||
/// Verifies huge inserts succeed with compression enabled and small page configuration.
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void Insert_HugeDoc_WithCompressionEnabledAndSmallPages_ShouldSucceed()
|
||||
{
|
||||
var localDbPath = Path.Combine(Path.GetTempPath(), $"test_overflow_compression_{Guid.NewGuid():N}.db");
|
||||
string localDbPath = Path.Combine(Path.GetTempPath(), $"test_overflow_compression_{Guid.NewGuid():N}.db");
|
||||
var options = new CompressionOptions
|
||||
{
|
||||
EnableCompression = true,
|
||||
@@ -175,7 +171,7 @@ public class DocumentOverflowTests : IDisposable
|
||||
|
||||
try
|
||||
{
|
||||
using var db = new Shared.TestDbContext(localDbPath, TinyPageConfig(), options);
|
||||
using var db = new TestDbContext(localDbPath, TinyPageConfig(), options);
|
||||
var huge = new string('Z', 2 * 1024 * 1024);
|
||||
var id = db.Users.Insert(new User
|
||||
{
|
||||
@@ -197,12 +193,13 @@ public class DocumentOverflowTests : IDisposable
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verifies updates from huge to small payloads succeed with compression enabled.
|
||||
/// Verifies updates from huge to small payloads succeed with compression enabled.
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void Update_HugeToSmall_WithCompressionEnabled_ShouldSucceed()
|
||||
{
|
||||
var localDbPath = Path.Combine(Path.GetTempPath(), $"test_overflow_compression_update_{Guid.NewGuid():N}.db");
|
||||
string localDbPath =
|
||||
Path.Combine(Path.GetTempPath(), $"test_overflow_compression_update_{Guid.NewGuid():N}.db");
|
||||
var options = new CompressionOptions
|
||||
{
|
||||
EnableCompression = true,
|
||||
@@ -214,7 +211,7 @@ public class DocumentOverflowTests : IDisposable
|
||||
|
||||
try
|
||||
{
|
||||
using var db = new Shared.TestDbContext(localDbPath, TinyPageConfig(), options);
|
||||
using var db = new TestDbContext(localDbPath, TinyPageConfig(), options);
|
||||
var user = new User
|
||||
{
|
||||
Id = ObjectId.NewObjectId(),
|
||||
@@ -251,10 +248,10 @@ public class DocumentOverflowTests : IDisposable
|
||||
|
||||
private static void CleanupLocalFiles(string dbPath)
|
||||
{
|
||||
var walPath = Path.ChangeExtension(dbPath, ".wal");
|
||||
string walPath = Path.ChangeExtension(dbPath, ".wal");
|
||||
var markerPath = $"{dbPath}.compact.state";
|
||||
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