Skip to content

Commit

Permalink
Add custom persistence provider documentation (#5516)
Browse files Browse the repository at this point in the history
* Add initial documentation proposal

* Add custom provider sample project for documentation code linking

* Fix linter error

* Improve code formatting so it can be read better in the documentation

* Documentation improvements

* Add TODO tags for things that still need to be written
* Use code linking for code examples, linking to the sample project
* Improve WriteMessagesAsync documentation, shuffle paragraphs around for readability, add headers to separate the explanations, change long paragraphs into bullet points

* Rename file name to custom-persistence-provider, add docs to TOC

* Fix linter problems

* Add missing PostStop method to SqliteJournal

* Update documentation

* Add SnapshotStore, extension, and unit testing documentation.

* Fix linter errors

* Fix bad word wrapping

Co-authored-by: Aaron Stannard <aaron@petabridge.com>
  • Loading branch information
Arkatufus and Aaronontheweb authored Jan 25, 2022
1 parent 185559a commit a5ef30f
Show file tree
Hide file tree
Showing 14 changed files with 1,850 additions and 0 deletions.
466 changes: 466 additions & 0 deletions docs/articles/persistence/custom-persistence-provider.md

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions docs/articles/toc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@
href: persistence/storage-plugins.md
- name: Custom serialization
href: persistence/custom-serialization.md
- name: Writing A Custom Persistent Provider
href: persistence/custom-persistence-provider.md
- name: Persistence Query
href: persistence/persistence-query.md
- name: Persistence Testing
Expand Down
33 changes: 33 additions & 0 deletions src/Akka.sln
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,12 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Sharding", "Sharding", "{CF
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ShoppingCart", "examples\Cluster\ClusterSharding\ShoppingCart\ShoppingCart.csproj", "{9F8CCEDE-E871-473A-9C9A-DDDDE69E5130}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Persistence", "Persistence", "{A640E39E-F45C-4AE9-AABF-7F1432D357DA}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Akka.Persistence.Custom", "examples\Akka.Persistence.Custom\Akka.Persistence.Custom.csproj", "{B9091AE9-B257-4D3A-A9BC-EE2B43AF57A8}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Akka.Persistence.Custom.Tests", "examples\Akka.Persistence.Custom.Tests\Akka.Persistence.Custom.Tests.csproj", "{F6C974B8-48F8-41C7-95AC-3CFAA720E0E4}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -1165,6 +1171,30 @@ Global
{9F8CCEDE-E871-473A-9C9A-DDDDE69E5130}.Release|x64.Build.0 = Release|Any CPU
{9F8CCEDE-E871-473A-9C9A-DDDDE69E5130}.Release|x86.ActiveCfg = Release|Any CPU
{9F8CCEDE-E871-473A-9C9A-DDDDE69E5130}.Release|x86.Build.0 = Release|Any CPU
{B9091AE9-B257-4D3A-A9BC-EE2B43AF57A8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B9091AE9-B257-4D3A-A9BC-EE2B43AF57A8}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B9091AE9-B257-4D3A-A9BC-EE2B43AF57A8}.Debug|x64.ActiveCfg = Debug|Any CPU
{B9091AE9-B257-4D3A-A9BC-EE2B43AF57A8}.Debug|x64.Build.0 = Debug|Any CPU
{B9091AE9-B257-4D3A-A9BC-EE2B43AF57A8}.Debug|x86.ActiveCfg = Debug|Any CPU
{B9091AE9-B257-4D3A-A9BC-EE2B43AF57A8}.Debug|x86.Build.0 = Debug|Any CPU
{B9091AE9-B257-4D3A-A9BC-EE2B43AF57A8}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B9091AE9-B257-4D3A-A9BC-EE2B43AF57A8}.Release|Any CPU.Build.0 = Release|Any CPU
{B9091AE9-B257-4D3A-A9BC-EE2B43AF57A8}.Release|x64.ActiveCfg = Release|Any CPU
{B9091AE9-B257-4D3A-A9BC-EE2B43AF57A8}.Release|x64.Build.0 = Release|Any CPU
{B9091AE9-B257-4D3A-A9BC-EE2B43AF57A8}.Release|x86.ActiveCfg = Release|Any CPU
{B9091AE9-B257-4D3A-A9BC-EE2B43AF57A8}.Release|x86.Build.0 = Release|Any CPU
{F6C974B8-48F8-41C7-95AC-3CFAA720E0E4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F6C974B8-48F8-41C7-95AC-3CFAA720E0E4}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F6C974B8-48F8-41C7-95AC-3CFAA720E0E4}.Debug|x64.ActiveCfg = Debug|Any CPU
{F6C974B8-48F8-41C7-95AC-3CFAA720E0E4}.Debug|x64.Build.0 = Debug|Any CPU
{F6C974B8-48F8-41C7-95AC-3CFAA720E0E4}.Debug|x86.ActiveCfg = Debug|Any CPU
{F6C974B8-48F8-41C7-95AC-3CFAA720E0E4}.Debug|x86.Build.0 = Debug|Any CPU
{F6C974B8-48F8-41C7-95AC-3CFAA720E0E4}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F6C974B8-48F8-41C7-95AC-3CFAA720E0E4}.Release|Any CPU.Build.0 = Release|Any CPU
{F6C974B8-48F8-41C7-95AC-3CFAA720E0E4}.Release|x64.ActiveCfg = Release|Any CPU
{F6C974B8-48F8-41C7-95AC-3CFAA720E0E4}.Release|x64.Build.0 = Release|Any CPU
{F6C974B8-48F8-41C7-95AC-3CFAA720E0E4}.Release|x86.ActiveCfg = Release|Any CPU
{F6C974B8-48F8-41C7-95AC-3CFAA720E0E4}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -1275,6 +1305,9 @@ Global
{CF2704C6-3A27-450F-9C60-081341D88C1D} = {C50E1A9E-820C-4E75-AE39-6F96A99AC4A7}
{3C6EB4EF-3726-432F-812E-07828876418B} = {CF2704C6-3A27-450F-9C60-081341D88C1D}
{9F8CCEDE-E871-473A-9C9A-DDDDE69E5130} = {CF2704C6-3A27-450F-9C60-081341D88C1D}
{A640E39E-F45C-4AE9-AABF-7F1432D357DA} = {D3AF8295-AEB5-4324-AA82-FCC0014AC310}
{B9091AE9-B257-4D3A-A9BC-EE2B43AF57A8} = {A640E39E-F45C-4AE9-AABF-7F1432D357DA}
{F6C974B8-48F8-41C7-95AC-3CFAA720E0E4} = {A640E39E-F45C-4AE9-AABF-7F1432D357DA}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {03AD8E21-7507-4E68-A4E9-F4A7E7273164}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<Project Sdk="Microsoft.NET.Sdk">
<Import Project="..\..\common.props" />
<Import Project="..\..\xunitSettings.props" />

