Skip to content

Commit

Permalink
Add unit tests for all storage type (#268)
Browse files Browse the repository at this point in the history
  • Loading branch information
Arkatufus authored May 13, 2024
1 parent 625c564 commit c916f08
Show file tree
Hide file tree
Showing 17 changed files with 539 additions and 219 deletions.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
using Akka.Persistence.PostgreSql.Snapshot;
using Akka.Persistence.Sql.Common.Extensions;
using Akka.Persistence.Sql.Common.Journal;
using Akka.Serialization;
using FluentAssertions;
using FluentAssertions.Extensions;
using Xunit;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,29 +20,53 @@
namespace Akka.Persistence.PostgreSql.Tests
{
[Collection("PostgreSqlSpec")]
public class PostgreSqlJournalBigIntSpec : JournalSpec
public sealed class PostgreSqlByteAJournalBigIntSpec : PostgreSqlJournalBigIntSpec
{
private static Config Initialize(PostgresFixture fixture)
public PostgreSqlByteAJournalBigIntSpec(ITestOutputHelper output, PostgresFixture fixture)
: base(output, fixture, "bytea")
{ }
}

[Collection("PostgreSqlSpec")]
public sealed class PostgreSqlJsonBJournalBigIntSpec : PostgreSqlJournalBigIntSpec
{
public PostgreSqlJsonBJournalBigIntSpec(ITestOutputHelper output, PostgresFixture fixture)
: base(output, fixture, "jsonb")
{ }
}

[Collection("PostgreSqlSpec")]
public sealed class PostgreSqlJsonJournalBigIntSpec : PostgreSqlJournalBigIntSpec
{
public PostgreSqlJsonJournalBigIntSpec(ITestOutputHelper output, PostgresFixture fixture)
: base(output, fixture, "json")
{ }
}

public abstract class PostgreSqlJournalBigIntSpec : JournalSpec
{
private static Config Initialize(PostgresFixture fixture, string storedAs)
{
//need to make sure db is created before the tests start
DbUtils.Initialize(fixture);

var config = @"
akka.persistence {
var config = $@"
akka.persistence {{
publish-plugin-commands = on
journal {
journal {{
plugin = ""akka.persistence.journal.postgresql""
postgresql {
postgresql {{
class = ""Akka.Persistence.PostgreSql.Journal.PostgreSqlJournal, Akka.Persistence.PostgreSql""
plugin-dispatcher = ""akka.actor.default-dispatcher""
table-name = event_journal
schema-name = public
auto-initialize = on
connection-string = """ + DbUtils.ConnectionString + @"""
connection-string = ""{DbUtils.ConnectionString}""
use-bigint-identity-for-ordering-column = on
}
}
}
stored-as = {storedAs}
}}
}}
}}
akka.test.single-expect-default = 10s";

return ConfigurationFactory.ParseString(config);
Expand All @@ -51,8 +75,8 @@ class = ""Akka.Persistence.PostgreSql.Journal.PostgreSqlJournal, Akka.Persistenc
// TODO: hack. Replace when https://github.com/akkadotnet/akka.net/issues/3811
protected override bool SupportsSerialization => false;

public PostgreSqlJournalBigIntSpec(ITestOutputHelper output, PostgresFixture fixture)
: base(Initialize(fixture), "PostgreSqlJournalBigIntSpec", output)
protected PostgreSqlJournalBigIntSpec(ITestOutputHelper output, PostgresFixture fixture, string storedAs)
: base(Initialize(fixture, storedAs), "PostgreSqlJournalBigIntSpec", output)
{
Initialize();
}
Expand Down
51 changes: 39 additions & 12 deletions src/Akka.Persistence.PostgreSql.Tests/PostgreSqlJournalSpec.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,28 +20,55 @@
namespace Akka.Persistence.PostgreSql.Tests
{
[Collection("PostgreSqlSpec")]
public class PostgreSqlJournalSpec : JournalSpec
public sealed class PostgreSqlByteAJournalSpec : PostgreSqlJournalSpec
{
private static Config Initialize(PostgresFixture fixture)
public PostgreSqlByteAJournalSpec(ITestOutputHelper output, PostgresFixture fixture)
: base(output, fixture, "bytea")
{
}
}

[Collection("PostgreSqlSpec")]
public sealed class PostgreSqlJsonBJournalSpec : PostgreSqlJournalSpec
{
public PostgreSqlJsonBJournalSpec(ITestOutputHelper output, PostgresFixture fixture)
: base(output, fixture, "jsonb")
{
}
}

[Collection("PostgreSqlSpec")]
public sealed class PostgreSqlJsonJournalSpec : PostgreSqlJournalSpec
{
public PostgreSqlJsonJournalSpec(ITestOutputHelper output, PostgresFixture fixture)
: base(output, fixture, "json")
{
}
}

public abstract class PostgreSqlJournalSpec : JournalSpec
{
private static Config Initialize(PostgresFixture fixture, string storedAs)
{
//need to make sure db is created before the tests start
DbUtils.Initialize(fixture);

var config = @"
akka.persistence {
var config = @$"
akka.persistence {{
publish-plugin-commands = on
journal {
journal {{
plugin = ""akka.persistence.journal.postgresql""
postgresql {
postgresql {{
class = ""Akka.Persistence.PostgreSql.Journal.PostgreSqlJournal, Akka.Persistence.PostgreSql""
plugin-dispatcher = ""akka.actor.default-dispatcher""
table-name = event_journal
schema-name = public
auto-initialize = on
connection-string = """ + DbUtils.ConnectionString + @"""
}
}
}
connection-string = ""{DbUtils.ConnectionString}""
stored-as = {storedAs}
}}
}}
}}
akka.test.single-expect-default = 10s";

return ConfigurationFactory.ParseString(config);
Expand All @@ -50,8 +77,8 @@ class = ""Akka.Persistence.PostgreSql.Journal.PostgreSqlJournal, Akka.Persistenc
// TODO: hack. Replace when https://github.com/akkadotnet/akka.net/issues/3811
protected override bool SupportsSerialization => false;

public PostgreSqlJournalSpec(ITestOutputHelper output, PostgresFixture fixture)
: base(Initialize(fixture), "PostgreSqlJournalSpec", output: output)
protected PostgreSqlJournalSpec(ITestOutputHelper output, PostgresFixture fixture, string storedAs)
: base(Initialize(fixture, storedAs), "PostgreSqlJournalSpec", output: output)
{
Initialize();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
// </copyright>
//-----------------------------------------------------------------------

using System;
using Akka.Configuration;
using Akka.Persistence.TCK.Serialization;
using Akka.Persistence.TCK.Snapshot;
using Akka.TestKit;
using Xunit;
Expand All @@ -14,36 +16,68 @@
namespace Akka.Persistence.PostgreSql.Tests
{
[Collection("PostgreSqlSpec")]
public class PostgreSqlSnapshotStoreSequentialAccessSpec : SnapshotStoreSpec
public sealed class PostgreSqlByteASnapshotStoreSequentialAccessSpec : PostgreSqlSnapshotStoreSequentialAccessSpec
{
private static Config Initialize(PostgresFixture fixture)
public PostgreSqlByteASnapshotStoreSequentialAccessSpec(ITestOutputHelper output, PostgresFixture fixture)
: base(output, fixture, "bytea")
{ }
}

[Collection("PostgreSqlSpec")]
public sealed class PostgreSqlJsonBSnapshotStoreSequentialAccessSpec : PostgreSqlSnapshotStoreSequentialAccessSpec
{
public PostgreSqlJsonBSnapshotStoreSequentialAccessSpec(ITestOutputHelper output, PostgresFixture fixture)
: base(output, fixture, "jsonb")
{ }

[Fact(Skip = "Akka.Persistence.PostgreSql in JsonB mode does not support ISurrogate serialization")]
public override void ShouldSerializeSnapshots()
{ }
}

[Collection("PostgreSqlSpec")]
public sealed class PostgreSqlJsonSnapshotStoreSequentialAccessSpec : PostgreSqlSnapshotStoreSequentialAccessSpec
{
public PostgreSqlJsonSnapshotStoreSequentialAccessSpec(ITestOutputHelper output, PostgresFixture fixture)
: base(output, fixture, "json")
{ }

[Fact(Skip = "Akka.Persistence.PostgreSql in Json mode does not support ISurrogate serialization")]
public override void ShouldSerializeSnapshots()
{ }
}

public abstract class PostgreSqlSnapshotStoreSequentialAccessSpec : SnapshotStoreSpec
{
private static Config Initialize(PostgresFixture fixture, string storedAs)
{
//need to make sure db is created before the tests start
DbUtils.Initialize(fixture);

var config = @"
akka.persistence {
var config = $@"
akka.persistence {{
publish-plugin-commands = on
snapshot-store {
snapshot-store {{
plugin = ""akka.persistence.snapshot-store.postgresql""
postgresql {
postgresql {{
class = ""Akka.Persistence.PostgreSql.Snapshot.PostgreSqlSnapshotStore, Akka.Persistence.PostgreSql""
plugin-dispatcher = ""akka.actor.default-dispatcher""
table-name = snapshot_store
schema-name = public
auto-initialize = on
connection-string = """ + DbUtils.ConnectionString + @"""
connection-string = ""{DbUtils.ConnectionString}""
sequential-access = on
}
}
}
stored-as = {storedAs}
}}
}}
}}
akka.test.single-expect-default = 10s";

return ConfigurationFactory.ParseString(config);
}

public PostgreSqlSnapshotStoreSequentialAccessSpec(ITestOutputHelper output, PostgresFixture fixture)
: base(Initialize(fixture), "PostgreSqlSnapshotStoreSpec", output: output)
protected PostgreSqlSnapshotStoreSequentialAccessSpec(ITestOutputHelper output, PostgresFixture fixture, string storedAs)
: base(Initialize(fixture, storedAs), "PostgreSqlSnapshotStoreSpec", output: output)
{
Initialize();
}
Expand All @@ -68,5 +102,9 @@ public void SnapshotStore_should_save_and_overwrite_snapshot_with_same_sequence_
Assert.Equal(md.SequenceNr, result.Snapshot.Metadata.SequenceNr);
// metadata timestamp may have been changed
}

[Fact(Skip = "Akka.Persistence.PostgreSql in JsonB mode does not support ISurrogate serialization")]
public override void ShouldSerializeSnapshots()
{ }
}
}
Loading

0 comments on commit c916f08

Please sign in to comment.