-
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.
Improve Akka.Persistence.TestKit (#7324)
- Loading branch information
Showing
21 changed files
with
1,046 additions
and
42 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
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
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
4 changes: 4 additions & 0 deletions
4
src/core/Akka.Persistence.TestKit/Akka.Persistence.TestKit.csproj.DotSettings
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,4 @@ | ||
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation"> | ||
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=connection/@EntryIndexedValue">True</s:Boolean> | ||
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=journal/@EntryIndexedValue">True</s:Boolean> | ||
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=snapshotstore/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary> |
107 changes: 107 additions & 0 deletions
107
src/core/Akka.Persistence.TestKit/ConnectionInterceptors.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,107 @@ | ||
// ----------------------------------------------------------------------- | ||
// <copyright file="ConnectionInterceptors.cs" company="Petabridge, LLC"> | ||
// Copyright (C) 2015 - 2024 Petabridge, LLC <https://petabridge.com> | ||
// </copyright> | ||
// ----------------------------------------------------------------------- | ||
|
||
using System; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
||
namespace Akka.Persistence.TestKit; | ||
|
||
public static class ConnectionInterceptors | ||
{ | ||
public sealed class Noop : IConnectionInterceptor | ||
{ | ||
public static readonly IConnectionInterceptor Instance = new Noop(); | ||
|
||
public Task InterceptAsync() => Task.FromResult(true); | ||
} | ||
|
||
public sealed class Failure : IConnectionInterceptor | ||
{ | ||
public static readonly IConnectionInterceptor Instance = new Failure(); | ||
|
||
public Task InterceptAsync() => throw new TestConnectionException(); | ||
} | ||
|
||
public sealed class Delay : IConnectionInterceptor | ||
{ | ||
public Delay(TimeSpan delay, IConnectionInterceptor next) | ||
{ | ||
_delay = delay; | ||
_next = next; | ||
} | ||
|
||
private readonly TimeSpan _delay; | ||
private readonly IConnectionInterceptor _next; | ||
|
||
public async Task InterceptAsync() | ||
{ | ||
await Task.Delay(_delay); | ||
await _next.InterceptAsync(); | ||
} | ||
} | ||
|
||
public sealed class OnCondition : IConnectionInterceptor | ||
{ | ||
public OnCondition(Func<Task<bool>> predicate, IConnectionInterceptor next, bool negate = false) | ||
{ | ||
_predicate = predicate; | ||
_next = next; | ||
_negate = negate; | ||
} | ||
|
||
public OnCondition(Func<bool> predicate, IConnectionInterceptor next, bool negate = false) | ||
{ | ||
_predicate = () => Task.FromResult(predicate()); | ||
_next = next; | ||
_negate = negate; | ||
} | ||
|
||
private readonly Func<Task<bool>> _predicate; | ||
private readonly IConnectionInterceptor _next; | ||
private readonly bool _negate; | ||
|
||
public async Task InterceptAsync() | ||
{ | ||
var result = await _predicate(); | ||
if ((_negate && !result) || (!_negate && result)) | ||
{ | ||
await _next.InterceptAsync(); | ||
} | ||
} | ||
} | ||
|
||
public sealed class CancelableDelay: IConnectionInterceptor | ||
{ | ||
public CancelableDelay(TimeSpan delay, IConnectionInterceptor next, CancellationToken cancellationToken) | ||
{ | ||
_delay = delay; | ||
_next = next; | ||
_cancellationToken = cancellationToken; | ||
} | ||
|
||
private readonly TimeSpan _delay; | ||
private readonly IConnectionInterceptor _next; | ||
private readonly CancellationToken _cancellationToken; | ||
|
||
public async Task InterceptAsync() | ||
{ | ||
try | ||
{ | ||
await Task.Delay(_delay, _cancellationToken); | ||
} | ||
catch (OperationCanceledException) | ||
{ | ||
// no-op | ||
} | ||
catch (TimeoutException) | ||
{ | ||
// no-op | ||
} | ||
await _next.InterceptAsync(); | ||
} | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
src/core/Akka.Persistence.TestKit/IConnectionInterceptor.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,14 @@ | ||
// ----------------------------------------------------------------------- | ||
// <copyright file="IConnectionInterceptor.cs" company="Petabridge, LLC"> | ||
// Copyright (C) 2015 - 2024 Petabridge, LLC <https://petabridge.com> | ||
// </copyright> | ||
// ----------------------------------------------------------------------- | ||
|
||
using System.Threading.Tasks; | ||
|
||
namespace Akka.Persistence.TestKit; | ||
|
||
public interface IConnectionInterceptor | ||
{ | ||
Task InterceptAsync(); | ||
} |
14 changes: 14 additions & 0 deletions
14
src/core/Akka.Persistence.TestKit/Journal/IJournalConnectionBehaviorSetter.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,14 @@ | ||
// ----------------------------------------------------------------------- | ||
// <copyright file="IConnectionBehaviorSetter.cs" company="Petabridge, LLC"> | ||
// Copyright (C) 2015 - 2024 Petabridge, LLC <https://petabridge.com> | ||
// </copyright> | ||
// ----------------------------------------------------------------------- | ||
|
||
using System.Threading.Tasks; | ||
|
||
namespace Akka.Persistence.TestKit; | ||
|
||
public interface IJournalConnectionBehaviorSetter | ||
{ | ||
Task SetInterceptorAsync(IConnectionInterceptor interceptor); | ||
} |
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
Oops, something went wrong.