This is an automated email from the ASF dual-hosted git repository.
fanningpj pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/pekko.git
The following commit(s) were added to refs/heads/main by this push:
new 6d7d2d2794 rename UnpersistentBehavior as PersistenceProbeBehavior
(#2494)
6d7d2d2794 is described below
commit 6d7d2d279426f83d6fada2cfe02be8d94c0ed697
Author: PJ Fanning <[email protected]>
AuthorDate: Sat Nov 15 14:16:50 2025 +0100
rename UnpersistentBehavior as PersistenceProbeBehavior (#2494)
* rename UnpersistentBehavior as PersistenceProbeBehavior
* scalafmt
* rename class
---
... => AccountExamplePersistenceProbeDocTest.java} | 52 +++++++++---------
...=> AccountExamplePersistenceProbeDocSpec.scala} | 22 ++++----
docs/src/main/paradox/typed/persistence-testing.md | 26 ++++-----
...persistent.scala => PersistenceProbeImpl.scala} | 2 +-
...havior.scala => PersistenceProbeBehavior.scala} | 32 ++++++------
...havior.scala => PersistenceProbeBehavior.scala} | 16 +++---
...cala => PersistenceProbeDurableStateSpec.scala} | 28 +++++-----
...cala => PersistenceProbeEventSourcedSpec.scala} | 61 +++++++++++-----------
8 files changed, 120 insertions(+), 119 deletions(-)
diff --git
a/cluster-sharding-typed/src/test/java/jdocs/org/apache/pekko/cluster/sharding/typed/AccountExampleUnpersistentDocTest.java
b/cluster-sharding-typed/src/test/java/jdocs/org/apache/pekko/cluster/sharding/typed/AccountExamplePersistenceProbeDocTest.java
similarity index 71%
rename from
cluster-sharding-typed/src/test/java/jdocs/org/apache/pekko/cluster/sharding/typed/AccountExampleUnpersistentDocTest.java
rename to
cluster-sharding-typed/src/test/java/jdocs/org/apache/pekko/cluster/sharding/typed/AccountExamplePersistenceProbeDocTest.java
index 759408f65e..5687d6691c 100644
---
a/cluster-sharding-typed/src/test/java/jdocs/org/apache/pekko/cluster/sharding/typed/AccountExampleUnpersistentDocTest.java
+++
b/cluster-sharding-typed/src/test/java/jdocs/org/apache/pekko/cluster/sharding/typed/AccountExamplePersistenceProbeDocTest.java
@@ -25,32 +25,32 @@ import java.math.BigDecimal;
import org.apache.pekko.actor.testkit.typed.javadsl.BehaviorTestKit;
import org.apache.pekko.actor.testkit.typed.javadsl.ReplyInbox;
import org.apache.pekko.actor.testkit.typed.javadsl.StatusReplyInbox;
-import org.apache.pekko.persistence.testkit.javadsl.UnpersistentBehavior;
+import org.apache.pekko.persistence.testkit.javadsl.PersistenceProbeBehavior;
import org.apache.pekko.persistence.testkit.javadsl.PersistenceEffect;
import org.apache.pekko.persistence.typed.PersistenceId;
import org.junit.Test;
-public class AccountExampleUnpersistentDocTest
+public class AccountExamplePersistenceProbeDocTest
// #test
extends JUnitSuite
// #test
{
@Test
public void createWithEmptyBalance() {
- UnpersistentBehavior<AccountEntity.Command, AccountEntity.Event,
AccountEntity.Account>
- unpersistent = emptyAccount();
+ PersistenceProbeBehavior<AccountEntity.Command, AccountEntity.Event,
AccountEntity.Account>
+ persistenceProbe = emptyAccount();
- BehaviorTestKit<AccountEntity.Command> testkit =
unpersistent.getBehaviorTestKit();
+ BehaviorTestKit<AccountEntity.Command> testkit =
persistenceProbe.getBehaviorTestKit();
StatusReplyInbox<Done> ackInbox =
testkit.runAskWithStatus(AccountEntity.CreateAccount::new);
ackInbox.expectValue(Done.getInstance());
-
unpersistent.getEventProbe().expectPersisted(AccountEntity.AccountCreated.INSTANCE);
+
persistenceProbe.getEventProbe().expectPersisted(AccountEntity.AccountCreated.INSTANCE);
// internal state is only exposed by the behavior via responses to
messages or if it happens
// to snapshot. This particular behavior never snapshots, so we
query within the actor's
// protocol
- assertFalse(unpersistent.getSnapshotProbe().hasEffects());
+ assertFalse(persistenceProbe.getSnapshotProbe().hasEffects());
ReplyInbox<AccountEntity.CurrentBalance> currentBalanceInbox =
testkit.runAsk(AccountEntity.GetBalance::new);
@@ -60,10 +60,10 @@ public class AccountExampleUnpersistentDocTest
@Test
public void handleDepositAndWithdraw() {
- UnpersistentBehavior<AccountEntity.Command, AccountEntity.Event,
AccountEntity.Account>
- unpersistent = openedAccount();
+ PersistenceProbeBehavior<AccountEntity.Command, AccountEntity.Event,
AccountEntity.Account>
+ persistenceProbe = openedAccount();
- BehaviorTestKit<AccountEntity.Command> testkit =
unpersistent.getBehaviorTestKit();
+ BehaviorTestKit<AccountEntity.Command> testkit =
persistenceProbe.getBehaviorTestKit();
BigDecimal currentBalance;
testkit
@@ -73,7 +73,7 @@ public class AccountExampleUnpersistentDocTest
assertEquals(
BigDecimal.valueOf(100),
- unpersistent
+ persistenceProbe
.getEventProbe()
.expectPersistedClass(AccountEntity.Deposited.class)
.persistedObject()
@@ -94,7 +94,7 @@ public class AccountExampleUnpersistentDocTest
// can save the persistence effect for in-depth inspection
PersistenceEffect<AccountEntity.Withdrawn> withdrawEffect =
-
unpersistent.getEventProbe().expectPersistedClass(AccountEntity.Withdrawn.class);
+
persistenceProbe.getEventProbe().expectPersistedClass(AccountEntity.Withdrawn.class);
assertEquals(BigDecimal.valueOf(10),
withdrawEffect.persistedObject().amount);
assertEquals(3L, withdrawEffect.sequenceNr());
assertTrue(withdrawEffect.tags().isEmpty());
@@ -110,48 +110,48 @@ public class AccountExampleUnpersistentDocTest
@Test
public void rejectWithdrawOverdraft() {
- UnpersistentBehavior<AccountEntity.Command, AccountEntity.Event,
AccountEntity.Account>
- unpersistent = accountWithBalance(BigDecimal.valueOf(100));
+ PersistenceProbeBehavior<AccountEntity.Command, AccountEntity.Event,
AccountEntity.Account>
+ persistenceProbe = accountWithBalance(BigDecimal.valueOf(100));
- BehaviorTestKit<AccountEntity.Command> testkit =
unpersistent.getBehaviorTestKit();
+ BehaviorTestKit<AccountEntity.Command> testkit =
persistenceProbe.getBehaviorTestKit();
testkit
.runAskWithStatus(
Done.class, replyTo -> new
AccountEntity.Withdraw(BigDecimal.valueOf(110), replyTo))
.expectErrorMessage("not enough funds to withdraw 110");
- assertFalse(unpersistent.getEventProbe().hasEffects());
+ assertFalse(persistenceProbe.getEventProbe().hasEffects());
}
// #test
- private UnpersistentBehavior<AccountEntity.Command, AccountEntity.Event,
AccountEntity.Account>
+ private PersistenceProbeBehavior<AccountEntity.Command,
AccountEntity.Event, AccountEntity.Account>
emptyAccount() {
return
- // #unpersistent-behavior
- UnpersistentBehavior.fromEventSourced(
+ // #persistenceProbe-behavior
+ PersistenceProbeBehavior.fromEventSourced(
AccountEntity.create("1", PersistenceId.of("Account", "1")),
null, // use the initial state
0 // initial sequence number
);
- // #unpersistent-behavior
+ // #persistenceProbe-behavior
}
- private UnpersistentBehavior<AccountEntity.Command, AccountEntity.Event,
AccountEntity.Account>
+ private PersistenceProbeBehavior<AccountEntity.Command,
AccountEntity.Event, AccountEntity.Account>
openedAccount() {
return
- // #unpersistent-behavior-provided-state
- UnpersistentBehavior.fromEventSourced(
+ // #persistenceProbe-behavior-provided-state
+ PersistenceProbeBehavior.fromEventSourced(
AccountEntity.create("1", PersistenceId.of("Account", "1")),
new AccountEntity.EmptyAccount()
.openedAccount(), // duplicate the event handler for
AccountCreated on an EmptyAccount
1 // assume that CreateAccount was the first command
);
- // #unpersistent-behavior-provided-state
+ // #persistenceProbe-behavior-provided-state
}
- private UnpersistentBehavior<AccountEntity.Command, AccountEntity.Event,
AccountEntity.Account>
+ private PersistenceProbeBehavior<AccountEntity.Command,
AccountEntity.Event, AccountEntity.Account>
accountWithBalance(BigDecimal balance) {
- return UnpersistentBehavior.fromEventSourced(
+ return PersistenceProbeBehavior.fromEventSourced(
AccountEntity.create("1", PersistenceId.of("Account", "1")),
new AccountEntity.OpenedAccount(balance),
2);
diff --git
a/cluster-sharding-typed/src/test/scala/docs/org/apache/pekko/cluster/sharding/typed/AccountExampleUnpersistentDocSpec.scala
b/cluster-sharding-typed/src/test/scala/docs/org/apache/pekko/cluster/sharding/typed/AccountExamplePersistenceProbeDocSpec.scala
similarity index 79%
rename from
cluster-sharding-typed/src/test/scala/docs/org/apache/pekko/cluster/sharding/typed/AccountExampleUnpersistentDocSpec.scala
rename to
cluster-sharding-typed/src/test/scala/docs/org/apache/pekko/cluster/sharding/typed/AccountExamplePersistenceProbeDocSpec.scala
index 865e936a50..d0ab11fa4c 100644
---
a/cluster-sharding-typed/src/test/scala/docs/org/apache/pekko/cluster/sharding/typed/AccountExampleUnpersistentDocSpec.scala
+++
b/cluster-sharding-typed/src/test/scala/docs/org/apache/pekko/cluster/sharding/typed/AccountExamplePersistenceProbeDocSpec.scala
@@ -19,10 +19,10 @@ import org.scalatest.matchers.should.Matchers
import org.scalatest.wordspec.AnyWordSpecLike
// #test
-import pekko.persistence.testkit.scaladsl.UnpersistentBehavior
+import pekko.persistence.testkit.scaladsl.PersistenceProbeBehavior
import pekko.persistence.typed.PersistenceId
-class AccountExampleUnpersistentDocSpec
+class AccountExamplePersistenceProbeDocSpec
extends AnyWordSpecLike
// #test
with Matchers
@@ -71,25 +71,25 @@ class AccountExampleUnpersistentDocSpec
}
// #test
- // #unpersistent-behavior
+ // #persistenceProbe-behavior
private def onAnEmptyAccount
- : UnpersistentBehavior.EventSourced[AccountEntity.Command,
AccountEntity.Event, AccountEntity.Account] =
- UnpersistentBehavior.fromEventSourced(AccountEntity("1",
PersistenceId("Account", "1")))
- // #unpersistent-behavior
+ : PersistenceProbeBehavior.EventSourced[AccountEntity.Command,
AccountEntity.Event, AccountEntity.Account] =
+ PersistenceProbeBehavior.fromEventSourced(AccountEntity("1",
PersistenceId("Account", "1")))
+ // #persistenceProbe-behavior
- // #unpersistent-behavior-provided-state
+ // #persistenceProbe-behavior-provided-state
private def onAnOpenedAccount
- : UnpersistentBehavior.EventSourced[AccountEntity.Command,
AccountEntity.Event, AccountEntity.Account] =
- UnpersistentBehavior.fromEventSourced(
+ : PersistenceProbeBehavior.EventSourced[AccountEntity.Command,
AccountEntity.Event, AccountEntity.Account] =
+ PersistenceProbeBehavior.fromEventSourced(
AccountEntity("1", PersistenceId("Account", "1")),
Some(
AccountEntity.EmptyAccount.applyEvent(AccountEntity.AccountCreated) ->
// reuse the event handler
1L // assume that CreateAccount was the first command
))
- // #unpersistent-behavior-provided-state
+ // #persistenceProbe-behavior-provided-state
private def onAnAccountWithBalance(balance: BigDecimal) =
- UnpersistentBehavior.fromEventSourced(
+ PersistenceProbeBehavior.fromEventSourced(
AccountEntity("1", PersistenceId("Account", "1")),
Some(AccountEntity.OpenedAccount(balance) -> 2L))
// #test
diff --git a/docs/src/main/paradox/typed/persistence-testing.md
b/docs/src/main/paradox/typed/persistence-testing.md
index 12eea0336f..17ecd576f4 100644
--- a/docs/src/main/paradox/typed/persistence-testing.md
+++ b/docs/src/main/paradox/typed/persistence-testing.md
@@ -21,28 +21,28 @@ To use Pekko Persistence TestKit, add the module to your
project:
## Unit testing with the BehaviorTestKit
-**Note!** The `UnpersistentBehavior` is a new feature: the API may have
changes breaking source compatibility in future versions.
+**Note!** The `PersistenceProbeBehavior` is a new feature: the API may have
changes breaking source compatibility in future versions.
-Unit testing of `EventSourcedBehavior` can be performed by converting it into
an @apidoc[UnpersistentBehavior]. Instead of
-persisting events and snapshots, the `UnpersistentBehavior` exposes
@apidoc[PersistenceProbe]s for events and snapshots which
+Unit testing of `EventSourcedBehavior` can be performed by converting it into
an @apidoc[PersistenceProbeBehavior]. Instead of
+persisting events and snapshots, the `PersistenceProbeBehavior` exposes
@apidoc[PersistenceProbe]s for events and snapshots which
can be asserted on.
Scala
-: @@snip
[AccountExampleUnpersistentDocSpec.scala](/cluster-sharding-typed/src/test/scala/docs/org/apache/pekko/cluster/sharding/typed/AccountExampleUnpersistentDocSpec.scala)
{ #unpersistent-behavior }
+: @@snip
[AccountExamplePersistenceProbeDocSpec.scala](/cluster-sharding-typed/src/test/scala/docs/org/apache/pekko/cluster/sharding/typed/AccountExamplePersistenceProbeDocSpec.scala)
{ #persistenceProbe-behavior }
Java
-: @@snip
[AccountExampleUnpersistentDocTest.java](/cluster-sharding-typed/src/test/java/jdocs/org/apache/pekko/cluster/sharding/typed/AccountExampleUnpersistentDocTest.java)
{ #unpersistent-behavior }
+: @@snip
[AccountExamplePersistenceProbeDocTest.java](/cluster-sharding-typed/src/test/java/jdocs/org/apache/pekko/cluster/sharding/typed/AccountExamplePersistenceProbeDocTest.java)
{ #persistenceProbe-behavior }
-The `UnpersistentBehavior` can be initialized with arbitrary states:
+The `PersistenceProbeBehavior` can be initialized with arbitrary states:
Scala
-: @@snip
[AccountExampleUnpersistentDocSpec.scala](/cluster-sharding-typed/src/test/scala/docs/org/apache/pekko/cluster/sharding/typed/AccountExampleUnpersistentDocSpec.scala)
{ #unpersistent-behavior-provided-state }
+: @@snip
[AccountExamplePersistenceProbeDocSpec.scala](/cluster-sharding-typed/src/test/scala/docs/org/apache/pekko/cluster/sharding/typed/AccountExamplePersistenceProbeDocSpec.scala)
{ #persistenceProbe-behavior-provided-state }
Java
-: @@snip
[AccountExampleUnpersistentDocTest.java](/cluster-sharding-typed/src/test/java/jdocs/org/apache/pekko/cluster/sharding/typed/AccountExampleUnpersistentDocTest.java)
{ #unpersistent-behavior-provided-state }
+: @@snip
[AccountExamplePersistenceProbeDocTest.java](/cluster-sharding-typed/src/test/java/jdocs/org/apache/pekko/cluster/sharding/typed/AccountExamplePersistenceProbeDocTest.java)
{ #persistenceProbe-behavior-provided-state }
-The `UnpersistentBehavior` is especially well-suited to the synchronous
@ref:[`BehaviorTestKit`](testing-sync.md#synchronous-behavior-testing):
-the `UnpersistentBehavior` can directly construct a `BehaviorTestKit` wrapping
the behavior. When commands are run by `BehaviorTestKit`,
+The `PersistenceProbeBehavior` is especially well-suited to the synchronous
@ref:[`BehaviorTestKit`](testing-sync.md#synchronous-behavior-testing):
+the `PersistenceProbeBehavior` can directly construct a `BehaviorTestKit`
wrapping the behavior. When commands are run by `BehaviorTestKit`,
they are processed in the calling thread (viz. the test suite), so when the
run returns, the suite can be sure that the message has been
fully processed. The internal state of the `EventSourcedBehavior` is not
exposed to the suite except to the extent that it affects how
the behavior responds to commands or the events it persists (in addition, any
snapshots made by the behavior are available through a
@@ -51,12 +51,12 @@ the behavior responds to commands or the events it persists
(in addition, any sn
A full test for the `AccountEntity`, which is shown in the @ref:[Persistence
Style Guide](persistence-style.md) might look like:
Scala
-: @@snip
[AccountExampleUnpersistentDocSpec.scala](/cluster-sharding-typed/src/test/scala/docs/org/apache/pekko/cluster/sharding/typed/AccountExampleUnpersistentDocSpec.scala)
{ #test }
+: @@snip
[AccountExamplePersistenceProbeDocSpec.scala](/cluster-sharding-typed/src/test/scala/docs/org/apache/pekko/cluster/sharding/typed/AccountExamplePersistenceProbeDocSpec.scala)
{ #test }
Java
-: @@snip
[AccountExampleUnpersistentDocTest.java](/cluster-sharding-typed/src/test/java/jdocs/org/apache/pekko/cluster/sharding/typed/AccountExampleUnpersistentDocTest.java)
{ #test }
+: @@snip
[AccountExamplePersistenceProbeDocTest.java](/cluster-sharding-typed/src/test/java/jdocs/org/apache/pekko/cluster/sharding/typed/AccountExamplePersistenceProbeDocTest.java)
{ #test }
-`UnpersistentBehavior` does not require any configuration. It therefore does
not verify the serialization of commands, events, or state.
+`PersistenceProbeBehavior` does not require any configuration. It therefore
does not verify the serialization of commands, events, or state.
If using this style, it is advised to independently test serialization for
those classes.
## Unit testing with the the ActorTestKit and EventSourcedBehaviorTestKit
diff --git
a/persistence-testkit/src/main/scala/org/apache/pekko/persistence/testkit/internal/Unpersistent.scala
b/persistence-testkit/src/main/scala/org/apache/pekko/persistence/testkit/internal/PersistenceProbeImpl.scala
similarity index 99%
rename from
persistence-testkit/src/main/scala/org/apache/pekko/persistence/testkit/internal/Unpersistent.scala
rename to
persistence-testkit/src/main/scala/org/apache/pekko/persistence/testkit/internal/PersistenceProbeImpl.scala
index 18204b4132..dbe95098b1 100644
---
a/persistence-testkit/src/main/scala/org/apache/pekko/persistence/testkit/internal/Unpersistent.scala
+++
b/persistence-testkit/src/main/scala/org/apache/pekko/persistence/testkit/internal/PersistenceProbeImpl.scala
@@ -37,7 +37,7 @@ import pekko.util.ConstantFun.{ scalaAnyToUnit => doNothing }
* INTERNAL API
*/
@InternalApi
-private[pekko] object Unpersistent {
+private[pekko] object PersistenceProbeImpl {
def eventSourced[Command, Event, State](behavior: Behavior[Command],
fromStateAndSequenceNr: Option[(State, Long)])(
onEvent: (Event, Long, Set[String]) => Unit)(onSnapshot: (State, Long)
=> Unit): Behavior[Command] = {
diff --git
a/persistence-testkit/src/main/scala/org/apache/pekko/persistence/testkit/javadsl/UnpersistentBehavior.scala
b/persistence-testkit/src/main/scala/org/apache/pekko/persistence/testkit/javadsl/PersistenceProbeBehavior.scala
similarity index 80%
rename from
persistence-testkit/src/main/scala/org/apache/pekko/persistence/testkit/javadsl/UnpersistentBehavior.scala
rename to
persistence-testkit/src/main/scala/org/apache/pekko/persistence/testkit/javadsl/PersistenceProbeBehavior.scala
index 71c78195fc..e6374533e7 100644
---
a/persistence-testkit/src/main/scala/org/apache/pekko/persistence/testkit/javadsl/UnpersistentBehavior.scala
+++
b/persistence-testkit/src/main/scala/org/apache/pekko/persistence/testkit/javadsl/PersistenceProbeBehavior.scala
@@ -21,14 +21,14 @@ import org.apache.pekko
import pekko.actor.testkit.typed.javadsl.BehaviorTestKit
import pekko.actor.typed.Behavior
import pekko.annotation.DoNotInherit
-import pekko.persistence.testkit.internal.{ PersistenceProbeImpl, Unpersistent
}
+import pekko.persistence.testkit.internal.PersistenceProbeImpl
/**
- * Factory methods to create UnpersistentBehavior instances for testing.
+ * Factory methods to create PersistenceProbeBehavior instances for testing.
*
* @since 1.3.0
*/
-object UnpersistentBehavior {
+object PersistenceProbeBehavior {
/**
* Given an EventSourcedBehavior, produce a non-persistent Behavior which
synchronously publishes events and snapshots
@@ -39,15 +39,15 @@ object UnpersistentBehavior {
* The returned Behavior does not intrinsically depend on configuration: it
therefore does not serialize and
* assumes an unbounded stash for commands.
*
- * @param behavior a (possibly wrapped) EventSourcedBehavior to serve as
the basis for the unpersistent behavior
- * @param initialState start the unpersistent behavior with this state; if
null, behavior's initialState will be used
- * @param initialSequenceNr start the unpersistent behavior with this
sequence number; only applies if initialState is non-null
- * @return an UnpersistentBehavior based on an EventSourcedBehavior
+ * @param behavior a (possibly wrapped) EventSourcedBehavior to serve as
the basis for the persistenceProbe behavior
+ * @param initialState start the persistenceProbe behavior with this state;
if null, behavior's initialState will be used
+ * @param initialSequenceNr start the persistenceProbe behavior with this
sequence number; only applies if initialState is non-null
+ * @return an PersistenceProbeBehavior based on an EventSourcedBehavior
*/
def fromEventSourced[Command, Event, State](
behavior: Behavior[Command],
initialState: State,
- initialSequenceNr: Long): UnpersistentBehavior[Command, Event, State] = {
+ initialSequenceNr: Long): PersistenceProbeBehavior[Command, Event,
State] = {
require(initialSequenceNr >= 0, "initialSequenceNr must be at least zero")
val initialStateAndSequenceNr = Option(initialState).map(_ ->
initialSequenceNr)
@@ -55,33 +55,33 @@ object UnpersistentBehavior {
val snapshotProbe = new PersistenceProbeImpl[State]
val b =
- Unpersistent.eventSourced(behavior, initialStateAndSequenceNr) {
+ PersistenceProbeImpl.eventSourced(behavior, initialStateAndSequenceNr) {
(event: Event, sequenceNr: Long, tags: ScalaSet[String]) =>
eventProbe.persist((event, sequenceNr, tags))
} { (snapshot, sequenceNr) =>
snapshotProbe.persist((snapshot, sequenceNr, ScalaSet.empty))
}
- new UnpersistentBehavior(b, eventProbe.asJava, snapshotProbe.asJava)
+ new PersistenceProbeBehavior(b, eventProbe.asJava, snapshotProbe.asJava)
}
def fromEventSourced[Command, Event, State](
- behavior: Behavior[Command]): UnpersistentBehavior[Command, Event,
State] =
+ behavior: Behavior[Command]): PersistenceProbeBehavior[Command, Event,
State] =
fromEventSourced(behavior, null.asInstanceOf[State], 0)
def fromDurableState[Command, State](
behavior: Behavior[Command],
- initialState: State): UnpersistentBehavior[Command, Void, State] = {
+ initialState: State): PersistenceProbeBehavior[Command, Void, State] = {
val probe = new PersistenceProbeImpl[State]
val b =
- Unpersistent.durableState(behavior, Option(initialState)) { (state,
version, tag) =>
+ PersistenceProbeImpl.durableState(behavior, Option(initialState)) {
(state, version, tag) =>
probe.persist((state, version, if (tag == "") ScalaSet.empty else
ScalaSet(tag)))
}
- new UnpersistentBehavior(b, noEventProbe, probe.asJava)
+ new PersistenceProbeBehavior(b, noEventProbe, probe.asJava)
}
- def fromDurableState[Command, State](behavior: Behavior[Command]):
UnpersistentBehavior[Command, Void, State] =
+ def fromDurableState[Command, State](behavior: Behavior[Command]):
PersistenceProbeBehavior[Command, Void, State] =
fromDurableState(behavior, null.asInstanceOf[State])
private val noEventProbe: PersistenceProbe[Void] =
@@ -101,7 +101,7 @@ object UnpersistentBehavior {
}
}
-final class UnpersistentBehavior[Command, Event, State] private (
+final class PersistenceProbeBehavior[Command, Event, State] private (
behavior: Behavior[Command],
eventProbe: PersistenceProbe[Event],
stateProbe: PersistenceProbe[State]) {
diff --git
a/persistence-testkit/src/main/scala/org/apache/pekko/persistence/testkit/scaladsl/UnpersistentBehavior.scala
b/persistence-testkit/src/main/scala/org/apache/pekko/persistence/testkit/scaladsl/PersistenceProbeBehavior.scala
similarity index 90%
rename from
persistence-testkit/src/main/scala/org/apache/pekko/persistence/testkit/scaladsl/UnpersistentBehavior.scala
rename to
persistence-testkit/src/main/scala/org/apache/pekko/persistence/testkit/scaladsl/PersistenceProbeBehavior.scala
index 72405f0e27..bf02b70f35 100644
---
a/persistence-testkit/src/main/scala/org/apache/pekko/persistence/testkit/scaladsl/UnpersistentBehavior.scala
+++
b/persistence-testkit/src/main/scala/org/apache/pekko/persistence/testkit/scaladsl/PersistenceProbeBehavior.scala
@@ -19,9 +19,9 @@ import org.apache.pekko
import pekko.actor.testkit.typed.scaladsl.BehaviorTestKit
import pekko.actor.typed.Behavior
import pekko.annotation.DoNotInherit
-import pekko.persistence.testkit.internal.{ PersistenceProbeImpl, Unpersistent
}
+import pekko.persistence.testkit.internal.PersistenceProbeImpl
-sealed trait UnpersistentBehavior[Command, State] {
+sealed trait PersistenceProbeBehavior[Command, State] {
val behavior: Behavior[Command]
lazy val behaviorTestKit = BehaviorTestKit(behavior)
@@ -29,11 +29,11 @@ sealed trait UnpersistentBehavior[Command, State] {
}
/**
- * Factory methods to create UnpersistentBehavior instances for testing.
+ * Factory methods to create PersistenceProbeBehavior instances for testing.
*
* @since 1.3.0
*/
-object UnpersistentBehavior {
+object PersistenceProbeBehavior {
/**
* Given an EventSourcedBehavior, produce a non-persistent Behavior which
synchronously publishes events and snapshots
@@ -50,7 +50,7 @@ object UnpersistentBehavior {
val eventProbe = new PersistenceProbeImpl[Event]
val snapshotProbe = new PersistenceProbeImpl[State]
val resultingBehavior =
- Unpersistent.eventSourced(behavior, initialStateAndSequenceNr) {
+ PersistenceProbeImpl.eventSourced(behavior, initialStateAndSequenceNr) {
(event: Event, sequenceNr: Long, tags: Set[String]) =>
eventProbe.persist((event, sequenceNr, tags))
} { (snapshot, sequenceNr) =>
@@ -71,7 +71,7 @@ object UnpersistentBehavior {
val probe = new PersistenceProbeImpl[State]
val resultingBehavior =
- Unpersistent.durableState(behavior, initialState) { (state, version,
tag) =>
+ PersistenceProbeImpl.durableState(behavior, initialState) { (state,
version, tag) =>
probe.persist((state, version, if (tag.isEmpty) Set.empty else
Set(tag)))
}
@@ -82,7 +82,7 @@ object UnpersistentBehavior {
override val behavior: Behavior[Command],
val eventProbe: PersistenceProbe[Event],
override val stateProbe: PersistenceProbe[State])
- extends UnpersistentBehavior[Command, State] {
+ extends PersistenceProbeBehavior[Command, State] {
def apply(f: (BehaviorTestKit[Command], PersistenceProbe[Event],
PersistenceProbe[State]) => Unit): Unit =
f(behaviorTestKit, eventProbe, stateProbe)
@@ -92,7 +92,7 @@ object UnpersistentBehavior {
final case class DurableState[Command, State](
override val behavior: Behavior[Command],
override val stateProbe: PersistenceProbe[State])
- extends UnpersistentBehavior[Command, State] {
+ extends PersistenceProbeBehavior[Command, State] {
def apply(f: (BehaviorTestKit[Command], PersistenceProbe[State]) => Unit):
Unit =
f(behaviorTestKit, stateProbe)
}
diff --git
a/persistence-testkit/src/test/scala/org/apache/pekko/persistence/testkit/scaladsl/UnpersistentDurableStateSpec.scala
b/persistence-testkit/src/test/scala/org/apache/pekko/persistence/testkit/scaladsl/PersistenceProbeDurableStateSpec.scala
similarity index 89%
rename from
persistence-testkit/src/test/scala/org/apache/pekko/persistence/testkit/scaladsl/UnpersistentDurableStateSpec.scala
rename to
persistence-testkit/src/test/scala/org/apache/pekko/persistence/testkit/scaladsl/PersistenceProbeDurableStateSpec.scala
index 93aac5562b..c20f447290 100644
---
a/persistence-testkit/src/test/scala/org/apache/pekko/persistence/testkit/scaladsl/UnpersistentDurableStateSpec.scala
+++
b/persistence-testkit/src/test/scala/org/apache/pekko/persistence/testkit/scaladsl/PersistenceProbeDurableStateSpec.scala
@@ -24,7 +24,7 @@ import pekko.persistence.typed.state.scaladsl._
import org.scalatest.matchers.should.Matchers
import org.scalatest.wordspec.AnyWordSpec
-object UnpersistentDurableStateSpec {
+object PersistenceProbeDurableStateSpec {
object BehaviorUnderTest {
sealed trait Command
@@ -136,14 +136,14 @@ object UnpersistentDurableStateSpec {
}
}
-class UnpersistentDurableStateSpec extends AnyWordSpec with Matchers {
- import UnpersistentDurableStateSpec._
+class PersistenceProbeDurableStateSpec extends AnyWordSpec with Matchers {
+ import PersistenceProbeDurableStateSpec._
import pekko.actor.testkit.typed.scaladsl._
import org.slf4j.event.Level
- "Unpersistent DurableStateBehavior" must {
+ "PersistenceProbe DurableStateBehavior" must {
"generate a fail-fast behavior from a non-DurableStateBehavior" in {
val notDurableState =
Behaviors.receive[Any] { (context, msg) =>
@@ -151,9 +151,9 @@ class UnpersistentDurableStateSpec extends AnyWordSpec with
Matchers {
Behaviors.same
}
- val unpersistent = UnpersistentBehavior.fromDurableState[Any,
Any](notDurableState)
- an[AssertionError] shouldBe thrownBy { unpersistent.behaviorTestKit }
- assert(!unpersistent.stateProbe.hasEffects, "should be no persistence
effects")
+ val persistenceProbe = PersistenceProbeBehavior.fromDurableState[Any,
Any](notDurableState)
+ an[AssertionError] shouldBe thrownBy { persistenceProbe.behaviorTestKit }
+ assert(!persistenceProbe.stateProbe.hasEffects, "should be no
persistence effects")
}
"generate a Behavior from a DurableStateBehavior and process
RecoveryCompleted" in {
@@ -163,9 +163,9 @@ class UnpersistentDurableStateSpec extends AnyWordSpec with
Matchers {
val behavior = BehaviorUnderTest("test-1", recoveryDone.ref)
// accessor-style API
- val unpersistent = UnpersistentBehavior.fromDurableState[Command,
State](behavior)
- val probe = unpersistent.stateProbe
- val testkit = unpersistent.behaviorTestKit
+ val persistenceProbe =
PersistenceProbeBehavior.fromDurableState[Command, State](behavior)
+ val probe = persistenceProbe.stateProbe
+ val testkit = persistenceProbe.behaviorTestKit
assert(!probe.hasEffects, "should not be persistence yet")
recoveryDone.expectMessage(Done)
@@ -182,7 +182,7 @@ class UnpersistentDurableStateSpec extends AnyWordSpec with
Matchers {
val replyTo = TestInbox[Done]()
// and the more functional-style API
- UnpersistentBehavior.fromDurableState[Command, State](behavior) {
(testkit, probe) =>
+ PersistenceProbeBehavior.fromDurableState[Command, State](behavior) {
(testkit, probe) =>
testkit.run(Add(1, replyTo.ref))
replyTo.expectMessage(Done)
probe.expectPersisted(State(1, Map.empty, Int.MaxValue), tag = "count")
@@ -197,7 +197,7 @@ class UnpersistentDurableStateSpec extends AnyWordSpec with
Matchers {
val notify3 = TestInbox[Done]()
val initialState = State(1, Map(3 -> notify3.ref), 3)
- UnpersistentBehavior.fromDurableState[Command, State](behavior,
Some(initialState)) { (testkit, probe) =>
+ PersistenceProbeBehavior.fromDurableState[Command, State](behavior,
Some(initialState)) { (testkit, probe) =>
val logs = testkit.logEntries()
logs.size shouldBe 1
@@ -230,7 +230,7 @@ class UnpersistentDurableStateSpec extends AnyWordSpec with
Matchers {
val replyTo1 = TestInbox[Done]()
val add = Add(1, TestInbox[Done]().ref)
- UnpersistentBehavior.fromDurableState[Command, State](behavior) {
(testkit, probe) =>
+ PersistenceProbeBehavior.fromDurableState[Command, State](behavior) {
(testkit, probe) =>
// stashes
testkit.run(AddWhenAtLeast(1, 1, replyTo1.ref))
assert(!probe.hasEffects, "should be no persistence effect")
@@ -254,7 +254,7 @@ class UnpersistentDurableStateSpec extends AnyWordSpec with
Matchers {
val behavior = BehaviorUnderTest("test-1", TestInbox[Done]().ref)
val replyTo = TestInbox[Long]()
- UnpersistentBehavior.fromDurableState[Command, State](behavior) {
(testkit, probe) =>
+ PersistenceProbeBehavior.fromDurableState[Command, State](behavior) {
(testkit, probe) =>
testkit.run(GetRevisionNumber(replyTo.ref))
(the[AssertionError] thrownBy (probe.extract())).getMessage shouldBe
"No persistence effects in probe"
replyTo.expectMessage(0)
diff --git
a/persistence-testkit/src/test/scala/org/apache/pekko/persistence/testkit/scaladsl/UnpersistentEventSourcedSpec.scala
b/persistence-testkit/src/test/scala/org/apache/pekko/persistence/testkit/scaladsl/PersistenceProbeEventSourcedSpec.scala
similarity index 84%
rename from
persistence-testkit/src/test/scala/org/apache/pekko/persistence/testkit/scaladsl/UnpersistentEventSourcedSpec.scala
rename to
persistence-testkit/src/test/scala/org/apache/pekko/persistence/testkit/scaladsl/PersistenceProbeEventSourcedSpec.scala
index 192d9a1da0..781750aef3 100644
---
a/persistence-testkit/src/test/scala/org/apache/pekko/persistence/testkit/scaladsl/UnpersistentEventSourcedSpec.scala
+++
b/persistence-testkit/src/test/scala/org/apache/pekko/persistence/testkit/scaladsl/PersistenceProbeEventSourcedSpec.scala
@@ -23,7 +23,7 @@ import pekko.persistence.typed.scaladsl._
import org.scalatest.matchers.should.Matchers
import org.scalatest.wordspec.AnyWordSpec
-object UnpersistentEventSourcedSpec {
+object PersistenceProbeEventSourcedSpec {
object BehaviorUnderTest {
sealed trait Command
@@ -154,14 +154,14 @@ object UnpersistentEventSourcedSpec {
}
}
-class UnpersistentEventSourcedSpec extends AnyWordSpec with Matchers {
- import UnpersistentEventSourcedSpec._
+class PersistenceProbeEventSourcedSpec extends AnyWordSpec with Matchers {
+ import PersistenceProbeEventSourcedSpec._
import pekko.actor.testkit.typed.scaladsl._
import org.slf4j.event.Level
- "Unpersistent EventSourcedBehavior" must {
+ "PersistenceProbe EventSourcedBehavior" must {
"generate a failing behavior from a non-EventSourcedBehavior" in {
val notEventSourced =
Behaviors.receive[Any] { (context, msg) =>
@@ -169,10 +169,10 @@ class UnpersistentEventSourcedSpec extends AnyWordSpec
with Matchers {
Behaviors.same
}
- val unpersistent = UnpersistentBehavior.fromEventSourced[Any, Any,
Any](notEventSourced)
- an[AssertionError] shouldBe thrownBy { unpersistent.behaviorTestKit }
- an[AssertionError] shouldBe thrownBy { unpersistent.eventProbe.extract()
}
- an[AssertionError] shouldBe thrownBy {
unpersistent.snapshotProbe.extract() }
+ val persistenceProbe = PersistenceProbeBehavior.fromEventSourced[Any,
Any, Any](notEventSourced)
+ an[AssertionError] shouldBe thrownBy { persistenceProbe.behaviorTestKit }
+ an[AssertionError] shouldBe thrownBy {
persistenceProbe.eventProbe.extract() }
+ an[AssertionError] shouldBe thrownBy {
persistenceProbe.snapshotProbe.extract() }
}
"generate a Behavior from an EventSourcedBehavior and process
RecoveryCompleted" in {
@@ -182,10 +182,10 @@ class UnpersistentEventSourcedSpec extends AnyWordSpec
with Matchers {
val behavior = BehaviorUnderTest("test-1", recoveryDone.ref)
// accessor API
- val unpersistent = UnpersistentBehavior.fromEventSourced[Command, Event,
State](behavior)
- val testkit = unpersistent.behaviorTestKit
- val eventProbe = unpersistent.eventProbe
- val snapshotProbe = unpersistent.snapshotProbe
+ val persistenceProbe =
PersistenceProbeBehavior.fromEventSourced[Command, Event, State](behavior)
+ val testkit = persistenceProbe.behaviorTestKit
+ val eventProbe = persistenceProbe.eventProbe
+ val snapshotProbe = persistenceProbe.snapshotProbe
assert(!eventProbe.hasEffects, "should not be events")
assert(!snapshotProbe.hasEffects, "should not be snapshots")
@@ -203,24 +203,25 @@ class UnpersistentEventSourcedSpec extends AnyWordSpec
with Matchers {
val replyTo = TestInbox[Done]()
// resource-style API
- UnpersistentBehavior.fromEventSourced[Command, Event, State](behavior) {
(testkit, eventProbe, snapshotProbe) =>
- testkit.clearLog()
+ PersistenceProbeBehavior.fromEventSourced[Command, Event,
State](behavior) {
+ (testkit, eventProbe, snapshotProbe) =>
+ testkit.clearLog()
- testkit.run(PersistDomainEvent(replyTo.ref))
- replyTo.expectMessage(Done)
- eventProbe.expectPersisted(DomainEvent, Set("domain"))
- snapshotProbe.drain() shouldBe empty
- assert(!testkit.hasEffects(), "should have no effects")
- testkit.clearLog()
+ testkit.run(PersistDomainEvent(replyTo.ref))
+ replyTo.expectMessage(Done)
+ eventProbe.expectPersisted(DomainEvent, Set("domain"))
+ snapshotProbe.drain() shouldBe empty
+ assert(!testkit.hasEffects(), "should have no effects")
+ testkit.clearLog()
- testkit.run(SnapshotNow)
- assert(!replyTo.hasMessages, "should not be a reply")
+ testkit.run(SnapshotNow)
+ assert(!replyTo.hasMessages, "should not be a reply")
- val PersistenceEffect(_, seqNr, tags) =
eventProbe.expectPersistedType[SnapshotMade.type]()
- seqNr shouldBe 2
- tags shouldBe empty
+ val PersistenceEffect(_, seqNr, tags) =
eventProbe.expectPersistedType[SnapshotMade.type]()
+ seqNr shouldBe 2
+ tags shouldBe empty
- snapshotProbe.expectPersisted(State(1, Map.empty, Int.MaxValue))
+ snapshotProbe.expectPersisted(State(1, Map.empty, Int.MaxValue))
}
}
@@ -240,7 +241,7 @@ class UnpersistentEventSourcedSpec extends AnyWordSpec with
Matchers {
if (evt == 1) throw new RuntimeException("Kaboom!")
})
- UnpersistentBehavior.fromEventSourced[Int, Int, Unit](behavior) {
(testkit, eventProbe, _) =>
+ PersistenceProbeBehavior.fromEventSourced[Int, Int, Unit](behavior) {
(testkit, eventProbe, _) =>
val oneException = the[RuntimeException] thrownBy testkit.run(1)
oneException.getMessage shouldBe "Kaboom!"
eventProbe.hasEffects shouldBe false
@@ -262,7 +263,7 @@ class UnpersistentEventSourcedSpec extends AnyWordSpec with
Matchers {
Seq(ObserverAdded(3, notify3.ref), SnapshotMade, DomainEvent,
DomainEvent)
.foldLeft(State(0, Map.empty, Int.MaxValue))(applyEvent _)
- UnpersistentBehavior.fromEventSourced[Command, Event, State](behavior,
Some(initialState -> 41L)) {
+ PersistenceProbeBehavior.fromEventSourced[Command, Event,
State](behavior, Some(initialState -> 41L)) {
(testkit, eventProbe, snapshotProbe) =>
recoveryDone.expectMessage(Done)
val logs = testkit.logEntries()
@@ -289,7 +290,7 @@ class UnpersistentEventSourcedSpec extends AnyWordSpec with
Matchers {
val behavior = BehaviorUnderTest("test-1", TestInbox[Done]().ref)
- UnpersistentBehavior.fromEventSourced[Command, Event, State](behavior,
None) {
+ PersistenceProbeBehavior.fromEventSourced[Command, Event,
State](behavior, None) {
(testkit, eventProbe, snapshotProbe) =>
val replyTo1 = TestInbox[Done]()
val pde = PersistDomainEvent(TestInbox[Done]().ref)
@@ -322,7 +323,7 @@ class UnpersistentEventSourcedSpec extends AnyWordSpec with
Matchers {
case x => x
}
- UnpersistentBehavior.fromEventSourced[Command, Event, State](behavior,
+ PersistenceProbeBehavior.fromEventSourced[Command, Event,
State](behavior,
Some(initialState -> randomStartingOffset)) {
(testkit, eventProbe, snapshotProbe) =>
val replyTo = TestInbox[Long]()
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]