frenzy_bunnies 0.0.7 → 0.0.8

Sign up to get free protection for your applications and to get access to all the features.
data/Guardfile CHANGED
@@ -1 +1,19 @@
1
+ guard 'minitest' do
2
+
3
+ # with Minitest::Spec
4
+ watch(%r|^spec/(.*)_spec\.rb|)
5
+ watch(%r|^lib/(.*)([^/]+)\.rb|) { |m| "spec/#{m[1]}#{m[2]}_spec.rb" }
6
+ watch(%r|^spec/spec_helper\.rb|) { "spec" }
7
+
8
+ # Rails 3.2
9
+ # watch(%r|^app/controllers/(.*)\.rb|) { |m| "test/controllers/#{m[1]}_test.rb" }
10
+ # watch(%r|^app/helpers/(.*)\.rb|) { |m| "test/helpers/#{m[1]}_test.rb" }
11
+ # watch(%r|^app/models/(.*)\.rb|) { |m| "test/unit/#{m[1]}_test.rb" }
12
+
13
+ # Rails
14
+ # watch(%r|^app/controllers/(.*)\.rb|) { |m| "test/functional/#{m[1]}_test.rb" }
15
+ # watch(%r|^app/helpers/(.*)\.rb|) { |m| "test/helpers/#{m[1]}_test.rb" }
16
+ # watch(%r|^app/models/(.*)\.rb|) { |m| "test/unit/#{m[1]}_test.rb" }
17
+ end
18
+
1
19
  guard 'coffeescript', :input => 'lib/frenzy_bunnies/web/public/js', :output => 'lib/frenzy_bunnies/web/public/js', :all_on_start => true
@@ -22,4 +22,6 @@ Gem::Specification.new do |gem|
22
22
  gem.add_runtime_dependency 'json'
23
23
 
24
24
  gem.add_development_dependency 'guard-coffeescript'
25
+ gem.add_development_dependency 'rr'
26
+ gem.add_development_dependency 'guard-minitest'
25
27
  end
@@ -1,5 +1,5 @@
1
1
  require 'hot_bunnies'
2
-
2
+ require 'timeout'
3
3
 
4
4
  module FrenzyBunnies
5
5
  end
@@ -2,7 +2,7 @@ require 'logger'
2
2
  require 'frenzy_bunnies/web'
3
3
 
4
4
  class FrenzyBunnies::Context
5
- attr_reader :queue_factory, :logger, :env
5
+ attr_reader :queue_factory, :logger, :env, :opts
6
6
 
7
7
  def initialize(opts={})
8
8
  @opts = opts
@@ -1,3 +1,3 @@
1
1
  module FrenzyBunnies
2
- VERSION = "0.0.7"
2
+ VERSION = "0.0.8"
3
3
  end
@@ -53,7 +53,6 @@ module FrenzyBunnies::Worker
53
53
  if(wkr.work(msg))
54
54
  h.ack
55
55
  incr! :passed
56
- @jobs_stats[:passed].update { |v| v + 1 }
57
56
  else
58
57
  h.reject
59
58
  incr! :failed
@@ -82,6 +81,10 @@ module FrenzyBunnies::Worker
82
81
  say "stopped"
83
82
  end
84
83
 
84
+ def queue_opts
85
+ @queue_opts
86
+ end
87
+
85
88
  def jobs_stats
86
89
  Hash[ @jobs_stats.map{ |k,v| [k, v.value] } ].merge({ :since => @working_since.to_i })
87
90
  end
