PolicyPersistenceActor extends AbstractShardedPersistenceActor<Command, Policy, PolicyId, PolicyId, PolicyEvent> { public static Props props(final PolicyId policyId, final SnapshotAdapter<Policy> snapshotAdapter, final ActorRef pubSubMediator) { return Props.create(PolicyPersistenceActor.class, policyId, snapshotAdapter, pubSubMediator); } PolicyPersistenceActor(final PolicyId policyId,
            final SnapshotAdapter<Policy> snapshotAdapter,
            final ActorRef pubSubMediator); static Props props(final PolicyId policyId,
            final SnapshotAdapter<Policy> snapshotAdapter,
            final ActorRef pubSubMediator); static ActorRef getShardRegion(final ActorSystem system); @Override String persistenceId(); @Override String journalPluginId(); @Override String snapshotPluginId(); static final String PERSISTENCE_ID_PREFIX; }
@Test public void checkForActivityOfNonexistentPolicy() { new TestKit(actorSystem) { { final PolicyId policyId = PolicyId.of("test.ns", "nonexistent.policy"); final Props persistentActorProps = PolicyPersistenceActor.props(policyId, new PolicyMongoSnapshotAdapter(), pubSubMediator); final TestProbe errorsProbe = TestProbe.apply(actorSystem); final Props parentProps = Props.create(Actor.class, () -> new AbstractActor() { @Override public void preStart() { getContext().actorOf(persistentActorProps); } @Override public SupervisorStrategy supervisorStrategy() { return new OneForOneStrategy(true, DeciderBuilder.matchAny(throwable -> { errorsProbe.ref().tell(throwable, getSelf()); return SupervisorStrategy.restart(); }).build()); } @Override public Receive createReceive() { return ReceiveBuilder.create() .matchAny(message -> { if (getTestActor().equals(getSender())) { getContext().actorSelection(getSelf().path().child("*")) .forward(message, getContext()); } else { getTestActor().forward(message, getContext()); } }) .build(); } }); final ActorRef underTest = actorSystem.actorOf(parentProps); final Object checkForActivity = AbstractShardedPersistenceActor.checkForActivity(1L); underTest.tell(checkForActivity, getRef()); underTest.tell(checkForActivity, getRef()); underTest.tell(checkForActivity, getRef()); expectMsg(PolicySupervisorActor.Control.PASSIVATE); errorsProbe.expectNoMessage(scala.concurrent.duration.Duration.create(3, TimeUnit.SECONDS)); } }; }