Skip to content

Commit

Permalink
add private constructor for ShardRegionCreator;
Browse files Browse the repository at this point in the history
Signed-off-by: Stefan Maute <stefan.maute@bosch.io>
  • Loading branch information
Stefan Maute committed Aug 24, 2022
1 parent 4fb6cdf commit ff52956
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@
@NotThreadSafe
public final class ShardRegionCreator {

private ShardRegionCreator() {
throw new AssertionError();
}

/**
* Create a shard region using a custom hand-off message.
*
Expand All @@ -41,17 +45,18 @@ public final class ShardRegionCreator {
*/
public static ActorRef start(final ActorSystem system, final String shardRegionName,
final Props props, final int numberOfShards, final String clusterRole) {

final var extractor = ShardRegionExtractor.of(numberOfShards, system);

return start(system, shardRegionName, props, extractor, clusterRole);
}

static ActorRef start(final ActorSystem system, final String shardRegionName, final Props props,
final ShardRegion.MessageExtractor extractor, final String clusterRole) {

final var clusterSharding = ClusterSharding.get(system);
final var settings = ClusterShardingSettings.create(system).withRole(clusterRole);
final var strategy = clusterSharding.defaultShardAllocationStrategy(settings);

return clusterSharding.start(shardRegionName, props, settings, extractor, strategy, new StopShardedActor());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public void terminateActorSystems() {
}

@Test
public void testHandOffMessage() throws Exception {
public void testHandOffMessage() {
new TestKit(system2) {{
// GIVEN: 2 actor systems form a cluster with shard regions started on both
final var props = Props.create(MessageForwarder.class, getRef());
Expand Down Expand Up @@ -146,7 +146,7 @@ public void testSelfRestart() {
// THEN: the sharded actor receives the hand-off message
expectMsgClass(StopShardedActor.class);

// WHEN: the sharded actor queues another message to self before stoppin
// WHEN: the sharded actor queues another message to self before stopping
firstShardedActor.tell(MessageForwarder.MESSAGE_SHARD, getRef());
expectMsg(MessageForwarder.MESSAGE_SHARD);
firstShardedActor.tell(PoisonPill.getInstance(), getRef());
Expand All @@ -162,6 +162,7 @@ public void testSelfRestart() {
private static boolean isShardedActorIn(final ActorRef shardedActor, final ActorSystem system) {
final var relativePath =
shardedActor.path().elements().drop(1).reduce((x, y) -> x + "/" + y).toString();

return ActorSelection.apply(system.systemImpl().systemGuardian(), relativePath)
.resolveOne(java.time.Duration.ofSeconds(10))
.thenApply(result -> true)
Expand Down Expand Up @@ -216,5 +217,7 @@ public Receive createReceive() {
.matchAny(message -> receiver.tell(message, getSelf()))
.build();
}

}

}

0 comments on commit ff52956

Please sign in to comment.