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,35 +0,0 @@
|
|
1
|
-
# -*- coding: utf-8 -*-
|
2
|
-
require 'spec_helper'
|
3
|
-
|
4
|
-
require 'tengine/event'
|
5
|
-
|
6
|
-
describe Tengine::Core::EventWrapper do
|
7
|
-
context "[]でpropertiesの属性にアクセス可能" do
|
8
|
-
before do
|
9
|
-
@event = Tengine::Core::Event.create!(
|
10
|
-
:key => Tengine::Event.uuid_gen.generate,
|
11
|
-
:event_type_name => "foo",
|
12
|
-
:sender_name => "server1",
|
13
|
-
:properties => {
|
14
|
-
:foo => [1,2,3,4],
|
15
|
-
:bar => "BAR"
|
16
|
-
})
|
17
|
-
@event.reload
|
18
|
-
end
|
19
|
-
|
20
|
-
subject do
|
21
|
-
Tengine::Core::EventWrapper.new(@event)
|
22
|
-
end
|
23
|
-
|
24
|
-
it do
|
25
|
-
@event.properties['foo'].should == [1,2,3,4]
|
26
|
-
@event.properties[:foo].should == nil
|
27
|
-
subject.properties['foo'].should == [1,2,3,4]
|
28
|
-
subject.properties[:foo].should == nil
|
29
|
-
subject['foo'].should == [1,2,3,4]
|
30
|
-
subject[:foo].should == [1,2,3,4]
|
31
|
-
subject['bar'].should == "BAR"
|
32
|
-
subject[:bar].should == "BAR"
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
@@ -1,87 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Tengine::Core::HandlerPath do
|
4
|
-
|
5
|
-
describe :find_handlers do
|
6
|
-
before do
|
7
|
-
Tengine::Core::Driver.delete_all
|
8
|
-
@d11 = Tengine::Core::Driver.find_or_create_by(name:"driver1", version:"1", enabled:true)
|
9
|
-
@d11h1 = @d11.handlers.find_or_create_by(:event_type_names => ["foo" ], :filepath => "path/to/driver1.rb", :lineno => 5)
|
10
|
-
@d11h2 = @d11.handlers.find_or_create_by(:event_type_names => ["boo" ], :filepath => "path/to/driver1.rb", :lineno => 10)
|
11
|
-
@d11h3 = @d11.handlers.find_or_create_by(:event_type_names => ["blah"], :filepath => "path/to/driver1.rb", :lineno => 15)
|
12
|
-
Tengine::Core::HandlerPath.create(:event_type_name => "foo", :driver => @d11, :handler_id => @d11h1.id)
|
13
|
-
Tengine::Core::HandlerPath.create(:event_type_name => "boo", :driver => @d11, :handler_id => @d11h2.id)
|
14
|
-
Tengine::Core::HandlerPath.create(:event_type_name => "blah", :driver => @d11, :handler_id => @d11h3.id)
|
15
|
-
@d21 = Tengine::Core::Driver.find_or_create_by(name:"driver1", version:"2", enabled:true)
|
16
|
-
@d21h1 = @d21.handlers.find_or_create_by(:event_type_names => ["foo"], :filepath => "path/to/driver1.rb", :lineno => 5)
|
17
|
-
@d21h2 = @d21.handlers.find_or_create_by(:event_type_names => ["boo"], :filepath => "path/to/driver1.rb", :lineno => 12)
|
18
|
-
Tengine::Core::HandlerPath.create(:event_type_name => "foo", :driver => @d21, :handler_id => @d21h1.id)
|
19
|
-
Tengine::Core::HandlerPath.create(:event_type_name => "boo", :driver => @d21, :handler_id => @d21h2.id)
|
20
|
-
@d22 = Tengine::Core::Driver.find_or_create_by(name:"driver2", version:"2", enabled:true)
|
21
|
-
@d22h1 = @d22.handlers.find_or_create_by(:event_type_names => ["foo"], :filepath => "path/to/driver2.rb", :lineno => 20)
|
22
|
-
@d22h2 = @d22.handlers.find_or_create_by(:event_type_names => ["bar"], :filepath => "path/to/driver2.rb", :lineno => 30)
|
23
|
-
Tengine::Core::HandlerPath.create(:event_type_name => "foo", :driver => @d22, :handler_id => @d22h1.id)
|
24
|
-
Tengine::Core::HandlerPath.create(:event_type_name => "bar", :driver => @d22, :handler_id => @d22h2.id)
|
25
|
-
@d23 = Tengine::Core::Driver.find_or_create_by(name:"driver3", version:"2", enabled:false)
|
26
|
-
@d23h1 = @d23.handlers.find_or_create_by(:event_type_names => ["bar"], :filepath => "path/to/driver3.rb", :lineno => 2)
|
27
|
-
@d23h2 = @d23.handlers.find_or_create_by(:event_type_names => ["baz"], :filepath => "path/to/driver3.rb", :lineno => 10)
|
28
|
-
Tengine::Core::HandlerPath.create(:event_type_name => "bar", :driver => @d23, :handler_id => @d23h1.id)
|
29
|
-
Tengine::Core::HandlerPath.create(:event_type_name => "baz", :driver => @d23, :handler_id => @d23h2.id)
|
30
|
-
end
|
31
|
-
|
32
|
-
context "with default_driver_version" do
|
33
|
-
it "should return handlers" do
|
34
|
-
Tengine::Core::HandlerPath.default_driver_version = "2"
|
35
|
-
Tengine::Core::HandlerPath.find_handlers("foo").map(&:id).should == [@d21h1.id, @d22h1.id]
|
36
|
-
Tengine::Core::HandlerPath.find_handlers("boo").map(&:id).should == [@d21h2.id]
|
37
|
-
Tengine::Core::HandlerPath.find_handlers("bar").map(&:id).should == [@d22h2.id]
|
38
|
-
Tengine::Core::HandlerPath.find_handlers("baz").map(&:id).should == []
|
39
|
-
Tengine::Core::HandlerPath.find_handlers("FOO").map(&:id).should == []
|
40
|
-
Tengine::Core::HandlerPath.find_handlers("blah").map(&:id).should == []
|
41
|
-
end
|
42
|
-
|
43
|
-
it "should return old handlers" do
|
44
|
-
Tengine::Core::HandlerPath.default_driver_version = "1"
|
45
|
-
Tengine::Core::HandlerPath.find_handlers("foo").map(&:id).should == [@d11h1.id]
|
46
|
-
Tengine::Core::HandlerPath.find_handlers("boo").map(&:id).should == [@d11h2.id]
|
47
|
-
Tengine::Core::HandlerPath.find_handlers("blah").map(&:id).should == [@d11h3.id]
|
48
|
-
Tengine::Core::HandlerPath.find_handlers("bar").map(&:id).should == []
|
49
|
-
Tengine::Core::HandlerPath.find_handlers("baz").map(&:id).should == []
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
context "generated handler_paths" do
|
54
|
-
before do
|
55
|
-
Tengine::Core::Driver.delete_all
|
56
|
-
Tengine::Core::HandlerPath.delete_all
|
57
|
-
end
|
58
|
-
|
59
|
-
it "should return handlers for enabled driver" do
|
60
|
-
@driver = Tengine::Core::Driver.new(:name => "driver01", :version => "123", :enabled => true)
|
61
|
-
@handler1 = @driver.handlers.new(:event_type_names => ["event01"],
|
62
|
-
:filepath => "path/to/driver01.rb", :lineno => 8)
|
63
|
-
@driver.save!
|
64
|
-
|
65
|
-
Tengine::Core::HandlerPath.all.count.should == 1
|
66
|
-
Tengine::Core::HandlerPath.default_driver_version = "123"
|
67
|
-
handlers = Tengine::Core::HandlerPath.find_handlers("event01")
|
68
|
-
handlers.count.should == 1
|
69
|
-
handlers.each do |handler|
|
70
|
-
handler.id.should == @handler1.id
|
71
|
-
end
|
72
|
-
end
|
73
|
-
|
74
|
-
it "should return handlers for disabled driver" do
|
75
|
-
@driver = Tengine::Core::Driver.new(:name => "driver01", :version => "123", :enabled => false)
|
76
|
-
@handler1 = @driver.handlers.new(:event_type_names => ["event01"],
|
77
|
-
:filepath => "path/to/driver01.rb", :lineno => 8)
|
78
|
-
@driver.save!
|
79
|
-
|
80
|
-
Tengine::Core::HandlerPath.all.count.should == 1
|
81
|
-
Tengine::Core::HandlerPath.default_driver_version = "123"
|
82
|
-
Tengine::Core::HandlerPath.find_handlers("event01").count.should == 0
|
83
|
-
end
|
84
|
-
end
|
85
|
-
end
|
86
|
-
|
87
|
-
end
|
@@ -1,190 +0,0 @@
|
|
1
|
-
# -*- coding: utf-8 -*-
|
2
|
-
require 'spec_helper'
|
3
|
-
|
4
|
-
describe Tengine::Core::Handler do
|
5
|
-
valid_attributes1 = {
|
6
|
-
:filepath => "path/to/driver.rb",
|
7
|
-
:lineno => 100,
|
8
|
-
}.freeze
|
9
|
-
|
10
|
-
context "filepathとlinenoは必須" do
|
11
|
-
it "正常系" do
|
12
|
-
driver1 = Tengine::Core::Handler.new(valid_attributes1)
|
13
|
-
driver1.valid?.should == true
|
14
|
-
end
|
15
|
-
|
16
|
-
[:filepath, :lineno].each do |key|
|
17
|
-
it "#{key}なし" do
|
18
|
-
attrs = valid_attributes1.dup
|
19
|
-
attrs.delete(key)
|
20
|
-
driver1 = Tengine::Core::Handler.new(attrs)
|
21
|
-
driver1.valid?.should == false
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
# context :process_event do
|
27
|
-
# before do
|
28
|
-
# @driver = Tengine::Core::Driver.new
|
29
|
-
# @handler = Tengine::Core::Handler.new(:driver => @driver)
|
30
|
-
# end
|
31
|
-
|
32
|
-
# it "マッチするかどうかと関係なくブロックが呼び出されます" do
|
33
|
-
# mock_dsl_context = mock(:dsl_context)
|
34
|
-
# mock_kernel = mock(:kernel)
|
35
|
-
# mock_event = mock(:event)
|
36
|
-
# mock_caller = mock(:caller)
|
37
|
-
# mock_block = nil
|
38
|
-
# mock_caller.instance_eval do
|
39
|
-
# mock_block = lambda{}
|
40
|
-
# end
|
41
|
-
# mock_event.stub(:kernel).and_return(mock_kernel)
|
42
|
-
# mock_kernel.stub(:dsl_context).and_return(mock_dsl_context)
|
43
|
-
# mock_dsl_context.stub(:__block_for__).and_return(mock_block)
|
44
|
-
# # @handler.should_receive(:instance_eval).with(&mock_block)
|
45
|
-
# mock_caller.should_receive(:__safety_driver__).and_yield
|
46
|
-
# mock_caller.should_receive(:__safety_event__).and_yield
|
47
|
-
# mock_caller.should_receive(:instance_eval)
|
48
|
-
# @handler.process_event(mock_event, &mock_block)
|
49
|
-
# end
|
50
|
-
# end
|
51
|
-
|
52
|
-
describe :match? do
|
53
|
-
context "without session" do
|
54
|
-
# it "by source_name"
|
55
|
-
# it "by sender_name"
|
56
|
-
# it "by occurred_at"
|
57
|
-
end
|
58
|
-
|
59
|
-
context "with session" do
|
60
|
-
context "foo & bar" do
|
61
|
-
before do
|
62
|
-
Tengine::Core::Driver.delete_all
|
63
|
-
Tengine::Core::Session.delete_all
|
64
|
-
@driver1 = Tengine::Core::Driver.new(:name => "driver1", :version => "123")
|
65
|
-
@handler = @driver1.handlers.new(:event_type_names => [:foo, :bar],
|
66
|
-
:filepath => "path/to/driver.rb",
|
67
|
-
:lineno => 11,
|
68
|
-
:filter => {
|
69
|
-
'method' => :and,
|
70
|
-
'children' => [
|
71
|
-
{ 'pattern' => 'foo', 'method' => :find_or_mark_in_session },
|
72
|
-
{ 'pattern' => 'bar', 'method' => :find_or_mark_in_session },
|
73
|
-
]
|
74
|
-
})
|
75
|
-
@driver1.save!
|
76
|
-
@handler
|
77
|
-
end
|
78
|
-
subject{ @handler }
|
79
|
-
|
80
|
-
it "最初にfooが受信したらセッションに記録してfalse" do
|
81
|
-
event_foo = FactoryGirl.create(:"tengine/core/event", :event_type_name => "foo")
|
82
|
-
subject.match?(event_foo).should == false
|
83
|
-
@driver1.session.system_properties.should == {'mark_foo' => true}
|
84
|
-
end
|
85
|
-
|
86
|
-
it "最初にbarが受信したらセッションに記録してfalse" do
|
87
|
-
# 実装がall?などを使って全てのフィルタを評価しない場合は失敗することがあります。
|
88
|
-
event_bar = FactoryGirl.create(:"tengine/core/event", :event_type_name => "bar")
|
89
|
-
subject.match?(event_bar).should == false
|
90
|
-
@driver1.session.system_properties.should == {'mark_bar' => true}
|
91
|
-
end
|
92
|
-
|
93
|
-
context "一度fooを受信した場合" do
|
94
|
-
before do
|
95
|
-
session = @driver1.session
|
96
|
-
session.system_properties = {'mark_foo' => true}
|
97
|
-
session.save!
|
98
|
-
end
|
99
|
-
|
100
|
-
it "再度fooが来るとセッションは変更なくfalse" do
|
101
|
-
event_foo = FactoryGirl.create(:"tengine/core/event", :event_type_name => "foo")
|
102
|
-
subject.match?(event_foo).should == false
|
103
|
-
@driver1.reload
|
104
|
-
@driver1.session.system_properties.should == {'mark_foo' => true}
|
105
|
-
end
|
106
|
-
|
107
|
-
it "barが来るとセッションを変更してtrue" do
|
108
|
-
event_bar = FactoryGirl.create(:"tengine/core/event", :event_type_name => "bar")
|
109
|
-
subject.match?(event_bar).should == true
|
110
|
-
@driver1.reload
|
111
|
-
@driver1.session.system_properties.should == {'mark_foo' => true, 'mark_bar' => true}
|
112
|
-
end
|
113
|
-
end
|
114
|
-
|
115
|
-
context "一度barを受信した場合" do
|
116
|
-
before do
|
117
|
-
session = @driver1.session
|
118
|
-
session.system_properties = {'mark_bar' => true}
|
119
|
-
session.save!
|
120
|
-
end
|
121
|
-
|
122
|
-
it "fooが来るとセッションを変更してtrue" do
|
123
|
-
event_foo = FactoryGirl.create(:"tengine/core/event", :event_type_name => "foo")
|
124
|
-
subject.match?(event_foo).should == true
|
125
|
-
@driver1.reload
|
126
|
-
@driver1.session.system_properties.should == {'mark_foo' => true, 'mark_bar' => true}
|
127
|
-
end
|
128
|
-
end
|
129
|
-
|
130
|
-
|
131
|
-
end
|
132
|
-
|
133
|
-
end
|
134
|
-
|
135
|
-
end
|
136
|
-
|
137
|
-
|
138
|
-
describe 'filter persistence' do
|
139
|
-
before do
|
140
|
-
Tengine::Core::Driver.delete_all
|
141
|
-
@driver1 = Tengine::Core::Driver.new(:name => "driver1", :version => "123")
|
142
|
-
end
|
143
|
-
|
144
|
-
it "デフォルトでは空のHash" do
|
145
|
-
@driver1.handlers.new(:event_type_names => [:foo, :bar],
|
146
|
-
:filepath => "path/to/driver.rb", :lineno => 8)
|
147
|
-
@driver1.save!
|
148
|
-
loaded = Tengine::Core::Driver.find(@driver1.id)
|
149
|
-
handler1 = loaded.handlers.first
|
150
|
-
handler1.filter.should == {}
|
151
|
-
end
|
152
|
-
|
153
|
-
it "はネストしたフィルタの情報を保持できる" do
|
154
|
-
expected_hash = {
|
155
|
-
:method => :or,
|
156
|
-
:children => [
|
157
|
-
{
|
158
|
-
:method => :and,
|
159
|
-
:children => [
|
160
|
-
{ :pattern => 'foo', :method => :find_or_mark_in_session },
|
161
|
-
{ :pattern => 'bar', :method => :find_or_mark_in_session },
|
162
|
-
]
|
163
|
-
},
|
164
|
-
{ :method => :equal, :pattern => "baz"}
|
165
|
-
]
|
166
|
-
}
|
167
|
-
@driver1.handlers.new(:event_type_names => [:foo, :bar],
|
168
|
-
:filepath => "path/to/driver.rb", :lineno => 8,
|
169
|
-
:filter => expected_hash)
|
170
|
-
@driver1.save!
|
171
|
-
loaded = Tengine::Core::Driver.find(@driver1.id)
|
172
|
-
handler1 = loaded.handlers.first
|
173
|
-
# mongoの制約でSymbolのキーは文字列に変換される。
|
174
|
-
handler1.filter.should == {
|
175
|
-
'method' => :or,
|
176
|
-
'children' => [
|
177
|
-
{
|
178
|
-
'method' => :and,
|
179
|
-
'children' => [
|
180
|
-
{ 'pattern' => 'foo', 'method' => :find_or_mark_in_session },
|
181
|
-
{ 'pattern' => 'bar', 'method' => :find_or_mark_in_session },
|
182
|
-
]
|
183
|
-
},
|
184
|
-
{ 'method' => :equal, 'pattern' => "baz"}
|
185
|
-
]
|
186
|
-
}
|
187
|
-
end
|
188
|
-
end
|
189
|
-
|
190
|
-
end
|
@@ -1,131 +0,0 @@
|
|
1
|
-
# -*- coding: utf-8 -*-
|
2
|
-
require 'spec_helper'
|
3
|
-
require 'amqp'
|
4
|
-
|
5
|
-
require_relative '../../../lib/tengine/core/heartbeat_watcher'
|
6
|
-
require 'tengine/mq/suite'
|
7
|
-
|
8
|
-
describe Tengine::Core::HeartbeatWatcher do
|
9
|
-
before do
|
10
|
-
Tengine::Core::Event.delete_all
|
11
|
-
@uuid = UUID.new
|
12
|
-
end
|
13
|
-
|
14
|
-
subject do
|
15
|
-
Tengine::Core::HeartbeatWatcher.new(%w[--heartbeat-hbw-interval=30])
|
16
|
-
end
|
17
|
-
|
18
|
-
describe "#search_for_invalid_heartbeat" do
|
19
|
-
|
20
|
-
before do
|
21
|
-
@fixtures = Array.new
|
22
|
-
@fixtures << Tengine::Core::Event.new(key: @uuid.generate, event_type_name: "job.heartbeat.tengine", occurred_at: 1.day.ago)
|
23
|
-
@fixtures << Tengine::Core::Event.new(key: @uuid.generate, event_type_name: "job.heartbeat.tengine", occurred_at: 1.second.ago)
|
24
|
-
@fixtures.each {|i| i.save! }
|
25
|
-
end
|
26
|
-
|
27
|
-
it "古いものを検索してくる" do
|
28
|
-
set = []
|
29
|
-
EM.run do
|
30
|
-
subject.search_for_invalid_heartbeat do |i|
|
31
|
-
set << i
|
32
|
-
end
|
33
|
-
EM.add_timer 0.1 do EM.stop end
|
34
|
-
end
|
35
|
-
|
36
|
-
set.should include(@fixtures[0])
|
37
|
-
set.should_not include(@fixtures[1])
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
describe "#search_for_invalid_heartbeat, kind_of" do
|
42
|
-
|
43
|
-
before do
|
44
|
-
@fixtures = Array.new
|
45
|
-
@fixtures << Tengine::Core::Event.new(key: "job1", event_type_name: "job.heartbeat.tengine", occurred_at: 1.day.ago)
|
46
|
-
@fixtures << Tengine::Core::Event.new(key: "job2", event_type_name: "job.heartbeat.tengine", occurred_at: 1.second.ago)
|
47
|
-
@fixtures << Tengine::Core::Event.new(key: "cor1", event_type_name: "core.heartbeat.tengine", occurred_at: 1.day.ago)
|
48
|
-
@fixtures << Tengine::Core::Event.new(key: "cor2", event_type_name: "core.heartbeat.tengine", occurred_at: 10.second.ago)
|
49
|
-
@fixtures << Tengine::Core::Event.new(key: "hbw1", event_type_name: "hbw.heartbeat.tengine", occurred_at: 1.day.ago)
|
50
|
-
@fixtures << Tengine::Core::Event.new(key: "hbw2", event_type_name: "hbw.heartbeat.tengine", occurred_at: 1.second.ago)
|
51
|
-
@fixtures << Tengine::Core::Event.new(key: "rsw1", event_type_name: "resourcew.heartbeat.tengine", occurred_at: 1.day.ago)
|
52
|
-
@fixtures << Tengine::Core::Event.new(key: "rsw2", event_type_name: "resourcew.heartbeat.tengine", occurred_at: 10.second.ago)
|
53
|
-
@fixtures << Tengine::Core::Event.new(key: "atd1", event_type_name: "atd.heartbeat.tengine", occurred_at: 1.day.ago)
|
54
|
-
@fixtures << Tengine::Core::Event.new(key: "atd2", event_type_name: "atd.heartbeat.tengine", occurred_at: 10.second.ago)
|
55
|
-
@fixtures << Tengine::Core::Event.new(key: "hog1", event_type_name: "hoge.heartbeat.tengine", occurred_at: 1.day.ago)
|
56
|
-
@fixtures << Tengine::Core::Event.new(key: "hog2", event_type_name: "hoge.heartbeat.tengine", occurred_at: 10.second.ago)
|
57
|
-
@fixtures.each {|i| i.save! }
|
58
|
-
end
|
59
|
-
|
60
|
-
it "古い job,core,hbw,resourcew,atd を検索してくる" do
|
61
|
-
EM.run do
|
62
|
-
subject.search_for_invalid_heartbeat do |i|
|
63
|
-
(i.key =~ /job1|cor1|hbw1|rsw1|atd1/).should be_true
|
64
|
-
(i.key =~ /job2|cor2|hbw2|rsw2|atd2|hog1|hog2/).should be_false
|
65
|
-
end
|
66
|
-
EM.add_timer 0.1 do EM.stop end
|
67
|
-
end
|
68
|
-
end
|
69
|
-
end
|
70
|
-
|
71
|
-
describe "#send_last_event" do
|
72
|
-
it "finished.process.hbw.tengineの発火" do
|
73
|
-
sender = mock(:sender)
|
74
|
-
subject.stub(:sender).and_return(sender)
|
75
|
-
sender.should_receive(:fire).with("finished.process.hbw.tengine", an_instance_of(Hash))
|
76
|
-
sender.should_receive(:stop)
|
77
|
-
subject.send_last_event
|
78
|
-
end
|
79
|
-
end
|
80
|
-
|
81
|
-
describe "#send_periodic_event" do
|
82
|
-
it "hbw.heartbeat.tengineの発火" do
|
83
|
-
sender = mock(:sender)
|
84
|
-
subject.stub(:sender).and_return(sender)
|
85
|
-
sender.should_receive(:fire).with("hbw.heartbeat.tengine", an_instance_of(Hash))
|
86
|
-
sender.stub(:fire).with("finished.process.hbw.tengine", an_instance_of(Hash)) # 来るかも
|
87
|
-
subject.send_periodic_event
|
88
|
-
end
|
89
|
-
end
|
90
|
-
|
91
|
-
describe "#send_invalidate_event" do
|
92
|
-
it "引数のイベントのtypeを書き換えて、他は同じで発火" do
|
93
|
-
e0 = Tengine::Core::Event.new(key: @uuid.generate, event_type_name: "job.heartbeat.tengine", occurred_at: 1.day.ago)
|
94
|
-
sender = mock(:sender)
|
95
|
-
subject.stub(:sender).and_return(sender)
|
96
|
-
sender.should_receive(:fire).with(an_instance_of(Tengine::Event), an_instance_of(Hash)) do |e1, h|
|
97
|
-
e1.event_type_name.should == "foobar"
|
98
|
-
e1.occurred_at.should == e0.occurred_at
|
99
|
-
e1.key.should == e0.key
|
100
|
-
end
|
101
|
-
|
102
|
-
subject.send_invalidate_event "foobar", e0
|
103
|
-
end
|
104
|
-
end
|
105
|
-
|
106
|
-
describe "#sender" do
|
107
|
-
before do
|
108
|
-
conn = mock(:connection)
|
109
|
-
conn.stub(:on_tcp_connection_loss)
|
110
|
-
conn.stub(:after_recovery)
|
111
|
-
conn.stub(:on_closed)
|
112
|
-
AMQP.stub(:connect).with(an_instance_of(Hash)).and_return(conn)
|
113
|
-
end
|
114
|
-
subject { Tengine::Core::HeartbeatWatcher.new([]).sender }
|
115
|
-
it { should be_kind_of(Tengine::Event::Sender) }
|
116
|
-
end
|
117
|
-
|
118
|
-
describe "#run" do
|
119
|
-
it "各種timerを登録する" do
|
120
|
-
EM.stub(:run).and_yield
|
121
|
-
Daemons.stub(:run_proc).with(anything, anything).and_yield
|
122
|
-
EM.should_receive(:add_periodic_timer).exactly(2).times
|
123
|
-
Tengine::Core::MethodTraceable.stub(:disabled=)
|
124
|
-
sender = mock(:sender)
|
125
|
-
sender.stub(:wait_for_connection).and_yield
|
126
|
-
subject.stub(:sender).and_return(sender)
|
127
|
-
subject.instance_eval { @config }.stub(:setup_loggers)
|
128
|
-
subject.run __FILE__
|
129
|
-
end
|
130
|
-
end
|
131
|
-
end
|
@@ -1,30 +0,0 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
# -*- coding: utf-8 -*-
|
5
|
-
require 'spec_helper'
|
6
|
-
|
7
|
-
require 'stringio'
|
8
|
-
|
9
|
-
describe Tengine::Core::IoToLogger do
|
10
|
-
|
11
|
-
context "redirect from io to logger" do
|
12
|
-
before do
|
13
|
-
@io = StringIO.new
|
14
|
-
@logger = Logger.new(@io)
|
15
|
-
@logger.level = Logger::INFO
|
16
|
-
end
|
17
|
-
subject{ Tengine::Core::IoToLogger.new(@logger) }
|
18
|
-
it "should provide puts method" do
|
19
|
-
subject.puts("foo")
|
20
|
-
@io.rewind
|
21
|
-
@io.readlines.should == ["foo\n"]
|
22
|
-
end
|
23
|
-
it "should provide write method" do
|
24
|
-
subject.write("foo")
|
25
|
-
@io.rewind
|
26
|
-
@io.readlines.should == ["foo\n"]
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
end
|