Replace BLite with Surreal embedded persistence
All checks were successful
NuGet Package Publish / nuget (push) Successful in 1m21s
All checks were successful
NuGet Package Publish / nuget (push) Successful in 1m21s
This commit is contained in:
@@ -2,21 +2,21 @@ using System.Text.Json;
|
||||
using System.Text.Json.Nodes;
|
||||
using Microsoft.Extensions.Logging.Abstractions;
|
||||
using ZB.MOM.WW.CBDDC.Core;
|
||||
using ZB.MOM.WW.CBDDC.Core.Network;
|
||||
using ZB.MOM.WW.CBDDC.Core.Sync;
|
||||
using ZB.MOM.WW.CBDDC.Persistence;
|
||||
using ZB.MOM.WW.CBDDC.Persistence.BLite;
|
||||
using ZB.MOM.WW.CBDDC.Core.Network;
|
||||
using ZB.MOM.WW.CBDDC.Core.Sync;
|
||||
using ZB.MOM.WW.CBDDC.Persistence;
|
||||
using ZB.MOM.WW.CBDDC.Persistence.Surreal;
|
||||
|
||||
namespace ZB.MOM.WW.CBDDC.Sample.Console.Tests;
|
||||
|
||||
public class SnapshotStoreTests : IDisposable
|
||||
{
|
||||
private readonly IPeerNodeConfigurationProvider _configProvider;
|
||||
private readonly SampleDbContext _context;
|
||||
private readonly SampleDocumentStore _documentStore;
|
||||
private readonly BLiteOplogStore<SampleDbContext> _oplogStore;
|
||||
private readonly BLitePeerConfigurationStore<SampleDbContext> _peerConfigStore;
|
||||
private readonly BLitePeerOplogConfirmationStore<SampleDbContext> _peerConfirmationStore;
|
||||
private readonly IPeerNodeConfigurationProvider _configProvider;
|
||||
private readonly SampleDbContext _context;
|
||||
private readonly SampleDocumentStore _documentStore;
|
||||
private readonly SurrealOplogStore _oplogStore;
|
||||
private readonly SurrealPeerConfigurationStore _peerConfigStore;
|
||||
private readonly SurrealPeerOplogConfirmationStore _peerConfirmationStore;
|
||||
private readonly SnapshotStore _snapshotStore;
|
||||
private readonly string _testDbPath;
|
||||
|
||||
@@ -25,29 +25,33 @@ public class SnapshotStoreTests : IDisposable
|
||||
/// </summary>
|
||||
public SnapshotStoreTests()
|
||||
{
|
||||
_testDbPath = Path.Combine(Path.GetTempPath(), $"test-snapshot-{Guid.NewGuid()}.blite");
|
||||
_context = new SampleDbContext(_testDbPath);
|
||||
_configProvider = CreateConfigProvider("test-node");
|
||||
var vectorClock = new VectorClockService();
|
||||
|
||||
_documentStore = new SampleDocumentStore(_context, _configProvider, vectorClock,
|
||||
NullLogger<SampleDocumentStore>.Instance);
|
||||
var snapshotMetadataStore = new BLiteSnapshotMetadataStore<SampleDbContext>(
|
||||
_context,
|
||||
NullLogger<BLiteSnapshotMetadataStore<SampleDbContext>>.Instance);
|
||||
_oplogStore = new BLiteOplogStore<SampleDbContext>(
|
||||
_context,
|
||||
_documentStore,
|
||||
new LastWriteWinsConflictResolver(),
|
||||
vectorClock,
|
||||
snapshotMetadataStore,
|
||||
NullLogger<BLiteOplogStore<SampleDbContext>>.Instance);
|
||||
_peerConfigStore = new BLitePeerConfigurationStore<SampleDbContext>(
|
||||
_context,
|
||||
NullLogger<BLitePeerConfigurationStore<SampleDbContext>>.Instance);
|
||||
_peerConfirmationStore = new BLitePeerOplogConfirmationStore<SampleDbContext>(
|
||||
_context,
|
||||
NullLogger<BLitePeerOplogConfirmationStore<SampleDbContext>>.Instance);
|
||||
_testDbPath = Path.Combine(Path.GetTempPath(), $"test-snapshot-{Guid.NewGuid()}.rocksdb");
|
||||
_context = new SampleDbContext(_testDbPath);
|
||||
_configProvider = CreateConfigProvider("test-node");
|
||||
var vectorClock = new VectorClockService();
|
||||
|
||||
_documentStore = new SampleDocumentStore(_context, _configProvider, vectorClock,
|
||||
logger: NullLogger<SampleDocumentStore>.Instance);
|
||||
var snapshotMetadataStore = new SurrealSnapshotMetadataStore(
|
||||
_context.SurrealEmbeddedClient,
|
||||
_context.SchemaInitializer,
|
||||
NullLogger<SurrealSnapshotMetadataStore>.Instance);
|
||||
_oplogStore = new SurrealOplogStore(
|
||||
_context.SurrealEmbeddedClient,
|
||||
_context.SchemaInitializer,
|
||||
_documentStore,
|
||||
new LastWriteWinsConflictResolver(),
|
||||
vectorClock,
|
||||
snapshotMetadataStore,
|
||||
NullLogger<SurrealOplogStore>.Instance);
|
||||
_peerConfigStore = new SurrealPeerConfigurationStore(
|
||||
_context.SurrealEmbeddedClient,
|
||||
_context.SchemaInitializer,
|
||||
NullLogger<SurrealPeerConfigurationStore>.Instance);
|
||||
_peerConfirmationStore = new SurrealPeerOplogConfirmationStore(
|
||||
_context.SurrealEmbeddedClient,
|
||||
_context.SchemaInitializer,
|
||||
NullLogger<SurrealPeerOplogConfirmationStore>.Instance);
|
||||
|
||||
_snapshotStore = new SnapshotStore(
|
||||
_documentStore,
|
||||
@@ -66,13 +70,13 @@ public class SnapshotStoreTests : IDisposable
|
||||
_documentStore?.Dispose();
|
||||
_context?.Dispose();
|
||||
|
||||
if (File.Exists(_testDbPath))
|
||||
try
|
||||
{
|
||||
File.Delete(_testDbPath);
|
||||
}
|
||||
catch
|
||||
{
|
||||
if (Directory.Exists(_testDbPath))
|
||||
try
|
||||
{
|
||||
Directory.Delete(_testDbPath, true);
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
@@ -170,26 +174,34 @@ public class SnapshotStoreTests : IDisposable
|
||||
snapshotStream.Position = 0;
|
||||
|
||||
// Create a new context/stores (simulating a different node)
|
||||
string newDbPath = Path.Combine(Path.GetTempPath(), $"test-snapshot-target-{Guid.NewGuid()}.blite");
|
||||
string newDbPath = Path.Combine(Path.GetTempPath(), $"test-snapshot-target-{Guid.NewGuid()}.rocksdb");
|
||||
try
|
||||
{
|
||||
using var newContext = new SampleDbContext(newDbPath);
|
||||
var newConfigProvider = CreateConfigProvider("test-new-node");
|
||||
var newVectorClock = new VectorClockService();
|
||||
var newDocStore = new SampleDocumentStore(newContext, newConfigProvider, newVectorClock,
|
||||
NullLogger<SampleDocumentStore>.Instance);
|
||||
var newSnapshotMetaStore = new BLiteSnapshotMetadataStore<SampleDbContext>(
|
||||
newContext, NullLogger<BLiteSnapshotMetadataStore<SampleDbContext>>.Instance);
|
||||
var newOplogStore = new BLiteOplogStore<SampleDbContext>(
|
||||
newContext, newDocStore, new LastWriteWinsConflictResolver(),
|
||||
newVectorClock,
|
||||
newSnapshotMetaStore,
|
||||
NullLogger<BLiteOplogStore<SampleDbContext>>.Instance);
|
||||
var newPeerStore = new BLitePeerConfigurationStore<SampleDbContext>(
|
||||
newContext, NullLogger<BLitePeerConfigurationStore<SampleDbContext>>.Instance);
|
||||
var newPeerConfirmationStore = new BLitePeerOplogConfirmationStore<SampleDbContext>(
|
||||
newContext,
|
||||
NullLogger<BLitePeerOplogConfirmationStore<SampleDbContext>>.Instance);
|
||||
var newConfigProvider = CreateConfigProvider("test-new-node");
|
||||
var newVectorClock = new VectorClockService();
|
||||
var newDocStore = new SampleDocumentStore(newContext, newConfigProvider, newVectorClock,
|
||||
logger: NullLogger<SampleDocumentStore>.Instance);
|
||||
var newSnapshotMetaStore = new SurrealSnapshotMetadataStore(
|
||||
newContext.SurrealEmbeddedClient,
|
||||
newContext.SchemaInitializer,
|
||||
NullLogger<SurrealSnapshotMetadataStore>.Instance);
|
||||
var newOplogStore = new SurrealOplogStore(
|
||||
newContext.SurrealEmbeddedClient,
|
||||
newContext.SchemaInitializer,
|
||||
newDocStore,
|
||||
new LastWriteWinsConflictResolver(),
|
||||
newVectorClock,
|
||||
newSnapshotMetaStore,
|
||||
NullLogger<SurrealOplogStore>.Instance);
|
||||
var newPeerStore = new SurrealPeerConfigurationStore(
|
||||
newContext.SurrealEmbeddedClient,
|
||||
newContext.SchemaInitializer,
|
||||
NullLogger<SurrealPeerConfigurationStore>.Instance);
|
||||
var newPeerConfirmationStore = new SurrealPeerOplogConfirmationStore(
|
||||
newContext.SurrealEmbeddedClient,
|
||||
newContext.SchemaInitializer,
|
||||
NullLogger<SurrealPeerOplogConfirmationStore>.Instance);
|
||||
|
||||
var newSnapshotStore = new SnapshotStore(
|
||||
newDocStore,
|
||||
@@ -218,14 +230,14 @@ public class SnapshotStoreTests : IDisposable
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (File.Exists(newDbPath))
|
||||
try
|
||||
{
|
||||
File.Delete(newDbPath);
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
if (Directory.Exists(newDbPath))
|
||||
try
|
||||
{
|
||||
Directory.Delete(newDbPath, true);
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -250,7 +262,7 @@ public class SnapshotStoreTests : IDisposable
|
||||
await _context.SaveChangesAsync();
|
||||
|
||||
// Create snapshot with different data
|
||||
string sourceDbPath = Path.Combine(Path.GetTempPath(), $"test-snapshot-source-{Guid.NewGuid()}.blite");
|
||||
string sourceDbPath = Path.Combine(Path.GetTempPath(), $"test-snapshot-source-{Guid.NewGuid()}.rocksdb");
|
||||
MemoryStream snapshotStream;
|
||||
|
||||
try
|
||||
@@ -259,22 +271,30 @@ public class SnapshotStoreTests : IDisposable
|
||||
await sourceContext.Users.InsertAsync(new User { Id = "new-user", Name = "New User", Age = 25 });
|
||||
await sourceContext.SaveChangesAsync();
|
||||
|
||||
var sourceConfigProvider = CreateConfigProvider("test-source-node");
|
||||
var sourceVectorClock = new VectorClockService();
|
||||
var sourceDocStore = new SampleDocumentStore(sourceContext, sourceConfigProvider, sourceVectorClock,
|
||||
NullLogger<SampleDocumentStore>.Instance);
|
||||
var sourceSnapshotMetaStore = new BLiteSnapshotMetadataStore<SampleDbContext>(
|
||||
sourceContext, NullLogger<BLiteSnapshotMetadataStore<SampleDbContext>>.Instance);
|
||||
var sourceOplogStore = new BLiteOplogStore<SampleDbContext>(
|
||||
sourceContext, sourceDocStore, new LastWriteWinsConflictResolver(),
|
||||
sourceVectorClock,
|
||||
sourceSnapshotMetaStore,
|
||||
NullLogger<BLiteOplogStore<SampleDbContext>>.Instance);
|
||||
var sourcePeerStore = new BLitePeerConfigurationStore<SampleDbContext>(
|
||||
sourceContext, NullLogger<BLitePeerConfigurationStore<SampleDbContext>>.Instance);
|
||||
var sourcePeerConfirmationStore = new BLitePeerOplogConfirmationStore<SampleDbContext>(
|
||||
sourceContext,
|
||||
NullLogger<BLitePeerOplogConfirmationStore<SampleDbContext>>.Instance);
|
||||
var sourceConfigProvider = CreateConfigProvider("test-source-node");
|
||||
var sourceVectorClock = new VectorClockService();
|
||||
var sourceDocStore = new SampleDocumentStore(sourceContext, sourceConfigProvider, sourceVectorClock,
|
||||
logger: NullLogger<SampleDocumentStore>.Instance);
|
||||
var sourceSnapshotMetaStore = new SurrealSnapshotMetadataStore(
|
||||
sourceContext.SurrealEmbeddedClient,
|
||||
sourceContext.SchemaInitializer,
|
||||
NullLogger<SurrealSnapshotMetadataStore>.Instance);
|
||||
var sourceOplogStore = new SurrealOplogStore(
|
||||
sourceContext.SurrealEmbeddedClient,
|
||||
sourceContext.SchemaInitializer,
|
||||
sourceDocStore,
|
||||
new LastWriteWinsConflictResolver(),
|
||||
sourceVectorClock,
|
||||
sourceSnapshotMetaStore,
|
||||
NullLogger<SurrealOplogStore>.Instance);
|
||||
var sourcePeerStore = new SurrealPeerConfigurationStore(
|
||||
sourceContext.SurrealEmbeddedClient,
|
||||
sourceContext.SchemaInitializer,
|
||||
NullLogger<SurrealPeerConfigurationStore>.Instance);
|
||||
var sourcePeerConfirmationStore = new SurrealPeerOplogConfirmationStore(
|
||||
sourceContext.SurrealEmbeddedClient,
|
||||
sourceContext.SchemaInitializer,
|
||||
NullLogger<SurrealPeerOplogConfirmationStore>.Instance);
|
||||
await sourcePeerConfirmationStore.UpdateConfirmationAsync(
|
||||
"peer-merge",
|
||||
"source-a",
|
||||
@@ -300,13 +320,13 @@ public class SnapshotStoreTests : IDisposable
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (File.Exists(sourceDbPath))
|
||||
try
|
||||
{
|
||||
File.Delete(sourceDbPath);
|
||||
}
|
||||
catch
|
||||
{
|
||||
if (Directory.Exists(sourceDbPath))
|
||||
try
|
||||
{
|
||||
Directory.Delete(sourceDbPath, true);
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
@@ -447,4 +467,4 @@ public class SnapshotStoreTests : IDisposable
|
||||
});
|
||||
return configProvider;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user