<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="$(TestSdkVersion)" />
<PackageReference Include="xunit" Version="$(XunitVersion)" />
<PackageReference Include="xunit.runner.visualstudio" Version="$(XunitVersion)">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\core\Akka.Persistence.TCK\Akka.Persistence.TCK.csproj" />
<ProjectReference Include="..\Akka.Persistence.Custom\Akka.Persistence.Custom.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// //-----------------------------------------------------------------------
// // <copyright file="SqliteJournalSerializationSpec.cs" company="Akka.NET Project">
// // Copyright (C) 2009-2022 Lightbend Inc. <http://www.lightbend.com>
// // Copyright (C) 2013-2022 .NET Foundation <https://github.com/akkadotnet/akka.net>
// // </copyright>
// //-----------------------------------------------------------------------

using System;
using Akka.Configuration;
using Akka.Persistence.TCK.Serialization;
using Xunit;
using Xunit.Abstractions;

namespace Akka.Persistence.Custom.Tests
{
public class SqliteJournalSerializationSpec : JournalSerializationSpec
{
public SqliteJournalSerializationSpec(ITestOutputHelper output)
: base(CreateSpecConfig("Filename=file:memdb-journal-" + Guid.NewGuid() + ".db"), nameof(SqliteJournalSerializationSpec), output)
{
}

private static Config CreateSpecConfig(string connectionString)
{
return ConfigurationFactory.ParseString(@"
akka.persistence {
publish-plugin-commands = on
journal {
plugin = ""akka.persistence.journal.custom-sqlite""
custom-sqlite {
event-adapters {
custom-adapter = ""Akka.Persistence.TCK.Serialization.TestJournal+MyWriteAdapter, Akka.Persistence.TCK""
}
event-adapter-bindings = {
""Akka.Persistence.TCK.Serialization.TestJournal+MyPayload3, Akka.Persistence.TCK"" = custom-adapter
}
class = ""Akka.Persistence.Custom.Journal.SqliteJournal, Akka.Persistence.Custom""
plugin-dispatcher = ""akka.actor.default-dispatcher""
auto-initialize = on
connection-string = """ + connectionString + @"""
}
}
}");
}


[Fact(Skip = "SQLite plugin does not support EventAdapter.Manifest")]
public override void Journal_should_serialize_Persistent_with_EventAdapter_manifest()
{
}
}
}
49 changes: 49 additions & 0 deletions src/examples/Akka.Persistence.Custom.Tests/SqliteJournalSpec.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// //-----------------------------------------------------------------------
// // <copyright file="SqliteJournalSpec.cs" company="Akka.NET Project">
// // Copyright (C) 2009-2022 Lightbend Inc. <http://www.lightbend.com>
// // Copyright (C) 2013-2022 .NET Foundation <https://github.com/akkadotnet/akka.net>
// // </copyright>
// //-----------------------------------------------------------------------

using System;
using System.Data.Common;
using System.Threading.Tasks;
using Akka.Configuration;
using Akka.Persistence.TCK.Journal;
using Akka.Util.Internal;
using Microsoft.Data.Sqlite;
using Xunit;
using Xunit.Abstractions;

namespace Akka.Persistence.Custom.Tests
{
public class SqliteJournalSpec : JournalSpec
{
public SqliteJournalSpec(ITestOutputHelper output)
: base(CreateSpecConfig("Filename=file:memdb-journal-" + Guid.NewGuid() + ".db"), nameof(SqliteJournalSpec), output)
{
SqlitePersistence.Get(Sys);

Initialize();
}

protected override bool SupportsSerialization => false;

private static Config CreateSpecConfig(string connectionString)
{
return ConfigurationFactory.ParseString(@"
akka.persistence {
publish-plugin-commands = on
journal {
plugin = ""akka.persistence.journal.custom-sqlite""
custom-sqlite {
class = ""Akka.Persistence.Custom.Journal.SqliteJournal, Akka.Persistence.Custom""
plugin-dispatcher = ""akka.actor.default-dispatcher""
auto-initialize = on
connection-string = """ + connectionString + @"""
}
}
}");
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// //-----------------------------------------------------------------------
// // <copyright file="SqliteSnapshotStoreSerializationSpec.cs" company="Akka.NET Project">
// // Copyright (C) 2009-2022 Lightbend Inc. <http://www.lightbend.com>
// // Copyright (C) 2013-2022 .NET Foundation <https://github.com/akkadotnet/akka.net>
// // </copyright>
// //-----------------------------------------------------------------------

using System;
using Akka.Configuration;
using Akka.Persistence.TCK.Serialization;
using Xunit.Abstractions;

namespace Akka.Persistence.Custom.Tests
{
public class SqliteSnapshotStoreSerializationSpec: SnapshotStoreSerializationSpec
{
public SqliteSnapshotStoreSerializationSpec(ITestOutputHelper output)
: base(CreateSpecConfig("Filename=file:serialization-snapshot-" + Guid.NewGuid() + ".db"), "SqliteSnapshotStoreSerializationSpec", output)
{
}

private static Config CreateSpecConfig(string connectionString)
{
return ConfigurationFactory.ParseString(@"
akka.persistence {
publish-plugin-commands = on
snapshot-store {
plugin = ""akka.persistence.snapshot-store.custom-sqlite""
custom-sqlite {
class = ""Akka.Persistence.Custom.Snapshot.SqliteSnapshotStore, Akka.Persistence.Custom""
plugin-dispatcher = ""akka.actor.default-dispatcher""
auto-initialize = on
connection-string = """ + connectionString + @"""
}
}
}");
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// //-----------------------------------------------------------------------
// // <copyright file="SqliteSnapshotStoreSpec.cs" company="Akka.NET Project">
// // Copyright (C) 2009-2022 Lightbend Inc. <http://www.lightbend.com>
// // Copyright (C) 2013-2022 .NET Foundation <https://github.com/akkadotnet/akka.net>
// // </copyright>
// //-----------------------------------------------------------------------

using System;
using Akka.Configuration;
using Akka.Persistence.TCK.Snapshot;
using Xunit.Abstractions;

namespace Akka.Persistence.Custom.Tests
{
public class SqliteSnapshotStoreSpec : SnapshotStoreSpec
{
public SqliteSnapshotStoreSpec(ITestOutputHelper output)
: base(CreateSpecConfig("Filename=file:memdb-snapshot-" + Guid.NewGuid() + ".db"), "SqliteSnapshotStoreSpec", output)
{
SqlitePersistence.Get(Sys);

Initialize();
}

private static Config CreateSpecConfig(string connectionString)
{
return ConfigurationFactory.ParseString(@"
akka.persistence {
publish-plugin-commands = on
snapshot-store {
plugin = ""akka.persistence.snapshot-store.custom-sqlite""
custom-sqlite {
class = ""Akka.Persistence.Custom.Snapshot.SqliteSnapshotStore, Akka.Persistence.Custom""
plugin-dispatcher = ""akka.actor.default-dispatcher""
auto-initialize = on
connection-string = """ + connectionString + @"""
}
}
}");
}

protected override bool SupportsSerialization => true;
}}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<LangVersion>8.0</LangVersion>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Data.SQLite" Version="5.0.11" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\core\Akka.Persistence\Akka.Persistence.csproj" />
</ItemGroup>

<ItemGroup>
<EmbeddedResource Include="sqlite.conf" />
</ItemGroup>

</Project>
Loading

0 comments on commit a5ef30f

Please sign in to comment.