ntl-orchestra 0.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +16 -0
  3. data/Gemfile +11 -0
  4. data/LICENSE.txt +22 -0
  5. data/README.md +539 -0
  6. data/Rakefile +21 -0
  7. data/bin/rake +16 -0
  8. data/lib/orchestra/conductor.rb +119 -0
  9. data/lib/orchestra/configuration.rb +12 -0
  10. data/lib/orchestra/dsl/nodes.rb +72 -0
  11. data/lib/orchestra/dsl/object_adapter.rb +134 -0
  12. data/lib/orchestra/dsl/operations.rb +108 -0
  13. data/lib/orchestra/errors.rb +44 -0
  14. data/lib/orchestra/node/output.rb +61 -0
  15. data/lib/orchestra/node.rb +130 -0
  16. data/lib/orchestra/operation.rb +49 -0
  17. data/lib/orchestra/performance.rb +137 -0
  18. data/lib/orchestra/recording.rb +83 -0
  19. data/lib/orchestra/run_list.rb +171 -0
  20. data/lib/orchestra/thread_pool.rb +163 -0
  21. data/lib/orchestra/util.rb +98 -0
  22. data/lib/orchestra/version.rb +3 -0
  23. data/lib/orchestra.rb +35 -0
  24. data/orchestra.gemspec +26 -0
  25. data/test/examples/fizz_buzz.rb +32 -0
  26. data/test/examples/invitation_service.rb +118 -0
  27. data/test/integration/multithreading_test.rb +38 -0
  28. data/test/integration/recording_telemetry_test.rb +86 -0
  29. data/test/integration/replayable_operation_test.rb +53 -0
  30. data/test/lib/console.rb +103 -0
  31. data/test/lib/test_runner.rb +19 -0
  32. data/test/support/telemetry_recorder.rb +49 -0
  33. data/test/test_helper.rb +16 -0
  34. data/test/unit/conductor_test.rb +25 -0
  35. data/test/unit/dsl_test.rb +122 -0
  36. data/test/unit/node_test.rb +122 -0
  37. data/test/unit/object_adapter_test.rb +100 -0
  38. data/test/unit/operation_test.rb +224 -0
  39. data/test/unit/run_list_test.rb +131 -0
  40. data/test/unit/thread_pool_test.rb +105 -0
  41. data/test/unit/util_test.rb +20 -0
  42. data/tmp/.keep +0 -0
  43. metadata +159 -0