@@ -0,0 +1,117 @@
1
+ require 'spec_helper'
2
+ require 'frenzy_bunnies'
3
+
4
+ class DummyWorker
5
+ include FrenzyBunnies::Worker
6
+ from_queue 'new.feeds'
7
+
8
+ def work(msg)
9
+ end
10
+ end
11
+
12
+ class CustomWorker
13
+ include FrenzyBunnies::Worker
14
+ from_queue 'new.feeds', :prefetch => 20, :durable => true, :timeout_job_after => 13, :threads => 25
15
+
16
+ def work(msg)
17
+ end
18
+ end
19
+
20
+ def with_test_queuefactory(ctx, ack=true, msg=nil, nowork=false)
21
+ qf = Object.new
22
+ q = Object.new
23
+ s = Object.new
24
+ hdr = Object.new
25
+ mock(qf).build_queue(anything, anything, anything) { q }
26
+ mock(q).subscribe(anything){ s }
27
+
28
+ mock(s).each(anything) { |h,b| b.call(hdr, msg) unless nowork }
29
+ mock(hdr).ack{true} if !nowork && ack
30
+ mock(hdr).reject{true} if !nowork && !ack
31
+
32
+ mock(ctx).queue_factory { qf } # should return our own
33
+ end
34
+
35
+ describe FrenzyBunnies::Worker do
36
+ it "should start with a clean slate" do
37
+ # check stats, default configuration
38
+ ctx = FrenzyBunnies::Context.new(:logger=> Logger.new(nil))
39
+ with_test_queuefactory(ctx, nil, nil, true)
40
+
41
+
42
+ DummyWorker.start(ctx)
43
+ DummyWorker.jobs_stats[:failed].must_equal 0
44
+ DummyWorker.jobs_stats[:passed].must_equal 0
45
+ q = DummyWorker.queue_opts
46
+ q.must_equal({:prefetch=>10, :durable=>false, :timeout_job_after=>5})
47
+
48
+ end
49
+ it "should respond to configuration tweaks" do
50
+ # check that all params are changed
51
+ ctx = FrenzyBunnies::Context.new(:logger=> Logger.new(nil))
52
+ with_test_queuefactory(ctx, nil, nil, true)
53
+
54
+ CustomWorker.start(ctx)
55
+ CustomWorker.jobs_stats[:failed].must_equal 0
56
+ CustomWorker.jobs_stats[:passed].must_equal 0
57
+ q = CustomWorker.queue_opts
58
+ q.must_equal({:prefetch=>20, :durable=>true, :timeout_job_after=>13, :threads=>25})
59
+ end
60
+ it "should stop when asked to" do
61
+ # validate that a worker stops
62
+ # check stats, default configuration
63
+ ctx = FrenzyBunnies::Context.new(:logger=> Logger.new(nil))
64
+ with_test_queuefactory(ctx, nil, nil, true)
65
+
66
+
67
+ DummyWorker.start(ctx)
68
+ DummyWorker.stop
69
+ end
70
+ it "should be passed a message to work on" do
71
+ ctx = FrenzyBunnies::Context.new(:logger=> Logger.new(nil))
72
+ with_test_queuefactory(ctx, true, "work!")
73
+
74
+ any_instance_of(DummyWorker){ |w| mock(w).work("work!"){ true } }
75
+ DummyWorker.start(ctx)
76
+ end
77
+ it "should acknowledge a unit of work when worker succeeds" do
78
+ ctx = FrenzyBunnies::Context.new(:logger=> Logger.new(nil))
79
+ with_test_queuefactory(ctx)
80
+
81
+ any_instance_of(DummyWorker){ |w| mock(w).work(anything){ true } }
82
+ DummyWorker.start(ctx)
83
+ DummyWorker.jobs_stats[:passed].must_equal 1
84
+ DummyWorker.jobs_stats[:failed].must_equal 0
85
+ end
86
+ it "should reject a unit of work when worker fails" do
87
+ ctx = FrenzyBunnies::Context.new(:logger=> Logger.new(nil))
88
+ with_test_queuefactory(ctx,false)
89
+
90
+ any_instance_of(DummyWorker){ |w| mock(w).work(anything){ false } }
91
+ mock(DummyWorker).error(anything, anything){ |text, _| text.must_match(/^REJECTED/) }
92
+ DummyWorker.start(ctx)
93
+ DummyWorker.jobs_stats[:failed].must_equal 1
94
+ DummyWorker.jobs_stats[:passed].must_equal 0
95
+ end
96
+ it "should reject a unit of work when worker times out" do
97
+ ctx = FrenzyBunnies::Context.new(:logger=> Logger.new(nil))
98
+ with_test_queuefactory(ctx,false)
99
+ DummyWorker.queue_opts[:timeout_job_after] = 1
100
+ any_instance_of(DummyWorker){ |w| mock(w).work(anything){ sleep(2) }}
101
+ mock(DummyWorker).error(anything, anything){ |text, _| text.must_match(/^TIMEOUT/) }
102
+ DummyWorker.start(ctx)
103
+ DummyWorker.jobs_stats[:failed].must_equal 1
104
+ DummyWorker.jobs_stats[:passed].must_equal 0
105
+ DummyWorker.queue_opts[:timeout_job_after] = 5
106
+ end
107
+ it "should reject a unit of work when worker fails exceptionally" do
108
+ ctx = FrenzyBunnies::Context.new(:logger=> Logger.new(nil))
109
+ with_test_queuefactory(ctx,false)
110
+
111
+ any_instance_of(DummyWorker){ |w| mock(w).work(anything){ throw :error } }
112
+ mock(DummyWorker).error(anything, anything){ |text, _| text.must_match(/^ERROR/) }
113
+ DummyWorker.start(ctx)
114
+ DummyWorker.jobs_stats[:failed].must_equal 1
115
+ DummyWorker.jobs_stats[:passed].must_equal 0
116
+ end
117
+ end
@@ -0,0 +1,35 @@
1
+ #require 'simplecov'
2
+ #SimpleCov.start if ENV["COVERAGE"]
3
+
4
+ require 'minitest/autorun'
5
+
6
+
7
+
8
+ require 'rr'
9
+
10
+
11
+ class MiniTest::Unit::TestCase
12
+ include RR::Adapters::MiniTest
13
+ end
14
+
15
+
16
+ require 'thor'
17
+ # This is to silence the 'task' warning for the mocks.
18
+ #
19
+ class Thor
20
+ class << self
21
+ def create_task(meth) #:nodoc:
22
+ if @usage && @desc
23
+ base_class = @hide ? Thor::HiddenTask : Thor::Task
24
+ tasks[meth] = base_class.new(meth, @desc, @long_desc, @usage, method_options)
25
+ @usage, @desc, @long_desc, @method_options, @hide = nil
26
+ true
27
+ elsif self.all_tasks[meth] || meth == "method_missing"
28
+ true
29
+ else
30
+ false
31
+ end
32
+ end
33
+ end
34
+ end
35
+
metadata CHANGED
@@ -1,154 +1,174 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: frenzy_bunnies
3
- version: !ruby/object:Gem::Version
4
- prerelease:
5
- version: 0.0.7
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.0.8
6
6
  platform: ruby
