use std::time::Duration;
use tick::Clock;
use crate::breaker::BreakerId;
#[derive(Debug)]
#[non_exhaustive]
pub struct RecoveryArgs<'a> {
pub(crate) breaker_id: &'a BreakerId,
pub(crate) clock: &'a Clock,
}
impl RecoveryArgs<'_> {
#[must_use]
pub fn breaker_id(&self) -> &BreakerId {
self.breaker_id
}
#[must_use]
pub fn clock(&self) -> &Clock {
self.clock
}
}
#[derive(Debug)]
pub struct RejectedInputArgs<'a> {
pub(crate) breaker_id: &'a BreakerId,
}
impl RejectedInputArgs<'_> {
#[must_use]
pub fn breaker_id(&self) -> &BreakerId {
self.breaker_id
}
}
#[derive(Debug)]
#[non_exhaustive]
pub struct OnProbingArgs<'a> {
pub(crate) breaker_id: &'a BreakerId,
}
impl OnProbingArgs<'_> {
#[must_use]
pub fn breaker_id(&self) -> &BreakerId {
self.breaker_id
}
}
#[derive(Debug)]
#[non_exhaustive]
pub struct OnClosedArgs<'a> {
pub(crate) breaker_id: &'a BreakerId,
pub(crate) open_duration: std::time::Duration,
}
impl OnClosedArgs<'_> {
#[must_use]
pub fn breaker_id(&self) -> &BreakerId {
self.breaker_id
}
#[must_use]
pub fn open_duration(&self) -> Duration {
self.open_duration
}
}
#[derive(Debug)]
#[non_exhaustive]
pub struct OnOpenedArgs<'a> {
pub(crate) breaker_id: &'a BreakerId,
}
impl OnOpenedArgs<'_> {
#[must_use]
pub fn breaker_id(&self) -> &BreakerId {
self.breaker_id
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn recovery_args_accessors() {
let key = BreakerId::from("test");
let clock = Clock::new_frozen();
let args = RecoveryArgs {
breaker_id: &key,
clock: &clock,
};
assert_eq!(args.breaker_id(), &key);
let _ = args.clock();
assert!(format!("{args:?}").contains("RecoveryArgs"));
}
#[test]
fn rejected_input_args_accessors() {
let key = BreakerId::from("rejected");
let args = RejectedInputArgs { breaker_id: &key };
assert_eq!(args.breaker_id(), &key);
assert!(format!("{args:?}").contains("RejectedInputArgs"));
}
#[test]
fn on_probing_args_accessors() {
let key = BreakerId::from("probing");
let args = OnProbingArgs { breaker_id: &key };
assert_eq!(args.breaker_id(), &key);
assert!(format!("{args:?}").contains("OnProbingArgs"));
}
#[test]
fn on_closed_args_accessors() {
let key = BreakerId::from("closed");
let duration = Duration::from_secs(5);
let args = OnClosedArgs {
breaker_id: &key,
open_duration: duration,
};
assert_eq!(args.breaker_id(), &key);
assert_eq!(args.open_duration(), duration);
assert!(format!("{args:?}").contains("OnClosedArgs"));
}
#[test]
fn on_opened_args_accessors() {
let key = BreakerId::from("opened");
let args = OnOpenedArgs { breaker_id: &key };
assert_eq!(args.breaker_id(), &key);
assert!(format!("{args:?}").contains("OnOpenedArgs"));
}
}