mirror of https://github.com/bastion-rs/bastion
Compare commits
2 Commits
d79afe82c0
...
8dadf99c2b
Author | SHA1 | Date |
---|---|---|
Valeryi Savich | 8dadf99c2b | |
Valeryi Savich | 872d26c46f |
|
@ -1,6 +1,5 @@
|
|||
pub mod actor_ref;
|
||||
pub mod context;
|
||||
pub mod definition;
|
||||
pub mod local_state;
|
||||
pub mod state;
|
||||
pub mod traits;
|
||||
|
|
|
@ -1,19 +1,18 @@
|
|||
use std::fmt::Debug;
|
||||
|
||||
use async_trait::async_trait;
|
||||
|
||||
use crate::actor::context::Context;
|
||||
use crate::error::Result;
|
||||
|
||||
#[async_trait]
|
||||
pub trait Actor: Sync {
|
||||
fn new() -> Self
|
||||
where
|
||||
Self: Sized;
|
||||
async fn on_init(&self, _ctx: &mut Context) {}
|
||||
async fn on_sync(&self, _ctx: &mut Context) {}
|
||||
async fn on_stopped(&self, _ctx: &mut Context) {}
|
||||
async fn on_terminated(&self, _ctx: &mut Context) {}
|
||||
async fn on_failed(&self, _ctx: &mut Context) {}
|
||||
async fn on_finished(&self, _ctx: &mut Context) {}
|
||||
async fn on_deinit(&self, _ctx: &mut Context) {}
|
||||
async fn handler(&self, ctx: &mut Context) -> Result<()>;
|
||||
pub trait Actor: 'static {
|
||||
async fn on_init(&mut self, _ctx: &mut Context) {}
|
||||
async fn on_sync(&mut self, _ctx: &mut Context) {}
|
||||
async fn on_stopped(&mut self, _ctx: &mut Context) {}
|
||||
async fn on_terminated(&mut self, _ctx: &mut Context) {}
|
||||
async fn on_failed(&mut self, _ctx: &mut Context) {}
|
||||
async fn on_finished(&mut self, _ctx: &mut Context) {}
|
||||
async fn on_deinit(&mut self, _ctx: &mut Context) {}
|
||||
async fn handler(&mut self, ctx: &mut Context) -> Result<()>;
|
||||
}
|
||||
|
|
|
@ -117,8 +117,25 @@ impl Hash for Definition {
|
|||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use crate::actor::definition::Definition;
|
||||
use crate::actor::context::Context;
|
||||
use crate::actor::traits::Actor;
|
||||
use crate::error::Result;
|
||||
use crate::routing::path::Scope;
|
||||
use crate::system::definition::Definition;
|
||||
|
||||
use async_trait::async_trait;
|
||||
|
||||
#[derive(Debug)]
|
||||
struct FakeActor {
|
||||
counter: u32,
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl Actor for FakeActor {
|
||||
async fn handler(&mut self, ctx: &mut Context) -> Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
fn fake_actor_name() -> String {
|
||||
let index = 1;
|
||||
|
@ -134,6 +151,16 @@ mod tests {
|
|||
assert_eq!(instance.redundancy, 1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_definition_with_custom_actor() {
|
||||
let instance = Definition::new().actor(FakeActor { counter: 0 });
|
||||
|
||||
assert_eq!(instance.actor.is_some(), true);
|
||||
assert_eq!(instance.scope, Scope::User);
|
||||
assert_eq!(instance.actor_name_fn.is_none(), true);
|
||||
assert_eq!(instance.redundancy, 1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_definition_with_custom_name() {
|
||||
let instance = Definition::new().name("test_name");
|
|
@ -1,8 +1,9 @@
|
|||
mod global_state;
|
||||
mod node;
|
||||
|
||||
use once_cell::sync::Lazy;
|
||||
|
||||
use crate::system::node::Node;
|
||||
|
||||
pub mod definition;
|
||||
mod global_state;
|
||||
mod node;
|
||||
|
||||
static SYSTEM: Lazy<Node> = Lazy::new(|| Node::new());
|
||||
|
|
Loading…
Reference in New Issue