stalk_climber 0.0.6 → 0.1.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.
- data/.rdoc_options +7 -0
- data/.travis.yml +8 -10
- data/Gemfile +1 -0
- data/lib/stalk_climber.rb +5 -0
- data/lib/stalk_climber/climber.rb +42 -54
- data/lib/stalk_climber/climber_enumerable.rb +110 -0
- data/lib/stalk_climber/climber_enumerables.rb +7 -0
- data/lib/stalk_climber/connection.rb +49 -37
- data/lib/stalk_climber/connection_pool.rb +37 -7
- data/lib/stalk_climber/job.rb +270 -67
- data/lib/stalk_climber/lazy_enumerable.rb +1 -0
- data/lib/stalk_climber/tube.rb +182 -0
- data/lib/stalk_climber/tubes.rb +37 -0
- data/lib/stalk_climber/version.rb +2 -1
- data/test/test_helper.rb +4 -2
- data/test/unit/beaneater_job_test.rb +260 -0
- data/test/unit/climber_enumerable.rb +18 -0
- data/test/unit/climber_test.rb +31 -100
- data/test/unit/connection_pool_test.rb +48 -33
- data/test/unit/connection_test.rb +200 -149
- data/test/unit/job_test.rb +240 -147
- data/test/unit/jobs_test.rb +106 -0
- data/test/unit/tube_test.rb +89 -0
- data/test/unit/tubes_test.rb +52 -0
- metadata +17 -2
@@ -0,0 +1,89 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class TubeTest < StalkClimber::TestCase
|
4
|
+
|
5
|
+
setup do
|
6
|
+
@climber = StalkClimber::Climber.new(BEANSTALK_ADDRESSES)
|
7
|
+
@tube_name = SecureRandom.uuid
|
8
|
+
@climber.connection_pool.transmit_to_all("watch #{@tube_name}")
|
9
|
+
@tube = StalkClimber::Tube.new(@climber.connection_pool, @tube_name)
|
10
|
+
end
|
11
|
+
|
12
|
+
|
13
|
+
context 'stats methods' do
|
14
|
+
|
15
|
+
should 'should delegate stats method to stats' do
|
16
|
+
stats_methods = StalkClimber::Tube::STATS_METHODS.values.reject do |method|
|
17
|
+
method == 'pause'
|
18
|
+
end
|
19
|
+
stats_methods << 'pause_time'
|
20
|
+
stats = @tube.stats
|
21
|
+
# Take 1 of stats_method.length to account for name superclass method
|
22
|
+
@tube.expects(:stats).times(stats_methods.length - 1).returns(stats)
|
23
|
+
stats_methods.each {|stats_method| @tube.public_send(stats_method)}
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
|
28
|
+
|
29
|
+
context 'exists?' do
|
30
|
+
|
31
|
+
should 'return false if the tube no longer exists' do
|
32
|
+
assert @tube.exists?
|
33
|
+
@climber.connection_pool.transmit_to_all("ignore #{@tube_name}")
|
34
|
+
refute @tube.exists?
|
35
|
+
end
|
36
|
+
|
37
|
+
|
38
|
+
should 'return true if the tube exists' do
|
39
|
+
@climber.connection_pool.transmit_to_all("ignore #{@tube_name}")
|
40
|
+
refute @tube.exists?
|
41
|
+
@climber.connection_pool.transmit_to_all("watch #{@tube_name}")
|
42
|
+
assert @tube.exists?
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
|
47
|
+
|
48
|
+
context '#to_h' do
|
49
|
+
|
50
|
+
should 'return the expected hash' do
|
51
|
+
stats_body = {
|
52
|
+
'cmd-delete' => 100,
|
53
|
+
'cmd-pause-tube' => 101,
|
54
|
+
'current-jobs-buried' => 102,
|
55
|
+
'current-jobs-delayed' => 103,
|
56
|
+
'current-jobs-ready' => 104,
|
57
|
+
'current-jobs-reserved' => 105,
|
58
|
+
'current-jobs-urgent' => 106,
|
59
|
+
'current-using' => 107,
|
60
|
+
'current-waiting' => 108,
|
61
|
+
'current-watching' => 109,
|
62
|
+
'name' => @tube_name,
|
63
|
+
'pause-time-left' => 110,
|
64
|
+
'pause' => 111,
|
65
|
+
'total-jobs' => 112,
|
66
|
+
}
|
67
|
+
stats_response = {
|
68
|
+
:body => stats_body,
|
69
|
+
:connection => @connection,
|
70
|
+
:id => 149,
|
71
|
+
:status => 'OK',
|
72
|
+
}
|
73
|
+
@tube.expects(:transmit_to_all).once.returns(stats_response)
|
74
|
+
expected_hash = Hash[stats_body.map { |k, v| [k, v] }]
|
75
|
+
assert_equal expected_hash, @tube.to_h
|
76
|
+
end
|
77
|
+
|
78
|
+
end
|
79
|
+
|
80
|
+
|
81
|
+
context '#to_s' do
|
82
|
+
|
83
|
+
should 'return expected string representation of tube' do
|
84
|
+
assert_equal "#<StalkClimber::Tube name=#{@tube_name}>", @tube.to_s
|
85
|
+
end
|
86
|
+
|
87
|
+
end
|
88
|
+
|
89
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class TubesTest < StalkClimber::TestCase
|
4
|
+
|
5
|
+
setup do
|
6
|
+
@climber = StalkClimber::Climber.new(BEANSTALK_ADDRESSES)
|
7
|
+
@tubes = @climber.tubes
|
8
|
+
end
|
9
|
+
|
10
|
+
|
11
|
+
context 'compositional components' do
|
12
|
+
|
13
|
+
should 'be some kind of Enumerable' do
|
14
|
+
assert_kind_of Enumerable, @tubes
|
15
|
+
end
|
16
|
+
|
17
|
+
|
18
|
+
should 'be some kind of Beaneater::Tubes' do
|
19
|
+
assert_kind_of Beaneater::Tubes, @tubes
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
|
24
|
+
|
25
|
+
context '#each' do
|
26
|
+
|
27
|
+
should 'delegate to Beaneater::Tubes#All' do
|
28
|
+
@tubes.expects(:all).once.returns(stub(:each => []))
|
29
|
+
@tubes.each
|
30
|
+
end
|
31
|
+
|
32
|
+
|
33
|
+
should 'iterate over all tubes in the pool yielding StalkClimber::Tube' do
|
34
|
+
@test_tubes = []
|
35
|
+
@climber.connection_pool.connections.each do |connection|
|
36
|
+
2.times do
|
37
|
+
@test_tubes << tube_name = SecureRandom.uuid
|
38
|
+
connection.transmit("watch #{tube_name}")
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
assert_equal @climber.connection_pool.connections.length * 2, @test_tubes.length
|
43
|
+
@tubes.each do |tube|
|
44
|
+
assert_kind_of StalkClimber::Tube, tube
|
45
|
+
@test_tubes.delete(tube.name)
|
46
|
+
end
|
47
|
+
assert_equal [], @test_tubes
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: stalk_climber
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
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: 2013-
|
12
|
+
date: 2013-12-07 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -67,6 +67,7 @@ extensions: []
|
|
67
67
|
extra_rdoc_files: []
|
68
68
|
files:
|
69
69
|
- .gitignore
|
70
|
+
- .rdoc_options
|
70
71
|
- .travis.yml
|
71
72
|
- Gemfile
|
72
73
|
- LICENSE
|
@@ -74,17 +75,26 @@ files:
|
|
74
75
|
- Rakefile
|
75
76
|
- lib/stalk_climber.rb
|
76
77
|
- lib/stalk_climber/climber.rb
|
78
|
+
- lib/stalk_climber/climber_enumerable.rb
|
79
|
+
- lib/stalk_climber/climber_enumerables.rb
|
77
80
|
- lib/stalk_climber/connection.rb
|
78
81
|
- lib/stalk_climber/connection_pool.rb
|
79
82
|
- lib/stalk_climber/job.rb
|
80
83
|
- lib/stalk_climber/lazy_enumerable.rb
|
84
|
+
- lib/stalk_climber/tube.rb
|
85
|
+
- lib/stalk_climber/tubes.rb
|
81
86
|
- lib/stalk_climber/version.rb
|
82
87
|
- stalk_climber.gemspec
|
83
88
|
- test/test_helper.rb
|
89
|
+
- test/unit/beaneater_job_test.rb
|
90
|
+
- test/unit/climber_enumerable.rb
|
84
91
|
- test/unit/climber_test.rb
|
85
92
|
- test/unit/connection_pool_test.rb
|
86
93
|
- test/unit/connection_test.rb
|
87
94
|
- test/unit/job_test.rb
|
95
|
+
- test/unit/jobs_test.rb
|
96
|
+
- test/unit/tube_test.rb
|
97
|
+
- test/unit/tubes_test.rb
|
88
98
|
homepage: https://github.com/gemeraldbeanstalk/stalk_climber
|
89
99
|
licenses:
|
90
100
|
- MIT
|
@@ -113,8 +123,13 @@ summary: StalkClimber is a Ruby library allowing improved sequential access to B
|
|
113
123
|
via a job cache.
|
114
124
|
test_files:
|
115
125
|
- test/test_helper.rb
|
126
|
+
- test/unit/beaneater_job_test.rb
|
127
|
+
- test/unit/climber_enumerable.rb
|
116
128
|
- test/unit/climber_test.rb
|
117
129
|
- test/unit/connection_pool_test.rb
|
118
130
|
- test/unit/connection_test.rb
|
119
131
|
- test/unit/job_test.rb
|
132
|
+
- test/unit/jobs_test.rb
|
133
|
+
- test/unit/tube_test.rb
|
134
|
+
- test/unit/tubes_test.rb
|
120
135
|
has_rdoc:
|