-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
TestJournal and TestSnaphostStore (#3881)
* TestJournal with Write interception and various failure strategies * Akka.Persistence.TestKit implementation
- Loading branch information
1 parent
eed2681
commit 37be6a5
Showing
36 changed files
with
3,020 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
src/core/Akka.Persistence.TestKit.Tests/Actors/PersistActor.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
// ----------------------------------------------------------------------- | ||
// <copyright file="PersistActor.cs" company="Akka.NET Project"> | ||
// Copyright (C) 2009-2019 Lightbend Inc. <http://www.lightbend.com> | ||
// Copyright (C) 2013-2019 .NET Foundation <https://github.com/akkadotnet/akka.net> | ||
// </copyright> | ||
// ----------------------------------------------------------------------- | ||
|
||
namespace Akka.Persistence.TestKit.Tests | ||
{ | ||
using System; | ||
using Actor; | ||
|
||
public class PersistActor : UntypedPersistentActor | ||
{ | ||
public PersistActor(IActorRef probe) | ||
{ | ||
_probe = probe; | ||
} | ||
|
||
private readonly IActorRef _probe; | ||
|
||
public override string PersistenceId => "foo"; | ||
|
||
protected override void OnCommand(object message) | ||
{ | ||
switch (message as string) | ||
{ | ||
case "write": | ||
Persist(message, _ => | ||
{ | ||
_probe.Tell("ack"); | ||
}); | ||
|
||
break; | ||
|
||
default: | ||
return; | ||
} | ||
} | ||
|
||
protected override void OnRecover(object message) | ||
{ | ||
} | ||
|
||
protected override void OnPersistFailure(Exception cause, object @event, long sequenceNr) | ||
{ | ||
_probe.Tell("failure"); | ||
|
||
base.OnPersistFailure(cause, @event, sequenceNr); | ||
} | ||
|
||
protected override void OnPersistRejected(Exception cause, object @event, long sequenceNr) | ||
{ | ||
_probe.Tell("rejected"); | ||
|
||
base.OnPersistRejected(cause, @event, sequenceNr); | ||
} | ||
} | ||
} |
100 changes: 100 additions & 0 deletions
100
src/core/Akka.Persistence.TestKit.Tests/Actors/SnapshotActor.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
// ----------------------------------------------------------------------- | ||
// <copyright file="SnapshotActor.cs" company="Akka.NET Project"> | ||
// Copyright (C) 2009-2019 Lightbend Inc. <http://www.lightbend.com> | ||
// Copyright (C) 2013-2019 .NET Foundation <https://github.com/akkadotnet/akka.net> | ||
// </copyright> | ||
// ----------------------------------------------------------------------- | ||
|
||
namespace Akka.Persistence.TestKit.Tests | ||
{ | ||
using System; | ||
using Actor; | ||
|
||
public class SnapshotActor : UntypedPersistentActor | ||
{ | ||
public SnapshotActor(IActorRef probe) | ||
{ | ||
_probe = probe; | ||
} | ||
|
||
private readonly IActorRef _probe; | ||
|
||
public override string PersistenceId => "bar"; | ||
|
||
protected override void OnCommand(object message) | ||
{ | ||
switch (message) | ||
{ | ||
case "save": | ||
SaveSnapshot(message); | ||
return; | ||
|
||
case DeleteOne del: | ||
DeleteSnapshot(del.SequenceNr); | ||
return; | ||
|
||
case DeleteMany del: | ||
DeleteSnapshots(del.Criteria); | ||
return; | ||
|
||
case SaveSnapshotSuccess _: | ||
case SaveSnapshotFailure _: | ||
case DeleteSnapshotSuccess _: | ||
case DeleteSnapshotFailure _: | ||
case DeleteSnapshotsSuccess _: | ||
case DeleteSnapshotsFailure _: | ||
_probe.Tell(message); | ||
return; | ||
|
||
default: | ||
return; | ||
} | ||
} | ||
|
||
protected override void OnRecover(object message) | ||
{ | ||
if (message is SnapshotOffer snapshot) | ||
{ | ||
_probe.Tell(message); | ||
} | ||
} | ||
|
||
protected override void OnRecoveryFailure(Exception reason, object message = null) | ||
{ | ||
_probe.Tell(new RecoveryFailure(reason, message)); | ||
base.OnRecoveryFailure(reason, message); | ||
} | ||
|
||
public class DeleteOne | ||
{ | ||
public DeleteOne(long sequenceNr) | ||
{ | ||
SequenceNr = sequenceNr; | ||
} | ||
|
||
public long SequenceNr { get; } | ||
} | ||
|
||
public class DeleteMany | ||
{ | ||
public DeleteMany(SnapshotSelectionCriteria criteria) | ||
{ | ||
Criteria = criteria; | ||
} | ||
|
||
public SnapshotSelectionCriteria Criteria { get; } | ||
} | ||
|
||
public class RecoveryFailure | ||
{ | ||
public RecoveryFailure(Exception reason, object message) | ||
{ | ||
Reason = reason; | ||
Message = message; | ||
} | ||
|
||
public Exception Reason { get; } | ||
public object Message { get; } | ||
} | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
src/core/Akka.Persistence.TestKit.Tests/Akka.Persistence.TestKit.Tests.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<Import Project="..\..\common.props" /> | ||
|
||
<PropertyGroup> | ||
<AssemblyTitle>Akka.Persistence.TestKit.Tests</AssemblyTitle> | ||
<TargetFrameworks>$(NetFrameworkTestVersion);$(NetCoreTestVersion)</TargetFrameworks> | ||
<GenerateAssemblyInfo>false</GenerateAssemblyInfo> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="$(TestSdkVersion)" /> | ||
<PackageReference Include="xunit" Version="$(XunitVersion)" /> | ||
<PackageReference Include="xunit.runner.utility" Version="$(XunitVersion)" /> | ||
<PackageReference Include="xunit.runner.visualstudio" Version="$(XunitVersion)" /> | ||
<PackageReference Include="TeamCity.ServiceMessages" Version="3.0.8" /> | ||
<PackageReference Include="FluentAssertions" Version="$(FluentAssertionsVersion)" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\Akka.Persistence.TestKit\Akka.Persistence.TestKit.csproj" /> | ||
<ProjectReference Include="..\Akka.Persistence.TestKit.Xunit2\Akka.Persistence.TestKit.Xunit2.csproj" /> | ||
<ProjectReference Include="..\Akka.Tests.Shared.Internals\Akka.Tests.Shared.Internals.csproj" /> | ||
</ItemGroup> | ||
|
||
<PropertyGroup Condition=" '$(TargetFramework)' == '$(NetCoreTestVersion)' "> | ||
<DefineConstants>$(DefineConstants);CORECLR</DefineConstants> | ||
</PropertyGroup> | ||
|
||
<PropertyGroup Condition=" '$(Configuration)' == 'Release' "> | ||
<DefineConstants>$(DefineConstants);RELEASE</DefineConstants> | ||
</PropertyGroup> | ||
</Project> |
Oops, something went wrong.