He-Pin commented on code in PR #3677:
URL: https://github.com/apache/pekko/pull/3677#discussion_r4367348684


##########
cluster-sharding/src/test/scala/org/apache/pekko/cluster/sharding/AbstractShardAllocationStrategySpec.scala:
##########
@@ -0,0 +1,96 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.pekko.cluster.sharding
+
+import scala.collection.immutable
+import scala.jdk.CollectionConverters._
+
+import org.apache.pekko
+import pekko.actor.ActorRef
+import pekko.cluster.sharding.ShardRegion.ShardId
+import pekko.testkit.PekkoSpec
+import pekko.testkit.TestProbe
+
+class AbstractShardAllocationStrategySpec extends PekkoSpec {
+
+  private val regionA: ActorRef = TestProbe().ref
+  private val regionB: ActorRef = TestProbe().ref
+
+  private val allocations: Map[ActorRef, immutable.IndexedSeq[ShardId]] = Map(
+    regionA -> immutable.IndexedSeq("shard-1", "shard-2"),
+    regionB -> immutable.IndexedSeq("shard-3"))
+
+  private val expectedAllocations: Map[ActorRef, List[ShardId]] =
+    allocations.map { case (region, shards) => region -> shards.toList }
+
+  private def seenAllocations(strategy: RecordingShardAllocationStrategy): 
Map[ActorRef, List[ShardId]] = {
+    val seen = strategy.allocationsSeen.asScala
+    seen should have size 1
+    seen.head.asScala.iterator.map { case (region, shards) => region -> 
shards.asScala.toList }.toMap
+  }
+
+  "The Java API of AbstractShardAllocationStrategy" must {

Review Comment:
   Added - `"start a Java strategy before allocating and rebalancing through 
the coordinator"` starts a real single-node cluster and sharding via 
`ClusterSharding.start(..., allocationStrategy = strategy, ...)`, sends two 
entities, and asserts that `start()` ran exactly once and first, that both 
shards were allocated through the Java callback, that a rebalance round reached 
the strategy, and that the coordinator's allocation view exposes the shard ids 
as a `java.util.List` of size 2.
   
   The assertions all live inside one `awaitAssert` so they are checked against 
a single snapshot of the recorded calls.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to