├── docs
├── index.md
├── articles
│ ├── toc.yml
│ └── index.md
├── images
│ ├── icon.png
│ └── akkalogo.png
├── toc.yml
├── web.config
└── docfx.json
├── src
├── Examples
│ ├── AkkaSql
│ │ ├── setup.sql
│ │ ├── Dockerfile
│ │ ├── docker-compose.yaml
│ │ └── setup.sh
│ ├── Akka.Hosting.SimpleDemo
│ │ ├── Echo.cs
│ │ ├── appsettings.Development.json
│ │ ├── appsettings.json
│ │ ├── Akka.Hosting.SimpleDemo.csproj
│ │ └── Program.cs
│ ├── Akka.Hosting.LoggingDemo
│ │ ├── Echo.cs
│ │ ├── appsettings.Development.json
│ │ ├── appsettings.json
│ │ ├── Akka.Hosting.LoggingDemo.csproj
│ │ ├── WorkerService.cs
│ │ └── Program.cs
│ └── Akka.Hosting.Asp.LoggingDemo
│ │ ├── Echo.cs
│ │ ├── appsettings.Development.json
│ │ ├── appsettings.json
│ │ ├── Akka.Hosting.Asp.LoggingDemo.csproj
│ │ ├── TestHealthCheck.cs
│ │ └── Program.cs
├── Akka.Hosting
│ ├── IDiscoveryOptions.cs
│ ├── Properties
│ │ └── FriendsOf.cs
│ ├── Coordination
│ │ └── LeaseOptionBase.cs
│ ├── Logging
│ │ └── LoggerFactorySetup.cs
│ ├── HealthChecks
│ │ ├── ActorSystemCheck.cs
│ │ ├── DelegateHealthCheck.cs
│ │ ├── HealthCheckAdapter.cs
│ │ └── AkkaHealthCheckExtensions.cs
│ ├── Akka.Hosting.csproj
│ ├── Util.cs
│ ├── LoggingExtensions.cs
│ └── IHoconOption.cs
├── Akka.Cluster.Hosting
│ ├── Properties
│ │ └── FriendsOf.cs
│ ├── ClusterDaemonOptions.cs
│ ├── Akka.Cluster.Hosting.csproj
│ ├── AkkaClusterHealthCheck.cs
│ └── ClusterClientDiscoveryOptions.cs
├── Akka.Hosting.TestKit
│ ├── Properties
│ │ └── FriendsOf.cs
│ ├── Akka.Hosting.TestKit.csproj.DotSettings
│ ├── Internals
│ │ ├── XUnitLoggerProvider.cs
│ │ ├── TestKitLoggerFactoryLogger.cs
│ │ └── XUnitLogger.cs
│ └── Akka.Hosting.TestKit.csproj
├── Akka.Persistence.Hosting
│ ├── Properties
│ │ └── FriendsOf.cs
│ ├── Akka.Persistence.Hosting.csproj
│ ├── Utils.cs
│ ├── Extensions.cs
│ ├── README.md
│ └── HealthChecks.cs
├── Akka.Remote.Hosting.Tests
│ ├── Resources
│ │ └── akka-validcert.pfx
│ ├── xunit.runner.json
│ └── Akka.Remote.Hosting.Tests.csproj
├── Akka.Hosting.Tests
│ ├── xunit.runner.json
│ ├── test.hocon
│ ├── XUnitLoggerProvider.cs
│ ├── HoconSpecs.cs
│ ├── TestHelpers.cs
│ ├── StartFailureSpec.cs
│ ├── Akka.Hosting.Tests.csproj
│ ├── SerializerRegistrationSpecs.cs
│ ├── HostingExtensionsSpec.cs
│ ├── XUnitLogger.cs
│ ├── Logging
│ │ ├── TestLogger.cs
│ │ ├── LoggerConfigEnd2EndSpecs.cs
│ │ ├── SerilogLoggerEnd2EndSpecs.cs
│ │ └── LogMessageFormatterSpec.cs
│ ├── UtilSpec.cs
│ └── Bugfix208Specs.cs
├── Akka.Cluster.Hosting.Tests
│ ├── xunit.runner.json
│ ├── ConfigAssertionHelper.cs
│ ├── XUnitLoggerProvider.cs
│ ├── ClusterClientSpecs.cs
│ ├── Akka.Cluster.Hosting.Tests.csproj
│ ├── ClusterShardingDistributedDataSpecs.cs
│ ├── ClusterSingletonWithDiSpecs.cs
│ ├── XUnitLogger.cs
│ └── TestHelper.cs
├── Akka.Hosting.API.Tests
│ ├── xunit.runner.json
│ ├── CoreApiSpec.cs
│ ├── Akka.Hosting.API.Tests.csproj
│ └── verify
│ │ └── CoreApiSpec.ApproveRemoting.verified.txt
├── Akka.Hosting.TestKit.Tests
│ ├── xunit.runner.json
│ ├── TestActorRefTests
│ │ ├── WrappedTerminated.cs
│ │ ├── Logger.cs
│ │ ├── WorkerActor.cs
│ │ ├── TActorBase.cs
│ │ ├── WatchAndForwardActor.cs
│ │ ├── NestingActor.cs
│ │ ├── SenderActor.cs
│ │ ├── FsmActor.cs
│ │ ├── ReplyActor.cs
│ │ ├── BossActor.cs
│ │ ├── PersistActor.cs
│ │ └── SnapshotActor.cs
│ ├── TestKitBaseTests
│ │ ├── RemainingTests.cs
│ │ ├── WithinTests.cs
│ │ ├── AwaitAssertTests.cs
│ │ ├── ExpectTests.cs
│ │ ├── IgnoreMessagesTests.cs
│ │ └── DilatedTests.cs
│ ├── Akka.Hosting.TestKit.Tests.csproj
│ ├── TestEventListenerTests
│ │ ├── ConfigTests.cs
│ │ ├── ForwardAllEventsTestEventListener.cs
│ │ ├── CustomEventFilterTests.cs
│ │ ├── DeadLettersEventFilterTests.cs
│ │ └── EventFilterTestBase.cs
│ ├── Properties
│ │ └── AssemblyInfo.cs
│ ├── TestKit_Config_Tests.cs
│ ├── DiPropsFailTest.cs
│ ├── HostingSpecSpec.cs
│ ├── NoImplicitSenderSpec.cs
│ ├── LoggerSpec.cs
│ ├── TestFSMRefTests
│ │ └── TestFSMRefSpec.cs
│ └── TestPersistenceTestKistTests
│ │ └── TestSnapshotStoreSpec.cs
├── Akka.Persistence.Hosting.Tests
│ ├── xunit.runner.json
│ ├── Akka.Persistence.Hosting.Tests.csproj
│ ├── HoconKeyValidatorSpec.cs
│ └── InMemoryPersistenceSpecs.cs
├── Akka.Hosting.Tests.Performance
│ ├── Program.cs
│ ├── Akka.Hosting.Tests.Performance.csproj
│ └── CombinedPerfSpecs.cs
└── Akka.Remote.Hosting
│ ├── Akka.Remote.Hosting.csproj
│ ├── README.md
│ └── AkkaRemoteHostingExtensions.cs
├── .nuke
└── parameters.json
├── global.json
├── appsettings.json
├── .github
├── dependabot.yaml
└── workflows
│ ├── pr_validation.yml
│ └── publish_nuget.yml
├── Akka.Hosting.sln.DotSettings
├── nuget.config
├── .gitattributes
├── scripts
├── bumpVersion.ps1
└── getReleaseNotes.ps1
└── Directory.Build.props
/docs/index.md:
--------------------------------------------------------------------------------
1 | # Introduction to My Project
--------------------------------------------------------------------------------
/src/Examples/AkkaSql/setup.sql:
--------------------------------------------------------------------------------
1 | CREATE DATABASE Akka;
2 | GO
--------------------------------------------------------------------------------
/docs/articles/toc.yml:
--------------------------------------------------------------------------------
1 | - name: Introduction
2 | href: index.md
--------------------------------------------------------------------------------
/.nuke/parameters.json:
--------------------------------------------------------------------------------
1 | {
2 | "$schema": "./build.schema.json"
3 | }
--------------------------------------------------------------------------------
/src/Examples/Akka.Hosting.SimpleDemo/Echo.cs:
--------------------------------------------------------------------------------
1 | public struct Echo{}
--------------------------------------------------------------------------------
/docs/articles/index.md:
--------------------------------------------------------------------------------
1 | # Introduction
2 |
3 | Article text goes here.
--------------------------------------------------------------------------------
/docs/images/icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/akkadotnet/Akka.Hosting/HEAD/docs/images/icon.png
--------------------------------------------------------------------------------
/docs/images/akkalogo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/akkadotnet/Akka.Hosting/HEAD/docs/images/akkalogo.png
--------------------------------------------------------------------------------
/global.json:
--------------------------------------------------------------------------------
1 | {
2 | "sdk": {
3 | "rollForward": "latestMinor",
4 | "version": "8.0.302"
5 | }
6 | }
--------------------------------------------------------------------------------
/src/Examples/Akka.Hosting.LoggingDemo/Echo.cs:
--------------------------------------------------------------------------------
1 | namespace Akka.Hosting.LoggingDemo;
2 |
3 | public struct Echo{}
--------------------------------------------------------------------------------
/src/Examples/Akka.Hosting.Asp.LoggingDemo/Echo.cs:
--------------------------------------------------------------------------------
1 | namespace Akka.Hosting.Asp.LoggingDemo;
2 |
3 | public struct Echo{}
--------------------------------------------------------------------------------
/src/Akka.Hosting/IDiscoveryOptions.cs:
--------------------------------------------------------------------------------
1 | namespace Akka.Hosting;
2 |
3 | public interface IDiscoveryOptions: IHoconOption
4 | {
5 | }
--------------------------------------------------------------------------------
/docs/toc.yml:
--------------------------------------------------------------------------------
1 | - name: Home
2 | href: index.md
3 | - name: Documentation
4 | href: articles/
5 | - name: API Reference
6 | href: api/
--------------------------------------------------------------------------------
/src/Akka.Cluster.Hosting/Properties/FriendsOf.cs:
--------------------------------------------------------------------------------
1 | using System.Runtime.CompilerServices;
2 |
3 | [assembly: InternalsVisibleTo("Akka.Cluster.Hosting.Tests")]
--------------------------------------------------------------------------------
/src/Akka.Hosting.TestKit/Properties/FriendsOf.cs:
--------------------------------------------------------------------------------
1 | using System.Runtime.CompilerServices;
2 |
3 | [assembly: InternalsVisibleTo("Akka.Hosting.TestKit.Tests")]
--------------------------------------------------------------------------------
/src/Akka.Persistence.Hosting/Properties/FriendsOf.cs:
--------------------------------------------------------------------------------
1 | using System.Runtime.CompilerServices;
2 |
3 | [assembly: InternalsVisibleTo("Akka.Persistence.Hosting.Tests")]
--------------------------------------------------------------------------------
/src/Akka.Remote.Hosting.Tests/Resources/akka-validcert.pfx:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/akkadotnet/Akka.Hosting/HEAD/src/Akka.Remote.Hosting.Tests/Resources/akka-validcert.pfx
--------------------------------------------------------------------------------
/src/Akka.Hosting/Properties/FriendsOf.cs:
--------------------------------------------------------------------------------
1 | using System.Runtime.CompilerServices;
2 |
3 | [assembly: InternalsVisibleTo("Akka.Hosting.Tests")]
4 | [assembly: InternalsVisibleTo("Akka.Hosting.Maui")]
--------------------------------------------------------------------------------
/src/Examples/Akka.Hosting.SimpleDemo/appsettings.Development.json:
--------------------------------------------------------------------------------
1 | {
2 | "Logging": {
3 | "LogLevel": {
4 | "Default": "Information",
5 | "Microsoft.AspNetCore": "Warning"
6 | }
7 | }
8 | }
9 |
--------------------------------------------------------------------------------
/src/Examples/Akka.Hosting.SimpleDemo/appsettings.json:
--------------------------------------------------------------------------------
1 | {
2 | "Logging": {
3 | "LogLevel": {
4 | "Default": "Information",
5 | "Microsoft.AspNetCore": "Warning"
6 | }
7 | },
8 | "AllowedHosts": "*"
9 | }
10 |
--------------------------------------------------------------------------------
/src/Akka.Hosting.Tests/xunit.runner.json:
--------------------------------------------------------------------------------
1 | {
2 | "$schema": "https://xunit.github.io/schema/current/xunit.runner.schema.json",
3 | "longRunningTestSeconds": 60,
4 | "parallelizeAssembly": false,
5 | "parallelizeTestCollections": false
6 | }
--------------------------------------------------------------------------------
/src/Akka.Cluster.Hosting.Tests/xunit.runner.json:
--------------------------------------------------------------------------------
1 | {
2 | "$schema": "https://xunit.github.io/schema/current/xunit.runner.schema.json",
3 | "longRunningTestSeconds": 60,
4 | "parallelizeAssembly": false,
5 | "parallelizeTestCollections": false
6 | }
--------------------------------------------------------------------------------
/src/Akka.Hosting.API.Tests/xunit.runner.json:
--------------------------------------------------------------------------------
1 | {
2 | "$schema": "https://xunit.github.io/schema/current/xunit.runner.schema.json",
3 | "longRunningTestSeconds": 60,
4 | "parallelizeAssembly": false,
5 | "parallelizeTestCollections": false
6 | }
--------------------------------------------------------------------------------
/src/Akka.Hosting.TestKit.Tests/xunit.runner.json:
--------------------------------------------------------------------------------
1 | {
2 | "$schema": "https://xunit.github.io/schema/current/xunit.runner.schema.json",
3 | "longRunningTestSeconds": 60,
4 | "parallelizeAssembly": false,
5 | "parallelizeTestCollections": false
6 | }
--------------------------------------------------------------------------------
/src/Akka.Remote.Hosting.Tests/xunit.runner.json:
--------------------------------------------------------------------------------
1 | {
2 | "$schema": "https://xunit.github.io/schema/current/xunit.runner.schema.json",
3 | "longRunningTestSeconds": 60,
4 | "parallelizeAssembly": false,
5 | "parallelizeTestCollections": false
6 | }
--------------------------------------------------------------------------------
/src/Examples/AkkaSql/Dockerfile:
--------------------------------------------------------------------------------
1 | FROM mcr.microsoft.com/mssql/server:2019-latest
2 |
3 | COPY ./setup.sql .
4 | COPY ./setup.sh .
5 |
6 | # Grant permission on the setup script
7 | #RUN chmod +x ./setup.sh
8 |
9 | CMD /bin/bash -C './setup.sh';'bash'
--------------------------------------------------------------------------------
/src/Akka.Persistence.Hosting.Tests/xunit.runner.json:
--------------------------------------------------------------------------------
1 | {
2 | "$schema": "https://xunit.github.io/schema/current/xunit.runner.schema.json",
3 | "longRunningTestSeconds": 60,
4 | "parallelizeAssembly": false,
5 | "parallelizeTestCollections": false
6 | }
--------------------------------------------------------------------------------
/docs/web.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/src/Examples/Akka.Hosting.LoggingDemo/appsettings.Development.json:
--------------------------------------------------------------------------------
1 | {
2 | "Logging": {
3 | "LogLevel": {
4 | "Default": "Information",
5 | "Microsoft": "Warning",
6 | "Microsoft.Hosting.Lifetime": "Information"
7 | }
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/src/Examples/Akka.Hosting.Asp.LoggingDemo/appsettings.Development.json:
--------------------------------------------------------------------------------
1 | {
2 | "Logging": {
3 | "LogLevel": {
4 | "Default": "Information",
5 | "Microsoft": "Warning",
6 | "Microsoft.Hosting.Lifetime": "Information"
7 | }
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/appsettings.json:
--------------------------------------------------------------------------------
1 | {
2 | "SignClient": {
3 | "AzureAd": {
4 | "AADInstance": "https://login.microsoftonline.com/",
5 | "ClientId": "",
6 | "TenantId": ""
7 | },
8 | "Service": {
9 | "Url": "",
10 | "ResourceId": ""
11 | }
12 | }
13 | }
--------------------------------------------------------------------------------
/.github/dependabot.yaml:
--------------------------------------------------------------------------------
1 | version: 2
2 |
3 | updates:
4 | - package-ecosystem: github-actions
5 | directory: "/"
6 | schedule:
7 | interval: daily
8 | time: "11:00"
9 |
10 | - package-ecosystem: nuget
11 | directory: "/"
12 | schedule:
13 | interval: daily
14 | time: "11:00"
15 |
--------------------------------------------------------------------------------
/src/Examples/Akka.Hosting.LoggingDemo/appsettings.json:
--------------------------------------------------------------------------------
1 | {
2 | "Logging": {
3 | "LogLevel": {
4 | "Default": "Information",
5 | "Microsoft": "Warning",
6 | "Microsoft.Hosting.Lifetime": "Information",
7 | "Akka": "Debug"
8 | }
9 | },
10 | "AllowedHosts": "*"
11 | }
12 |
--------------------------------------------------------------------------------
/src/Akka.Hosting.Tests.Performance/Program.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using NBench;
3 |
4 | namespace Akka.Hosting.Tests.Performance
5 | {
6 | class Program
7 | {
8 | static int Main(string[] args)
9 | {
10 | return NBenchRunner.Run();
11 | }
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/src/Examples/Akka.Hosting.Asp.LoggingDemo/appsettings.json:
--------------------------------------------------------------------------------
1 | {
2 | "Logging": {
3 | "LogLevel": {
4 | "Default": "Information",
5 | "Microsoft": "Warning",
6 | "Microsoft.Hosting.Lifetime": "Information",
7 | "Akka": "Debug"
8 | }
9 | },
10 | "AllowedHosts": "*"
11 | }
12 |
--------------------------------------------------------------------------------
/src/Examples/AkkaSql/docker-compose.yaml:
--------------------------------------------------------------------------------
1 | version: '3'
2 |
3 | services:
4 | sqlserver:
5 | image: sharding2.sql
6 | build:
7 | context: .
8 | ports:
9 | - '1533:1433'
10 | environment:
11 | ACCEPT_EULA: Y
12 | SA_PASSWORD: l0lTh1sIsOpenSource
13 | MSSQL_PID: Developer
--------------------------------------------------------------------------------
/src/Examples/AkkaSql/setup.sh:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | # start SQL Server
4 | /opt/mssql/bin/sqlservr &
5 |
6 | #wait for the SQL Server to come up
7 | sleep 15s
8 |
9 | # setup the tables
10 | echo "Connecting to SQL and creating Akka database."
11 | /opt/mssql-tools/bin/sqlcmd -S localhost -U sa -P ${SA_PASSWORD} -d master -i setup.sql
12 |
13 | sleep infinity
--------------------------------------------------------------------------------
/Akka.Hosting.sln.DotSettings:
--------------------------------------------------------------------------------
1 |
2 | True
--------------------------------------------------------------------------------
/src/Akka.Hosting.Tests/test.hocon:
--------------------------------------------------------------------------------
1 | # See petabridge.cmd configuration options here: https://cmd.petabridge.com/articles/install/host-configuration.html
2 | petabridge.cmd{
3 | # default IP address used to listen for incoming petabridge.cmd client connections
4 | # should be a safe default as it listens on "all network interfaces".
5 | host = "0.0.0.0"
6 |
7 | # default port number used to listen for incoming petabridge.cmd client connections
8 | port = 9110
9 | }
--------------------------------------------------------------------------------
/nuget.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/src/Akka.Hosting.TestKit/Akka.Hosting.TestKit.csproj.DotSettings:
--------------------------------------------------------------------------------
1 |
2 | True
--------------------------------------------------------------------------------
/src/Examples/Akka.Hosting.SimpleDemo/Akka.Hosting.SimpleDemo.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 | $(TestsNetCoreFramework)
4 | enable
5 | enable
6 | false
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/src/Akka.Hosting.Tests.Performance/Akka.Hosting.Tests.Performance.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 | Exe
4 | $(TestsNetCoreFramework)
5 | false
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/src/Akka.Persistence.Hosting/Akka.Persistence.Hosting.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 | $(LibraryFramework);$(NetLibraryFramework)
4 | README.md
5 | Akka.Persistence Microsoft.Extensions.Hosting support.
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/src/Akka.Remote.Hosting/Akka.Remote.Hosting.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 | $(LibraryFramework);$(NetLibraryFramework)
4 | README.md
5 | Akka.Remote Microsoft.Extensions.Hosting support.
6 | Latest
7 | enable
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/src/Akka.Cluster.Hosting.Tests/ConfigAssertionHelper.cs:
--------------------------------------------------------------------------------
1 | using Akka.Configuration;
2 | using Xunit;
3 |
4 | namespace Akka.Cluster.Hosting.Tests;
5 |
6 | public static class ConfigAssertionHelper
7 | {
8 | public static void AssertSameString(this Config first, Config second, string key)
9 | => Assert.Equal(second.GetString(key), first.GetString(key));
10 |
11 | public static void AssertSameInt(this Config first, Config second, string key)
12 | => Assert.Equal(second.GetInt(key), first.GetInt(key));
13 |
14 | public static void AssertSameTimeSpan(this Config first, Config second, string key)
15 | => Assert.Equal(second.GetTimeSpan(key), first.GetTimeSpan(key));
16 | }
--------------------------------------------------------------------------------
/src/Akka.Hosting.Tests/XUnitLoggerProvider.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.Extensions.Logging;
2 | using Xunit.Abstractions;
3 |
4 | namespace Akka.Hosting.Tests;
5 |
6 | public class XUnitLoggerProvider : ILoggerProvider
7 | {
8 | private readonly ITestOutputHelper _helper;
9 | private readonly LogLevel _logLevel;
10 |
11 | public XUnitLoggerProvider(ITestOutputHelper helper, LogLevel logLevel)
12 | {
13 | _helper = helper;
14 | _logLevel = logLevel;
15 | }
16 |
17 | public void Dispose()
18 | {
19 | // no-op
20 | }
21 |
22 | public ILogger CreateLogger(string categoryName)
23 | {
24 | return new XUnitLogger(categoryName, _helper, _logLevel);
25 | }
26 | }
--------------------------------------------------------------------------------
/src/Akka.Cluster.Hosting/ClusterDaemonOptions.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using Akka.Cluster.Sharding;
3 | using Akka.Configuration;
4 | using Akka.Hosting;
5 |
6 | namespace Akka.Cluster.Hosting;
7 |
8 | public sealed class ClusterDaemonOptions
9 | {
10 | public TimeSpan? KeepAliveInterval { get; set; }
11 | public ClusterShardingSettings? ShardingSettings { get; set; }
12 | public string? Role { get; set; }
13 | public object? HandoffStopMessage { get; set; }
14 |
15 | internal Config ToHocon()
16 | {
17 | return KeepAliveInterval is not null
18 | ? $"akka.cluster.sharded-daemon-process.keep-alive-interval = {KeepAliveInterval.ToHocon()}"
19 | : Config.Empty;
20 | }
21 | }
--------------------------------------------------------------------------------
/src/Akka.Cluster.Hosting.Tests/XUnitLoggerProvider.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.Extensions.Logging;
2 | using Xunit.Abstractions;
3 |
4 | namespace Akka.Cluster.Hosting.Tests;
5 |
6 | public class XUnitLoggerProvider : ILoggerProvider
7 | {
8 | private readonly ITestOutputHelper _helper;
9 | private readonly LogLevel _logLevel;
10 |
11 | public XUnitLoggerProvider(ITestOutputHelper helper, LogLevel logLevel)
12 | {
13 | _helper = helper;
14 | _logLevel = logLevel;
15 | }
16 |
17 | public void Dispose()
18 | {
19 | // no-op
20 | }
21 |
22 | public ILogger CreateLogger(string categoryName)
23 | {
24 | return new XUnitLogger(categoryName, _helper, _logLevel);
25 | }
26 | }
--------------------------------------------------------------------------------
/.gitattributes:
--------------------------------------------------------------------------------
1 | # Auto detect text files and perform LF normalization
2 | * text=auto
3 |
4 |
5 | # Custom for Visual Studio
6 | *.cs diff=csharp
7 | *.sln merge=union
8 | *.csproj merge=union
9 | *.vbproj merge=union
10 | *.fsproj merge=union
11 | *.dbproj merge=union
12 |
13 | # Standard to msysgit
14 | *.doc diff=astextplain
15 | *.DOC diff=astextplain
16 | *.docx diff=astextplain
17 | *.DOCX diff=astextplain
18 | *.dot diff=astextplain
19 | *.DOT diff=astextplain
20 | *.pdf diff=astextplain
21 | *.PDF diff=astextplain
22 | *.rtf diff=astextplain
23 | *.RTF diff=astextplain
24 |
25 | # Needed for Mono build shell script
26 | *.sh -text eol=lf
27 |
28 | # Needed for API Approvals
29 | *.txt text eol=crlf
30 |
31 | build.sh eol=lf
32 |
--------------------------------------------------------------------------------
/src/Akka.Hosting/Coordination/LeaseOptionBase.cs:
--------------------------------------------------------------------------------
1 | // -----------------------------------------------------------------------
2 | //
3 | // Copyright (C) 2013-2022 .NET Foundation
4 | //
5 | // -----------------------------------------------------------------------
6 |
7 | using System;
8 | using Akka.Actor.Setup;
9 |
10 | namespace Akka.Hosting.Coordination
11 | {
12 | public abstract class LeaseOptionBase : IHoconOption
13 | {
14 | public abstract string ConfigPath { get; }
15 | public abstract Type Class { get; }
16 | public abstract void Apply(AkkaConfigurationBuilder builder, Setup? setup = null);
17 | }
18 | }
--------------------------------------------------------------------------------
/src/Akka.Hosting.TestKit/Internals/XUnitLoggerProvider.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.Extensions.Logging;
2 | using Xunit.Abstractions;
3 |
4 | namespace Akka.Hosting.TestKit.Internals
5 | {
6 | public class XUnitLoggerProvider : ILoggerProvider
7 | {
8 | private readonly ITestOutputHelper _helper;
9 | private readonly LogLevel _logLevel;
10 |
11 | public XUnitLoggerProvider(ITestOutputHelper helper, LogLevel logLevel)
12 | {
13 | _helper = helper;
14 | _logLevel = logLevel;
15 | }
16 |
17 | public void Dispose()
18 | {
19 | // no-op
20 | }
21 |
22 | public ILogger CreateLogger(string categoryName)
23 | {
24 | return new XUnitLogger(categoryName, _helper, _logLevel);
25 | }
26 | }
27 | }
28 |
29 |
--------------------------------------------------------------------------------
/src/Akka.Cluster.Hosting/Akka.Cluster.Hosting.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 | $(LibraryFramework);$(NetLibraryFramework)
4 | README.md
5 | Akka.Cluster and Akka.Cluster.Sharding Microsoft.Extensions.Hosting support.
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/src/Examples/Akka.Hosting.Asp.LoggingDemo/Akka.Hosting.Asp.LoggingDemo.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 | $(TestsNetCoreFramework)
4 | enable
5 | enable
6 | false
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 | PreserveNewest
16 |
17 |
18 | PreserveNewest
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/src/Akka.Hosting/Logging/LoggerFactorySetup.cs:
--------------------------------------------------------------------------------
1 | // -----------------------------------------------------------------------
2 | //
3 | // Copyright (C) 2009-2022 Lightbend Inc.
4 | // Copyright (C) 2013-2022 .NET Foundation
5 | //
6 | // -----------------------------------------------------------------------
7 |
8 | using Akka.Actor.Setup;
9 | using Microsoft.Extensions.Logging;
10 |
11 | namespace Akka.Hosting.Logging
12 | {
13 | public class LoggerFactorySetup : Setup
14 | {
15 | public LoggerFactorySetup(ILoggerFactory loggerFactory)
16 | {
17 | LoggerFactory = loggerFactory;
18 | }
19 |
20 | public ILoggerFactory LoggerFactory { get; }
21 | }
22 | }
--------------------------------------------------------------------------------
/src/Akka.Hosting.TestKit.Tests/TestActorRefTests/WrappedTerminated.cs:
--------------------------------------------------------------------------------
1 | //-----------------------------------------------------------------------
2 | //
3 | // Copyright (C) 2009-2021 Lightbend Inc.
4 | // Copyright (C) 2013-2021 .NET Foundation
5 | //
6 | //-----------------------------------------------------------------------
7 |
8 | using Akka.Actor;
9 |
10 | namespace Akka.Hosting.TestKit.Tests.TestActorRefTests;
11 |
12 | public class WrappedTerminated
13 | {
14 | private readonly Terminated _terminated;
15 |
16 | public WrappedTerminated(Terminated terminated)
17 | {
18 | _terminated = terminated;
19 | }
20 |
21 | public Terminated Terminated { get { return _terminated; } }
22 | }
--------------------------------------------------------------------------------
/src/Akka.Hosting.Tests/HoconSpecs.cs:
--------------------------------------------------------------------------------
1 | using System.Threading.Tasks;
2 | using Akka.Actor;
3 | using FluentAssertions;
4 | using Microsoft.Extensions.DependencyInjection;
5 | using Xunit;
6 | using static Akka.Hosting.Tests.TestHelpers;
7 |
8 | namespace Akka.Hosting.Tests;
9 |
10 | public class HoconSpecs
11 | {
12 | [Fact]
13 | public async Task Should_load_HOCON_from_file()
14 | {
15 | // arrange
16 | using var host = await StartHost(collection => collection.AddAkka("Test", builder =>
17 | {
18 | builder.AddHoconFile("test.hocon", HoconAddMode.Append);
19 | }));
20 |
21 | // act
22 | var sys = host.Services.GetRequiredService();
23 | var hocon = sys.Settings.Config;
24 |
25 | // assert
26 | hocon.HasPath("petabridge.cmd").Should().BeTrue();
27 | }
28 | }
--------------------------------------------------------------------------------
/src/Akka.Hosting/HealthChecks/ActorSystemCheck.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Threading;
3 | using System.Threading.Tasks;
4 | using Akka.Actor;
5 | using Microsoft.Extensions.Diagnostics.HealthChecks;
6 |
7 | namespace Akka.Hosting.HealthChecks;
8 |
9 | ///
10 | /// Checks to see if the is alive or not.
11 | ///
12 | public sealed class ActorSystemLivenessCheck : IAkkaHealthCheck
13 | {
14 | public Task CheckHealthAsync(AkkaHealthCheckContext context, CancellationToken cancellationToken = default)
15 | {
16 | if (context.ActorSystem.WhenTerminated.IsCompleted)
17 | {
18 | return Task.FromResult(new HealthCheckResult(status: context.Registration.FailureStatus, description: "ActorSystem has terminated."));
19 | }
20 |
21 | return Task.FromResult(new HealthCheckResult(HealthStatus.Healthy, description: "ActorSystem is running."));
22 | }
23 | }
--------------------------------------------------------------------------------
/src/Akka.Hosting.TestKit.Tests/TestActorRefTests/Logger.cs:
--------------------------------------------------------------------------------
1 | //-----------------------------------------------------------------------
2 | //
3 | // Copyright (C) 2009-2021 Lightbend Inc.
4 | // Copyright (C) 2013-2021 .NET Foundation
5 | //
6 | //-----------------------------------------------------------------------
7 |
8 | using Akka.Actor;
9 | using Akka.Event;
10 |
11 | namespace Akka.Hosting.TestKit.Tests.TestActorRefTests;
12 |
13 | public class Logger : ActorBase
14 | {
15 | private int _count;
16 | private string? _msg;
17 | protected override bool Receive(object message)
18 | {
19 | if(message is Warning { Message: string } warning)
20 | {
21 | _count++;
22 | _msg = (string)warning.Message;
23 | return true;
24 | }
25 | return false;
26 | }
27 | }
--------------------------------------------------------------------------------
/src/Examples/Akka.Hosting.LoggingDemo/Akka.Hosting.LoggingDemo.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | $(TestsNetCoreFramework)
5 | enable
6 | enable
7 | false
8 | Exe
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 | PreserveNewest
22 |
23 |
24 | PreserveNewest
25 |
26 |
27 |
28 |
29 |
--------------------------------------------------------------------------------
/src/Akka.Hosting.TestKit.Tests/TestKitBaseTests/RemainingTests.cs:
--------------------------------------------------------------------------------
1 | //-----------------------------------------------------------------------
2 | //
3 | // Copyright (C) 2009-2021 Lightbend Inc.
4 | // Copyright (C) 2013-2021 .NET Foundation
5 | //
6 | //-----------------------------------------------------------------------
7 |
8 | using System;
9 | using System.Threading.Tasks;
10 | using Xunit;
11 |
12 | namespace Akka.Hosting.TestKit.Tests.TestKitBaseTests;
13 |
14 | public class RemainingTests : TestKit
15 | {
16 | protected override void ConfigureAkka(AkkaConfigurationBuilder builder, IServiceProvider provider)
17 | {
18 |
19 | }
20 |
21 | [Fact]
22 | public void Throw_if_remaining_is_called_outside_Within()
23 | {
24 | Assert.Throws(() => Remaining);
25 | }
26 | }
--------------------------------------------------------------------------------
/src/Akka.Hosting.TestKit.Tests/TestKitBaseTests/WithinTests.cs:
--------------------------------------------------------------------------------
1 | //-----------------------------------------------------------------------
2 | //
3 | // Copyright (C) 2009-2021 Lightbend Inc.
4 | // Copyright (C) 2013-2021 .NET Foundation
5 | //
6 | //-----------------------------------------------------------------------
7 |
8 | using System;
9 | using System.Threading.Tasks;
10 | using Xunit;
11 |
12 | namespace Akka.Hosting.TestKit.Tests.TestKitBaseTests;
13 |
14 | public class WithinTests : TestKit
15 | {
16 | protected override void ConfigureAkka(AkkaConfigurationBuilder builder, IServiceProvider provider)
17 | {
18 |
19 | }
20 |
21 | [Fact]
22 | public void Within_should_increase_max_timeout_by_the_provided_epsilon_value()
23 | {
24 | Within(TimeSpan.FromSeconds(1), () => ExpectNoMsg(), TimeSpan.FromMilliseconds(50));
25 | }
26 | }
--------------------------------------------------------------------------------
/src/Akka.Hosting/Akka.Hosting.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 | $(LibraryFramework);$(NetLibraryFramework)
4 | README.md
5 | Akka.NET Microsoft.Extensions.Hosting support.
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/src/Examples/Akka.Hosting.Asp.LoggingDemo/TestHealthCheck.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.Extensions.Diagnostics.HealthChecks;
2 |
3 | namespace Akka.Hosting.Asp.LoggingDemo
4 | {
5 | public class TestHealth : IAkkaHealthCheck
6 | {
7 | private readonly ILogger _logger;
8 |
9 | public TestHealth(ILogger logger)
10 | {
11 | _logger = logger;
12 | }
13 |
14 | public Task CheckHealthAsync(AkkaHealthCheckContext context, CancellationToken cancellationToken = default)
15 | {
16 | try
17 | {
18 | _logger.LogInformation("DI healthcheck is running");
19 | return Task.FromResult(HealthCheckResult.Healthy("Test is healthy"));
20 | }
21 | catch (Exception ex)
22 | {
23 | _logger.LogError(ex, "Health check failed for test");
24 | return Task.FromResult(HealthCheckResult.Unhealthy($"Test health check failed: {ex.Message}"));
25 | }
26 | }
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/scripts/bumpVersion.ps1:
--------------------------------------------------------------------------------
1 | function UpdateVersionAndReleaseNotes {
2 | param (
3 | [Parameter(Mandatory=$true)]
4 | [PSCustomObject]$ReleaseNotesResult,
5 |
6 | [Parameter(Mandatory=$true)]
7 | [string]$XmlFilePath
8 | )
9 |
10 | # Load XML
11 | $xmlContent = New-Object XML
12 | $xmlContent.Load($XmlFilePath)
13 |
14 | # Update VersionPrefix and PackageReleaseNotes
15 | $versionPrefixElement = $xmlContent.SelectSingleNode("//VersionPrefix")
16 | $versionPrefixElement.InnerText = $ReleaseNotesResult.Version
17 |
18 | $packageReleaseNotesElement = $xmlContent.SelectSingleNode("//PackageReleaseNotes")
19 | $packageReleaseNotesElement.InnerText = $ReleaseNotesResult.ReleaseNotes
20 |
21 | # Save the updated XML
22 | $xmlContent.Save($XmlFilePath)
23 | }
24 |
25 | # Usage example:
26 | # $notes = Get-ReleaseNotes -MarkdownFile "$PSScriptRoot\RELEASE_NOTES.md"
27 | # $propsPath = Join-Path -Path (Get-Item $PSScriptRoot).Parent.FullName -ChildPath "Directory.Build.props"
28 | # UpdateVersionAndReleaseNotes -ReleaseNotesResult $notes -XmlFilePath $propsPath
29 |
--------------------------------------------------------------------------------
/src/Akka.Hosting.TestKit.Tests/TestActorRefTests/WorkerActor.cs:
--------------------------------------------------------------------------------
1 | //-----------------------------------------------------------------------
2 | //
3 | // Copyright (C) 2009-2021 Lightbend Inc.
4 | // Copyright (C) 2013-2021 .NET Foundation
5 | //
6 | //-----------------------------------------------------------------------
7 |
8 | using Akka.Actor;
9 |
10 | namespace Akka.Hosting.TestKit.Tests.TestActorRefTests;
11 |
12 | public class WorkerActor : TActorBase
13 | {
14 | protected override bool ReceiveMessage(object message)
15 | {
16 | if((message as string) == "work")
17 | {
18 | Sender.Tell("workDone");
19 | Context.Stop(Self);
20 | return true;
21 |
22 | }
23 | //TODO: case replyTo: Promise[_] ⇒ replyTo.asInstanceOf[Promise[Any]].success("complexReply")
24 | if(message is IActorRef)
25 | {
26 | ((IActorRef)message).Tell("complexReply", Self);
27 | return true;
28 | }
29 | return false;
30 | }
31 | }
--------------------------------------------------------------------------------
/src/Akka.Hosting.TestKit.Tests/TestActorRefTests/TActorBase.cs:
--------------------------------------------------------------------------------
1 | //-----------------------------------------------------------------------
2 | //
3 | // Copyright (C) 2009-2021 Lightbend Inc.
4 | // Copyright (C) 2013-2021 .NET Foundation
5 | //
6 | //-----------------------------------------------------------------------
7 |
8 | using System.Threading;
9 | using Akka.Actor;
10 |
11 | namespace Akka.Hosting.TestKit.Tests.TestActorRefTests;
12 |
13 | // ReSharper disable once InconsistentNaming
14 | public abstract class TActorBase : ActorBase
15 | {
16 | protected sealed override bool Receive(object message)
17 | {
18 | var currentThread = Thread.CurrentThread;
19 | if(currentThread != TestActorRefSpec.Thread)
20 | TestActorRefSpec.OtherThread = currentThread;
21 | return ReceiveMessage(message);
22 | }
23 |
24 | protected abstract bool ReceiveMessage(object message);
25 |
26 | protected ActorSystem System
27 | {
28 | get { return ((LocalActorRef)Self).Cell.System; }
29 | }
30 | }
--------------------------------------------------------------------------------
/src/Akka.Hosting/HealthChecks/DelegateHealthCheck.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Threading;
3 | using System.Threading.Tasks;
4 | using Akka.Actor;
5 | using Microsoft.Extensions.Diagnostics.HealthChecks;
6 |
7 | namespace Akka.Hosting.HealthChecks;
8 |
9 | ///
10 | /// INTERNAL API
11 | ///
12 | /// Delegate-based health check implementation. Lowest ceremony API for defining health checks on the
13 | /// .
14 | ///
15 | internal sealed class DelegateHealthCheck : IAkkaHealthCheck
16 | {
17 | private readonly Func> _healthCheckFunc;
18 |
19 | public DelegateHealthCheck(Func> healthCheckFunc)
20 | {
21 | _healthCheckFunc = healthCheckFunc ?? throw new ArgumentNullException(nameof(healthCheckFunc));
22 | }
23 |
24 | public Task CheckHealthAsync(AkkaHealthCheckContext context, CancellationToken cancellationToken = default)
25 | {
26 | return _healthCheckFunc(context.ActorSystem, context.ActorRegistry, cancellationToken);
27 | }
28 | }
--------------------------------------------------------------------------------
/src/Akka.Hosting.Tests.Performance/CombinedPerfSpecs.cs:
--------------------------------------------------------------------------------
1 | using NBench;
2 |
3 | namespace Akka.Hosting.Tests.Performance
4 | {
5 | ///
6 | /// Test to see gauge the impact of having multiple things to measure on a benchmark
7 | ///
8 | public class CombinedPerfSpecs
9 | {
10 | private Counter? _counter;
11 |
12 | [PerfSetup]
13 | public void Setup(BenchmarkContext context)
14 | {
15 | _counter = context.GetCounter("TestCounter");
16 | }
17 |
18 | [PerfBenchmark(Description = "Test to gauge the impact of having multiple things to measure on a benchmark.",
19 | NumberOfIterations = 3, RunMode = RunMode.Throughput, RunTimeMilliseconds = 1000, TestMode = TestMode.Test)]
20 | [CounterThroughputAssertion("TestCounter", MustBe.GreaterThan, 10000000.0d)]
21 | [MemoryAssertion(MemoryMetric.TotalBytesAllocated, MustBe.LessThanOrEqualTo, ByteConstants.ThirtyTwoKb)]
22 | [GcTotalAssertion(GcMetric.TotalCollections, GcGeneration.Gen2, MustBe.ExactlyEqualTo, 0.0d)]
23 | public void Benchmark()
24 | {
25 | _counter!.Increment();
26 | }
27 | }
28 | }
--------------------------------------------------------------------------------
/src/Akka.Hosting.TestKit.Tests/Akka.Hosting.TestKit.Tests.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | $(TestsNetCoreFramework)
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 | all
18 | runtime; build; native; contentfiles; analyzers; buildtransitive
19 |
20 |
21 |
22 |
23 |
24 | Always
25 |
26 |
27 |
28 |
29 |
--------------------------------------------------------------------------------
/src/Akka.Hosting/HealthChecks/HealthCheckAdapter.cs:
--------------------------------------------------------------------------------
1 | using System.Threading;
2 | using System.Threading.Tasks;
3 | using Akka.Actor;
4 | using Microsoft.Extensions.Diagnostics.HealthChecks;
5 |
6 | namespace Akka.Hosting.HealthChecks;
7 |
8 | ///
9 | /// INTERNAL API
10 | ///
11 | /// Adapter wrapper around the to make it API-compatible with
12 | ///
13 | internal sealed class HealthCheckAdapter : IHealthCheck
14 | {
15 | private readonly IAkkaHealthCheck _healthCheck;
16 | private readonly ActorSystem _actorSystem;
17 | public HealthCheckAdapter(IAkkaHealthCheck healthCheck, ActorSystem actorSystem)
18 | {
19 | _healthCheck = healthCheck;
20 | _actorSystem = actorSystem;
21 | }
22 |
23 | public Task CheckHealthAsync(HealthCheckContext context, CancellationToken cancellationToken = new CancellationToken())
24 | {
25 | var akkaHealthCheckContext = new AkkaHealthCheckContext(_actorSystem)
26 | {
27 | Registration = context.Registration
28 | };
29 |
30 | return _healthCheck.CheckHealthAsync(akkaHealthCheckContext, cancellationToken);
31 | }
32 | }
--------------------------------------------------------------------------------
/src/Akka.Hosting.TestKit.Tests/TestActorRefTests/WatchAndForwardActor.cs:
--------------------------------------------------------------------------------
1 | //-----------------------------------------------------------------------
2 | //
3 | // Copyright (C) 2009-2021 Lightbend Inc.
4 | // Copyright (C) 2013-2021 .NET Foundation
5 | //
6 | //-----------------------------------------------------------------------
7 |
8 | using Akka.Actor;
9 |
10 | namespace Akka.Hosting.TestKit.Tests.TestActorRefTests;
11 |
12 | public class WatchAndForwardActor : ActorBase
13 | {
14 | private readonly IActorRef _forwardToActor;
15 |
16 | public WatchAndForwardActor(IActorRef watchedActor, IActorRef forwardToActor)
17 | {
18 | _forwardToActor = forwardToActor;
19 | Context.Watch(watchedActor);
20 | }
21 |
22 | protected override bool Receive(object message)
23 | {
24 | var terminated = message as Terminated;
25 | if(terminated != null)
26 | _forwardToActor.Tell(new WrappedTerminated(terminated), Sender);
27 | else
28 | _forwardToActor.Tell(message, Sender);
29 | return true;
30 | }
31 | }
--------------------------------------------------------------------------------
/src/Akka.Hosting/HealthChecks/AkkaHealthCheckExtensions.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using Akka.Actor;
3 | using Microsoft.Extensions.DependencyInjection;
4 | using Microsoft.Extensions.Diagnostics.HealthChecks;
5 |
6 | namespace Akka.Hosting.HealthChecks;
7 |
8 | internal static class AkkaHealthCheckExtensions
9 | {
10 | public const string AkkaTag = "akka";
11 |
12 | ///
13 | /// Converts an to a
14 | ///
15 | /// the original Akka.NET health check registration.
16 | public static HealthCheckRegistration ToHealthCheckRegistration(this AkkaHealthCheckRegistration registration)
17 | {
18 | // func for lazily instantiating the health check registration
19 | Func adapter = provider =>
20 | new HealthCheckAdapter(registration.Factory(provider), provider.GetRequiredService());
21 |
22 | var tags = registration.Tags;
23 | tags.Add(AkkaTag);
24 |
25 | return new HealthCheckRegistration(registration.Name, adapter, registration.FailureStatus, tags,
26 | registration.Timeout);
27 | }
28 | }
--------------------------------------------------------------------------------
/src/Akka.Hosting.TestKit.Tests/TestActorRefTests/NestingActor.cs:
--------------------------------------------------------------------------------
1 | //-----------------------------------------------------------------------
2 | //
3 | // Copyright (C) 2009-2021 Lightbend Inc.
4 | // Copyright (C) 2013-2021 .NET Foundation
5 | //
6 | //-----------------------------------------------------------------------
7 |
8 | using Akka.Actor;
9 | using Akka.TestKit;
10 |
11 | namespace Akka.Hosting.TestKit.Tests.TestActorRefTests;
12 |
13 | public class NestingActor : ActorBase
14 | {
15 | private readonly IActorRef _nested;
16 |
17 | public NestingActor(bool createTestActorRef)
18 | {
19 | _nested = createTestActorRef ? Context.ActorOf() : new TestActorRef(Context.System, Props.Create(), null, null);
20 | }
21 |
22 | protected override bool Receive(object message)
23 | {
24 | Sender.Tell(_nested, Self);
25 | return true;
26 | }
27 |
28 | private class NestedActor : ActorBase
29 | {
30 | protected override bool Receive(object message)
31 | {
32 | return true;
33 | }
34 | }
35 | }
--------------------------------------------------------------------------------
/.github/workflows/pr_validation.yml:
--------------------------------------------------------------------------------
1 | name: pr_validation
2 |
3 | on:
4 | push:
5 | branches:
6 | - master
7 | - dev
8 | - main
9 | - feature/*
10 | pull_request:
11 | branches:
12 | - master
13 | - dev
14 | - main
15 | - feature/*
16 |
17 | jobs:
18 | test:
19 | name: Test-${{matrix.os}}
20 | runs-on: ${{matrix.os}}
21 |
22 | strategy:
23 | matrix:
24 | os: [ubuntu-latest, windows-latest]
25 |
26 | steps:
27 | - name: "Checkout"
28 | uses: actions/checkout@v6
29 | with:
30 | lfs: true
31 | fetch-depth: 0
32 |
33 | - name: "Install .NET SDK"
34 | uses: actions/setup-dotnet@v5
35 | with:
36 | global-json-file: "./global.json"
37 |
38 | - name: "Update release notes"
39 | shell: pwsh
40 | run: |
41 | ./build.ps1
42 |
43 | - name: "dotnet build"
44 | run: dotnet build -c Release
45 |
46 | # .NET Framework tests can't run reliably on Linux, so we only do .NET 8
47 |
48 | - name: "dotnet test"
49 | shell: bash
50 | run: dotnet test -c Release
51 |
52 | - name: "dotnet pack"
53 | run: dotnet pack -c Release -o ./bin/nuget
54 |
--------------------------------------------------------------------------------
/src/Akka.Persistence.Hosting/Utils.cs:
--------------------------------------------------------------------------------
1 | // -----------------------------------------------------------------------
2 | //
3 | // Copyright (C) 2013-2022 .NET Foundation
4 | //
5 | // -----------------------------------------------------------------------
6 |
7 | using System.Collections.Generic;
8 | using System.Linq;
9 |
10 | namespace Akka.Persistence.Hosting
11 | {
12 | internal static class Utils
13 | {
14 | // This illegal character list is conservative. Normally '.' and '/' is allowed in a HOCON literal, but we'll
15 | // ban it just because it'll make our life harder in the future.
16 | private const string IllegalChars = "$\"{}[]:=,#`^?!@*&\\./";
17 |
18 | public static string[] IsIllegalHoconKey(this string s)
19 | {
20 | var illegals = new List();
21 | foreach (var c in s)
22 | {
23 | if(IllegalChars.Contains(c))
24 | illegals.Add($"{c}");
25 | else if(char.IsWhiteSpace(c))
26 | illegals.Add($"\\u{(int)c:X4}");
27 | }
28 |
29 | return illegals.Distinct().ToArray();
30 | }
31 | }
32 | }
--------------------------------------------------------------------------------
/src/Akka.Hosting.TestKit.Tests/TestEventListenerTests/ConfigTests.cs:
--------------------------------------------------------------------------------
1 | //-----------------------------------------------------------------------
2 | //
3 | // Copyright (C) 2009-2021 Lightbend Inc.
4 | // Copyright (C) 2013-2021 .NET Foundation
5 | //
6 | //-----------------------------------------------------------------------
7 |
8 | using System;
9 | using System.Linq;
10 | using System.Threading.Tasks;
11 | using FluentAssertions;
12 | using Xunit;
13 |
14 | namespace Akka.Hosting.TestKit.Tests.TestEventListenerTests
15 | {
16 | public class ConfigTests : TestKit
17 | {
18 | protected override void ConfigureAkka(AkkaConfigurationBuilder builder, IServiceProvider provider)
19 | {
20 | }
21 |
22 | [Fact]
23 | public void TestEventListener_is_in_config_by_default()
24 | {
25 | var configLoggers = Sys.Settings.Config.GetStringList("akka.loggers", new string[] { });
26 | configLoggers.Any(logger => logger.Contains("Akka.TestKit.TestEventListener")).Should().BeTrue();
27 | configLoggers.Any(logger => logger.Contains("Akka.Event.DefaultLogger")).Should().BeFalse();
28 | }
29 | }
30 | }
31 |
32 |
--------------------------------------------------------------------------------
/src/Akka.Hosting.TestKit/Akka.Hosting.TestKit.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | TestKit for writing tests for Akka.NET using Akka.Hosting and xUnit.
5 | $(LibraryFramework);$(NetLibraryFramework)
6 | true
7 | true
8 | false
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/src/Akka.Hosting.TestKit/Internals/TestKitLoggerFactoryLogger.cs:
--------------------------------------------------------------------------------
1 | // -----------------------------------------------------------------------
2 | //
3 | // Copyright (C) 2013-2022 .NET Foundation
4 | //
5 | // -----------------------------------------------------------------------
6 |
7 | using Akka.Actor;
8 | using Akka.Event;
9 | using Akka.Hosting.Logging;
10 |
11 | namespace Akka.Hosting.TestKit.Internals
12 | {
13 | public class TestKitLoggerFactoryLogger: LoggerFactoryLogger
14 | {
15 | protected override bool Receive(object message)
16 | {
17 | switch (message)
18 | {
19 | case InitializeLogger init:
20 | InternalLogger.Info($"{nameof(TestKitLoggerFactoryLogger)} started");
21 | ((EventStream)init.LoggingBus).Subscribe(Self);
22 | // Only reply if there's an actual sender waiting (not NoSender)
23 | if (!Sender.Equals(ActorRefs.NoSender))
24 | Sender.Tell(new LoggerInitialized());
25 | return true;
26 |
27 | default:
28 | return base.Receive(message);
29 | }
30 | }
31 | }
32 | }
--------------------------------------------------------------------------------
/src/Akka.Hosting.Tests/TestHelpers.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Threading.Tasks;
3 | using Akka.Actor;
4 | using Akka.Event;
5 | using Akka.TestKit.Xunit2.Internals;
6 | using Microsoft.Extensions.DependencyInjection;
7 | using Microsoft.Extensions.Hosting;
8 | using Xunit.Abstractions;
9 |
10 | namespace Akka.Hosting.Tests;
11 |
12 | public static class TestHelpers
13 | {
14 | public static async Task StartHost(Action testSetup)
15 | {
16 | var host = new HostBuilder()
17 | .ConfigureServices(services =>
18 | {
19 | services.AddSingleton();
20 | testSetup(services);
21 | }).Build();
22 |
23 | await host.StartAsync();
24 | return host;
25 | }
26 |
27 | public static AkkaConfigurationBuilder AddTestOutputLogger(this AkkaConfigurationBuilder builder,
28 | ITestOutputHelper output)
29 | {
30 | builder.WithActors((system, registry) =>
31 | {
32 | var extSystem = (ExtendedActorSystem)system;
33 | var logger = extSystem.SystemActorOf(Props.Create(() => new TestOutputLogger(output)), "log-test");
34 | logger.Tell(new InitializeLogger(system.EventStream));
35 | });
36 |
37 | return builder;
38 | }
39 | }
--------------------------------------------------------------------------------
/src/Akka.Persistence.Hosting.Tests/Akka.Persistence.Hosting.Tests.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | $(TestsNetCoreFramework)
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 | all
15 | runtime; build; native; contentfiles; analyzers; buildtransitive
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 | Always
27 |
28 |
29 |
30 |
31 |
--------------------------------------------------------------------------------
/src/Akka.Hosting.TestKit.Tests/TestEventListenerTests/ForwardAllEventsTestEventListener.cs:
--------------------------------------------------------------------------------
1 | //-----------------------------------------------------------------------
2 | //
3 | // Copyright (C) 2009-2021 Lightbend Inc.
4 | // Copyright (C) 2013-2021 .NET Foundation
5 | //
6 | //-----------------------------------------------------------------------
7 |
8 | using Akka.Actor;
9 | using Akka.Event;
10 | using Akka.TestKit;
11 |
12 | namespace Akka.Hosting.TestKit.Tests.TestEventListenerTests;
13 |
14 | public class ForwardAllEventsTestEventListener : TestEventListener
15 | {
16 | private IActorRef? _forwarder;
17 |
18 | protected override void Print(LogEvent m)
19 | {
20 | if(m.Message is ForwardAllEventsTo to)
21 | {
22 | _forwarder = to.Forwarder;
23 | _forwarder.Tell("OK");
24 | }
25 | else if(_forwarder != null)
26 | {
27 | _forwarder.Forward(m);
28 | }
29 | else
30 | {
31 | base.Print(m);
32 | }
33 | }
34 |
35 | public class ForwardAllEventsTo
36 | {
37 | public ForwardAllEventsTo(IActorRef forwarder)
38 | {
39 | Forwarder = forwarder;
40 | }
41 |
42 | public IActorRef Forwarder { get; }
43 | }
44 | }
--------------------------------------------------------------------------------
/src/Akka.Remote.Hosting.Tests/Akka.Remote.Hosting.Tests.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 | $(TestsNetCoreFramework)
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 | all
14 | runtime; build; native; contentfiles; analyzers; buildtransitive
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 | Always
25 |
26 |
27 | Always
28 |
29 |
30 |
31 |
--------------------------------------------------------------------------------
/scripts/getReleaseNotes.ps1:
--------------------------------------------------------------------------------
1 | function Get-ReleaseNotes {
2 | param (
3 | [Parameter(Mandatory=$true)]
4 | [string]$MarkdownFile
5 | )
6 |
7 | # Read markdown file content
8 | $content = Get-Content -Path $MarkdownFile -Raw
9 |
10 | # Split content based on headers
11 | $sections = $content -split "####"
12 |
13 | # Output object to store result
14 | $outputObject = [PSCustomObject]@{
15 | Version = $null
16 | Date = $null
17 | ReleaseNotes = $null
18 | }
19 |
20 | # Check if we have at least 3 sections (1. Before the header, 2. Header, 3. Release notes)
21 | if ($sections.Count -ge 3) {
22 | $header = $sections[1].Trim()
23 | $releaseNotes = $sections[2].Trim()
24 |
25 | # Extract version and date from the header
26 | $headerParts = $header -split " ", 2
27 | if ($headerParts.Count -eq 2) {
28 | $outputObject.Version = $headerParts[0]
29 | $outputObject.Date = $headerParts[1]
30 | }
31 |
32 | $outputObject.ReleaseNotes = $releaseNotes
33 | }
34 |
35 | # Return the output object
36 | return $outputObject
37 | }
38 |
39 | # Call function example:
40 | #$result = Get-ReleaseNotes -MarkdownFile "$PSScriptRoot\RELEASE_NOTES.md"
41 | #Write-Output "Version: $($result.Version)"
42 | #Write-Output "Date: $($result.Date)"
43 | #Write-Output "Release Notes:"
44 | #Write-Output $result.ReleaseNotes
45 |
--------------------------------------------------------------------------------
/.github/workflows/publish_nuget.yml:
--------------------------------------------------------------------------------
1 | name: Publish NuGet
2 |
3 | on:
4 | push:
5 | tags:
6 | - '*'
7 |
8 | jobs:
9 | publish-nuget:
10 |
11 | name: publish-nuget
12 | runs-on: ${{ matrix.os }}
13 | strategy:
14 | matrix:
15 | os: [ubuntu-latest]
16 |
17 | steps:
18 | - uses: actions/checkout@v6
19 | - name: Setup .NET Core
20 | uses: actions/setup-dotnet@v5
21 | with:
22 | dotnet-version: ${{ env.DOTNET_VERSION }}
23 |
24 | - name: "Update release notes"
25 | shell: pwsh
26 | run: |
27 | ./build.ps1
28 |
29 | - name: Create Packages
30 | run: dotnet pack /p:PackageVersion=${{ github.ref_name }} -c Release -o ./output
31 |
32 | - name: Push Packages
33 | run: dotnet nuget push "output/*.nupkg" -k ${{ secrets.NUGET_KEY }} -s https://api.nuget.org/v3/index.json
34 |
35 | - name: release
36 | uses: actions/create-release@v1
37 | id: create_release
38 | with:
39 | draft: false
40 | prerelease: false
41 | release_name: 'Akka.Hosting ${{ github.ref_name }}'
42 | tag_name: ${{ github.ref }}
43 | body_path: RELEASE_NOTES.md
44 | env:
45 | GITHUB_TOKEN: ${{ github.token }}
46 |
47 | - name: Upload Release Asset
48 | uses: AButler/upload-release-assets@v3.0
49 | with:
50 | repo-token: ${{ github.token }}
51 | release-tag: ${{ github.ref_name }}
52 | files: 'output/*.nupkg'
--------------------------------------------------------------------------------
/src/Akka.Cluster.Hosting.Tests/ClusterClientSpecs.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 | using Akka.Actor;
3 | using Akka.Cluster.Tools.Client;
4 | using Xunit;
5 |
6 | namespace Akka.Cluster.Hosting.Tests;
7 |
8 | public class ClusterClientSpecs
9 | {
10 | [Fact(DisplayName = "ClusterClientReceptionistSettings should be set correctly")]
11 | public void ClusterClientReceptionistSettingsSpec()
12 | {
13 | var config = AkkaClusterHostingExtensions.CreateReceptionistConfig("customName", "customRole")
14 | .GetConfig("akka.cluster.client.receptionist");
15 | var settings = ClusterReceptionistSettings.Create(config);
16 |
17 | Assert.Equal("customName", config.GetString("name"));
18 | Assert.Equal("customRole", settings.Role);
19 | }
20 |
21 | [Fact(DisplayName = "ClusterClientSettings should be set correctly")]
22 | public void ClusterClientSettingsSpec()
23 | {
24 | var contacts = new List
25 | {
26 | ActorPath.Parse("akka.tcp://one@localhost:1111/system/receptionist"),
27 | ActorPath.Parse("akka.tcp://two@localhost:1111/system/receptionist"),
28 | ActorPath.Parse("akka.tcp://three@localhost:1111/system/receptionist"),
29 | };
30 |
31 | var settings = AkkaClusterHostingExtensions.CreateClusterClientSettings(
32 | ClusterClientReceptionist.DefaultConfig(),
33 | contacts);
34 |
35 | contacts.CollectionEquals(settings.InitialContacts);
36 | }
37 | }
--------------------------------------------------------------------------------
/src/Akka.Cluster.Hosting.Tests/Akka.Cluster.Hosting.Tests.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 | $(TestsNetCoreFramework)
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 | all
15 | runtime; build; native; contentfiles; analyzers; buildtransitive
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 | Always
27 |
28 |
29 |
--------------------------------------------------------------------------------
/src/Akka.Hosting.TestKit.Tests/TestKitBaseTests/AwaitAssertTests.cs:
--------------------------------------------------------------------------------
1 | //-----------------------------------------------------------------------
2 | //
3 | // Copyright (C) 2009-2021 Lightbend Inc.
4 | // Copyright (C) 2013-2021 .NET Foundation
5 | //
6 | //-----------------------------------------------------------------------
7 |
8 | using System;
9 | using System.Threading.Tasks;
10 | using Akka.Configuration;
11 | using Xunit;
12 | using Xunit.Sdk;
13 |
14 | namespace Akka.Hosting.TestKit.Tests.TestKitBaseTests;
15 |
16 | public class AwaitAssertTests : TestKit
17 | {
18 | protected override Config Config { get; } = "akka.test.timefactor=2";
19 |
20 | protected override void ConfigureAkka(AkkaConfigurationBuilder builder, IServiceProvider provider)
21 | {
22 | }
23 |
24 | [Fact]
25 | public void AwaitAssert_must_not_throw_any_exception_when_assertion_is_valid()
26 | {
27 | AwaitAssert(() => Assert.Equal("foo", "foo"));
28 | }
29 |
30 | [Fact]
31 | public void AwaitAssert_must_throw_exception_when_assertion_is_invalid()
32 | {
33 | Within(TimeSpan.FromMilliseconds(300), TimeSpan.FromSeconds(1), () =>
34 | {
35 | Assert.Throws(() =>
36 | AwaitAssert(() => Assert.Equal("foo", "bar"), TimeSpan.FromMilliseconds(500), TimeSpan.FromMilliseconds(300)));
37 | });
38 | }
39 | }
--------------------------------------------------------------------------------
/src/Akka.Hosting.API.Tests/CoreApiSpec.cs:
--------------------------------------------------------------------------------
1 | using System.Threading.Tasks;
2 | using Akka.Cluster.Hosting.SBR;
3 | using Akka.Persistence.Hosting;
4 | using Akka.Remote.Hosting;
5 | using VerifyTests;
6 | using VerifyXunit;
7 | using Xunit;
8 | using static PublicApiGenerator.ApiGenerator;
9 | using static VerifyXunit.Verifier;
10 |
11 | namespace Akka.Hosting.API.Tests;
12 |
13 | [UsesVerify]
14 | public class CoreApiSpec
15 | {
16 | static CoreApiSpec()
17 | {
18 | VerifierSettings.ScrubLinesContaining("\"RepositoryUrl\"");
19 | VerifierSettings.ScrubLinesContaining("Versioning.TargetFramework");
20 | VerifyDiffPlex.Initialize();
21 | }
22 |
23 | private static Task VerifyAssembly()
24 | {
25 | var settings = new VerifySettings();
26 | settings.UseDirectory("verify");
27 | return Verify(typeof(T).Assembly.GeneratePublicApi(), settings);
28 | }
29 |
30 | [Fact]
31 | public Task ApproveCore()
32 | {
33 | return VerifyAssembly();
34 | }
35 |
36 | [Fact]
37 | public Task ApproveTestKit()
38 | {
39 | return VerifyAssembly();
40 | }
41 |
42 | [Fact]
43 | public Task ApproveCluster()
44 | {
45 | return VerifyAssembly();
46 | }
47 |
48 | [Fact]
49 | public Task ApproveRemoting()
50 | {
51 | return VerifyAssembly();
52 | }
53 |
54 | [Fact]
55 | public Task ApprovePersistence()
56 | {
57 | return VerifyAssembly();
58 | }
59 | }
--------------------------------------------------------------------------------
/src/Akka.Hosting.TestKit.Tests/TestActorRefTests/SenderActor.cs:
--------------------------------------------------------------------------------
1 | //-----------------------------------------------------------------------
2 | //
3 | // Copyright (C) 2009-2021 Lightbend Inc.
4 | // Copyright (C) 2013-2021 .NET Foundation
5 | //
6 | //-----------------------------------------------------------------------
7 |
8 | using Akka.Actor;
9 |
10 | namespace Akka.Hosting.TestKit.Tests.TestActorRefTests;
11 |
12 | public class SenderActor : TActorBase
13 | {
14 | private readonly IActorRef _replyActor;
15 |
16 | public SenderActor(IActorRef replyActor)
17 | {
18 | _replyActor = replyActor;
19 | }
20 |
21 | protected override bool ReceiveMessage(object message)
22 | {
23 | var strMessage = message as string;
24 | switch(strMessage)
25 | {
26 | case "complex":
27 | _replyActor.Tell("complexRequest", Self);
28 | return true;
29 | case "complex2":
30 | _replyActor.Tell("complexRequest2", Self);
31 | return true;
32 | case "simple":
33 | _replyActor.Tell("simpleRequest", Self);
34 | return true;
35 | case "complexReply":
36 | TestActorRefSpec.Counter--;
37 | return true;
38 | case "simpleReply":
39 | TestActorRefSpec.Counter--;
40 | return true;
41 | }
42 | return false;
43 | }
44 | }
--------------------------------------------------------------------------------
/docs/docfx.json:
--------------------------------------------------------------------------------
1 | {
2 | "metadata": [
3 | {
4 | "src": [
5 | {
6 | "files": [ "**/*.csproj" ],
7 | "exclude": [
8 | "**/obj/**",
9 | "**/bin/**",
10 | "_site/**",
11 | "**/*Tests*.csproj",
12 | "**/*Tests.*.csproj"
13 | ],
14 | "src": "../src"
15 | }
16 | ],
17 | "dest": "api"
18 | }
19 | ],
20 | "build": {
21 | "content": [
22 | {
23 | "files": [
24 | "api/**.yml",
25 | "api/index.md"
26 | ]
27 | },
28 | {
29 | "files": [
30 | "articles/**.md",
31 | "articles/**/toc.yml",
32 | "toc.yml",
33 | "*.md"
34 | ],
35 | "exclude": [
36 | "obj/**",
37 | "_site/**"
38 | ]
39 | },
40 | ],
41 | "resource": [
42 | {
43 | "files": [
44 | "images/**",
45 | "web.config",
46 | ],
47 | "exclude": [
48 | "obj/**",
49 | "_site/**"
50 | ]
51 | }
52 | ],
53 | "sitemap": {
54 | "baseUrl": "https://yoursite.github.io/"
55 | },
56 | "dest": "_site",
57 | "globalMetadata": {
58 | "_appTitle": "Akka.Hosting",
59 | "_disableContribution": "true",
60 | "_appLogoPath": "/images/icon.png",
61 | },
62 | "globalMetadataFiles": [],
63 | "fileMetadataFiles": [],
64 | "template": [
65 | "default",
66 | "template"
67 | ],
68 | "postProcessors": ["ExtractSearchIndex"],
69 | "noLangKeyword": false
70 | }
71 | }
--------------------------------------------------------------------------------
/src/Akka.Hosting.Tests/StartFailureSpec.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Threading.Tasks;
3 | using Akka.Actor;
4 | using FluentAssertions;
5 | using Microsoft.Extensions.DependencyInjection;
6 | using Microsoft.Extensions.Hosting;
7 | using Microsoft.Extensions.Logging;
8 | using Xunit;
9 | using Xunit.Abstractions;
10 | using static FluentAssertions.FluentActions;
11 |
12 | namespace Akka.Hosting.Tests;
13 |
14 | public class StartFailureSpec
15 | {
16 | private readonly ITestOutputHelper _output;
17 |
18 | public StartFailureSpec(ITestOutputHelper output)
19 | {
20 | _output = output;
21 | }
22 |
23 | [Fact]
24 | public async Task ShouldThrowWhenActorSystemFailedToStart()
25 | {
26 | // arrange
27 | var host = new HostBuilder()
28 | .ConfigureLogging(builder =>
29 | {
30 | builder.ClearProviders();
31 | builder.AddProvider(new XUnitLoggerProvider(_output, LogLevel.Debug));
32 | })
33 | .ConfigureServices(services =>
34 | {
35 | services.AddAkka("MySys", (builder, provider) =>
36 | {
37 | builder.AddStartup((_, _) => throw new TestException("BOOM"));
38 | });
39 | })
40 | .Build();
41 |
42 | await Awaiting(async () => await host.StartAsync()).Should()
43 | .ThrowExactlyAsync().WithMessage("BOOM");
44 | }
45 |
46 | private class TestException: Exception
47 | {
48 | public TestException(string? message) : base(message)
49 | {
50 | }
51 | }
52 | }
--------------------------------------------------------------------------------
/src/Akka.Hosting.TestKit.Tests/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | //-----------------------------------------------------------------------
2 | //
3 | // Copyright (C) 2009-2021 Lightbend Inc.
4 | // Copyright (C) 2013-2021 .NET Foundation
5 | //
6 | //-----------------------------------------------------------------------
7 |
8 | using System.Reflection;
9 | using System.Runtime.InteropServices;
10 |
11 | // General Information about an assembly is controlled through the following
12 | // set of attributes. Change these attribute values to modify the information
13 | // associated with an assembly.
14 | using Xunit;
15 |
16 | // Setting ComVisible to false makes the types in this assembly not visible
17 | // to COM components. If you need to access a type in this assembly from
18 | // COM, set the ComVisible attribute to true on that type.
19 | [assembly: ComVisible(false)]
20 |
21 | // The following GUID is for the ID of the typelib if this project is exposed to COM
22 | [assembly: Guid("b21496c0-a536-4953-9253-d2d0d526e42d")]
23 |
24 | // Version information for an assembly consists of the following four values:
25 | //
26 | // Major Version
27 | // Minor Version
28 | // Build Number
29 | // Revision
30 | //
31 | // You can specify all the values or you can default the Build and Revision Numbers
32 | // by using the '*' as shown below:
33 | // [assembly: AssemblyVersion("1.0.*")]
34 |
35 | [assembly: CollectionBehavior(CollectionBehavior.CollectionPerAssembly, DisableTestParallelization = true)]
36 |
--------------------------------------------------------------------------------
/src/Akka.Hosting.TestKit.Tests/TestActorRefTests/FsmActor.cs:
--------------------------------------------------------------------------------
1 | //-----------------------------------------------------------------------
2 | //
3 | // Copyright (C) 2009-2021 Lightbend Inc.
4 | // Copyright (C) 2013-2021 .NET Foundation
5 | //
6 | //-----------------------------------------------------------------------
7 |
8 | using Akka.Actor;
9 |
10 | namespace Akka.Hosting.TestKit.Tests.TestActorRefTests;
11 |
12 | public enum TestFsmState
13 | {
14 | First,
15 | Last
16 | }
17 |
18 | public class FsmActor : FSM
19 | {
20 | private readonly IActorRef _replyActor;
21 |
22 | public FsmActor(IActorRef replyActor)
23 | {
24 | _replyActor = replyActor;
25 |
26 | When(TestFsmState.First, e =>
27 | {
28 | if (e.FsmEvent.Equals("check"))
29 | {
30 | _replyActor.Tell("first");
31 | }
32 | else if (e.FsmEvent.Equals("next"))
33 | {
34 | return GoTo(TestFsmState.Last);
35 | }
36 |
37 | return Stay();
38 | });
39 |
40 | When(TestFsmState.Last, e =>
41 | {
42 | if (e.FsmEvent.Equals("check"))
43 | {
44 | _replyActor.Tell("last");
45 | }
46 | else if (e.FsmEvent.Equals("next"))
47 | {
48 | return GoTo(TestFsmState.First);
49 | }
50 |
51 | return Stay();
52 | });
53 |
54 | StartWith(TestFsmState.First, "foo");
55 | }
56 | }
--------------------------------------------------------------------------------
/src/Akka.Persistence.Hosting/Extensions.cs:
--------------------------------------------------------------------------------
1 | // -----------------------------------------------------------------------
2 | //
3 | // Copyright (C) 2013-2023 .NET Foundation
4 | //
5 | // -----------------------------------------------------------------------
6 |
7 | using System;
8 | using System.Data;
9 | using System.Runtime.CompilerServices;
10 | using Akka.Hosting;
11 |
12 | namespace Akka.Persistence.Hosting
13 | {
14 | public static class Extensions
15 | {
16 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
17 | public static string ToHocon(this IsolationLevel? level)
18 | {
19 | if (level is null)
20 | throw new ArgumentNullException(nameof(level));
21 | return level.Value.ToHocon();
22 | }
23 |
24 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
25 | public static string ToHocon(this IsolationLevel level)
26 | {
27 | return level switch
28 | {
29 | IsolationLevel.Unspecified => "unspecified".ToHocon(),
30 | IsolationLevel.ReadCommitted => "read-committed".ToHocon(),
31 | IsolationLevel.ReadUncommitted => "read-uncommitted".ToHocon(),
32 | IsolationLevel.RepeatableRead => "repeatable-read".ToHocon(),
33 | IsolationLevel.Serializable => "serializable".ToHocon(),
34 | IsolationLevel.Snapshot => "snapshot".ToHocon(),
35 | IsolationLevel.Chaos => "chaos".ToHocon(),
36 | _ => throw new IndexOutOfRangeException($"Unknown IsolationLevel value: {level}"),
37 | };
38 | }
39 |
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/src/Akka.Persistence.Hosting/README.md:
--------------------------------------------------------------------------------
1 | # Akka.Persistence.Hosting
2 |
3 | ## Akka.Persistence Extension Method
4 |
5 | ### WithJournal() Method
6 |
7 | Used to configure a specific Akka.Persistence.Journal instance, primarily to support [Event Adapters](https://getakka.net/articles/persistence/event-adapters.html).
8 |
9 | ```csharp
10 | public static AkkaConfigurationBuilder WithJournal(
11 | this AkkaConfigurationBuilder builder,
12 | string journalId,
13 | Action journalBuilder);
14 | ```
15 |
16 | ### Parameters
17 |
18 | * `journalId` __string__
19 |
20 | The id of the journal. i.e. if you want to apply this adapter to the `akka.persistence.journal.sql` journal, just use `"sql"`.
21 |
22 | * `journalBuilder` __Action\__
23 |
24 | Configuration method for configuring the journal.
25 |
26 | ### WithInMemoryJournal() Method
27 |
28 | Add an in-memory journal to the `ActorSystem`, usually for testing purposes.
29 |
30 | ```csharp
31 | public static AkkaConfigurationBuilder WithInMemoryJournal(
32 | this AkkaConfigurationBuilder builder);
33 | ```
34 |
35 | ```csharp
36 | public static AkkaConfigurationBuilder WithInMemoryJournal(
37 | this AkkaConfigurationBuilder builder,
38 | Action journalBuilder);
39 | ```
40 |
41 | ### Parameters
42 |
43 | * `journalBuilder` __Action\__
44 |
45 | Configuration method for configuring the journal.
46 |
47 | ### WithInMemorySnapshotStore() Method
48 |
49 | Add an in-memory snapshot store to the `ActorSystem`, usually for testing purposes.
50 |
51 | ```csharp
52 | public static AkkaConfigurationBuilder WithInMemorySnapshotStore(
53 | this AkkaConfigurationBuilder builder);
54 | ```
55 |
--------------------------------------------------------------------------------
/src/Akka.Hosting.TestKit.Tests/TestActorRefTests/ReplyActor.cs:
--------------------------------------------------------------------------------
1 | //-----------------------------------------------------------------------
2 | //
3 | // Copyright (C) 2009-2021 Lightbend Inc.
4 | // Copyright (C) 2013-2021 .NET Foundation
5 | //
6 | //-----------------------------------------------------------------------
7 |
8 | using System;
9 | using Akka.Actor;
10 | using Akka.TestKit;
11 |
12 | namespace Akka.Hosting.TestKit.Tests.TestActorRefTests;
13 |
14 | public class ReplyActor : TActorBase
15 | {
16 | private IActorRef? _replyTo;
17 |
18 | protected override bool ReceiveMessage(object message)
19 | {
20 | var strMessage = message as string;
21 | switch(strMessage)
22 | {
23 | case "complexRequest":
24 | _replyTo = Sender;
25 | var worker = new TestActorRef(System, Props.Create());
26 | worker.Tell("work");
27 | return true;
28 | case "complexRequest2":
29 | var worker2 = new TestActorRef(System, Props.Create());
30 | worker2.Tell(Sender, Self);
31 | return true;
32 | case "workDone":
33 | if (_replyTo is null)
34 | throw new NullReferenceException("_replyTo is null, make sure that \"complexRequest\" is sent first");
35 |
36 | _replyTo.Tell("complexReply", Self);
37 | return true;
38 | case "simpleRequest":
39 | Sender.Tell("simpleReply", Self);
40 | return true;
41 | }
42 | return false;
43 | }
44 | }
--------------------------------------------------------------------------------
/src/Akka.Persistence.Hosting.Tests/HoconKeyValidatorSpec.cs:
--------------------------------------------------------------------------------
1 | // -----------------------------------------------------------------------
2 | //
3 | // Copyright (C) 2013-2022 .NET Foundation
4 | //
5 | // -----------------------------------------------------------------------
6 |
7 | using System;
8 | using System.Collections.Generic;
9 | using FluentAssertions;
10 | using Xunit;
11 |
12 | namespace Akka.Persistence.Hosting.Tests;
13 |
14 | public class HoconKeyValidatorSpec
15 | {
16 | [MemberData(nameof(StringFactory))]
17 | [Theory(DisplayName = "HOCON key validator should detect illegal characters")]
18 | public void ValidatorTest(string input, string[] illegals)
19 | {
20 | var illegalChars = input.IsIllegalHoconKey();
21 | illegalChars.Length.Should().Be(illegals.Length);
22 | illegalChars.Should().BeEquivalentTo(illegals);
23 | }
24 |
25 | public static IEnumerable