vuderacha-syrup 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,244 @@
1
+ require 'syrup/runner'
2
+
3
+ describe Syrup::Runner do
4
+ before(:each) do
5
+ # Wire all the stubs
6
+ @app_name = 'mytestapp'
7
+ @config_store = mock('config_store')
8
+ @app = mock('application')
9
+ @config_store.stub!(:applications).and_return({'mytestapp' => @app})
10
+ @logger = mock('logger', :null_object => true)
11
+
12
+ # Create the runner
13
+ @runner = Syrup::Runner.new(@config_store, @logger)
14
+ end
15
+
16
+ it "should run the default fabric when neither the application nor the global environment define a fabric" do
17
+ @app.stub!(:properties).and_return({})
18
+ @config_store.stub!(:properties).and_return({})
19
+ @app.stub!(:fabric).and_return nil
20
+ @config_store.stub!(:fabric).and_return nil
21
+ @app.stub!(:app).and_return nil
22
+ @app.stub!(:start_parameters).and_return []
23
+
24
+ SyrupKernelSim.simulating do
25
+ @runner.run @app_name
26
+ end
27
+
28
+ SyrupKernelSim.load_list.length.should == 1
29
+ File.expand_path(SyrupKernelSim.load_list[0]).should == File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'lib', 'syrup', 'fabrics', 'default.rb'))
30
+ end
31
+
32
+ it "should run the global environment fabric if the application does not specify one" do
33
+ @app.stub!(:properties).and_return({})
34
+ @config_store.stub!(:properties).and_return({})
35
+ @app.stub!(:fabric).and_return nil
36
+ @config_store.stub!(:fabric).and_return 'globalfabric.rb'
37
+ @app.stub!(:app).and_return nil
38
+ @app.stub!(:start_parameters).and_return []
39
+
40
+ SyrupKernelSim.simulating do
41
+ @runner.run @app_name
42
+ end
43
+
44
+ SyrupKernelSim.load_list.should == ['globalfabric.rb']
45
+ end
46
+
47
+ it "should run the application fabric even if the global environment specifies one" do
48
+ @app.stub!(:properties).and_return({})
49
+ @config_store.stub!(:properties).and_return({})
50
+ @app.stub!(:fabric).and_return 'appfabric.rb'
51
+ @config_store.stub!(:fabric).and_return 'globalfabric.rb'
52
+ @app.stub!(:app).and_return nil
53
+ @app.stub!(:start_parameters).and_return []
54
+
55
+ SyrupKernelSim.simulating do
56
+ @runner.run @app_name
57
+ end
58
+
59
+ SyrupKernelSim.load_list.should == ['appfabric.rb']
60
+ end
61
+
62
+ it "should run the application fabric even if the global environment doesn't specify one" do
63
+ @app.stub!(:properties).and_return({})
64
+ @config_store.stub!(:properties).and_return({})
65
+ @app.stub!(:fabric).and_return 'appfabric.rb'
66
+ @config_store.stub!(:fabric).and_return nil
67
+ @app.stub!(:app).and_return nil
68
+ @app.stub!(:start_parameters).and_return []
69
+
70
+ SyrupKernelSim.simulating do
71
+ @runner.run @app_name
72
+ end
73
+
74
+ SyrupKernelSim.load_list.should == ['appfabric.rb']
75
+ end
76
+
77
+ it "should not support invoking the application outside of the fabric" do
78
+ lambda {@runner.run_application}.should raise_error("Cannot execute application outside of Fabric")
79
+ end
80
+
81
+ it "should support invoking the application whilst the fabric is running" do
82
+ @app.stub!(:properties).and_return({})
83
+ @config_store.stub!(:properties).and_return({})
84
+ @app.stub!(:fabric).and_return 'appfabric.rb'
85
+ @config_store.stub!(:fabric).and_return nil
86
+ @app.stub!(:app).and_return 'myapp.rb'
87
+ @app.stub!(:start_parameters).and_return []
88
+
89
+ SyrupKernelSim.simulating do
90
+ SyrupKernelSim.register_load_handler do |name|
91
+ # Run the application if we're simulating the run of the fabric
92
+ Syrup::Runner.run_application if name == 'appfabric.rb'
93
+ end
94
+
95
+ @runner.run @app_name
96
+ end
97
+
98
+ SyrupKernelSim.load_list.should == ['appfabric.rb', 'myapp.rb']
99
+ end
100
+
101
+ it "should overwrite ARGV whilst the application is running" do
102
+ @app.stub!(:properties).and_return({})
103
+ @config_store.stub!(:properties).and_return({})
104
+ @app.stub!(:fabric).and_return 'appfabric.rb'
105
+ @config_store.stub!(:fabric).and_return nil
106
+ @app.stub!(:app).and_return 'myapp.rb'
107
+ @app.stub!(:start_parameters).and_return ['a', 'b']
108
+
109
+ SyrupKernelSim.simulating do
110
+ SyrupKernelSim.register_load_handler do |name|
111
+ # Ensure that ARGV has been set properly
112
+ ARGV.should == ['a', 'b']
113
+ end
114
+
115
+ @runner.run @app_name
116
+ end
117
+ end
118
+
119
+ it "should restore ARGV after the application has run" do
120
+ @app.stub!(:properties).and_return({})
121
+ @config_store.stub!(:properties).and_return({})
122
+ @app.stub!(:fabric).and_return 'appfabric.rb'
123
+ @config_store.stub!(:fabric).and_return nil
124
+ @app.stub!(:app).and_return 'myapp.rb'
125
+ @app.stub!(:start_parameters).and_return ['a', 'b']
126
+
127
+ SyrupKernelSim.simulating do
128
+ @runner.run @app_name
129
+ end
130
+
131
+ ARGV.should_not == ['a', 'b']
132
+ end
133
+
134
+ it "should set the global properties" do
135
+ @app.stub!(:properties).and_return({})
136
+ @config_store.stub!(:properties).and_return({'A' => 1, 'B' => 2})
137
+ @app.stub!(:fabric).and_return 'appfabric.rb'
138
+ @config_store.stub!(:fabric).and_return nil
139
+ @app.stub!(:app).and_return nil
140
+ @app.stub!(:start_parameters).and_return []
141
+
142
+ SyrupKernelSim.simulating do
143
+ @runner.run @app_name
144
+ end
145
+
146
+ SyrupKernelSim.consts.length.should == 2
147
+ SyrupKernelSim.consts['A'].should == 1
148
+ SyrupKernelSim.consts['B'].should == 2
149
+ end
150
+
151
+ it "should set the application properties" do
152
+ @app.stub!(:properties).and_return({'A' => 1, 'B' => 2})
153
+ @config_store.stub!(:properties).and_return({})
154
+ @app.stub!(:fabric).and_return 'appfabric.rb'
155
+ @config_store.stub!(:fabric).and_return nil
156
+ @app.stub!(:app).and_return nil
157
+ @app.stub!(:start_parameters).and_return []
158
+
159
+ SyrupKernelSim.simulating do
160
+ @runner.run @app_name
161
+ end
162
+
163
+ SyrupKernelSim.consts.length.should == 2
164
+ SyrupKernelSim.consts['A'].should == 1
165
+ SyrupKernelSim.consts['B'].should == 2
166
+ end
167
+
168
+ it "should mix global and application properties, and application properties should take precendence" do
169
+ @app.stub!(:properties).and_return({'B' => 3, 'C' => 4})
170
+ @config_store.stub!(:properties).and_return({'A' => 1, 'B' => 2})
171
+ @app.stub!(:fabric).and_return 'appfabric.rb'
172
+ @config_store.stub!(:fabric).and_return nil
173
+ @app.stub!(:app).and_return nil
174
+ @app.stub!(:start_parameters).and_return []
175
+
176
+ SyrupKernelSim.simulating do
177
+ @runner.run @app_name
178
+ end
179
+
180
+ SyrupKernelSim.consts.length.should == 3
181
+ SyrupKernelSim.consts['A'].should == 1
182
+ SyrupKernelSim.consts['B'].should == 3
183
+ SyrupKernelSim.consts['C'].should == 4
184
+ end
185
+ end
186
+
187
+ class SyrupKernelSim
188
+ def self.simulating
189
+ load_list.clear
190
+ @simulating = true
191
+ yield ensure @simulating, @load_handler = false, nil
192
+ end
193
+
194
+ def self.is_simulating?
195
+ @simulating
196
+ end
197
+
198
+ def self.file_loaded(name)
199
+ load_list << name
200
+
201
+ # Invoke any registered handlers
202
+ if @load_handler
203
+ @load_handler.call(name)
204
+ end
205
+ end
206
+
207
+ def self.load_list
208
+ @load_list ||= []
209
+ end
210
+
211
+ def self.consts
212
+ @consts ||= {}
213
+ end
214
+
215
+ def self.register_load_handler(&handler)
216
+ raise "Cannot add load handler when not simulating!" if not @simulating
217
+
218
+ @load_handler = handler
219
+ end
220
+ end
221
+
222
+ # Patch Kernel so we can intercept load events
223
+ module Kernel
224
+ alias :syrup_original_load :load
225
+
226
+ def load(name)
227
+ # Just forward to the real method if we're not simulating
228
+ return syrup_original_load(name) if not SyrupKernelSim.is_simulating?
229
+
230
+ # Oterhwise, record the value, and tell the simulator to invoke any handler
231
+ SyrupKernelSim.file_loaded(name) if SyrupKernelSim.is_simulating?
232
+ end
233
+ end
234
+ class Module
235
+ alias :syrup_original_const_set :const_set
236
+
237
+ def const_set(k, v)
238
+ # Just forward to the real method if we're not simulating
239
+ return syrup_original_const_set(k, v) if not SyrupKernelSim.is_simulating?
240
+
241
+ # Otherwise, record the value
242
+ SyrupKernelSim.consts[k] = v
243
+ end
244
+ end
@@ -0,0 +1,8 @@
1
+ $:.push File.join(File.dirname(__FILE__), '..', 'lib')
2
+ require 'syrup'
3
+
4
+ describe "Syrup::Application" do
5
+ it "should report a version" do
6
+ Syrup::Application.version.should_not be_nil
7
+ end
8
+ end
metadata ADDED
@@ -0,0 +1,73 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: vuderacha-syrup
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Paul Jones
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-03-28 00:00:00 -07:00
13
+ default_executable: syrup
14
+ dependencies: []
15
+
16
+ description: Syrup is a process manager for working with services. It provides the ability to deploy and manage long-running services.
17
+ email: pauljones23@gmail.com
18
+ executables:
19
+ - syrup
20
+ extensions: []
21
+
22
+ extra_rdoc_files:
23
+ - README.rdoc
24
+ files:
25
+ - Rakefile
26
+ - README.rdoc
27
+ - VERSION.yml
28
+ - bin/syrup
29
+ - lib/launcher.rb
30
+ - lib/syrup
31
+ - lib/syrup/config_store.rb
32
+ - lib/syrup/daemon.rb
33
+ - lib/syrup/executor.rb
34
+ - lib/syrup/fabric_support.rb
35
+ - lib/syrup/fabrics
36
+ - lib/syrup/fabrics/default.rb
37
+ - lib/syrup/fabrics/rack.rb
38
+ - lib/syrup/manager.rb
39
+ - lib/syrup/runner.rb
40
+ - lib/syrup.rb
41
+ - spec/syrup
42
+ - spec/syrup/config_store_spec.rb
43
+ - spec/syrup/runner_spec.rb
44
+ - spec/syrup_spec.rb
45
+ has_rdoc: true
46
+ homepage: http://github.com/vuderacha/syrup/
47
+ post_install_message:
48
+ rdoc_options:
49
+ - --inline-source
50
+ - --charset=UTF-8
51
+ require_paths:
52
+ - lib
53
+ required_ruby_version: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ version: "0"
58
+ version:
59
+ required_rubygems_version: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ version: "0"
64
+ version:
65
+ requirements: []
66
+
67
+ rubyforge_project:
68
+ rubygems_version: 1.2.0
69
+ signing_key:
70
+ specification_version: 2
71
+ summary: Ruby service application manager.
72
+ test_files: []
73
+