mamiya 0.0.1.alpha19 → 0.0.1.alpha20
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +18 -0
- data/lib/mamiya/agent.rb +25 -30
- data/lib/mamiya/agent/actions.rb +9 -6
- data/lib/mamiya/agent/handlers/task.rb +13 -0
- data/lib/mamiya/agent/task_queue.rb +151 -0
- data/lib/mamiya/agent/tasks/abstract.rb +61 -0
- data/lib/mamiya/agent/tasks/clean.rb +44 -0
- data/lib/mamiya/agent/tasks/fetch.rb +60 -0
- data/lib/mamiya/agent/tasks/notifyable.rb +30 -0
- data/lib/mamiya/cli/client.rb +1 -1
- data/lib/mamiya/master.rb +4 -9
- data/lib/mamiya/master/agent_monitor_handlers.rb +42 -25
- data/lib/mamiya/master/web.rb +22 -7
- data/lib/mamiya/version.rb +1 -1
- data/mamiya.gemspec +1 -1
- data/spec/agent/actions_spec.rb +2 -8
- data/spec/agent/handlers/task_spec.rb +39 -0
- data/spec/agent/task_queue_spec.rb +246 -0
- data/spec/agent/tasks/abstract_spec.rb +58 -0
- data/spec/agent/tasks/clean_spec.rb +72 -0
- data/spec/agent/tasks/fetch_spec.rb +56 -0
- data/spec/agent/tasks/notifyable_spec.rb +37 -0
- data/spec/agent_spec.rb +33 -54
- data/spec/master/agent_monitor_spec.rb +155 -69
- data/spec/master/web_spec.rb +340 -1
- data/spec/master_spec.rb +0 -21
- metadata +22 -10
- data/lib/mamiya/agent/fetcher.rb +0 -165
- data/lib/mamiya/agent/handlers/fetch.rb +0 -78
- data/spec/agent/fetcher_spec.rb +0 -237
- data/spec/agent/handlers/fetch_spec.rb +0 -127
@@ -1,127 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
require 'json'
|
4
|
-
require 'villein/event'
|
5
|
-
|
6
|
-
require 'mamiya/agent/handlers/fetch'
|
7
|
-
|
8
|
-
describe Mamiya::Agent::Handlers::Fetch do
|
9
|
-
let(:event) do
|
10
|
-
Villein::Event.new(
|
11
|
-
{
|
12
|
-
'SERF_EVENT' => 'user',
|
13
|
-
'SERF_USER_EVENT' => 'mamiya:fetch',
|
14
|
-
},
|
15
|
-
payload: {
|
16
|
-
application: 'app',
|
17
|
-
package: 'package',
|
18
|
-
}.to_json,
|
19
|
-
)
|
20
|
-
end
|
21
|
-
|
22
|
-
let(:fetcher) { double('fetcher', start!: nil) }
|
23
|
-
let(:serf) { double('serf', name: 'myname', event: nil) }
|
24
|
-
|
25
|
-
let(:agent) do
|
26
|
-
double('agent', fetcher: fetcher, serf: serf, update_tags!: nil)
|
27
|
-
end
|
28
|
-
|
29
|
-
subject(:handler) { described_class.new(agent, event) }
|
30
|
-
|
31
|
-
before do
|
32
|
-
allow(fetcher).to receive(:queue_size).and_return(0)
|
33
|
-
allow(fetcher).to receive(:enqueue) do |&block|
|
34
|
-
block.call
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
it "enqueue a request" do
|
39
|
-
expect(fetcher).to receive(:enqueue).with('app', 'package', kind_of(Hash))
|
40
|
-
|
41
|
-
handler.run!
|
42
|
-
end
|
43
|
-
|
44
|
-
it "responds ack" do
|
45
|
-
allow(fetcher).to receive(:enqueue).with('app', 'package')
|
46
|
-
expect(serf).to receive(:event).with('mamiya:fetch-result:ack',
|
47
|
-
{name: serf.name, application: 'app', package: 'package', pending: 1}.to_json,
|
48
|
-
coalesce: false,
|
49
|
-
)
|
50
|
-
|
51
|
-
handler.run!
|
52
|
-
end
|
53
|
-
|
54
|
-
it "kicks update_tag! on start" do
|
55
|
-
allow(fetcher).to receive(:enqueue) do |app, package, options, &block|
|
56
|
-
options[:before].call
|
57
|
-
end
|
58
|
-
expect(agent).to receive(:update_tags!)
|
59
|
-
handler.run!
|
60
|
-
end
|
61
|
-
|
62
|
-
it "reports start" do
|
63
|
-
allow(fetcher).to receive(:enqueue) do |app, package, options, &block|
|
64
|
-
options[:before].call
|
65
|
-
end
|
66
|
-
expect(serf).to receive(:event).with('mamiya:fetch-result:start',
|
67
|
-
{name: serf.name, application: 'app', package: 'package', pending: 1}.to_json,
|
68
|
-
coalesce: false
|
69
|
-
)
|
70
|
-
|
71
|
-
handler.run!
|
72
|
-
end
|
73
|
-
|
74
|
-
it "responds success" do
|
75
|
-
callback = nil
|
76
|
-
allow(fetcher).to receive(:enqueue).with('app', 'package', kind_of(Hash)) do |&block|
|
77
|
-
callback = block
|
78
|
-
end
|
79
|
-
|
80
|
-
handler.run!
|
81
|
-
|
82
|
-
expect(serf).to receive(:event).with(
|
83
|
-
'mamiya:fetch-result:success',
|
84
|
-
{name: serf.name, application: 'app', package: 'package', pending: 0}.to_json,
|
85
|
-
coalesce: false
|
86
|
-
)
|
87
|
-
|
88
|
-
callback.call
|
89
|
-
end
|
90
|
-
|
91
|
-
it "updates tag" do
|
92
|
-
expect(agent).to receive(:update_tags!)
|
93
|
-
handler.run!
|
94
|
-
end
|
95
|
-
|
96
|
-
context "when failed" do
|
97
|
-
it "notifies error" do
|
98
|
-
callback = nil
|
99
|
-
allow(fetcher).to receive(:enqueue).with('app', 'package', kind_of(Hash)) do |&block|
|
100
|
-
callback = block
|
101
|
-
end
|
102
|
-
|
103
|
-
handler.run!
|
104
|
-
|
105
|
-
error = RuntimeError.new('test')
|
106
|
-
expect(serf).to receive(:event).with(
|
107
|
-
'mamiya:fetch-result:error',
|
108
|
-
{
|
109
|
-
name: serf.name, application: 'app', package: 'package',
|
110
|
-
error: error.class, pending: 0,
|
111
|
-
}.to_json,
|
112
|
-
coalesce: false,
|
113
|
-
)
|
114
|
-
|
115
|
-
callback.call(error)
|
116
|
-
end
|
117
|
-
|
118
|
-
it "updates tag" do
|
119
|
-
allow(fetcher).to receive(:enqueue) do |&block|
|
120
|
-
block.call(Exception.new)
|
121
|
-
end
|
122
|
-
|
123
|
-
expect(agent).to receive(:update_tags!)
|
124
|
-
handler.run!
|
125
|
-
end
|
126
|
-
end
|
127
|
-
end
|