tengine_core 0.5.28
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.rspec +1 -0
- data/Gemfile +40 -0
- data/Gemfile.lock +95 -0
- data/README.md +54 -0
- data/Rakefile +44 -0
- data/VERSION +1 -0
- data/bin/tengine_atd +8 -0
- data/bin/tengine_heartbeat_watchd +8 -0
- data/bin/tengined +182 -0
- data/examples/VERSION +1 -0
- data/examples/uc01_execute_processing_for_event.rb +11 -0
- data/examples/uc02_fire_another_event.rb +16 -0
- data/examples/uc03_2handlers_for_1event.rb +16 -0
- data/examples/uc08_if_both_a_and_b_occurs.rb +11 -0
- data/examples/uc10_if_the_event_occurs_at_the_server.rb +15 -0
- data/examples/uc50_commit_event_at_first.rb +17 -0
- data/examples/uc51_commit_event_at_first_submit.rb +29 -0
- data/examples/uc52_commit_event_after_all_handler_submit.rb +31 -0
- data/examples/uc52_never_commit_event_unless_all_handler_submit.rb +31 -0
- data/examples/uc60_event_in_handler.rb +18 -0
- data/examples/uc62_session_in_driver.rb +16 -0
- data/examples/uc64_safety_countup.rb +14 -0
- data/examples/uc70_driver_enabled_on_activation.rb +13 -0
- data/examples/uc71_driver_disabled_on_activation.rb +14 -0
- data/examples/uc72_setup_eventmachine.rb +17 -0
- data/examples/uc80_raise_io_error.rb +10 -0
- data/examples/uc81_raise_runtime_error.rb +10 -0
- data/examples2/driver01.rb +18 -0
- data/examples2/driver02.rb +19 -0
- data/examples2/uc08_if_both_a_and_b_occurs.rb +13 -0
- data/examples2/uc10_if_the_event_occurs_at_the_server.rb +18 -0
- data/examples2/uc51_commit_event_at_first_submit_1.rb +16 -0
- data/examples2/uc51_commit_event_at_first_submit_2.rb +17 -0
- data/examples2/uc51_commit_event_at_first_submit_3.rb +17 -0
- data/examples2/uc62_session_in_driver.rb +16 -0
- data/examples2/uc71_driver_disabled_on_activation.rb +16 -0
- data/failure_examples/VERSION +1 -0
- data/failure_examples/uc53_submit_outside_of_handler.rb +15 -0
- data/failure_examples/uc61_event_outside_of_handler.rb +12 -0
- data/failure_examples/uc63_session_outside_of_driver.rb +13 -0
- data/lib/tengine/core.rb +74 -0
- data/lib/tengine/core/bootstrap.rb +123 -0
- data/lib/tengine/core/collection_accessible.rb +34 -0
- data/lib/tengine/core/config.rb +10 -0
- data/lib/tengine/core/config/atd.rb +225 -0
- data/lib/tengine/core/config/core.rb +319 -0
- data/lib/tengine/core/config/heartbeat_watcher.rb +229 -0
- data/lib/tengine/core/connection_test/.gitignore +1 -0
- data/lib/tengine/core/connection_test/fire_bar_on_foo.rb +16 -0
- data/lib/tengine/core/driveable.rb +213 -0
- data/lib/tengine/core/driver.rb +69 -0
- data/lib/tengine/core/driver/finder.rb +42 -0
- data/lib/tengine/core/dsl_evaluator.rb +110 -0
- data/lib/tengine/core/dsl_filter_def.rb +11 -0
- data/lib/tengine/core/dsl_loader.rb +108 -0
- data/lib/tengine/core/event.rb +145 -0
- data/lib/tengine/core/event/finder.rb +82 -0
- data/lib/tengine/core/event_exception_reportable.rb +88 -0
- data/lib/tengine/core/event_wrapper.rb +21 -0
- data/lib/tengine/core/find_by_name.rb +31 -0
- data/lib/tengine/core/handler.rb +152 -0
- data/lib/tengine/core/handler_path.rb +33 -0
- data/lib/tengine/core/heartbeat_watcher.rb +161 -0
- data/lib/tengine/core/io_to_logger.rb +22 -0
- data/lib/tengine/core/kernel.rb +510 -0
- data/lib/tengine/core/kernel_runtime.rb +91 -0
- data/lib/tengine/core/method_traceable.rb +38 -0
- data/lib/tengine/core/mongoid_fix.rb +19 -0
- data/lib/tengine/core/mutex.rb +177 -0
- data/lib/tengine/core/optimistic_lock.rb +69 -0
- data/lib/tengine/core/plugins.rb +54 -0
- data/lib/tengine/core/schedule.rb +21 -0
- data/lib/tengine/core/scheduler.rb +156 -0
- data/lib/tengine/core/selectable_attr.rb +29 -0
- data/lib/tengine/core/session.rb +21 -0
- data/lib/tengine/core/session_wrapper.rb +68 -0
- data/lib/tengine/core/setting.rb +21 -0
- data/lib/tengine/core/validation.rb +36 -0
- data/lib/tengine/errors.rb +18 -0
- data/lib/tengine/rspec.rb +8 -0
- data/lib/tengine/rspec/context_wrapper.rb +51 -0
- data/lib/tengine/rspec/extension.rb +53 -0
- data/lib/tengine_core.rb +23 -0
- data/spec/factories/tengine_core_drivers.rb +10 -0
- data/spec/factories/tengine_core_events.rb +14 -0
- data/spec/factories/tengine_core_handler_paths.rb +9 -0
- data/spec/factories/tengine_core_handlers.rb +9 -0
- data/spec/factories/tengine_core_sessions.rb +9 -0
- data/spec/mongoid.yml +35 -0
- data/spec/spec_helper.rb +48 -0
- data/spec/support/mongo_index_key_log.rb +91 -0
- data/spec/tengine/core/bootstrap_spec.rb +278 -0
- data/spec/tengine/core/bugfix/bind_dsl_file_in_multi_byte_dir_spec.rb +21 -0
- data/spec/tengine/core/bugfix/enabled_on_activation_spec.rb +112 -0
- data/spec/tengine/core/bugfix/receive_event_spec.rb +133 -0
- data/spec/tengine/core/bugfix/use_dsl_version_method.rb +12 -0
- data/spec/tengine/core/bugfix/use_dsl_version_method_spec.rb +28 -0
- data/spec/tengine/core/bugfix/use_event_in_handler_dsl.rb +11 -0
- data/spec/tengine/core/bugfix//351/235/236ACSII/343/201/256/343/203/206/343/202/231/343/202/243/343/203/254/343/202/257/343/203/210/343/203/252/345/220/215/source_location_encoding.rb +35 -0
- data/spec/tengine/core/bugfix//351/235/236ACSII/343/201/256/343/203/206/343/202/231/343/202/243/343/203/254/343/202/257/343/203/210/343/203/252/345/220/215//351/235/236ASCII/343/201/256/343/203/225/343/202/241/343/202/244/343/203/253/345/220/215_dsl.rb +38 -0
- data/spec/tengine/core/bugfix//351/235/236ACSII/343/201/256/343/203/207/343/202/243/343/203/254/343/202/257/343/203/210/343/203/252/345/220/215/source_location_encoding.rb +35 -0
- data/spec/tengine/core/bugfix//351/235/236ACSII/343/201/256/343/203/207/343/202/243/343/203/254/343/202/257/343/203/210/343/203/252/345/220/215//351/235/236ASCII/343/201/256/343/203/225/343/202/241/343/202/244/343/203/253/345/220/215_dsl.rb +38 -0
- data/spec/tengine/core/config/atd_spec.rb +62 -0
- data/spec/tengine/core/config/core_spec.rb +479 -0
- data/spec/tengine/core/config/heartbeat_watcher_spec.rb +62 -0
- data/spec/tengine/core/config/syntax_error_in_erb.yml.erb +13 -0
- data/spec/tengine/core/config/wrong_category_name.yml.erb +13 -0
- data/spec/tengine/core/config/wrong_field_name.yml.erb +12 -0
- data/spec/tengine/core/config/wrong_yaml.yml.erb +13 -0
- data/spec/tengine/core/config_spec/another_port.yml +54 -0
- data/spec/tengine/core/config_spec/config_with_dir_absolute_load_path.yml +16 -0
- data/spec/tengine/core/config_spec/config_with_dir_relative_load_path.yml +16 -0
- data/spec/tengine/core/config_spec/config_with_file_absolute_load_path.yml +16 -0
- data/spec/tengine/core/config_spec/config_with_file_relative_load_path.yml +16 -0
- data/spec/tengine/core/config_spec/log_config_spec.rb +235 -0
- data/spec/tengine/core/driveable_spec.rb +240 -0
- data/spec/tengine/core/driver_spec.rb +159 -0
- data/spec/tengine/core/dsl_loader_spec.rb +172 -0
- data/spec/tengine/core/dsls/uc08_if_both_a_and_b_occurs_spec.rb +35 -0
- data/spec/tengine/core/dsls/uc10_if_the_event_occurs_at_the_server_spec.rb +58 -0
- data/spec/tengine/core/dsls/uc50_commit_event_at_first_spec.rb +29 -0
- data/spec/tengine/core/dsls/uc52_commit_event_after_all_handler_submit_spec.rb +33 -0
- data/spec/tengine/core/dsls/uc52_never_commit_event_unless_all_handler_submit_spec.rb +37 -0
- data/spec/tengine/core/dsls/uc53_submit_outside_of_handler_spec.rb +37 -0
- data/spec/tengine/core/dsls/uc60_event_in_handler_spec.rb +31 -0
- data/spec/tengine/core/dsls/uc61_event_outside_of_handler_spec.rb +37 -0
- data/spec/tengine/core/dsls/uc62_session_in_driver_spec.rb +36 -0
- data/spec/tengine/core/dsls/uc63_session_outside_of_driver_spec.rb +35 -0
- data/spec/tengine/core/dsls/uc64_safety_countup_spec.rb +134 -0
- data/spec/tengine/core/dsls/uc70_driver_enabled_on_activation_spec.rb +39 -0
- data/spec/tengine/core/dsls/uc71_driver_disabled_on_activation_spec.rb +36 -0
- data/spec/tengine/core/dsls/uc72_setup_eventmachine_spec.rb +39 -0
- data/spec/tengine/core/dsls/uc80_raise_io_error_spec.rb +53 -0
- data/spec/tengine/core/dsls/uc81_raise_runtime_error_spec.rb +49 -0
- data/spec/tengine/core/event/finder_spec.rb +136 -0
- data/spec/tengine/core/event_exception_reportable_spec.rb +33 -0
- data/spec/tengine/core/event_spec.rb +161 -0
- data/spec/tengine/core/event_wrapper_spec.rb +35 -0
- data/spec/tengine/core/handler_path_spec.rb +87 -0
- data/spec/tengine/core/handler_spec.rb +190 -0
- data/spec/tengine/core/heartbeat_watcher_spec.rb +131 -0
- data/spec/tengine/core/io_to_logger_spec.rb +30 -0
- data/spec/tengine/core/kernel_spec.rb +885 -0
- data/spec/tengine/core/mutex_spec.rb +184 -0
- data/spec/tengine/core/optimistic_lock_spec.rb +55 -0
- data/spec/tengine/core/scheculer_spec.rb +121 -0
- data/spec/tengine/core/selectable_attr_spec.rb +30 -0
- data/spec/tengine/core/session_spec.rb +104 -0
- data/spec/tengine/core/setting_spec.rb +79 -0
- data/spec/tengine/core_spec.rb +13 -0
- data/spec/tengine_spec.rb +14 -0
- data/tengine_core.gemspec +248 -0
- data/tmp/log/.gitignore +1 -0
- data/tmp/tengined_status/.gitignore +1 -0
- metadata +421 -0
@@ -0,0 +1,62 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
require 'tengine/event'
|
5
|
+
|
6
|
+
describe Tengine::Core::Config::Atd do
|
7
|
+
|
8
|
+
describe :[] do
|
9
|
+
it "should convert a Hash to a Tengine::Core::Config::Atd" do
|
10
|
+
converted = Tengine::Core::Config::Atd[{:process => {:daemon => true}}]
|
11
|
+
converted.should be_a(Tengine::Core::Config::Atd)
|
12
|
+
converted[:process][:daemon].should be_true
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should return same Tengine::Core::Config::Atd" do
|
16
|
+
converted = Tengine::Core::Config::Atd.new(:process => {:daemon => true})
|
17
|
+
Tengine::Core::Config::Atd[converted].should == converted
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
context "デフォルト" do
|
22
|
+
subject do
|
23
|
+
Tengine::Core::Config::Atd.new
|
24
|
+
end
|
25
|
+
its(:db){ should == {
|
26
|
+
'host' => 'localhost',
|
27
|
+
'port' => 27017,
|
28
|
+
'username' => nil,
|
29
|
+
'password' => nil,
|
30
|
+
'database' => 'tengine_production',
|
31
|
+
}}
|
32
|
+
|
33
|
+
it "db" do
|
34
|
+
subject.db.should == {
|
35
|
+
'host' => 'localhost',
|
36
|
+
'port' => 27017,
|
37
|
+
'username' => nil,
|
38
|
+
'password' => nil,
|
39
|
+
'database' => 'tengine_production',
|
40
|
+
}
|
41
|
+
end
|
42
|
+
|
43
|
+
it "process_daemon" do
|
44
|
+
subject[:process][:daemon].should be_false
|
45
|
+
end
|
46
|
+
|
47
|
+
it "heartbeat_atd" do
|
48
|
+
subject[:heartbeat][:atd][:interval].should == 0
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
52
|
+
|
53
|
+
context "指定した設定ファイルが存在しない場合" do
|
54
|
+
it "例外を生成します" do
|
55
|
+
config_path = File.expand_path("../config_spec/unexist_config.yml", File.dirname(__FILE__))
|
56
|
+
expect{
|
57
|
+
Tengine::Core::Config::Atd.new(:config => config_path)
|
58
|
+
}.to raise_error(Tengine::Core::ConfigError, /No such file or directory - #{config_path}/)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
end
|
@@ -0,0 +1,479 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
require 'tengine/event'
|
5
|
+
|
6
|
+
describe Tengine::Core::Config::Core do
|
7
|
+
|
8
|
+
# log_configのテストは spec/models/tengine/core/config_spec/log_config_spec.rb にあります。
|
9
|
+
|
10
|
+
describe :[] do
|
11
|
+
it "should convert a Hash to a Tengine::Core::Config::Core" do
|
12
|
+
converted = Tengine::Core::Config::Core[{ :process => { :daemon => true}}]
|
13
|
+
converted.should be_a(Tengine::Core::Config::Core)
|
14
|
+
converted[:process][:daemon].should be_true
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should return same Tengine::Core::Config::Core" do
|
18
|
+
converted = Tengine::Core::Config::Core.new(:process => { :daemon => true})
|
19
|
+
Tengine::Core::Config::Core[converted].should == converted
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
context "デフォルト" do
|
24
|
+
subject do
|
25
|
+
Tengine::Core::Config::Core.new
|
26
|
+
end
|
27
|
+
its(:status_dir){ should == "./tmp/tengined_status" }
|
28
|
+
its(:activation_dir){ should == "./tmp/tengined_activations" }
|
29
|
+
|
30
|
+
its(:confirmation_threshold){ should == Tengine::Event::LEVELS_INV[:info] }
|
31
|
+
its(:heartbeat_enabled?){ should == false }
|
32
|
+
|
33
|
+
its(:db){ should == {
|
34
|
+
'host' => 'localhost',
|
35
|
+
'port' => 27017,
|
36
|
+
'username' => nil,
|
37
|
+
'password' => nil,
|
38
|
+
'database' => 'tengine_production',
|
39
|
+
}}
|
40
|
+
|
41
|
+
it do
|
42
|
+
subject.db.should == {
|
43
|
+
'host' => 'localhost',
|
44
|
+
'port' => 27017,
|
45
|
+
'username' => nil,
|
46
|
+
'password' => nil,
|
47
|
+
'database' => 'tengine_production',
|
48
|
+
}
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
|
53
|
+
shared_examples_for "ディレクトリもファイルも存在しない場合はエラー" do |path|
|
54
|
+
before do
|
55
|
+
@error_message = "file or directory doesn't exist. #{path}"
|
56
|
+
Dir.should_receive(:exist?).with(path).and_return(false)
|
57
|
+
File.should_receive(:exist?).with(path).and_return(false)
|
58
|
+
end
|
59
|
+
it :dsl_dir_path do
|
60
|
+
expect{ subject.dsl_dir_path }.should raise_error(Tengine::Core::ConfigError, @error_message)
|
61
|
+
end
|
62
|
+
it :dsl_file_paths do
|
63
|
+
expect{ subject.dsl_file_paths }.should raise_error(Tengine::Core::ConfigError, @error_message)
|
64
|
+
end
|
65
|
+
it :dsl_version_path do
|
66
|
+
expect{ subject.dsl_version_path }.should raise_error(Tengine::Core::ConfigError, @error_message)
|
67
|
+
end
|
68
|
+
it :dsl_version do
|
69
|
+
expect{ subject.dsl_version }.should raise_error(Tengine::Core::ConfigError, @error_message)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
|
74
|
+
|
75
|
+
context "load_pathに相対パス" do
|
76
|
+
before do
|
77
|
+
# capistranoのデフォルトのデプロイ先を想定しています
|
78
|
+
# see "BACK TO CONFIGURATION" in https://github.com/capistrano/capistrano/wiki/2.x-From-The-Beginning
|
79
|
+
# http://www.slideshare.net/T2J/capistrano-tips-tips
|
80
|
+
Dir.stub!(:pwd).and_return("/u/apps/app1/current")
|
81
|
+
end
|
82
|
+
|
83
|
+
shared_examples_for "相対パス指定時のパスの振る舞い" do
|
84
|
+
it :dsl_dir_path do
|
85
|
+
subject.dsl_dir_path.should == "/u/apps/app1/current/tengine_dsls"
|
86
|
+
end
|
87
|
+
|
88
|
+
it :dsl_version_path do
|
89
|
+
subject.dsl_version_path.should == "/u/apps/app1/current/tengine_dsls/VERSION"
|
90
|
+
end
|
91
|
+
|
92
|
+
it "VERSIONファイルがある場合" do
|
93
|
+
File.should_receive(:exist?).with("/u/apps/app1/current/tengine_dsls/VERSION").and_return(true)
|
94
|
+
File.should_receive(:read).and_return("TEST20110905164100")
|
95
|
+
subject.dsl_version.should == "TEST20110905164100"
|
96
|
+
end
|
97
|
+
|
98
|
+
it "VERSIONファイルがない場合" do
|
99
|
+
File.should_receive(:exist?).with("/u/apps/app1/current/tengine_dsls/VERSION").and_return(false)
|
100
|
+
t = Time.local(2011,9,5,17,28,30)
|
101
|
+
Time.stub!(:now).and_return(t)
|
102
|
+
subject.dsl_version.should == "20110905172830"
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
context "のディレクトリを指定する設定ファイル" do
|
107
|
+
subject do
|
108
|
+
Tengine::Core::Config::Core.new(:config => File.expand_path("../config_spec/config_with_dir_relative_load_path.yml", File.dirname(__FILE__)))
|
109
|
+
end
|
110
|
+
it "should allow to read value by using []" do
|
111
|
+
expected = {
|
112
|
+
# :daemon => true,
|
113
|
+
:activation_timeout => 300,
|
114
|
+
:load_path => "tengine_dsls",
|
115
|
+
:cache_drivers => true,
|
116
|
+
# :pid_dir => "tmp/tengined_pids",
|
117
|
+
:status_dir => "tmp/tengined_status",
|
118
|
+
:activation_dir => "tmp/tengined_activations",
|
119
|
+
# :heartbeat_period => 600,
|
120
|
+
:confirmation_threshold => "warn",
|
121
|
+
:skip_load=>nil,
|
122
|
+
:skip_enablement=>nil,
|
123
|
+
:wait_activation=>nil,
|
124
|
+
}
|
125
|
+
subject[:tengined].to_hash.should == expected
|
126
|
+
subject['tengined'].to_hash.should == expected
|
127
|
+
subject[:process]['daemon'].should == true
|
128
|
+
subject[:process][:daemon].should == true
|
129
|
+
subject[:event_queue][:connection][:host].should == "localhost"
|
130
|
+
subject['event_queue']['connection']['host'].should == "localhost"
|
131
|
+
subject[:event_queue][:queue][:name].should == "tengine_event_queue2"
|
132
|
+
subject['event_queue']['queue']['name'].should == "tengine_event_queue2"
|
133
|
+
end
|
134
|
+
its(:heartbeat_enabled?){ should == true }
|
135
|
+
|
136
|
+
describe :relative_path_from_dsl_dir do
|
137
|
+
it "絶対パスが指定されるとdsl_dir_pathからの相対パスを返します" do
|
138
|
+
Dir.should_receive(:exist?).with("/u/apps/app1/current/tengine_dsls").and_return(true)
|
139
|
+
subject.relative_path_from_dsl_dir("/u/apps/app1/shared/config").should == "../../shared/config"
|
140
|
+
end
|
141
|
+
|
142
|
+
it "相対パスが指定されると(計算のしようがないので)そのまま返します" do
|
143
|
+
subject.relative_path_from_dsl_dir("lib/tengine/foo/bar").should == "lib/tengine/foo/bar"
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
describe :confirmation_threshold do
|
148
|
+
it "--tengined-confirmation-levelで設定した値を数値に変換する" do
|
149
|
+
subject.confirmation_threshold.should == Tengine::Event::LEVELS_INV[:warn]
|
150
|
+
end
|
151
|
+
end
|
152
|
+
|
153
|
+
context "ディレクトリが存在する場合" do
|
154
|
+
before do
|
155
|
+
Dir.should_receive(:exist?).with("/u/apps/app1/current/tengine_dsls").and_return(true)
|
156
|
+
end
|
157
|
+
|
158
|
+
it :dsl_file_paths do
|
159
|
+
Dir.should_receive(:glob).
|
160
|
+
with("/u/apps/app1/current/tengine_dsls/**/*.rb").
|
161
|
+
and_return(["/u/apps/app1/current/tengine_dsls/foo/bar.rb"])
|
162
|
+
subject.dsl_file_paths.should == ["/u/apps/app1/current/tengine_dsls/foo/bar.rb"]
|
163
|
+
end
|
164
|
+
|
165
|
+
it_should_behave_like "相対パス指定時のパスの振る舞い"
|
166
|
+
end
|
167
|
+
|
168
|
+
it_should_behave_like "ディレクトリもファイルも存在しない場合はエラー", "/u/apps/app1/current/tengine_dsls"
|
169
|
+
end
|
170
|
+
|
171
|
+
context "のファイルを指定する設定ファイル" do
|
172
|
+
subject do
|
173
|
+
Tengine::Core::Config::Core.new(:config => File.expand_path("../config_spec/config_with_file_relative_load_path.yml", File.dirname(__FILE__)))
|
174
|
+
end
|
175
|
+
it "should allow to read value by using []" do
|
176
|
+
expected = {
|
177
|
+
# :daemon => true,
|
178
|
+
:activation_timeout => 300,
|
179
|
+
:load_path => "tengine_dsls/init.rb",
|
180
|
+
:cache_drivers => true,
|
181
|
+
# :pid_dir => "tmp/tengined_pids",
|
182
|
+
:status_dir => "tmp/tengined_status",
|
183
|
+
:activation_dir => "tmp/tengined_activations",
|
184
|
+
# :heartbeat_period => 600,
|
185
|
+
:confirmation_threshold => "warn",
|
186
|
+
:skip_load=>nil,
|
187
|
+
:skip_enablement=>nil,
|
188
|
+
:wait_activation=>nil,
|
189
|
+
}
|
190
|
+
subject[:tengined].to_hash.should == expected
|
191
|
+
subject['tengined'].to_hash.should == expected
|
192
|
+
subject[:tengined]['load_path'].should == "tengine_dsls/init.rb"
|
193
|
+
subject[:tengined][:load_path].should == "tengine_dsls/init.rb"
|
194
|
+
end
|
195
|
+
|
196
|
+
describe :relative_path_from_dsl_dir do
|
197
|
+
it "絶対パスが指定されるとdsl_dir_pathからの相対パスを返します" do
|
198
|
+
Dir.should_receive(:exist?).with("/u/apps/app1/current/tengine_dsls/init.rb").and_return(false)
|
199
|
+
File.should_receive(:exist?).with("/u/apps/app1/current/tengine_dsls/init.rb").and_return(true)
|
200
|
+
subject.relative_path_from_dsl_dir("/u/apps/app1/shared/config").should == "../../shared/config"
|
201
|
+
end
|
202
|
+
|
203
|
+
it "相対パスが指定されると(計算のしようがないので)そのまま返します" do
|
204
|
+
subject.relative_path_from_dsl_dir("lib/tengine/foo/bar").should == "lib/tengine/foo/bar"
|
205
|
+
end
|
206
|
+
end
|
207
|
+
|
208
|
+
context "ファイルが存在する場合" do
|
209
|
+
before do
|
210
|
+
Dir.should_receive(:exist?).with("/u/apps/app1/current/tengine_dsls/init.rb").and_return(false)
|
211
|
+
File.should_receive(:exist?).with("/u/apps/app1/current/tengine_dsls/init.rb").and_return(true)
|
212
|
+
end
|
213
|
+
|
214
|
+
it :dsl_file_paths do
|
215
|
+
subject.dsl_file_paths.should == ["/u/apps/app1/current/tengine_dsls/init.rb"]
|
216
|
+
end
|
217
|
+
|
218
|
+
it_should_behave_like "相対パス指定時のパスの振る舞い"
|
219
|
+
end
|
220
|
+
|
221
|
+
it_should_behave_like "ディレクトリもファイルも存在しない場合はエラー", "/u/apps/app1/current/tengine_dsls/init.rb"
|
222
|
+
end
|
223
|
+
end
|
224
|
+
|
225
|
+
|
226
|
+
context "load_pathに絶対パス" do
|
227
|
+
|
228
|
+
shared_examples_for "絶対パス指定時のパスの振る舞い" do
|
229
|
+
it :dsl_dir_path do
|
230
|
+
subject.dsl_dir_path.should == "/var/lib/tengine"
|
231
|
+
end
|
232
|
+
|
233
|
+
it :dsl_version_path do
|
234
|
+
subject.dsl_version_path.should == "/var/lib/tengine/VERSION"
|
235
|
+
end
|
236
|
+
|
237
|
+
it "VERSIONファイルがある場合" do
|
238
|
+
File.should_receive(:exist?).with("/var/lib/tengine/VERSION").and_return(true)
|
239
|
+
File.should_receive(:read).and_return("TEST20110905164100")
|
240
|
+
subject.dsl_version.should == "TEST20110905164100"
|
241
|
+
end
|
242
|
+
|
243
|
+
it "VERSIONファイルがない場合" do
|
244
|
+
File.should_receive(:exist?).with("/var/lib/tengine/VERSION").and_return(false)
|
245
|
+
t = Time.local(2011,9,5,17,28,30)
|
246
|
+
Time.stub!(:now).and_return(t)
|
247
|
+
subject.dsl_version.should == "20110905172830"
|
248
|
+
end
|
249
|
+
end
|
250
|
+
|
251
|
+
context "のディレクトリを指定する設定ファイル" do
|
252
|
+
subject do
|
253
|
+
Tengine::Core::Config::Core.new(:config => File.expand_path("../config_spec/config_with_dir_absolute_load_path.yml", File.dirname(__FILE__)))
|
254
|
+
end
|
255
|
+
it "should allow to read value by using []" do
|
256
|
+
expected = {
|
257
|
+
# :daemon => true,
|
258
|
+
:activation_timeout => 300,
|
259
|
+
:load_path => "/var/lib/tengine",
|
260
|
+
:cache_drivers => true,
|
261
|
+
# :pid_dir => "/var/run/tengined_pids",
|
262
|
+
:status_dir => "/var/run/tengined_status",
|
263
|
+
:activation_dir => "/var/run/tengined_activations",
|
264
|
+
# :heartbeat_period => 600,
|
265
|
+
:confirmation_threshold => "warn",
|
266
|
+
:skip_load=>nil,
|
267
|
+
:skip_enablement=>nil,
|
268
|
+
:wait_activation=>nil,
|
269
|
+
}
|
270
|
+
subject[:tengined].to_hash.should == expected
|
271
|
+
subject['tengined'].to_hash.should == expected
|
272
|
+
subject[:process]['daemon'].should == true
|
273
|
+
subject[:process][:daemon].should == true
|
274
|
+
subject[:event_queue][:connection][:host].should == "localhost"
|
275
|
+
subject['event_queue']['connection']['host'].should == "localhost"
|
276
|
+
subject[:event_queue][:queue][:name].should == "tengine_event_queue2"
|
277
|
+
subject['event_queue']['queue']['name'].should == "tengine_event_queue2"
|
278
|
+
end
|
279
|
+
its(:heartbeat_enabled?){ should == true }
|
280
|
+
|
281
|
+
describe :relative_path_from_dsl_dir do
|
282
|
+
it "絶対パスが指定されるとdsl_dir_pathからの相対パスを返します" do
|
283
|
+
Dir.should_receive(:exist?).with("/var/lib/tengine").and_return(true)
|
284
|
+
subject.relative_path_from_dsl_dir("/var/lib/tengine/foo/bar").should == "foo/bar"
|
285
|
+
end
|
286
|
+
|
287
|
+
it "相対パスが指定されると(計算のしようがないので)そのまま返します" do
|
288
|
+
subject.relative_path_from_dsl_dir("lib/tengine/foo/bar").should == "lib/tengine/foo/bar"
|
289
|
+
end
|
290
|
+
end
|
291
|
+
|
292
|
+
describe :confirmation_threshold do
|
293
|
+
it "--tengined-confirmation-levelで設定した値を数値に変換する" do
|
294
|
+
subject.confirmation_threshold.should == Tengine::Event::LEVELS_INV[:warn]
|
295
|
+
end
|
296
|
+
end
|
297
|
+
|
298
|
+
context "ディレクトリが存在する場合" do
|
299
|
+
before do
|
300
|
+
Dir.should_receive(:exist?).with("/var/lib/tengine").and_return(true)
|
301
|
+
end
|
302
|
+
|
303
|
+
it :dsl_file_paths do
|
304
|
+
Dir.should_receive(:glob).
|
305
|
+
with("/var/lib/tengine/**/*.rb").
|
306
|
+
and_return(["/var/lib/tengine/foo/bar.rb"])
|
307
|
+
subject.dsl_file_paths.should == ["/var/lib/tengine/foo/bar.rb"]
|
308
|
+
end
|
309
|
+
|
310
|
+
# C0カバレッジを100%にするために追加しています
|
311
|
+
it "dsl_dir_path and dsl_file_paths" do
|
312
|
+
Dir.should_receive(:glob).
|
313
|
+
with("/var/lib/tengine/**/*.rb").
|
314
|
+
and_return(["/var/lib/tengine/foo/bar.rb"])
|
315
|
+
subject.dsl_dir_path.should == "/var/lib/tengine"
|
316
|
+
subject.dsl_file_paths.should == ["/var/lib/tengine/foo/bar.rb"]
|
317
|
+
end
|
318
|
+
|
319
|
+
it_should_behave_like "絶対パス指定時のパスの振る舞い"
|
320
|
+
end
|
321
|
+
|
322
|
+
it_should_behave_like "ディレクトリもファイルも存在しない場合はエラー", "/var/lib/tengine"
|
323
|
+
end
|
324
|
+
|
325
|
+
context "のファイルを指定する設定ファイル" do
|
326
|
+
subject do
|
327
|
+
Tengine::Core::Config::Core.new(:config => File.expand_path("../config_spec/config_with_file_absolute_load_path.yml", File.dirname(__FILE__)))
|
328
|
+
end
|
329
|
+
it "should allow to read value by using []" do
|
330
|
+
expected = {
|
331
|
+
# :daemon => true,
|
332
|
+
:activation_timeout => 300,
|
333
|
+
:load_path => "/var/lib/tengine/init.rb",
|
334
|
+
:cache_drivers => true,
|
335
|
+
# :pid_dir => "/var/run/tengined_pids",
|
336
|
+
:status_dir => "/var/run/tengined_status",
|
337
|
+
:activation_dir => "/var/run/tengined_activations",
|
338
|
+
# :heartbeat_period => 600,
|
339
|
+
:confirmation_threshold => "warn",
|
340
|
+
:skip_load=>nil,
|
341
|
+
:skip_enablement=>nil,
|
342
|
+
:wait_activation=>nil,
|
343
|
+
}
|
344
|
+
subject[:tengined].to_hash.should == expected
|
345
|
+
subject['tengined'].to_hash.should == expected
|
346
|
+
subject[:tengined]['load_path'].should == "/var/lib/tengine/init.rb"
|
347
|
+
subject[:tengined][:load_path].should == "/var/lib/tengine/init.rb"
|
348
|
+
end
|
349
|
+
|
350
|
+
describe :relative_path_from_dsl_dir do
|
351
|
+
it "絶対パスが指定されるとdsl_dir_pathからの相対パスを返します" do
|
352
|
+
Dir.should_receive(:exist?).with("/var/lib/tengine/init.rb").and_return(false)
|
353
|
+
File.should_receive(:exist?).with("/var/lib/tengine/init.rb").and_return(true)
|
354
|
+
subject.relative_path_from_dsl_dir("/var/lib/tengine/foo/bar").should == "foo/bar"
|
355
|
+
end
|
356
|
+
|
357
|
+
it "相対パスが指定されると(計算のしようがないので)そのまま返します" do
|
358
|
+
subject.relative_path_from_dsl_dir("lib/tengine/foo/bar").should == "lib/tengine/foo/bar"
|
359
|
+
end
|
360
|
+
end
|
361
|
+
|
362
|
+
context "ファイルが存在する場合" do
|
363
|
+
before do
|
364
|
+
Dir.should_receive(:exist?).with("/var/lib/tengine/init.rb").and_return(false)
|
365
|
+
File.should_receive(:exist?).with("/var/lib/tengine/init.rb").and_return(true)
|
366
|
+
end
|
367
|
+
|
368
|
+
it :dsl_file_paths do
|
369
|
+
subject.dsl_file_paths.should == ["/var/lib/tengine/init.rb"]
|
370
|
+
end
|
371
|
+
|
372
|
+
it_should_behave_like "絶対パス指定時のパスの振る舞い"
|
373
|
+
end
|
374
|
+
|
375
|
+
it_should_behave_like "ディレクトリもファイルも存在しない場合はエラー", "/var/lib/tengine/init.rb"
|
376
|
+
end
|
377
|
+
end
|
378
|
+
|
379
|
+
context "指定した設定ファイルが存在しない場合" do
|
380
|
+
it "例外を生成します" do
|
381
|
+
config_path = File.expand_path("../config_spec/unexist_config.yml", File.dirname(__FILE__))
|
382
|
+
expect{
|
383
|
+
Tengine::Core::Config::Core.new(:config => config_path)
|
384
|
+
}.to raise_error(Tengine::Core::ConfigError, /No such file or directory - #{config_path}/)
|
385
|
+
end
|
386
|
+
end
|
387
|
+
|
388
|
+
|
389
|
+
context "[BUG] tengined起動時に-fオプションで設定ファイルを指定した際に、設定ファイルに記載したdb-portの設定が有効でない" do
|
390
|
+
before do
|
391
|
+
@config_path = File.expand_path("../config_spec/another_port.yml", File.dirname(__FILE__))
|
392
|
+
end
|
393
|
+
|
394
|
+
shared_examples_for "正しく読み込む" do
|
395
|
+
it "DBについて" do
|
396
|
+
@config.should be_a(Tengine::Core::Config::Core) if @config
|
397
|
+
hash = @config || @hash
|
398
|
+
hash[:db]['port'].should == 21039
|
399
|
+
hash[:db]['host'].should == 'localhost'
|
400
|
+
hash[:db]['username'].should == nil
|
401
|
+
hash[:db]['password'].should == nil
|
402
|
+
hash[:db]['database'].should == "tengine_production"
|
403
|
+
end
|
404
|
+
end
|
405
|
+
|
406
|
+
context "バグストーリーに添付された設定ファイルをロード" do
|
407
|
+
# このテストは元々パスしてました
|
408
|
+
before do
|
409
|
+
@config = Tengine::Core::Config::Core.new(:config => @config_path)
|
410
|
+
end
|
411
|
+
it_should_behave_like "正しく読み込む"
|
412
|
+
end
|
413
|
+
|
414
|
+
context "起動コマンドの引数を解釈したConfig" do
|
415
|
+
before do
|
416
|
+
@config = Tengine::Core::Config::Core.parse(["-f", @config_path]) # bin/tenginedではARGVが渡されます
|
417
|
+
end
|
418
|
+
it_should_behave_like "正しく読み込む"
|
419
|
+
end
|
420
|
+
|
421
|
+
context "起動コマンドの引数を解釈したHash" do
|
422
|
+
before do
|
423
|
+
@hash = Tengine::Core::Config::Core.parse_to_hash(["-f", @config_path]) # bin/tenginedではARGVが渡されます
|
424
|
+
end
|
425
|
+
it ":configを除いてスケルトンとほとんど同じ" do
|
426
|
+
@hash[:config].should == @config_path
|
427
|
+
@hash[:config] = nil
|
428
|
+
@hash.should == Tengine::Core::Config::Core.skelton_hash
|
429
|
+
end
|
430
|
+
end
|
431
|
+
end
|
432
|
+
|
433
|
+
context "tenginedの設定ファイルが不正でエラーになった場合原因が分からないので、不正な箇所が解るようにする" do
|
434
|
+
it "erbの式の中に間違ったrubyのコードがある設定ファイル" do
|
435
|
+
path = File.expand_path("../config/syntax_error_in_erb.yml.erb", File.dirname(__FILE__))
|
436
|
+
begin
|
437
|
+
Tengine::Core::Config::Core.parse(["-f", path])
|
438
|
+
fail
|
439
|
+
rescue Tengine::Core::ConfigError => e
|
440
|
+
e.message.should =~ /syntax_error_in_erb.yml.erb:9: syntax error/
|
441
|
+
e.message.should include(path)
|
442
|
+
end
|
443
|
+
end
|
444
|
+
|
445
|
+
it "YAMLとして間違っている設定ファイル" do
|
446
|
+
path = File.expand_path("../config/wrong_yaml.yml.erb", File.dirname(__FILE__))
|
447
|
+
begin
|
448
|
+
Tengine::Core::Config::Core.parse(["-f", path])
|
449
|
+
fail
|
450
|
+
rescue Tengine::Core::ConfigError => e
|
451
|
+
e.message.should =~ /couldn't parse YAML at line \d+ column \d+/
|
452
|
+
e.message.should include(path)
|
453
|
+
end
|
454
|
+
end
|
455
|
+
|
456
|
+
it "項目名が間違っている設定ファイル" do
|
457
|
+
path = File.expand_path("../config/wrong_field_name.yml.erb", File.dirname(__FILE__))
|
458
|
+
begin
|
459
|
+
Tengine::Core::Config::Core.parse(["-f", path])
|
460
|
+
fail
|
461
|
+
rescue Tengine::Core::ConfigError => e
|
462
|
+
e.message.should =~ /undefined method `load_path='/
|
463
|
+
e.message.should include(path)
|
464
|
+
end
|
465
|
+
end
|
466
|
+
|
467
|
+
it "カテゴリ名が間違っている設定ファイル" do
|
468
|
+
path = File.expand_path("../config/wrong_category_name.yml.erb", File.dirname(__FILE__))
|
469
|
+
begin
|
470
|
+
Tengine::Core::Config::Core.parse(["-f", path])
|
471
|
+
fail
|
472
|
+
rescue Tengine::Core::ConfigError => e
|
473
|
+
e.message.should =~ /child not found for \"process_configs\"/
|
474
|
+
e.message.should include(path)
|
475
|
+
end
|
476
|
+
end
|
477
|
+
end
|
478
|
+
|
479
|
+
end
|