Class: Dynflow::Testing::InThreadWorld
- Inherits:
-
World
- Object
- World
- Dynflow::Testing::InThreadWorld
show all
- Defined in:
- lib/dynflow/testing/in_thread_world.rb
Instance Attribute Summary
Attributes inherited from World
#action_classes, #auto_rescue, #auto_validity_check, #client_dispatcher, #clock, #config, #connector, #coordinator, #dead_letter_handler, #delayed_executor, #execution_plan_cleaner, #executor, #executor_dispatcher, #id, #logger_adapter, #meta, #middleware, #persistence, #subscription_index, #terminated, #termination_timeout, #throttle_limiter, #transaction_adapter, #validity_check_timeout
Class Method Summary
collapse
Instance Method Summary
collapse
-
#event(execution_plan_id, step_id, event, done = Concurrent::Promises.resolvable_future, optional: false) ⇒ Object
-
#execute(execution_plan_id, done = Concurrent::Promises.resolvable_future) ⇒ Object
-
#initialize(*args) ⇒ InThreadWorld
constructor
A new instance of InThreadWorld.
-
#plan_event(execution_plan_id, step_id, event, time, done = Concurrent::Promises.resolvable_future, optional: false) ⇒ Object
-
#terminate(future = Concurrent::Promises.resolvable_future) ⇒ Object
Methods inherited from World
#action_logger, #auto_execute, #before_termination, #delay, #delay_with_options, #get_execution_status, #halt, #logger, #ping, #ping_without_cache, #plan, #plan_elsewhere, #plan_request, #plan_with_options, #post_initialization, #publish_request, #registered_world, #reload!, #subscribed_actions, #terminating?, #trigger, #try_spawn, #update_register
#invalidate, #invalidate_execution_lock, #invalidate_planning_lock, #locks_validity_check, #perform_validity_checks, #prune_execution_inhibition_locks!, #with_valid_execution_plan_for_lock, #worlds_validity_check
Constructor Details
Returns a new instance of InThreadWorld.
Class Method Details
.coordinator_adapter ⇒ Object
33
34
35
|
# File 'lib/dynflow/testing/in_thread_world.rb', line 33
def self.coordinator_adapter
->(world, _) { CoordiationAdapterWithLog.new(world) }
end
|
.instance(&block) ⇒ Object
The worlds created by this method are getting terminated after each test run
38
39
40
|
# File 'lib/dynflow/testing/in_thread_world.rb', line 38
def self.instance(&block)
@instance ||= self.new(test_world_config(&block))
end
|
.logger_adapter ⇒ Object
29
30
31
|
# File 'lib/dynflow/testing/in_thread_world.rb', line 29
def self.logger_adapter
@adapter ||= Dynflow::LoggerAdapters::Simple.new $stderr, 4
end
|
.persistence_adapter ⇒ Object
21
22
23
24
25
26
27
|
# File 'lib/dynflow/testing/in_thread_world.rb', line 21
def self.persistence_adapter
@persistence_adapter ||= begin
db_config = ENV['DB_CONN_STRING'] || 'sqlite:/'
puts "Using database configuration: #{db_config}"
Dynflow::PersistenceAdapters::Sequel.new(db_config)
end
end
|
.test_world_config {|config| ... } ⇒ Object
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
# File 'lib/dynflow/testing/in_thread_world.rb', line 6
def self.test_world_config
config = Dynflow::Config.new
config.persistence_adapter = persistence_adapter
config.logger_adapter = logger_adapter
config.coordinator_adapter = coordinator_adapter
config.delayed_executor = nil
config.auto_rescue = false
config.auto_validity_check = false
config.exit_on_terminate = false
config.auto_execute = false
config.auto_terminate = false
yield config if block_given?
return config
end
|
Instance Method Details
#event(execution_plan_id, step_id, event, done = Concurrent::Promises.resolvable_future, optional: false) ⇒ Object
62
63
64
|
# File 'lib/dynflow/testing/in_thread_world.rb', line 62
def event(execution_plan_id, step_id, event, done = Concurrent::Promises.resolvable_future, optional: false)
@executor.event(execution_plan_id, step_id, event, done, optional: optional)
end
|
#execute(execution_plan_id, done = Concurrent::Promises.resolvable_future) ⇒ Object
48
49
50
|
# File 'lib/dynflow/testing/in_thread_world.rb', line 48
def execute(execution_plan_id, done = Concurrent::Promises.resolvable_future)
@executor.execute(execution_plan_id, done)
end
|
#plan_event(execution_plan_id, step_id, event, time, done = Concurrent::Promises.resolvable_future, optional: false) ⇒ Object
66
67
68
69
70
71
72
|
# File 'lib/dynflow/testing/in_thread_world.rb', line 66
def plan_event(execution_plan_id, step_id, event, time, done = Concurrent::Promises.resolvable_future, optional: false)
if time.nil? || time < Time.now
event(execution_plan_id, step_id, event, done, optional: optional)
else
clock.ping(executor, time, Director::Event[SecureRandom.uuid, execution_plan_id, step_id, event, done, optional], :delayed_event)
end
end
|
#terminate(future = Concurrent::Promises.resolvable_future) ⇒ Object
52
53
54
55
56
57
58
59
60
|
# File 'lib/dynflow/testing/in_thread_world.rb', line 52
def terminate(future = Concurrent::Promises.resolvable_future)
run_before_termination_hooks
@executor.terminate
coordinator.delete_world(registered_world)
future.fulfill true
@terminated.resolve
rescue => e
future.reject e
end
|