Skip to content

Commit 80f73bc

Browse files
Added ShardingEnvelope checks for ShardingMessageAdapter (#7449)
* cleaned up `ShardingBufferAdapterSpec` * added `ShardEnvelope` check condition
1 parent 468546c commit 80f73bc

File tree

1 file changed

+33
-27
lines changed

1 file changed

+33
-27
lines changed

src/contrib/cluster/Akka.Cluster.Sharding.Tests/ShardingBufferAdapterSpec.cs

+33-27
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
using System;
99
using System.Collections.Immutable;
10+
using System.Threading.Tasks;
1011
using Akka.Actor;
1112
using Akka.Cluster.Tools.Singleton;
1213
using Akka.Configuration;
@@ -72,18 +73,20 @@ public object Apply(object message, IActorContext context)
7273
private const string ShardTypeName = "Caat";
7374

7475
private static Config SpecConfig =>
75-
ConfigurationFactory.ParseString(@"
76-
akka.loglevel = DEBUG
77-
akka.actor.provider = cluster
78-
akka.remote.dot-netty.tcp.port = 0
79-
akka.remote.log-remote-lifecycle-events = off
80-
81-
akka.test.single-expect-default = 5 s
82-
akka.cluster.sharding.state-store-mode = ""ddata""
83-
akka.cluster.sharding.verbose-debug-logging = on
84-
akka.cluster.sharding.fail-on-invalid-entity-state-transition = on
85-
akka.cluster.sharding.distributed-data.durable.keys = []")
86-
.WithFallback(ClusterSingletonManager.DefaultConfig()
76+
ConfigurationFactory.ParseString("""
77+
78+
akka.loglevel = DEBUG
79+
akka.actor.provider = cluster
80+
akka.remote.dot-netty.tcp.port = 0
81+
akka.remote.log-remote-lifecycle-events = off
82+
83+
akka.test.single-expect-default = 5 s
84+
akka.cluster.sharding.state-store-mode = "ddata"
85+
akka.cluster.sharding.verbose-debug-logging = on
86+
akka.cluster.sharding.fail-on-invalid-entity-state-transition = on
87+
akka.cluster.sharding.distributed-data.durable.keys = []
88+
""")
89+
.WithFallback(ClusterSingleton.DefaultConfig()
8790
.WithFallback(ClusterSharding.DefaultConfig()));
8891

8992
private readonly AtomicCounter _counterA = new (0);
@@ -105,9 +108,11 @@ public ShardingBufferAdapterSpec(ITestOutputHelper helper) : base(SpecConfig, he
105108

106109
InitializeLogger(_sysB, "[sysB]");
107110

111+
// ReSharper disable VirtualMemberCallInConstructor
108112
_pA = CreateTestProbe(_sysA);
109113
_pB = CreateTestProbe(_sysB);
110-
114+
// ReSharper restore VirtualMemberCallInConstructor
115+
111116
ClusterSharding.Get(_sysA).SetShardingBufferMessageAdapter(new TestMessageAdapter(_counterA));
112117
ClusterSharding.Get(_sysB).SetShardingBufferMessageAdapter(new TestMessageAdapter(_counterB));
113118

@@ -134,37 +139,38 @@ private IActorRef StartShard(ActorSystem sys)
134139
}
135140

136141
[Fact(DisplayName = "ClusterSharding buffer message adapter must be called when message was buffered")]
137-
public void ClusterSharding_must_initialize_cluster_and_allocate_sharded_actors()
142+
public async Task ClusterSharding_must_initialize_cluster_and_allocate_sharded_actors()
138143
{
139-
Cluster.Get(_sysA).Join(Cluster.Get(_sysA).SelfAddress); // coordinator on A
144+
await Cluster.Get(_sysA).JoinAsync(Cluster.Get(_sysA).SelfAddress); // coordinator on A
140145

141-
AwaitAssert(() =>
146+
await AwaitAssertAsync(() =>
142147
{
143148
Cluster.Get(_sysA).SelfMember.Status.Should().Be(MemberStatus.Up);
144149
}, TimeSpan.FromSeconds(1));
145150

146-
Cluster.Get(_sysB).Join(Cluster.Get(_sysA).SelfAddress);
151+
await Cluster.Get(_sysB).JoinAsync(Cluster.Get(_sysA).SelfAddress);
147152

148-
Within(TimeSpan.FromSeconds(10), () =>
153+
await WithinAsync(TimeSpan.FromSeconds(10), async () =>
149154
{
150-
AwaitAssert(() =>
155+
await AwaitAssertAsync(async () =>
151156
{
152157
foreach (var s in ImmutableHashSet.Create(_sysA, _sysB))
153158
{
154159
Cluster.Get(s).SendCurrentClusterState(TestActor);
155-
ExpectMsg<ClusterEvent.CurrentClusterState>().Members.Count.Should().Be(2);
160+
(await ExpectMsgAsync<ClusterEvent.CurrentClusterState>()).Members.Count.Should().Be(2);
156161
}
157162
});
158163
});
159164

160-
_regionA.Tell(1, _pA.Ref);
161-
_pA.ExpectMsg(1);
165+
// need to make sure that ShardingEnvelope doesn't impacted by this change
166+
_regionA.Tell(new ShardingEnvelope("1", 1), _pA.Ref);
167+
await _pA.ExpectMsgAsync(1);
162168

163169
_regionB.Tell(2, _pB.Ref);
164-
_pB.ExpectMsg(2);
170+
await _pB.ExpectMsgAsync(2);
165171

166172
_regionB.Tell(3, _pB.Ref);
167-
_pB.ExpectMsg(3);
173+
await _pB.ExpectMsgAsync(3);
168174

169175
var counterAValue = _counterA.Current;
170176
var counterBValue = _counterB.Current;
@@ -175,13 +181,13 @@ public void ClusterSharding_must_initialize_cluster_and_allocate_sharded_actors(
175181
counterBValue.Should().BeGreaterOrEqualTo(2);
176182

177183
_regionA.Tell(1, _pA.Ref);
178-
_pA.ExpectMsg(1);
184+
await _pA.ExpectMsgAsync(1);
179185

180186
_regionB.Tell(2, _pB.Ref);
181-
_pB.ExpectMsg(2);
187+
await _pB.ExpectMsgAsync(2);
182188

183189
_regionB.Tell(3, _pB.Ref);
184-
_pB.ExpectMsg(3);
190+
await _pB.ExpectMsgAsync(3);
185191

186192
// Each entity should not have their messages buffered once they were instantiated
187193
_counterA.Current.Should().Be(counterAValue);

0 commit comments

Comments
 (0)