Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
// -----------------------------------------------------------------------
// <copyright file="MySqlSnapshotStoreSaveSnapshotSpec.cs" company="Akka.NET Project">
// Copyright (C) 2013-2023 .NET Foundation <https://github.com/akkadotnet/akka.net>
// </copyright>
// -----------------------------------------------------------------------

using System;
using Akka.Configuration;
using Akka.Persistence.Sql.Tests.Common.Containers;
using Akka.Persistence.Sql.Tests.Common.Internal.Xunit;
using FluentAssertions.Extensions;
using Xunit;
using Xunit.Abstractions;

namespace Akka.Persistence.Sql.Tests.MySql
{
#if !DEBUG
[SkipWindows]
#endif
[Collection(nameof(MySqlPersistenceSpec))]
public class MySqlSnapshotStoreSaveSnapshotSpec: SnapshotStoreSaveSnapshotSpecBase
{
public MySqlSnapshotStoreSaveSnapshotSpec(ITestOutputHelper output, MySqlContainer fixture)
: base(Configuration(fixture), nameof(MySqlSnapshotStoreSaveSnapshotSpec), output)
{
}

private static Configuration.Config Configuration(MySqlContainer fixture)
{
if (!fixture.InitializeDbAsync().Wait(10.Seconds()))
throw new Exception("Failed to clean up database in 10 seconds");

return ConfigurationFactory.ParseString(
$$"""
akka.persistence {
publish-plugin-commands = on
journal {
plugin = "akka.persistence.journal.sql"
sql {
connection-string = "{{fixture.ConnectionString}}"
provider-name = "{{fixture.ProviderName}}"
read-isolation-level = read-committed
write-isolation-level = read-committed
}
}
snapshot-store {
plugin = "akka.persistence.snapshot-store.sql"
sql {
connection-string = "{{fixture.ConnectionString}}"
provider-name = "{{fixture.ProviderName}}"
read-isolation-level = read-committed
write-isolation-level = read-committed
}
}
}
""")
.WithFallback(SqlPersistence.DefaultConfiguration);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// -----------------------------------------------------------------------
// <copyright file="PostgreSqlSnapshotStoreSaveSnapshotSpec.cs" company="Akka.NET Project">
// Copyright (C) 2013-2023 .NET Foundation <https://github.com/akkadotnet/akka.net>
// </copyright>
// -----------------------------------------------------------------------

using System;
using Akka.Configuration;
using Akka.Persistence.Sql.Tests.Common.Containers;
using Akka.Persistence.Sql.Tests.Common.Internal.Xunit;
using FluentAssertions.Extensions;
using Xunit;
using Xunit.Abstractions;

namespace Akka.Persistence.Sql.Tests.PostgreSql
{
#if !DEBUG
[SkipWindows]
#endif
[Collection(nameof(PostgreSqlPersistenceSpec))]
public class PostgreSqlSnapshotStoreSaveSnapshotSpec: SnapshotStoreSaveSnapshotSpecBase
{
public PostgreSqlSnapshotStoreSaveSnapshotSpec(ITestOutputHelper output, PostgreSqlContainer fixture)
: base(Configuration(fixture), nameof(PostgreSqlSnapshotStoreSaveSnapshotSpec), output)
{
}

private static Configuration.Config Configuration(PostgreSqlContainer fixture)
{
if (!fixture.InitializeDbAsync().Wait(10.Seconds()))
throw new Exception("Failed to clean up database in 10 seconds");

return ConfigurationFactory.ParseString(
$$"""
akka.persistence {
publish-plugin-commands = on
snapshot-store {
plugin = "akka.persistence.snapshot-store.sql"
sql {
connection-string = "{{fixture.ConnectionString}}"
provider-name = "{{fixture.ProviderName}}"
}
}
}
""")
.WithFallback(SqlPersistence.DefaultConfiguration);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// -----------------------------------------------------------------------
// <copyright file="SnapshotStoreSaveSnapshotSpecBase.cs" company="Akka.NET Project">
// Copyright (C) 2013-2023 .NET Foundation <https://github.com/akkadotnet/akka.net>
// </copyright>
// -----------------------------------------------------------------------

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

namespace Akka.Persistence.Sql.Tests
{
public abstract class SnapshotStoreSaveSnapshotSpecBase: SnapshotStoreSaveSnapshotSpec
{
protected SnapshotStoreSaveSnapshotSpecBase(Configuration.Config config, string actorSystemName, ITestOutputHelper? output = null)
: base(config, actorSystemName, output)
{

}

[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);

now = DateTime.UtcNow;
metadata = new SnapshotMetadata(PersistenceId, 0, DateTime.MinValue);
snapshotStore.Tell(new SaveSnapshot(metadata, 3), 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);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// -----------------------------------------------------------------------
// <copyright file="SqlServerSnapshotStoreSaveSnapshotSpec.cs" company="Akka.NET Project">
// Copyright (C) 2013-2023 .NET Foundation <https://github.com/akkadotnet/akka.net>
// </copyright>
// -----------------------------------------------------------------------

using Akka.Persistence.Sql.Tests.Common.Containers;
using Akka.Persistence.Sql.Tests.Common.Internal.Xunit;
using Xunit;
using Xunit.Abstractions;

namespace Akka.Persistence.Sql.Tests.SqlServer
{
#if !DEBUG
[SkipWindows]
#endif
[Collection(nameof(SqlServerPersistenceSpec))]
public class SqlServerSnapshotStoreSaveSnapshotSpec: SnapshotStoreSaveSnapshotSpecBase
{
public SqlServerSnapshotStoreSaveSnapshotSpec(ITestOutputHelper output, SqlServerContainer fixture)
: base(Configuration(fixture), nameof(SqlServerSnapshotStoreSaveSnapshotSpec), output)
{
}

private static Configuration.Config Configuration(SqlServerContainer fixture)
=> SqlServerSnapshotSpecConfig.Create(fixture, "snapshotSpec");

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

using Akka.Persistence.Sql.Tests.Common.Containers;
using Akka.Persistence.Sql.Tests.Common.Internal.Xunit;
using Xunit;
using Xunit.Abstractions;

namespace Akka.Persistence.Sql.Tests.Sqlite
{
#if !DEBUG
[SkipWindows]
#endif
[Collection(nameof(MsSqlitePersistenceSpec))]
public class MsSqliteSnapshotStoreSaveSnapshotSpec: SnapshotStoreSaveSnapshotSpecBase
{
public MsSqliteSnapshotStoreSaveSnapshotSpec(ITestOutputHelper output, MsSqliteContainer fixture)
: base(SqliteSnapshotSpecConfig.Create(fixture), nameof(MsSqliteSnapshotStoreSaveSnapshotSpec), output)
{
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// -----------------------------------------------------------------------
// <copyright file="SqliteSnapshotStoreSaveSnapshotSpec.cs" company="Akka.NET Project">
// Copyright (C) 2013-2023 .NET Foundation <https://github.com/akkadotnet/akka.net>
// </copyright>
// -----------------------------------------------------------------------

using Akka.Persistence.Sql.Tests.Common.Containers;
using Akka.Persistence.Sql.Tests.Common.Internal.Xunit;
using Xunit;
using Xunit.Abstractions;

namespace Akka.Persistence.Sql.Tests.Sqlite
{
#if !DEBUG
[SkipWindows]
#endif
[Collection(nameof(SqlitePersistenceSpec))]
public class SqliteSnapshotStoreSaveSnapshotSpec: SnapshotStoreSaveSnapshotSpecBase
{
public SqliteSnapshotStoreSaveSnapshotSpec(ITestOutputHelper output, SqliteContainer fixture)
: base(Configuration(fixture), nameof(SqliteSnapshotStoreSaveSnapshotSpec), output)
{
}

private static Configuration.Config Configuration(SqliteContainer fixture)
=> SqliteSnapshotSpecConfig.Create(fixture);

}
}