Introduce pluggable snapshot storage for persistence

This commit is contained in:
Jacob Dubin
2026-05-17 07:02:49 -05:00
parent 785dc2b48b
commit 888f472f69
5 changed files with 67 additions and 8 deletions

View File

@@ -5,6 +5,33 @@ namespace Jibo.Cloud.Tests.Infrastructure;
public sealed class PersistenceStoreTests
{
[Fact]
public void PersonalMemoryStore_CanUseAlternateSnapshotBackend()
{
var backend = new RecordingSnapshotStore();
var store = new InMemoryPersonalMemoryStore(backend);
var scope = new PersonalMemoryTenantScope("acct-b", "loop-b", "device-b", "person-b");
store.SetName(scope, "Alt Backend");
Assert.Single(backend.Saves);
Assert.Equal("Alt Backend", store.GetName(scope));
Assert.Equal("1", store.GetPersistenceStateInfo().SchemaVersion);
}
[Fact]
public void CloudStateStore_CanUseAlternateSnapshotBackend()
{
var backend = new RecordingSnapshotStore();
var store = new InMemoryCloudStateStore(backend);
store.CreateMedia("openjibo-default-loop", "backend-photo", "image", "photo-ref", false, null);
Assert.Single(backend.Saves);
Assert.Contains(store.ListMedia(), item => item.Path == "backend-photo");
Assert.Equal("1", store.GetPersistenceStateInfo().SchemaVersion);
}
[Fact]
public void PersonalMemoryStore_RoundTripsStateAndRevision()
{
@@ -84,4 +111,19 @@ public sealed class PersistenceStoreTests
}
}
}
private sealed class RecordingSnapshotStore : ISnapshotStore
{
public List<object> Saves { get; } = [];
public TSnapshot2? Load<TSnapshot2>() where TSnapshot2 : class
{
return default;
}
public void Save<TSnapshot2>(TSnapshot2 snapshot) where TSnapshot2 : class
{
Saves.Add(snapshot);
}
}
}