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,39 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
- require 'spec_helper'
3
-
4
- describe "uc70_driver_enabled_on_activation" do
5
- before do
6
- Tengine::Core::Driver.delete_all
7
- Tengine::Core::Session.delete_all
8
- @config = Tengine::Core::Config::Core.new({
9
- :tengined => {
10
- :load_path => File.expand_path('../../../../examples/uc70_driver_enabled_on_activation.rb', File.dirname(__FILE__)),
11
- :skip_enablement => true,
12
- },
13
- })
14
- @bootstrap = Tengine::Core::Bootstrap.new(@config)
15
- @kernel = Tengine::Core::Kernel.new(@config)
16
- end
17
-
18
- it "普通に登録されて、起動後は有効になっている" do
19
- @bootstrap.load_dsl
20
- driver = Tengine::Core::Driver.first
21
- driver.enabled.should == false
22
- driver.enabled_on_activation.should == true
23
- @bootstrap.enable_drivers
24
- driver.reload
25
- driver.enabled.should == true
26
- driver.enabled_on_activation.should == true
27
- @kernel.bind
28
- #
29
- klass = driver.target_class_name.constantize
30
- obj = klass.new
31
- klass.should_receive(:new).and_return(obj)
32
- obj.should_receive(:puts).with("handler70")
33
- mock_headers = mock(:headers)
34
- mock_headers.should_receive(:ack)
35
- raw_event = Tengine::Event.new(:event_type_name => "event70")
36
- @kernel.process_message(mock_headers, raw_event.to_json)
37
- end
38
-
39
- end
@@ -1,36 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
- require 'spec_helper'
3
-
4
- describe "uc71_driver_disabled_on_activation" do
5
- before do
6
- Tengine::Core::Driver.delete_all
7
- Tengine::Core::Session.delete_all
8
- @config = Tengine::Core::Config::Core.new({
9
- :tengined => {
10
- :load_path => File.expand_path('../../../../examples/uc71_driver_disabled_on_activation.rb', File.dirname(__FILE__)),
11
- :skip_enablement => true,
12
- },
13
- })
14
- @bootstrap = Tengine::Core::Bootstrap.new(@config)
15
- @kernel = Tengine::Core::Kernel.new(@config)
16
- end
17
-
18
- it "普通に登録されて、起動後は有効になっている" do
19
- @bootstrap.load_dsl
20
- driver = Tengine::Core::Driver.first
21
- driver.enabled.should == false
22
- driver.enabled_on_activation.should == false
23
- @bootstrap.enable_drivers
24
- driver.reload
25
- driver.enabled.should == false
26
- driver.enabled_on_activation.should == false
27
- @kernel.bind
28
- #
29
- @kernel.context.should_not_receive(:puts).with("handler71")
30
- mock_headers = mock(:headers)
31
- mock_headers.should_receive(:ack)
32
- raw_event = Tengine::Event.new(:event_type_name => "event71")
33
- @kernel.process_message(mock_headers, raw_event.to_json)
34
- end
35
-
36
- end
@@ -1,39 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
- require 'spec_helper'
3
-
4
- describe "uc72_setup_eventmachine_spec" do
5
- before do
6
- Tengine::Core::Driver.delete_all
7
- Tengine::Core::Session.delete_all
8
- @dsl_path = File.expand_path('../../../../examples/uc72_setup_eventmachine.rb', File.dirname(__FILE__))
9
- config = Tengine::Core::Config::Core.new({
10
- :tengined => {
11
- :load_path => @dsl_path,
12
- },
13
- })
14
- @kernel = Tengine::Core::Kernel.new(config)
15
- @bootstrap = Tengine::Core::Bootstrap.new(config)
16
- @bootstrap.kernel = @kernel
17
- end
18
-
19
- it "EM.run実行時にsetup_eventmachineに渡されたブロックが実行されます" do
20
- @kernel.em_setup_blocks.length.should == 0
21
- expect{
22
- @bootstrap.load_dsl
23
- }.to change(@kernel.em_setup_blocks, :length).by(1)
24
- @kernel.em_setup_blocks.length.should == 1
25
- expect{
26
- @kernel.bind
27
- }.to_not change(@kernel.em_setup_blocks, :length)
28
- @kernel.em_setup_blocks.length.should == 1
29
- EM.should_receive(:run).and_yield
30
- EM.stub(:defer) # #enable_heartbeat
31
- mq = mock(:mq, :queue => nil)
32
- @kernel.stub(:mq).at_least(1).times.and_return(mq)
33
- @kernel.should_receive(:setup_mq_connection)
34
- @kernel.should_receive(:subscribe_queue).and_yield
35
- @kernel.context.should_receive(:puts).with("setup_eventmachine")
36
- EM.should_receive(:add_periodic_timer).with(3)
37
- @kernel.activate
38
- end
39
- end
@@ -1,53 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
- require 'spec_helper'
3
-
4
- require 'stringio'
5
-
6
- describe "uc80_raise_io_error" do
7
- before(:all) do
8
- @logger = Tengine.logger
9
- end
10
- after(:all) do
11
- Tengine.logger = @logger
12
- end
13
-
14
- before do
15
- Tengine::Core::Driver.delete_all
16
- Tengine::Core::Session.delete_all
17
- @dsl_path = File.expand_path('../../../../examples/uc80_raise_io_error.rb', File.dirname(__FILE__))
18
- @config = Tengine::Core::Config::Core.new({
19
- :tengined => {
20
- :load_path => @dsl_path,
21
- },
22
- })
23
- @bootstrap = Tengine::Core::Bootstrap.new(@config)
24
- @kernel = Tengine::Core::Kernel.new(@config)
25
- end
26
-
27
- it "例外がraiseされると、その例外の内容がログに出力され、イベント処理エラーイベントをfireする" do
28
- @bootstrap.load_dsl
29
- @kernel.bind
30
- mock_headers = mock(:headers)
31
- mock_headers.should_receive(:ack)
32
- raw_event = Tengine::Event.new(:event_type_name => "event80")
33
- @buffer = StringIO.new
34
- Tengine.logger = Logger.new(@buffer)
35
- Tengine.logger.level = Logger::ERROR
36
- @kernel.should_receive(:fire).with("event80.error.tengined",
37
- :properties => {
38
- :original_event => instance_of(String),
39
- :error_class_name => "IOError",
40
- :error_message => "by driver80",
41
- :error_backtrace => instance_of(Array),
42
- # :block_source_location => "#{@dsl_path}:6" # 6はブロックの行番号
43
- })
44
- Tengine::Core::Kernel.temp_exception_reporter(:except_test) do
45
- expect{
46
- @kernel.process_message(mock_headers, raw_event.to_json)
47
- }.to_not raise_error
48
- end
49
- @buffer.rewind
50
- @buffer.string.should =~ /\[IOError\] by driver80/
51
- end
52
-
53
- end
@@ -1,49 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
- require 'spec_helper'
3
-
4
- describe "uc81_raise_runtime_error" do
5
- before do
6
- Tengine::Core::HandlerPath.delete_all
7
- Tengine::Core::Driver.delete_all
8
- Tengine::Core::Session.delete_all
9
- @dsl_path = File.expand_path('../../../../examples/uc81_raise_runtime_error.rb', File.dirname(__FILE__))
10
- @config = Tengine::Core::Config::Core.new({
11
- :tengined => {
12
- :load_path => @dsl_path,
13
- },
14
- })
15
- @bootstrap = Tengine::Core::Bootstrap.new(@config)
16
- @kernel = Tengine::Core::Kernel.new(@config)
17
- end
18
-
19
- it "例外がraiseされると、イベント処理エラーイベントをfireする" do
20
- @bootstrap.load_dsl
21
- @kernel.bind
22
-
23
- driver = Tengine::Core::Driver.first
24
- driver.enabled.should == true
25
- driver.version.should == @config.dsl_version
26
- path = Tengine::Core::HandlerPath.first
27
- path.event_type_name.should == "event81"
28
- path.driver_id.should == driver.id
29
- Tengine::Core::HandlerPath.default_driver_version.should == @config.dsl_version
30
-
31
- mock_headers = mock(:headers)
32
- mock_headers.should_receive(:ack)
33
- raw_event = Tengine::Event.new(:event_type_name => "event81")
34
- @kernel.should_receive(:fire).with("event81.error.tengined",
35
- :properties => {
36
- :original_event => instance_of(String),
37
- :error_class_name => "RuntimeError",
38
- :error_message => "by driver81",
39
- :error_backtrace => instance_of(Array),
40
- # :block_source_location => "#{@dsl_path}:6" # 6はブロックの行番号
41
- })
42
- Tengine::Core::Kernel.temp_exception_reporter(:except_test) do
43
- expect{
44
- @kernel.process_message(mock_headers, raw_event.to_json)
45
- }.to_not raise_error
46
- end
47
- end
48
-
49
- end
@@ -1,136 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
- require 'spec_helper'
3
-
4
- describe Tengine::Core::Event::Finder do
5
-
6
- context "検索" do
7
- before(:all) do
8
- Tengine::Core::Event.delete_all
9
- occured_at_base = Time.now
10
- base = {
11
- :sender_name => "agent:server1/99326/tengine_job_agent",
12
- :level => 2,
13
- }
14
- uuid_gen = Tengine::Event.uuid_gen
15
- [
16
- {:event_type_name => "start.execution.job.tengine", :source_name => "execution:localhost/123/1111/1111"}.update(base),
17
- {:event_type_name => "start.jobnet.job.tengine", :source_name => "job:localhost/123/2222/3333"}.update(base),
18
- {:event_type_name => "start.job.job.tengine", :source_name => "job:localhost/123/2222/4444"}.update(base),
19
- {:event_type_name => "finished.process.job.tengine", :source_name => "job:localhost/123/2222/4444"}.update(base),
20
- {:event_type_name => "success.job.job.tengine", :source_name => "job:localhost/123/2222/4444"}.update(base),
21
- {:event_type_name => "success.jobnet.job.tengine", :source_name => "job:localhost/123/2222/3333"}.update(base),
22
- {:event_type_name => "success.execution.job.tengine", :source_name => "execution:localhost/123/1111/1111"}.update(base),
23
- ].each_with_index do |attrs, i|
24
- Tengine::Core::Event.create!(attrs.update(:key => uuid_gen.generate, :occurred_at => occured_at_base + (i*10)))
25
- end
26
- end
27
-
28
-
29
- context "event_type_name" do
30
- it ".jobnet.job.tengine" do
31
- f = Tengine::Core::Event::Finder.new(:event_type_name => "/.jobnet.job.tengine$/")
32
- result = f.paginate
33
- result.map{|h| h[:event_type_name]}.should == [
34
- "success.jobnet.job.tengine",
35
- "start.jobnet.job.tengine",
36
- ]
37
- end
38
-
39
- it "start.job." do
40
- f = Tengine::Core::Event::Finder.new(:event_type_name => "start.job.")
41
- result = f.paginate
42
- result.map{|h| h[:event_type_name]}.should == [
43
- "start.job.job.tengine",
44
- ]
45
- end
46
-
47
- it "/start.job./" do
48
- f = Tengine::Core::Event::Finder.new(:event_type_name => "/start.job./")
49
- result = f.paginate
50
- result.map{|h| h[:event_type_name]}.should == [
51
- "start.job.job.tengine",
52
- "start.jobnet.job.tengine",
53
- ]
54
- end
55
- end
56
-
57
- context "source_name" do
58
- it "execution" do
59
- f = Tengine::Core::Event::Finder.new(:source_name => "execution:localhost/123")
60
- result = f.paginate
61
- result.map{|h| h[:event_type_name]}.should == [
62
- "success.execution.job.tengine",
63
- "start.execution.job.tengine",
64
- ]
65
- end
66
-
67
- it "job" do
68
- f = Tengine::Core::Event::Finder.new(:source_name => "job:localhost/123/2222")
69
- result = f.paginate
70
- result.map{|h| h[:event_type_name]}.should == [
71
- "success.jobnet.job.tengine",
72
- "success.job.job.tengine",
73
- "finished.process.job.tengine",
74
- "start.job.job.tengine",
75
- "start.jobnet.job.tengine",
76
- ]
77
- end
78
- end
79
-
80
- context "sender_name" do
81
- it "string" do
82
- f = Tengine::Core::Event::Finder.new(:sender_name => "server1")
83
- result = f.paginate
84
- result.map{|h| h[:event_type_name]}.should == []
85
- end
86
-
87
- it "regexp" do
88
- f = Tengine::Core::Event::Finder.new(:sender_name => "/server1/")
89
- result = f.paginate
90
- result.map{|h| h[:event_type_name]}.should == [
91
- "success.execution.job.tengine",
92
- "success.jobnet.job.tengine",
93
- "success.job.job.tengine",
94
- "finished.process.job.tengine",
95
- "start.job.job.tengine",
96
- "start.jobnet.job.tengine",
97
- "start.execution.job.tengine",
98
- ]
99
- end
100
- end
101
-
102
- context "scope" do
103
- it "ソート順は発生時刻の降順であること" do
104
- f = Tengine::Core::Event::Finder.new
105
- result = f.paginate
106
- result.map{|h| h[:event_type_name]}.should == [
107
- "success.execution.job.tengine",
108
- "success.jobnet.job.tengine",
109
- "success.job.job.tengine",
110
- "finished.process.job.tengine",
111
- "start.job.job.tengine",
112
- "start.jobnet.job.tengine",
113
- "start.execution.job.tengine",
114
- ]
115
-
116
- occurred_at_base = Time.now
117
- result.each_with_index do |event, i|
118
- event.occurred_at = occurred_at_base + i
119
- event.save!
120
- end
121
-
122
- f = Tengine::Core::Event::Finder.new
123
- result = f.paginate
124
- result.map{|h| h[:event_type_name]}.should == [
125
- "start.execution.job.tengine",
126
- "start.jobnet.job.tengine",
127
- "start.job.job.tengine",
128
- "finished.process.job.tengine",
129
- "success.job.job.tengine",
130
- "success.jobnet.job.tengine",
131
- "success.execution.job.tengine",
132
- ]
133
- end
134
- end
135
- end
136
- end
@@ -1,33 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
- require 'spec_helper'
3
-
4
- require 'tengine/event'
5
-
6
- describe Tengine::Core::EventExceptionReportable do
7
-
8
- describe :to_reporter do
9
- context "Symbolで指定" do
10
- Tengine::Core::EventExceptionReportable::EVENT_EXCEPTION_REPORTERS.keys.each do |reporter_name|
11
- it reporter_name do
12
- Tengine::Core::EventExceptionReportable.to_reporter(reporter_name).should_not == nil
13
- end
14
- end
15
- it "存在しないreporter名" do
16
- expect{
17
- Tengine::Core::EventExceptionReportable.to_reporter(:unexist_reporter)
18
- }.to raise_error(NameError, "Unknown reporter: :unexist_reporter")
19
- end
20
- end
21
-
22
- it "Procを指定" do
23
- proc1 = Proc.new{ puts "foo" }
24
- Tengine::Core::EventExceptionReportable.to_reporter(proc1).should == proc1
25
- end
26
-
27
- it "不正なreporterを指定" do
28
- expect{
29
- Tengine::Core::EventExceptionReportable.to_reporter(100)
30
- }.to raise_error(ArgumentError, "Invalid reporter: 100")
31
- end
32
- end
33
- end
@@ -1,161 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
- require 'spec_helper'
3
-
4
- describe Tengine::Core::Event do
5
-
6
- valid_attributes1 = {
7
- :event_type_name => "valid.event-type_name1",
8
- :key => "some_unique_key1",
9
- }.freeze
10
-
11
- context "event_type_nameとkeyは必須" do
12
- it "正常系" do
13
- Tengine::Core::Event.delete_all
14
- driver1 = Tengine::Core::Event.new(valid_attributes1)
15
- driver1.valid?.should == true
16
- end
17
-
18
- [:event_type_name, :key].each do |key|
19
- it "#{key}なし" do
20
- attrs = valid_attributes1.dup
21
- attrs.delete(key)
22
- driver1 = Tengine::Core::Event.new(attrs)
23
- driver1.valid?.should == false
24
- end
25
- end
26
- end
27
-
28
- context "keyはバージョン毎にユニーク" do
29
- before do
30
- Tengine::Core::Event.delete_all
31
- Tengine::Core::Event.create!(valid_attributes1)
32
- end
33
-
34
- it "同じ名前で登録されているものが存在する場合エラー、しかしunique indexによるエラーが発生します" do
35
- begin
36
- Tengine::Core::Event.create!(valid_attributes1)
37
- fail
38
- rescue Mongo::OperationFailure => e
39
- e.message.should =~ /E11000/
40
- e.message.should =~ /duplicate key error/
41
- e.message.should =~ /tengine_core_events/
42
- e.message.should =~ /some_unique_key1/
43
- end
44
- end
45
- end
46
-
47
- context "must be unique with key and sender_name" do
48
- it "raise an exception when violate unique consistent" do
49
- Mongoid.persist_in_safe_mode.should == true
50
-
51
- unique_key_name = "key1"
52
- Tengine::Core::Event.delete_all
53
- Tengine::Core::Event.create!(:event_type_name => "foo", :key => unique_key_name, :sender_name => "server1")
54
- expect {
55
- Tengine::Core::Event.create!(:event_type_name => "foo", :key => unique_key_name, :sender_name => "server2")
56
- }.to raise_error # (Mongo::OperationFailure, /duplicate key error/)
57
- end
58
- end
59
-
60
- context "event_type_name" do
61
- it { Tengine::Core::Event.new(:key => "k", :event_type_name => "foo").should be_valid }
62
- it { Tengine::Core::Event.new(:key => "k", :event_type_name => "Foo").should be_valid }
63
- it { Tengine::Core::Event.new(:key => "k", :event_type_name => "F00").should be_valid }
64
- it { Tengine::Core::Event.new(:key => "k", :event_type_name => "foo.bar.baz").should be_valid }
65
- it { Tengine::Core::Event.new(:key => "k", :event_type_name => "foo."*1024+"bar").should be_valid }
66
-
67
- it { Tengine::Core::Event.new(:key => "k", :event_type_name => "").should_not be_valid }
68
- it { Tengine::Core::Event.new(:key => "k", :event_type_name => "\0").should_not be_valid }
69
- it { Tengine::Core::Event.new(:key => "k", :event_type_name => " ").should_not be_valid }
70
- it { Tengine::Core::Event.new(:key => "k", :event_type_name => " ").should_not be_valid }
71
- it { Tengine::Core::Event.new(:key => "k", :event_type_name => "\t").should_not be_valid }
72
- it { Tengine::Core::Event.new(:key => "k", :event_type_name => "\n").should_not be_valid }
73
- it { Tengine::Core::Event.new(:key => "k", :event_type_name => ";").should_not be_valid }
74
- it { Tengine::Core::Event.new(:key => "k", :event_type_name => ",").should_not be_valid }
75
- it { Tengine::Core::Event.new(:key => "k", :event_type_name => "#").should_not be_valid }
76
- it { Tengine::Core::Event.new(:key => "k", :event_type_name => "-->").should_not be_valid }
77
- it { Tengine::Core::Event.new(:key => "k", :event_type_name => """).should_not be_valid }
78
- it { Tengine::Core::Event.new(:key => "k", :event_type_name => "javascript:alert('hello')").should_not be_valid }
79
- it { Tengine::Core::Event.new(:key => "k", :event_type_name => "javascript:alert(String.fromCharCode(88,83,83))").should_not be_valid }
80
- it { Tengine::Core::Event.new(:key => "k", :event_type_name => "<script>alert('hello')</script>").should_not be_valid }
81
- it { Tengine::Core::Event.new(:key => "k", :event_type_name => '<img src="javascript:alert(\'hello\')">').should_not be_valid }
82
- it { Tengine::Core::Event.new(:key => "k", :event_type_name => " foo").should_not be_valid }
83
- it { Tengine::Core::Event.new(:key => "k", :event_type_name => "foo ").should_not be_valid }
84
- it { Tengine::Core::Event.new(:key => "k", :event_type_name => " foo ").should_not be_valid }
85
- it { Tengine::Core::Event.new(:key => "k", :event_type_name => "'foo'").should_not be_valid }
86
- it { Tengine::Core::Event.new(:key => "k", :event_type_name => '"foo"').should_not be_valid }
87
- it { Tengine::Core::Event.new(:key => "k", :event_type_name => "foo bar baz").should_not be_valid }
88
- it { Tengine::Core::Event.new(:key => "k", :event_type_name => "(foo(bar(baz)))").should_not be_valid }
89
- it { Tengine::Core::Event.new(:key => "k", :event_type_name => "ふぅ").should_not be_valid }
90
- it { Tengine::Core::Event.new(:key => "k", :event_type_name => "נד בייקר").should_not be_valid } # hebrew
91
- it { Tengine::Core::Event.new(:key => "k", :event_type_name => ".error.tengined").should_not be_valid }
92
-
93
- # 実在のイベント種別名
94
- it { Tengine::Core::Event.new(:key => "k", :event_type_name => "start.job.job.tengine").should be_valid }
95
- it { Tengine::Core::Event.new(:key => "k", :event_type_name => "job.heartbeat.tengine").should be_valid }
96
- it { Tengine::Core::Event.new(:key => "k", :event_type_name => "alert.execution.job.tengine").should be_valid }
97
- it { Tengine::Core::Event.new(:key => "k", :event_type_name => "finished.process.job.tengine.failed.tengined").should be_valid }
98
- it { Tengine::Core::Event.new(:key => "k", :event_type_name => "Tengine::Resource::VirtualServer.created.tengine_resource_watchd").should be_valid }
99
- end
100
-
101
-
102
- describe :level do
103
-
104
- it "i18n_scopeが設定される" do
105
- Tengine::Core::Event.level_enum.i18n_scope.should == ['selectable_attrs', 'tengine/core/event', 'level']
106
- end
107
-
108
- context :i18n_scope do
109
- before(:all) do
110
- @default_locale_backup = I18n.default_locale
111
- @locale_backup = I18n.locale
112
- end
113
-
114
- after(:all) do
115
- I18n.locale = @locale_backup
116
- I18n.default_locale = @default_locale_backup
117
- end
118
-
119
- before do
120
- I18n.backend = I18n::Backend::Simple.new
121
- I18n.backend.store_translations 'en', 'selectable_attrs' => {'tengine/core/event' => {'level' => {
122
- 'debug' => 'DEBUG',
123
- 'info' => 'INFO',
124
- 'warn' => 'WARN',
125
- 'error' => 'ERROR',
126
- 'fatal' => 'FATAL',
127
- } } }
128
- I18n.backend.store_translations 'ja', 'selectable_attrs' => {'tengine/core/event' => {'level' => {
129
- 'debug' => 'デバッグ',
130
- 'info' => '情報',
131
- 'warn' => '警告',
132
- 'error' => 'エラー',
133
- 'fatal' => '致命的なエラー',
134
- } } }
135
- end
136
-
137
- context "#level_name" do
138
- {
139
- :debug => {:en => "DEBUG", :ja => "デバッグ"},
140
- :info => {:en => "INFO" , :ja => "情報"},
141
- :warn => {:en => "WARN" , :ja => "警告"},
142
- :error => {:en => "ERROR", :ja => "エラー"},
143
- :fatal => {:en => "FATAL", :ja => "致命的なエラー"},
144
- }.each do |level_key, hash|
145
- context level_key.inspect do
146
- subject{ Tengine::Core::Event.new(:level_key => level_key)}
147
- hash.each do |locale, level_name|
148
- it do
149
- I18n.locale = locale.to_s
150
- subject.level_name.should == level_name
151
- end
152
- end
153
- end
154
-
155
- end
156
- end
157
-
158
- end
159
- end
160
-
161
- end