7
- authors:
8
- - Dotan Nahum
9
- autorequire:
7
+ authors:
8
+ - Dotan Nahum
9
+ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
-
13
- date: 2012-09-15 00:00:00 Z
14
- dependencies:
15
- - !ruby/object:Gem::Dependency
16
- name: hot_bunnies
17
- prerelease: false
18
- requirement: &id001 !ruby/object:Gem::Requirement
19
- none: false
20
- requirements:
21
- - - ">="
22
- - !ruby/object:Gem::Version
23
- version: 1.4.0.pre3
24
- type: :runtime
25
- version_requirements: *id001
26
- - !ruby/object:Gem::Dependency
27
- name: thor
28
- prerelease: false
29
- requirement: &id002 !ruby/object:Gem::Requirement
30
- none: false
31
- requirements:
32
- - - ">="
33
- - !ruby/object:Gem::Version
34
- version: "0"
35
- type: :runtime
36
- version_requirements: *id002
37
- - !ruby/object:Gem::Dependency
38
- name: sinatra
39
- prerelease: false
40
- requirement: &id003 !ruby/object:Gem::Requirement
41
- none: false
42
- requirements:
43
- - - ">="
44
- - !ruby/object:Gem::Version
45
- version: "0"
46
- type: :runtime
47
- version_requirements: *id003
48
- - !ruby/object:Gem::Dependency
49
- name: atomic
50
- prerelease: false
51
- requirement: &id004 !ruby/object:Gem::Requirement
52
- none: false
53
- requirements:
54
- - - ">="
55
- - !ruby/object:Gem::Version
56
- version: "0"
57
- type: :runtime
58
- version_requirements: *id004
59
- - !ruby/object:Gem::Dependency
60
- name: json
61
- prerelease: false
62
- requirement: &id005 !ruby/object:Gem::Requirement
63
- none: false
64
- requirements:
65
- - - ">="
66
- - !ruby/object:Gem::Version
67
- version: "0"
68
- type: :runtime
69
- version_requirements: *id005
70
- - !ruby/object:Gem::Dependency
71
- name: guard-coffeescript
72
- prerelease: false
73
- requirement: &id006 !ruby/object:Gem::Requirement
74
- none: false
75
- requirements:
76
- - - ">="
77
- - !ruby/object:Gem::Version
78
- version: "0"
79
- type: :development
80
- version_requirements: *id006
12
+ date: 2012-09-16 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: hot_bunnies
16
+ version_requirements: &2056 !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - ! '>='
19
+ - !ruby/object:Gem::Version
20
+ version: 1.4.0.pre3
21
+ none: false
22
+ requirement: *2056
23
+ prerelease: false
24
+ type: :runtime
25
+ - !ruby/object:Gem::Dependency
26
+ name: thor
27
+ version_requirements: &2074 !ruby/object:Gem::Requirement
28
+ requirements:
29
+ - - ! '>='
30
+ - !ruby/object:Gem::Version
31
+ version: '0'
32
+ none: false
33
+ requirement: *2074
34
+ prerelease: false
35
+ type: :runtime
36
+ - !ruby/object:Gem::Dependency
37
+ name: sinatra
38
+ version_requirements: &2090 !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - ! '>='
41
+ - !ruby/object:Gem::Version
42
+ version: '0'
43
+ none: false
44
+ requirement: *2090
45
+ prerelease: false
46
+ type: :runtime
47
+ - !ruby/object:Gem::Dependency
48
+ name: atomic
49
+ version_requirements: &2106 !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ none: false
55
+ requirement: *2106
56
+ prerelease: false
57
+ type: :runtime
58
+ - !ruby/object:Gem::Dependency
59
+ name: json
60
+ version_requirements: &2122 !ruby/object:Gem::Requirement
61
+ requirements:
62
+ - - ! '>='
63
+ - !ruby/object:Gem::Version
64
+ version: '0'
65
+ none: false
66
+ requirement: *2122
67
+ prerelease: false
68
+ type: :runtime
69
+ - !ruby/object:Gem::Dependency
70
+ name: guard-coffeescript
71
+ version_requirements: &2138 !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ! '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ none: false
77
+ requirement: *2138
78
+ prerelease: false
79
+ type: :development
80
+ - !ruby/object:Gem::Dependency
81
+ name: rr
82
+ version_requirements: &2156 !ruby/object:Gem::Requirement
83
+ requirements:
84
+ - - ! '>='
85
+ - !ruby/object:Gem::Version
86
+ version: '0'
87
+ none: false
88
+ requirement: *2156
89
+ prerelease: false
90
+ type: :development
91
+ - !ruby/object:Gem::Dependency
92
+ name: guard-minitest
93
+ version_requirements: &2172 !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - ! '>='
96
+ - !ruby/object:Gem::Version
97
+ version: '0'
98
+ none: false
99
+ requirement: *2172
100
+ prerelease: false
101
+ type: :development
81
102
  description: RabbitMQ JRuby based workers on top of hot_bunnies
