pjfanning commented on code in PR #3677: URL: https://github.com/apache/pekko/pull/3677#discussion_r4366422477
########## 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: These tests only call the adapter methods directly, so nothing runs a Java `AbstractShardAllocationStrategy` inside a real `ShardCoordinator`. A small spec that starts sharding with `RecordingShardAllocationStrategy` via `ClusterSharding.start(..., allocationStrategy, ...)` and checks that the strategy is invoked and shards get allocated would catch integration regressions, for example a later change to how the coordinator calls or wraps the strategy. -- 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]
