tengine_core 0.5.28
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.rspec +1 -0
- data/Gemfile +40 -0
- data/Gemfile.lock +95 -0
- data/README.md +54 -0
- data/Rakefile +44 -0
- data/VERSION +1 -0
- data/bin/tengine_atd +8 -0
- data/bin/tengine_heartbeat_watchd +8 -0
- data/bin/tengined +182 -0
- data/examples/VERSION +1 -0
- data/examples/uc01_execute_processing_for_event.rb +11 -0
- data/examples/uc02_fire_another_event.rb +16 -0
- data/examples/uc03_2handlers_for_1event.rb +16 -0
- data/examples/uc08_if_both_a_and_b_occurs.rb +11 -0
- data/examples/uc10_if_the_event_occurs_at_the_server.rb +15 -0
- data/examples/uc50_commit_event_at_first.rb +17 -0
- data/examples/uc51_commit_event_at_first_submit.rb +29 -0
- data/examples/uc52_commit_event_after_all_handler_submit.rb +31 -0
- data/examples/uc52_never_commit_event_unless_all_handler_submit.rb +31 -0
- data/examples/uc60_event_in_handler.rb +18 -0
- data/examples/uc62_session_in_driver.rb +16 -0
- data/examples/uc64_safety_countup.rb +14 -0
- data/examples/uc70_driver_enabled_on_activation.rb +13 -0
- data/examples/uc71_driver_disabled_on_activation.rb +14 -0
- data/examples/uc72_setup_eventmachine.rb +17 -0
- data/examples/uc80_raise_io_error.rb +10 -0
- data/examples/uc81_raise_runtime_error.rb +10 -0
- data/examples2/driver01.rb +18 -0
- data/examples2/driver02.rb +19 -0
- data/examples2/uc08_if_both_a_and_b_occurs.rb +13 -0
- data/examples2/uc10_if_the_event_occurs_at_the_server.rb +18 -0
- data/examples2/uc51_commit_event_at_first_submit_1.rb +16 -0
- data/examples2/uc51_commit_event_at_first_submit_2.rb +17 -0
- data/examples2/uc51_commit_event_at_first_submit_3.rb +17 -0
- data/examples2/uc62_session_in_driver.rb +16 -0
- data/examples2/uc71_driver_disabled_on_activation.rb +16 -0
- data/failure_examples/VERSION +1 -0
- data/failure_examples/uc53_submit_outside_of_handler.rb +15 -0
- data/failure_examples/uc61_event_outside_of_handler.rb +12 -0
- data/failure_examples/uc63_session_outside_of_driver.rb +13 -0
- data/lib/tengine/core.rb +74 -0
- data/lib/tengine/core/bootstrap.rb +123 -0
- data/lib/tengine/core/collection_accessible.rb +34 -0
- data/lib/tengine/core/config.rb +10 -0
- data/lib/tengine/core/config/atd.rb +225 -0
- data/lib/tengine/core/config/core.rb +319 -0
- data/lib/tengine/core/config/heartbeat_watcher.rb +229 -0
- data/lib/tengine/core/connection_test/.gitignore +1 -0
- data/lib/tengine/core/connection_test/fire_bar_on_foo.rb +16 -0
- data/lib/tengine/core/driveable.rb +213 -0
- data/lib/tengine/core/driver.rb +69 -0
- data/lib/tengine/core/driver/finder.rb +42 -0
- data/lib/tengine/core/dsl_evaluator.rb +110 -0
- data/lib/tengine/core/dsl_filter_def.rb +11 -0
- data/lib/tengine/core/dsl_loader.rb +108 -0
- data/lib/tengine/core/event.rb +145 -0
- data/lib/tengine/core/event/finder.rb +82 -0
- data/lib/tengine/core/event_exception_reportable.rb +88 -0
- data/lib/tengine/core/event_wrapper.rb +21 -0
- data/lib/tengine/core/find_by_name.rb +31 -0
- data/lib/tengine/core/handler.rb +152 -0
- data/lib/tengine/core/handler_path.rb +33 -0
- data/lib/tengine/core/heartbeat_watcher.rb +161 -0
- data/lib/tengine/core/io_to_logger.rb +22 -0
- data/lib/tengine/core/kernel.rb +510 -0
- data/lib/tengine/core/kernel_runtime.rb +91 -0
- data/lib/tengine/core/method_traceable.rb +38 -0
- data/lib/tengine/core/mongoid_fix.rb +19 -0
- data/lib/tengine/core/mutex.rb +177 -0
- data/lib/tengine/core/optimistic_lock.rb +69 -0
- data/lib/tengine/core/plugins.rb +54 -0
- data/lib/tengine/core/schedule.rb +21 -0
- data/lib/tengine/core/scheduler.rb +156 -0
- data/lib/tengine/core/selectable_attr.rb +29 -0
- data/lib/tengine/core/session.rb +21 -0
- data/lib/tengine/core/session_wrapper.rb +68 -0
- data/lib/tengine/core/setting.rb +21 -0
- data/lib/tengine/core/validation.rb +36 -0
- data/lib/tengine/errors.rb +18 -0
- data/lib/tengine/rspec.rb +8 -0
- data/lib/tengine/rspec/context_wrapper.rb +51 -0
- data/lib/tengine/rspec/extension.rb +53 -0
- data/lib/tengine_core.rb +23 -0
- data/spec/factories/tengine_core_drivers.rb +10 -0
- data/spec/factories/tengine_core_events.rb +14 -0
- data/spec/factories/tengine_core_handler_paths.rb +9 -0
- data/spec/factories/tengine_core_handlers.rb +9 -0
- data/spec/factories/tengine_core_sessions.rb +9 -0
- data/spec/mongoid.yml +35 -0
- data/spec/spec_helper.rb +48 -0
- data/spec/support/mongo_index_key_log.rb +91 -0
- data/spec/tengine/core/bootstrap_spec.rb +278 -0
- data/spec/tengine/core/bugfix/bind_dsl_file_in_multi_byte_dir_spec.rb +21 -0
- data/spec/tengine/core/bugfix/enabled_on_activation_spec.rb +112 -0
- data/spec/tengine/core/bugfix/receive_event_spec.rb +133 -0
- data/spec/tengine/core/bugfix/use_dsl_version_method.rb +12 -0
- data/spec/tengine/core/bugfix/use_dsl_version_method_spec.rb +28 -0
- data/spec/tengine/core/bugfix/use_event_in_handler_dsl.rb +11 -0
- 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 +35 -0
- 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 +38 -0
- 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 +35 -0
- 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 +38 -0
- data/spec/tengine/core/config/atd_spec.rb +62 -0
- data/spec/tengine/core/config/core_spec.rb +479 -0
- data/spec/tengine/core/config/heartbeat_watcher_spec.rb +62 -0
- data/spec/tengine/core/config/syntax_error_in_erb.yml.erb +13 -0
- data/spec/tengine/core/config/wrong_category_name.yml.erb +13 -0
- data/spec/tengine/core/config/wrong_field_name.yml.erb +12 -0
- data/spec/tengine/core/config/wrong_yaml.yml.erb +13 -0
- data/spec/tengine/core/config_spec/another_port.yml +54 -0
- data/spec/tengine/core/config_spec/config_with_dir_absolute_load_path.yml +16 -0
- data/spec/tengine/core/config_spec/config_with_dir_relative_load_path.yml +16 -0
- data/spec/tengine/core/config_spec/config_with_file_absolute_load_path.yml +16 -0
- data/spec/tengine/core/config_spec/config_with_file_relative_load_path.yml +16 -0
- data/spec/tengine/core/config_spec/log_config_spec.rb +235 -0
- data/spec/tengine/core/driveable_spec.rb +240 -0
- data/spec/tengine/core/driver_spec.rb +159 -0
- data/spec/tengine/core/dsl_loader_spec.rb +172 -0
- data/spec/tengine/core/dsls/uc08_if_both_a_and_b_occurs_spec.rb +35 -0
- data/spec/tengine/core/dsls/uc10_if_the_event_occurs_at_the_server_spec.rb +58 -0
- data/spec/tengine/core/dsls/uc50_commit_event_at_first_spec.rb +29 -0
- data/spec/tengine/core/dsls/uc52_commit_event_after_all_handler_submit_spec.rb +33 -0
- data/spec/tengine/core/dsls/uc52_never_commit_event_unless_all_handler_submit_spec.rb +37 -0
- data/spec/tengine/core/dsls/uc53_submit_outside_of_handler_spec.rb +37 -0
- data/spec/tengine/core/dsls/uc60_event_in_handler_spec.rb +31 -0
- data/spec/tengine/core/dsls/uc61_event_outside_of_handler_spec.rb +37 -0
- data/spec/tengine/core/dsls/uc62_session_in_driver_spec.rb +36 -0
- data/spec/tengine/core/dsls/uc63_session_outside_of_driver_spec.rb +35 -0
- data/spec/tengine/core/dsls/uc64_safety_countup_spec.rb +134 -0
- data/spec/tengine/core/dsls/uc70_driver_enabled_on_activation_spec.rb +39 -0
- data/spec/tengine/core/dsls/uc71_driver_disabled_on_activation_spec.rb +36 -0
- data/spec/tengine/core/dsls/uc72_setup_eventmachine_spec.rb +39 -0
- data/spec/tengine/core/dsls/uc80_raise_io_error_spec.rb +53 -0
- data/spec/tengine/core/dsls/uc81_raise_runtime_error_spec.rb +49 -0
- data/spec/tengine/core/event/finder_spec.rb +136 -0
- data/spec/tengine/core/event_exception_reportable_spec.rb +33 -0
- data/spec/tengine/core/event_spec.rb +161 -0
- data/spec/tengine/core/event_wrapper_spec.rb +35 -0
- data/spec/tengine/core/handler_path_spec.rb +87 -0
- data/spec/tengine/core/handler_spec.rb +190 -0
- data/spec/tengine/core/heartbeat_watcher_spec.rb +131 -0
- data/spec/tengine/core/io_to_logger_spec.rb +30 -0
- data/spec/tengine/core/kernel_spec.rb +885 -0
- data/spec/tengine/core/mutex_spec.rb +184 -0
- data/spec/tengine/core/optimistic_lock_spec.rb +55 -0
- data/spec/tengine/core/scheculer_spec.rb +121 -0
- data/spec/tengine/core/selectable_attr_spec.rb +30 -0
- data/spec/tengine/core/session_spec.rb +104 -0
- data/spec/tengine/core/setting_spec.rb +79 -0
- data/spec/tengine/core_spec.rb +13 -0
- data/spec/tengine_spec.rb +14 -0
- data/tengine_core.gemspec +248 -0
- data/tmp/log/.gitignore +1 -0
- data/tmp/tengined_status/.gitignore +1 -0
- metadata +421 -0
@@ -0,0 +1,62 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
require 'tengine/event'
|
5
|
+
|
6
|
+
describe Tengine::Core::Config::HeartbeatWatcher do
|
7
|
+
|
8
|
+
describe :[] do
|
9
|
+
it "should convert a Hash to a Tengine::Core::Config::HeartbeatWatcher" do
|
10
|
+
converted = Tengine::Core::Config::HeartbeatWatcher[{:process => {:daemon => true}}]
|
11
|
+
converted.should be_a(Tengine::Core::Config::HeartbeatWatcher)
|
12
|
+
converted[:process][:daemon].should be_true
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should return same Tengine::Core::Config::HeartbeatWatcher" do
|
16
|
+
converted = Tengine::Core::Config::HeartbeatWatcher.new(:process => {:daemon => true})
|
17
|
+
Tengine::Core::Config::HeartbeatWatcher[converted].should == converted
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
context "デフォルト" do
|
22
|
+
subject do
|
23
|
+
Tengine::Core::Config::HeartbeatWatcher.new
|
24
|
+
end
|
25
|
+
its(:db){ should == {
|
26
|
+
'host' => 'localhost',
|
27
|
+
'port' => 27017,
|
28
|
+
'username' => nil,
|
29
|
+
'password' => nil,
|
30
|
+
'database' => 'tengine_production',
|
31
|
+
}}
|
32
|
+
|
33
|
+
it "db" do
|
34
|
+
subject.db.should == {
|
35
|
+
'host' => 'localhost',
|
36
|
+
'port' => 27017,
|
37
|
+
'username' => nil,
|
38
|
+
'password' => nil,
|
39
|
+
'database' => 'tengine_production',
|
40
|
+
}
|
41
|
+
end
|
42
|
+
|
43
|
+
it "process_daemon" do
|
44
|
+
subject[:process][:daemon].should be_false
|
45
|
+
end
|
46
|
+
|
47
|
+
it "heartbeat_hbw" do
|
48
|
+
subject[:heartbeat][:hbw][:interval].should == 0
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
52
|
+
|
53
|
+
context "指定した設定ファイルが存在しない場合" do
|
54
|
+
it "例外を生成します" do
|
55
|
+
config_path = File.expand_path("../config_spec/unexist_config.yml", File.dirname(__FILE__))
|
56
|
+
expect{
|
57
|
+
Tengine::Core::Config::HeartbeatWatcher.new(:config => config_path)
|
58
|
+
}.to raise_error(Tengine::Core::ConfigError, /No such file or directory - #{config_path}/)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
--
|
2
|
+
process:
|
3
|
+
daemon: true
|
4
|
+
pid_dir: "/var/run/tengined_pids"
|
5
|
+
tengined:
|
6
|
+
load_path: "/var/lib/tengine"
|
7
|
+
status_dir: "/var/run/tengined_status"
|
8
|
+
activation_dir: "/var/run/tengined_activations"
|
9
|
+
heartbeat_period: <%= 10 * 60 - %>
|
10
|
+
confirmation_threshold: "warn"
|
11
|
+
event_queue:
|
12
|
+
queue:
|
13
|
+
name: tengine_event_queue2
|
@@ -0,0 +1,13 @@
|
|
1
|
+
---
|
2
|
+
process_configs:
|
3
|
+
daemon: true
|
4
|
+
pid_dir: "/var/run/tengined_pids"
|
5
|
+
tengined:
|
6
|
+
load_path: "/var/lib/tengine"
|
7
|
+
status_dir: "/var/run/tengined_status"
|
8
|
+
activation_dir: "/var/run/tengined_activations"
|
9
|
+
heartbeat_period: 600
|
10
|
+
confirmation_threshold: "warn"
|
11
|
+
event_queue:
|
12
|
+
queue:
|
13
|
+
name: tengine_event_queue2
|
@@ -0,0 +1,12 @@
|
|
1
|
+
---
|
2
|
+
process:
|
3
|
+
daemon: true
|
4
|
+
pid_dir: "/var/run/tengined_pids"
|
5
|
+
load_path: "/var/lib/tengine"
|
6
|
+
status_dir: "/var/run/tengined_status"
|
7
|
+
activation_dir: "/var/run/tengined_activations"
|
8
|
+
heartbeat_period: 600
|
9
|
+
confirmation_threshold: "warn"
|
10
|
+
event_queue:
|
11
|
+
queue:
|
12
|
+
name: tengine_event_queue2
|
@@ -0,0 +1,13 @@
|
|
1
|
+
---
|
2
|
+
process:
|
3
|
+
daemon: true
|
4
|
+
pid_dir: "/var/run/tengined_pids"
|
5
|
+
tengined:
|
6
|
+
load_path: "/var/lib/tengine"
|
7
|
+
- status_dir: "/var/run/tengined_status"
|
8
|
+
activation_dir: "/var/run/tengined_activations"
|
9
|
+
heartbeat_period: 600
|
10
|
+
confirmation_threshold: "warn"
|
11
|
+
event_queue:
|
12
|
+
queue:
|
13
|
+
name: tengine_event_queue2
|
@@ -0,0 +1,54 @@
|
|
1
|
+
process:
|
2
|
+
daemon: false
|
3
|
+
pid_dir: "./tmp/tengined_pids" # 本番環境での例 "/var/run/tengined_pids"
|
4
|
+
|
5
|
+
tengined:
|
6
|
+
activation_timeout: 300,
|
7
|
+
load_path: "./spec_dsl/"
|
8
|
+
activation_dir: "./tmp/tengined_activations" # 本番環境での例 "/var/run/tengined_activations"
|
9
|
+
|
10
|
+
db:
|
11
|
+
host: 'localhost'
|
12
|
+
port: 21039
|
13
|
+
username:
|
14
|
+
password:
|
15
|
+
database: 'tengine_production'
|
16
|
+
|
17
|
+
event_queue:
|
18
|
+
connection:
|
19
|
+
host: 'localhost'
|
20
|
+
port: 5672
|
21
|
+
# vhost:
|
22
|
+
# user:
|
23
|
+
# pass:
|
24
|
+
exchange:
|
25
|
+
name: 'tengine_event_exchange'
|
26
|
+
type: 'direct'
|
27
|
+
durable: true
|
28
|
+
queue:
|
29
|
+
name: 'tengine_event_queue'
|
30
|
+
durable: true
|
31
|
+
|
32
|
+
log_common:
|
33
|
+
output: # file path or "STDOUT" / "STDERR"
|
34
|
+
rotation: 3 # rotation file count or daily,weekly,monthly. default: 3
|
35
|
+
rotation_size: 1024 * 1024 # number of max log file size. default: 1048576 (10MB)
|
36
|
+
level: 'debug' # debug/info/warn/error/fatal. default: info
|
37
|
+
|
38
|
+
application_log:
|
39
|
+
output: # file path or "STDOUT" / "STDERR". default: if daemon process then "./log/application.log" else "STDOUT"
|
40
|
+
rotation: # rotation file count or daily,weekly,monthly. default: value of --log-common-rotation
|
41
|
+
rotation_size: # number of max log file size. default: value of --log-common-rotation-size
|
42
|
+
level: # debug/info/warn/error/fatal. default: value of --log-common-level
|
43
|
+
|
44
|
+
process_stdout_log:
|
45
|
+
output: # file path or "STDOUT" / "STDERR". default: if daemon process then "./log/#{$PROGRAM_NAME}_#{Process.pid}_stdout.log" else "STDOUT"
|
46
|
+
rotation: # rotation file count or daily,weekly,monthly. default: value of --log-common-rotation
|
47
|
+
rotation_size: # number of max log file size. default: value of --log-common-rotation-size
|
48
|
+
level: # debug/info/warn/error/fatal. default: value of --log-common-level
|
49
|
+
|
50
|
+
process_stderr_log:
|
51
|
+
output: # file path or "STDOUT" / "STDERR". default: if daemon process then "./log/#{$PROGRAM_NAME}_#{Process.pid}_stderr.log" else "STDERR"
|
52
|
+
rotation: # rotation file count or daily,weekly,monthly. default: value of --log-common-rotation
|
53
|
+
rotation_size: # number of max log file size. default: value of --log-common-rotation-size
|
54
|
+
level: # debug/info/warn/error/fatal. default: value of --log-common-level
|
@@ -0,0 +1,16 @@
|
|
1
|
+
process:
|
2
|
+
daemon: true
|
3
|
+
pid_dir: "/var/run/tengined_pids"
|
4
|
+
|
5
|
+
tengined:
|
6
|
+
load_path: "/var/lib/tengine"
|
7
|
+
status_dir: "/var/run/tengined_status"
|
8
|
+
activation_dir: "/var/run/tengined_activations"
|
9
|
+
# heartbeat_period: 600
|
10
|
+
confirmation_threshold: "warn"
|
11
|
+
event_queue:
|
12
|
+
queue:
|
13
|
+
name: tengine_event_queue2
|
14
|
+
heartbeat:
|
15
|
+
core:
|
16
|
+
interval: 600
|
@@ -0,0 +1,16 @@
|
|
1
|
+
process:
|
2
|
+
daemon: true
|
3
|
+
pid_dir: "tmp/tengined_pids"
|
4
|
+
|
5
|
+
tengined:
|
6
|
+
load_path: "tengine_dsls"
|
7
|
+
status_dir: "tmp/tengined_status"
|
8
|
+
activation_dir: "tmp/tengined_activations"
|
9
|
+
# heartbeat_period: 600
|
10
|
+
confirmation_threshold: "warn"
|
11
|
+
event_queue:
|
12
|
+
queue:
|
13
|
+
name: tengine_event_queue2
|
14
|
+
heartbeat:
|
15
|
+
core:
|
16
|
+
interval: 600
|
@@ -0,0 +1,16 @@
|
|
1
|
+
process:
|
2
|
+
daemon: true
|
3
|
+
pid_dir: "/var/run/tengined_pids"
|
4
|
+
|
5
|
+
tengined:
|
6
|
+
load_path: "/var/lib/tengine/init.rb"
|
7
|
+
status_dir: "/var/run/tengined_status"
|
8
|
+
activation_dir: "/var/run/tengined_activations"
|
9
|
+
# heartbeat_period: 600
|
10
|
+
confirmation_threshold: "warn"
|
11
|
+
event_queue:
|
12
|
+
queue:
|
13
|
+
name: tengine_event_queue2
|
14
|
+
heartbeat:
|
15
|
+
core:
|
16
|
+
interval: 600
|
@@ -0,0 +1,16 @@
|
|
1
|
+
process:
|
2
|
+
daemon: true
|
3
|
+
pid_dir: "tmp/tengined_pids"
|
4
|
+
|
5
|
+
tengined:
|
6
|
+
load_path: "tengine_dsls/init.rb"
|
7
|
+
status_dir: "tmp/tengined_status"
|
8
|
+
activation_dir: "tmp/tengined_activations"
|
9
|
+
# heartbeat_period: 600
|
10
|
+
confirmation_threshold: "warn"
|
11
|
+
event_queue:
|
12
|
+
queue:
|
13
|
+
name: tengine_event_queue2
|
14
|
+
heartbeat:
|
15
|
+
core:
|
16
|
+
interval: 600
|
@@ -0,0 +1,235 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe Tengine::Core::Config::Core do
|
5
|
+
|
6
|
+
context "ログの設定なし" do
|
7
|
+
{
|
8
|
+
true => "デーモン起動",
|
9
|
+
false => "非デーモン起動",
|
10
|
+
}.each do |daemon_process, context_name|
|
11
|
+
context(context_name) do
|
12
|
+
before{ @config = Tengine::Core::Config::Core.new(:process => {:daemon => daemon_process})}
|
13
|
+
|
14
|
+
context "正しい設定の場合" do
|
15
|
+
|
16
|
+
context :application_log do
|
17
|
+
it do
|
18
|
+
@config[:process][:daemon].should == daemon_process
|
19
|
+
|
20
|
+
mock_logger = mock(:logger)
|
21
|
+
Logger.should_receive(:new).
|
22
|
+
with(daemon_process ? "./log/application.log" : STDOUT, 3, 1024 * 1024).
|
23
|
+
and_return(mock_logger)
|
24
|
+
mock_logger.should_receive(:level=).with(Logger::INFO)
|
25
|
+
mock_logger.should_receive(:formatter=).with(an_instance_of(Proc))
|
26
|
+
@config.application_log.new_logger
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
context :process_stdout_log do
|
31
|
+
it do
|
32
|
+
mock_logger = mock(:logger)
|
33
|
+
Logger.should_receive(:new).
|
34
|
+
with(daemon_process ? %r{^\./log/.*_stdout\.log} : STDOUT, 3, 1024 * 1024).
|
35
|
+
and_return(mock_logger)
|
36
|
+
mock_logger.should_receive(:level=).with(Logger::INFO)
|
37
|
+
mock_logger.should_receive(:formatter=).with(an_instance_of(Proc))
|
38
|
+
@config.process_stdout_log.new_logger
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
context :process_stderr_log do
|
43
|
+
it do
|
44
|
+
mock_logger = mock(:logger)
|
45
|
+
Logger.should_receive(:new).
|
46
|
+
with(daemon_process ? %r{^\./log/.*_stderr\.log} : STDERR, 3, 1024 * 1024).
|
47
|
+
and_return(mock_logger)
|
48
|
+
mock_logger.should_receive(:level=).with(Logger::INFO)
|
49
|
+
mock_logger.should_receive(:formatter=).with(an_instance_of(Proc))
|
50
|
+
@config.process_stderr_log.new_logger
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
context :invalid_log_type_name do
|
56
|
+
it "should raise ArgumentError"do
|
57
|
+
expect{
|
58
|
+
@config.invalid_log_type_name
|
59
|
+
}.to raise_error(NoMethodError)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
context "共通設定なし各ログの設定あり" do
|
69
|
+
{
|
70
|
+
true => "デーモン起動の場合",
|
71
|
+
false => "非デーモン起動の場合",
|
72
|
+
}.each do |daemon_process, context_name|
|
73
|
+
context(context_name) do
|
74
|
+
before do
|
75
|
+
@config = Tengine::Core::Config::Core.new({
|
76
|
+
:process => {:daemon => daemon_process},
|
77
|
+
:application_log => {
|
78
|
+
:output => "/var/log/tengined/application.log",
|
79
|
+
:rotation => "daily",
|
80
|
+
:level => "error",
|
81
|
+
},
|
82
|
+
:process_stdout_log => {
|
83
|
+
:output => "/var/log/tengined/process_stdout.log",
|
84
|
+
:rotation => "weekly",
|
85
|
+
:level => "info",
|
86
|
+
},
|
87
|
+
:process_stderr_log => {
|
88
|
+
:output => "/var/log/tengined/process_stderr.log",
|
89
|
+
:rotation => "monthly",
|
90
|
+
:level => "info",
|
91
|
+
},
|
92
|
+
})
|
93
|
+
end
|
94
|
+
|
95
|
+
context :application_log do
|
96
|
+
it do
|
97
|
+
mock_logger = mock(:logger)
|
98
|
+
Logger.should_receive(:new).
|
99
|
+
with("/var/log/tengined/application.log", "daily", 1048576).
|
100
|
+
and_return(mock_logger)
|
101
|
+
mock_logger.should_receive(:level=).with(Logger::ERROR)
|
102
|
+
mock_logger.should_receive(:formatter=).with(an_instance_of(Proc))
|
103
|
+
@config.application_log.new_logger
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
context :process_stdout_log do
|
108
|
+
it do
|
109
|
+
mock_logger = mock(:logger)
|
110
|
+
Logger.should_receive(:new).
|
111
|
+
with("/var/log/tengined/process_stdout.log", "weekly", 1048576).
|
112
|
+
and_return(mock_logger)
|
113
|
+
mock_logger.should_receive(:level=).with(Logger::INFO)
|
114
|
+
mock_logger.should_receive(:formatter=).with(an_instance_of(Proc))
|
115
|
+
@config.process_stdout_log.new_logger
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
context :process_stderr_log do
|
120
|
+
it do
|
121
|
+
mock_logger = mock(:logger)
|
122
|
+
Logger.should_receive(:new).
|
123
|
+
with("/var/log/tengined/process_stderr.log", "monthly", 1048576).
|
124
|
+
and_return(mock_logger)
|
125
|
+
mock_logger.should_receive(:level=).with(Logger::INFO)
|
126
|
+
mock_logger.should_receive(:formatter=).with(an_instance_of(Proc))
|
127
|
+
@config.process_stderr_log.new_logger
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
end
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
context "共通設定あり各ログの設定あり" do
|
136
|
+
{
|
137
|
+
true => "デーモン起動の場合",
|
138
|
+
false => "非デーモン起動の場合",
|
139
|
+
}.each do |daemon_process, context_name|
|
140
|
+
context(context_name) do
|
141
|
+
before do
|
142
|
+
@config = Tengine::Core::Config::Core.new({
|
143
|
+
:process => {:daemon => daemon_process},
|
144
|
+
:log_common => {
|
145
|
+
:rotation => "daily",
|
146
|
+
:level => "info",
|
147
|
+
},
|
148
|
+
:application_log => {
|
149
|
+
:output => "/var/log/tengined/application.log",
|
150
|
+
},
|
151
|
+
:process_stdout_log => {
|
152
|
+
:output => "/var/log/tengined/process_stdout.log",
|
153
|
+
},
|
154
|
+
:process_stderr_log => {
|
155
|
+
:output => "/var/log/tengined/process_stderr.log",
|
156
|
+
:rotation => "monthly",
|
157
|
+
},
|
158
|
+
})
|
159
|
+
end
|
160
|
+
|
161
|
+
context :application_log do
|
162
|
+
it do
|
163
|
+
mock_logger = mock(:logger)
|
164
|
+
Logger.should_receive(:new).
|
165
|
+
with("/var/log/tengined/application.log", "daily", 1048576).
|
166
|
+
and_return(mock_logger)
|
167
|
+
mock_logger.should_receive(:level=).with(Logger::INFO)
|
168
|
+
mock_logger.should_receive(:formatter=).with(an_instance_of(Proc))
|
169
|
+
@config.application_log.new_logger
|
170
|
+
end
|
171
|
+
end
|
172
|
+
|
173
|
+
context :process_stdout_log do
|
174
|
+
it do
|
175
|
+
mock_logger = mock(:logger)
|
176
|
+
Logger.should_receive(:new).
|
177
|
+
with("/var/log/tengined/process_stdout.log", "daily", 1048576).
|
178
|
+
and_return(mock_logger)
|
179
|
+
mock_logger.should_receive(:level=).with(Logger::INFO)
|
180
|
+
mock_logger.should_receive(:formatter=).with(an_instance_of(Proc))
|
181
|
+
@config.process_stdout_log.new_logger
|
182
|
+
end
|
183
|
+
end
|
184
|
+
|
185
|
+
context :process_stderr_log do
|
186
|
+
it do
|
187
|
+
mock_logger = mock(:logger)
|
188
|
+
Logger.should_receive(:new).
|
189
|
+
with("/var/log/tengined/process_stderr.log", "monthly", 1048576).
|
190
|
+
and_return(mock_logger)
|
191
|
+
mock_logger.should_receive(:level=).with(Logger::INFO)
|
192
|
+
mock_logger.should_receive(:formatter=).with(an_instance_of(Proc))
|
193
|
+
@config.process_stderr_log.new_logger
|
194
|
+
end
|
195
|
+
end
|
196
|
+
|
197
|
+
describe :setup_loggers do
|
198
|
+
before do
|
199
|
+
@tengine_logger_bak = Tengine.logger
|
200
|
+
@tengine_core_stdout_logger_bak = Tengine::Core.stdout_logger
|
201
|
+
@tengine_core_stderr_logger_bak = Tengine::Core.stderr_logger
|
202
|
+
@stdout_bak = $stdout
|
203
|
+
@stderr_bak = $stderr
|
204
|
+
end
|
205
|
+
after do
|
206
|
+
Tengine.logger = @tengine_logger_bak
|
207
|
+
Tengine::Core.stdout_logger = @tengine_core_stdout_logger_bak
|
208
|
+
Tengine::Core.stderr_logger = @tengine_core_stderr_logger_bak
|
209
|
+
$stdout = @stdout_bak
|
210
|
+
$stderr = @stderr_bak
|
211
|
+
end
|
212
|
+
it do
|
213
|
+
mock_logger1 = mock(:logger1)
|
214
|
+
mock_logger2 = mock(:logger2)
|
215
|
+
mock_logger3 = mock(:logger3)
|
216
|
+
mock_loggers = [mock_logger1, mock_logger2, mock_logger3]
|
217
|
+
mock_loggers.each{|m| [:level=, :formatter=].each {|n| m.should_receive(n)}}
|
218
|
+
mock_logger2.should_receive(:info).with("Tengine::Core::Config::Core#setup_loggers complete")
|
219
|
+
# mock_logger3.should_receive(:info).with("Tengine::Core::Config::Core#setup_loggers failure")
|
220
|
+
Logger.should_receive(:new).with("/var/log/tengined/application.log", "daily", 1024 * 1024).and_return(mock_logger1)
|
221
|
+
Logger.should_receive(:new).with("/var/log/tengined/process_stdout.log", "daily", 1024 * 1024).and_return(mock_logger2)
|
222
|
+
Logger.should_receive(:new).with("/var/log/tengined/process_stderr.log", "monthly", 1024 * 1024).and_return(mock_logger3)
|
223
|
+
@config.setup_loggers
|
224
|
+
Tengine.logger.should == mock_logger1
|
225
|
+
Tengine::Core.stdout_logger.should == mock_logger2
|
226
|
+
Tengine::Core.stderr_logger.should == mock_logger3
|
227
|
+
end
|
228
|
+
|
229
|
+
end
|
230
|
+
|
231
|
+
end
|
232
|
+
end
|
233
|
+
end
|
234
|
+
|
235
|
+
end
|