1
+ // //-----------------------------------------------------------------------
2
+ // // <copyright file="ChannelExecutorConfigurationSpec.cs" company="Akka.NET Project">
3
+ // // Copyright (C) 2009-2022 Lightbend Inc. <http://www.lightbend.com>
4
+ // // Copyright (C) 2013-2022 .NET Foundation <https://github.com/akkadotnet/akka.net>
5
+ // // </copyright>
6
+ // //-----------------------------------------------------------------------
7
+
8
+ using System . Threading . Tasks ;
9
+ using Akka . Actor ;
10
+ using Akka . Configuration ;
11
+ using Akka . Dispatch ;
12
+ using Akka . TestKit ;
13
+ using Xunit ;
14
+ using FluentAssertions ;
15
+
16
+ namespace Akka . Tests . Dispatch
17
+ {
18
+ public class ChannelExecutorConfigurationSpec : AkkaSpec
19
+ {
20
+ [ Fact ]
21
+ public void ChannelExecutor_config_should_be_injected_when_it_doesnt_exist ( )
22
+ {
23
+ var config = ConfigurationFactory . ParseString ( @"executor = channel-executor" ) ;
24
+ var configurator = new ChannelExecutorConfigurator ( config , Sys . Dispatchers . Prerequisites ) ;
25
+ configurator . Priority . Should ( ) . Be ( TaskSchedulerPriority . Normal ) ;
26
+ }
27
+
28
+ [ Fact ]
29
+ public void ChannelExecutor_default_should_be_overriden_by_config ( )
30
+ {
31
+ var config = ConfigurationFactory . ParseString ( @"
32
+ executor = channel-executor
33
+ channel-executor.priority = high" ) ;
34
+ var configurator = new ChannelExecutorConfigurator ( config , Sys . Dispatchers . Prerequisites ) ;
35
+ configurator . Priority . Should ( ) . Be ( TaskSchedulerPriority . High ) ;
36
+ }
37
+
38
+ [ Fact ]
39
+ public void ChannelExecutorConfigurator_should_use_default_when_config_is_null ( )
40
+ {
41
+ var configurator = new ChannelExecutorConfigurator ( null , Sys . Dispatchers . Prerequisites ) ;
42
+ configurator . Priority . Should ( ) . Be ( TaskSchedulerPriority . Normal ) ;
43
+ }
44
+
45
+ // backward compatibility test
46
+ [ Fact ]
47
+ public async Task ChannelExecutor_instantiation_should_not_throw_when_config_doesnt_exist ( )
48
+ {
49
+ var config = ConfigurationFactory . ParseString ( @"
50
+ akka.actor.default-dispatcher = {
51
+ executor = channel-executor
52
+ }" ) ;
53
+
54
+ // Throws NRE in 1.4.29-32
55
+ var sys = ActorSystem . Create ( "test" , config ) ;
56
+
57
+ // Check that all settings are correct
58
+ var dispatcher = sys . Dispatchers . Lookup ( "akka.actor.default-dispatcher" ) ;
59
+ dispatcher . Configurator . Config . GetString ( "executor" ) . Should ( ) . Be ( "channel-executor" ) ;
60
+
61
+ var configurator = new ChannelExecutorConfigurator ( dispatcher . Configurator . Config , Sys . Dispatchers . Prerequisites ) ;
62
+ configurator . Priority . Should ( ) . Be ( TaskSchedulerPriority . Normal ) ;
63
+
64
+ await sys . Terminate ( ) ;
65
+ }
66
+ }
67
+ }
0 commit comments