agent 0.10.0 → 0.11.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +16 -11
- data/lib/agent/channel.rb +4 -2
- data/lib/agent/version.rb +1 -1
- data/spec/blocking_once_spec.rb +13 -13
- data/spec/channel_spec.rb +44 -44
- data/spec/error_spec.rb +2 -2
- data/spec/examples/channel_of_channels_spec.rb +2 -2
- data/spec/examples/producer_consumer_spec.rb +5 -5
- data/spec/examples/sieve_spec.rb +2 -2
- data/spec/go_spec.rb +3 -3
- data/spec/notifier_spec.rb +7 -7
- data/spec/once_spec.rb +13 -13
- data/spec/pop_spec.rb +29 -29
- data/spec/push_spec.rb +27 -27
- data/spec/queue_spec.rb +92 -92
- data/spec/queues_spec.rb +6 -6
- data/spec/selector_spec.rb +117 -58
- data/spec/spec_helper.rb +0 -1
- data/spec/uuid_spec.rb +2 -2
- data/spec/wait_group_spec.rb +5 -5
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cb98d2b1912834ca7a296fb6dd1895c90c62d371
|
4
|
+
data.tar.gz: ea72c26e2be6e8bbd7ef710a2a2a87e0ef8141c6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c3bcd58b2138db30b0c1f732673b7b9654f90b26358cf89c480efab7aa7ef8e9b5ae876949d726f64c93459cd8b995b35ff5202bf2665be23656632340b64094
|
7
|
+
data.tar.gz: 30116a292e6d8e36894b2da56638bda87a817be19355f4c7ffe0d70a243d3a11c9cc13e913705c4eec067f3a95c75badd62b42279c469874764adef23e20097e
|
data/Gemfile.lock
CHANGED
@@ -1,21 +1,26 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
agent (0.
|
4
|
+
agent (0.10.0)
|
5
5
|
|
6
6
|
GEM
|
7
7
|
remote: http://rubygems.org/
|
8
8
|
specs:
|
9
|
-
diff-lcs (1.
|
10
|
-
rake (
|
11
|
-
rspec (2.
|
12
|
-
rspec-core (~> 2.
|
13
|
-
rspec-expectations (~> 2.
|
14
|
-
rspec-mocks (~> 2.
|
15
|
-
rspec-core (2.
|
16
|
-
|
17
|
-
|
18
|
-
|
9
|
+
diff-lcs (1.2.5)
|
10
|
+
rake (10.4.2)
|
11
|
+
rspec (3.2.0)
|
12
|
+
rspec-core (~> 3.2.0)
|
13
|
+
rspec-expectations (~> 3.2.0)
|
14
|
+
rspec-mocks (~> 3.2.0)
|
15
|
+
rspec-core (3.2.0)
|
16
|
+
rspec-support (~> 3.2.0)
|
17
|
+
rspec-expectations (3.2.0)
|
18
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
19
|
+
rspec-support (~> 3.2.0)
|
20
|
+
rspec-mocks (3.2.0)
|
21
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
22
|
+
rspec-support (~> 3.2.0)
|
23
|
+
rspec-support (3.2.1)
|
19
24
|
|
20
25
|
PLATFORMS
|
21
26
|
java
|
data/lib/agent/channel.rb
CHANGED
@@ -61,8 +61,10 @@ module Agent
|
|
61
61
|
def receive(options={})
|
62
62
|
check_direction(:receive)
|
63
63
|
q = queue
|
64
|
-
return
|
65
|
-
|
64
|
+
return q.pop(options) if q
|
65
|
+
pop = Pop.new(options)
|
66
|
+
pop.close
|
67
|
+
[pop.object, false]
|
66
68
|
end
|
67
69
|
alias :pop :receive
|
68
70
|
|
data/lib/agent/version.rb
CHANGED
data/spec/blocking_once_spec.rb
CHANGED
@@ -13,8 +13,8 @@ describe Agent::BlockingOnce do
|
|
13
13
|
r << 1
|
14
14
|
end
|
15
15
|
|
16
|
-
r.size.
|
17
|
-
r.first.
|
16
|
+
expect(r.size).to eq(1)
|
17
|
+
expect(r.first).to eq(1)
|
18
18
|
end
|
19
19
|
|
20
20
|
it "should only execute the first block passed to it" do
|
@@ -28,8 +28,8 @@ describe Agent::BlockingOnce do
|
|
28
28
|
r << 2
|
29
29
|
end
|
30
30
|
|
31
|
-
r.size.
|
32
|
-
r.first.
|
31
|
+
expect(r.size).to eq(1)
|
32
|
+
expect(r.first).to eq(1)
|
33
33
|
end
|
34
34
|
|
35
35
|
it "should return the value returned from the block" do
|
@@ -37,18 +37,18 @@ describe Agent::BlockingOnce do
|
|
37
37
|
1
|
38
38
|
end
|
39
39
|
|
40
|
-
value.
|
40
|
+
expect(value).to eq(1)
|
41
41
|
end
|
42
42
|
|
43
43
|
it "should return nil for value and an error if it has already been used" do
|
44
44
|
value, error = @blocking_once.perform{ 1 }
|
45
|
-
value.
|
46
|
-
error.
|
45
|
+
expect(value).to eq(1)
|
46
|
+
expect(error).to be_nil
|
47
47
|
|
48
48
|
value, error = @blocking_once.perform{ 2 }
|
49
|
-
value.
|
50
|
-
error.
|
51
|
-
error.
|
49
|
+
expect(value).to be_nil
|
50
|
+
expect(error).not_to be_nil
|
51
|
+
expect(error).to be_message("already performed")
|
52
52
|
end
|
53
53
|
|
54
54
|
it "should roll back and allow the block to be executed again" do
|
@@ -78,7 +78,7 @@ describe Agent::BlockingOnce do
|
|
78
78
|
finished_channel.close
|
79
79
|
|
80
80
|
# Three sleeps at 0.1 == 0.3, so if it's less than 0.3...
|
81
|
-
(Time.now.to_f - s).
|
81
|
+
expect(Time.now.to_f - s).to be < 0.3
|
82
82
|
end
|
83
83
|
|
84
84
|
it "should have minimal contention between threads when they contend for position" do
|
@@ -111,9 +111,9 @@ describe Agent::BlockingOnce do
|
|
111
111
|
# wait for the finished channel to be completed
|
112
112
|
2.times{ finished_channel.receive }
|
113
113
|
|
114
|
-
r.size.
|
114
|
+
expect(r.size).to eq(1)
|
115
115
|
# Onlt the first sleep should be performed, so things should quickly
|
116
|
-
(Time.now.to_f - s).
|
116
|
+
expect(Time.now.to_f - s).to be_within(0.05).of(0.15)
|
117
117
|
|
118
118
|
waiting_channel.close
|
119
119
|
finished_channel.close
|
data/spec/channel_spec.rb
CHANGED
@@ -5,13 +5,13 @@ describe Agent::Channel do
|
|
5
5
|
context "naming" do
|
6
6
|
it "should not be required" do
|
7
7
|
c = nil
|
8
|
-
|
8
|
+
expect { c = channel!(String) }.not_to raise_error
|
9
9
|
c.close
|
10
10
|
end
|
11
11
|
|
12
12
|
it "be able to be set" do
|
13
13
|
c = channel!(String, :name => "gibberish")
|
14
|
-
c.name.
|
14
|
+
expect(c.name).to eq("gibberish")
|
15
15
|
c.close
|
16
16
|
end
|
17
17
|
end
|
@@ -24,14 +24,14 @@ describe Agent::Channel do
|
|
24
24
|
it "should support send only" do
|
25
25
|
c = channel!(String, 3, :direction => :send)
|
26
26
|
|
27
|
-
|
28
|
-
|
29
|
-
|
27
|
+
expect { c << "hello" }.not_to raise_error
|
28
|
+
expect { c.push "hello" }.not_to raise_error
|
29
|
+
expect { c.send "hello" }.not_to raise_error
|
30
30
|
|
31
|
-
c.direction.
|
31
|
+
expect(c.direction).to eq(:send)
|
32
32
|
|
33
|
-
|
34
|
-
|
33
|
+
expect { c.pop }.to raise_error Agent::Errors::InvalidDirection
|
34
|
+
expect { c.receive }.to raise_error Agent::Errors::InvalidDirection
|
35
35
|
|
36
36
|
c.close
|
37
37
|
end
|
@@ -39,11 +39,11 @@ describe Agent::Channel do
|
|
39
39
|
it "should support receive only" do
|
40
40
|
c = channel!(String, :direction => :receive)
|
41
41
|
|
42
|
-
|
43
|
-
|
44
|
-
|
42
|
+
expect { c << "hello" }.to raise_error Agent::Errors::InvalidDirection
|
43
|
+
expect { c.push "hello" }.to raise_error Agent::Errors::InvalidDirection
|
44
|
+
expect { c.send "hello" }.to raise_error Agent::Errors::InvalidDirection
|
45
45
|
|
46
|
-
c.direction.
|
46
|
+
expect(c.direction).to eq(:receive)
|
47
47
|
|
48
48
|
# timeout blocking receive calls
|
49
49
|
timed_out = false
|
@@ -51,29 +51,29 @@ describe Agent::Channel do
|
|
51
51
|
s.case(c, :receive)
|
52
52
|
s.timeout(0.1){ timed_out = true }
|
53
53
|
end
|
54
|
-
timed_out.
|
54
|
+
expect(timed_out).to eq(true)
|
55
55
|
c.close
|
56
56
|
end
|
57
57
|
|
58
58
|
it "should default to bi-directional communication" do
|
59
59
|
c = channel!(String, 1)
|
60
|
-
|
61
|
-
|
60
|
+
expect { c.send "hello" }.not_to raise_error
|
61
|
+
expect { c.receive }.not_to raise_error
|
62
62
|
|
63
|
-
c.direction.
|
63
|
+
expect(c.direction).to eq(:bidirectional)
|
64
64
|
end
|
65
65
|
|
66
66
|
it "should be able to be dup'd as a uni-directional channel" do
|
67
67
|
c = channel!(String, 1)
|
68
68
|
|
69
69
|
send_only = c.as_send_only
|
70
|
-
send_only.direction.
|
70
|
+
expect(send_only.direction).to eq(:send)
|
71
71
|
|
72
72
|
receive_only = c.as_receive_only
|
73
|
-
receive_only.direction.
|
73
|
+
expect(receive_only.direction).to eq(:receive)
|
74
74
|
|
75
75
|
send_only.send("nifty")
|
76
|
-
receive_only.receive[0].
|
76
|
+
expect(receive_only.receive[0]).to eq("nifty")
|
77
77
|
end
|
78
78
|
end
|
79
79
|
|
@@ -83,35 +83,35 @@ describe Agent::Channel do
|
|
83
83
|
end
|
84
84
|
|
85
85
|
it "not raise an error the first time it is called" do
|
86
|
-
|
87
|
-
@c.
|
86
|
+
expect { @c.close }.not_to raise_error
|
87
|
+
expect(@c).to be_closed
|
88
88
|
end
|
89
89
|
|
90
90
|
it "should raise an error the second time it is called" do
|
91
91
|
@c.close
|
92
|
-
|
92
|
+
expect { @c.close }.to raise_error(Agent::Errors::ChannelClosed)
|
93
93
|
end
|
94
94
|
|
95
95
|
it "should respond to closed?" do
|
96
|
-
@c.
|
96
|
+
expect(@c).not_to be_closed
|
97
97
|
@c.close
|
98
|
-
@c.
|
98
|
+
expect(@c).to be_closed
|
99
99
|
end
|
100
100
|
|
101
101
|
it "should return that a receive was a failure when a channel is closed while being read from" do
|
102
102
|
go!{ sleep 0.01; @c.close }
|
103
103
|
_, ok = @c.receive
|
104
|
-
ok.
|
104
|
+
expect(ok).to eq(false)
|
105
105
|
end
|
106
106
|
|
107
107
|
it "should raise an error when sending to a channel that has already been closed" do
|
108
108
|
@c.close
|
109
|
-
|
109
|
+
expect { @c.send("a") }.to raise_error(Agent::Errors::ChannelClosed)
|
110
110
|
end
|
111
111
|
|
112
112
|
it "should return [nil, false] when receiving from a channel that has already been closed" do
|
113
113
|
@c.close
|
114
|
-
@c.receive.
|
114
|
+
expect(@c.receive).to eq([nil, false])
|
115
115
|
end
|
116
116
|
end
|
117
117
|
|
@@ -121,28 +121,28 @@ describe Agent::Channel do
|
|
121
121
|
end
|
122
122
|
|
123
123
|
it "should deadlock on single thread", :vm => :ruby do
|
124
|
-
|
124
|
+
expect { @c.receive }.to raise_error
|
125
125
|
end
|
126
126
|
|
127
127
|
it "should not deadlock with multiple threads" do
|
128
128
|
go!{ sleep(0.1); @c.push "hi" }
|
129
|
-
|
129
|
+
expect { @c.receive }.not_to raise_error
|
130
130
|
end
|
131
131
|
end
|
132
132
|
|
133
133
|
context "typed" do
|
134
134
|
it "should create a typed channel" do
|
135
|
-
|
135
|
+
expect { channel! }.to raise_error Agent::Errors::Untyped
|
136
136
|
c = nil
|
137
|
-
|
137
|
+
expect { c = channel!(Integer) }.not_to raise_error
|
138
138
|
c.close
|
139
139
|
end
|
140
140
|
|
141
141
|
it "should reject messages of invalid type" do
|
142
142
|
c = channel!(String)
|
143
143
|
go!{ c.receive }
|
144
|
-
|
145
|
-
|
144
|
+
expect { c.send 1 }.to raise_error(Agent::Errors::InvalidType)
|
145
|
+
expect { c.send "hello" }.not_to raise_error
|
146
146
|
c.close
|
147
147
|
end
|
148
148
|
end
|
@@ -158,9 +158,9 @@ describe Agent::Channel do
|
|
158
158
|
c = channel!(String)
|
159
159
|
|
160
160
|
go!{ sleep(0.15); c.send("hello") }
|
161
|
-
c.receive[0].
|
161
|
+
expect(c.receive[0]).to eq("hello")
|
162
162
|
|
163
|
-
(Time.now - n).
|
163
|
+
expect(Time.now - n).to be_within(0.05).of(0.15)
|
164
164
|
end
|
165
165
|
|
166
166
|
it "should support buffered" do
|
@@ -175,8 +175,8 @@ describe Agent::Channel do
|
|
175
175
|
s.timeout(0.1)
|
176
176
|
end
|
177
177
|
|
178
|
-
c.receive[0].
|
179
|
-
c.receive[0].
|
178
|
+
expect(c.receive[0]).to eq("hello 1")
|
179
|
+
expect(c.receive[0]).to eq("hello 2")
|
180
180
|
select! do |s|
|
181
181
|
s.case(c, :receive){|v| r.push(v) }
|
182
182
|
s.timeout(0.1)
|
@@ -201,15 +201,15 @@ describe Agent::Channel do
|
|
201
201
|
# - http://golang.org/doc/effective_go.html#chan_of_chan
|
202
202
|
|
203
203
|
it "should be a first class, serializable value" do
|
204
|
-
|
205
|
-
|
204
|
+
expect { Marshal.dump(@c) }.not_to raise_error
|
205
|
+
expect { Marshal.load(Marshal.dump(@c)).is_a?(Agent::Channel) }.not_to raise_error
|
206
206
|
end
|
207
207
|
|
208
208
|
it "should be able to pass as a value on a different channel" do
|
209
209
|
@c.send "hello"
|
210
210
|
|
211
211
|
cm = Marshal.load(Marshal.dump(@c))
|
212
|
-
cm.receive[0].
|
212
|
+
expect(cm.receive[0]).to eq("hello")
|
213
213
|
end
|
214
214
|
end
|
215
215
|
|
@@ -219,21 +219,21 @@ describe Agent::Channel do
|
|
219
219
|
string = "foo"
|
220
220
|
c.send(string)
|
221
221
|
string_copy = c.receive[0]
|
222
|
-
string_copy.
|
223
|
-
string_copy.object_id.
|
222
|
+
expect(string_copy).to eq(string)
|
223
|
+
expect(string_copy.object_id).not_to eq(string.object_id)
|
224
224
|
end
|
225
225
|
|
226
226
|
it "skips marshaling when configured to" do
|
227
227
|
c = channel!(String, 1, :skip_marshal => true)
|
228
228
|
string = "foo"
|
229
229
|
c.send(string)
|
230
|
-
c.receive[0].object_id.
|
230
|
+
expect(c.receive[0].object_id).to eq(string.object_id)
|
231
231
|
end
|
232
232
|
|
233
233
|
it "skips marshaling for channels by default" do
|
234
234
|
c = channel!(Agent::Channel, 1)
|
235
235
|
c.send(c)
|
236
|
-
c.receive[0].object_id.
|
236
|
+
expect(c.receive[0].object_id).to eq(c.object_id)
|
237
237
|
end
|
238
238
|
end
|
239
239
|
end
|
data/spec/error_spec.rb
CHANGED
@@ -6,10 +6,10 @@ describe Agent::Error do
|
|
6
6
|
end
|
7
7
|
|
8
8
|
it "should create an error" do
|
9
|
-
@error.to_s.
|
9
|
+
expect(@error.to_s).to eq("msg")
|
10
10
|
end
|
11
11
|
|
12
12
|
it "should match the error's message" do
|
13
|
-
@error.
|
13
|
+
expect(@error).to be_message("msg")
|
14
14
|
end
|
15
15
|
end
|
@@ -10,7 +10,7 @@ describe "Channel of Channels" do
|
|
10
10
|
res = Request.new(n, channel!(Integer))
|
11
11
|
|
12
12
|
reqs << res
|
13
|
-
res.resultChan.receive[0].
|
13
|
+
expect(res.resultChan.receive[0]).to eq(n+1)
|
14
14
|
res.resultChan.close
|
15
15
|
end
|
16
16
|
end
|
@@ -52,7 +52,7 @@ describe "Channel of Channels" do
|
|
52
52
|
res = Request.new(n, channel!(Integer))
|
53
53
|
|
54
54
|
reqs << res
|
55
|
-
res.resultChan.receive[0].
|
55
|
+
expect(res.resultChan.receive[0]).to eq(n+1)
|
56
56
|
res.resultChan.close
|
57
57
|
end
|
58
58
|
end
|
@@ -66,8 +66,8 @@ describe "Producer-Consumer" do
|
|
66
66
|
go!(c, 3, s, &consumer)
|
67
67
|
|
68
68
|
messages = [s.pop[0], s.pop[0]]
|
69
|
-
messages.
|
70
|
-
messages.
|
69
|
+
expect(messages).to include("producer finished")
|
70
|
+
expect(messages).to include("consumer finished")
|
71
71
|
|
72
72
|
c.close
|
73
73
|
s.close
|
@@ -85,9 +85,9 @@ describe "Producer-Consumer" do
|
|
85
85
|
|
86
86
|
go!(g, &producer)
|
87
87
|
|
88
|
-
c.receive[0].
|
89
|
-
c.receive[0].
|
90
|
-
c.receive[0].
|
88
|
+
expect(c.receive[0]).to eq(1)
|
89
|
+
expect(c.receive[0]).to eq(2)
|
90
|
+
expect(c.receive[0]).to eq(3)
|
91
91
|
c.close
|
92
92
|
end
|
93
93
|
end
|
data/spec/examples/sieve_spec.rb
CHANGED
@@ -69,7 +69,7 @@ describe "sieve of Eratosthenes" do
|
|
69
69
|
end
|
70
70
|
end
|
71
71
|
|
72
|
-
result.
|
72
|
+
expect(result).to eq([2,3,5,7,11,13,17,19])
|
73
73
|
channels.each(&:close)
|
74
74
|
end
|
75
75
|
|
@@ -143,7 +143,7 @@ describe "sieve of Eratosthenes" do
|
|
143
143
|
end
|
144
144
|
end
|
145
145
|
|
146
|
-
result.
|
146
|
+
expect(result).to eq([2,3,5,7,11,13,17,19])
|
147
147
|
channels.each(&:close)
|
148
148
|
end
|
149
149
|
end
|
data/spec/go_spec.rb
CHANGED
@@ -2,16 +2,16 @@ require "spec_helper"
|
|
2
2
|
|
3
3
|
describe "Agent.go!" do
|
4
4
|
it "should launch a 'goroutine' that is actually a thread" do
|
5
|
-
Agent.go!{}.
|
5
|
+
expect(Agent.go!{}).to be_a(Thread)
|
6
6
|
end
|
7
7
|
|
8
8
|
it "should pass into the thread any arguments passed to it" do
|
9
9
|
b = nil
|
10
10
|
Agent.go!(1){|a| b = a }.join
|
11
|
-
b.
|
11
|
+
expect(b).to eq(1)
|
12
12
|
end
|
13
13
|
|
14
14
|
it "should raise an error if no block is passed" do
|
15
|
-
|
15
|
+
expect{ Agent.go! }.to raise_error(Agent::Errors::BlockMissing)
|
16
16
|
end
|
17
17
|
end
|