-
-
Notifications
You must be signed in to change notification settings - Fork 295
Expand file tree
/
Copy pathPartitionMiddlewareTests.cs
More file actions
86 lines (69 loc) · 2.83 KB
/
PartitionMiddlewareTests.cs
File metadata and controls
86 lines (69 loc) · 2.83 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
using System;
using System.Threading;
using System.Threading.Tasks;
using ClusterTest.Messages;
using FluentAssertions;
using Proto.Cluster;
using Proto.Cluster.Identity;
using Proto.Cluster.Partition;
using Proto.Cluster.PartitionActivator;
using Xunit;
namespace Proto.Cluster.Tests;
public class PartitionActivatorMiddlewareTests : IClassFixture<PartitionActivatorMiddlewareTests.ActivatorMiddlewareFixture>
{
private readonly ActivatorMiddlewareFixture _fx;
public PartitionActivatorMiddlewareTests(ActivatorMiddlewareFixture fx) => _fx = fx;
[Fact]
public async Task ShouldInvokeActivatorMiddleware()
{
var cluster = _fx.Members[0];
var identity = ClusterIdentity.Create("act", EchoActor.Kind);
await cluster.RequestAsync<Pong>(identity, new Ping(), CancellationToken.None);
_fx.ActivationRequests.Should().BeGreaterThan(0);
}
public class ActivatorMiddlewareFixture : BaseInMemoryClusterFixture
{
public int ActivationRequests;
public ActivatorMiddlewareFixture() : base(1, config => config.WithActorRequestTimeout(TimeSpan.FromSeconds(4)))
{
}
protected override IIdentityLookup GetIdentityLookup(string clusterName) =>
new PartitionActivatorLookup(props => props.WithReceiverMiddleware(next => async (ctx, env) =>
{
if (env.Message is ActivationRequest)
{
Interlocked.Increment(ref ActivationRequests);
}
await next(ctx, env);
}));
}
}
public class PartitionPlacementMiddlewareTests : IClassFixture<PartitionPlacementMiddlewareTests.PlacementMiddlewareFixture>
{
private readonly PlacementMiddlewareFixture _fx;
public PartitionPlacementMiddlewareTests(PlacementMiddlewareFixture fx) => _fx = fx;
[Fact]
public async Task ShouldInvokePlacementMiddleware()
{
var cluster = _fx.Members[0];
var identity = ClusterIdentity.Create("place", EchoActor.Kind);
await cluster.RequestAsync<Pong>(identity, new Ping(), CancellationToken.None);
_fx.ActivationRequests.Should().BeGreaterThan(0);
}
public class PlacementMiddlewareFixture : BaseInMemoryClusterFixture
{
public int ActivationRequests;
public PlacementMiddlewareFixture() : base(1, config => config.WithActorRequestTimeout(TimeSpan.FromSeconds(4)))
{
}
protected override IIdentityLookup GetIdentityLookup(string clusterName) =>
new PartitionIdentityLookup(new PartitionConfig(), props => props.WithReceiverMiddleware(next => async (ctx, env) =>
{
if (env.Message is ActivationRequest)
{
Interlocked.Increment(ref ActivationRequests);
}
await next(ctx, env);
}));
}
}