-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement SnapshotStore SaveSnapshot spec (#400)
- Loading branch information
Showing
4 changed files
with
138 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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">-----------------------------------------------------------------------
 | ||
<copyright file="$FILENAME$" company="Akka.NET Project">
 | ||
Copyright (C) 2013 - $CURRENT_YEAR$ .NET Foundation <https://github.com/akkadotnet/akka.net>
 | ||
<copyright file="${File.FileName}" company="Akka.NET Project">
 | ||
Copyright (C) 2013 - ${CurrentDate.Year} .NET Foundation <https://github.com/akkadotnet/akka.net>
 | ||
</copyright>
 | ||
-----------------------------------------------------------------------</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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
src/Akka.Persistence.SqlServer.Tests/SqlServerConnectionFailureSpec.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
|
||
|
||
} |
79 changes: 79 additions & 0 deletions
79
src/Akka.Persistence.SqlServer.Tests/SqlServerSnapshotStoreSaveSnapshotSpec.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |