Skip to content

Commit

Permalink
Implement SnapshotStore SaveSnapshot spec (#400)
Browse files Browse the repository at this point in the history
  • Loading branch information
Arkatufus authored Sep 10, 2024
1 parent 1accb2f commit a12e877
Show file tree
Hide file tree
Showing 4 changed files with 138 additions and 4 deletions.
7 changes: 4 additions & 3 deletions Akka.Persistence.SqlServer.sln.DotSettings
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:String x:Key="/Default/CodeStyle/FileHeader/FileHeaderText/@EntryValue">-----------------------------------------------------------------------&#xD;
&lt;copyright file="$FILENAME$" company="Akka.NET Project"&gt;&#xD;
Copyright (C) 2013 - $CURRENT_YEAR$ .NET Foundation &lt;https://github.com/akkadotnet/akka.net&gt;&#xD;
&lt;copyright file="${File.FileName}" company="Akka.NET Project"&gt;&#xD;
Copyright (C) 2013 - ${CurrentDate.Year} .NET Foundation &lt;https://github.com/akkadotnet/akka.net&gt;&#xD;
&lt;/copyright&gt;&#xD;
-----------------------------------------------------------------------</s:String></wpf:ResourceDictionary>
-----------------------------------------------------------------------</s:String>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EFeature_002EServices_002ECodeCleanup_002EFileHeader_002EFileHeaderSettingsMigrate/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public SqlServerFixture()
}

protected string ImageName => "mcr.microsoft.com/mssql/server";
protected string Tag => "2019-latest";
protected string Tag => "2022-latest";

protected string SqlServerImageName => $"{ImageName}:{Tag}";

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// -----------------------------------------------------------------------
// <copyright file="SqlServerConnectionFailureSpec.cs" company="Akka.NET Project">
// Copyright (C) 2013 - 2024 .NET Foundation <https://github.com/akkadotnet/akka.net>
// </copyright>
// -----------------------------------------------------------------------

using Akka.Configuration;
using Akka.Persistence.Sql.TestKit;
using Xunit;
using Xunit.Abstractions;

namespace Akka.Persistence.SqlServer.Tests;

[Collection("SqlServerSpec")]
public class SqlServerConnectionFailureSpec: SqlJournalConnectionFailureSpec
{
public SqlServerConnectionFailureSpec(ITestOutputHelper output, SqlServerFixture fixture)
: base(InitConfig(fixture, DefaultInvalidConnectionString), output)
{

}

private static Config InitConfig(SqlServerFixture fixture, string connectionString)
{
//need to make sure db is created before the tests start
DbUtils.Initialize(fixture.ConnectionString);
var specString = $$"""
akka.persistence {
publish-plugin-commands = on
snapshot-store {
plugin = "akka.persistence.snapshot-store.sql-server"
sql-server {
class = "Akka.Persistence.SqlServer.Snapshot.SqlServerSnapshotStore, Akka.Persistence.SqlServer"
plugin-dispatcher = "akka.actor.default-dispatcher"
table-name = SnapshotStore
schema-name = dbo
auto-initialize = on
connection-string = "{{connectionString}}"
}
}
}
""";

return ConfigurationFactory.ParseString(specString);
}

protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
DbUtils.Clean();
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
// -----------------------------------------------------------------------
// <copyright file="SqlServerSnapshotStoreSaveSnapshotSpec.cs" company="Akka.NET Project">
// Copyright (C) 2013 - 2024 .NET Foundation <https://github.com/akkadotnet/akka.net>
// </copyright>
// -----------------------------------------------------------------------

using System;
using System.Threading.Tasks;
using Akka.Configuration;
using Akka.Persistence.TCK.Serialization;
using Akka.Persistence.TCK.Snapshot;
using FluentAssertions;
using FluentAssertions.Extensions;
using Xunit;
using Xunit.Abstractions;

namespace Akka.Persistence.SqlServer.Tests;

[Collection("SqlServerSpec")]
public class SqlServerSnapshotStoreSaveSnapshotSpec: SnapshotStoreSaveSnapshotSpec
{
public SqlServerSnapshotStoreSaveSnapshotSpec(ITestOutputHelper output, SqlServerFixture fixture)
: base(InitConfig(fixture), nameof(SqlServerSnapshotStoreSaveSnapshotSpec), output)
{

}

private static Config InitConfig(SqlServerFixture fixture)
{
//need to make sure db is created before the tests start
DbUtils.Initialize(fixture.ConnectionString);
var specString = $$"""
akka.persistence {
publish-plugin-commands = on
snapshot-store {
plugin = "akka.persistence.snapshot-store.sql-server"
sql-server {
class = "Akka.Persistence.SqlServer.Snapshot.SqlServerSnapshotStore, Akka.Persistence.SqlServer"
plugin-dispatcher = "akka.actor.default-dispatcher"
table-name = SnapshotStore
schema-name = dbo
auto-initialize = on
connection-string = "{{DbUtils.ConnectionString}}"
}
}
}
""";

return ConfigurationFactory.ParseString(specString);
}

protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
DbUtils.Clean();
}

[Fact(DisplayName = "Multiple SaveSnapshot invocation with default metadata should not throw")]
public async Task MultipleSnapshotsWithDefaultMetadata()
{
var persistence = Persistence.Instance.Apply(Sys);
var snapshotStore = persistence.SnapshotStoreFor(null);
var snap = new TestPayload(SenderProbe.Ref);

var now = DateTime.UtcNow;
var metadata = new SnapshotMetadata(PersistenceId, 0, DateTime.MinValue);
snapshotStore.Tell(new SaveSnapshot(metadata, snap), SenderProbe);
var success = await SenderProbe.ExpectMsgAsync<SaveSnapshotSuccess>(10.Minutes());
success.Metadata.PersistenceId.Should().Be(metadata.PersistenceId);
success.Metadata.Timestamp.Should().BeAfter(now);
success.Metadata.SequenceNr.Should().Be(metadata.SequenceNr);

snapshotStore.Tell(new SaveSnapshot(metadata, snap), SenderProbe);
success = await SenderProbe.ExpectMsgAsync<SaveSnapshotSuccess>();
success.Metadata.PersistenceId.Should().Be(metadata.PersistenceId);
success.Metadata.Timestamp.Should().BeAfter(now);
success.Metadata.SequenceNr.Should().Be(metadata.SequenceNr);
}
}

0 comments on commit a12e877

Please sign in to comment.