82
- email:
83
- - jondotan@gmail.com
84
- executables:
85
- - frenzy_bunnies
103
+ email:
104
+ - jondotan@gmail.com
105
+ executables:
106
+ - frenzy_bunnies
86
107
  extensions: []
87
-
88
108
  extra_rdoc_files: []
89
-
90
- files:
91
- - .gitignore
92
- - Gemfile
93
- - Guardfile
94
- - LICENSE
95
- - README.md
96
- - Rakefile
97
- - bin/frenzy_bunnies
98
- - examples/feed.rb
99
- - examples/feed_worker.rb
100
- - examples/feed_workers_bin.rb
101
- - fb-cap.png
102
- - frenzy_bunnies.gemspec
103
- - lib/frenzy_bunnies.rb
104
- - lib/frenzy_bunnies/cli.rb
105
- - lib/frenzy_bunnies/context.rb
106
- - lib/frenzy_bunnies/health.rb
107
- - lib/frenzy_bunnies/health/collector.rb
108
- - lib/frenzy_bunnies/health/providers/jvm.rb
109
- - lib/frenzy_bunnies/queue_factory.rb
110
- - lib/frenzy_bunnies/version.rb
111
- - lib/frenzy_bunnies/web.rb
112
- - lib/frenzy_bunnies/web/public/css/bootstrap.min.css
113
- - lib/frenzy_bunnies/web/public/img/bunny16.png
114
- - lib/frenzy_bunnies/web/public/img/bunny32.png
115
- - lib/frenzy_bunnies/web/public/index.html
116
- - lib/frenzy_bunnies/web/public/js/app.coffee
117
- - lib/frenzy_bunnies/web/public/js/app.js
118
- - lib/frenzy_bunnies/web/public/js/backbone-min.js
119
- - lib/frenzy_bunnies/web/public/js/bootstrap.js
120
- - lib/frenzy_bunnies/web/public/js/bootstrap.min.js
121
- - lib/frenzy_bunnies/web/public/js/jquery-1.8.0.min.js
122
- - lib/frenzy_bunnies/web/public/js/jquery.filesize.js
123
- - lib/frenzy_bunnies/web/public/js/jquery.timeago.js
124
- - lib/frenzy_bunnies/web/public/js/underscore-min.js
125
- - lib/frenzy_bunnies/worker.rb
126
- homepage: ""
109
+ files:
110
+ - .gitignore
111
+ - Gemfile
112
+ - Guardfile
113
+ - LICENSE
114
+ - README.md
115
+ - Rakefile
116
+ - bin/frenzy_bunnies
117
+ - examples/feed.rb
118
+ - examples/feed_worker.rb
119
+ - examples/feed_workers_bin.rb
120
+ - fb-cap.png
121
+ - frenzy_bunnies.gemspec
122
+ - lib/frenzy_bunnies.rb
123
+ - lib/frenzy_bunnies/cli.rb
124
+ - lib/frenzy_bunnies/context.rb
125
+ - lib/frenzy_bunnies/health.rb
126
+ - lib/frenzy_bunnies/health/collector.rb
127
+ - lib/frenzy_bunnies/health/providers/jvm.rb
128
+ - lib/frenzy_bunnies/queue_factory.rb
129
+ - lib/frenzy_bunnies/version.rb
130
+ - lib/frenzy_bunnies/web.rb
131
+ - lib/frenzy_bunnies/web/public/css/bootstrap.min.css
132
+ - lib/frenzy_bunnies/web/public/img/bunny16.png
133
+ - lib/frenzy_bunnies/web/public/img/bunny32.png
134
+ - lib/frenzy_bunnies/web/public/index.html
135
+ - lib/frenzy_bunnies/web/public/js/app.coffee
136
+ - lib/frenzy_bunnies/web/public/js/app.js
137
+ - lib/frenzy_bunnies/web/public/js/backbone-min.js
138
+ - lib/frenzy_bunnies/web/public/js/bootstrap.js
139
+ - lib/frenzy_bunnies/web/public/js/bootstrap.min.js
140
+ - lib/frenzy_bunnies/web/public/js/jquery-1.8.0.min.js
141
+ - lib/frenzy_bunnies/web/public/js/jquery.filesize.js
142
+ - lib/frenzy_bunnies/web/public/js/jquery.timeago.js
143
+ - lib/frenzy_bunnies/web/public/js/underscore-min.js
144
+ - lib/frenzy_bunnies/worker.rb
145
+ - spec/frenzy_bunnies/worker_spec.rb
146
+ - spec/spec_helper.rb
147
+ homepage: ''
127
148
  licenses: []
