-
-
Notifications
You must be signed in to change notification settings - Fork 295
Expand file tree
/
Copy pathConsistentHashPoolRouterTests.cs
More file actions
46 lines (38 loc) · 1.36 KB
/
ConsistentHashPoolRouterTests.cs
File metadata and controls
46 lines (38 loc) · 1.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
using System;
using System.Threading.Tasks;
using Proto.Router.Messages;
using Proto.TestFixtures;
using Proto;
using Xunit;
namespace Proto.Router.Tests;
public class ConsistentHashPoolRouterTests
{
private static readonly Props MyActorProps = Props.FromProducer(() => new RespondWithSelfActor());
private readonly TimeSpan _timeout = TimeSpan.FromMilliseconds(1000);
private record Ping(string Id) : IHashable
{
public string HashBy() => Id;
}
[Fact]
public async Task ConsistentHashPoolRouter_MessageWithSameHashAlwaysGoesToSameRoutee()
{
var system = new ActorSystem();
await using var _ = system;
var props = system.Root.NewConsistentHashPool(MyActorProps, 3)
.WithMailbox(() => new TestMailbox());
var router = system.Root.Spawn(props);
var pid1 = await system.Root.RequestAsync<PID>(router, new Ping("a"), _timeout);
var pid2 = await system.Root.RequestAsync<PID>(router, new Ping("b"), _timeout);
var pid3 = await system.Root.RequestAsync<PID>(router, new Ping("a"), _timeout);
Assert.Equal(pid1, pid3);
Assert.NotEqual(pid1, pid2);
}
private class RespondWithSelfActor : IActor
{
public Task ReceiveAsync(IContext context)
{
context.Respond(context.Self);
return Task.CompletedTask;
}
}
}