carioca 1.4 → 2.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/main.yml +18 -0
- data/.gitignore +11 -0
- data/.rspec +3 -0
- data/Gemfile +6 -1
- data/Gemfile.lock +49 -0
- data/README.md +12 -220
- data/Rakefile +5 -66
- data/bin/console +15 -0
- data/bin/setup +8 -0
- data/carioca.gemspec +32 -23
- data/config/locales/en.yml +15 -0
- data/config/locales/fr.yml +19 -0
- data/lib/carioca/configuration.rb +47 -0
- data/lib/carioca/constants.rb +45 -0
- data/lib/carioca/container.rb +16 -0
- data/lib/carioca/dependencies.rb +19 -0
- data/lib/carioca/helpers.rb +44 -31
- data/lib/carioca/mixin.rb +32 -0
- data/lib/carioca/{tasks/rake.rb → rake/manage.rb} +2 -4
- data/lib/carioca/rake/tasks/registry.tasks +57 -0
- data/lib/carioca/registry.rb +93 -0
- data/lib/carioca/registry_file.rb +62 -0
- data/lib/carioca/services/config.rb +140 -0
- data/lib/carioca/services/i18n.rb +20 -0
- data/lib/carioca/services/init.rb +2 -0
- data/lib/carioca/validator.rb +49 -0
- data/lib/carioca.rb +2 -319
- data/samples/Rakefile +2 -0
- data/samples/config/carioca.registry +22 -0
- data/samples/config/locales/en.yml +2 -0
- data/samples/config/locales/es.yml +2 -0
- data/samples/config/locales/fr.yml +2 -0
- data/samples/config/settings.yml +24 -0
- data/samples/test.rb +71 -0
- metadata +46 -187
- data/AUTHORS +0 -8
- data/COPYRIGHT +0 -24
- data/ChangeLog +0 -10
- data/INSTALL +0 -7
- data/doc/manual.rdoc +0 -225
- data/lib/carioca/exceptions.rb +0 -9
- data/lib/carioca/private.rb +0 -168
- data/lib/carioca/services/configuration.rb +0 -203
- data/lib/carioca/services/debug.rb +0 -71
- data/lib/carioca/services/logger.rb +0 -58
- data/lib/carioca/services.rb +0 -143
- data/lib/carioca/tasks/registry_init.rake +0 -12
- data/spec/carioca_spec.rb +0 -468
- data/spec/config/.config +0 -14
- data/spec/config/services.registry +0 -55
- data/spec/init_spec.rb +0 -2
- data/spec/samples/dummy.rb +0 -11
- data/spec/samples/otherdummy.rb +0 -11
- data/spec/samples/requireddummy.rb +0 -11
- data/spec/spec_helper.rb +0 -18
- data/ultragreen_roodi_coding_convention.yml +0 -25
data/spec/carioca_spec.rb
DELETED
@@ -1,468 +0,0 @@
|
|
1
|
-
# coding: utf-8
|
2
|
-
require'rubygems'
|
3
|
-
require'rspec'
|
4
|
-
require 'carioca'
|
5
|
-
require 'fileutils'
|
6
|
-
|
7
|
-
$debug = true
|
8
|
-
|
9
|
-
describe Carioca do
|
10
|
-
|
11
|
-
before :all do
|
12
|
-
FileUtils.rm_rf("/tmp/log.file")
|
13
|
-
File::unlink('/tmp/dorsal/ringserver.pid') if File::exist?('/tmp/dorsal/ringserver.pid')
|
14
|
-
File::unlink('/tmp/dorsal/service-distdummy.pid') if File::exist?('/tmp/dorsal/service-distdummy.pid')
|
15
|
-
pid = `ps aux|grep ruby|grep -v grep |grep 'Ultragreen Ring Server'|awk '{ print $2}'`
|
16
|
-
unless pid.empty? then
|
17
|
-
res = `kill -TERM #{pid.chomp}`
|
18
|
-
end
|
19
|
-
pid = `ps aux|grep ruby|grep -v grep |grep 'a dummy test service'|awk '{ print $2}'`
|
20
|
-
unless pid.empty? then
|
21
|
-
res = `kill -TERM #{pid.chomp}`
|
22
|
-
end
|
23
|
-
$carioca = Carioca::Services::Registry.init :file => 'spec/config/services.registry', :debug => $debug
|
24
|
-
end
|
25
|
-
|
26
|
-
subject { Carioca }
|
27
|
-
it { should be_an_instance_of Module}
|
28
|
-
context "Carioca::Services" do
|
29
|
-
subject { Carioca::Services }
|
30
|
-
it { should be_an_instance_of Module }
|
31
|
-
end
|
32
|
-
|
33
|
-
context "Carioca::Services::Registry" do
|
34
|
-
subject { $carioca }
|
35
|
-
context "#init" do
|
36
|
-
it "should be a Singleton" do
|
37
|
-
carioca1 = Carioca::Services::Registry.init
|
38
|
-
carioca2 = Carioca::Services::Registry.init
|
39
|
-
test = (carioca1.inspect == carioca2.inspect)
|
40
|
-
test.should be true
|
41
|
-
end
|
42
|
-
|
43
|
-
|
44
|
-
it { should be_an_instance_of Carioca::Services::Registry }
|
45
|
-
it { $carioca.list.keys.should include "logger" }
|
46
|
-
it "should log Registry starting and logger init if debug mode", :if => $debug do
|
47
|
-
open('/tmp/log.file').grep(/DEBUG -- Carioca: Registry started, service logger preloaded/).size.should eq 1
|
48
|
-
end
|
49
|
-
it "should not log Registry starting and logger init if not debug mode", :unless => $debug do
|
50
|
-
open('/tmp/log.file').grep(/DEBUG -- Carioca: Registry started, service logger preloaded/).size.should eq 0
|
51
|
-
end
|
52
|
-
|
53
|
-
|
54
|
-
it "should be possible to log with this primary service" do
|
55
|
-
$logger = subject.get_service :name => 'logger'
|
56
|
-
$logger.info("test").should eq true
|
57
|
-
open('/tmp/log.file').grep(/INFO -- : test/).size.should eq 1
|
58
|
-
$logger.warn("test").should eq true
|
59
|
-
open('/tmp/log.file').grep(/WARN -- : test/).size.should eq 1
|
60
|
-
$logger.error("test").should eq true
|
61
|
-
open('/tmp/log.file').grep(/ERROR -- : test/).size.should eq 1
|
62
|
-
$logger.fatal("test").should eq true
|
63
|
-
open('/tmp/log.file').grep(/FATAL -- : test/).size.should eq 1
|
64
|
-
$logger.info("Program") { "running" }
|
65
|
-
open('/tmp/log.file').grep(/INFO -- Program: running/).size.should eq 1
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
context "attributs" do
|
70
|
-
context "#debug (RW)" do
|
71
|
-
it { should respond_to :debug }
|
72
|
-
it { should respond_to :debug= }
|
73
|
-
it "should be true if debug mode", :if => $debug do
|
74
|
-
subject.debug.should eq true
|
75
|
-
end
|
76
|
-
it "should be false if not debug mode", :unless => $debug do
|
77
|
-
subject.debug.should eq false
|
78
|
-
end
|
79
|
-
end
|
80
|
-
|
81
|
-
context "#name (RW)" do
|
82
|
-
it { should respond_to :name }
|
83
|
-
it { should respond_to :name= }
|
84
|
-
it { $carioca.name.should be_an_instance_of String }
|
85
|
-
it { $carioca.name.should eq 'Carioca'}
|
86
|
-
end
|
87
|
-
|
88
|
-
context "#list (RO)" do
|
89
|
-
it { should respond_to :list }
|
90
|
-
it { should_not respond_to :list= }
|
91
|
-
it { subject.list.should be_an_instance_of Hash }
|
92
|
-
it { $carioca.list.keys.sort.should eq ["configuration", "debug", "distdummy","dorsal", "dummy", "logger", "uuid", "uuidbygemfile"] }
|
93
|
-
end
|
94
|
-
|
95
|
-
context "#loaded_services (RO)" do
|
96
|
-
it { should respond_to :loaded_services }
|
97
|
-
it { should_not respond_to :loaded_services= }
|
98
|
-
it { subject.loaded_services.should be_an_instance_of Hash }
|
99
|
-
it { $carioca.loaded_services.keys.should eq ["logger"] }
|
100
|
-
end
|
101
|
-
|
102
|
-
context "#registry_filename" do
|
103
|
-
it { should respond_to :registry_filename }
|
104
|
-
it { should respond_to :registry_filename= }
|
105
|
-
it { subject.registry_filename.should be_an_instance_of String }
|
106
|
-
it { $carioca.registry_filename.should eq "spec/config/services.registry" }
|
107
|
-
end
|
108
|
-
|
109
|
-
end
|
110
|
-
|
111
|
-
context "#start_service" do
|
112
|
-
it { should respond_to :start_service }
|
113
|
-
it { should respond_to :get_service }
|
114
|
-
|
115
|
-
context "Builtin services" do
|
116
|
-
context "Logger service" do
|
117
|
-
it "should be possible to get the builtin logger service" do
|
118
|
-
$logger = subject.get_service :name => 'logger'
|
119
|
-
end
|
120
|
-
it "should log if debug mode", :if => $debug do
|
121
|
-
open('/tmp/log.file').grep(/DEBUG -- Carioca: getting service logger/).size.should >= 1
|
122
|
-
end
|
123
|
-
it "should not log if debug mode", :unless => $debug do
|
124
|
-
open('/tmp/log.file').grep(/DEBUG -- Carioca: getting service logger/).size.should eq 0
|
125
|
-
end
|
126
|
-
end
|
127
|
-
|
128
|
-
|
129
|
-
context "Debug Proxy Service" do
|
130
|
-
it "should start the builtin service debug" do
|
131
|
-
myservice = subject.start_service :name => 'debug' , :params => {:service => 'dummy'}
|
132
|
-
myservice.test 'titi'
|
133
|
-
end
|
134
|
-
it { subject.list.keys.should include "debug" }
|
135
|
-
it "should log a proxy service log sequence", :if => $debug do
|
136
|
-
open('/tmp/log.file').grep(/DEBUG -- ProxyDebug: BEGIN CALL for mapped service dummy/).size.should eq 1
|
137
|
-
open('/tmp/log.file').grep(/DEBUG -- ProxyDebug: called: test/).size.should eq 1
|
138
|
-
open('/tmp/log.file').grep(/DEBUG -- ProxyDebug: args : titi/).size.should eq 1
|
139
|
-
open('/tmp/log.file').grep(/DEBUG -- ProxyDebug: => returned: OK/).size.should eq 1
|
140
|
-
open('/tmp/log.file').grep(/DEBUG -- ProxyDebug: END CALL/).size.should eq 1
|
141
|
-
end
|
142
|
-
end
|
143
|
-
|
144
|
-
context "Configuration Service" do
|
145
|
-
it "should start the builtin configuration service" do
|
146
|
-
$conf = subject.start_service :name => 'configuration'
|
147
|
-
end
|
148
|
-
it "should access flat settings" do
|
149
|
-
$conf.settings.context1.key0.should eq 'value'
|
150
|
-
$conf.settings.context1.node.key1 eq 'value1'
|
151
|
-
$conf.settings.context1.node.key2 eq 'value2'
|
152
|
-
$conf.settings.context2.key0.should eq 'value'
|
153
|
-
$conf.settings.context2.node.key1 eq 'value3'
|
154
|
-
$conf.settings.context2.node.key2 eq 'value4'
|
155
|
-
end
|
156
|
-
it "should access contextualized settings" do
|
157
|
-
$conf = subject.restart_service :name => 'configuration', :params => { :context => 'context2' }
|
158
|
-
$conf.settings.key0.should eq 'value'
|
159
|
-
$conf.settings.node.key1 eq 'value3'
|
160
|
-
$conf.settings.node.key2 eq 'value4'
|
161
|
-
end
|
162
|
-
it "should access inherited settings from YAML" do
|
163
|
-
$conf = subject.restart_service :name => 'configuration', :params => { :context => 'context3' }
|
164
|
-
$conf.settings.key0.should eq 'value'
|
165
|
-
$conf.settings.node.key1 eq 'value3'
|
166
|
-
$conf.settings.node.key2 eq 'value4'
|
167
|
-
end
|
168
|
-
it "should be possible to override a config value" do
|
169
|
-
$conf.settings.node.key2 = 'value8'
|
170
|
-
$conf.settings.node.key2.should eq 'value8'
|
171
|
-
$conf.settings[:node][:key2] = 'value6'
|
172
|
-
$conf.settings[:node][:key2].should eq 'value6'
|
173
|
-
end
|
174
|
-
it { $conf.should respond_to :config_file }
|
175
|
-
it { $conf.should respond_to :config_file= }
|
176
|
-
it { $conf.should respond_to :save! }
|
177
|
-
|
178
|
-
it "should be saved in other file" do
|
179
|
-
$conf.config_file = '/tmp/.config'
|
180
|
-
$conf.save!.should be true
|
181
|
-
|
182
|
-
end
|
183
|
-
it "should stop the configuration service" do
|
184
|
-
subject.stop_service({:name => 'configuration'}).should eq true
|
185
|
-
end
|
186
|
-
end
|
187
|
-
|
188
|
-
end
|
189
|
-
|
190
|
-
context "External services" do
|
191
|
-
|
192
|
-
it "should start a dummy service precised in registry YAML configuration" do
|
193
|
-
|
194
|
-
$dummy = subject.start_service :name => 'dummy'
|
195
|
-
$dummy.should be_an_instance_of ExternalServices::Dummy
|
196
|
-
end
|
197
|
-
it { subject.list.keys.should include "dummy" }
|
198
|
-
it "should be possible to use test method of the dummy service, and return 'OK'" do
|
199
|
-
$dummy.test.should eq 'OK'
|
200
|
-
end
|
201
|
-
it "should start a gem service precised in registry YAML configuration" do
|
202
|
-
$uuid = subject.start_service :name => 'uuid'
|
203
|
-
$uuid.should be_an_instance_of UUID
|
204
|
-
end
|
205
|
-
it { subject.list.keys.should include "uuid" }
|
206
|
-
it "should be possible to execute a method with the gem service" do
|
207
|
-
$uuid.generate.should be_a_kind_of String
|
208
|
-
end
|
209
|
-
it "should start a file in gem service precised by gem_file in registry YAML configuration" do
|
210
|
-
$uuidgemfile = subject.start_service :name => 'uuidbygemfile'
|
211
|
-
$uuidgemfile.should be_an_instance_of UUID
|
212
|
-
end
|
213
|
-
it { subject.list.keys.should include "uuidbygemfile" }
|
214
|
-
it { subject.loaded_services.keys.should include "uuidbygemfile" }
|
215
|
-
it "should be possible to execute a method with the gem_file service" do
|
216
|
-
$uuidgemfile.generate.should be_a_kind_of String
|
217
|
-
subject.stop_service :name => "uuidbygemfile"
|
218
|
-
end
|
219
|
-
|
220
|
-
|
221
|
-
context "Distributed service" do
|
222
|
-
it "should be possible to execute a distributed service" do
|
223
|
-
$dummy_dist = subject.start_service :name => 'distdummy'
|
224
|
-
end
|
225
|
-
it "should exist a processus Ring server" do
|
226
|
-
File::exist?('/tmp/dorsal/ringserver.pid').should be true
|
227
|
-
pid = `ps aux|grep ruby|grep -v grep |grep 'Ultragreen Ring Server'|awk '{ print $2}'`
|
228
|
-
pid.should_not be_empty
|
229
|
-
end
|
230
|
-
it "should log if debug mode", :if => $debug do
|
231
|
-
open('/tmp/log.file').grep(/DEBUG -- Carioca: Starting new Ring Server/).size.should >= 1
|
232
|
-
end
|
233
|
-
it "should not log if debug mode", :unless => $debug do
|
234
|
-
open('/tmp/log.file').grep(/DEBUG -- Carioca: Starting new Ring Server/).size.should eq 0
|
235
|
-
end
|
236
|
-
it "should include 'distdummy' in @loaded_services.keys" do
|
237
|
-
subject.loaded_services.should include "distdummy"
|
238
|
-
end
|
239
|
-
it "should distdummy be a DRbObject" do
|
240
|
-
$dummy_dist.should be_a_kind_of DRb::DRbObject
|
241
|
-
end
|
242
|
-
it "should be possible to use test method of the distributed dummy service, and return 'OK'" do
|
243
|
-
$dummy_dist.test.should eq 'OK'
|
244
|
-
end
|
245
|
-
end
|
246
|
-
|
247
|
-
end
|
248
|
-
end
|
249
|
-
|
250
|
-
|
251
|
-
context "#stop_service" do
|
252
|
-
it { should respond_to :stop_service }
|
253
|
-
it "should raise ArgumentError if the option hash argument passed not include :name" do
|
254
|
-
lambda { subject.stop_service }.should raise_error ArgumentError
|
255
|
-
lambda { subject.stop_service(:notname => 'debug') }.should raise_error ArgumentError
|
256
|
-
end
|
257
|
-
it "should return true if service really stop" do
|
258
|
-
subject.stop_service({:name => 'dummy'}).should eq true
|
259
|
-
end
|
260
|
-
it "should log if debug mode", :if => $debug do
|
261
|
-
open('/tmp/log.file').grep(/DEBUG -- Carioca: Service dummy stopped/).size.should >= 1
|
262
|
-
end
|
263
|
-
it "should not log if debug mode", :unless => $debug do
|
264
|
-
open('/tmp/log.file').grep(/DEBUG -- Carioca: Service dummy stopped/).size.should eq 0
|
265
|
-
end
|
266
|
-
it "should return false if service not already running" do
|
267
|
-
subject.stop_service({:name => 'dum'}).should eq false
|
268
|
-
end
|
269
|
-
it "should log if debug mode and service not loaded", :if => $debug do
|
270
|
-
open('/tmp/log.file').grep(/DEBUG -- Carioca: Service dum not loaded/).size.should >= 1
|
271
|
-
end
|
272
|
-
it "should not log if debug mode and service not loaded", :unless => $debug do
|
273
|
-
open('/tmp/log.file').grep(/DEBUG -- Carioca: Service dum not loaded/).size.should eq 0
|
274
|
-
end
|
275
|
-
it "should return false if service :name is logger" do
|
276
|
-
subject.stop_service({:name => 'logger'}).should eq false
|
277
|
-
end
|
278
|
-
it "should log if debug mode and service :name is logger", :if => $debug do
|
279
|
-
open('/tmp/log.file').grep(/DEBUG -- Carioca: Service logger can't be unloaded/).size.should >= 1
|
280
|
-
end
|
281
|
-
it "should not log if debug mode and service :name is logger", :unless => $debug do
|
282
|
-
open('/tmp/log.file').grep(/DEBUG -- Carioca: Service logger can't be unloaded/).size.should eq 0
|
283
|
-
end
|
284
|
-
|
285
|
-
context "Distributed Service" do
|
286
|
-
it "should be possible to stop a distributed service" do
|
287
|
-
$dummy_dist = subject.start_service :name => 'distdummy'
|
288
|
-
subject.stop_service({:name => 'distdummy'}).should be true
|
289
|
-
end
|
290
|
-
it "should not exist forked daemon instance for this stopped service" do
|
291
|
-
pid = `ps aux|grep ruby|grep -v grep |grep 'a dummy test service'|awk '{ print $2}'`
|
292
|
-
pid.should be_empty
|
293
|
-
end
|
294
|
-
it "should not exist the pid file of this stopped services" do
|
295
|
-
File::exist?('/tmp/dorsal/service-distdummy.pid').should be false
|
296
|
-
$dummy_dist = subject.start_service :name => 'distdummy'
|
297
|
-
end
|
298
|
-
end
|
299
|
-
|
300
|
-
end
|
301
|
-
|
302
|
-
context "#restart_service" do
|
303
|
-
it { should respond_to :start_service }
|
304
|
-
it "should start an instance of a service like dummy_one" do
|
305
|
-
$dummy = subject.restart_service :name => 'dummy_one'
|
306
|
-
$dummy = subject.restart_service :name => 'dummy'
|
307
|
-
$dummy.should be_an_instance_of ExternalServices::Dummy
|
308
|
-
$carioca.loaded_services.keys.should include 'dummy'
|
309
|
-
$carioca.loaded_services.keys.should include 'dummy_one'
|
310
|
-
end
|
311
|
-
it "should restart a service already loaded and log it" do
|
312
|
-
$dummy = subject.restart_service :name => 'dummy'
|
313
|
-
end
|
314
|
-
|
315
|
-
context "Distributed service" do
|
316
|
-
it "should ne possible to restart a distributed service" do
|
317
|
-
$dummy_dist = subject.restart_service :name => 'distdummy'
|
318
|
-
end
|
319
|
-
it "should log it if debug mode", :if => $debug do
|
320
|
-
open('/tmp/log.file').grep(/DEBUG -- Carioca: Restarting distributed service distdummy/).size.should eq 1
|
321
|
-
end
|
322
|
-
end
|
323
|
-
|
324
|
-
it "should log it if debug mode", :if => $debug do
|
325
|
-
open('/tmp/log.file').grep(/DEBUG -- Carioca: Restarting service dummy/).size.should eq 1
|
326
|
-
end
|
327
|
-
it "should not log it if not debug mode", :if => $debug do
|
328
|
-
open('/tmp/log.file').grep(/DEBUG -- Carioca: Restarting service dummy/).size.should eq 1
|
329
|
-
end
|
330
|
-
|
331
|
-
end
|
332
|
-
|
333
|
-
|
334
|
-
context "#unregister_service" do
|
335
|
-
it { should respond_to :unregister_service }
|
336
|
-
it "should be possible te unregistered the configuration service" do
|
337
|
-
subject.list.keys.should include "configuration"
|
338
|
-
subject.unregister_service :name => "configuration"
|
339
|
-
subject.list.keys.should_not include "configuration"
|
340
|
-
end
|
341
|
-
it "should raise RegistryError if trying to unregister logger" do
|
342
|
-
lambda { subject.unregister_service :name => "logger"}.should raise_error RegistryError
|
343
|
-
end
|
344
|
-
it "should raise RegistryError if trying to unregister a loaded service" do
|
345
|
-
lambda { subject.unregister_service :name => "dummy"}.should raise_error RegistryError
|
346
|
-
end
|
347
|
-
|
348
|
-
end
|
349
|
-
|
350
|
-
context "#discover_builtins" do
|
351
|
-
it { should respond_to :discover_builtins }
|
352
|
-
it "should rebuild builtin service in @list" do
|
353
|
-
subject.discover_builtins
|
354
|
-
subject.list.keys.should include "configuration"
|
355
|
-
end
|
356
|
-
end
|
357
|
-
|
358
|
-
context "#register_service" do
|
359
|
-
it { should respond_to :register_service }
|
360
|
-
it "should add a new service" do
|
361
|
-
subject.register_service :name => 'otherdummy',
|
362
|
-
:type => :file,
|
363
|
-
:resource => './spec/samples/otherdummy.rb',
|
364
|
-
:service =>'ExternalServices::OtherDummy',
|
365
|
-
:description => 'An other Dummy Service',
|
366
|
-
:requires => ['requireddummy']
|
367
|
-
end
|
368
|
-
it "should raised RegistryError if started without a registered required service" do
|
369
|
-
lambda { subject.start_service :name => 'otherdummy' }.should raise_error RegistryError
|
370
|
-
end
|
371
|
-
it "should follow requires when started" do
|
372
|
-
subject.register_service :name => 'requireddummy',
|
373
|
-
:type => :file,
|
374
|
-
:resource => './spec/samples/requireddummy.rb',
|
375
|
-
:service =>'ExternalServices::RequiredDummy',
|
376
|
-
:description => 'An other Dummy Service'
|
377
|
-
subject.start_service :name => 'otherdummy'
|
378
|
-
open('/tmp/log.file').grep(/DEBUG -- Carioca: Registry dependancy found and not loaded : requireddummy/).size.should eq 1 if $debug
|
379
|
-
subject.loaded_services.keys.should include 'requireddummy'
|
380
|
-
subject.loaded_services.keys.should include 'otherdummy'
|
381
|
-
end
|
382
|
-
it "should raise Argument error if :type is not :gem, :file, :gem_file or :builtin" do
|
383
|
-
lambda { subject.register_service :name => 'otherdummy',
|
384
|
-
:type => :error,
|
385
|
-
:resource => 'spec/samples/otherdummy.rb',
|
386
|
-
:service =>'ExternalServices::OtherDummy',
|
387
|
-
:description => 'An other Dummy Service'}.should raise_error ArgumentError
|
388
|
-
|
389
|
-
end
|
390
|
-
end
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
context "#save!" do
|
397
|
-
it { should respond_to :save! }
|
398
|
-
it "should save the config to an other file @registry_filename" do
|
399
|
-
File::unlink('/tmp/test.reg') if File::exist?('/tmp/test.reg')
|
400
|
-
prev = subject.registry_filename
|
401
|
-
subject.registry_filename = '/tmp/test.reg'
|
402
|
-
subject.save!
|
403
|
-
File::exist?('/tmp/test.reg').should be true
|
404
|
-
subject.registry_filename = prev
|
405
|
-
subject.registry_filename.should eq "spec/config/services.registry"
|
406
|
-
end
|
407
|
-
|
408
|
-
end
|
409
|
-
|
410
|
-
|
411
|
-
|
412
|
-
context "#close" do
|
413
|
-
context "Closing the Carioca registry" do
|
414
|
-
it { should respond_to :close }
|
415
|
-
it "should close" do
|
416
|
-
subject.close.should eq true
|
417
|
-
end
|
418
|
-
it "should log a registry closing notification if debug mode", :if => $debug do
|
419
|
-
open('/tmp/log.file').grep(/DEBUG -- Carioca: closing Registry .../).size.should eq 1
|
420
|
-
end
|
421
|
-
it "should not log a registry closing notification if not debug mode", :unless => $debug do
|
422
|
-
open('/tmp/log.file').grep(/DEBUG -- Carioca: closing Registry .../).size.should eq 0
|
423
|
-
end
|
424
|
-
it "should log a distributed service killing notification if debug mode", :if => $debug do
|
425
|
-
open('/tmp/log.file').grep(/DEBUG -- Carioca: Killing distributed Service distdummy./).size.should >= 1
|
426
|
-
end
|
427
|
-
it "should not log a distributed service killing notification if not debug mode", :unless => $debug do
|
428
|
-
open('/tmp/log.file').grep(/DEBUG -- Carioca: Killing distributed Service distdummy./).size.should eq 0
|
429
|
-
end
|
430
|
-
it "should log a stopping notification for each services if debug mode", :if => $debug do
|
431
|
-
['debug','uuid','dorsal','dummy','dummy_one','requireddummy','otherdummy'].each do |service|
|
432
|
-
open('/tmp/log.file').grep(/DEBUG -- Carioca: Service #{service} stopped/).size.should >= 1
|
433
|
-
end
|
434
|
-
end
|
435
|
-
it "should not log a stopping notification for each services if not debug mode", :unless => $debug do
|
436
|
-
['debug','uuid','dorsal','dummy','dummy_one','requireddummy','otherdummy'].each do |service|
|
437
|
-
open('/tmp/log.file').grep(/DEBUG -- Carioca: Service #{service} stopped/).size.should eq 0
|
438
|
-
end
|
439
|
-
end
|
440
|
-
it "should log a registry closing confirmation if debug mode", :if => $debug do
|
441
|
-
open('/tmp/log.file').grep(/DEBUG -- Carioca: Registry services closed, logger will be closed asynchronously/).size.should eq 1
|
442
|
-
end
|
443
|
-
it "should not log a registry closing confirmation if not debug mode", :unless => $debug do
|
444
|
-
open('/tmp/log.file').grep(/DEBUG -- Carioca: Registry services closed, logger will be closed asynchronously/).size.should eq 0
|
445
|
-
end
|
446
|
-
it "should loaded services empty" do
|
447
|
-
subject.loaded_services.empty?.should eq true
|
448
|
-
end
|
449
|
-
context "Distributed service" do
|
450
|
-
end
|
451
|
-
end
|
452
|
-
end
|
453
|
-
end
|
454
|
-
after :all do
|
455
|
-
FileUtils.rm_rf("/tmp/log.file")
|
456
|
-
File::unlink('/tmp/dorsal/ringserver.pid') if File::exist?('/tmp/dorsal/ringserver.pid')
|
457
|
-
File::unlink('/tmp/dorsal/service-distdummy.pid') if File::exist?('/tmp/dorsal/service-distdummy.pid')
|
458
|
-
pid = `ps aux|grep ruby|grep -v grep |grep 'Ultragreen Ring Server'|awk '{ print $2}'`
|
459
|
-
unless pid.empty? then
|
460
|
-
res = `kill -TERM #{pid.chomp}`
|
461
|
-
end
|
462
|
-
pid = `ps aux|grep ruby|grep -v grep |grep 'a dummy test service'|awk '{ print $2}'`
|
463
|
-
unless pid.empty? then
|
464
|
-
res = `kill -TERM #{pid.chomp}`
|
465
|
-
end
|
466
|
-
end
|
467
|
-
|
468
|
-
end
|
data/spec/config/.config
DELETED
@@ -1,55 +0,0 @@
|
|
1
|
-
---
|
2
|
-
uuid:
|
3
|
-
:type: :gem
|
4
|
-
:resource: uuid
|
5
|
-
:description: a Rubygems called uuid to build UUID ids.
|
6
|
-
:service: UUID
|
7
|
-
logger:
|
8
|
-
# :distributed: true
|
9
|
-
:type: :builtin
|
10
|
-
:resource: logger
|
11
|
-
:init_options:
|
12
|
-
:target: /tmp/log.file
|
13
|
-
:description: The standard ruby Logger internal wrapper Service
|
14
|
-
:service: Carioca::Services::InternalLogger
|
15
|
-
configuration:
|
16
|
-
# :distributed: true
|
17
|
-
:type: :builtin
|
18
|
-
:resource: configuration
|
19
|
-
:description: The configuration service of Carioca
|
20
|
-
:service: Carioca::Services::Configuration
|
21
|
-
:init_options:
|
22
|
-
:config_file: ./spec/config/.config
|
23
|
-
dorsal:
|
24
|
-
:type: :gem
|
25
|
-
:resource: dorsal
|
26
|
-
:description: The Dorsal Distributed Services architecture
|
27
|
-
:service: Dorsal::Controller
|
28
|
-
:init_options:
|
29
|
-
:host: localhost
|
30
|
-
:port: 8686
|
31
|
-
:dir: /tmp/dorsal
|
32
|
-
:description: Ultragreen Ring Server
|
33
|
-
dummy:
|
34
|
-
:type: :file
|
35
|
-
:resource: ./spec/samples/dummy.rb
|
36
|
-
:description: a dummy test service
|
37
|
-
:service: ExternalServices::Dummy
|
38
|
-
distdummy:
|
39
|
-
:type: :file
|
40
|
-
:resource: ./spec/samples/dummy.rb
|
41
|
-
:description: a dummy test service
|
42
|
-
:service: ExternalServices::Dummy
|
43
|
-
:distributed: true
|
44
|
-
uuidbygemfile:
|
45
|
-
:type: :gem_file
|
46
|
-
:resource: uuid:lib/uuid.rb
|
47
|
-
:description: uuid file in gem
|
48
|
-
:service: UUID
|
49
|
-
debug:
|
50
|
-
:type: :builtin
|
51
|
-
:resource: debug
|
52
|
-
:init_options:
|
53
|
-
:service: dummy
|
54
|
-
:description: Class Proxy debug logger Service
|
55
|
-
:service: Carioca::Services::ProxyDebug
|
data/spec/init_spec.rb
DELETED
data/spec/samples/dummy.rb
DELETED
data/spec/samples/otherdummy.rb
DELETED
data/spec/spec_helper.rb
DELETED
@@ -1,18 +0,0 @@
|
|
1
|
-
# coding: utf-8
|
2
|
-
# This file was generated by the `rspec --init` command. Conventionally, all
|
3
|
-
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
4
|
-
# Require this file using `require "spec_helper.rb"` to ensure that it is only
|
5
|
-
# loaded once.
|
6
|
-
#
|
7
|
-
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
8
|
-
RSpec.configure do |config|
|
9
|
-
# config.treat_symbols_as_metadata_keys_with_true_values = true
|
10
|
-
config.run_all_when_everything_filtered = true
|
11
|
-
# config.filter_run :focus
|
12
|
-
config.mock_with :rspec do |c|
|
13
|
-
c.syntax = [:should, :expect]
|
14
|
-
end
|
15
|
-
config.expect_with :rspec do |c|
|
16
|
-
c.syntax = [:should, :expect]
|
17
|
-
end
|
18
|
-
end
|
@@ -1,25 +0,0 @@
|
|
1
|
-
AssignmentInConditionalCheck:
|
2
|
-
CaseMissingElseCheck:
|
3
|
-
ClassLineCountCheck:
|
4
|
-
line_count: 300
|
5
|
-
ClassNameCheck:
|
6
|
-
pattern: !ruby/regexp /^[A-Z][a-zA-Z0-9]*$/
|
7
|
-
#ClassVariableCheck:
|
8
|
-
CyclomaticComplexityBlockCheck:
|
9
|
-
complexity: 5
|
10
|
-
CyclomaticComplexityMethodCheck:
|
11
|
-
complexity: 10
|
12
|
-
EmptyRescueBodyCheck:
|
13
|
-
ForLoopCheck:
|
14
|
-
MethodLineCountCheck:
|
15
|
-
line_count: 30
|
16
|
-
MethodNameCheck:
|
17
|
-
pattern: !ruby/regexp /^[_a-z<>=\[|+-\/\*`]+[_a-z0-9_<>=~@\[\]]*[=!\?]?$/
|
18
|
-
# MissingForeignKeyIndexCheck:
|
19
|
-
ModuleLineCountCheck:
|
20
|
-
line_count: 500
|
21
|
-
ModuleNameCheck:
|
22
|
-
pattern: !ruby/regexp /^[A-Z][a-zA-Z0-9]*$/
|
23
|
-
ParameterNumberCheck:
|
24
|
-
parameter_count: 5
|
25
|
-
|