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.
Files changed (127) hide show
  1. data/Gemfile +1 -37
  2. data/Gemfile.lock +59 -61
  3. data/README.md +8 -6
  4. data/bin/create_indexes_for_tengine_core +18 -0
  5. data/bin/tengined +3 -3
  6. data/examples/list.txt +36 -0
  7. data/examples/uc08_if_both_a_and_b_occurs.rb +7 -1
  8. data/examples/uc20_fire_with_properties.rb +19 -0
  9. data/examples/uc21_fire_with_same_key.rb +23 -0
  10. data/examples/uc22_fire_with_source_name.rb +17 -0
  11. data/examples/uc23_fire_with_level.rb +19 -0
  12. data/examples/uc24_fire_with_level_key.rb +19 -0
  13. data/examples/uc30_local_variables.rb +28 -0
  14. data/examples/uc31_instance_variables.rb +35 -0
  15. data/examples/uc32_class_variables.rb +20 -0
  16. data/examples/uc33_statics.rb +20 -0
  17. data/examples2/uc30_local_variables.rb +55 -0
  18. data/examples2/uc31_instance_variables.rb +46 -0
  19. data/examples2/uc32_class_variables.rb +22 -0
  20. data/examples2/uc33_statics.rb +23 -0
  21. data/lib/tengine/core/bootstrap.rb +1 -1
  22. data/lib/tengine/core/config/atd.rb +0 -3
  23. data/lib/tengine/core/config/core.rb +21 -20
  24. data/lib/tengine/core/config/heartbeat_watcher.rb +0 -3
  25. data/lib/tengine/core/driveable.rb +34 -12
  26. data/lib/tengine/core/driver.rb +22 -9
  27. data/lib/tengine/core/dsl_evaluator.rb +2 -15
  28. data/lib/tengine/core/dsl_filter_def.rb +40 -0
  29. data/lib/tengine/core/dsl_loader.rb +1 -1
  30. data/lib/tengine/core/event.rb +44 -29
  31. data/lib/tengine/core/event/finder.rb +1 -1
  32. data/lib/tengine/core/event_exception_reportable.rb +7 -10
  33. data/lib/tengine/core/event_wrapper.rb +1 -1
  34. data/lib/tengine/core/find_by_name.rb +1 -1
  35. data/lib/tengine/core/handler.rb +14 -4
  36. data/lib/tengine/core/handler_path.rb +1 -1
  37. data/lib/tengine/core/heartbeat_watcher.rb +3 -2
  38. data/lib/tengine/core/kernel.rb +22 -6
  39. data/lib/tengine/core/mongoid_fix.rb +2 -1
  40. data/lib/tengine/core/mutex.rb +22 -8
  41. data/lib/tengine/core/optimistic_lock.rb +6 -6
  42. data/lib/tengine/core/safe_updatable.rb +24 -26
  43. data/lib/tengine/core/schedule.rb +2 -2
  44. data/lib/tengine/core/scheduler.rb +5 -4
  45. data/lib/tengine/core/session.rb +14 -0
  46. data/lib/tengine/core/session_wrapper.rb +20 -4
  47. data/lib/tengine/core/setting.rb +3 -3
  48. data/lib/tengine/rspec/extension.rb +6 -8
  49. metadata +156 -171
  50. data/.document +0 -5
  51. data/.rspec +0 -1
  52. data/Rakefile +0 -44
  53. data/VERSION +0 -1
  54. data/lib/tengine/core/connection_test/.gitignore +0 -1
  55. data/spec/factories/tengine_core_drivers.rb +0 -10
  56. data/spec/factories/tengine_core_events.rb +0 -14
  57. data/spec/factories/tengine_core_handler_paths.rb +0 -9
  58. data/spec/factories/tengine_core_handlers.rb +0 -9
  59. data/spec/factories/tengine_core_sessions.rb +0 -9
  60. data/spec/mongoid.yml +0 -35
  61. data/spec/spec_helper.rb +0 -48
  62. data/spec/support/mongo_index_key_log.rb +0 -91
  63. data/spec/tengine/core/bootstrap_spec.rb +0 -278
  64. data/spec/tengine/core/bugfix/bind_dsl_file_in_multi_byte_dir_spec.rb +0 -21
  65. data/spec/tengine/core/bugfix/enabled_on_activation_spec.rb +0 -112
  66. data/spec/tengine/core/bugfix/receive_event_spec.rb +0 -133
  67. data/spec/tengine/core/bugfix/use_dsl_version_method.rb +0 -12
  68. data/spec/tengine/core/bugfix/use_dsl_version_method_spec.rb +0 -28
  69. data/spec/tengine/core/bugfix/use_event_in_handler_dsl.rb +0 -11
  70. 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
  71. 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
  72. 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
  73. 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
  74. data/spec/tengine/core/config/atd_spec.rb +0 -62
  75. data/spec/tengine/core/config/core_spec.rb +0 -479
  76. data/spec/tengine/core/config/heartbeat_watcher_spec.rb +0 -62
  77. data/spec/tengine/core/config/syntax_error_in_erb.yml.erb +0 -13
  78. data/spec/tengine/core/config/wrong_category_name.yml.erb +0 -13
  79. data/spec/tengine/core/config/wrong_field_name.yml.erb +0 -12
  80. data/spec/tengine/core/config/wrong_yaml.yml.erb +0 -13
  81. data/spec/tengine/core/config_spec/another_port.yml +0 -54
  82. data/spec/tengine/core/config_spec/config_with_dir_absolute_load_path.yml +0 -16
  83. data/spec/tengine/core/config_spec/config_with_dir_relative_load_path.yml +0 -16
  84. data/spec/tengine/core/config_spec/config_with_file_absolute_load_path.yml +0 -16
  85. data/spec/tengine/core/config_spec/config_with_file_relative_load_path.yml +0 -16
  86. data/spec/tengine/core/config_spec/log_config_spec.rb +0 -245
  87. data/spec/tengine/core/driveable_spec.rb +0 -240
  88. data/spec/tengine/core/driver_spec.rb +0 -159
  89. data/spec/tengine/core/dsl_loader_spec.rb +0 -172
  90. data/spec/tengine/core/dsls/uc08_if_both_a_and_b_occurs_spec.rb +0 -35
  91. data/spec/tengine/core/dsls/uc10_if_the_event_occurs_at_the_server_spec.rb +0 -58
  92. data/spec/tengine/core/dsls/uc50_commit_event_at_first_spec.rb +0 -29
  93. data/spec/tengine/core/dsls/uc52_commit_event_after_all_handler_submit_spec.rb +0 -33
  94. data/spec/tengine/core/dsls/uc52_never_commit_event_unless_all_handler_submit_spec.rb +0 -38
  95. data/spec/tengine/core/dsls/uc53_submit_outside_of_handler_spec.rb +0 -37
  96. data/spec/tengine/core/dsls/uc60_event_in_handler_spec.rb +0 -31
  97. data/spec/tengine/core/dsls/uc61_event_outside_of_handler_spec.rb +0 -37
  98. data/spec/tengine/core/dsls/uc62_session_in_driver_spec.rb +0 -36
  99. data/spec/tengine/core/dsls/uc63_session_outside_of_driver_spec.rb +0 -35
  100. data/spec/tengine/core/dsls/uc64_safety_countup_spec.rb +0 -134
  101. data/spec/tengine/core/dsls/uc70_driver_enabled_on_activation_spec.rb +0 -39
  102. data/spec/tengine/core/dsls/uc71_driver_disabled_on_activation_spec.rb +0 -36
  103. data/spec/tengine/core/dsls/uc72_setup_eventmachine_spec.rb +0 -39
  104. data/spec/tengine/core/dsls/uc80_raise_io_error_spec.rb +0 -53
  105. data/spec/tengine/core/dsls/uc81_raise_runtime_error_spec.rb +0 -49
  106. data/spec/tengine/core/event/finder_spec.rb +0 -136
  107. data/spec/tengine/core/event_exception_reportable_spec.rb +0 -33
  108. data/spec/tengine/core/event_spec.rb +0 -161
  109. data/spec/tengine/core/event_wrapper_spec.rb +0 -35
  110. data/spec/tengine/core/handler_path_spec.rb +0 -87
  111. data/spec/tengine/core/handler_spec.rb +0 -190
  112. data/spec/tengine/core/heartbeat_watcher_spec.rb +0 -131
  113. data/spec/tengine/core/io_to_logger_spec.rb +0 -30
  114. data/spec/tengine/core/kernel_spec.rb +0 -902
  115. data/spec/tengine/core/mongodb_spec.rb +0 -12
  116. data/spec/tengine/core/mongoid_fix_spec.rb +0 -52
  117. data/spec/tengine/core/mutex_spec.rb +0 -201
  118. data/spec/tengine/core/optimistic_lock_spec.rb +0 -55
  119. data/spec/tengine/core/scheculer_spec.rb +0 -121
  120. data/spec/tengine/core/selectable_attr_spec.rb +0 -30
  121. data/spec/tengine/core/session_spec.rb +0 -104
  122. data/spec/tengine/core/setting_spec.rb +0 -79
  123. data/spec/tengine/core_spec.rb +0 -13
  124. data/spec/tengine_spec.rb +0 -14
  125. data/tengine_core.gemspec +0 -251
  126. data/tmp/log/.gitignore +0 -1
  127. data/tmp/tengined_status/.gitignore +0 -1
