ntl-orchestra 0.9.2 → 0.9.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +3 -0
- data/Gemfile +1 -1
- data/README.md +91 -90
- data/lib/orchestra/conductor.rb +6 -6
- data/lib/orchestra/dsl/object_adapter.rb +16 -16
- data/lib/orchestra/dsl/operations.rb +35 -35
- data/lib/orchestra/dsl/{nodes.rb → steps.rb} +7 -9
- data/lib/orchestra/execution.rb +158 -0
- data/lib/orchestra/operation.rb +16 -16
- data/lib/orchestra/recording/playback.rb +47 -0
- data/lib/orchestra/recording.rb +5 -45
- data/lib/orchestra/run_list.rb +49 -49
- data/lib/orchestra/{node → step}/output.rb +8 -8
- data/lib/orchestra/{node.rb → step.rb} +22 -25
- data/lib/orchestra/thread_pool.rb +3 -3
- data/lib/orchestra/version.rb +1 -1
- data/lib/orchestra.rb +2 -2
- data/test/examples/fizz_buzz.rb +5 -5
- data/test/examples/invitation_service.rb +9 -9
- data/test/integration/multithreading_test.rb +5 -5
- data/test/integration/recording_telemetry_test.rb +3 -6
- data/test/integration/replayable_operation_test.rb +4 -4
- data/test/lib/console.rb +1 -1
- data/test/support/telemetry_recorder.rb +7 -7
- data/test/unit/dsl_test.rb +26 -26
- data/test/unit/object_adapter_test.rb +14 -14
- data/test/unit/operation_test.rb +45 -45
- data/test/unit/run_list_test.rb +12 -12
- data/test/unit/step_test.rb +122 -0
- data/test/unit/thread_pool_test.rb +2 -2
- metadata +15 -13
- data/lib/orchestra/performance.rb +0 -137
- data/test/unit/node_test.rb +0 -122
data/test/unit/dsl_test.rb
CHANGED
@@ -1,49 +1,49 @@
|
|
1
1
|
class DSLTest < Minitest::Test
|
2
|
-
def
|
2
|
+
def test_failing_to_supply_execute_block
|
3
3
|
error = assert_raises ArgumentError do
|
4
|
-
Orchestra::
|
4
|
+
Orchestra::Step::InlineStep.build do
|
5
5
|
provides :foo
|
6
6
|
depends_on :bar
|
7
7
|
end
|
8
8
|
end
|
9
9
|
|
10
|
-
assert_equal "expected inline
|
10
|
+
assert_equal "expected inline step to define a execute block", error.message
|
11
11
|
end
|
12
12
|
|
13
|
-
def
|
13
|
+
def test_two_steps_one_name
|
14
14
|
error = assert_raises ArgumentError do
|
15
15
|
Orchestra::Operation.new do
|
16
|
-
|
16
|
+
step :foo do
|
17
17
|
depends_on :bar
|
18
|
-
|
18
|
+
execute do bar + bar end
|
19
19
|
end
|
20
|
-
|
20
|
+
step :foo do
|
21
21
|
depends_on :qux
|
22
|
-
|
22
|
+
execute do qux * qux end
|
23
23
|
end
|
24
24
|
end
|
25
25
|
end
|
26
26
|
|
27
|
-
assert_equal "There are duplicate
|
27
|
+
assert_equal "There are duplicate steps named :foo", error.message
|
28
28
|
end
|
29
29
|
|
30
|
-
def
|
30
|
+
def test_result_step
|
31
31
|
operation = Orchestra::Operation.new do
|
32
|
-
result :foo do
|
32
|
+
result :foo do execute do 'foo' end end
|
33
33
|
end
|
34
34
|
assert_equal :foo, operation.result
|
35
35
|
|
36
36
|
error = assert_raises ArgumentError do
|
37
37
|
operation = Orchestra::Operation.new do
|
38
|
-
result do
|
38
|
+
result do execute do 'foo' end end
|
39
39
|
end
|
40
40
|
end
|
41
|
-
assert_equal "Could not infer name for
|
41
|
+
assert_equal "Could not infer name for step from a provision", error.message
|
42
42
|
|
43
43
|
operation = Orchestra::Operation.new do
|
44
44
|
result do
|
45
45
|
provides :foo
|
46
|
-
|
46
|
+
execute do 'foo' end
|
47
47
|
end
|
48
48
|
end
|
49
49
|
assert_equal :foo, operation.result
|
@@ -51,20 +51,20 @@ class DSLTest < Minitest::Test
|
|
51
51
|
|
52
52
|
def test_command_operations_using_finally
|
53
53
|
operation = Orchestra::Operation.new do
|
54
|
-
|
54
|
+
step :unnecessary do
|
55
55
|
provides :baz
|
56
|
-
|
56
|
+
execute do raise "Can't get here" end
|
57
57
|
end
|
58
58
|
|
59
|
-
|
59
|
+
step :necessary do
|
60
60
|
depends_on :baz
|
61
61
|
provides :bar
|
62
|
-
|
62
|
+
execute do baz + 1 end
|
63
63
|
end
|
64
64
|
|
65
65
|
finally do
|
66
66
|
depends_on :bar
|
67
|
-
|
67
|
+
execute do bar * 2 end
|
68
68
|
end
|
69
69
|
end
|
70
70
|
|
@@ -80,7 +80,7 @@ class DSLTest < Minitest::Test
|
|
80
80
|
conductor = Orchestra::Conductor.new
|
81
81
|
conductor.add_observer test_observer
|
82
82
|
|
83
|
-
assert_equal nil, conductor.
|
83
|
+
assert_equal nil, conductor.execute(operation, :baz => 3)
|
84
84
|
assert_equal 8, test_observer.result
|
85
85
|
end
|
86
86
|
|
@@ -88,12 +88,12 @@ class DSLTest < Minitest::Test
|
|
88
88
|
operation = Orchestra::Operation.new do
|
89
89
|
result do
|
90
90
|
modifies :list
|
91
|
-
|
91
|
+
execute do list << :foo end
|
92
92
|
end
|
93
93
|
end
|
94
94
|
|
95
95
|
ary = []
|
96
|
-
Orchestra.
|
96
|
+
Orchestra.execute operation, :list => ary
|
97
97
|
|
98
98
|
assert_equal [:foo], ary
|
99
99
|
end
|
@@ -101,8 +101,8 @@ class DSLTest < Minitest::Test
|
|
101
101
|
def test_must_supply_result
|
102
102
|
error = assert_raises ArgumentError do
|
103
103
|
Orchestra::Operation.new do
|
104
|
-
|
105
|
-
|
104
|
+
step :foo do
|
105
|
+
execute do 'foo' end
|
106
106
|
end
|
107
107
|
end
|
108
108
|
end
|
@@ -110,13 +110,13 @@ class DSLTest < Minitest::Test
|
|
110
110
|
assert_equal "Must supply a result", error.message
|
111
111
|
end
|
112
112
|
|
113
|
-
def
|
113
|
+
def test_must_contain_at_least_one_step
|
114
114
|
error = assert_raises ArgumentError do
|
115
115
|
Orchestra::Operation.new do
|
116
116
|
self.result = :foo
|
117
117
|
end
|
118
118
|
end
|
119
119
|
|
120
|
-
assert_equal "Must supply at least one
|
120
|
+
assert_equal "Must supply at least one step", error.message
|
121
121
|
end
|
122
122
|
end
|
@@ -5,7 +5,7 @@ class ObjectAdapterTest < Minitest::Test
|
|
5
5
|
|
6
6
|
def test_method_does_not_exist_on_singleton
|
7
7
|
error = assert_raises NotImplementedError do
|
8
|
-
@builder.
|
8
|
+
@builder.add_step Splitter, :provides => :words, :method => :foo
|
9
9
|
end
|
10
10
|
|
11
11
|
assert_equal "ObjectAdapterTest::Splitter does not implement method `foo'", error.message
|
@@ -13,29 +13,29 @@ class ObjectAdapterTest < Minitest::Test
|
|
13
13
|
|
14
14
|
def test_method_does_not_exist_on_object
|
15
15
|
error = assert_raises NotImplementedError do
|
16
|
-
@builder.
|
16
|
+
@builder.add_step Upcaser, :provides => :words
|
17
17
|
end
|
18
18
|
|
19
|
-
assert_equal "ObjectAdapterTest::Upcaser does not implement instance method `
|
19
|
+
assert_equal "ObjectAdapterTest::Upcaser does not implement instance method `execute'", error.message
|
20
20
|
end
|
21
21
|
|
22
22
|
def test_dependencies_inferred_from_method_defaults
|
23
|
-
|
23
|
+
step = @builder.add_step Upcaser, :iterates_over => :words, :provides => :upcased_words, :method => :call
|
24
24
|
|
25
|
-
assert_equal [:words, :transform],
|
26
|
-
assert_equal [:words],
|
25
|
+
assert_equal [:words, :transform], step.dependencies
|
26
|
+
assert_equal [:words], step.required_dependencies
|
27
27
|
end
|
28
28
|
|
29
|
-
def
|
29
|
+
def test_executing_an_operation_with_integrated_objects
|
30
30
|
operation = Orchestra::Operation.new do
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
31
|
+
step Splitter, :provides => :words
|
32
|
+
step Upcaser, :iterates_over => :words, :provides => :upcased_words, :method => :call
|
33
|
+
step Bolder, :iterates_over => :upcased_words, :provides => :bolded_words, :method => :call
|
34
|
+
step Joiner, :method => :join
|
35
35
|
self.result = :joiner
|
36
36
|
end
|
37
37
|
|
38
|
-
result = Orchestra.
|
38
|
+
result = Orchestra.execute(
|
39
39
|
operation,
|
40
40
|
:sentence => "the quick brown fox jumps over the lazy dog",
|
41
41
|
:bold_text => "*",
|
@@ -50,7 +50,7 @@ class ObjectAdapterTest < Minitest::Test
|
|
50
50
|
def test_provent_singleton_objects_from_handling_collections
|
51
51
|
error = assert_raises ArgumentError do
|
52
52
|
Orchestra::Operation.new do
|
53
|
-
|
53
|
+
step Splitter, :iterates_over => :sentence
|
54
54
|
end
|
55
55
|
end
|
56
56
|
|
@@ -61,7 +61,7 @@ class ObjectAdapterTest < Minitest::Test
|
|
61
61
|
end
|
62
62
|
|
63
63
|
module Splitter
|
64
|
-
def self.
|
64
|
+
def self.execute sentence
|
65
65
|
sentence.split %r{[[:space:]]+}
|
66
66
|
end
|
67
67
|
end
|
data/test/unit/operation_test.rb
CHANGED
@@ -1,19 +1,19 @@
|
|
1
1
|
module OperationTest
|
2
|
-
class
|
2
|
+
class ExecutionTest < Minitest::Test
|
3
3
|
def test_simple_operation
|
4
4
|
operation = build_simple_operation
|
5
5
|
|
6
6
|
assert_equal(
|
7
7
|
%(THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG),
|
8
|
-
operation.
|
8
|
+
operation.execute(:sentence => %(the quick brown fox jumps over the lazy dog)),
|
9
9
|
)
|
10
10
|
end
|
11
11
|
|
12
|
-
def
|
12
|
+
def test_executing_operation_without_inputs
|
13
13
|
operation = build_simple_operation
|
14
14
|
|
15
15
|
error = assert_raises Orchestra::MissingInputError do
|
16
|
-
operation.
|
16
|
+
operation.execute
|
17
17
|
end
|
18
18
|
|
19
19
|
assert_equal %(Missing input :sentence), error.message
|
@@ -23,7 +23,7 @@ module OperationTest
|
|
23
23
|
operation = build_mutator
|
24
24
|
|
25
25
|
shopping_list = [%(1 clove garlic)]
|
26
|
-
operation.
|
26
|
+
operation.execute :shopping_list => shopping_list
|
27
27
|
|
28
28
|
assert_equal(
|
29
29
|
[%(1 clove garlic), %(2 bunches of carrots), %(1 stalk of celery), %(3 yellow onions)],
|
@@ -36,41 +36,41 @@ module OperationTest
|
|
36
36
|
|
37
37
|
assert_equal(
|
38
38
|
%(THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG),
|
39
|
-
operation.
|
39
|
+
operation.execute(:upcased_word_list => %w(THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG)),
|
40
40
|
)
|
41
41
|
end
|
42
42
|
|
43
|
-
def
|
43
|
+
def test_passing_conductor_into_steps
|
44
44
|
conductor = Orchestra::Conductor.new
|
45
45
|
|
46
|
-
|
46
|
+
step = Orchestra::Step::InlineStep.build do
|
47
47
|
depends_on :conductor
|
48
48
|
provides :conductor_id
|
49
|
-
|
49
|
+
execute do conductor.object_id end
|
50
50
|
end
|
51
51
|
|
52
|
-
assert_equal conductor.object_id,
|
52
|
+
assert_equal conductor.object_id, step.execute[:conductor_id]
|
53
53
|
end
|
54
54
|
|
55
55
|
def test_missing_input_errors
|
56
56
|
operation = Orchestra::Operation.new do
|
57
|
-
|
57
|
+
step :foo do
|
58
58
|
depends_on :bar
|
59
|
-
|
59
|
+
execute do bar + bar end
|
60
60
|
end
|
61
|
-
|
61
|
+
step :baz do
|
62
62
|
depends_on :qux
|
63
|
-
|
63
|
+
execute do qux * qux end
|
64
64
|
end
|
65
|
-
|
65
|
+
step :result do
|
66
66
|
depends_on :foo, :baz
|
67
|
-
|
67
|
+
execute do baz - foo end
|
68
68
|
end
|
69
69
|
self.result = :result
|
70
70
|
end
|
71
71
|
|
72
72
|
error = assert_raises Orchestra::MissingInputError do
|
73
|
-
Orchestra.
|
73
|
+
Orchestra.execute operation, :bar => nil
|
74
74
|
end
|
75
75
|
|
76
76
|
assert_equal "Missing inputs :bar and :qux", error.message
|
@@ -80,21 +80,21 @@ module OperationTest
|
|
80
80
|
|
81
81
|
def build_simple_operation
|
82
82
|
Orchestra::Operation.new do
|
83
|
-
|
83
|
+
step :split do
|
84
84
|
depends_on :sentence
|
85
85
|
provides :word_list
|
86
|
-
|
86
|
+
execute do sentence.split %r{[[:space:]]+} end
|
87
87
|
end
|
88
88
|
|
89
|
-
|
89
|
+
step :upcase do
|
90
90
|
depends_on :word_list
|
91
91
|
provides :upcased_word_list
|
92
|
-
|
92
|
+
execute do word_list.map &:upcase end
|
93
93
|
end
|
94
94
|
|
95
|
-
|
95
|
+
step :join do
|
96
96
|
depends_on :upcased_word_list
|
97
|
-
|
97
|
+
execute do upcased_word_list.join ' ' end
|
98
98
|
end
|
99
99
|
|
100
100
|
self.result = :join
|
@@ -103,22 +103,22 @@ module OperationTest
|
|
103
103
|
|
104
104
|
def build_mutator
|
105
105
|
Orchestra::Operation.new do
|
106
|
-
|
106
|
+
step :carrots do
|
107
107
|
depends_on :shopping_list
|
108
108
|
provides :shopping_list
|
109
|
-
|
109
|
+
execute do shopping_list << "2 bunches of carrots" end
|
110
110
|
end
|
111
111
|
|
112
|
-
|
112
|
+
step :celery do
|
113
113
|
depends_on :shopping_list
|
114
114
|
provides :shopping_list
|
115
|
-
|
115
|
+
execute do shopping_list << "1 stalk of celery" end
|
116
116
|
end
|
117
117
|
|
118
|
-
|
118
|
+
step :onions do
|
119
119
|
depends_on :shopping_list
|
120
120
|
provides :shopping_list
|
121
|
-
|
121
|
+
execute do shopping_list << "3 yellow onions" end
|
122
122
|
end
|
123
123
|
|
124
124
|
self.result = :shopping_list
|
@@ -129,33 +129,33 @@ module OperationTest
|
|
129
129
|
|
130
130
|
class IntrospectionTest < Minitest::Test
|
131
131
|
def test_introspecting_dependencies
|
132
|
-
|
132
|
+
step = Orchestra::Step::InlineStep.build do
|
133
133
|
depends_on :foo, :bar => :baz
|
134
134
|
provides :baz
|
135
|
-
|
135
|
+
execute do :noop end
|
136
136
|
end
|
137
137
|
|
138
|
-
assert_equal [:foo, :bar],
|
138
|
+
assert_equal [:foo, :bar], step.dependencies
|
139
139
|
end
|
140
140
|
|
141
141
|
def test_introspecting_optional_dependencies
|
142
|
-
|
142
|
+
step = Orchestra::Step::InlineStep.build do
|
143
143
|
depends_on :foo, :bar => :baz
|
144
144
|
provides :qux
|
145
|
-
|
145
|
+
execute do :noop end
|
146
146
|
end
|
147
147
|
|
148
|
-
assert_equal [:bar],
|
148
|
+
assert_equal [:bar], step.optional_dependencies
|
149
149
|
end
|
150
150
|
|
151
151
|
def test_introspecting_mandatory_dependencies
|
152
|
-
|
152
|
+
step = Orchestra::Step::InlineStep.build do
|
153
153
|
depends_on :foo, :bar => :baz
|
154
154
|
provides :baz
|
155
|
-
|
155
|
+
execute do :noop end
|
156
156
|
end
|
157
157
|
|
158
|
-
assert_equal [:foo],
|
158
|
+
assert_equal [:foo], step.required_dependencies
|
159
159
|
end
|
160
160
|
|
161
161
|
end
|
@@ -163,24 +163,24 @@ module OperationTest
|
|
163
163
|
class EmbeddingOperationsTest < Minitest::Test
|
164
164
|
def test_embedding_operations
|
165
165
|
inner = Orchestra::Operation.new do
|
166
|
-
|
166
|
+
step :double do
|
167
167
|
depends_on :number
|
168
168
|
provides :doubled
|
169
|
-
|
169
|
+
execute do number * 2 end
|
170
170
|
end
|
171
171
|
|
172
172
|
result :plus_one do
|
173
173
|
depends_on :doubled
|
174
|
-
|
174
|
+
execute do doubled + 1 end
|
175
175
|
end
|
176
176
|
end
|
177
177
|
|
178
178
|
outer = Orchestra::Operation.new do
|
179
|
-
|
179
|
+
step inner
|
180
180
|
|
181
181
|
result :squared do
|
182
182
|
depends_on :plus_one
|
183
|
-
|
183
|
+
execute do plus_one ** 2 end
|
184
184
|
end
|
185
185
|
end
|
186
186
|
|
@@ -189,7 +189,7 @@ module OperationTest
|
|
189
189
|
conductor = Orchestra::Conductor.new
|
190
190
|
conductor.add_observer TelemetryRecorder.new telemetry
|
191
191
|
|
192
|
-
result = conductor.
|
192
|
+
result = conductor.execute outer, :number => 4
|
193
193
|
|
194
194
|
assert_equal 81, result
|
195
195
|
|
@@ -216,7 +216,7 @@ module OperationTest
|
|
216
216
|
},
|
217
217
|
},
|
218
218
|
:output => 81,
|
219
|
-
:
|
219
|
+
:operation_name => nil,
|
220
220
|
:service_calls => [],
|
221
221
|
}
|
222
222
|
end
|
data/test/unit/run_list_test.rb
CHANGED
@@ -4,16 +4,16 @@ class RunListTest < Minitest::Test
|
|
4
4
|
|
5
5
|
run_list = builder.build
|
6
6
|
|
7
|
-
assert_equal %w(foo⇒bar bar⇒baz baz⇒qux qux⇒res), run_list.
|
7
|
+
assert_equal %w(foo⇒bar bar⇒baz baz⇒qux qux⇒res), run_list.step_names
|
8
8
|
assert_includes run_list.dependencies, :foo
|
9
9
|
end
|
10
10
|
|
11
|
-
def
|
11
|
+
def test_discards_unnecessary_steps
|
12
12
|
builder['aba⇒cab'] = OpenStruct.new :required_dependencies => [:aba], :optional_dependencies => [], :provisions => [:cab]
|
13
13
|
|
14
14
|
run_list = builder.build
|
15
15
|
|
16
|
-
assert_equal %w(foo⇒bar bar⇒baz baz⇒qux qux⇒res), run_list.
|
16
|
+
assert_equal %w(foo⇒bar bar⇒baz baz⇒qux qux⇒res), run_list.step_names
|
17
17
|
end
|
18
18
|
|
19
19
|
def test_supplying_dependencies
|
@@ -21,16 +21,16 @@ class RunListTest < Minitest::Test
|
|
21
21
|
|
22
22
|
run_list = builder.build
|
23
23
|
|
24
|
-
assert_equal %w(baz⇒qux qux⇒res), run_list.
|
24
|
+
assert_equal %w(baz⇒qux qux⇒res), run_list.step_names
|
25
25
|
refute_includes run_list.dependencies, :foo
|
26
26
|
end
|
27
27
|
|
28
|
-
def
|
29
|
-
assemble_builder
|
28
|
+
def test_steps_that_modify
|
29
|
+
assemble_builder modifying_steps
|
30
30
|
|
31
31
|
run_list = builder.build
|
32
32
|
|
33
|
-
assert_equal %w(foo bar baz), run_list.
|
33
|
+
assert_equal %w(foo bar baz), run_list.step_names
|
34
34
|
end
|
35
35
|
|
36
36
|
def test_reorders_optional_deps_before_mandatory_deps_when_possible
|
@@ -38,7 +38,7 @@ class RunListTest < Minitest::Test
|
|
38
38
|
|
39
39
|
run_list = builder.build
|
40
40
|
|
41
|
-
assert_equal %w(baz+foo bar+baz foo+bar final), run_list.
|
41
|
+
assert_equal %w(baz+foo bar+baz foo+bar final), run_list.step_names
|
42
42
|
assert_equal [], run_list.required_dependencies
|
43
43
|
assert_equal [:bar, :baz, :foo], run_list.optional_dependencies
|
44
44
|
end
|
@@ -58,16 +58,16 @@ class RunListTest < Minitest::Test
|
|
58
58
|
|
59
59
|
private
|
60
60
|
|
61
|
-
def assemble_builder
|
61
|
+
def assemble_builder steps = default_steps
|
62
62
|
@builder ||= begin
|
63
63
|
builder = Orchestra::RunList::Builder.new :res
|
64
|
-
builder.merge!
|
64
|
+
builder.merge! steps
|
65
65
|
builder
|
66
66
|
end
|
67
67
|
end
|
68
68
|
alias_method :builder, :assemble_builder
|
69
69
|
|
70
|
-
def
|
70
|
+
def default_steps
|
71
71
|
{
|
72
72
|
'foo⇒bar' => OpenStruct.new(:required_dependencies => [:foo], :provisions => [:bar], optional_dependencies: []),
|
73
73
|
'bar⇒baz' => OpenStruct.new(:required_dependencies => [:bar], :provisions => [:baz], optional_dependencies: []),
|
@@ -76,7 +76,7 @@ class RunListTest < Minitest::Test
|
|
76
76
|
}
|
77
77
|
end
|
78
78
|
|
79
|
-
def
|
79
|
+
def modifying_steps
|
80
80
|
{
|
81
81
|
'foo' => OpenStruct.new(:required_dependencies => [:shared], :provisions => [:shared], optional_dependencies: []),
|
82
82
|
'bar' => OpenStruct.new(:required_dependencies => [:shared], :provisions => [:shared], optional_dependencies: []),
|
@@ -0,0 +1,122 @@
|
|
1
|
+
class StepTest < Minitest::Test
|
2
|
+
def test_invoking_a_step
|
3
|
+
step = build_simple_step
|
4
|
+
|
5
|
+
assert_equal(
|
6
|
+
{ :bar => 4 },
|
7
|
+
step.execute(:foo => 2, :bar => 2),
|
8
|
+
)
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_providing_a_single_hash
|
12
|
+
step = Orchestra::Step::InlineStep.new(
|
13
|
+
:dependencies => [:foo],
|
14
|
+
:provides => [:bar],
|
15
|
+
:execute_block => lambda { { :bar => (foo * 2) } },
|
16
|
+
)
|
17
|
+
|
18
|
+
assert_equal(
|
19
|
+
{ :bar => 4 },
|
20
|
+
step.execute(:foo => 2),
|
21
|
+
)
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_providing_a_single_hash_that_is_not_the_output
|
25
|
+
step = Orchestra::Step::InlineStep.new(
|
26
|
+
:dependencies => [:foo],
|
27
|
+
:provides => [:bar],
|
28
|
+
:execute_block => lambda { { :baz => (foo * 2) } },
|
29
|
+
)
|
30
|
+
|
31
|
+
assert_equal(
|
32
|
+
{ :bar => { :baz => 4 } },
|
33
|
+
step.execute(:foo => 2),
|
34
|
+
)
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_invoking_a_collection_step
|
38
|
+
step = Orchestra::Step::InlineStep.new(
|
39
|
+
:dependencies => [:foo],
|
40
|
+
:provides => [:bar],
|
41
|
+
:execute_block => lambda { |e| e * 2 },
|
42
|
+
:collection => :foo,
|
43
|
+
)
|
44
|
+
|
45
|
+
assert_equal(
|
46
|
+
{ :bar => [2, 4, 6, 8] },
|
47
|
+
step.execute(:foo => [1, 2, 3, 4]),
|
48
|
+
)
|
49
|
+
end
|
50
|
+
|
51
|
+
def test_defaulting
|
52
|
+
step = build_simple_step
|
53
|
+
|
54
|
+
assert_equal(
|
55
|
+
{ :bar => 8 },
|
56
|
+
step.execute(:foo => 2),
|
57
|
+
)
|
58
|
+
end
|
59
|
+
|
60
|
+
def test_introspecting_dependencies
|
61
|
+
step = build_simple_step
|
62
|
+
|
63
|
+
assert_equal [:foo, :bar], step.dependencies
|
64
|
+
end
|
65
|
+
|
66
|
+
def test_introspecting_mandatory_dependencies
|
67
|
+
step = build_simple_step
|
68
|
+
|
69
|
+
assert_equal [:foo], step.required_dependencies
|
70
|
+
end
|
71
|
+
|
72
|
+
def test_step_fails_to_supply_provisions
|
73
|
+
step = Orchestra::Step::InlineStep.new(
|
74
|
+
:provides => [:foo, :bar, :baz],
|
75
|
+
:execute_block => lambda { nil },
|
76
|
+
)
|
77
|
+
|
78
|
+
error = assert_raises Orchestra::MissingProvisionError do step.execute end
|
79
|
+
|
80
|
+
assert_equal(
|
81
|
+
"failed to supply output: :foo, :bar and :baz",
|
82
|
+
error.message,
|
83
|
+
)
|
84
|
+
end
|
85
|
+
|
86
|
+
def test_cannot_return_nil
|
87
|
+
step = Orchestra::Step::InlineStep.new(
|
88
|
+
:provides => [:foo],
|
89
|
+
:execute_block => lambda do nil end
|
90
|
+
)
|
91
|
+
|
92
|
+
error = assert_raises Orchestra::MissingProvisionError do step.execute end
|
93
|
+
|
94
|
+
assert_equal(
|
95
|
+
"failed to supply output: :foo",
|
96
|
+
error.message,
|
97
|
+
)
|
98
|
+
end
|
99
|
+
|
100
|
+
def test_step_provides_extra_provisions
|
101
|
+
step = Orchestra::Step::InlineStep.new(
|
102
|
+
:provides => [:foo],
|
103
|
+
:execute_block => lambda do { :foo => :bar, :baz => :qux } end,
|
104
|
+
)
|
105
|
+
|
106
|
+
assert_equal(
|
107
|
+
{ :foo => :bar },
|
108
|
+
step.execute,
|
109
|
+
)
|
110
|
+
end
|
111
|
+
|
112
|
+
private
|
113
|
+
|
114
|
+
def build_simple_step
|
115
|
+
Orchestra::Step::InlineStep.new(
|
116
|
+
:defaults => { :bar => lambda { 4 } },
|
117
|
+
:dependencies => [:foo, :bar],
|
118
|
+
:provides => [:bar],
|
119
|
+
:execute_block => lambda { foo * bar },
|
120
|
+
)
|
121
|
+
end
|
122
|
+
end
|
@@ -49,7 +49,7 @@ class ThreadPoolTest < Minitest::Test
|
|
49
49
|
|
50
50
|
def test_performing_work
|
51
51
|
@iterations.times do
|
52
|
-
result = @thread_pool.
|
52
|
+
result = @thread_pool.execute do :deadbeef end
|
53
53
|
|
54
54
|
assert_equal :deadbeef, result
|
55
55
|
end
|
@@ -77,7 +77,7 @@ class ThreadPoolTest < Minitest::Test
|
|
77
77
|
10.times do
|
78
78
|
assert_raises NoMethodError do
|
79
79
|
input.each do |num|
|
80
|
-
@thread_pool.
|
80
|
+
@thread_pool.execute do num * 2 end
|
81
81
|
end
|
82
82
|
end
|
83
83
|
end
|