128
-
129
- post_install_message:
149
+ post_install_message:
130
150
  rdoc_options: []
131
-
132
- require_paths:
133
- - lib
134
- required_ruby_version: !ruby/object:Gem::Requirement
151
+ require_paths:
152
+ - lib
153
+ required_ruby_version: !ruby/object:Gem::Requirement
154
+ requirements:
155
+ - - ! '>='
156
+ - !ruby/object:Gem::Version
157
+ version: '0'
135
158
  none: false
136
- requirements:
137
- - - ">="
138
- - !ruby/object:Gem::Version
139
- version: "0"
140
- required_rubygems_version: !ruby/object:Gem::Requirement
159
+ required_rubygems_version: !ruby/object:Gem::Requirement
160
+ requirements:
161
+ - - ! '>='
162
+ - !ruby/object:Gem::Version
163
+ version: '0'
141
164
  none: false
142
- requirements:
143
- - - ">="
144
- - !ruby/object:Gem::Version
145
- version: "0"
146
165
  requirements: []
147
-
148
- rubyforge_project:
166
+ rubyforge_project:
149
167
  rubygems_version: 1.8.15
150
- signing_key:
168
+ signing_key:
151
169
  specification_version: 3
152
170
  summary: RabbitMQ JRuby based workers on top of hot_bunnies
153
- test_files: []
154
-
171
+ test_files:
172
+ - spec/frenzy_bunnies/worker_spec.rb
173
+ - spec/spec_helper.rb
174
+ ...