Reformat/cleanup
All checks were successful
NuGet Package Publish / nuget (push) Successful in 1m10s
All checks were successful
NuGet Package Publish / nuget (push) Successful in 1m10s
This commit is contained in:
@@ -1,30 +1,28 @@
|
||||
using System.Text.Json;
|
||||
using Microsoft.Extensions.Logging.Abstractions;
|
||||
using ZB.MOM.WW.CBDDC.Core;
|
||||
using ZB.MOM.WW.CBDDC.Core.Network;
|
||||
using ZB.MOM.WW.CBDDC.Core.Storage;
|
||||
using ZB.MOM.WW.CBDDC.Core.Sync;
|
||||
using ZB.MOM.WW.CBDDC.Persistence.BLite;
|
||||
using Microsoft.Extensions.Logging.Abstractions;
|
||||
using System.Text.Json;
|
||||
using Xunit;
|
||||
using ZB.MOM.WW.CBDDC.Persistence;
|
||||
using ZB.MOM.WW.CBDDC.Persistence.BLite;
|
||||
|
||||
namespace ZB.MOM.WW.CBDDC.Sample.Console.Tests;
|
||||
|
||||
/// <summary>
|
||||
/// Tests for BLite persistence stores: Export, Import, Merge, Drop operations.
|
||||
/// Tests for BLite persistence stores: Export, Import, Merge, Drop operations.
|
||||
/// </summary>
|
||||
public class BLiteStoreExportImportTests : IDisposable
|
||||
{
|
||||
private readonly string _testDbPath;
|
||||
private readonly IPeerNodeConfigurationProvider _configProvider;
|
||||
private readonly SampleDbContext _context;
|
||||
private readonly SampleDocumentStore _documentStore;
|
||||
private readonly BLiteOplogStore<SampleDbContext> _oplogStore;
|
||||
private readonly BLitePeerConfigurationStore<SampleDbContext> _peerConfigStore;
|
||||
private readonly BLiteSnapshotMetadataStore<SampleDbContext> _snapshotMetadataStore;
|
||||
private readonly IPeerNodeConfigurationProvider _configProvider;
|
||||
private readonly string _testDbPath;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="BLiteStoreExportImportTests"/> class.
|
||||
/// Initializes a new instance of the <see cref="BLiteStoreExportImportTests" /> class.
|
||||
/// </summary>
|
||||
public BLiteStoreExportImportTests()
|
||||
{
|
||||
@@ -33,7 +31,8 @@ public class BLiteStoreExportImportTests : IDisposable
|
||||
_configProvider = CreateConfigProvider("test-node");
|
||||
var vectorClock = new VectorClockService();
|
||||
|
||||
_documentStore = new SampleDocumentStore(_context, _configProvider, vectorClock, NullLogger<SampleDocumentStore>.Instance);
|
||||
_documentStore = new SampleDocumentStore(_context, _configProvider, vectorClock,
|
||||
NullLogger<SampleDocumentStore>.Instance);
|
||||
_snapshotMetadataStore = new BLiteSnapshotMetadataStore<SampleDbContext>(
|
||||
_context, NullLogger<BLiteSnapshotMetadataStore<SampleDbContext>>.Instance);
|
||||
_oplogStore = new BLiteOplogStore<SampleDbContext>(
|
||||
@@ -45,10 +44,42 @@ public class BLiteStoreExportImportTests : IDisposable
|
||||
_context, NullLogger<BLitePeerConfigurationStore<SampleDbContext>>.Instance);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Disposes test resources and removes the temporary database file.
|
||||
/// </summary>
|
||||
public void Dispose()
|
||||
{
|
||||
_documentStore?.Dispose();
|
||||
_context?.Dispose();
|
||||
|
||||
if (File.Exists(_testDbPath))
|
||||
try
|
||||
{
|
||||
File.Delete(_testDbPath);
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
private static IPeerNodeConfigurationProvider CreateConfigProvider(string nodeId)
|
||||
{
|
||||
var configProvider = Substitute.For<IPeerNodeConfigurationProvider>();
|
||||
configProvider.GetConfiguration().Returns(new PeerNodeConfiguration
|
||||
{
|
||||
NodeId = nodeId,
|
||||
TcpPort = 5000,
|
||||
AuthToken = "test-token",
|
||||
OplogRetentionHours = 24,
|
||||
MaintenanceIntervalMinutes = 60
|
||||
});
|
||||
return configProvider;
|
||||
}
|
||||
|
||||
#region OplogStore Tests
|
||||
|
||||
/// <summary>
|
||||
/// Verifies that exporting oplog entries returns all persisted records.
|
||||
/// Verifies that exporting oplog entries returns all persisted records.
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async Task OplogStore_ExportAsync_ReturnsAllEntries()
|
||||
@@ -69,7 +100,7 @@ public class BLiteStoreExportImportTests : IDisposable
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verifies that importing oplog entries adds them to the store.
|
||||
/// Verifies that importing oplog entries adds them to the store.
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async Task OplogStore_ImportAsync_AddsEntries()
|
||||
@@ -92,7 +123,7 @@ public class BLiteStoreExportImportTests : IDisposable
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verifies that merging oplog entries adds only entries that are not already present.
|
||||
/// Verifies that merging oplog entries adds only entries that are not already present.
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async Task OplogStore_MergeAsync_OnlyAddsNewEntries()
|
||||
@@ -117,7 +148,7 @@ public class BLiteStoreExportImportTests : IDisposable
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verifies that chain range lookup resolves entries by hash and returns the expected range.
|
||||
/// Verifies that chain range lookup resolves entries by hash and returns the expected range.
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async Task OplogStore_GetChainRangeAsync_UsesHashLookup()
|
||||
@@ -126,7 +157,8 @@ public class BLiteStoreExportImportTests : IDisposable
|
||||
var payload1 = JsonDocument.Parse("{\"test\":\"k1\"}").RootElement;
|
||||
var payload2 = JsonDocument.Parse("{\"test\":\"k2\"}").RootElement;
|
||||
var entry1 = new OplogEntry("col1", "k1", OperationType.Put, payload1, new HlcTimestamp(1000, 0, "node1"), "");
|
||||
var entry2 = new OplogEntry("col1", "k2", OperationType.Put, payload2, new HlcTimestamp(2000, 0, "node1"), entry1.Hash);
|
||||
var entry2 = new OplogEntry("col1", "k2", OperationType.Put, payload2, new HlcTimestamp(2000, 0, "node1"),
|
||||
entry1.Hash);
|
||||
|
||||
await _oplogStore.AppendOplogEntryAsync(entry1);
|
||||
await _oplogStore.AppendOplogEntryAsync(entry2);
|
||||
@@ -141,7 +173,7 @@ public class BLiteStoreExportImportTests : IDisposable
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verifies that dropping the oplog store removes all entries.
|
||||
/// Verifies that dropping the oplog store removes all entries.
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async Task OplogStore_DropAsync_ClearsAllEntries()
|
||||
@@ -164,7 +196,7 @@ public class BLiteStoreExportImportTests : IDisposable
|
||||
#region PeerConfigurationStore Tests
|
||||
|
||||
/// <summary>
|
||||
/// Verifies that exporting peer configurations returns all persisted peers.
|
||||
/// Verifies that exporting peer configurations returns all persisted peers.
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async Task PeerConfigStore_ExportAsync_ReturnsAllPeers()
|
||||
@@ -183,7 +215,7 @@ public class BLiteStoreExportImportTests : IDisposable
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verifies that importing peer configurations adds peers to the store.
|
||||
/// Verifies that importing peer configurations adds peers to the store.
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async Task PeerConfigStore_ImportAsync_AddsPeers()
|
||||
@@ -204,7 +236,7 @@ public class BLiteStoreExportImportTests : IDisposable
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verifies that merging peer configurations adds only new peers.
|
||||
/// Verifies that merging peer configurations adds only new peers.
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async Task PeerConfigStore_MergeAsync_OnlyAddsNewPeers()
|
||||
@@ -229,7 +261,7 @@ public class BLiteStoreExportImportTests : IDisposable
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verifies that dropping peer configurations removes all peers.
|
||||
/// Verifies that dropping peer configurations removes all peers.
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async Task PeerConfigStore_DropAsync_ClearsAllPeers()
|
||||
@@ -252,7 +284,7 @@ public class BLiteStoreExportImportTests : IDisposable
|
||||
#region SnapshotMetadataStore Tests
|
||||
|
||||
/// <summary>
|
||||
/// Verifies that exporting snapshot metadata returns all persisted metadata entries.
|
||||
/// Verifies that exporting snapshot metadata returns all persisted metadata entries.
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async Task SnapshotMetadataStore_ExportAsync_ReturnsAllMetadata()
|
||||
@@ -273,7 +305,7 @@ public class BLiteStoreExportImportTests : IDisposable
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verifies that importing snapshot metadata adds metadata entries to the store.
|
||||
/// Verifies that importing snapshot metadata adds metadata entries to the store.
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async Task SnapshotMetadataStore_ImportAsync_AddsMetadata()
|
||||
@@ -294,7 +326,7 @@ public class BLiteStoreExportImportTests : IDisposable
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verifies that merging snapshot metadata adds only entries with new node identifiers.
|
||||
/// Verifies that merging snapshot metadata adds only entries with new node identifiers.
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async Task SnapshotMetadataStore_MergeAsync_OnlyAddsNewMetadata()
|
||||
@@ -318,7 +350,7 @@ public class BLiteStoreExportImportTests : IDisposable
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verifies that dropping snapshot metadata removes all metadata entries.
|
||||
/// Verifies that dropping snapshot metadata removes all metadata entries.
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async Task SnapshotMetadataStore_DropAsync_ClearsAllMetadata()
|
||||
@@ -340,7 +372,7 @@ public class BLiteStoreExportImportTests : IDisposable
|
||||
#region DocumentStore Tests
|
||||
|
||||
/// <summary>
|
||||
/// Verifies that exporting documents returns all persisted documents.
|
||||
/// Verifies that exporting documents returns all persisted documents.
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async Task DocumentStore_ExportAsync_ReturnsAllDocuments()
|
||||
@@ -360,7 +392,7 @@ public class BLiteStoreExportImportTests : IDisposable
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verifies that importing documents adds them to the underlying store.
|
||||
/// Verifies that importing documents adds them to the underlying store.
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async Task DocumentStore_ImportAsync_AddsDocuments()
|
||||
@@ -385,7 +417,7 @@ public class BLiteStoreExportImportTests : IDisposable
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verifies that document merge behavior honors conflict resolution.
|
||||
/// Verifies that document merge behavior honors conflict resolution.
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async Task DocumentStore_MergeAsync_UsesConflictResolution()
|
||||
@@ -414,7 +446,7 @@ public class BLiteStoreExportImportTests : IDisposable
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verifies that dropping documents removes all persisted documents.
|
||||
/// Verifies that dropping documents removes all persisted documents.
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async Task DocumentStore_DropAsync_ClearsAllDocuments()
|
||||
@@ -468,38 +500,10 @@ public class BLiteStoreExportImportTests : IDisposable
|
||||
|
||||
private static Document CreateDocument<T>(string collection, string key, T entity) where T : class
|
||||
{
|
||||
var json = JsonSerializer.Serialize(entity);
|
||||
string json = JsonSerializer.Serialize(entity);
|
||||
var content = JsonDocument.Parse(json).RootElement;
|
||||
return new Document(collection, key, content, new HlcTimestamp(0, 0, ""), false);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// Disposes test resources and removes the temporary database file.
|
||||
/// </summary>
|
||||
public void Dispose()
|
||||
{
|
||||
_documentStore?.Dispose();
|
||||
_context?.Dispose();
|
||||
|
||||
if (File.Exists(_testDbPath))
|
||||
{
|
||||
try { File.Delete(_testDbPath); } catch { }
|
||||
}
|
||||
}
|
||||
|
||||
private static IPeerNodeConfigurationProvider CreateConfigProvider(string nodeId)
|
||||
{
|
||||
var configProvider = Substitute.For<IPeerNodeConfigurationProvider>();
|
||||
configProvider.GetConfiguration().Returns(new PeerNodeConfiguration
|
||||
{
|
||||
NodeId = nodeId,
|
||||
TcpPort = 5000,
|
||||
AuthToken = "test-token",
|
||||
OplogRetentionHours = 24,
|
||||
MaintenanceIntervalMinutes = 60
|
||||
});
|
||||
return configProvider;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user