@@ -0,0 +1,105 @@
1
+ class ThreadPoolTest < Minitest::Test
2
+ def setup
3
+ @thread_pool = Orchestra::ThreadPool.new
4
+ @thread_pool.count = 5
5
+ end
6
+
7
+ def teardown
8
+ @thread_pool.shutdown
9
+ end
10
+
11
+ def test_threads_are_spun_up_asleep
12
+ expected_status = ['sleep'] * 5
13
+ assert_equal expected_status, @thread_pool.status
14
+ end
15
+
16
+ def test_shutting_down
17
+ 100.times do |idx|
18
+ assert_equal 5, @thread_pool.count
19
+ begin
20
+ @thread_pool.shutdown
21
+ rescue Timeout::Error
22
+ flunk "Timeout on iteration #{idx}"
23
+ end
24
+ assert_equal 0, @thread_pool.count
25
+
26
+ @thread_pool.count = 5
27
+ end
28
+ end
29
+
30
+ def test_adjusting_thread_count_is_robust
31
+ iterate = lambda { |delta|
32
+ old_count = @thread_pool.count
33
+ new_count = old_count + delta
34
+ expected_status = ['sleep'] * new_count
35
+ @thread_pool.count = new_count
36
+ assert_equal expected_status, @thread_pool.status, "going from #{old_count} ⇒ #{new_count}"
37
+ }
38
+
39
+ # Add 100 times
40
+ 100.times do iterate.call 1 end
41
+
42
+ # Remove 100 times
43
+ 100.times do iterate.call -1 end
44
+ end
45
+
46
+ def test_performing_work
47
+ 100.times do
48
+ result = @thread_pool.perform do :deadbeef end
49
+
50
+ assert_equal :deadbeef, result
51
+ end
52
+ end
53
+
54
+ def test_enqueueing_work
55
+ jobs = 100.times.map do |num|
56
+ @thread_pool.enqueue do (num + 1) * 2 end
57
+ end
58
+
59
+ result = jobs.map &:wait
60
+
61
+ assert_equal 100, result.uniq.size
62
+ assert_equal 2, result.first
63
+ assert_equal 200, result.last
64
+ end
65
+
66
+ def test_handling_exceptions
67
+ Thread.current.abort_on_exception = false
68
+ old_thread_count = @thread_pool.count
69
+
70
+ input = 100.times.to_a
71
+ input << nil
72
+
73
+ 10.times do
74
+ assert_raises NoMethodError do
75
+ input.each do |num|
76
+ @thread_pool.perform do num * 2 end
77
+ end
78
+ end
79
+ end
80
+
81
+ assert_equal ['sleep'] * old_thread_count, @thread_pool.status
82
+ end
83
+
84
+ def test_observing_jobs
85
+ observer = TestObserver.new
86
+
87
+ job = @thread_pool.enqueue do 2 end
88
+ job.add_observer observer
89
+ job.wait
90
+
91
+ assert_equal [:finished, "2"], observer.results
92
+ end
93
+
94
+ class TestObserver
95
+ attr :results
96
+
97
+ def initialize
98
+ @results = []
99
+ end
100
+
101
+ def update event, payload
102
+ @results = [event, payload.inspect]
103
+ end
104
+ end
105
+ end
@@ -0,0 +1,20 @@
1
+ class UtilTest < Minitest::Test
2
+ def test_snake_casing
3
+ assert_equal "foo/bar", Orchestra::Util.to_snake_case("Foo::Bar")
4
+ assert_equal "foo_bar", Orchestra::Util.to_snake_case("FOOBar")
5
+ end
6
+
7
+ def test_recursive_symbolizing
8
+ expected_hsh = {
9
+ foo: [{
10
+ bar: { baz: 'qux' },
11
+ },{
12
+ ping: ['pong'],
13
+ }],
14
+ }
15
+
16
+ actual_hsh = Orchestra::Util.recursively_symbolize JSON.load JSON.dump expected_hsh
17
+
18
+ assert_equal expected_hsh, actual_hsh
19
+ end
20
+ end
data/tmp/.keep ADDED
File without changes
metadata ADDED
@@ -0,0 +1,159 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ntl-orchestra
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.9.0
5
+ platform: ruby
6
+ authors:
7
+ - ntl
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-12-03 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: invokr
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.6'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.6'
41
+ - !ruby/object:Gem::Dependency
42
+ name: pry
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ description: Orchestra is an orchestration framework for designing complex operations
70
+ in an object oriented fashion.
71
+ email:
72
+ - nathanladd+github@gmail.com
73
+ executables: []
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - ".gitignore"
78
+ - Gemfile
79
+ - LICENSE.txt
80
+ - README.md
81
+ - Rakefile
82
+ - bin/rake
83
+ - lib/orchestra.rb
84
+ - lib/orchestra/conductor.rb
85
+ - lib/orchestra/configuration.rb
86
+ - lib/orchestra/dsl/nodes.rb
87
+ - lib/orchestra/dsl/object_adapter.rb
88
+ - lib/orchestra/dsl/operations.rb
89
+ - lib/orchestra/errors.rb
90
+ - lib/orchestra/node.rb
91
+ - lib/orchestra/node/output.rb
92
+ - lib/orchestra/operation.rb
93
+ - lib/orchestra/performance.rb
94
+ - lib/orchestra/recording.rb
95
+ - lib/orchestra/run_list.rb
96
+ - lib/orchestra/thread_pool.rb
97
+ - lib/orchestra/util.rb
98
+ - lib/orchestra/version.rb
99
+ - orchestra.gemspec
100
+ - test/examples/fizz_buzz.rb
101
+ - test/examples/invitation_service.rb
102
+ - test/integration/multithreading_test.rb
103
+ - test/integration/recording_telemetry_test.rb
104
+ - test/integration/replayable_operation_test.rb
105
+ - test/lib/console.rb
106
+ - test/lib/test_runner.rb
107
+ - test/support/telemetry_recorder.rb
108
+ - test/test_helper.rb
109
+ - test/unit/conductor_test.rb
110
+ - test/unit/dsl_test.rb
111
+ - test/unit/node_test.rb
112
+ - test/unit/object_adapter_test.rb
113
+ - test/unit/operation_test.rb
114
+ - test/unit/run_list_test.rb
115
+ - test/unit/thread_pool_test.rb
116
+ - test/unit/util_test.rb
117
+ - tmp/.keep
118
+ homepage: https://github.com/ntl/orchestra
119
+ licenses:
120
+ - MIT
121
+ metadata: {}
122
+ post_install_message:
123
+ rdoc_options: []
124
+ require_paths:
125
+ - lib
126
+ required_ruby_version: !ruby/object:Gem::Requirement
127
+ requirements:
128
+ - - ">="
129
+ - !ruby/object:Gem::Version
130
+ version: '0'
131
+ required_rubygems_version: !ruby/object:Gem::Requirement
132
+ requirements:
133
+ - - ">="
134
+ - !ruby/object:Gem::Version
135
+ version: '0'
136
+ requirements: []
137
+ rubyforge_project:
138
+ rubygems_version: 2.2.2
139
+ signing_key:
140
+ specification_version: 4
141
+ summary: Orchestrate complex operations with ease.
142
+ test_files:
143
+ - test/examples/fizz_buzz.rb
144
+ - test/examples/invitation_service.rb
145
+ - test/integration/multithreading_test.rb
146
+ - test/integration/recording_telemetry_test.rb
147
+ - test/integration/replayable_operation_test.rb
148
+ - test/lib/console.rb
149
+ - test/lib/test_runner.rb
150
+ - test/support/telemetry_recorder.rb
151
+ - test/test_helper.rb
152
+ - test/unit/conductor_test.rb
153
+ - test/unit/dsl_test.rb
154
+ - test/unit/node_test.rb
155
+ - test/unit/object_adapter_test.rb
156
+ - test/unit/operation_test.rb
157
+ - test/unit/run_list_test.rb
158
+ - test/unit/thread_pool_test.rb
159
+ - test/unit/util_test.rb