1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
//! The functions and structs contained within this module can be used to test the behavior of an
//! actor in a sequential way.
//!
//! In order to be able to test an actor, every behavior has to support specific testing messages.
//! These can be enabled with the .enable_state_checks() method on the BehaviorBuilder.
//!
//! Example:
//! ```
//! use aector::actor::{Actor, MailboxType};
//! use aector::actor_system::ActorSystem;
//! use aector::behavior::{ActorManageMessage, Behavior, BehaviorBuilder, BehaviorAction};
//! use aector::testing::ActorTestBuilder;
//! #[tokio::test]
//! async fn simple_actor_test() {
//! // define a simple behavior for an i32 state
//! let behavior = BehaviorBuilder::new()
//! .on_tell::<i32>(|msg, state, ctx| -> BehaviorAction<i32> {
//! *state += msg;
//! Behavior::keep()
//! })
//! .enable_state_checks()
//! .build();
//!
//! let actor = Actor::new(0, behavior, MailboxType::Unbounded);
//! let addr = actor.get_addr();
//!
//! // create an empty actorsystem
//! let sys = ActorSystem::new();
//! sys.spawn(actor, "actor to be tested".to_string());
//!
//! // define test
//! let test_actor = ActorTestBuilder::new(addr)
//! .check(|state: &i32| *state == 0)
//! .tell(10)
//! .check(|state| *state == 10)
//! .tell(ActorManageMessage::Kill)
//! .build();
//!
//! let test_res = sys.spawn_test(test_actor).await;
//! assert_eq!(test_res, true);
//!
//! // start actor system to run actors
//! sys.start().await;
//!
//! }
//! ```
//!
pub use ;