tengine_core 0.5.39 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +1 -37
- data/Gemfile.lock +59 -61
- data/README.md +8 -6
- data/bin/create_indexes_for_tengine_core +18 -0
- data/bin/tengined +3 -3
- data/examples/list.txt +36 -0
- data/examples/uc08_if_both_a_and_b_occurs.rb +7 -1
- data/examples/uc20_fire_with_properties.rb +19 -0
- data/examples/uc21_fire_with_same_key.rb +23 -0
- data/examples/uc22_fire_with_source_name.rb +17 -0
- data/examples/uc23_fire_with_level.rb +19 -0
- data/examples/uc24_fire_with_level_key.rb +19 -0
- data/examples/uc30_local_variables.rb +28 -0
- data/examples/uc31_instance_variables.rb +35 -0
- data/examples/uc32_class_variables.rb +20 -0
- data/examples/uc33_statics.rb +20 -0
- data/examples2/uc30_local_variables.rb +55 -0
- data/examples2/uc31_instance_variables.rb +46 -0
- data/examples2/uc32_class_variables.rb +22 -0
- data/examples2/uc33_statics.rb +23 -0
- data/lib/tengine/core/bootstrap.rb +1 -1
- data/lib/tengine/core/config/atd.rb +0 -3
- data/lib/tengine/core/config/core.rb +21 -20
- data/lib/tengine/core/config/heartbeat_watcher.rb +0 -3
- data/lib/tengine/core/driveable.rb +34 -12
- data/lib/tengine/core/driver.rb +22 -9
- data/lib/tengine/core/dsl_evaluator.rb +2 -15
- data/lib/tengine/core/dsl_filter_def.rb +40 -0
- data/lib/tengine/core/dsl_loader.rb +1 -1
- data/lib/tengine/core/event.rb +44 -29
- data/lib/tengine/core/event/finder.rb +1 -1
- data/lib/tengine/core/event_exception_reportable.rb +7 -10
- data/lib/tengine/core/event_wrapper.rb +1 -1
- data/lib/tengine/core/find_by_name.rb +1 -1
- data/lib/tengine/core/handler.rb +14 -4
- data/lib/tengine/core/handler_path.rb +1 -1
- data/lib/tengine/core/heartbeat_watcher.rb +3 -2
- data/lib/tengine/core/kernel.rb +22 -6
- data/lib/tengine/core/mongoid_fix.rb +2 -1
- data/lib/tengine/core/mutex.rb +22 -8
- data/lib/tengine/core/optimistic_lock.rb +6 -6
- data/lib/tengine/core/safe_updatable.rb +24 -26
- data/lib/tengine/core/schedule.rb +2 -2
- data/lib/tengine/core/scheduler.rb +5 -4
- data/lib/tengine/core/session.rb +14 -0
- data/lib/tengine/core/session_wrapper.rb +20 -4
- data/lib/tengine/core/setting.rb +3 -3
- data/lib/tengine/rspec/extension.rb +6 -8
- metadata +156 -171
- data/.document +0 -5
- data/.rspec +0 -1
- data/Rakefile +0 -44
- data/VERSION +0 -1
- data/lib/tengine/core/connection_test/.gitignore +0 -1
- data/spec/factories/tengine_core_drivers.rb +0 -10
- data/spec/factories/tengine_core_events.rb +0 -14
- data/spec/factories/tengine_core_handler_paths.rb +0 -9
- data/spec/factories/tengine_core_handlers.rb +0 -9
- data/spec/factories/tengine_core_sessions.rb +0 -9
- data/spec/mongoid.yml +0 -35
- data/spec/spec_helper.rb +0 -48
- data/spec/support/mongo_index_key_log.rb +0 -91
- data/spec/tengine/core/bootstrap_spec.rb +0 -278
- data/spec/tengine/core/bugfix/bind_dsl_file_in_multi_byte_dir_spec.rb +0 -21
- data/spec/tengine/core/bugfix/enabled_on_activation_spec.rb +0 -112
- data/spec/tengine/core/bugfix/receive_event_spec.rb +0 -133
- data/spec/tengine/core/bugfix/use_dsl_version_method.rb +0 -12
- data/spec/tengine/core/bugfix/use_dsl_version_method_spec.rb +0 -28
- data/spec/tengine/core/bugfix/use_event_in_handler_dsl.rb +0 -11
- 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 +0 -35
- 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 +0 -38
- 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 +0 -35
- 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 +0 -38
- data/spec/tengine/core/config/atd_spec.rb +0 -62
- data/spec/tengine/core/config/core_spec.rb +0 -479
- data/spec/tengine/core/config/heartbeat_watcher_spec.rb +0 -62
- data/spec/tengine/core/config/syntax_error_in_erb.yml.erb +0 -13
- data/spec/tengine/core/config/wrong_category_name.yml.erb +0 -13
- data/spec/tengine/core/config/wrong_field_name.yml.erb +0 -12
- data/spec/tengine/core/config/wrong_yaml.yml.erb +0 -13
- data/spec/tengine/core/config_spec/another_port.yml +0 -54
- data/spec/tengine/core/config_spec/config_with_dir_absolute_load_path.yml +0 -16
- data/spec/tengine/core/config_spec/config_with_dir_relative_load_path.yml +0 -16
- data/spec/tengine/core/config_spec/config_with_file_absolute_load_path.yml +0 -16
- data/spec/tengine/core/config_spec/config_with_file_relative_load_path.yml +0 -16
- data/spec/tengine/core/config_spec/log_config_spec.rb +0 -245
- data/spec/tengine/core/driveable_spec.rb +0 -240
- data/spec/tengine/core/driver_spec.rb +0 -159
- data/spec/tengine/core/dsl_loader_spec.rb +0 -172
- data/spec/tengine/core/dsls/uc08_if_both_a_and_b_occurs_spec.rb +0 -35
- data/spec/tengine/core/dsls/uc10_if_the_event_occurs_at_the_server_spec.rb +0 -58
- data/spec/tengine/core/dsls/uc50_commit_event_at_first_spec.rb +0 -29
- data/spec/tengine/core/dsls/uc52_commit_event_after_all_handler_submit_spec.rb +0 -33
- data/spec/tengine/core/dsls/uc52_never_commit_event_unless_all_handler_submit_spec.rb +0 -38
- data/spec/tengine/core/dsls/uc53_submit_outside_of_handler_spec.rb +0 -37
- data/spec/tengine/core/dsls/uc60_event_in_handler_spec.rb +0 -31
- data/spec/tengine/core/dsls/uc61_event_outside_of_handler_spec.rb +0 -37
- data/spec/tengine/core/dsls/uc62_session_in_driver_spec.rb +0 -36
- data/spec/tengine/core/dsls/uc63_session_outside_of_driver_spec.rb +0 -35
- data/spec/tengine/core/dsls/uc64_safety_countup_spec.rb +0 -134
- data/spec/tengine/core/dsls/uc70_driver_enabled_on_activation_spec.rb +0 -39
- data/spec/tengine/core/dsls/uc71_driver_disabled_on_activation_spec.rb +0 -36
- data/spec/tengine/core/dsls/uc72_setup_eventmachine_spec.rb +0 -39
- data/spec/tengine/core/dsls/uc80_raise_io_error_spec.rb +0 -53
- data/spec/tengine/core/dsls/uc81_raise_runtime_error_spec.rb +0 -49
- data/spec/tengine/core/event/finder_spec.rb +0 -136
- data/spec/tengine/core/event_exception_reportable_spec.rb +0 -33
- data/spec/tengine/core/event_spec.rb +0 -161
- data/spec/tengine/core/event_wrapper_spec.rb +0 -35
- data/spec/tengine/core/handler_path_spec.rb +0 -87
- data/spec/tengine/core/handler_spec.rb +0 -190
- data/spec/tengine/core/heartbeat_watcher_spec.rb +0 -131
- data/spec/tengine/core/io_to_logger_spec.rb +0 -30
- data/spec/tengine/core/kernel_spec.rb +0 -902
- data/spec/tengine/core/mongodb_spec.rb +0 -12
- data/spec/tengine/core/mongoid_fix_spec.rb +0 -52
- data/spec/tengine/core/mutex_spec.rb +0 -201
- data/spec/tengine/core/optimistic_lock_spec.rb +0 -55
- data/spec/tengine/core/scheculer_spec.rb +0 -121
- data/spec/tengine/core/selectable_attr_spec.rb +0 -30
- data/spec/tengine/core/session_spec.rb +0 -104
- data/spec/tengine/core/setting_spec.rb +0 -79
- data/spec/tengine/core_spec.rb +0 -13
- data/spec/tengine_spec.rb +0 -14
- data/tengine_core.gemspec +0 -251
- data/tmp/log/.gitignore +0 -1
- data/tmp/tengined_status/.gitignore +0 -1
@@ -1,62 +0,0 @@
|
|
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
|
@@ -1,479 +0,0 @@
|
|
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
|