bunnish 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +49 -1
- data/VERSION +1 -1
- data/bin/bunnish +14 -5
- data/bunnish.gemspec +84 -0
- data/lib/bunnish/{count.rb → command/count.rb} +1 -4
- data/lib/bunnish/command/delete.rb +58 -0
- data/lib/bunnish/{help.rb → command/help.rb} +3 -1
- data/lib/bunnish/{publish.rb → command/publish.rb} +4 -5
- data/lib/bunnish/{status.rb → command/status.rb} +5 -10
- data/lib/bunnish/{subscribe.rb → command/subscribe.rb} +4 -3
- data/lib/bunnish/command.rb +6 -0
- data/lib/bunnish.rb +6 -10
- data/spec/bin/bunnish_spec.rb +75 -0
- data/spec/lib/bunnish/command/count_spec.rb +11 -0
- data/spec/lib/bunnish/command/delete_spec.rb +11 -0
- data/spec/lib/bunnish/command/help_spec.rb +12 -0
- data/spec/lib/bunnish/command/publish_spec.rb +11 -0
- data/spec/lib/bunnish/command/status_spec.rb +11 -0
- data/spec/lib/bunnish/command/subscribe_spec.rb +11 -0
- data/spec/lib/bunnish_spec.rb +70 -0
- data/spec/spec_helper.rb +11 -2
- metadata +35 -25
- data/spec/bunnish_spec.rb +0 -4
data/README.rdoc
CHANGED
@@ -1,6 +1,54 @@
|
|
1
1
|
= bunnish
|
2
2
|
|
3
|
-
|
3
|
+
'bunnish' is a command for AMQP access to message queue.
|
4
|
+
|
5
|
+
== Supported Ruby versions and implementations
|
6
|
+
bunnish should work identically on:
|
7
|
+
|
8
|
+
* Ruby 1.9.3+
|
9
|
+
* Ruby 1.9.2+
|
10
|
+
* Ruby 1.8.7+
|
11
|
+
|
12
|
+
== Install
|
13
|
+
|
14
|
+
You can install bunnish by gem.
|
15
|
+
gem install bunnish
|
16
|
+
|
17
|
+
== Usage
|
18
|
+
|
19
|
+
Publish messages:
|
20
|
+
$ cat messages.txt
|
21
|
+
foo
|
22
|
+
bar
|
23
|
+
baz
|
24
|
+
$ cat messages.txt | bunnish publish -h mq-server -p 5672 test-queue
|
25
|
+
[2012-12-08 20:33:33](INFO) create direct exchange 'test-queue'
|
26
|
+
[2012-12-08 20:33:33](INFO) create queue 'test-queue'
|
27
|
+
[2012-12-08 20:33:33](INFO) bind queue 'test-queue' to direct exchange 'test-queue'
|
28
|
+
[2012-12-08 20:33:33](INFO) publish to test-queue(0 messages, 0 consumers)
|
29
|
+
[2012-12-08 20:33:33](INFO) published 3 messages into test-queue(3 messages, 0 consumers)
|
30
|
+
|
31
|
+
Check queue status:
|
32
|
+
$ bunnish status -h mq-server -p 5672 test-queue
|
33
|
+
test-queue : 3 messages, 0 consumers
|
34
|
+
|
35
|
+
Get queue count:
|
36
|
+
$ bunnish count -h mq-server -p 5672 test-queue
|
37
|
+
3
|
38
|
+
|
39
|
+
Subscribe from queue:
|
40
|
+
$ bunnish subscribe -h mq-server -p 5672 test-queue
|
41
|
+
[2012-12-08 20:35:57](INFO) subscribe from test-queue(3 messages, 0 consumers)
|
42
|
+
foo
|
43
|
+
bar
|
44
|
+
baz
|
45
|
+
[2012-12-08 20:35:58](INFO) subscribed 3 messages from test-queue(0 messages, 0 consumers)
|
46
|
+
$ bunnish status -h mq-server -p 5672 test-queue
|
47
|
+
1 queue is empty:
|
48
|
+
test-queue
|
49
|
+
|
50
|
+
Read help:
|
51
|
+
$ bunnish help
|
4
52
|
|
5
53
|
== Contributing to bunnish
|
6
54
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.2
|
data/bin/bunnish
CHANGED
@@ -4,15 +4,24 @@ require "bunnish"
|
|
4
4
|
|
5
5
|
command = ARGV.shift
|
6
6
|
|
7
|
+
exit_code = 0
|
8
|
+
|
7
9
|
case command
|
8
10
|
when "count"
|
9
|
-
Bunnish::Count.run(ARGV)
|
11
|
+
exit_code = Bunnish::Command::Count.run(ARGV) || 0
|
12
|
+
when "delete"
|
13
|
+
exit_code = Bunnish::Command::Delete.run(ARGV) || 0
|
10
14
|
when "help"
|
11
|
-
Bunnish::Help.run(ARGV)
|
15
|
+
exit_code = Bunnish::Command::Help.run(ARGV) || 0
|
12
16
|
when "publish"
|
13
|
-
Bunnish::Publish.run(ARGV)
|
17
|
+
exit_code = Bunnish::Command::Publish.run(ARGV) || 0
|
14
18
|
when "status"
|
15
|
-
Bunnish::Status.run(ARGV)
|
19
|
+
exit_code = Bunnish::Command::Status.run(ARGV) || 0
|
16
20
|
when "subscribe"
|
17
|
-
Bunnish::Subscribe.run(ARGV)
|
21
|
+
exit_code = Bunnish::Command::Subscribe.run(ARGV) || 0
|
22
|
+
else
|
23
|
+
STDERR.puts "invalid command: '#{command}'"
|
24
|
+
exit_code = 1
|
18
25
|
end
|
26
|
+
|
27
|
+
exit exit_code
|
data/bunnish.gemspec
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = "bunnish"
|
8
|
+
s.version = "0.0.2"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Kenji Hara"]
|
12
|
+
s.date = "2012-12-08"
|
13
|
+
s.description = "Command for AMQP access to Message Queue."
|
14
|
+
s.email = "haracane@gmail.com"
|
15
|
+
s.executables = ["bunnish"]
|
16
|
+
s.extra_rdoc_files = [
|
17
|
+
"LICENSE.txt",
|
18
|
+
"README.rdoc"
|
19
|
+
]
|
20
|
+
s.files = [
|
21
|
+
".document",
|
22
|
+
".rspec",
|
23
|
+
"Gemfile",
|
24
|
+
"LICENSE.txt",
|
25
|
+
"README.rdoc",
|
26
|
+
"Rakefile",
|
27
|
+
"VERSION",
|
28
|
+
"bin/bunnish",
|
29
|
+
"bunnish.gemspec",
|
30
|
+
"lib/bunnish.rb",
|
31
|
+
"lib/bunnish/command.rb",
|
32
|
+
"lib/bunnish/command/count.rb",
|
33
|
+
"lib/bunnish/command/delete.rb",
|
34
|
+
"lib/bunnish/command/help.rb",
|
35
|
+
"lib/bunnish/command/publish.rb",
|
36
|
+
"lib/bunnish/command/status.rb",
|
37
|
+
"lib/bunnish/command/subscribe.rb",
|
38
|
+
"spec/bin/bunnish_spec.rb",
|
39
|
+
"spec/lib/bunnish/command/count_spec.rb",
|
40
|
+
"spec/lib/bunnish/command/delete_spec.rb",
|
41
|
+
"spec/lib/bunnish/command/help_spec.rb",
|
42
|
+
"spec/lib/bunnish/command/publish_spec.rb",
|
43
|
+
"spec/lib/bunnish/command/status_spec.rb",
|
44
|
+
"spec/lib/bunnish/command/subscribe_spec.rb",
|
45
|
+
"spec/lib/bunnish_spec.rb",
|
46
|
+
"spec/spec_helper.rb"
|
47
|
+
]
|
48
|
+
s.homepage = "http://github.com/haracane/bunnish"
|
49
|
+
s.licenses = ["MIT"]
|
50
|
+
s.require_paths = ["lib"]
|
51
|
+
s.rubygems_version = "1.8.17"
|
52
|
+
s.summary = "Command for AMQP access to Message Queue."
|
53
|
+
|
54
|
+
if s.respond_to? :specification_version then
|
55
|
+
s.specification_version = 3
|
56
|
+
|
57
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
58
|
+
s.add_runtime_dependency(%q<json>, [">= 0"])
|
59
|
+
s.add_runtime_dependency(%q<bunny>, [">= 0"])
|
60
|
+
s.add_development_dependency(%q<rspec>, ["~> 2.8.0"])
|
61
|
+
s.add_development_dependency(%q<rdoc>, ["~> 3.12"])
|
62
|
+
s.add_development_dependency(%q<bundler>, [">= 0"])
|
63
|
+
s.add_development_dependency(%q<jeweler>, ["~> 1.8.4"])
|
64
|
+
s.add_development_dependency(%q<rcov>, [">= 0"])
|
65
|
+
else
|
66
|
+
s.add_dependency(%q<json>, [">= 0"])
|
67
|
+
s.add_dependency(%q<bunny>, [">= 0"])
|
68
|
+
s.add_dependency(%q<rspec>, ["~> 2.8.0"])
|
69
|
+
s.add_dependency(%q<rdoc>, ["~> 3.12"])
|
70
|
+
s.add_dependency(%q<bundler>, [">= 0"])
|
71
|
+
s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
|
72
|
+
s.add_dependency(%q<rcov>, [">= 0"])
|
73
|
+
end
|
74
|
+
else
|
75
|
+
s.add_dependency(%q<json>, [">= 0"])
|
76
|
+
s.add_dependency(%q<bunny>, [">= 0"])
|
77
|
+
s.add_dependency(%q<rspec>, ["~> 2.8.0"])
|
78
|
+
s.add_dependency(%q<rdoc>, ["~> 3.12"])
|
79
|
+
s.add_dependency(%q<bundler>, [">= 0"])
|
80
|
+
s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
|
81
|
+
s.add_dependency(%q<rcov>, [">= 0"])
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
@@ -1,9 +1,6 @@
|
|
1
|
-
module Bunnish
|
1
|
+
module Bunnish::Command
|
2
2
|
module Count
|
3
3
|
def self.run(argv, input_stream=$stdin, output_stream=$stdout, error_stream=$stderr)
|
4
|
-
input_stream ||= $stdin
|
5
|
-
output_stream ||= $stdout
|
6
|
-
error_stream ||= $stderr
|
7
4
|
|
8
5
|
params = Bunnish.parse_opts(argv)
|
9
6
|
|
@@ -0,0 +1,58 @@
|
|
1
|
+
module Bunnish::Command
|
2
|
+
module Delete
|
3
|
+
def self.fetch_queue_name(queue_name_list, input_stream)
|
4
|
+
return queue_name_list.shift if queue_name_list
|
5
|
+
line = input_stream.gets
|
6
|
+
return line.chomp if line
|
7
|
+
return nil
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.run(argv, input_stream=$stdin, output_stream=$stdout, error_stream=$stderr)
|
11
|
+
|
12
|
+
params = Bunnish.parse_opts(argv)
|
13
|
+
|
14
|
+
host = params[:host]
|
15
|
+
port = params[:port]
|
16
|
+
user = params[:user]
|
17
|
+
password = params[:password]
|
18
|
+
durable = params[:durable]
|
19
|
+
|
20
|
+
STDERR.puts argv
|
21
|
+
queue_name_list = argv.shift
|
22
|
+
|
23
|
+
queue_name_list = queue_name_list.split(/[, \r\n]+/) if queue_name_list
|
24
|
+
|
25
|
+
bunny = Bunny.new(:logging => false, :spec => '09', :host=>host, :port=>port, :user=>user, :pass=>password)
|
26
|
+
|
27
|
+
# start a communication session with the amqp server
|
28
|
+
bunny.start
|
29
|
+
|
30
|
+
exit_code = 0
|
31
|
+
|
32
|
+
while queue_name = self.fetch_queue_name(queue_name_list, input_stream)
|
33
|
+
# create/get queue
|
34
|
+
# queue = bunny.queues[queue_name]
|
35
|
+
queue = bunny.queue(queue_name, :durable=>durable)
|
36
|
+
|
37
|
+
if queue.nil? then
|
38
|
+
error_stream.puts Time.now.strftime("[%Y-%m-%d %H:%M:%S](INFO) #{queue_name} does not exist")
|
39
|
+
next
|
40
|
+
end
|
41
|
+
|
42
|
+
result = queue.delete
|
43
|
+
|
44
|
+
if result == :delete_ok then
|
45
|
+
error_stream.puts Time.now.strftime("[%Y-%m-%d %H:%M:%S](INFO) deleted #{queue_name}")
|
46
|
+
else
|
47
|
+
error_stream.puts Time.now.strftime("[%Y-%m-%d %H:%M:%S](ERROR) failed to #{queue_name}")
|
48
|
+
exit_code = 1
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
# Close client
|
53
|
+
bunny.stop
|
54
|
+
|
55
|
+
return exit_code
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
module Bunnish
|
1
|
+
module Bunnish::Command
|
2
2
|
module Publish
|
3
3
|
def self.output_log(streams, message)
|
4
4
|
streams.each do |stream|
|
@@ -22,9 +22,6 @@ module Bunnish
|
|
22
22
|
end
|
23
23
|
|
24
24
|
def self.run(argv, input_stream=$stdin, output_stream=$stdout, error_stream=$stderr)
|
25
|
-
input_stream ||= $stdin
|
26
|
-
output_stream ||= $stdout
|
27
|
-
error_stream ||= $stderr
|
28
25
|
|
29
26
|
params = Bunnish.parse_opts(argv)
|
30
27
|
|
@@ -62,7 +59,7 @@ module Bunnish
|
|
62
59
|
end
|
63
60
|
end
|
64
61
|
|
65
|
-
fanout_flag = (exchange_name != '' && 1 < queue_name_list.size)
|
62
|
+
fanout_flag = (exchange_name && exchange_name != '' && 1 < queue_name_list.size)
|
66
63
|
|
67
64
|
bunny = nil
|
68
65
|
direct_exchange = nil
|
@@ -171,6 +168,8 @@ module Bunnish
|
|
171
168
|
log_streams.values.each do |log_stream|
|
172
169
|
log_stream.close
|
173
170
|
end
|
171
|
+
|
172
|
+
return 0
|
174
173
|
end
|
175
174
|
|
176
175
|
end
|
@@ -1,9 +1,6 @@
|
|
1
|
-
module Bunnish
|
1
|
+
module Bunnish::Command
|
2
2
|
module Status
|
3
3
|
def self.run(argv, input_stream=$stdin, output_stream=$stdout, error_stream=$stderr)
|
4
|
-
input_stream ||= $stdin
|
5
|
-
output_stream ||= $stdout
|
6
|
-
error_stream ||= $stderr
|
7
4
|
|
8
5
|
params = Bunnish.parse_opts(argv)
|
9
6
|
|
@@ -81,14 +78,12 @@ module Bunnish
|
|
81
78
|
rescue Exception=>e
|
82
79
|
message = Time.now.strftime("[%Y-%m-%d %H:%M:%S](EXCEPTION)#{e.message}(#{e.class.name}): #{e.backtrace.map{|s| " #{s}"}.join("\n")}")
|
83
80
|
output_stream.puts message
|
84
|
-
|
81
|
+
return 1
|
85
82
|
end
|
86
83
|
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
84
|
+
return 1 if error_flag
|
85
|
+
return 2 if warn_flag
|
86
|
+
return 0
|
92
87
|
end
|
93
88
|
end
|
94
89
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
module Bunnish
|
1
|
+
module Bunnish::Command
|
2
2
|
module Subscribe
|
3
3
|
def self.output_log(streams, message)
|
4
4
|
streams.each do |stream|
|
@@ -29,7 +29,6 @@ module Bunnish
|
|
29
29
|
user = params[:user]
|
30
30
|
password = params[:password]
|
31
31
|
durable = params[:durable]
|
32
|
-
exchange_name = params[:exchange_name]
|
33
32
|
unit_size = params[:unit_size] || 10000
|
34
33
|
raise_exception_flag = params[:raise_exception_flag]
|
35
34
|
ack = params[:ack]
|
@@ -85,7 +84,7 @@ module Bunnish
|
|
85
84
|
if message_max <= 0
|
86
85
|
self.output_log [error_stream, log_stream], Time.now.strftime("[%Y-%m-%d %H:%M:%S](INFO)#{log_label} finished")
|
87
86
|
bunny.stop
|
88
|
-
|
87
|
+
return 0
|
89
88
|
end
|
90
89
|
else
|
91
90
|
self.output_log [error_stream, log_stream], Time.now.strftime("[%Y-%m-%d %H:%M:%S](INFO)#{log_label} subscribe from #{queue_name}(#{remain_count} messages, #{consumer_count} consumers)")
|
@@ -143,6 +142,8 @@ module Bunnish
|
|
143
142
|
|
144
143
|
# Close client
|
145
144
|
bunny.stop
|
145
|
+
|
146
|
+
return 0
|
146
147
|
end
|
147
148
|
end
|
148
149
|
end
|
data/lib/bunnish.rb
CHANGED
@@ -1,11 +1,5 @@
|
|
1
1
|
require "rubygems"
|
2
2
|
require "bunny"
|
3
|
-
require "bunnish/count"
|
4
|
-
require "bunnish/help"
|
5
|
-
require "bunnish/publish"
|
6
|
-
require "bunnish/status"
|
7
|
-
require "bunnish/subscribe"
|
8
|
-
|
9
3
|
|
10
4
|
module Bunnish
|
11
5
|
def self.parse_opts(argv)
|
@@ -17,7 +11,7 @@ module Bunnish
|
|
17
11
|
ack = true
|
18
12
|
raise_exception_flag = false
|
19
13
|
|
20
|
-
exchange_name =
|
14
|
+
exchange_name = nil
|
21
15
|
delimiter = nil
|
22
16
|
|
23
17
|
consumer_tag = nil
|
@@ -47,7 +41,7 @@ module Bunnish
|
|
47
41
|
when '-u'
|
48
42
|
user = argv.shift
|
49
43
|
when '-P'
|
50
|
-
password = argv.shift
|
44
|
+
password = argv.shift
|
51
45
|
when '--ack'
|
52
46
|
ack = (argv.shift == 't')
|
53
47
|
when '--delimiter'
|
@@ -68,7 +62,7 @@ module Bunnish
|
|
68
62
|
when '--raise-exception'
|
69
63
|
raise_exception_flag = true
|
70
64
|
when '--consumer-tag'
|
71
|
-
consumer_tag = argv.shift
|
65
|
+
consumer_tag = argv.shift
|
72
66
|
when '--timeout'
|
73
67
|
timeout = argv.shift.to_i
|
74
68
|
when '--exclusive'
|
@@ -117,4 +111,6 @@ module Bunnish
|
|
117
111
|
}
|
118
112
|
|
119
113
|
end
|
120
|
-
end
|
114
|
+
end
|
115
|
+
|
116
|
+
require "bunnish/command"
|
@@ -0,0 +1,75 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe "bin/bunnish" do
|
4
|
+
before :all do
|
5
|
+
@stderr = Bunnish::REDIRECT[:stderr]
|
6
|
+
@input_file = Tempfile.new("bunnish")
|
7
|
+
@input_file.puts "foo"
|
8
|
+
@input_file.puts "bar"
|
9
|
+
@input_file.puts "baz"
|
10
|
+
@input_file.close
|
11
|
+
`#{Bunnish::RUBY_CMD} #{Bunnish::BIN_DIR}/bunnish delete bunnish-test-queue 2> /dev/null`
|
12
|
+
end
|
13
|
+
after :all do
|
14
|
+
@input_file.unlink
|
15
|
+
end
|
16
|
+
before :each do
|
17
|
+
`cat #{@input_file.path} | #{Bunnish::RUBY_CMD} #{Bunnish::BIN_DIR}/bunnish publish bunnish-test-queue 2> /dev/null`
|
18
|
+
end
|
19
|
+
after :each do
|
20
|
+
`#{Bunnish::RUBY_CMD} #{Bunnish::BIN_DIR}/bunnish delete bunnish-test-queue 2> /dev/null`
|
21
|
+
end
|
22
|
+
describe "count" do
|
23
|
+
it "should output valid queue count" do
|
24
|
+
result = `#{Bunnish::RUBY_CMD} #{Bunnish::BIN_DIR}/bunnish count bunnish-test-queue 2> #{@stderr}`
|
25
|
+
result.chomp!
|
26
|
+
result.should == "3"
|
27
|
+
end
|
28
|
+
end
|
29
|
+
describe "delete" do
|
30
|
+
it "should delete queue" do
|
31
|
+
`#{Bunnish::RUBY_CMD} #{Bunnish::BIN_DIR}/bunnish delete bunnish-test-queue 2> #{@stderr}`
|
32
|
+
result = `#{Bunnish::RUBY_CMD} #{Bunnish::BIN_DIR}/bunnish count bunnish-test-queue 2> /dev/null`
|
33
|
+
result = result.chomp!
|
34
|
+
result.should == "0"
|
35
|
+
end
|
36
|
+
end
|
37
|
+
describe "help" do
|
38
|
+
it "should delete queue" do
|
39
|
+
result = `#{Bunnish::RUBY_CMD} #{Bunnish::BIN_DIR}/bunnish help bunnish-test-queue 2> #{@stderr}`
|
40
|
+
result.split().size.should > 0
|
41
|
+
$?.should == 0
|
42
|
+
end
|
43
|
+
end
|
44
|
+
describe "publish" do
|
45
|
+
it "should publish valid messages" do
|
46
|
+
`echo qux | #{Bunnish::RUBY_CMD} #{Bunnish::BIN_DIR}/bunnish publish bunnish-test-queue 2> #{@stderr}`
|
47
|
+
result = `#{Bunnish::RUBY_CMD} #{Bunnish::BIN_DIR}/bunnish subscribe bunnish-test-queue 2> /dev/null`
|
48
|
+
result = result.split()
|
49
|
+
# result.each do |line| STDERR.puts line end
|
50
|
+
result.shift.should == "foo"
|
51
|
+
result.shift.should == "bar"
|
52
|
+
result.shift.should == "baz"
|
53
|
+
result.shift.should == "qux"
|
54
|
+
result.size.should == 0
|
55
|
+
end
|
56
|
+
end
|
57
|
+
describe "status" do
|
58
|
+
it "should print valid status of message queue" do
|
59
|
+
result = `#{Bunnish::RUBY_CMD} #{Bunnish::BIN_DIR}/bunnish status bunnish-test-queue 2> #{@stderr}`
|
60
|
+
result = result.split(/\n/)
|
61
|
+
# STDERR.puts result.inspect
|
62
|
+
result.include?("bunnish-test-queue : 3 messages, 0 consumers").should be_true
|
63
|
+
end
|
64
|
+
end
|
65
|
+
describe "subscribe" do
|
66
|
+
it "should subscribe valid messages" do
|
67
|
+
result = `#{Bunnish::RUBY_CMD} #{Bunnish::BIN_DIR}/bunnish subscribe bunnish-test-queue 2> #{@stderr}`
|
68
|
+
result = result.split()
|
69
|
+
# result.each do |line| STDERR.puts line end
|
70
|
+
result.shift.should == "foo"
|
71
|
+
result.shift.should == "bar"
|
72
|
+
result.shift.should == "baz"
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
|
4
|
+
describe Bunnish do
|
5
|
+
describe "#parse_opts(argv)" do
|
6
|
+
context "when argv = []" do
|
7
|
+
it "should return defalut hash" do
|
8
|
+
result = Bunnish.parse_opts([])
|
9
|
+
result[:host].should == "localhost"
|
10
|
+
result[:port].should == 5672
|
11
|
+
result[:user].should == "guest"
|
12
|
+
result[:password].should == "guest"
|
13
|
+
result[:durable].should == false
|
14
|
+
result[:ack].should == true
|
15
|
+
result[:exchange_name].should == nil
|
16
|
+
result[:unit_size].should == nil
|
17
|
+
result[:raise_exception_flag].should == false
|
18
|
+
result[:delimiter].should == nil
|
19
|
+
result[:log_label].should == nil
|
20
|
+
result[:log_dir].should == nil
|
21
|
+
result[:log_path].should == nil
|
22
|
+
result[:consumer_tag].should == nil
|
23
|
+
result[:timeout].should == 1
|
24
|
+
result[:exclusive].should == false
|
25
|
+
result[:message_max].should == nil
|
26
|
+
result[:current_all_flag].should == false
|
27
|
+
result[:min_size].should == nil
|
28
|
+
result[:empty_list_max].should == nil
|
29
|
+
result[:warn_size].should == nil
|
30
|
+
result[:error_size].should == nil
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
argv = ("-h mq-server -p 15672 -u user -P password --durable t" \
|
35
|
+
+ " --ack f --exchange-name exchange --unit-size 10" \
|
36
|
+
+ " --raise-exception --delimiter delim" \
|
37
|
+
+ " --log-label log-label --log-dir log-dir --log-file log-file" \
|
38
|
+
+ " --consumer-tag ctag --timeout 11 --exclusive t --message-max 12" \
|
39
|
+
+ " --current-all --min-size 13 --empty-list-max 14" \
|
40
|
+
+ " --warn 15 --error 16").split(/ /)
|
41
|
+
|
42
|
+
context "when argv = #{argv.inspect}" do
|
43
|
+
it 'should return valid hash' do
|
44
|
+
result = Bunnish.parse_opts(argv)
|
45
|
+
result[:host].should == "mq-server"
|
46
|
+
result[:port].should == 15672
|
47
|
+
result[:user].should == "user"
|
48
|
+
result[:password].should == "password"
|
49
|
+
result[:durable].should == true
|
50
|
+
result[:ack].should == false
|
51
|
+
result[:exchange_name].should == "exchange"
|
52
|
+
result[:unit_size].should == 10
|
53
|
+
result[:raise_exception_flag].should == true
|
54
|
+
result[:delimiter].should == "delim"
|
55
|
+
result[:log_label].should == "[log-label]"
|
56
|
+
result[:log_dir].should == "log-dir"
|
57
|
+
result[:log_path].should == "log-file"
|
58
|
+
result[:consumer_tag].should == "ctag"
|
59
|
+
result[:timeout].should == 11
|
60
|
+
result[:exclusive].should == true
|
61
|
+
result[:message_max].should == "12"
|
62
|
+
result[:current_all_flag].should == true
|
63
|
+
result[:min_size].should == 13
|
64
|
+
result[:empty_list_max].should == 14
|
65
|
+
result[:warn_size].should == 15
|
66
|
+
result[:error_size].should == 16
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
2
2
|
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
3
|
-
require
|
4
|
-
require
|
3
|
+
require "rspec"
|
4
|
+
require "bunnish"
|
5
|
+
require "tempfile"
|
5
6
|
|
6
7
|
# Requires supporting files with custom matchers and macros, etc,
|
7
8
|
# in ./support/ and its subdirectories.
|
@@ -10,3 +11,11 @@ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
|
10
11
|
RSpec.configure do |config|
|
11
12
|
|
12
13
|
end
|
14
|
+
|
15
|
+
module Bunnish
|
16
|
+
BUNNISH_HOME = File.expand_path(File.dirname(__FILE__) + "/..")
|
17
|
+
BIN_DIR = "#{BUNNISH_HOME}/bin"
|
18
|
+
LIB_DIR = "#{BUNNISH_HOME}/lib"
|
19
|
+
RUBY_CMD = "/usr/bin/env ruby -I #{LIB_DIR}"
|
20
|
+
REDIRECT = {:stderr=>"/dev/null"}
|
21
|
+
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bunnish
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 27
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 2
|
10
|
+
version: 0.0.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Kenji Hara
|
@@ -15,9 +15,11 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2012-12-
|
18
|
+
date: 2012-12-08 00:00:00 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
|
+
name: json
|
22
|
+
prerelease: false
|
21
23
|
type: :runtime
|
22
24
|
requirement: &id001 !ruby/object:Gem::Requirement
|
23
25
|
none: false
|
@@ -29,9 +31,9 @@ dependencies:
|
|
29
31
|
- 0
|
30
32
|
version: "0"
|
31
33
|
version_requirements: *id001
|
32
|
-
name: json
|
33
|
-
prerelease: false
|
34
34
|
- !ruby/object:Gem::Dependency
|
35
|
+
name: bunny
|
36
|
+
prerelease: false
|
35
37
|
type: :runtime
|
36
38
|
requirement: &id002 !ruby/object:Gem::Requirement
|
37
39
|
none: false
|
@@ -43,9 +45,9 @@ dependencies:
|
|
43
45
|
- 0
|
44
46
|
version: "0"
|
45
47
|
version_requirements: *id002
|
46
|
-
name: bunny
|
47
|
-
prerelease: false
|
48
48
|
- !ruby/object:Gem::Dependency
|
49
|
+
name: rspec
|
50
|
+
prerelease: false
|
49
51
|
type: :development
|
50
52
|
requirement: &id003 !ruby/object:Gem::Requirement
|
51
53
|
none: false
|
@@ -59,9 +61,9 @@ dependencies:
|
|
59
61
|
- 0
|
60
62
|
version: 2.8.0
|
61
63
|
version_requirements: *id003
|
62
|
-
name: rspec
|
63
|
-
prerelease: false
|
64
64
|
- !ruby/object:Gem::Dependency
|
65
|
+
name: rdoc
|
66
|
+
prerelease: false
|
65
67
|
type: :development
|
66
68
|
requirement: &id004 !ruby/object:Gem::Requirement
|
67
69
|
none: false
|
@@ -74,9 +76,9 @@ dependencies:
|
|
74
76
|
- 12
|
75
77
|
version: "3.12"
|
76
78
|
version_requirements: *id004
|
77
|
-
name: rdoc
|
78
|
-
prerelease: false
|
79
79
|
- !ruby/object:Gem::Dependency
|
80
|
+
name: bundler
|
81
|
+
prerelease: false
|
80
82
|
type: :development
|
81
83
|
requirement: &id005 !ruby/object:Gem::Requirement
|
82
84
|
none: false
|
@@ -88,9 +90,9 @@ dependencies:
|
|
88
90
|
- 0
|
89
91
|
version: "0"
|
90
92
|
version_requirements: *id005
|
91
|
-
name: bundler
|
92
|
-
prerelease: false
|
93
93
|
- !ruby/object:Gem::Dependency
|
94
|
+
name: jeweler
|
95
|
+
prerelease: false
|
94
96
|
type: :development
|
95
97
|
requirement: &id006 !ruby/object:Gem::Requirement
|
96
98
|
none: false
|
@@ -104,9 +106,9 @@ dependencies:
|
|
104
106
|
- 4
|
105
107
|
version: 1.8.4
|
106
108
|
version_requirements: *id006
|
107
|
-
name: jeweler
|
108
|
-
prerelease: false
|
109
109
|
- !ruby/object:Gem::Dependency
|
110
|
+
name: rcov
|
111
|
+
prerelease: false
|
110
112
|
type: :development
|
111
113
|
requirement: &id007 !ruby/object:Gem::Requirement
|
112
114
|
none: false
|
@@ -118,8 +120,6 @@ dependencies:
|
|
118
120
|
- 0
|
119
121
|
version: "0"
|
120
122
|
version_requirements: *id007
|
121
|
-
name: rcov
|
122
|
-
prerelease: false
|
123
123
|
description: Command for AMQP access to Message Queue.
|
124
124
|
email: haracane@gmail.com
|
125
125
|
executables:
|
@@ -138,13 +138,23 @@ files:
|
|
138
138
|
- Rakefile
|
139
139
|
- VERSION
|
140
140
|
- bin/bunnish
|
141
|
+
- bunnish.gemspec
|
141
142
|
- lib/bunnish.rb
|
142
|
-
- lib/bunnish/
|
143
|
-
- lib/bunnish/
|
144
|
-
- lib/bunnish/
|
145
|
-
- lib/bunnish/
|
146
|
-
- lib/bunnish/
|
147
|
-
-
|
143
|
+
- lib/bunnish/command.rb
|
144
|
+
- lib/bunnish/command/count.rb
|
145
|
+
- lib/bunnish/command/delete.rb
|
146
|
+
- lib/bunnish/command/help.rb
|
147
|
+
- lib/bunnish/command/publish.rb
|
148
|
+
- lib/bunnish/command/status.rb
|
149
|
+
- lib/bunnish/command/subscribe.rb
|
150
|
+
- spec/bin/bunnish_spec.rb
|
151
|
+
- spec/lib/bunnish/command/count_spec.rb
|
152
|
+
- spec/lib/bunnish/command/delete_spec.rb
|
153
|
+
- spec/lib/bunnish/command/help_spec.rb
|
154
|
+
- spec/lib/bunnish/command/publish_spec.rb
|
155
|
+
- spec/lib/bunnish/command/status_spec.rb
|
156
|
+
- spec/lib/bunnish/command/subscribe_spec.rb
|
157
|
+
- spec/lib/bunnish_spec.rb
|
148
158
|
- spec/spec_helper.rb
|
149
159
|
homepage: http://github.com/haracane/bunnish
|
150
160
|
licenses:
|
@@ -175,7 +185,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
175
185
|
requirements: []
|
176
186
|
|
177
187
|
rubyforge_project:
|
178
|
-
rubygems_version: 1.8.
|
188
|
+
rubygems_version: 1.8.17
|
179
189
|
signing_key:
|
180
190
|
specification_version: 3
|
181
191
|
summary: Command for AMQP access to Message Queue.
|
data/spec/bunnish_spec.rb
DELETED