Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 49 additions & 13 deletions core/src/component/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -704,7 +704,7 @@ mod tests {

#[test]
fn component_core_send() -> () {
let system = KompactConfig::default()
let system = crate::test_support::test_kompact_config()
.build()
.wait()
.expect("KompactSystem");
Expand Down Expand Up @@ -880,7 +880,10 @@ mod tests {
#[cfg(feature = "distributed")]
#[test]
fn child_unique_registration_test() -> () {
let system = KompactConfig::default().build().wait().expect("system");
let system = crate::test_support::test_kompact_config()
.build()
.wait()
.expect("system");
let parent = system.create(ParentComponent::unique);
system.start(&parent);
thread::sleep(TIMEOUT);
Expand All @@ -903,7 +906,10 @@ mod tests {
#[cfg(feature = "distributed")]
#[test]
fn child_alias_registration_test() -> () {
let system = KompactConfig::default().build().wait().expect("system");
let system = crate::test_support::test_kompact_config()
.build()
.wait()
.expect("system");
let parent = system.create(|| ParentComponent::alias(TEST_ALIAS.into()));
system.start(&parent);
thread::sleep(TIMEOUT);
Expand Down Expand Up @@ -953,7 +959,10 @@ mod tests {
ignore_requests!(B, TestComp);
ignore_indications!(A, TestComp);

let system = KompactConfig::default().build().wait().expect("System");
let system = crate::test_support::test_kompact_config()
.build()
.wait()
.expect("System");
let comp = system.create(TestComp::new);
let dynamic: Arc<dyn AbstractComponent<Message = Never>> = comp;
dynamic.on_dyn_definition(|def| {
Expand Down Expand Up @@ -1056,7 +1065,10 @@ mod tests {

#[test]
fn test_immediate_blocking() {
let system = KompactConfig::default().build().wait().expect("System");
let system = crate::test_support::test_kompact_config()
.build()
.wait()
.expect("System");
let comp = system.create(BlockingComponent::new);
system
.start_notify(&comp)
Expand All @@ -1076,7 +1088,10 @@ mod tests {

#[test]
fn test_channel_blocking() {
let system = KompactConfig::default().build().wait().expect("System");
let system = crate::test_support::test_kompact_config()
.build()
.wait()
.expect("System");
let comp = system.create(BlockingComponent::new);
system
.start_notify(&comp)
Expand All @@ -1100,7 +1115,10 @@ mod tests {

#[test]
fn test_mixed_blocking() {
let system = KompactConfig::default().build().wait().expect("System");
let system = crate::test_support::test_kompact_config()
.build()
.wait()
.expect("System");
let comp = system.create(BlockingComponent::new);
system
.start_notify(&comp)
Expand All @@ -1125,7 +1143,10 @@ mod tests {

#[test]
fn test_shutdown_blocking() {
let system = KompactConfig::default().build().wait().expect("System");
let system = crate::test_support::test_kompact_config()
.build()
.wait()
.expect("System");
let comp = system.create(BlockingComponent::new);
system
.start_notify(&comp)
Expand All @@ -1145,7 +1166,10 @@ mod tests {

#[test]
fn test_component_spawn_off() -> () {
let system = KompactConfig::default().build().wait().expect("System");
let system = crate::test_support::test_kompact_config()
.build()
.wait()
.expect("System");
let comp = system.create(BlockingComponent::new);
system
.start_notify(&comp)
Expand Down Expand Up @@ -1256,7 +1280,10 @@ mod tests {

#[test]
fn test_immediate_non_blocking() {
let system = KompactConfig::default().build().wait().expect("System");
let system = crate::test_support::test_kompact_config()
.build()
.wait()
.expect("System");
let comp = system.create(AsyncComponent::new);
system
.start_notify(&comp)
Expand All @@ -1276,7 +1303,10 @@ mod tests {

#[test]
fn test_channel_non_blocking() {
let system = KompactConfig::default().build().wait().expect("System");
let system = crate::test_support::test_kompact_config()
.build()
.wait()
.expect("System");
let comp = system.create(AsyncComponent::new);
system
.start_notify(&comp)
Expand All @@ -1300,7 +1330,10 @@ mod tests {

#[test]
fn test_concurrent_non_blocking() {
let system = KompactConfig::default().build().wait().expect("System");
let system = crate::test_support::test_kompact_config()
.build()
.wait()
.expect("System");
let comp = system.create(AsyncComponent::new);
system
.start_notify(&comp)
Expand Down Expand Up @@ -1413,7 +1446,10 @@ mod tests {

#[test]
fn test_channel_disconnection() {
let system = KompactConfig::default().build().wait().expect("System");
let system = crate::test_support::test_kompact_config()
.build()
.wait()
.expect("System");
let sender = system.create(CountSender::default);

let counter1 = system.create(Counter::default);
Expand Down
63 changes: 43 additions & 20 deletions core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,8 @@ pub mod routing;
pub mod runtime;
mod serialisation;
mod supervision;
/// Test support utilities
pub mod test_support;
/// Reusable timer facility internals
pub mod timer;
mod utils;
Expand Down Expand Up @@ -319,7 +321,7 @@ pub mod prelude {
///
/// Import all with `use prelude_test::*;`.
pub mod prelude_test {
pub use crate::serialisation::ser_test_helpers;
pub use crate::{serialisation::ser_test_helpers, test_support};
}

/// A module containing helper functions for benchmarking
Expand Down Expand Up @@ -548,7 +550,7 @@ mod tests {

#[test]
fn default_settings() {
let system = KompactConfig::default()
let system = crate::test_support::test_kompact_config()
.build()
.wait()
.expect("KompactSystem");
Expand All @@ -558,7 +560,7 @@ mod tests {

#[test]
fn custom_settings() {
let mut settings = KompactConfig::default();
let mut settings = crate::test_support::test_kompact_config();
settings.set_config_value(
&crate::config_keys::system::LABEL,
"custom-system".to_string(),
Expand All @@ -573,7 +575,7 @@ mod tests {

#[test]
fn custom_executor() {
let mut settings = KompactConfig::default();
let mut settings = crate::test_support::test_kompact_config();
settings
.set_config_value(&crate::config_keys::system::THREADS, 2)
.executor(executors::crossbeam_channel_pool::ThreadPool::new);
Expand All @@ -583,7 +585,7 @@ mod tests {

#[test]
fn custom_scheduler() {
let mut settings = KompactConfig::default();
let mut settings = crate::test_support::test_kompact_config();
settings.scheduler(move |t| {
crate::runtime::ExecutorScheduler::from(
executors::crossbeam_channel_pool::ThreadPool::new(t),
Expand Down Expand Up @@ -673,7 +675,10 @@ mod tests {

#[test]
fn test_dedicated_ref() -> () {
let system = KompactConfig::default().build().wait().expect("System");
let system = crate::test_support::test_kompact_config()
.build()
.wait()
.expect("System");
let cc = system.create_dedicated(CounterComponent::new);
system.start(&cc);
let cc_ref: ActorRef<Box<dyn Any + Send>> = cc.actor_ref();
Expand Down Expand Up @@ -704,7 +709,10 @@ mod tests {
let core_ids = core_affinity::get_core_ids().expect("Failed to fetch core ids");
assert!(core_ids.len() >= 2, "this test requires at least two cores");

let system = KompactConfig::default().build().wait().expect("System");
let system = crate::test_support::test_kompact_config()
.build()
.wait()
.expect("System");
let cc = system.create_dedicated_pinned(CounterComponent::new, core_ids[0]);
system.start(&cc);
let cc_ref: ActorRef<Box<dyn Any + Send>> = cc.actor_ref();
Expand Down Expand Up @@ -732,7 +740,10 @@ mod tests {

#[test]
fn test_dedicated() -> () {
let system = KompactConfig::default().build().wait().expect("System");
let system = crate::test_support::test_kompact_config()
.build()
.wait()
.expect("System");

let tc = system.create_dedicated(TestComponent::new);
let rc = system.create_dedicated(RecvComponent::new);
Expand Down Expand Up @@ -807,7 +818,7 @@ mod tests {

#[test]
fn test_timer() -> () {
let system = KompactConfig::default()
let system = crate::test_support::test_kompact_config()
.build()
.wait()
.expect("KompactSystem");
Expand Down Expand Up @@ -862,7 +873,7 @@ mod tests {

#[test]
fn test_start_stop() -> () {
let system = KompactConfig::default()
let system = crate::test_support::test_kompact_config()
.build()
.wait()
.expect("KompactSystem");
Expand Down Expand Up @@ -982,7 +993,7 @@ mod tests {
#[test]
#[ignore]
fn test_component_failure() -> () {
let system = KompactConfig::default()
let system = crate::test_support::test_kompact_config()
.build()
.wait()
.expect("KompactSystem");
Expand Down Expand Up @@ -1043,7 +1054,7 @@ mod tests {
#[test]
#[ignore]
fn test_component_recovery() -> () {
let system = KompactConfig::default()
let system = crate::test_support::test_kompact_config()
.build()
.wait()
.expect("KompactSystem");
Expand Down Expand Up @@ -1198,7 +1209,7 @@ mod tests {
#[test]
#[ignore]
fn test_component_recovery_with_state() -> () {
let system = KompactConfig::default()
let system = crate::test_support::test_kompact_config()
.build()
.wait()
.expect("KompactSystem");
Expand Down Expand Up @@ -1274,7 +1285,10 @@ mod tests {

#[test]
fn test_async_shutdown() -> () {
let system = KompactConfig::default().build().wait().expect("system");
let system = crate::test_support::test_kompact_config()
.build()
.wait()
.expect("system");
let stopper = system.create(Stopper::new);
system.start(&stopper);
system.await_termination();
Expand All @@ -1283,7 +1297,10 @@ mod tests {
#[test]
fn test_async_terminated_inside_futures_executor() -> () {
futures::executor::block_on(async {
let system = KompactConfig::default().build().await.expect("system");
let system = crate::test_support::test_kompact_config()
.build()
.await
.expect("system");
let stopper = system.create(Stopper::new);
system.start(&stopper);
system.terminated().await;
Expand Down Expand Up @@ -1316,7 +1333,7 @@ mod tests {
#[test]
fn test_config_from_string() -> () {
let default_values = r#"a = 7"#;
let mut conf = KompactConfig::default();
let mut conf = crate::test_support::test_kompact_config();
conf.load_config_str(default_values);
let system = conf.build().wait().expect("system");
let c = system.create(ConfigComponent::new);
Expand All @@ -1333,7 +1350,7 @@ mod tests {
let config_file_path = Fixture::blank("test_settings.toml");
let mut config_file = File::create(config_file_path.deref()).expect("config file");
config_file.write_all(b"a = 7").expect("write config file");
let mut conf = KompactConfig::default();
let mut conf = crate::test_support::test_kompact_config();
conf.load_config_file(config_file_path.to_path_buf());
let system = conf.build().wait().expect("system");
let c = system.create(ConfigComponent::new);
Expand All @@ -1350,7 +1367,7 @@ mod tests {
let config_file_path = Fixture::blank("test_settings.toml");
let mut config_file = File::create(config_file_path.deref()).expect("config file");
config_file.write_all(b"a = 7").expect("write config file");
let mut conf = KompactConfig::default();
let mut conf = crate::test_support::test_kompact_config();
conf.load_config_str(default_values)
.load_config_file(config_file_path.to_path_buf());
let system = conf.build().wait().expect("system");
Expand All @@ -1365,14 +1382,20 @@ mod tests {
#[test]
fn test_async_build_inside_futures_executor() -> () {
futures::executor::block_on(async {
let system = KompactConfig::default().build().await.expect("system");
let system = crate::test_support::test_kompact_config()
.build()
.await
.expect("system");
system.shutdown().await.expect("shutdown");
});
}

#[test]
fn test_system_spawn() -> () {
let system = KompactConfig::default().build().wait().expect("system");
let system = crate::test_support::test_kompact_config()
.build()
.wait()
.expect("system");
let handle = system.spawn(async move { "test".to_string() });
let res = futures::executor::block_on(handle).expect("result");
assert_eq!(res, "test");
Expand Down
7 changes: 7 additions & 0 deletions core/src/runtime/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,13 @@ fn default_logger() -> Arc<KompactLogger> {
.expect("Can't re-initialise global logger after it has been dropped!")
}

pub(crate) fn set_default_logger(logger: KompactLogger) {
DEFAULT_ROOT_LOGGER
.load_full()
.expect("Can't re-initialise global logger after it has been dropped!");
DEFAULT_ROOT_LOGGER.store(Some(Arc::new(logger)));
}

/// Removes the global default logger
///
/// This causes the remaining messages to be flushed to the output.
Expand Down
Loading
Loading