Class: FileTailGroupTest
- Inherits:
-
Test::Unit::TestCase
- Object
- Test::Unit::TestCase
- FileTailGroupTest
show all
- Includes:
- File::Tail
- Defined in:
- tests/file_tail_group_test.rb
Constant Summary
Constants included
from File::Tail
File::Tail::VERSION, File::Tail::VERSION_ARRAY, File::Tail::VERSION_BUILD, File::Tail::VERSION_MAJOR, File::Tail::VERSION_MINOR
Instance Attribute Summary
Attributes included from File::Tail
#break_if_eof, #default_bufsize, #interval, #line_separator, #max_interval, #reopen_deleted, #reopen_suspicious, #return_if_eof, #suspicious_interval
Instance Method Summary
collapse
Methods included from File::Tail
#after_reopen, #backward, #debug?, #forward, #output_debug_information, #preset_attributes, #read_line, #reopen_file, #restat, #sleep_interval, #tail
Instance Method Details
#make_file ⇒ Object
79
80
81
82
83
84
|
# File 'tests/file_tail_group_test.rb', line 79
def make_file
name = File.expand_path(File.join(Dir.tmpdir, "tmp.#$$"))
file = File.open(name, 'w+')
file.extend File::Tail
return file, name
end
|
#test_add_file_to_group ⇒ Object
29
30
31
32
33
34
35
|
# File 'tests/file_tail_group_test.rb', line 29
def test_add_file_to_group
g = Group.new
t, = make_file
g.add_file t
assert_equal t.path, g.each_tailer.first.file.path
assert_equal t.path, g.each_file.first.path
end
|
#test_add_filename_to_group ⇒ Object
37
38
39
40
41
42
43
44
|
# File 'tests/file_tail_group_test.rb', line 37
def test_add_filename_to_group
g = Group.new
t, name = make_file
t.close
g.add_filename name
assert_equal name, g.each_tailer.first.file.path
assert_equal t.path, g.each_file.first.path
end
|
#test_add_generic_to_group ⇒ Object
46
47
48
49
50
51
52
53
54
55
56
57
|
# File 'tests/file_tail_group_test.rb', line 46
def test_add_generic_to_group
g = Group.new
t1, n1 = make_file
t1.close
t2, n1 = make_file
g << n1
g << t2
assert g.each_tailer.any? { |t| t.file.path == n1 }
assert g.each_tailer.any? { |t| t.file.path == t2.path }
assert g.each_file.any? { |t| t.path == n1 }
assert g.each_file.any? { |t| t.path == t2.path }
end
|
#test_create_group ⇒ Object
13
14
15
16
17
18
|
# File 'tests/file_tail_group_test.rb', line 13
def test_create_group
t, = make_file
g = Group[t]
assert_equal t.path, g.each_tailer.first.file.path
assert_equal t.path, g.each_file.first.path
end
|
#test_stop_group ⇒ Object
20
21
22
23
24
25
26
27
|
# File 'tests/file_tail_group_test.rb', line 20
def test_stop_group
t, = make_file
g = Group[t]
assert_equal t.path, g.each_tailer.first.file.path
assert_equal t.path, g.each_file.first.path
g.stop
assert_nil g.each_file.first
end
|
#test_tail_multiple_files ⇒ Object
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
# File 'tests/file_tail_group_test.rb', line 59
def test_tail_multiple_files
t1, = make_file
t1.max_interval = 0.1
t2, = make_file
t2.max_interval = 0.1
g = Group[t1, t2]
q = Queue.new
t = Thread.new do
g.tail { |l| q << l }
end
t1.puts "foo"
assert_equal "foo\n", q.pop
t2.puts "bar"
assert_equal "bar\n", q.pop
ensure
t and t.exit
end
|