Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add shortcut method "helpers" and its tests
- Loading branch information
Showing
5 changed files
with
174 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# | ||
# Fluentd | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
|
||
require 'fluent/plugin' | ||
require 'fluent/configurable' | ||
require 'fluent/plugin_id' | ||
require 'fluent/log' | ||
require 'fluent/plugin_helper' | ||
|
||
module Fluent | ||
module Plugin | ||
class Base | ||
include Configurable | ||
include PluginId | ||
include PluginLoggerMixin | ||
include PluginHelper::Mixin | ||
|
||
def initialize; end | ||
def configure(conf); end | ||
def start; end | ||
def stop; end | ||
def shutdown; end | ||
def close; end | ||
def terminate; end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# | ||
# Fluentd | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
|
||
require 'fluent/plugin_helper/event_emitter' | ||
require 'fluent/plugin_helper/thread' | ||
require 'fluent/plugin_helper/event_loop' | ||
require 'fluent/plugin_helper/timer' | ||
require 'fluent/plugin_helper/child_process' | ||
|
||
module Fluent | ||
module PluginHelper | ||
module Mixin | ||
def self.included(mod) | ||
mod.extend(Fluent::PluginHelper) | ||
end | ||
end | ||
|
||
def helpers(*snake_case_symbols) | ||
helper_modules = snake_case_symbols.map{|name| Fluent::PluginHelper.const_get(name.to_s.split('_').map(&:capitalize).join) } | ||
include *helper_modules | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
require_relative 'helper' | ||
require 'fluent/plugin_helper' | ||
require 'fluent/plugin/base' | ||
|
||
class ConfigTest < Test::Unit::TestCase | ||
module FluentTest; end | ||
|
||
sub_test_case 'Fluent::Plugin::Base.helpers method works as shortcut to include helper modules' do | ||
class FluentTest::PluginTest1 < Fluent::Plugin::Base | ||
helpers :event_emitter | ||
end | ||
class FluentTest::PluginTest2 < Fluent::Plugin::Base | ||
helpers :thread | ||
end | ||
class FluentTest::PluginTest3 < Fluent::Plugin::Base | ||
helpers :event_loop | ||
end | ||
class FluentTest::PluginTest4 < Fluent::Plugin::Base | ||
helpers :timer | ||
end | ||
class FluentTest::PluginTest5 < Fluent::Plugin::Base | ||
helpers :child_process | ||
end | ||
class FluentTest::PluginTest0 < Fluent::Plugin::Base | ||
helpers :event_emitter, :thread, :event_loop, :timer, :child_process, :child_process | ||
end | ||
|
||
test 'plugin can include helper event_emitter' do | ||
assert FluentTest::PluginTest1.include?(Fluent::PluginHelper::EventEmitter) | ||
p1 = FluentTest::PluginTest1.new | ||
assert p1.respond_to?(:emits?) | ||
assert p1.emits? | ||
end | ||
|
||
test 'plugin can include helper thread' do | ||
assert FluentTest::PluginTest2.include?(Fluent::PluginHelper::Thread) | ||
p2 = FluentTest::PluginTest2.new | ||
assert p2.respond_to?(:thread_current_running?) | ||
assert p2.respond_to?(:thread_create) | ||
end | ||
|
||
test 'plugin can include helper event_loop' do | ||
assert FluentTest::PluginTest3.include?(Fluent::PluginHelper::EventLoop) | ||
p3 = FluentTest::PluginTest3.new | ||
assert p3.respond_to?(:event_loop_attach) | ||
assert p3.respond_to?(:event_loop_running?) | ||
end | ||
|
||
test 'plugin can include helper timer' do | ||
assert FluentTest::PluginTest4.include?(Fluent::PluginHelper::Timer) | ||
p4 = FluentTest::PluginTest4.new | ||
assert p4.respond_to?(:timer_execute) | ||
end | ||
|
||
test 'plugin can include helper child_process' do | ||
assert FluentTest::PluginTest5.include?(Fluent::PluginHelper::ChildProcess) | ||
p5 = FluentTest::PluginTest5.new | ||
assert p5.respond_to?(:child_process_execute) | ||
end | ||
|
||
test 'plugin can 2 or more helpers at once' do | ||
assert FluentTest::PluginTest0.include?(Fluent::PluginHelper::EventEmitter) | ||
assert FluentTest::PluginTest0.include?(Fluent::PluginHelper::Thread) | ||
assert FluentTest::PluginTest0.include?(Fluent::PluginHelper::EventLoop) | ||
assert FluentTest::PluginTest0.include?(Fluent::PluginHelper::Timer) | ||
assert FluentTest::PluginTest0.include?(Fluent::PluginHelper::ChildProcess) | ||
|
||
p0 = FluentTest::PluginTest0.new | ||
assert p0.respond_to?(:child_process_execute) | ||
assert p0.respond_to?(:timer_execute) | ||
assert p0.respond_to?(:event_loop_attach) | ||
assert p0.respond_to?(:event_loop_running?) | ||
assert p0.respond_to?(:thread_current_running?) | ||
assert p0.respond_to?(:thread_create) | ||
assert p0.respond_to?(:emits?) | ||
end | ||
end | ||
end |