fileq 0.1.3
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.
- data/README +15 -0
- data/lib/fileq.rb +455 -0
- data/lib/job.rb +181 -0
- data/lib/lockfile.rb +88 -0
- data/test/fileq_createdir_tests.rb +83 -0
- data/test/fileq_find_tests.rb +74 -0
- data/test/fileq_first_tests.rb +33 -0
- data/test/fileq_job_tests.rb +218 -0
- data/test/fileq_queue_tests.rb +365 -0
- data/test/fileq_test.rb +12 -0
- data/test/lockfile_test.rb +4 -0
- data/test/lockfile_tests.rb +132 -0
- data/test/test_helper.rb +8 -0
- metadata +67 -0
data/test/fileq_test.rb
ADDED
@@ -0,0 +1,132 @@
|
|
1
|
+
|
2
|
+
class LockFileTests < Test::Unit::TestCase
|
3
|
+
|
4
|
+
def setup
|
5
|
+
FileUtils.mkdir 'test/tmp/'
|
6
|
+
@tmp_fname1 = 'lock.file'
|
7
|
+
@tmp_name1 = 'test/tmp/' + @tmp_fname1
|
8
|
+
FileUtils.touch @tmp_name1
|
9
|
+
|
10
|
+
@tmp_fname2 = 'junk.file'
|
11
|
+
@tmp_name2 = 'test/tmp/' + @tmp_fname2
|
12
|
+
FileUtils.touch @tmp_name2
|
13
|
+
end
|
14
|
+
|
15
|
+
def teardown
|
16
|
+
FileUtils.rm_rf 'test/tmp'
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_create
|
20
|
+
assert(Xxeo::LockFile.new(@tmp_name1))
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_create_fail
|
24
|
+
assert_raise RuntimeError do
|
25
|
+
Xxeo::LockFile.new('dldldld')
|
26
|
+
end
|
27
|
+
|
28
|
+
File.chmod(0444, @tmp_name1)
|
29
|
+
assert_raise RuntimeError do
|
30
|
+
Xxeo::LockFile.new(@tmp_name1)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_lock_unlock
|
35
|
+
lf = Xxeo::LockFile.new(@tmp_name1)
|
36
|
+
assert(lf)
|
37
|
+
|
38
|
+
lf.lock
|
39
|
+
assert(lf.locked?)
|
40
|
+
assert_equal(1, lf.lock_count)
|
41
|
+
lf.unlock
|
42
|
+
|
43
|
+
assert(!lf.locked?)
|
44
|
+
assert_equal(0, lf.lock_count)
|
45
|
+
end
|
46
|
+
|
47
|
+
def test_lock_recursive
|
48
|
+
lf = Xxeo::LockFile.new(@tmp_name1)
|
49
|
+
assert(lf)
|
50
|
+
|
51
|
+
5.times do |i|
|
52
|
+
lf.lock
|
53
|
+
assert(lf.locked?)
|
54
|
+
assert_equal(i + 1, lf.lock_count)
|
55
|
+
end
|
56
|
+
|
57
|
+
4.times do |i|
|
58
|
+
lf.unlock
|
59
|
+
assert(lf.locked?)
|
60
|
+
assert_equal(4 - i, lf.lock_count)
|
61
|
+
end
|
62
|
+
|
63
|
+
# Final unlock
|
64
|
+
lf.unlock
|
65
|
+
|
66
|
+
assert(!lf.locked?)
|
67
|
+
assert_equal(0, lf.lock_count)
|
68
|
+
end
|
69
|
+
|
70
|
+
def test_unlock_fail
|
71
|
+
lf = Xxeo::LockFile.new(@tmp_name1)
|
72
|
+
assert(lf)
|
73
|
+
|
74
|
+
lf.lock
|
75
|
+
lf.unlock
|
76
|
+
assert_raise RuntimeError do
|
77
|
+
lf.unlock
|
78
|
+
end
|
79
|
+
|
80
|
+
|
81
|
+
lf = Xxeo::LockFile.new(@tmp_name1)
|
82
|
+
assert(lf)
|
83
|
+
|
84
|
+
assert_raise RuntimeError do
|
85
|
+
lf.unlock
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
# Have two processes fork, we need to test
|
90
|
+
# that they do something orderly that they normally
|
91
|
+
# wouldn't do if there wasn't a lock or if the lock
|
92
|
+
# didn't work
|
93
|
+
# For example, if the lock didn't work and they
|
94
|
+
# did writes, they should end up all mixed up
|
95
|
+
# This testing is hard since we cannot guaranty the
|
96
|
+
# ordering of which process wins the lock.
|
97
|
+
#
|
98
|
+
def test_lock_with_processes
|
99
|
+
5.times do | i |
|
100
|
+
fork {
|
101
|
+
File.open(@tmp_name2, "a") do
|
102
|
+
| f |
|
103
|
+
lf = Xxeo::LockFile.new(@tmp_name1)
|
104
|
+
assert(lf)
|
105
|
+
lf.lock
|
106
|
+
10.times {
|
107
|
+
f.syswrite(i.to_s)
|
108
|
+
sleep 0.01
|
109
|
+
}
|
110
|
+
f.syswrite("\n")
|
111
|
+
lf.unlock
|
112
|
+
end
|
113
|
+
}
|
114
|
+
end
|
115
|
+
l = Process.waitall
|
116
|
+
l.each { |pid, pstat| assert_equal(0, pstat.exitstatus) }
|
117
|
+
|
118
|
+
# Check the output
|
119
|
+
f = File.new(@tmp_name2)
|
120
|
+
lines = f.readlines
|
121
|
+
f.close
|
122
|
+
|
123
|
+
assert_equal(5, lines.length)
|
124
|
+
lines.sort!
|
125
|
+
5.times do | i |
|
126
|
+
assert_equal((i.to_s * 10) + "\n", lines[i])
|
127
|
+
end
|
128
|
+
|
129
|
+
end
|
130
|
+
|
131
|
+
end
|
132
|
+
|
data/test/test_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,67 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
rubygems_version: 0.9.4
|
3
|
+
specification_version: 1
|
4
|
+
name: fileq
|
5
|
+
version: !ruby/object:Gem::Version
|
6
|
+
version: 0.1.3
|
7
|
+
date: 2007-07-24 00:00:00 -07:00
|
8
|
+
summary: Simple transactional, persistent queue on top of Unix filesystem semantics
|
9
|
+
require_paths:
|
10
|
+
- lib
|
11
|
+
email: drudru@gmail.com
|
12
|
+
homepage: http://code.google.com/p/fileque/
|
13
|
+
rubyforge_project:
|
14
|
+
description:
|
15
|
+
autorequire: fileq
|
16
|
+
default_executable:
|
17
|
+
bindir: bin
|
18
|
+
has_rdoc: true
|
19
|
+
required_ruby_version: !ruby/object:Gem::Version::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">"
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 0.0.0
|
24
|
+
version:
|
25
|
+
platform: ruby
|
26
|
+
signing_key:
|
27
|
+
cert_chain:
|
28
|
+
post_install_message:
|
29
|
+
authors:
|
30
|
+
- Dru Nelson
|
31
|
+
files:
|
32
|
+
- test/fileq_test.rb
|
33
|
+
- test/fileq_job_tests.rb
|
34
|
+
- test/fileq_queue_tests.rb
|
35
|
+
- test/fileq_find_tests.rb
|
36
|
+
- test/lockfile_tests.rb
|
37
|
+
- test/lockfile_test.rb
|
38
|
+
- test/fileq_first_tests.rb
|
39
|
+
- test/test_helper.rb
|
40
|
+
- test/fixtures
|
41
|
+
- test/fileq_createdir_tests.rb
|
42
|
+
- lib/lockfile.rb
|
43
|
+
- lib/job.rb
|
44
|
+
- lib/fileq.rb
|
45
|
+
- README
|
46
|
+
test_files:
|
47
|
+
- test/fileq_test.rb
|
48
|
+
- test/fileq_job_tests.rb
|
49
|
+
- test/fileq_queue_tests.rb
|
50
|
+
- test/fileq_find_tests.rb
|
51
|
+
- test/lockfile_tests.rb
|
52
|
+
- test/lockfile_test.rb
|
53
|
+
- test/fileq_first_tests.rb
|
54
|
+
- test/test_helper.rb
|
55
|
+
- test/fileq_createdir_tests.rb
|
56
|
+
rdoc_options: []
|
57
|
+
|
58
|
+
extra_rdoc_files:
|
59
|
+
- README
|
60
|
+
executables: []
|
61
|
+
|
62
|
+
extensions: []
|
63
|
+
|
64
|
+
requirements: []
|
65
|
+
|
66
|
+
dependencies: []
|
67
|
+
|