@@ -1,240 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
- require 'spec_helper'
3
-
4
- describe Tengine::Core::Driveable do
5
-
6
- describe :handling_by_instance_method do
7
- before do
8
- Tengine::Core::Setting.delete_all
9
- Tengine::Core::Setting.create!(:name => "dsl_version", :value => "123")
10
- Tengine::Core::Driver.delete_all
11
- Tengine::Core::HandlerPath.delete_all
12
- end
13
-
14
- def driveable_test_class_index
15
- $dtcindex ||= 0
16
- end
17
-
18
- def define_driveable_test_class
19
- $dtcindex ||= 0
20
- $dtcindex += 1
21
- @klass = Class.new
22
- Object.const_set(:"DriveableTestClass#{$dtcindex}", @klass)
23
- @klass.module_eval do
24
- include Tengine::Core::Driveable
25
-
26
- on:event01
27
- def foo # 引数なしでもOK
28
- STDOUT.puts "#{self.class.name}#foo"
29
- end
30
-
31
- on :event02, :event3 # 複数のイベント種別をハンドリング
32
- def bar(with_event) # 引数ありでもOK
33
- STDOUT.puts "#{self.class.name}#foo with event"
34
- end
35
-
36
- class << self # クラスメソッドの定義
37
- on:event04
38
- def baz # 引数なしでもOK
39
- STDOUT.puts "#{self.name}#baz"
40
- end
41
- end
42
-
43
- on :event05, :event6 # 複数のイベント種別をハンドリング
44
- def self.hoge(with_event) # 引数ありでもOK
45
- STDOUT.puts "#{self.name}#hoge with event"
46
- end
47
- end
48
- end
49
-
50
- context "[Bug]tenginedのデプロイコマンド bundle exec cap deploy:start を実行すると起動しないことがある" do
51
- context "nameとversionが同じものを2度書きもうとして" do
52
- before do
53
- @klass1, @klass2 = Class.new, Class.new
54
- end
55
-
56
- it "nameとversionのuniquenessバリデーションにひっかかる場合にはMongoid::Errors::Validationsをraiseしない" do
57
- Tengine::Core::Setting.should_receive(:dsl_version).exactly(3).times.and_return("123")
58
- @klass1.should_receive(:driver).and_return(nil)
59
- @klass1.should_receive(:driver_name).and_return("foo")
60
- @klass1.module_eval { include Tengine::Core::Driveable }
61
-
62
- @klass2.should_receive(:driver).and_return(nil)
63
- @klass2.should_receive(:driver_name).exactly(2).times.and_return("foo")
64
- @klass2.module_eval { include Tengine::Core::Driveable }
65
- end
66
-
67
- it "versionのformatバリデーションにひっかかる場合にはMongoid::Errors::Validationsをraiseする" do
68
- [@klass1, @klass2].each do |k|
69
- Tengine::Core::Setting.should_receive(:dsl_version).and_return("123")
70
- k.should_receive(:driver).and_return(nil)
71
- k.should_receive(:driver_name).and_return("123")
72
- expect { k.module_eval { include Tengine::Core::Driveable } }.to raise_error
73
- end
74
- end
75
-
76
- it "バリデーションで引っかからずにユニークインデックスの一意キー制約違反で落ちる場合にはMongo::OperationFailureをraiseしない" do
77
- # バリデーションのチェックをくぐり抜けてインサートを行わせるため
78
- Mongoid::Persistence::Operations::Insert.class_eval do
79
- def persist
80
- prepare do |doc|
81
- Fiber.yield
82
- collection.insert(doc.as_document, options)
83
- Mongoid::IdentityMap.set(doc)
84
- end
85
- end
86
- end
87
-
88
- f1 = Fiber.new {
89
- Tengine::Core::Setting.should_receive(:dsl_version).and_return("123")
90
- @klass1.should_receive(:driver).and_return(nil)
91
- @klass1.should_receive(:driver_name).and_return("bar")
92
- @klass1.module_eval { include Tengine::Core::Driveable }
93
- }
94
- f1.resume
95
-
96
- f2 = Fiber.new {
97
- Tengine::Core::Setting.should_receive(:dsl_version).exactly(2).times.and_return("123")
98
- @klass2.should_receive(:driver).and_return(nil)
99
- @klass2.should_receive(:driver_name).exactly(2).times.and_return("bar")
100
- @klass2.module_eval { include Tengine::Core::Driveable }
101
- }
102
- f2.resume
103
- f1.resume
104
- f2.resume
105
- f1.resume
106
- f2.resume
107
-
108
- # 元に戻しておく
109
- Mongoid::Persistence::Operations::Insert.class_eval do
110
- def persist
111
- prepare do |doc|
112
- collection.insert(doc.as_document, options)
113
- Mongoid::IdentityMap.set(doc)
114
- end
115
- end
116
- end
117
- end
118
- end
119
- end
120
-
121
- it "クラスを定義するファイルをloadするとドライバが登録されます" do
122
- expect{
123
- expect{
124
- # load(File.expand_path('driveable_spec/driveable_test_class.rb', File.dirname(__FILE__)))
125
- define_driveable_test_class
126
- }.to change(Tengine::Core::Driver, :count).by(1)
127
- }.to change(Tengine::Core::HandlerPath, :count).by(6)
128
- end
129
-
130
- context "すでにロードされている場合" do
131
- before do
132
- driver = Tengine::Core::Driver.new(
133
- :name => "DriveableTestClass#{driveable_test_class_index + 1}",
134
- :version => Tengine::Core::Setting.dsl_version,
135
- :target_class_name => "DriveableTestClass#{driveable_test_class_index + 1}"
136
- )
137
- options = {:filepath => __FILE__, :lineno => __LINE__}
138
- handler1 = driver.handlers.new({:target_method_name => 'foo' , :target_instantiation_key => :instance_method, :event_type_names => ['event01']}.update(options))
139
- handler2 = driver.handlers.new({:target_method_name => 'bar' , :target_instantiation_key => :instance_method, :event_type_names => ['event02', 'event03']}.update(options))
140
- handler3 = driver.handlers.new({:target_method_name => 'baz' , :target_instantiation_key => :static , :event_type_names => ['event04']}.update(options))
141
- handler4 = driver.handlers.new({:target_method_name => 'hoge', :target_instantiation_key => :static , :event_type_names => ['event05', 'event06']}.update(options))
142
- driver.save!
143
- driver.handler_paths.create!(:handler_id => handler1.id, :event_type_name => "event01")
144
- driver.handler_paths.create!(:handler_id => handler2.id, :event_type_name => "event02")
145
- driver.handler_paths.create!(:handler_id => handler2.id, :event_type_name => "event03")
146
- driver.handler_paths.create!(:handler_id => handler3.id, :event_type_name => "event04")
147
- driver.handler_paths.create!(:handler_id => handler4.id, :event_type_name => "event05")
148
- driver.handler_paths.create!(:handler_id => handler4.id, :event_type_name => "event06")
149
- end
150
- it "ドライバの件数は増えない" do
151
- expect{
152
- expect{
153
- define_driveable_test_class
154
- }.to_not change(Tengine::Core::Driver, :count)
155
- }.to_not change(Tengine::Core::HandlerPath, :count)
156
- end
157
- end
158
-
159
- context "ロードされたドライバ" do
160
- before do
161
- # load(File.expand_path('driveable_spec/driveable_test_class.rb', File.dirname(__FILE__)))
162
- define_driveable_test_class
163
- end
164
-
165
- subject{ Tengine::Core::Driver.first }
166
- its(:name){ should =~ /\ADriveableTestClass/ }
167
- its(:version){ should_not == nil }
168
- its(:enabled){ should == true }
169
- its(:enabled_on_activation){ should == true }
170
- its(:target_class_name){ should =~ /\ADriveableTestClass/ }
171
-
172
- context "handlers[0]" do
173
- subject{ Tengine::Core::Driver.first.handlers[0] }
174
- its(:target_instantiation_key){ should == :instance_method }
175
- its(:target_method_name){ should == 'foo' }
176
- end
177
-
178
- context "handlers[1]" do
179
- subject{ Tengine::Core::Driver.first.handlers[1] }
180
- its(:target_instantiation_key){ should == :instance_method }
181
- its(:target_method_name){ should == 'bar' }
182
- end
183
-
184
- context "handlers[2]" do
185
- subject{ Tengine::Core::Driver.first.handlers[2] }
186
- its(:target_instantiation_key){ should == :static }
187
- its(:target_method_name){ should == 'baz' }
188
- end
189
-
190
- context "handlers[3]" do
191
- subject{ Tengine::Core::Driver.first.handlers[3] }
192
- its(:target_instantiation_key){ should == :static }
193
- its(:target_method_name){ should == 'hoge' }
194
- end
195
-
196
- context "インスタンスメソッドによるイベントハンドリング" do
197
- (0..1).each do |idx|
198
- context "handlers[#{idx}]" do
199
- subject{ Tengine::Core::Driver.first.handlers[idx] }
200
- before do
201
- @event = mock(:event)
202
- end
203
- it "インスタンスが生成される" do
204
- instance = @klass.new
205
- @klass.should_receive(:new).with(no_args).and_return(instance)
206
- STDOUT.should_receive(:puts)
207
- subject.process_event(@event)
208
- end
209
- end
210
- end
211
-
212
- context "class << self...endで定義したクラスメソッドによるハンドリング" do
213
- subject{ Tengine::Core::Driver.first.handlers[2] }
214
- before do
215
- @event = mock(:event)
216
- end
217
- it "インスタンスが生成される" do
218
- STDOUT.should_receive(:puts)
219
- subject.process_event(@event)
220
- end
221
- end
222
-
223
- context "def self.hogeで定義したクラスメソッドによるハンドリング" do
224
- subject{ Tengine::Core::Driver.first.handlers[3] }
225
- before do
226
- @event = mock(:event)
227
- end
228
- it "インスタンスが生成される" do
229
- STDOUT.should_receive(:puts)
230
- subject.process_event(@event)
231
- end
232
- end
233
-
234
- end
235
- end
236
-
237
- end
238
-
239
-
240
- end
@@ -1,159 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
- require 'spec_helper'
3
-
4
- require 'mongoid/version'
5
-
6
- describe Tengine::Core::Driver do
7
-
8
- valid_attributes1 = {
9
- :name => "driver100",
10
- :version => "100",
11
- }.freeze
12
-
13
- context "nameとversionは必須" do
14
- it "正常系" do
15
- Tengine::Core::Driver.delete_all
16
- driver1 = Tengine::Core::Driver.new(valid_attributes1)
17
- driver1.valid?.should == true
18
- end
19
-
20
- [:name, :version].each do |key|
21
- it "#{key}なし" do
22
- attrs = valid_attributes1.dup
23
- attrs.delete(key)
24
- driver1 = Tengine::Core::Driver.new(attrs)
25
- driver1.valid?.should == false
26
- end
27
- end
28
- end
29
-
30
- context "nameはバージョン毎にユニーク" do
31
- before do
32
- Tengine::Core::Driver.delete_all
33
- Tengine::Core::Driver.create!(valid_attributes1)
34
- end
35
-
36
- it "同じ名前で登録されているものが存在する場合エラー" do
37
- msg =
38
- case Mongoid::VERSION
39
- when /^2\.2\./ then
40
- "Validation failed - Name is already taken in same version."
41
- else
42
- "Validation failed - Name is already taken."
43
- end
44
- expect{
45
- Tengine::Core::Driver.create!(valid_attributes1)
46
- }.to raise_error(Mongoid::Errors::Validations, msg)
47
- end
48
-
49
- it "同じバージョンでも異なる名前ならばOK" do
50
- Tengine::Core::Driver.create!(valid_attributes1.merge(:name => "driver200"))
51
- end
52
-
53
- it "同じ名前でも異なるバージョンならばOK" do
54
- Tengine::Core::Driver.create!(valid_attributes1.merge(:version => "101"))
55
- end
56
- end
57
-
58
- context "nameのフォーマットはベース名に準拠する" do
59
- it "スラッシュ'/’はリソース識別子で使われるのでnameには使用できません" do
60
- driver1 = Tengine::Core::Driver.new(:name => "foo/bar")
61
- driver1.valid?.should == false
62
- driver1.errors[:name].should == [Tengine::Core::Validation::BASE_NAME.message]
63
- end
64
-
65
- it "コロン':'はリソース識別子で使われるのでnameには使用できません" do
66
- driver1 = Tengine::Core::Driver.new(:name => "foo:bar")
67
- driver1.valid?.should == false
68
- driver1.errors[:name].should == [Tengine::Core::Validation::BASE_NAME.message]
69
- end
70
- end
71
-
72
- context "保存時にHandlerPathを自動的に登録します" do
73
- before do
74
- Tengine::Core::Driver.delete_all
75
- Tengine::Core::HandlerPath.delete_all
76
- @d11 = Tengine::Core::Driver.new(:name => "driver1", :version => "1", :enabled => true)
77
- @d11h1 = @d11.handlers.new(:event_type_names => ["foo" ], :filepath => "path/to/driver.rb", :lineno => 3)
78
- @d11h2 = @d11.handlers.new(:event_type_names => ["boo" ], :filepath => "path/to/driver.rb", :lineno => 5)
79
- @d11h3 = @d11.handlers.new(:event_type_names => ["blah"], :filepath => "path/to/driver.rb", :lineno => 7)
80
- @d11.save!
81
- end
82
- it do
83
- Tengine::Core::HandlerPath.count.should == 3
84
- Tengine::Core::HandlerPath.event_type_name("foo").map(&:handler_id).should == [@d11h1.id]
85
- Tengine::Core::HandlerPath.event_type_name("boo").map(&:handler_id).should == [@d11h2.id]
86
- Tengine::Core::HandlerPath.event_type_name("blah").map(&:handler_id).should == [@d11h3.id]
87
- end
88
- end
89
-
90
- context "must have only one session" do
91
- subject do
92
- Tengine::Core::Driver.delete_all
93
- Tengine::Core::Driver.create!(:name => "driver1", :version => "1", :enabled => true)
94
- end
95
- its(:session){ should be_a(Tengine::Core::Session)}
96
- end
97
-
98
- describe "名前で検索" do
99
- before do
100
- Tengine::Core::Setting.delete_all
101
- Tengine::Core::Setting.create!(:name => "dsl_version", :value => "2")
102
- Tengine::Core::Driver.delete_all
103
- Tengine::Core::Driver.create!(:name => "driver1", :version => "1", :enabled => true)
104
- Tengine::Core::Driver.create!(:name => "driver2", :version => "1", :enabled => true)
105
- Tengine::Core::Driver.create!(:name => "driver3", :version => "2", :enabled => true)
106
- Tengine::Core::Driver.create!(:name => "driver4", :version => "2", :enabled => true)
107
- end
108
-
109
- [:find_by_name, :find_by_name!].each do |method_name|
110
- context "存在する場合はそれを返す" do
111
- it "バージョン指定なし" do
112
- driver = Tengine::Core::Driver.send(method_name, "driver3")
113
- driver.should be_a(Tengine::Core::Driver)
114
- driver.name.should == "driver3"
115
- driver.version.should == "2"
116
- end
117
-
118
- it "バージョン指定あり" do
119
- driver = Tengine::Core::Driver.send(method_name, "driver1", :version => "1")
120
- driver.should be_a(Tengine::Core::Driver)
121
- driver.name.should == "driver1"
122
- driver.version.should == "1"
123
- end
124
- end
125
- end
126
-
127
- context ":find_by_nameは見つからなかった場合はnilを返す" do
128
- it "バージョン指定なし" do
129
- Tengine::Core::Driver.find_by_name("driver1").should == nil
130
- end
131
-
132
- it "バージョン指定あり" do
133
- Tengine::Core::Driver.find_by_name("driver3", :version => "1").should == nil
134
- end
135
- end
136
-
137
- context ":find_by_name!は見つからなかった場合はTengine::Errors::NotFoundをraiseする" do
138
- it "バージョン指定なし" do
139
- begin
140
- Tengine::Core::Driver.find_by_name!("driver2")
141
- fail
142
- rescue Tengine::Errors::NotFound => e
143
- e.message.should == "Tengine::Core::Driver named \"driver2\" not found"
144
- end
145
- end
146
-
147
- it "バージョン指定あり" do
148
- begin
149
- Tengine::Core::Driver.find_by_name!("driver4", :version => "1")
150
- fail
151
- rescue Tengine::Errors::NotFound => e
152
- e.message.should == "Tengine::Core::Driver named \"driver4\" with {:version=>\"1\"} not found"
153
- end
154
- end
155
- end
156
-
157
- end
158
-
159
- end
@@ -1,172 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
- require 'spec_helper'
3
-
4
- describe Tengine::Core::DslLoader do
5
-
6
- describe :__evaluate__ do
7
- before do
8
- Tengine::Core::Driver.delete_all
9
- Tengine::Core::HandlerPath.delete_all
10
- end
11
-
12
- context "DSLのファイルを指定する場合" do
13
- context "Driverを有効化して登録(シングルプロセスモード)" do
14
- before do
15
- config = Tengine::Core::Config::Core.new({
16
- :tengined => {
17
- :load_path => File.expand_path('../../../examples/uc01_execute_processing_for_event.rb', File.dirname(__FILE__))
18
- }
19
- })
20
- @kernel = Tengine::Core::Kernel.new(config)
21
- end
22
-
23
- it "イベントハンドラ定義を評価して、ドライバとハンドラを登録する" do
24
- @kernel.evaluate
25
- # $LOAD_PATH.include?(@config[:dsl_store_path]).should be_true
26
- # driver01 = Tengine::Core::Driver.find(:conditions => {:name => "driver01"})
27
- Tengine::Core::Driver.count.should == 1
28
- driver01 = Tengine::Core::Driver.first
29
- driver01.should_not be_nil
30
- driver01.name.should == "driver01"
31
- driver01.version.should == "20110902213500"
32
- driver01.enabled.should == true
33
- driver01.handlers.count.should == 1
34
- handler1 = driver01.handlers.first
35
- handler1.event_type_names.should == %w[event01]
36
- Tengine::Core::HandlerPath.where(:driver_id => driver01.id).count.should == 1
37
- Tengine::Core::HandlerPath.default_driver_version = "20110902213500"
38
- Tengine::Core::HandlerPath.find_handlers("event01").count.should == 1
39
- end
40
- end
41
-
42
-
43
- context "Driverを無効化して登録(マルチプロセスモード)" do
44
- before do
45
- config = Tengine::Core::Config::Core.new({
46
- :tengined => {
47
- :load_path => File.expand_path('../../../examples/uc01_execute_processing_for_event.rb', File.dirname(__FILE__)),
48
- :skip_enablement => true
49
- }
50
- })
51
- @kernel = Tengine::Core::Kernel.new(config)
52
- end
53
-
54
- it "イベントハンドラ定義を評価して、ドライバとハンドラを登録する" do
55
- @kernel.evaluate
56
- Tengine::Core::Driver.count.should == 1
57
- driver01 = Tengine::Core::Driver.first
58
- driver01.should_not be_nil
59
- driver01.name.should == "driver01"
60
- driver01.version.should == "20110902213500"
61
- driver01.handlers.count.should == 1
62
- handler1 = driver01.handlers.first
63
- handler1.event_type_names.should == %w[event01]
64
- Tengine::Core::HandlerPath.where(:driver_id => driver01.id).count.should == 1
65
- Tengine::Core::HandlerPath.default_driver_version = "20110902213500"
66
- Tengine::Core::HandlerPath.find_handlers("event01").count.should == 0
67
- end
68
- end
69
- end
70
-
71
- context "DSLのファイルを指定しない場合" do
72
- before do
73
- config = Tengine::Core::Config::Core.new({
74
- :tengined => {
75
- :load_path => File.expand_path('../../../examples', File.dirname(__FILE__))
76
- }
77
- })
78
- @kernel = Tengine::Core::Kernel.new(config)
79
- @loader = @kernel.dsl_context
80
-
81
- @loader.config.should_receive(:dsl_file_paths).and_return([
82
- "#{config[:tengined][:load_path]}/uc01_execute_processing_for_event.rb",
83
- "#{config[:tengined][:load_path]}/uc02_fire_another_event.rb",
84
- "#{config[:tengined][:load_path]}/uc03_2handlers_for_1event.rb",
85
- ])
86
- end
87
-
88
- it "イベントハンドラ定義を評価して、ドライバとハンドラを登録する" do
89
- # driver03にevent03が複数定義されているための警告メッセージ
90
- # Tengine::Core.stdout_logger.should_receive(:warn).with("driver\"driver03\"には、同一のevent_type_name\"event03\"が複数存在します")
91
-
92
- @kernel.evaluate
93
-
94
- Tengine::Core::Driver.count.should == 3
95
- drivers = Tengine::Core::Driver.all
96
- drivers.map(&:name).sort.should == ["driver01", "driver02", "driver03"]
97
- drivers.each do |driver|
98
- driver.version.should == "20110902213500"
99
- end
100
-
101
- driver01 = Tengine::Core::Driver.where(:name => "driver01").first
102
- handler1 = driver01.handlers.first
103
- handler1.event_type_names.should == %w[event01]
104
- Tengine::Core::HandlerPath.where(:driver_id => driver01.id).count.should == 1
105
-
106
- driver02 = Tengine::Core::Driver.where(:name => "driver02").first
107
- driver02.handlers.count.should == 2
108
- handler2_1, handler2_2 = driver02.handlers
109
- handler2_1.event_type_names.should == %w[event02_1]
110
- handler2_2.event_type_names.should == %w[event02_2]
111
- Tengine::Core::HandlerPath.where(:driver_id => driver02.id).count.should == 2
112
-
113
- driver03 = Tengine::Core::Driver.where(:name => "driver03").first
114
- driver03.handlers.count.should == 2
115
- handler3_1 = driver03.handlers.first
116
- handler3_1.filepath.should == "uc03_2handlers_for_1event.rb"
117
- handler3_1.lineno.should == 8
118
- handler3_1.event_type_names.should == %w[event03]
119
- handler3_2 = driver03.handlers.last
120
- handler3_2.filepath.should == "uc03_2handlers_for_1event.rb"
121
- handler3_2.lineno.should == 12
122
- handler3_2.event_type_names.should == %w[event03]
123
- Tengine::Core::HandlerPath.where(:driver_id => driver03.id).count.should == 2
124
- end
125
- end
126
- end
127
-
128
- describe "フィルタの登録" do
129
- before do
130
- Tengine::Core::Driver.delete_all
131
- Tengine::Core::HandlerPath.delete_all
132
- end
133
-
134
- context "Driverを有効化して登録(シングルプロセスモード)" do
135
- before do
136
- config = Tengine::Core::Config::Core.new({
137
- :tengined => {
138
- :load_path => File.expand_path('../../../examples/uc08_if_both_a_and_b_occurs.rb', File.dirname(__FILE__))
139
- }
140
- })
141
- @kernel = Tengine::Core::Kernel.new(config)
142
- end
143
-
144
- it "イベントハンドラ定義を評価して、ドライバとハンドラを登録する" do
145
- @kernel.evaluate
146
- Tengine::Core::Driver.count.should == 1
147
- driver = Tengine::Core::Driver.first
148
- driver.should_not be_nil
149
- driver.name.should == "driver08"
150
- driver.version.should == "20110902213500"
151
- driver.handlers.count.should == 1
152
- handler1 = driver.handlers.first
153
- handler1.event_type_names.should == %w[event08_a event_08_b]
154
- handler1.filter.should == {
155
- 'method' => :and,
156
- 'children' => [
157
- { 'pattern' => :event08_a , 'method' => :find_or_mark_in_session },
158
- { 'pattern' => :event_08_b, 'method' => :find_or_mark_in_session },
159
- ]
160
- }
161
- Tengine::Core::HandlerPath.where(:driver_id => driver.id).count.should == 2
162
- Tengine::Core::HandlerPath.default_driver_version = "20110902213500"
163
- handler_a = Tengine::Core::HandlerPath.find_handlers("event08_a").first
164
- handler_b = Tengine::Core::HandlerPath.find_handlers("event_08_b").last
165
- handler_a.id.should == handler1.id
166
- handler_b.id.should == handler1.id
167
- end
168
- end
169
-
170
- end
171
-
172
- end