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,18 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class ClimberEnumerableTest < StalkClimber::TestCase
|
4
|
+
|
5
|
+
# Bulk of testing left to derived classes
|
6
|
+
|
7
|
+
context '::new' do
|
8
|
+
|
9
|
+
should 'return a new class with the specified enumerator method' do
|
10
|
+
klass = StalkClimber::ClimberEnumerable.new(:foo)
|
11
|
+
assert klass.included_modules.include?(StalkClimber::ClimberEnumerable), 'Expected ClimberEnumerable based class to include ClimberEnumerable'
|
12
|
+
assert(klass.respond_to?(:enumerator_method), 'Expected ClimberEnumerable based class to implement :enumerator_method')
|
13
|
+
assert_equal :foo, klass.enumerator_method
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
data/test/unit/climber_test.rb
CHANGED
@@ -1,136 +1,67 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
|
3
|
-
class ClimberTest <
|
3
|
+
class ClimberTest < StalkClimber::TestCase
|
4
4
|
|
5
|
-
|
6
|
-
climber = StalkClimber::Climber.new(BEANSTALK_ADDRESSES)
|
5
|
+
context '#connection_pool' do
|
7
6
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
5.times.to_a.map! do
|
12
|
-
test_jobs[connection.address] << StalkClimber::Job.new(connection.transmit(StalkClimber::Connection::PROBE_TRANSMISSION))
|
13
|
-
end
|
7
|
+
should 'create a ConnectionPool' do
|
8
|
+
climber = StalkClimber::Climber.new('beanstalk://localhost')
|
9
|
+
assert_kind_of StalkClimber::ConnectionPool, climber.connection_pool
|
14
10
|
end
|
15
11
|
|
16
|
-
jobs = {}
|
17
|
-
climber.each do |job|
|
18
|
-
jobs[job.connection.address] ||= {}
|
19
|
-
jobs[job.connection.address][job.id] = job
|
20
|
-
end
|
21
12
|
|
22
|
-
|
23
|
-
|
24
|
-
|
13
|
+
should 'raise an error without beanstalk addresses' do
|
14
|
+
climber = StalkClimber::Climber.new
|
15
|
+
assert_raises RuntimeError do
|
16
|
+
climber.connection_pool
|
17
|
+
end
|
25
18
|
end
|
26
19
|
|
27
|
-
climber.connection_pool.connections.each do |connection|
|
28
|
-
test_jobs[connection.address].map(&:delete)
|
29
|
-
end
|
30
20
|
end
|
31
21
|
|
32
22
|
|
33
|
-
|
34
|
-
climber = StalkClimber::Climber.new(BEANSTALK_ADDRESSES)
|
35
|
-
test_jobs = {}
|
36
|
-
climber.connection_pool.connections.each do |connection|
|
37
|
-
test_jobs[connection.address] = []
|
38
|
-
5.times.to_a.map! do
|
39
|
-
test_jobs[connection.address] << StalkClimber::Job.new(connection.transmit(StalkClimber::Connection::PROBE_TRANSMISSION))
|
40
|
-
end
|
41
|
-
end
|
23
|
+
context 'max_job_ids' do
|
42
24
|
|
43
|
-
|
44
|
-
|
45
|
-
climber.
|
46
|
-
|
25
|
+
should 'return correct max job ids' do
|
26
|
+
climber = StalkClimber::Climber.new(BEANSTALK_ADDRESSES, 'test_tube')
|
27
|
+
max_ids = climber.max_job_ids
|
28
|
+
max_ids.each do |connection, max_id|
|
29
|
+
assert_equal connection.max_job_id - 1, max_id
|
47
30
|
end
|
48
31
|
end
|
49
32
|
|
50
|
-
climber.connection_pool.connections.each do |connection|
|
51
|
-
test_jobs[connection.address].map(&:delete)
|
52
|
-
end
|
53
33
|
end
|
54
34
|
|
55
35
|
|
56
|
-
|
57
|
-
climber = StalkClimber::Climber.new('beanstalk://localhost')
|
58
|
-
assert_kind_of StalkClimber::ConnectionPool, climber.connection_pool
|
59
|
-
end
|
60
|
-
|
36
|
+
context '#jobs' do
|
61
37
|
|
62
|
-
|
63
|
-
|
64
|
-
assert_raise RuntimeError do
|
65
|
-
climber.connection_pool
|
38
|
+
should 'return an instance of Jobs' do
|
39
|
+
assert_kind_of StalkClimber::Jobs, StalkClimber::Climber.new(BEANSTALK_ADDRESSES).jobs
|
66
40
|
end
|
67
|
-
end
|
68
41
|
|
42
|
+
end
|
69
43
|
|
70
|
-
def test_enumerable_works_correctly
|
71
|
-
climber = StalkClimber::Climber.new(BEANSTALK_ADDRESSES)
|
72
|
-
test_jobs = {}
|
73
|
-
climber.connection_pool.connections.each do |connection|
|
74
|
-
test_jobs[connection.address] = []
|
75
|
-
5.times.to_a.map! do
|
76
|
-
test_jobs[connection.address] << StalkClimber::Job.new(connection.transmit(StalkClimber::Connection::PROBE_TRANSMISSION))
|
77
|
-
end
|
78
|
-
end
|
79
|
-
|
80
|
-
assert_nothing_raised do
|
81
|
-
# verify enumeration can be short circuited
|
82
|
-
climber.any? do |job|
|
83
|
-
true
|
84
|
-
end
|
85
44
|
|
86
|
-
|
87
|
-
climber.all? do |job|
|
88
|
-
job
|
89
|
-
end
|
90
|
-
end
|
45
|
+
context '#initialize' do
|
91
46
|
|
92
|
-
|
93
|
-
|
47
|
+
should 'accept a custom test tube' do
|
48
|
+
climber = StalkClimber::Climber.new(BEANSTALK_ADDRESSES, 'test_tube')
|
49
|
+
assert_equal 'test_tube', climber.test_tube
|
50
|
+
assert_equal 'test_tube', climber.connection_pool.test_tube
|
94
51
|
end
|
95
|
-
end
|
96
|
-
|
97
52
|
|
98
|
-
def test_each_is_an_alias_for_climb
|
99
|
-
assert_equal(
|
100
|
-
StalkClimber::Climber.instance_method(:climb),
|
101
|
-
StalkClimber::Climber.instance_method(:each),
|
102
|
-
'Expected StalkClimber::Climber#each to be an alias for StalkClimber::Climber#climb'
|
103
|
-
)
|
104
53
|
end
|
105
54
|
|
106
55
|
|
107
|
-
|
108
|
-
assert_equal(
|
109
|
-
StalkClimber::Climber.instance_method(:climb_threaded),
|
110
|
-
StalkClimber::Climber.instance_method(:each_threaded),
|
111
|
-
'Expected StalkClimber::Climber#each_threaded to be an alias for StalkClimber::Climber#climb_threaded'
|
112
|
-
)
|
113
|
-
end
|
56
|
+
context '#tubes' do
|
114
57
|
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
assert_equal connection.max_job_id - 1, max_id
|
58
|
+
should 'delegate to connection_pool for tubes' do
|
59
|
+
climber = StalkClimber::Climber.new(BEANSTALK_ADDRESSES, 'test_tube')
|
60
|
+
connection_pool = climber.connection_pool
|
61
|
+
connection_pool.expects(:tubes).once
|
62
|
+
climber.tubes
|
121
63
|
end
|
122
|
-
end
|
123
|
-
|
124
|
-
|
125
|
-
def test_to_enum_returns_an_enumerator
|
126
|
-
assert_kind_of Enumerator, StalkClimber::Climber.new(BEANSTALK_ADDRESSES).to_enum
|
127
|
-
end
|
128
|
-
|
129
64
|
|
130
|
-
def test_with_a_test_tube
|
131
|
-
climber = StalkClimber::Climber.new(BEANSTALK_ADDRESSES, 'test_tube')
|
132
|
-
assert_equal 'test_tube', climber.test_tube
|
133
|
-
assert_equal 'test_tube', climber.connection_pool.test_tube
|
134
65
|
end
|
135
66
|
|
136
67
|
end
|
@@ -3,54 +3,69 @@
|
|
3
3
|
|
4
4
|
require 'test_helper'
|
5
5
|
|
6
|
-
class ConnectionPoolTest <
|
6
|
+
class ConnectionPoolTest < StalkClimber::TestCase
|
7
7
|
|
8
|
-
|
9
|
-
|
10
|
-
|
8
|
+
context '#initialize' do
|
9
|
+
|
10
|
+
should 'test for bad url and raise StalkClimber::ConnectionPool::InvalidURIScheme' do
|
11
|
+
assert_raises(StalkClimber::ConnectionPool::InvalidURIScheme) do
|
12
|
+
StalkClimber::ConnectionPool.new('fake://foo')
|
13
|
+
end
|
11
14
|
end
|
12
|
-
end
|
13
15
|
|
14
16
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
17
|
+
should 'support multiple connections when passed as an array' do
|
18
|
+
connection_pool = StalkClimber::ConnectionPool.new(['beanstalk://localhost:11300','beanstalk://localhost'])
|
19
|
+
connections = connection_pool.connections
|
20
|
+
assert_equal 2, connection_pool.connections.size
|
21
|
+
assert_equal ['localhost:11300','localhost:11300'], connections.map(&:address)
|
22
|
+
end
|
19
23
|
|
20
24
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
25
|
+
should 'support multiple connections when passed as a comma separated string' do
|
26
|
+
connection_pool = StalkClimber::ConnectionPool.new('beanstalk://localhost:11300,beanstalk://localhost')
|
27
|
+
connections = connection_pool.connections
|
28
|
+
assert_equal 2, connections.size
|
29
|
+
assert_equal ['localhost:11300','localhost:11300'], connections.map(&:address)
|
30
|
+
end
|
27
31
|
|
28
32
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
end
|
33
|
+
should 'support a single connection url passed as a string' do
|
34
|
+
connection_pool = StalkClimber::ConnectionPool.new('beanstalk://localhost')
|
35
|
+
assert_kind_of StalkClimber::ConnectionPool, connection_pool
|
36
|
+
assert_kind_of Beaneater::Pool, connection_pool
|
37
|
+
end
|
35
38
|
|
36
39
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
40
|
+
should 'convert a single connection url into an array' do
|
41
|
+
connection_pool = StalkClimber::ConnectionPool.new('beanstalk://localhost')
|
42
|
+
assert_equal ['localhost:11300'], connection_pool.addresses
|
43
|
+
end
|
44
|
+
|
45
|
+
|
46
|
+
should 'support multiple URL formats' do
|
47
|
+
connection_pool = StalkClimber::ConnectionPool.new('127.0.0.1,0.0.0.0:11301,beanstalk://localhost:11300')
|
48
|
+
connections = connection_pool.connections
|
49
|
+
assert_equal 3, connections.size
|
50
|
+
assert_equal ['127.0.0.1:11300','0.0.0.0:11301', 'localhost:11300'], connections.map(&:address)
|
51
|
+
end
|
42
52
|
|
43
53
|
|
44
|
-
|
45
|
-
|
46
|
-
|
54
|
+
should 'support using a custom test tube' do
|
55
|
+
connection_pool = StalkClimber::ConnectionPool.new('beanstalk://localhost', 'test_tube')
|
56
|
+
assert_equal 'test_tube', connection_pool.test_tube
|
57
|
+
assert connection_pool.connections.all? { |connection| connection.test_tube == 'test_tube' }
|
58
|
+
end
|
47
59
|
end
|
48
60
|
|
49
61
|
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
62
|
+
context 'delegations' do
|
63
|
+
|
64
|
+
should 'delegate methods to beanstalk connection' do
|
65
|
+
connection_pool = StalkClimber::ConnectionPool.new('beanstalk://localhost')
|
66
|
+
assert_equal 'localhost', connection_pool.connections.first.host
|
67
|
+
end
|
68
|
+
|
54
69
|
end
|
55
70
|
|
56
71
|
end
|
@@ -1,251 +1,302 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
|
3
|
-
class ConnectionTest <
|
3
|
+
class ConnectionTest < StalkClimber::TestCase
|
4
4
|
|
5
|
-
|
5
|
+
setup do
|
6
6
|
@connection = StalkClimber::Connection.new('localhost:11300')
|
7
7
|
end
|
8
8
|
|
9
9
|
|
10
|
-
|
11
|
-
refute @connection.instance_variable_get(:@cache)
|
12
|
-
assert_equal({}, @connection.cache)
|
13
|
-
assert_equal({}, @connection.instance_variable_get(:@cache))
|
14
|
-
end
|
10
|
+
context '#cached_jobs' do
|
15
11
|
|
12
|
+
should 'create and return a hash instance variable' do
|
13
|
+
refute @connection.instance_variable_get(:@cached_jobs)
|
14
|
+
assert_equal({}, @connection.cached_jobs)
|
15
|
+
assert_equal({}, @connection.instance_variable_get(:@cached_jobs))
|
16
|
+
end
|
16
17
|
|
17
|
-
def test_cache_is_reset_if_max_job_id_lower_than_max_climbed_job_id
|
18
|
-
seeds = seed_jobs
|
19
|
-
@connection.each {}
|
20
|
-
assert_not_equal({}, @connection.cache)
|
21
|
-
assert_not_equal(Float::INFINITY, @connection.min_climbed_job_id)
|
22
|
-
assert_not_equal(0, @connection.max_climbed_job_id)
|
23
18
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
19
|
+
should 'reset if max job id lower than max climbed job id' do
|
20
|
+
seeds = seed_jobs
|
21
|
+
@connection.each_job {}
|
22
|
+
refute_equal({}, @connection.cached_jobs)
|
23
|
+
refute_equal(Float::INFINITY, @connection.min_climbed_job_id)
|
24
|
+
refute_equal(0, @connection.max_climbed_job_id)
|
30
25
|
|
26
|
+
@connection.send(:update_climbed_job_ids_from_max_id, 1)
|
27
|
+
assert_equal({}, @connection.cached_jobs)
|
28
|
+
assert_equal(Float::INFINITY, @connection.min_climbed_job_id)
|
29
|
+
assert_equal(0, @connection.max_climbed_job_id)
|
30
|
+
seeds.map(&:delete)
|
31
|
+
end
|
31
32
|
|
32
|
-
def test_connection_is_some_kind_of_enumerable
|
33
|
-
assert @connection.kind_of?(Enumerable)
|
34
33
|
end
|
35
34
|
|
36
35
|
|
37
|
-
|
38
|
-
seeds = seed_jobs
|
39
|
-
seeds.map(&:delete)
|
40
|
-
seed_ids = seeds.map(&:id)
|
36
|
+
context '#job_enumerator' do
|
41
37
|
|
42
|
-
|
43
|
-
|
38
|
+
should 'be some kind of enumerable' do
|
39
|
+
assert_kind_of Enumerable, @connection.job_enumerator
|
44
40
|
end
|
45
41
|
|
46
|
-
assert_nil deleted, "Deleted job found in enumeration: #{deleted}"
|
47
42
|
end
|
48
43
|
|
49
44
|
|
50
|
-
|
51
|
-
seeds = seed_jobs
|
45
|
+
context '#each_job' do
|
52
46
|
|
53
|
-
jobs
|
54
|
-
|
55
|
-
|
56
|
-
|
47
|
+
should 'not enumerate deleted jobs' do
|
48
|
+
seeds = seed_jobs
|
49
|
+
seeds.map(&:delete)
|
50
|
+
seed_ids = seeds.map(&:id)
|
51
|
+
|
52
|
+
deleted = @connection.each_job.detect do |job|
|
53
|
+
seed_ids.include?(job.id)
|
54
|
+
end
|
57
55
|
|
58
|
-
|
59
|
-
@connection.each do |job|
|
60
|
-
assert_equal jobs[job.id], job
|
56
|
+
assert_nil deleted, "Deleted job found in enumeration: #{deleted}"
|
61
57
|
end
|
62
58
|
|
63
|
-
seeds.map(&:delete)
|
64
|
-
end
|
65
59
|
|
60
|
+
should 'cache jobs for later use' do
|
61
|
+
seeds = seed_jobs
|
62
|
+
|
63
|
+
jobs = {}
|
64
|
+
@connection.each_job do |job|
|
65
|
+
jobs[job.id] = job
|
66
|
+
end
|
66
67
|
|
67
|
-
|
68
|
-
|
68
|
+
@connection.expects(:with_job).never
|
69
|
+
@connection.each_job do |job|
|
70
|
+
assert_equal jobs[job.id], job
|
71
|
+
end
|
69
72
|
|
70
|
-
|
71
|
-
@connection.each do |job|
|
72
|
-
jobs[job.id] = job
|
73
|
+
seeds.map(&:delete)
|
73
74
|
end
|
74
75
|
|
75
|
-
deleted_job = jobs[jobs.keys[2]]
|
76
|
-
deleted_job.delete
|
77
76
|
|
78
|
-
|
79
|
-
|
80
|
-
|
77
|
+
should 'delete cached jobs that no longer exists' do
|
78
|
+
seeds = seed_jobs
|
79
|
+
|
80
|
+
jobs = {}
|
81
|
+
@connection.each_job do |job|
|
82
|
+
jobs[job.id] = job
|
83
|
+
end
|
84
|
+
|
85
|
+
deleted_job = jobs[jobs.keys[2]]
|
86
|
+
deleted_job.delete
|
87
|
+
|
88
|
+
@connection.expects(:with_job).never
|
89
|
+
@connection.each_job do |job|
|
90
|
+
assert_equal jobs.delete(job.id), job
|
91
|
+
end
|
92
|
+
|
93
|
+
assert_equal 1, jobs.length
|
94
|
+
assert_equal deleted_job.id, jobs.values.first.id
|
95
|
+
|
96
|
+
seeds.map {|job| job.delete if job.exists? }
|
81
97
|
end
|
82
98
|
|
83
|
-
assert_equal 1, jobs.length
|
84
|
-
assert_equal deleted_job.id, jobs.values.first.id
|
85
99
|
|
86
|
-
|
87
|
-
|
100
|
+
should 'hit jobs below climbed range that have not been previously hit' do
|
101
|
+
seeds = seed_jobs(10)
|
88
102
|
|
103
|
+
count = 0
|
104
|
+
@connection.each_job do |job|
|
105
|
+
count += 1
|
106
|
+
break if count == 5
|
107
|
+
end
|
89
108
|
|
90
|
-
|
91
|
-
seeds = seed_jobs(10)
|
109
|
+
initial_min_climbed_job_id = @connection.min_climbed_job_id
|
92
110
|
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
111
|
+
all_jobs = {}
|
112
|
+
@connection.each_job do |job|
|
113
|
+
all_jobs[job.id] = job
|
114
|
+
end
|
115
|
+
|
116
|
+
seeds.each do |job|
|
117
|
+
assert_equal all_jobs[job.id].body, job.body
|
118
|
+
assert_equal all_jobs[job.id].id, job.id
|
119
|
+
job.delete
|
120
|
+
end
|
121
|
+
|
122
|
+
assert @connection.min_climbed_job_id < initial_min_climbed_job_id
|
97
123
|
end
|
98
124
|
|
99
|
-
initial_min_climbed_job_id = @connection.min_climbed_job_id
|
100
125
|
|
101
|
-
|
102
|
-
|
103
|
-
|
126
|
+
should 'hit each job only once' do
|
127
|
+
seeds = seed_jobs
|
128
|
+
|
129
|
+
jobs = {}
|
130
|
+
@connection.each_job do |job|
|
131
|
+
refute jobs[job.id]
|
132
|
+
jobs[job.id] = job
|
133
|
+
end
|
134
|
+
|
135
|
+
seeds.map(&:delete)
|
104
136
|
end
|
105
137
|
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
138
|
+
|
139
|
+
should 'get enumerator via #job_enumerator' do
|
140
|
+
@connection.expects(:job_enumerator).returns(Enumerator.new { |yielder| yielder << 1 })
|
141
|
+
@connection.each_job {}
|
110
142
|
end
|
111
143
|
|
112
|
-
assert @connection.min_climbed_job_id < initial_min_climbed_job_id
|
113
|
-
end
|
114
144
|
|
145
|
+
should 'set min and max climbed job ids appropriately' do
|
146
|
+
assert_equal Float::INFINITY, @connection.min_climbed_job_id
|
147
|
+
assert_equal 0, @connection.max_climbed_job_id
|
115
148
|
|
116
|
-
|
117
|
-
|
149
|
+
max_id = @connection.max_job_id
|
150
|
+
@connection.expects(:max_job_id).once.returns(max_id)
|
151
|
+
@connection.each_job {}
|
118
152
|
|
119
|
-
|
120
|
-
|
121
|
-
refute jobs[job.id]
|
122
|
-
jobs[job.id] = job
|
153
|
+
assert_equal 1, @connection.min_climbed_job_id
|
154
|
+
assert_equal max_id, @connection.max_climbed_job_id
|
123
155
|
end
|
124
156
|
|
125
|
-
seeds.map(&:delete)
|
126
|
-
end
|
127
157
|
|
158
|
+
should 'allow for breaking enumeration' do
|
159
|
+
begin
|
160
|
+
count = 0
|
161
|
+
@connection.each_job do |job|
|
162
|
+
break if 2 == count += 1
|
163
|
+
assert(false, "Connection#each_job did not break when expected") if count >= 3
|
164
|
+
end
|
165
|
+
rescue => e
|
166
|
+
assert(false, "Breaking from Connection#each_job raised #{e.inspect}")
|
167
|
+
end
|
168
|
+
end
|
128
169
|
|
129
|
-
def test_each_calls_to_enum
|
130
|
-
@connection.expects(:to_enum).returns(Enumerator.new { |yielder| yielder << 1 })
|
131
|
-
@connection.each {}
|
132
170
|
end
|
133
171
|
|
172
|
+
context '#fetch_job' do
|
134
173
|
|
135
|
-
|
136
|
-
assert_nothing_raised do
|
174
|
+
should 'return nil or the requested job if it exists' do
|
137
175
|
job = @connection.fetch_job(@connection.max_job_id)
|
138
176
|
assert_equal nil, job
|
177
|
+
|
178
|
+
probe = seed_jobs(1).first
|
179
|
+
assert_equal probe.id, @connection.fetch_job(probe.id).id
|
180
|
+
probe.delete
|
139
181
|
end
|
140
182
|
|
141
|
-
probe = seed_jobs(1).first
|
142
|
-
assert_equal probe.id, @connection.fetch_job(probe.id).id
|
143
|
-
probe.delete
|
144
183
|
end
|
145
184
|
|
146
185
|
|
147
|
-
|
148
|
-
|
149
|
-
|
186
|
+
context '#fetch_job!' do
|
187
|
+
|
188
|
+
should 'return requested job or raise an error if the job does not exists' do
|
189
|
+
assert_raises Beaneater::NotFoundError do
|
190
|
+
@connection.fetch_job!(@connection.max_job_id)
|
191
|
+
end
|
192
|
+
|
193
|
+
probe = seed_jobs(1).first
|
194
|
+
assert_equal probe.id, @connection.fetch_job!(probe.id).id
|
195
|
+
probe.delete
|
150
196
|
end
|
151
197
|
|
152
|
-
probe = seed_jobs(1).first
|
153
|
-
assert_equal probe.id, @connection.fetch_job!(probe.id).id
|
154
|
-
probe.delete
|
155
198
|
end
|
156
199
|
|
157
200
|
|
158
|
-
|
159
|
-
|
201
|
+
context '#fetch_jobs' do
|
202
|
+
|
203
|
+
should 'return each requested job or nil' do
|
160
204
|
jobs = @connection.fetch_jobs(@connection.max_job_id, @connection.max_job_id)
|
161
205
|
assert_equal [nil, nil], jobs
|
206
|
+
|
207
|
+
probes = seed_jobs(2)
|
208
|
+
probe_ids = probes.map(&:id)
|
209
|
+
assert_equal probe_ids, @connection.fetch_jobs(probe_ids).map(&:id)
|
210
|
+
probes.map(&:delete)
|
162
211
|
end
|
163
212
|
|
164
|
-
probes = seed_jobs(2)
|
165
|
-
probe_ids = probes.map(&:id)
|
166
|
-
assert_equal probe_ids, @connection.fetch_jobs(probe_ids).map(&:id)
|
167
|
-
probes.map(&:delete)
|
168
213
|
end
|
169
214
|
|
170
215
|
|
171
|
-
|
172
|
-
|
216
|
+
context '#fetch_jobs!' do
|
217
|
+
|
218
|
+
should 'return the requested jobs or raise an error if any job does not exist' do
|
219
|
+
probes = seed_jobs(2)
|
173
220
|
|
174
|
-
|
175
|
-
|
221
|
+
probe_ids = probes.map(&:id)
|
222
|
+
assert_equal probe_ids, @connection.fetch_jobs!(probe_ids).map(&:id)
|
176
223
|
|
177
|
-
|
178
|
-
|
224
|
+
assert_raises Beaneater::NotFoundError do
|
225
|
+
@connection.fetch_jobs!(probe_ids.first, @connection.max_job_id, probe_ids.last)
|
226
|
+
end
|
227
|
+
|
228
|
+
probes.map(&:delete)
|
179
229
|
end
|
180
230
|
|
181
|
-
probes.map(&:delete)
|
182
231
|
end
|
183
232
|
|
184
233
|
|
185
|
-
|
186
|
-
initial_max = @connection.max_job_id
|
187
|
-
seed_jobs(3).map(&:delete)
|
188
|
-
# 3 new jobs, +1 for the probe job
|
189
|
-
assert_equal initial_max + 4, @connection.max_job_id
|
190
|
-
end
|
234
|
+
context '#max_job_id' do
|
191
235
|
|
236
|
+
should 'return expected max job id' do
|
237
|
+
initial_max = @connection.max_job_id
|
238
|
+
seed_jobs(3).map(&:delete)
|
239
|
+
# 3 new jobs, +1 for the probe job
|
240
|
+
assert_equal initial_max + 4, @connection.max_job_id
|
241
|
+
end
|
192
242
|
|
193
|
-
def test_max_job_id_should_increment_max_climbed_id_if_successor
|
194
|
-
@connection.each {}
|
195
|
-
max = @connection.max_climbed_job_id
|
196
|
-
@connection.max_job_id
|
197
|
-
assert_equal max + 1, @connection.max_climbed_job_id
|
198
|
-
end
|
199
243
|
|
244
|
+
should 'increment max climbed id if successor visited' do
|
245
|
+
@connection.each_job {}
|
246
|
+
max = @connection.max_climbed_job_id
|
247
|
+
@connection.max_job_id
|
248
|
+
assert_equal max + 1, @connection.max_climbed_job_id
|
249
|
+
end
|
250
|
+
|
251
|
+
|
252
|
+
should 'not increment max_climbed_id unless visiting successor' do
|
253
|
+
@connection.each_job {}
|
254
|
+
max = @connection.max_climbed_job_id
|
255
|
+
seed_jobs(1).map(&:delete)
|
256
|
+
@connection.max_job_id
|
257
|
+
assert_equal max, @connection.max_climbed_job_id
|
258
|
+
end
|
200
259
|
|
201
|
-
def test_max_job_id_should_not_increment_max_climbed_id_unless_successor
|
202
|
-
@connection.each {}
|
203
|
-
max = @connection.max_climbed_job_id
|
204
|
-
seed_jobs(1).map(&:delete)
|
205
|
-
@connection.max_job_id
|
206
|
-
assert_equal max, @connection.max_climbed_job_id
|
207
260
|
end
|
208
261
|
|
209
262
|
|
210
|
-
|
211
|
-
assert_equal Float::INFINITY, @connection.min_climbed_job_id
|
212
|
-
assert_equal 0, @connection.max_climbed_job_id
|
263
|
+
context '#initialize' do
|
213
264
|
|
214
|
-
|
215
|
-
|
216
|
-
|
265
|
+
should 'initialize with a test tube' do
|
266
|
+
StalkClimber::Connection.any_instance.expects(:use_test_tube)
|
267
|
+
connection = StalkClimber::Connection.new('localhost:11300', 'test_tube')
|
268
|
+
assert_equal 'test_tube', connection.test_tube
|
269
|
+
end
|
217
270
|
|
218
|
-
assert_equal 1, @connection.min_climbed_job_id
|
219
|
-
assert_equal max_id, @connection.max_climbed_job_id
|
220
271
|
end
|
221
272
|
|
273
|
+
context '#test_tube=' do
|
274
|
+
|
275
|
+
should 'initialize with test tube but allow configuration' do
|
276
|
+
assert_equal StalkClimber::Connection::DEFAULT_TUBE, @connection.test_tube
|
277
|
+
tube_name = 'test_tube'
|
278
|
+
@connection.test_tube = tube_name
|
279
|
+
assert_equal tube_name, @connection.test_tube
|
280
|
+
end
|
222
281
|
|
223
|
-
def test_initialize_with_a_test_tube
|
224
|
-
StalkClimber::Connection.any_instance.expects(:use_test_tube)
|
225
|
-
connection = StalkClimber::Connection.new('localhost:11300', 'test_tube')
|
226
|
-
assert_equal 'test_tube', connection.test_tube
|
227
|
-
end
|
228
282
|
|
283
|
+
should 'use the supplied test tube' do
|
284
|
+
@connection.expects(:transmit).with('use test_tube')
|
285
|
+
@connection.expects(:transmit).with('watch test_tube')
|
286
|
+
@connection.expects(:transmit).with('ignore default')
|
287
|
+
@connection.test_tube = 'test_tube'
|
288
|
+
assert_equal 'test_tube', @connection.test_tube
|
289
|
+
end
|
229
290
|
|
230
|
-
def test_test_tube_is_initialized_but_configurable
|
231
|
-
assert_equal StalkClimber::Connection::DEFAULT_TUBE, @connection.test_tube
|
232
|
-
tube_name = 'test_tube'
|
233
|
-
@connection.test_tube = tube_name
|
234
|
-
assert_equal tube_name, @connection.test_tube
|
235
291
|
end
|
236
292
|
|
237
293
|
|
238
|
-
|
239
|
-
@connection.expects(:transmit).with('use test_tube')
|
240
|
-
@connection.expects(:transmit).with('watch test_tube')
|
241
|
-
@connection.expects(:transmit).with('ignore default')
|
242
|
-
@connection.test_tube = 'test_tube'
|
243
|
-
assert_equal 'test_tube', @connection.test_tube
|
244
|
-
end
|
294
|
+
context '#to_enum' do
|
245
295
|
|
296
|
+
should 'return an enumerator' do
|
297
|
+
assert_kind_of Enumerator, @connection.to_enum
|
298
|
+
end
|
246
299
|
|
247
|
-
def test_to_enum_returns_an_enumerator
|
248
|
-
assert_kind_of Enumerator, @connection.to_enum
|
249
300
|
end
|
250
301
|
|
251
302
|
end
|