fluent-plugin-nats 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.travis.yml +4 -0
- data/README.md +3 -0
- data/VERSION +1 -1
- data/lib/fluent/plugin/in_nats.rb +3 -2
- data/test/plugin/in_nats.rb +34 -5
- data/test/test_helper.rb +45 -2
- metadata +3 -2
data/.travis.yml
ADDED
data/README.md
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.2
|
@@ -19,6 +19,7 @@ module Fluent
|
|
19
19
|
def configure(conf)
|
20
20
|
super
|
21
21
|
@conf = conf
|
22
|
+
@uri = "nats://#{user}:#{password}@#{host}:#{port}"
|
22
23
|
unless @host && @queue
|
23
24
|
raise ConfigError, "'host' and 'queue' must be all specified."
|
24
25
|
end
|
@@ -26,7 +27,7 @@ module Fluent
|
|
26
27
|
|
27
28
|
def start
|
28
29
|
super
|
29
|
-
$log.info "listening nats on
|
30
|
+
$log.info "listening nats on #{@uri}/#{@queue}"
|
30
31
|
@thread = Thread.new(&method(:run))
|
31
32
|
end
|
32
33
|
|
@@ -37,7 +38,7 @@ module Fluent
|
|
37
38
|
end
|
38
39
|
|
39
40
|
def run
|
40
|
-
NATS.start {
|
41
|
+
NATS.start(:uri => @uri) {
|
41
42
|
NATS.subscribe(@queue) do |msg, reply, sub|
|
42
43
|
Engine.emit(sub, 0, msg)
|
43
44
|
end
|
data/test/plugin/in_nats.rb
CHANGED
@@ -2,8 +2,10 @@ require 'test/unit'
|
|
2
2
|
require 'fluent/test'
|
3
3
|
require 'lib/fluent/plugin/in_nats'
|
4
4
|
require 'nats/client'
|
5
|
+
require 'test_helper'
|
5
6
|
|
6
7
|
class NATSInputTest < Test::Unit::TestCase
|
8
|
+
include NATSTestHelper
|
7
9
|
|
8
10
|
CONFIG = %[
|
9
11
|
port 4222
|
@@ -13,10 +15,11 @@ class NATSInputTest < Test::Unit::TestCase
|
|
13
15
|
queue fluent.>
|
14
16
|
]
|
15
17
|
|
18
|
+
|
16
19
|
def create_driver(conf=CONFIG)
|
17
20
|
Fluent::Test::InputTestDriver.new(Fluent::NATSInput).configure(conf)
|
18
21
|
end
|
19
|
-
|
22
|
+
|
20
23
|
def test_configure
|
21
24
|
d = create_driver
|
22
25
|
assert_equal 4222, d.instance.port
|
@@ -26,7 +29,7 @@ class NATSInputTest < Test::Unit::TestCase
|
|
26
29
|
assert_equal 'fluent.>', d.instance.queue
|
27
30
|
end
|
28
31
|
|
29
|
-
def
|
32
|
+
def test_emit_with_credentials
|
30
33
|
d = create_driver
|
31
34
|
|
32
35
|
time = Time.parse("2011-01-02 13:14:15 UTC").to_i
|
@@ -35,21 +38,47 @@ class NATSInputTest < Test::Unit::TestCase
|
|
35
38
|
d.expect_emit "fluent.test1", 0, {"message"=>'nats'}.to_json
|
36
39
|
d.expect_emit "fluent.test2", 0, {"message"=>'nats'}.to_json
|
37
40
|
|
41
|
+
uri = "nats://#{d.instance.user}:#{d.instance.password}@#{d.instance.host}:#{d.instance.port}"
|
42
|
+
|
43
|
+
start_nats(uri)
|
38
44
|
d.run do
|
39
45
|
d.expected_emits.each { |tag, time, record|
|
40
|
-
send(tag, record)
|
46
|
+
send(uri, tag, record)
|
41
47
|
sleep 0.5
|
42
48
|
}
|
43
49
|
end
|
50
|
+
kill_nats
|
44
51
|
end
|
45
52
|
|
53
|
+
def test_emit_without_credentials
|
54
|
+
d = create_driver
|
55
|
+
|
56
|
+
time = Time.parse("2011-01-02 13:14:15 UTC").to_i
|
57
|
+
Fluent::Engine.now = time
|
58
|
+
|
59
|
+
d.expect_emit "fluent.test1", 0, {"message"=>'nats'}.to_json
|
60
|
+
d.expect_emit "fluent.test2", 0, {"message"=>'nats'}.to_json
|
61
|
+
|
62
|
+
uri = "nats://#{d.instance.host}:#{d.instance.port}"
|
63
|
+
|
64
|
+
start_nats(uri)
|
65
|
+
d.run do
|
66
|
+
d.expected_emits.each { |tag, time, record|
|
67
|
+
send(uri, tag, record)
|
68
|
+
sleep 0.5
|
69
|
+
}
|
70
|
+
end
|
71
|
+
kill_nats
|
72
|
+
end
|
73
|
+
|
74
|
+
|
46
75
|
def setup
|
47
76
|
Fluent::Test.setup
|
48
77
|
end
|
49
78
|
|
50
|
-
def send(tag, msg)
|
79
|
+
def send(uri, tag, msg)
|
51
80
|
EM.run {
|
52
|
-
n = NATS.connect
|
81
|
+
n = NATS.connect(:uri => uri)
|
53
82
|
n.publish(tag,msg)
|
54
83
|
n.close
|
55
84
|
}
|
data/test/test_helper.rb
CHANGED
@@ -22,7 +22,50 @@ unless ENV.has_key?('VERBOSE')
|
|
22
22
|
$log = nulllogger
|
23
23
|
end
|
24
24
|
|
25
|
-
require 'fluent/plugin/in_nats'
|
26
|
-
|
27
25
|
class Test::Unit::TestCase
|
28
26
|
end
|
27
|
+
|
28
|
+
require 'nats/client'
|
29
|
+
|
30
|
+
module NATSTestHelper
|
31
|
+
|
32
|
+
def server_pid
|
33
|
+
@pid ||= File.read(@pid_file).chomp.to_i
|
34
|
+
end
|
35
|
+
|
36
|
+
def setup_nats_server(uri)
|
37
|
+
@uri = URI.parse(uri)
|
38
|
+
@pid_file = '/tmp/test-nats.pid'
|
39
|
+
args = "-p #{@uri.port} -P #{@pid_file}"
|
40
|
+
args += " --user #{@uri.user}" unless (@uri.user.nil? || @uri.user.empty?)
|
41
|
+
args += " --pass #{@uri.password}" unless (@uri.password.nil? || @uri.password.empty?)
|
42
|
+
args += " #{@flags}" if @flags
|
43
|
+
args += ' -d'
|
44
|
+
end
|
45
|
+
|
46
|
+
def kill_nats
|
47
|
+
if File.exists? @pid_file
|
48
|
+
%x[kill -9 #{server_pid} 2> /dev/null]
|
49
|
+
%x[rm #{@pid_file} 2> /dev/null]
|
50
|
+
%x[rm #{NATS::AUTOSTART_LOG_FILE} 2> /dev/null]
|
51
|
+
@pid = nil
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def start_nats(uri)
|
56
|
+
|
57
|
+
args = setup_nats_server(uri)
|
58
|
+
|
59
|
+
if NATS.server_running? @uri
|
60
|
+
@was_running = true
|
61
|
+
return 0
|
62
|
+
end
|
63
|
+
|
64
|
+
%x[bundle exec nats-server #{args} 2> /dev/null]
|
65
|
+
exitstatus = $?.exitstatus
|
66
|
+
NATS.wait_for_server(@uri, 10)
|
67
|
+
exitstatus
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fluent-plugin-nats
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-08-
|
12
|
+
date: 2012-08-31 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: fluentd
|
@@ -83,6 +83,7 @@ extensions: []
|
|
83
83
|
extra_rdoc_files: []
|
84
84
|
files:
|
85
85
|
- .gitignore
|
86
|
+
- .travis.yml
|
86
87
|
- COPYING
|
87
88
|
- Gemfile
|
88
89
|
- Gemfile.lock
|