Class PersistenceTestKit


  • public class PersistenceTestKit
    extends java.lang.Object
    Class for testing persisted events in persistent actors.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void clearAll()
      Clear all data from storage.
      void clearAllPreservingSeqNumbers()
      Clear all data in storage preserving sequence numbers.
      void clearByIdPreservingSeqNumbers​(java.lang.String persistenceId)
      Clear all data in storage for particular persistence id preserving sequence numbers.
      void clearByPersistenceId​(java.lang.String persistenceId)
      Clear all data from storage for particular persistence id.
      static PersistenceTestKit create​(ActorSystem system)  
      static PersistenceTestKit create​(ActorSystem<?> system)  
      <A> A expectNextPersisted​(java.lang.String persistenceId, A event)
      Check that event has been saved in the storage.
      <A> A expectNextPersisted​(java.lang.String persistenceId, A event, java.time.Duration max)
      Check for max time that event has been saved in the storage.
      <A> A expectNextPersistedClass​(java.lang.String persistenceId, java.lang.Class<A> cla)
      Check that next persisted in storage for particular persistence id event has expected type.
      <A> A expectNextPersistedClass​(java.lang.String persistenceId, java.lang.Class<A> cla, java.time.Duration max)
      Check for max time that next persisted in storage for particular persistence id event has expected type.
      void expectNothingPersisted​(java.lang.String persistenceId)
      Check that nothing has been saved in the storage.
      void expectNothingPersisted​(java.lang.String persistenceId, java.time.Duration max)
      Check for max time that nothing has been saved in the storage.
      void failNextDelete()
      Fail next delete from storage attempt with default exception for any persistence id.
      void failNextDelete​(java.lang.String persistenceId)
      Fail next delete from storage attempt with default exception for particular persistence id.
      void failNextDelete​(java.lang.String persistenceId, java.lang.Throwable cause)
      Fail next delete from storage attempt with cause exception for particular persistence id.
      void failNextDelete​(java.lang.Throwable cause)
      Fail next delete from storage attempt with cause exception for any persistence id.
      void failNextNDeletes​(int n)
      Fail next n delete from storage attempts with default exception for any persistence id.
      void failNextNDeletes​(int n, java.lang.Throwable cause)
      Fail next n delete from storage attempts with cause exception for any persistence id.
      void failNextNDeletes​(java.lang.String persistenceId, int n)
      Fail next n delete from storage attempts with default exception for particular persistence id.
      void failNextNDeletes​(java.lang.String persistenceId, int n, java.lang.Throwable cause)
      Fail next n delete from storage attempts with cause exception for particular persistence id.
      void failNextNOps​(int n)
      Fail n following journal operations regardless of their type.
      void failNextNOps​(int n, java.lang.Throwable cause)
      Fail n following journal operations depending on the condition cond.
      void failNextNOpsCond​(java.util.function.BiFunction<java.lang.String,​JournalOperation,​java.lang.Object> cond, int n)
      Fail n following journal operations depending on the condition cond.
      void failNextNOpsCond​(java.util.function.BiFunction<java.lang.String,​JournalOperation,​java.lang.Object> cond, int n, java.lang.Throwable cause)
      Fail n following journal operations depending on the condition cond.
      void failNextNPersisted​(int n)
      Fail next n write operations with default exception for any persistence id.
      void failNextNPersisted​(int n, java.lang.Throwable cause)
      Fail next n write operations with the cause exception for any persistence id.
      void failNextNPersisted​(java.lang.String persistenceId, int n)
      Fail next n write operations for particular persistence id.
      void failNextNPersisted​(java.lang.String persistenceId, int n, java.lang.Throwable cause)
      Fail next n write operations with the cause exception for particular persistence id.
      void failNextNReads​(int n)
      Fail next n read from storage (recovery) attempts with default exception for any persistence id.
      void failNextNReads​(int n, java.lang.Throwable cause)
      Fail next n read from storage (recovery) attempts with cause exception for any persistence id.
      void failNextNReads​(java.lang.String persistenceId, int n)
      Fail next n read from storage (recovery) attempts with default exception for particular persistence id.
      void failNextNReads​(java.lang.String persistenceId, int n, java.lang.Throwable cause)
      Fail next n read from storage (recovery) attempts with cause exception for particular persistence id.
      void failNextPersisted()
      Fail next write operation with default exception for any persistence id.
      void failNextPersisted​(java.lang.String persistenceId)
      Fail next write operation with default exception for particular persistence id.
      void failNextPersisted​(java.lang.String persistenceId, java.lang.Throwable cause)
      Fail next write operation with cause exception for particular persistence id.
      void failNextPersisted​(java.lang.Throwable cause)
      Fail next write operation event with cause exception for any persistence id.
      void failNextRead()
      Fail next read from storage (recovery) attempt with default exception for any persistence id.
      void failNextRead​(java.lang.String persistenceId)
      Fail next read from storage (recovery) attempt with default exception for any persistence id.
      void failNextRead​(java.lang.String persistenceId, java.lang.Throwable cause)
      Fail next read from storage (recovery) attempt with cause exception for particular persistence id.
      void failNextRead​(java.lang.Throwable cause)
      Fail next read from storage (recovery) attempt with cause exception for any persistence id.
      java.util.List<java.lang.Object> persistedInStorage​(java.lang.String persistenceId)
      Retrieve all events saved in storage by persistence id.
      void persistForRecovery​(java.lang.String persistenceId, java.util.List<java.lang.Object> events)
      Persist events into storage in order.
      <A> java.util.List<A> receivePersisted​(java.lang.String persistenceId, int n, java.lang.Class<A> cla)
      Receive next n events from the storage.
      <A> java.util.List<A> receivePersisted​(java.lang.String persistenceId, int n, java.lang.Class<A> cla, java.time.Duration max)
      Receive for max time next n events from the storage.
      void rejectNextDelete()
      Reject next delete from storage operation for any persistence id with default exception.
      void rejectNextDelete​(java.lang.String persistenceId)
      Reject next delete from storage operations for particular persistence id with default exception.
      void rejectNextDelete​(java.lang.String persistenceId, java.lang.Throwable cause)
      Reject next delete from storage operations for particular persistence id with cause exception.
      void rejectNextDelete​(java.lang.Throwable cause)
      Reject next delete from storage operation for any persistence id with cause exception.
      void rejectNextNDeletes​(int n)
      Reject next n delete from storage operations for any persistence id with default exception.
      void rejectNextNDeletes​(int n, java.lang.Throwable cause)
      Reject next n delete from storage operations for any persistence id with cause exception.
      void rejectNextNDeletes​(java.lang.String persistenceId, int n)
      Reject next n delete from storage operations for particular persistence id with default exception.
      void rejectNextNDeletes​(java.lang.String persistenceId, int n, java.lang.Throwable cause)
      Reject next n delete from storage operations for particular persistence id with cause exception.
      void rejectNextNOps​(int n)
      Reject n following journal operations regardless of their type.
      void rejectNextNOps​(int n, java.lang.Throwable cause)
      Reject n following journal operations regardless of their type.
      void rejectNextNOpsCond​(java.util.function.BiFunction<java.lang.String,​JournalOperation,​java.lang.Object> cond, int n)
      Reject n following journal operations depending on the condition cond.
      void rejectNextNOpsCond​(java.util.function.BiFunction<java.lang.String,​JournalOperation,​java.lang.Object> cond, int n, java.lang.Throwable cause)
      Reject n following journal operations depending on the condition cond.
      void rejectNextNPersisted​(int n)
      Reject next n save in storage operations for any persistence id with default exception.
      void rejectNextNPersisted​(int n, java.lang.Throwable cause)
      Reject next n save in storage operations for any persistence id with cause exception.
      void rejectNextNPersisted​(java.lang.String persistenceId, int n)
      Reject next n save in storage operations for particular persistence id with default exception.
      void rejectNextNPersisted​(java.lang.String persistenceId, int n, java.lang.Throwable cause)
      Reject next n save in storage operations for particular persistence id with cause exception.
      void rejectNextNReads​(int n)
      Reject next n read from storage operations for any persistence id with default exception.
      void rejectNextNReads​(int n, java.lang.Throwable cause)
      Reject next n read from storage operations for any persistence id with cause exception.
      void rejectNextNReads​(java.lang.String persistenceId, int n)
      Reject next n read from storage operations for particular persistence id with default exception.
      void rejectNextNReads​(java.lang.String persistenceId, int n, java.lang.Throwable cause)
      Reject next n read from storage operations for particular persistence id with cause exception.
      void rejectNextPersisted()
      Reject next save in storage operation for any persistence id with default exception.
      void rejectNextPersisted​(java.lang.String persistenceId)
      Reject next save in storage operation for particular persistence id with default exception.
      void rejectNextPersisted​(java.lang.String persistenceId, java.lang.Throwable cause)
      Reject next save in storage operation for particular persistence id with cause exception.
      void rejectNextPersisted​(java.lang.Throwable cause)
      Reject next save in storage operation for any persistence id with cause exception.
      void rejectNextRead()
      Reject next read from storage operation for any persistence id with default exception.
      void rejectNextRead​(java.lang.String persistenceId)
      Reject next read from storage operation for particular persistence id with default exception.
      void rejectNextRead​(java.lang.String persistenceId, java.lang.Throwable cause)
      Reject next read from storage operation for particular persistence id with cause exception.
      void rejectNextRead​(java.lang.Throwable cause)
      Reject next read from storage operation for any persistence id with cause exception.
      void resetPolicy()
      PersistenceTestKit withPolicy​(ProcessingPolicy<JournalOperation> policy)
      Set new processing policy for journal operations.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • PersistenceTestKit

        public PersistenceTestKit​(ActorSystem system)
    • Method Detail

      • expectNothingPersisted

        public void expectNothingPersisted​(java.lang.String persistenceId)
        Check that nothing has been saved in the storage.
      • expectNothingPersisted

        public void expectNothingPersisted​(java.lang.String persistenceId,
                                           java.time.Duration max)
        Check for max time that nothing has been saved in the storage.
      • expectNextPersisted

        public <A> A expectNextPersisted​(java.lang.String persistenceId,
                                         A event)
        Check that event has been saved in the storage.
      • expectNextPersisted

        public <A> A expectNextPersisted​(java.lang.String persistenceId,
                                         A event,
                                         java.time.Duration max)
        Check for max time that event has been saved in the storage.
      • expectNextPersistedClass

        public <A> A expectNextPersistedClass​(java.lang.String persistenceId,
                                              java.lang.Class<A> cla)
        Check that next persisted in storage for particular persistence id event has expected type.
      • expectNextPersistedClass

        public <A> A expectNextPersistedClass​(java.lang.String persistenceId,
                                              java.lang.Class<A> cla,
                                              java.time.Duration max)
        Check for max time that next persisted in storage for particular persistence id event has expected type.
      • failNextNPersisted

        public void failNextNPersisted​(java.lang.String persistenceId,
                                       int n,
                                       java.lang.Throwable cause)
        Fail next n write operations with the cause exception for particular persistence id.
      • failNextNPersisted

        public void failNextNPersisted​(java.lang.String persistenceId,
                                       int n)
        Fail next n write operations for particular persistence id.
      • failNextNPersisted

        public void failNextNPersisted​(int n,
                                       java.lang.Throwable cause)
        Fail next n write operations with the cause exception for any persistence id.
      • failNextNPersisted

        public void failNextNPersisted​(int n)
        Fail next n write operations with default exception for any persistence id.
      • failNextPersisted

        public void failNextPersisted​(java.lang.String persistenceId,
                                      java.lang.Throwable cause)
        Fail next write operation with cause exception for particular persistence id.
      • failNextPersisted

        public void failNextPersisted​(java.lang.String persistenceId)
        Fail next write operation with default exception for particular persistence id.
      • failNextPersisted

        public void failNextPersisted​(java.lang.Throwable cause)
        Fail next write operation event with cause exception for any persistence id.
      • failNextPersisted

        public void failNextPersisted()
        Fail next write operation with default exception for any persistence id.
      • failNextRead

        public void failNextRead​(java.lang.Throwable cause)
        Fail next read from storage (recovery) attempt with cause exception for any persistence id.
      • failNextRead

        public void failNextRead()
        Fail next read from storage (recovery) attempt with default exception for any persistence id.
      • failNextRead

        public void failNextRead​(java.lang.String persistenceId,
                                 java.lang.Throwable cause)
        Fail next read from storage (recovery) attempt with cause exception for particular persistence id.
      • failNextRead

        public void failNextRead​(java.lang.String persistenceId)
        Fail next read from storage (recovery) attempt with default exception for any persistence id.
      • failNextNReads

        public void failNextNReads​(int n,
                                   java.lang.Throwable cause)
        Fail next n read from storage (recovery) attempts with cause exception for any persistence id.
      • failNextNReads

        public void failNextNReads​(int n)
        Fail next n read from storage (recovery) attempts with default exception for any persistence id.
      • failNextNReads

        public void failNextNReads​(java.lang.String persistenceId,
                                   int n,
                                   java.lang.Throwable cause)
        Fail next n read from storage (recovery) attempts with cause exception for particular persistence id.
      • failNextNReads

        public void failNextNReads​(java.lang.String persistenceId,
                                   int n)
        Fail next n read from storage (recovery) attempts with default exception for particular persistence id.
      • failNextDelete

        public void failNextDelete​(java.lang.Throwable cause)
        Fail next delete from storage attempt with cause exception for any persistence id.
      • failNextDelete

        public void failNextDelete()
        Fail next delete from storage attempt with default exception for any persistence id.
      • failNextDelete

        public void failNextDelete​(java.lang.String persistenceId,
                                   java.lang.Throwable cause)
        Fail next delete from storage attempt with cause exception for particular persistence id.
      • failNextDelete

        public void failNextDelete​(java.lang.String persistenceId)
        Fail next delete from storage attempt with default exception for particular persistence id.
      • failNextNDeletes

        public void failNextNDeletes​(int n,
                                     java.lang.Throwable cause)
        Fail next n delete from storage attempts with cause exception for any persistence id.
      • failNextNDeletes

        public void failNextNDeletes​(int n)
        Fail next n delete from storage attempts with default exception for any persistence id.
      • failNextNDeletes

        public void failNextNDeletes​(java.lang.String persistenceId,
                                     int n,
                                     java.lang.Throwable cause)
        Fail next n delete from storage attempts with cause exception for particular persistence id.
      • failNextNDeletes

        public void failNextNDeletes​(java.lang.String persistenceId,
                                     int n)
        Fail next n delete from storage attempts with default exception for particular persistence id.
      • receivePersisted

        public <A> java.util.List<A> receivePersisted​(java.lang.String persistenceId,
                                                      int n,
                                                      java.lang.Class<A> cla)
        Receive next n events from the storage.
      • receivePersisted

        public <A> java.util.List<A> receivePersisted​(java.lang.String persistenceId,
                                                      int n,
                                                      java.lang.Class<A> cla,
                                                      java.time.Duration max)
        Receive for max time next n events from the storage.
      • rejectNextNPersisted

        public void rejectNextNPersisted​(java.lang.String persistenceId,
                                         int n,
                                         java.lang.Throwable cause)
        Reject next n save in storage operations for particular persistence id with cause exception.
      • rejectNextNPersisted

        public void rejectNextNPersisted​(java.lang.String persistenceId,
                                         int n)
        Reject next n save in storage operations for particular persistence id with default exception.
      • rejectNextNPersisted

        public void rejectNextNPersisted​(int n)
        Reject next n save in storage operations for any persistence id with default exception.
      • rejectNextNPersisted

        public void rejectNextNPersisted​(int n,
                                         java.lang.Throwable cause)
        Reject next n save in storage operations for any persistence id with cause exception.
      • rejectNextPersisted

        public void rejectNextPersisted​(java.lang.String persistenceId)
        Reject next save in storage operation for particular persistence id with default exception.
      • rejectNextPersisted

        public void rejectNextPersisted​(java.lang.String persistenceId,
                                        java.lang.Throwable cause)
        Reject next save in storage operation for particular persistence id with cause exception.
      • rejectNextPersisted

        public void rejectNextPersisted​(java.lang.Throwable cause)
        Reject next save in storage operation for any persistence id with cause exception.
      • rejectNextPersisted

        public void rejectNextPersisted()
        Reject next save in storage operation for any persistence id with default exception.
      • rejectNextRead

        public void rejectNextRead()
        Reject next read from storage operation for any persistence id with default exception.
      • rejectNextRead

        public void rejectNextRead​(java.lang.Throwable cause)
        Reject next read from storage operation for any persistence id with cause exception.
      • rejectNextNReads

        public void rejectNextNReads​(int n)
        Reject next n read from storage operations for any persistence id with default exception.
      • rejectNextNReads

        public void rejectNextNReads​(int n,
                                     java.lang.Throwable cause)
        Reject next n read from storage operations for any persistence id with cause exception.
      • rejectNextRead

        public void rejectNextRead​(java.lang.String persistenceId)
        Reject next read from storage operation for particular persistence id with default exception.
      • rejectNextRead

        public void rejectNextRead​(java.lang.String persistenceId,
                                   java.lang.Throwable cause)
        Reject next read from storage operation for particular persistence id with cause exception.
      • rejectNextNReads

        public void rejectNextNReads​(java.lang.String persistenceId,
                                     int n)
        Reject next n read from storage operations for particular persistence id with default exception.
      • rejectNextNReads

        public void rejectNextNReads​(java.lang.String persistenceId,
                                     int n,
                                     java.lang.Throwable cause)
        Reject next n read from storage operations for particular persistence id with cause exception.
      • rejectNextDelete

        public void rejectNextDelete()
        Reject next delete from storage operation for any persistence id with default exception.
      • rejectNextDelete

        public void rejectNextDelete​(java.lang.Throwable cause)
        Reject next delete from storage operation for any persistence id with cause exception.
      • rejectNextNDeletes

        public void rejectNextNDeletes​(int n)
        Reject next n delete from storage operations for any persistence id with default exception.
      • rejectNextNDeletes

        public void rejectNextNDeletes​(int n,
                                       java.lang.Throwable cause)
        Reject next n delete from storage operations for any persistence id with cause exception.
      • rejectNextDelete

        public void rejectNextDelete​(java.lang.String persistenceId)
        Reject next delete from storage operations for particular persistence id with default exception.
      • rejectNextDelete

        public void rejectNextDelete​(java.lang.String persistenceId,
                                     java.lang.Throwable cause)
        Reject next delete from storage operations for particular persistence id with cause exception.
      • rejectNextNDeletes

        public void rejectNextNDeletes​(java.lang.String persistenceId,
                                       int n)
        Reject next n delete from storage operations for particular persistence id with default exception.
      • rejectNextNDeletes

        public void rejectNextNDeletes​(java.lang.String persistenceId,
                                       int n,
                                       java.lang.Throwable cause)
        Reject next n delete from storage operations for particular persistence id with cause exception.
      • rejectNextNOpsCond

        public void rejectNextNOpsCond​(java.util.function.BiFunction<java.lang.String,​JournalOperation,​java.lang.Object> cond,
                                       int n)
        Reject n following journal operations depending on the condition cond. Rejection triggers, when cond returns true. Reject operations with default ExpectedRejection exception.
      • rejectNextNOpsCond

        public void rejectNextNOpsCond​(java.util.function.BiFunction<java.lang.String,​JournalOperation,​java.lang.Object> cond,
                                       int n,
                                       java.lang.Throwable cause)
        Reject n following journal operations depending on the condition cond. Rejection triggers, when cond returns true. Rejects operations with the cause exception.
      • rejectNextNOps

        public void rejectNextNOps​(int n)
        Reject n following journal operations regardless of their type. Rejects operations with default ExpectedRejection exception.
      • rejectNextNOps

        public void rejectNextNOps​(int n,
                                   java.lang.Throwable cause)
        Reject n following journal operations regardless of their type. Rejects operations with the cause exception.
      • persistForRecovery

        public void persistForRecovery​(java.lang.String persistenceId,
                                       java.util.List<java.lang.Object> events)
        Persist events into storage in order.
      • persistedInStorage

        public java.util.List<java.lang.Object> persistedInStorage​(java.lang.String persistenceId)
        Retrieve all events saved in storage by persistence id.
      • clearAll

        public void clearAll()
        Clear all data from storage.

        NOTE! Also clears sequence numbers in storage!

        See Also:
        clearAllPreservingSeqNumbers()
      • clearByPersistenceId

        public void clearByPersistenceId​(java.lang.String persistenceId)
        Clear all data from storage for particular persistence id.

        NOTE! Also clears sequence number in storage!

        See Also:
        clearByIdPreservingSeqNumbers(java.lang.String)
      • clearAllPreservingSeqNumbers

        public void clearAllPreservingSeqNumbers()
        Clear all data in storage preserving sequence numbers.

        See Also:
        clearAll()
      • clearByIdPreservingSeqNumbers

        public void clearByIdPreservingSeqNumbers​(java.lang.String persistenceId)
        Clear all data in storage for particular persistence id preserving sequence numbers.

        See Also:
        clearByPersistenceId(java.lang.String)
      • failNextNOpsCond

        public void failNextNOpsCond​(java.util.function.BiFunction<java.lang.String,​JournalOperation,​java.lang.Object> cond,
                                     int n)
        Fail n following journal operations depending on the condition cond. Failure triggers, when cond returns true. Fails operations with default ExpectedFailure exception.
      • failNextNOpsCond

        public void failNextNOpsCond​(java.util.function.BiFunction<java.lang.String,​JournalOperation,​java.lang.Object> cond,
                                     int n,
                                     java.lang.Throwable cause)
        Fail n following journal operations depending on the condition cond. Failure triggers, when cond returns true. Fails operations with the cause exception.
      • failNextNOps

        public void failNextNOps​(int n)
        Fail n following journal operations regardless of their type. Fails operations with default ExpectedFailure exception.
      • failNextNOps

        public void failNextNOps​(int n,
                                 java.lang.Throwable cause)
        Fail n following journal operations depending on the condition cond. Failure triggers, when cond returns true. Fails operations with the cause exception.