-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added runner to ActorContext to get number of queued messages
- Loading branch information
1 parent
cf5440e
commit b14ab8b
Showing
10 changed files
with
115 additions
and
17 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
| ||
namespace Nixie.Tests.Actors; | ||
|
||
public class MessageCountRequest | ||
{ | ||
|
||
} | ||
|
||
public class MessageCountResponse | ||
{ | ||
public int? Counter { get; } | ||
|
||
public MessageCountResponse(int? counter) | ||
{ | ||
Counter = counter; | ||
} | ||
} | ||
|
||
public sealed class MessageCountActor : IActor<MessageCountRequest, MessageCountResponse> | ||
{ | ||
private readonly IActorContext<MessageCountActor, MessageCountRequest, MessageCountResponse> context; | ||
|
||
public MessageCountActor(IActorContext<MessageCountActor, MessageCountRequest, MessageCountResponse> context) | ||
{ | ||
this.context = context; | ||
} | ||
|
||
public Task<MessageCountResponse?> Receive(MessageCountRequest message) | ||
{ | ||
return Task.FromResult<MessageCountResponse?>(new(context.Runner?.MessageCount)); | ||
} | ||
} | ||
|
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,22 @@ | ||
| ||
using Nixie.Tests.Actors; | ||
|
||
namespace Nixie.Tests; | ||
|
||
[Collection("Nixie")] | ||
public sealed class TestMessageCount | ||
{ | ||
[Fact] | ||
public async Task TestMessageCountEmpty() | ||
{ | ||
using ActorSystem asx = new(); | ||
|
||
IActorRef<MessageCountActor, MessageCountRequest, MessageCountResponse> actor = asx.Spawn<MessageCountActor, MessageCountRequest, MessageCountResponse>(); | ||
|
||
MessageCountResponse? message = await actor.Ask(new MessageCountRequest()); | ||
Assert.NotNull(message); | ||
|
||
Assert.True(message.Counter.HasValue); | ||
Assert.Equal(0, message.Counter.Value); | ||
} | ||
} |
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
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
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