gri 10.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +7 -0
- data/MIT-LICENSE.txt +20 -0
- data/README.md +132 -0
- data/Rakefile +5 -0
- data/bin/grapher +17 -0
- data/bin/gri +5 -0
- data/bin/gricast +17 -0
- data/bin/grispark +5 -0
- data/bin/griwalk +9 -0
- data/bin/trad +19 -0
- data/bin/trad-http +17 -0
- data/gri.gemspec +21 -0
- data/lib/fluent/plugin/out_gri.rb +56 -0
- data/lib/gri/api.rb +28 -0
- data/lib/gri/app_collector.rb +154 -0
- data/lib/gri/app_walker.rb +23 -0
- data/lib/gri/blank.rb +49 -0
- data/lib/gri/builtindefs.rb +211 -0
- data/lib/gri/cast.rb +84 -0
- data/lib/gri/cgraph.rb +37 -0
- data/lib/gri/clist.rb +163 -0
- data/lib/gri/collector.rb +284 -0
- data/lib/gri/config.rb +134 -0
- data/lib/gri/ds_list.rb +166 -0
- data/lib/gri/format_helper.rb +112 -0
- data/lib/gri/gparams.rb +43 -0
- data/lib/gri/graph.rb +239 -0
- data/lib/gri/grapher.rb +70 -0
- data/lib/gri/ldb.rb +160 -0
- data/lib/gri/list.rb +242 -0
- data/lib/gri/log.rb +140 -0
- data/lib/gri/loop.rb +109 -0
- data/lib/gri/ltsv.rb +58 -0
- data/lib/gri/main.rb +107 -0
- data/lib/gri/mlog.rb +22 -0
- data/lib/gri/mmsgpack.rb +57 -0
- data/lib/gri/msnmp.rb +601 -0
- data/lib/gri/page.rb +235 -0
- data/lib/gri/pcollector.rb +209 -0
- data/lib/gri/plugin.rb +75 -0
- data/lib/gri/plugin/bootstrap.rb +65 -0
- data/lib/gri/plugin/cisco.rb +98 -0
- data/lib/gri/plugin/exec_collector.rb +89 -0
- data/lib/gri/plugin/juniper.rb +5 -0
- data/lib/gri/plugin/netsnmp.rb +8 -0
- data/lib/gri/plugin/ucdavis.rb +176 -0
- data/lib/gri/plugin/writer_fluentd.rb +26 -0
- data/lib/gri/polling_unit.rb +88 -0
- data/lib/gri/q.rb +5 -0
- data/lib/gri/request.rb +29 -0
- data/lib/gri/rrd.rb +438 -0
- data/lib/gri/scheduler.rb +68 -0
- data/lib/gri/sgraph.rb +147 -0
- data/lib/gri/spark.rb +94 -0
- data/lib/gri/tra_collector.rb +80 -0
- data/lib/gri/trad.rb +170 -0
- data/lib/gri/updater.rb +201 -0
- data/lib/gri/util_daemon.rb +19 -0
- data/lib/gri/util_marshal.rb +13 -0
- data/lib/gri/utils.rb +63 -0
- data/lib/gri/vendor.rb +76 -0
- data/lib/gri/version.rb +3 -0
- data/lib/gri/wmain.rb +67 -0
- data/lib/gri/writer.rb +184 -0
- data/mcollector +47 -0
- data/test/mock.rb +60 -0
- data/test/root/gra/.sysdb/sysdb.txt +3 -0
- data/test/root/gra/testhost/.records.txt +2 -0
- data/test/root/if.def +2 -0
- data/test/root/test.conf +4 -0
- data/test/root/testtab +9 -0
- data/test/root/testtab2 +2 -0
- data/test/root/tra/testhost/_/20130614 +20 -0
- data/test/test_app.rb +58 -0
- data/test/test_builtindefs.rb +24 -0
- data/test/test_collector.rb +58 -0
- data/test/test_config.rb +62 -0
- data/test/test_ds_list.rb +48 -0
- data/test/test_exec_collector.rb +33 -0
- data/test/test_format_helper.rb +68 -0
- data/test/test_graph.rb +69 -0
- data/test/test_ldb.rb +29 -0
- data/test/test_list.rb +65 -0
- data/test/test_log.rb +16 -0
- data/test/test_loop.rb +35 -0
- data/test/test_ltsv.rb +38 -0
- data/test/test_main.rb +19 -0
- data/test/test_mmsgpack.rb +27 -0
- data/test/test_msnmp.rb +147 -0
- data/test/test_page.rb +51 -0
- data/test/test_pcollector.rb +71 -0
- data/test/test_plugin.rb +62 -0
- data/test/test_plugin_cisco.rb +23 -0
- data/test/test_polling_unit.rb +58 -0
- data/test/test_request.rb +26 -0
- data/test/test_rrd.rb +53 -0
- data/test/test_rrd_updater.rb +139 -0
- data/test/test_scheduler.rb +31 -0
- data/test/test_tra_collector.rb +40 -0
- data/test/test_trad.rb +33 -0
- data/test/test_util_marshal.rb +17 -0
- data/test/test_utils.rb +15 -0
- data/test/test_vendor.rb +40 -0
- data/test/test_writer.rb +33 -0
- data/test/unittest_helper.rb +27 -0
- metadata +208 -0
data/test/test_config.rb
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/unittest_helper')
|
2
|
+
|
3
|
+
require 'gri/config'
|
4
|
+
|
5
|
+
module GRI
|
6
|
+
|
7
|
+
class TestConfig < Test::Unit::TestCase
|
8
|
+
def test_config
|
9
|
+
conf = GRI::Config.new
|
10
|
+
conf['key'] = 1
|
11
|
+
ae 1, conf['key']
|
12
|
+
conf['key'] = 'a'
|
13
|
+
ae 'a', conf['key']
|
14
|
+
ae [1, 'a'], conf.getvar('key')
|
15
|
+
|
16
|
+
conf[:s] = 'aaa'
|
17
|
+
ae({"key"=>[1, "a"], :s=>"aaa"}, conf.to_h)
|
18
|
+
|
19
|
+
assert_nil conf['notexist']
|
20
|
+
|
21
|
+
conf['key2'] = false
|
22
|
+
assert !conf['key2']
|
23
|
+
assert conf.has_key?('key2')
|
24
|
+
assert !conf.has_key?('key3')
|
25
|
+
|
26
|
+
Config.init
|
27
|
+
assert_nil Config['key']
|
28
|
+
Config['key'] = 1
|
29
|
+
ae 1, Config['key']
|
30
|
+
Config['key'] = 'a'
|
31
|
+
ae 'a', Config['key']
|
32
|
+
ae [1, 'a'], Config.getvar('key')
|
33
|
+
assert conf.has_key?('key')
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_load_from_file
|
37
|
+
path = File.expand_path(File.dirname(__FILE__) + '/root/test.conf')
|
38
|
+
conf = GRI::Config.load_from_file path
|
39
|
+
ae 1, conf['test-opt-num'].to_i
|
40
|
+
ae 'foo', conf['test-opt-str']
|
41
|
+
ae ["/dir1", "/dir2"], conf.getvar('plugin-dir')
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_get_targets_from_lines
|
45
|
+
lines = ['localhost ver=2c community=public', 'testhost community=xxxxxx']
|
46
|
+
targets = GRI::Config.get_targets_from_lines lines
|
47
|
+
host, options = targets.first
|
48
|
+
ae 'localhost', host
|
49
|
+
ae '2c', options['ver']
|
50
|
+
ae 'public', options['community']
|
51
|
+
assert !options['interfaces']
|
52
|
+
|
53
|
+
lines = ['exhost type=exec cmd="vmstat 1 3|tail -1" ' +
|
54
|
+
'out_keys=procs_r,procs_b,memory_swpd,memory_free,memory_buff']
|
55
|
+
targets = GRI::Config.get_targets_from_lines lines
|
56
|
+
host, options = targets.first
|
57
|
+
ae 'exec', options['type']
|
58
|
+
ae 'vmstat 1 3|tail -1', options['cmd']
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/unittest_helper')
|
2
|
+
|
3
|
+
require 'rack'
|
4
|
+
require 'gri/log'
|
5
|
+
require 'gri/config'
|
6
|
+
require 'gri/ds_list'
|
7
|
+
|
8
|
+
module GRI
|
9
|
+
|
10
|
+
class TestDSList < Test::Unit::TestCase
|
11
|
+
def setup
|
12
|
+
@root_dir = File.expand_path(File.dirname(__FILE__) + '/root')
|
13
|
+
gra_dir = @root_dir + '/gra'
|
14
|
+
Config.init
|
15
|
+
Config['gra-dir'] = gra_dir
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_ds_list_get_data_hash
|
19
|
+
dlist = DSList.new
|
20
|
+
records = Utils.load_records Config['gra-dir'] + '/testhost'
|
21
|
+
ae 'eth0', records['_eth0']['ifDescr']
|
22
|
+
|
23
|
+
data_hash = dlist.get_data_hash records
|
24
|
+
key, prop, = data_hash[''].first
|
25
|
+
ae '_eth0', key
|
26
|
+
ae 'eth0', prop[:name]
|
27
|
+
|
28
|
+
s = dlist.format_cell '%D', prop
|
29
|
+
ae '<td>testdescr</td>', s
|
30
|
+
|
31
|
+
ae ['<td>eth0</td>', '<td>testdescr</td>'],
|
32
|
+
dlist.format_tr(['%N', '%D'], prop)
|
33
|
+
|
34
|
+
prop[:ipaddr] = '192.168.0.0/255.255.255.0'
|
35
|
+
ae ['<td>192.168.0.0/24</td>'], dlist.format_tr(['%I'], prop)
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_ds_list_mk_comp_links
|
39
|
+
dlist = DSList.new
|
40
|
+
comps = ['s', 'v']
|
41
|
+
ckeys = ['_eth0', '_eth1']
|
42
|
+
res = dlist.mk_comp_links comps, 'testhost', ckeys
|
43
|
+
ae 2, res.size
|
44
|
+
ae "<a href=\"?p=s&r=testhost__eth0&r=testhost__eth1\">stack</a>", res.first
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/unittest_helper')
|
2
|
+
|
3
|
+
require 'mock'
|
4
|
+
require 'gri/plugin/exec_collector'
|
5
|
+
|
6
|
+
module GRI
|
7
|
+
|
8
|
+
class MockExecCollector < ExecCollector
|
9
|
+
def popen cmd
|
10
|
+
return MockIO.new, MockIO.new, MockIO.new
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
class TestExecCollector < Test::Unit::TestCase
|
15
|
+
def test_exec_collector
|
16
|
+
Collector::TYPES['exec'] = MockExecCollector
|
17
|
+
host = 'exhost'
|
18
|
+
options = {'type'=>'exec', 'cmd'=>'vmstat 1 1|tail -1',
|
19
|
+
'out_keys'=>'procs_r,procs_b,memory_swpd,memory_free,memory_buff'}
|
20
|
+
records = []
|
21
|
+
collector = Collector.create(options['type'], host, options) {|rs|
|
22
|
+
records += rs
|
23
|
+
}
|
24
|
+
assert_kind_of ExecCollector, collector
|
25
|
+
|
26
|
+
collector.on_read "0 0"
|
27
|
+
assert records.empty?
|
28
|
+
collector.on_read " 2000 3000\n0 0 4000 5000"
|
29
|
+
ae 1, records.size
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/unittest_helper')
|
2
|
+
|
3
|
+
require 'gri/format_helper'
|
4
|
+
|
5
|
+
module GRI
|
6
|
+
|
7
|
+
class TestFormatHelper < Test::Unit::TestCase
|
8
|
+
include FormatHelper
|
9
|
+
|
10
|
+
def test_format_helper_h
|
11
|
+
ae "</br>", h('</br>')
|
12
|
+
ae "[nil]", h([nil])
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_format_helper_escape_once
|
16
|
+
ae '&', escape_once('&')
|
17
|
+
ae '&', escape_once('&')
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_format_helper_u
|
21
|
+
ae "_%3A%3C%3E%5C%25", u('_:<>\%')
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_format_helper_url_to
|
25
|
+
ae '/aaa', url_to('aaa')
|
26
|
+
ae '?a=1', url_to('?a=1')
|
27
|
+
assert_match %r{\A/aaa\?[ab]=[^&]+&}, url_to('aaa', :a=>1, 'b'=>'"')
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_format_helper_mk_query
|
31
|
+
ae '?a=1', mk_query(:a=>1)
|
32
|
+
assert_match /\bb=a\+%26\b/, mk_query(:a=>1, :b=>'a &')
|
33
|
+
assert_not_match /\bc=/, mk_query(:c=>nil)
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_format_helper_td
|
37
|
+
ae '<td>item</td>', td('item')
|
38
|
+
ae '<th>item</th>', td('item', :head=>true)
|
39
|
+
ae '<td colspan=2>item</td>', td('item', :colspan=>2)
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_format_helper_mk_tag
|
43
|
+
ae '<a href="/">top</a>', mk_tag('a', {:href=>'/'}, 'top')
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_format_helper_text_field
|
47
|
+
ae '<input type="text" name="text" value="aaa" size="40"/>',
|
48
|
+
text_field('text', 'aaa', 40, nil, nil)
|
49
|
+
end
|
50
|
+
|
51
|
+
def test_format_helper_popup_menu
|
52
|
+
a = [[1, 'a'], [2, 'b'], [3, 'c', true]]
|
53
|
+
ae '<select name="popup"><option value="1">a</option><option value="2">b</option><option value="3" selected>c</option></select>',
|
54
|
+
popup_menu('popup', nil, *a)
|
55
|
+
end
|
56
|
+
|
57
|
+
def test_format_helper_to_scalestr
|
58
|
+
assert_nil to_scalestr(nil)
|
59
|
+
ae '0.0', to_scalestr(0)
|
60
|
+
ae '1.024K', to_scalestr(1024)
|
61
|
+
ae '1K', to_scalestr(1024, 1024)
|
62
|
+
ae '1.234M', to_scalestr(1234000)
|
63
|
+
ae '1.234G', to_scalestr(1234000000)
|
64
|
+
ae '1.234T', to_scalestr(1234000000000)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
end
|
data/test/test_graph.rb
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/unittest_helper')
|
2
|
+
|
3
|
+
require 'gri/graph'
|
4
|
+
|
5
|
+
module GRI
|
6
|
+
|
7
|
+
class TestGraph < Test::Unit::TestCase
|
8
|
+
def setup
|
9
|
+
@root_dir = File.dirname(__FILE__) + '/root'
|
10
|
+
@graph = Graph.new :dir=>'/var/tmp'
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_graph_get_rrdpaths_and_ub
|
14
|
+
gra_dirs = [@root_dir + '/gra']
|
15
|
+
rs = ['testhost__eth0']
|
16
|
+
graph = Graph.new :dirs=>gra_dirs
|
17
|
+
res = graph.get_rrdpaths_and_ub rs
|
18
|
+
ae 1000000000, res[1]
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_graph_mk_graph_title
|
22
|
+
gra_dirs = [@root_dir + '/gra']
|
23
|
+
rs = ['testhost__eth0']
|
24
|
+
graph = Graph.new :dirs=>gra_dirs
|
25
|
+
params = {}
|
26
|
+
res = graph.mk_graph_title rs, params
|
27
|
+
assert_nil res
|
28
|
+
|
29
|
+
params = {'p'=>'t'}
|
30
|
+
res = graph.mk_graph_title rs, params
|
31
|
+
ae '"testhost eth0 testdescr"', res
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_graph_mk_graph_args
|
35
|
+
rrdpaths = ['/usr/local/gri/gra/host00__eth0.rrd',
|
36
|
+
'/usr/local/gri/gra/host01__eth0.rrd',]
|
37
|
+
params = {'p'=>''}
|
38
|
+
specs = DEFS.get_specs ''
|
39
|
+
res = @graph.mk_graph_args specs, rrdpaths, params
|
40
|
+
assert_match /\A-v\s+"bps"/, res[0]
|
41
|
+
assert_match /\A--base\s+1000/, res[1]
|
42
|
+
assert_match /\A--lower-limit\s+0/, res[2]
|
43
|
+
exprs = res[3].split
|
44
|
+
assert_match /\ADEF:v1inoctet=/, exprs[0]
|
45
|
+
assert_match /\ADEF:v2inoctet=/, exprs[1]
|
46
|
+
assert_match /\ACDEF:inoctet0=/, exprs[2]
|
47
|
+
assert_match /\AAREA:inoctet0#/, exprs[3]
|
48
|
+
assert_match /\AGPRINT:inoctet0:/, exprs[4]
|
49
|
+
exprs = res[4].split
|
50
|
+
assert_match /\ADEF:v1outoctet=/, exprs[0]
|
51
|
+
assert_match /\ADEF:v2outoctet=/, exprs[1]
|
52
|
+
assert_match /\ACDEF:outoctet0=/, exprs[2]
|
53
|
+
assert_match /\ALINE1:outoctet0#/, exprs[3]
|
54
|
+
assert_match /\AGPRINT:outoctet0:/, exprs[4]
|
55
|
+
end
|
56
|
+
|
57
|
+
def test_graph_mk_defstr
|
58
|
+
rrdpaths = ['/usr/local/gri/gra/host00__eth0.rrd',
|
59
|
+
'/usr/local/gri/gra/host01__eth0.rrd',]
|
60
|
+
params = {'fmt'=>'json'}
|
61
|
+
specs = DEFS.get_specs ''
|
62
|
+
ds_specs = specs[:ds].grep /Octets/
|
63
|
+
res = @graph.mk_defstr ds_specs, rrdpaths, params, nil
|
64
|
+
assert_match /XPORT:inoctet0:"in"/, res[0]
|
65
|
+
assert_match /XPORT:outoctet0:"out"/, res[1]
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
end
|
data/test/test_ldb.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/unittest_helper')
|
2
|
+
|
3
|
+
require 'gri/ldb'
|
4
|
+
|
5
|
+
module GRI
|
6
|
+
|
7
|
+
class TestLDB < Test::Unit::TestCase
|
8
|
+
def setup
|
9
|
+
root_dir = File.expand_path(File.dirname(__FILE__) + '/root')
|
10
|
+
dir = root_dir + "/tra/testhost"
|
11
|
+
@ldb = LocalLDB.new dir
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_local_ldb
|
15
|
+
time = Time.local(2013, 6, 14, 12, 0)
|
16
|
+
a = []
|
17
|
+
@ldb.get_after('', time) {|t, h|
|
18
|
+
a.push h
|
19
|
+
}
|
20
|
+
ae 7, a.size
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_get_data_names
|
24
|
+
data_names = @ldb.get_data_names
|
25
|
+
ae [''], data_names.keys
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
data/test/test_list.rb
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/unittest_helper')
|
2
|
+
|
3
|
+
require 'rack'
|
4
|
+
require 'gri/log'
|
5
|
+
require 'gri/config'
|
6
|
+
require 'gri/builtindefs'
|
7
|
+
require 'gri/grapher'
|
8
|
+
require 'gri/list'
|
9
|
+
require 'gri/msnmp'
|
10
|
+
require 'gri/vendor'
|
11
|
+
require 'gri/plugin/ucdavis'
|
12
|
+
|
13
|
+
module GRI
|
14
|
+
|
15
|
+
class TestList < Test::Unit::TestCase
|
16
|
+
def setup
|
17
|
+
@root_dir = File.expand_path(File.dirname(__FILE__) + '/root')
|
18
|
+
gra_dir = @root_dir + '/gra'
|
19
|
+
Config.init
|
20
|
+
Config['gra-dir'] = gra_dir
|
21
|
+
@list = List.new
|
22
|
+
@app = Rack::MockRequest.new @list
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_mk_regexp
|
26
|
+
s = '1a.*#'
|
27
|
+
list = List.new
|
28
|
+
ae "1a\\.\\*\\#", list.mk_regexp(s).source
|
29
|
+
list = List.new :use_regexp_search=>'on'
|
30
|
+
ae "1a.*\\#", list.mk_regexp(s).source
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_load_sysdb
|
34
|
+
sysdb = @list.load_sysdb Config.getvar('gra-dir')
|
35
|
+
assert_match /Linux host.example.com/, sysdb['192.168.0.1']['sysDescr']
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_list
|
39
|
+
res = @app.get '/'
|
40
|
+
ae 200, res.status
|
41
|
+
end
|
42
|
+
|
43
|
+
def test_list_sysdb_list
|
44
|
+
dirs = Config.getvar 'gra-dir'
|
45
|
+
sysdb = {}
|
46
|
+
params = {}
|
47
|
+
lines = @list.sysdb_list dirs, sysdb, params
|
48
|
+
ae [], lines
|
49
|
+
sysdb = {'host1'=>{}, 'host2'=>{}}
|
50
|
+
lines = @list.sysdb_list dirs, sysdb, params
|
51
|
+
ae ['host1', 'host2'], lines.map {|h, s| h}
|
52
|
+
end
|
53
|
+
|
54
|
+
def test_list_grep_graph
|
55
|
+
dirs = Config.getvar 'gra-dir'
|
56
|
+
sysdb = @list.load_sysdb dirs
|
57
|
+
hlines = @list.sysdb_list dirs, sysdb, {}
|
58
|
+
hosts = hlines.map {|h, l| h}
|
59
|
+
res = @list.grep_graph dirs, hosts, {}
|
60
|
+
ae 2, res.values.first.size
|
61
|
+
ae '', res.values.first.first.first
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
end
|
data/test/test_log.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/unittest_helper')
|
2
|
+
|
3
|
+
require 'gri/log'
|
4
|
+
|
5
|
+
module GRI
|
6
|
+
|
7
|
+
class TestLog < Test::Unit::TestCase
|
8
|
+
def test_log
|
9
|
+
time = Time.local(2014,1,2,3,4,56)
|
10
|
+
formatter = Log::Formatter.new
|
11
|
+
s = formatter.call nil, time, nil, 'test message'
|
12
|
+
ae "2014-01-02 03:04:56 test message\n", s
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
data/test/test_loop.rb
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/unittest_helper')
|
2
|
+
|
3
|
+
require 'gri/loop'
|
4
|
+
require 'gri/collector'
|
5
|
+
|
6
|
+
module GRI
|
7
|
+
|
8
|
+
class TestLoop < Test::Unit::TestCase
|
9
|
+
def setup
|
10
|
+
@loop = Loop.new
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_loop_attach_detach
|
14
|
+
collector = GRI::Collector.new('testhost', {}, {})
|
15
|
+
detached = false
|
16
|
+
@loop.on_detach {detached = true}
|
17
|
+
|
18
|
+
@loop.attach collector
|
19
|
+
ae 1, @loop.collectors.size
|
20
|
+
io = Object.new
|
21
|
+
@loop.watch io, :r, 5, collector
|
22
|
+
@loop.watch io, :w, 5, collector
|
23
|
+
@loop.watch io, :rw, 5, collector
|
24
|
+
@loop.detach collector
|
25
|
+
ae 0, @loop.collectors.size
|
26
|
+
assert detached
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_loop_has_active_watchers
|
30
|
+
assert !@loop.has_active_watchers?
|
31
|
+
@loop.run
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
data/test/test_ltsv.rb
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/unittest_helper')
|
2
|
+
|
3
|
+
require 'gri/ltsv'
|
4
|
+
|
5
|
+
module GRI
|
6
|
+
|
7
|
+
class TestLTSV < Test::Unit::TestCase
|
8
|
+
def test_ltsv_escape
|
9
|
+
ae 'a\tb', LTSV.escape("a\tb")
|
10
|
+
ae 'a\n\r\tb', LTSV.escape("a\n\r\tb")
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_ltsv_serialize
|
14
|
+
value = {'a'=>'1', 'b'=>'2', 'zzz'=>'10'}
|
15
|
+
line = LTSV.serialize value
|
16
|
+
ae value, LTSV.parse_string(line)
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_ltsv_dump_to_file
|
20
|
+
path = '/var/tmp/ltsv_test.txt'
|
21
|
+
values = [{'a'=>'1', 'b'=>'2'}, {'x'=>'10', 'y'=>'20'}]
|
22
|
+
LTSV.dump_to_file values, path
|
23
|
+
vs = LTSV.load_from_file path
|
24
|
+
ae values, vs
|
25
|
+
File.unlink path
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_parse_string
|
29
|
+
line = "a:b\tb:1\tc:\td:"
|
30
|
+
h = LTSV.parse_string line
|
31
|
+
ae 'b', h['a']
|
32
|
+
ae '1', h['b']
|
33
|
+
assert_nil h['c']
|
34
|
+
assert_nil h['d']
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|