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,12 +0,0 @@
|
|
1
|
-
# -*- coding: utf-8 -*-
|
2
|
-
require 'spec_helper'
|
3
|
-
|
4
|
-
describe "MongoDB" do
|
5
|
-
|
6
|
-
context "server version must be >= 2.0.x" do
|
7
|
-
subject{ Mongoid.database.connection.server_version }
|
8
|
-
it{ should be_a(Mongo::ServerVersion)}
|
9
|
-
its(:to_s){ should =~ /^2\.\d+\./ }
|
10
|
-
end
|
11
|
-
|
12
|
-
end
|
@@ -1,52 +0,0 @@
|
|
1
|
-
# -*- coding: utf-8 -*-
|
2
|
-
require 'spec_helper'
|
3
|
-
require 'tengine/core/mongoid_fix'
|
4
|
-
|
5
|
-
describe Mongoid::Cursor do
|
6
|
-
|
7
|
-
class TestDocument
|
8
|
-
include Mongoid::Document
|
9
|
-
end
|
10
|
-
|
11
|
-
[
|
12
|
-
Mongo::ConnectionFailure,
|
13
|
-
Mongo::OperationTimeout,
|
14
|
-
Mongo::OperationFailure
|
15
|
-
].each do |e|
|
16
|
-
|
17
|
-
context e do
|
18
|
-
|
19
|
-
subject { TestDocument.all }
|
20
|
-
|
21
|
-
before(:all) { TestDocument.new.save }
|
22
|
-
|
23
|
-
before do
|
24
|
-
ex = e.new "not master"
|
25
|
-
@m = Mongoid.max_retries_on_connection_failure
|
26
|
-
Mongoid.max_retries_on_connection_failure = 32
|
27
|
-
n = 0
|
28
|
-
Mongo::Cursor.any_instance.stub(:next) do
|
29
|
-
n += 1
|
30
|
-
raise ex while n < 1
|
31
|
-
nil
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
after do
|
36
|
-
Mongoid.max_retries_on_connection_failure = @m
|
37
|
-
# Mongo::Cursor.any_instance.unstub(:next)
|
38
|
-
TestDocument.delete_all
|
39
|
-
end
|
40
|
-
|
41
|
-
it do
|
42
|
-
begin
|
43
|
-
subject.to_a
|
44
|
-
rescue Exception
|
45
|
-
puts $!.backtrace
|
46
|
-
end
|
47
|
-
end
|
48
|
-
# its(:to_a) { should be_empty }
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
end
|
@@ -1,201 +0,0 @@
|
|
1
|
-
# -*- coding: utf-8 -*-
|
2
|
-
require 'spec_helper'
|
3
|
-
require 'tengine/core'
|
4
|
-
|
5
|
-
describe Tengine::Core::Mutex do
|
6
|
-
before do
|
7
|
-
Tengine::Core::Mutex::Mutex.delete_all
|
8
|
-
end
|
9
|
-
|
10
|
-
context "#new" do
|
11
|
-
subject { Tengine::Core::Mutex.new "test mutex 01" }
|
12
|
-
|
13
|
-
it { should be_kind_of(Tengine::Core::Mutex) }
|
14
|
-
its(:mutex) { should be_kind_of(Tengine::Core::Mutex::Mutex) }
|
15
|
-
its(:recursive) { should be_zero }
|
16
|
-
|
17
|
-
context "negative ttl" do
|
18
|
-
it { expect { Tengine::Core::Mutex.new "test negative ttl", -1 }.to raise_exception(ArgumentError) }
|
19
|
-
end
|
20
|
-
|
21
|
-
context "infinite ttl" do
|
22
|
-
it { expect { Tengine::Core::Mutex.new "test negative ttl", (1.0 / 0.0) }.to raise_exception(TypeError) }
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
context "#synchronize" do
|
27
|
-
subject { Tengine::Core::Mutex.new "test mutex 01", Math::PI / 10 }
|
28
|
-
|
29
|
-
it "requires block" do
|
30
|
-
expect {
|
31
|
-
subject.synchronize
|
32
|
-
}.to raise_exception(ArgumentError)
|
33
|
-
end
|
34
|
-
|
35
|
-
it "synchronizes #0: no other lockers" do
|
36
|
-
block_called = false
|
37
|
-
EM.run_block do
|
38
|
-
subject.synchronize do
|
39
|
-
block_called = true
|
40
|
-
end
|
41
|
-
end
|
42
|
-
block_called.should be_true
|
43
|
-
end
|
44
|
-
|
45
|
-
it "synchronizes #1: with another locker, which is expired" do
|
46
|
-
# "stub" waiters
|
47
|
-
m = subject.mutex
|
48
|
-
m.waiters ||= []
|
49
|
-
m.waiters << { :_id => 1, :timeout => Time.at(0) }
|
50
|
-
m.save
|
51
|
-
|
52
|
-
block_called = false
|
53
|
-
t0 = Time.now
|
54
|
-
EM.run_block do
|
55
|
-
subject.synchronize do
|
56
|
-
block_called = true
|
57
|
-
end
|
58
|
-
end
|
59
|
-
t1 = Time.now
|
60
|
-
block_called.should be_true
|
61
|
-
m.reload.waiters.should be_empty
|
62
|
-
(t1 - t0).should be_within(0.5).of(0) #immediate
|
63
|
-
end
|
64
|
-
|
65
|
-
it "synchronizes #2: with another locker, which is expiring" do
|
66
|
-
# "stub" waiters
|
67
|
-
m = subject.mutex
|
68
|
-
m.waiters ||= []
|
69
|
-
m.waiters << { :_id => 1, :timeout => Time.now + m.ttl / 2 }
|
70
|
-
m.save
|
71
|
-
|
72
|
-
block_called = false
|
73
|
-
t0 = Time.now
|
74
|
-
EM.run do
|
75
|
-
subject.synchronize do
|
76
|
-
block_called = true
|
77
|
-
EM.stop
|
78
|
-
end
|
79
|
-
end
|
80
|
-
t1 = Time.now
|
81
|
-
block_called.should be_true
|
82
|
-
m.reload.waiters.should be_empty
|
83
|
-
(t1 - t0).should be_within(1.0).of(0.3 + m.ttl)
|
84
|
-
end
|
85
|
-
|
86
|
-
it "synchronizes #3: with another locker, which is not expiring" do
|
87
|
-
# "stub" waiters
|
88
|
-
m = subject.mutex
|
89
|
-
s = mock("mutex")
|
90
|
-
s.stub("_id").and_return(1)
|
91
|
-
m.waiters ||= []
|
92
|
-
m.waiters << { :_id => s._id, :timeout => Time.now + 10 }
|
93
|
-
m.save
|
94
|
-
|
95
|
-
block_called = false
|
96
|
-
t0 = Time.now
|
97
|
-
EM.run do
|
98
|
-
EM.add_timer 5 do
|
99
|
-
m.unlock s
|
100
|
-
end
|
101
|
-
subject.synchronize do
|
102
|
-
block_called = true
|
103
|
-
EM.stop
|
104
|
-
end
|
105
|
-
end
|
106
|
-
t1 = Time.now
|
107
|
-
block_called.should be_true
|
108
|
-
m.reload.waiters.should be_empty
|
109
|
-
(t1 - t0).should be_within(1.0).of(5 + m.ttl)
|
110
|
-
end
|
111
|
-
|
112
|
-
it "synchronizes #4: multi-threaded situation" do
|
113
|
-
x = y = z = nil
|
114
|
-
|
115
|
-
EM.run do
|
116
|
-
EM.defer do
|
117
|
-
m = Tengine::Core::Mutex.new "test mutex 02"
|
118
|
-
m.synchronize do
|
119
|
-
x = Time.now.to_f
|
120
|
-
end
|
121
|
-
y = Time.now.to_f
|
122
|
-
end
|
123
|
-
|
124
|
-
EM.defer do
|
125
|
-
sleep 0.5
|
126
|
-
m = Tengine::Core::Mutex.new "test mutex 02"
|
127
|
-
m.synchronize do
|
128
|
-
z = Time.now.to_f
|
129
|
-
end
|
130
|
-
end
|
131
|
-
|
132
|
-
EM.add_timer(2.5) do
|
133
|
-
EM.stop
|
134
|
-
end
|
135
|
-
end
|
136
|
-
|
137
|
-
x.should_not be_nil
|
138
|
-
y.should_not be_nil
|
139
|
-
z.should_not be_nil
|
140
|
-
x.should < z
|
141
|
-
y.should <= z
|
142
|
-
end
|
143
|
-
|
144
|
-
it "synchronizes #5: no stack overflow" do
|
145
|
-
STDERR.puts "This test takes two minutes to run. Relax and take a cup of coffee."
|
146
|
-
m = Tengine::Core::Mutex.new "test mutex 03", 0.00000000001
|
147
|
-
n = m.mutex
|
148
|
-
n.waiters ||= []
|
149
|
-
n.waiters << { :_id => 1, :timeout => Time.now + 120 }
|
150
|
-
n.save
|
151
|
-
|
152
|
-
expect do
|
153
|
-
EM.run do
|
154
|
-
m.synchronize do
|
155
|
-
EM.stop
|
156
|
-
end
|
157
|
-
end
|
158
|
-
end.to_not raise_error(SystemStackError)
|
159
|
-
end
|
160
|
-
end
|
161
|
-
|
162
|
-
context "#heartbeat" do
|
163
|
-
subject { Tengine::Core::Mutex.new "test mutex 01", Math::PI / 10 }
|
164
|
-
|
165
|
-
it "prevents automatic unlocking" do
|
166
|
-
m = subject.mutex
|
167
|
-
t1 = nil
|
168
|
-
t0 = Time.now.to_f
|
169
|
-
EM.run do
|
170
|
-
EM.defer do
|
171
|
-
subject.synchronize do
|
172
|
-
20.times do
|
173
|
-
subject.heartbeat
|
174
|
-
sleep(m.ttl / 2)
|
175
|
-
end
|
176
|
-
end
|
177
|
-
end
|
178
|
-
EM.defer do
|
179
|
-
sleep m.ttl
|
180
|
-
loop do
|
181
|
-
# hacky...
|
182
|
-
if h = m.reload.waiters.first
|
183
|
-
if h["timeout"] < Time.now
|
184
|
-
t1 = Time.now.to_f
|
185
|
-
EM.stop
|
186
|
-
break
|
187
|
-
end
|
188
|
-
else
|
189
|
-
t1 = Time.now.to_f
|
190
|
-
EM.stop
|
191
|
-
break
|
192
|
-
end
|
193
|
-
end
|
194
|
-
end
|
195
|
-
end
|
196
|
-
|
197
|
-
t1.should_not be_nil
|
198
|
-
(t1 - t0).should be_within(1.0).of(10 * subject.mutex.ttl)
|
199
|
-
end
|
200
|
-
end
|
201
|
-
end
|
@@ -1,55 +0,0 @@
|
|
1
|
-
# -*- coding: utf-8 -*-
|
2
|
-
require 'spec_helper'
|
3
|
-
|
4
|
-
describe Tengine::Core::OptimisticLock do
|
5
|
-
|
6
|
-
class Tengine::Core::OptimisticLockTestBox1
|
7
|
-
include Mongoid::Document
|
8
|
-
include Tengine::Core::OptimisticLock
|
9
|
-
|
10
|
-
set_locking_field :version
|
11
|
-
|
12
|
-
field :version, :type => Integer
|
13
|
-
field :value, :type => String
|
14
|
-
end
|
15
|
-
|
16
|
-
context "update_with_lock" do
|
17
|
-
before do
|
18
|
-
@test_box1 = Tengine::Core::OptimisticLockTestBox1.create!(:version => 2, :value => "foo")
|
19
|
-
end
|
20
|
-
|
21
|
-
it "競合がなければ素直に更新する" do
|
22
|
-
test_box = Tengine::Core::OptimisticLockTestBox1.find(@test_box1.id)
|
23
|
-
test_box.update_with_lock do
|
24
|
-
test_box.value += "o"
|
25
|
-
end
|
26
|
-
test_box.reload
|
27
|
-
test_box.value.should == "fooo"
|
28
|
-
test_box.version.should == 3
|
29
|
-
end
|
30
|
-
|
31
|
-
it "競合しても単純に上書きしたりせず、最新を取得し直して更新する" do
|
32
|
-
test_box1 = Tengine::Core::OptimisticLockTestBox1.find(@test_box1.id)
|
33
|
-
test_box2 = Tengine::Core::OptimisticLockTestBox1.find(@test_box1.id)
|
34
|
-
# test_box1を更新
|
35
|
-
test_box1_count = 0
|
36
|
-
test_box1.update_with_lock do
|
37
|
-
test_box1_count += 1
|
38
|
-
test_box1.value += "o"
|
39
|
-
end
|
40
|
-
test_box1_count.should == 1
|
41
|
-
test_box1.value.should == "fooo"
|
42
|
-
test_box1.version.should == 3
|
43
|
-
# test_box2を更新
|
44
|
-
test_box2_count = 0
|
45
|
-
test_box2.update_with_lock do
|
46
|
-
test_box2_count += 1
|
47
|
-
test_box2.value += "w"
|
48
|
-
end
|
49
|
-
test_box2_count.should == 2
|
50
|
-
test_box2.value.should == "fooow"
|
51
|
-
test_box2.version.should == 4
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
end
|
@@ -1,121 +0,0 @@
|
|
1
|
-
# -*- coding: utf-8 -*-
|
2
|
-
require 'spec_helper'
|
3
|
-
require 'amqp'
|
4
|
-
|
5
|
-
require_relative '../../../lib/tengine/core/scheduler'
|
6
|
-
require 'tengine/mq/suite'
|
7
|
-
|
8
|
-
describe Tengine::Core::Scheduler do
|
9
|
-
before do
|
10
|
-
Tengine::Core::Schedule.delete_all
|
11
|
-
@uuid = UUID.new
|
12
|
-
end
|
13
|
-
|
14
|
-
subject do
|
15
|
-
Tengine::Core::Scheduler.new(%w[--heartbeat-atd-interval=30])
|
16
|
-
end
|
17
|
-
|
18
|
-
describe "#search_for_schedule" do
|
19
|
-
|
20
|
-
before do
|
21
|
-
@fixtures = Array.new
|
22
|
-
@fixtures << Tengine::Core::Schedule.new(event_type_name: "stop.execution.job.tengine", scheduled_at: 1.day.ago)
|
23
|
-
@fixtures << Tengine::Core::Schedule.new(event_type_name: "stop.execution.job.tengine", scheduled_at: Time.now + 10)
|
24
|
-
@fixtures << Tengine::Core::Schedule.new(event_type_name: "stop.execution.job.tengine", scheduled_at: 1.day.ago, status: Tengine::Core::Schedule::FIRED)
|
25
|
-
@fixtures.each {|i| i.save! }
|
26
|
-
end
|
27
|
-
|
28
|
-
it "古いものを検索してくる" do
|
29
|
-
EM.stub(:next_tick).and_yield
|
30
|
-
set = []
|
31
|
-
subject.search_for_schedule do |i|
|
32
|
-
set << i
|
33
|
-
end
|
34
|
-
|
35
|
-
set.should include(@fixtures[0])
|
36
|
-
set.should_not include(@fixtures[1])
|
37
|
-
set.should_not include(@fixtures[2])
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
describe "#send_last_event" do
|
42
|
-
it "finished.process.atd.tengineの発火" do
|
43
|
-
sender = mock(:sender)
|
44
|
-
subject.stub(:sender).and_return(sender)
|
45
|
-
sender.should_receive(:fire).with("finished.process.atd.tengine", an_instance_of(Hash))
|
46
|
-
sender.should_receive(:stop)
|
47
|
-
subject.send_last_event
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
describe "#send_periodic_event" do
|
52
|
-
it "atd.heartbeat.tengineの発火" do
|
53
|
-
sender = mock(:sender)
|
54
|
-
subject.stub(:sender).and_return(sender)
|
55
|
-
sender.should_receive(:fire).with("atd.heartbeat.tengine", an_instance_of(Hash))
|
56
|
-
sender.stub(:fire).with("finished.process.atd.tengine", an_instance_of(Hash)) # 来るかも
|
57
|
-
subject.send_periodic_event
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
describe "#send_scheduled_event" do
|
62
|
-
it "スケジュールされたイベントの発火" do
|
63
|
-
s0 = Tengine::Core::Schedule.new(event_type_name: "test.event.not.tengine", source_name: "test://localhost/dev/null", properties: {foo: 'bar'})
|
64
|
-
sender = mock(:sender)
|
65
|
-
subject.stub(:sender).and_return(sender)
|
66
|
-
sender.should_receive(:fire).with(s0.event_type_name, an_instance_of(Hash)) do |e1, h|
|
67
|
-
h[:source_name].should == s0.source_name
|
68
|
-
h[:properties].should == {:foo => 'bar'}
|
69
|
-
h[:key].should == s0._id
|
70
|
-
end
|
71
|
-
|
72
|
-
subject.send_scheduled_event s0
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|
76
|
-
describe "#mark_schedule_done" do
|
77
|
-
it "実行したスケジュールは終了とする" do
|
78
|
-
s0 = Tengine::Core::Schedule.new(event_type_name: "test.event.not.tengine", source_name: "test://localhost/dev/null")
|
79
|
-
s0.save
|
80
|
-
subject.mark_schedule_done s0
|
81
|
-
s0.reload
|
82
|
-
s0.status.should == Tengine::Core::Schedule::FIRED
|
83
|
-
end
|
84
|
-
|
85
|
-
it "すでに終了していたら何もしない" do
|
86
|
-
s0 = Tengine::Core::Schedule.new(event_type_name: "test.event.not.tengine", source_name: "test://localhost/dev/null", status: Tengine::Core::Schedule::FIRED)
|
87
|
-
s0.save
|
88
|
-
s0.reload
|
89
|
-
t = s0.updated_at
|
90
|
-
subject.mark_schedule_done s0
|
91
|
-
s0.reload
|
92
|
-
s0.updated_at.should == t
|
93
|
-
end
|
94
|
-
end
|
95
|
-
|
96
|
-
describe "#sender" do
|
97
|
-
before do
|
98
|
-
conn = mock(:connection)
|
99
|
-
conn.stub(:on_tcp_connection_loss)
|
100
|
-
conn.stub(:after_recovery)
|
101
|
-
conn.stub(:on_closed)
|
102
|
-
AMQP.stub(:connect).with(an_instance_of(Hash)).and_return(conn)
|
103
|
-
end
|
104
|
-
subject { Tengine::Core::Scheduler.new([]).sender }
|
105
|
-
it { should be_kind_of(Tengine::Event::Sender) }
|
106
|
-
end
|
107
|
-
|
108
|
-
describe "#run" do
|
109
|
-
it "各種timerを登録する" do
|
110
|
-
EM.stub(:run).and_yield
|
111
|
-
Daemons.stub(:run_proc).with(anything, anything).and_yield
|
112
|
-
EM.should_receive(:add_periodic_timer).exactly(2).times
|
113
|
-
Tengine::Core::MethodTraceable.stub(:disabled=)
|
114
|
-
sender = mock(:sender)
|
115
|
-
sender.stub(:wait_for_connection).and_yield
|
116
|
-
subject.stub(:sender).and_return(sender)
|
117
|
-
subject.instance_eval { @config }.stub(:setup_loggers)
|
118
|
-
subject.run __FILE__
|
119
|
-
end
|
120
|
-
end
|
121
|
-
end
|
@@ -1,30 +0,0 @@
|
|
1
|
-
# -*- coding: utf-8 -*-
|
2
|
-
require 'spec_helper'
|
3
|
-
|
4
|
-
require 'stringio'
|
5
|
-
|
6
|
-
describe Tengine::Core::SelectableAttr do
|
7
|
-
|
8
|
-
module TestModule1
|
9
|
-
class TestClass1
|
10
|
-
include Tengine::Core::SelectableAttr
|
11
|
-
selectable_attr :foo do
|
12
|
-
entry 1, :a, "do"
|
13
|
-
entry 2, :b, "re"
|
14
|
-
entry 3, :c, "mi"
|
15
|
-
end
|
16
|
-
multi_selectable_attr :bar do
|
17
|
-
entry 1, :x, "red"
|
18
|
-
entry 2, :y, "green"
|
19
|
-
entry 3, :z, "blue"
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
it "i18n_scopeが設定されている" do
|
25
|
-
TestModule1::TestClass1.foo_enum.i18n_scope.should == ['selectable_attrs', 'test_module1/test_class1', 'foo']
|
26
|
-
TestModule1::TestClass1.bar_enum.i18n_scope.should == ['selectable_attrs', 'test_module1/test_class1', 'bar']
|
27
|
-
end
|
28
|
-
|
29
|
-
|
30
|
-
end
|