zmqp 0.0.1

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.
@@ -0,0 +1,43 @@
1
+ require 'zmqp'
2
+ require 'pathname'
3
+
4
+ require 'bundler'
5
+ Bundler.setup
6
+ Bundler.require :test
7
+
8
+ BASE_PATH = Pathname.new(__FILE__).dirname + '..'
9
+
10
+ RSpec.configure do |config|
11
+ # config.exclusion_filter = { :slow => true }
12
+ # config.filter = { :focus => true }
13
+ # config.include(UserExampleHelpers)
14
+ # config.mock_with :mocha
15
+ # config.mock_with :flexmock
16
+ # config.mock_with :rr
17
+ end
18
+
19
+ #$LOAD_PATH << "." unless $LOAD_PATH.include? "." # moronic 1.9.2 breaks things bad
20
+ #
21
+ #require 'rspec'
22
+ #require 'yaml'
23
+ #
24
+ #def rspec2?
25
+ # defined?(RSpec)
26
+ #end
27
+
28
+ amqp_config = File.dirname(__FILE__) + '/amqp.yml'
29
+
30
+ if File.exists? amqp_config
31
+ class Hash
32
+ def symbolize_keys
33
+ self.inject({}) { |result, (key, value)|
34
+ new_key = key.is_a?(String) ? key.to_sym : key
35
+ new_value = value.is_a?(Hash) ? value.symbolize_keys : value
36
+ result[new_key] = new_value
37
+ result
38
+ }
39
+ end
40
+ end
41
+
42
+ AMQP_OPTS = YAML::load_file(amqp_config).symbolize_keys[:test]
43
+ end
data/spec/zmqp_spec.rb ADDED
@@ -0,0 +1,186 @@
1
+ require 'spec_helper'
2
+
3
+ #require 'amqp-spec/rspec'
4
+ #require 'amqp'
5
+
6
+ module MockClientModule
7
+ def my_mock_method
8
+ end
9
+ end
10
+
11
+ class MockClient
12
+ include AMQP::Client
13
+ end
14
+
15
+ describe AMQP, 'as a class' do
16
+
17
+ context 'has class accessors, with default values' do
18
+ subject { AMQP }
19
+
20
+ its(:logging) { should be_false }
21
+ its(:connection) { should be_nil }
22
+ its(:conn) { should be_nil } # Alias for #connection
23
+ its(:closing) { should be_false }
24
+ its(:settings) { should == {:host=>"127.0.0.1",
25
+ :port=>5672,
26
+ :user=>"guest",
27
+ :pass=>"guest",
28
+ :vhost=>"/",
29
+ :timeout=>nil,
30
+ :logging=>false,
31
+ :ssl=>false} }
32
+ its(:client) { should == AMQP::BasicClient }
33
+
34
+ end
35
+
36
+ describe '.client=' do
37
+ after(:all) { AMQP.client = AMQP::BasicClient }
38
+
39
+ it 'is used to change default client module' do
40
+ AMQP.client = MockClientModule
41
+ AMQP.client.should == MockClientModule
42
+ MockClientModule.ancestors.should include AMQP
43
+ end
44
+
45
+ describe 'new default client module' do
46
+ it 'sticks around after being assigned' do
47
+ AMQP.client.should == MockClientModule
48
+ end
49
+
50
+ it 'extends any object that includes AMQP::Client' do
51
+ @client = MockClient.new
52
+ @client.should respond_to :my_mock_method
53
+ end
54
+ end
55
+ end
56
+
57
+ describe '.logging=' do
58
+ it 'changes logging setting' do
59
+ pending 'require "pp"; pp XX - not sure how to intercept'
60
+ end
61
+ end
62
+
63
+ describe '.connect' do
64
+ it 'delegates to Client.connect' do
65
+ AMQP::Client.should_receive(:connect).with("args")
66
+ AMQP.connect "args"
67
+ end
68
+
69
+ it 'raises error unless called inside EM event loop' do
70
+ expect { AMQP.connect {} }.to raise_error RuntimeError, /eventmachine not initialized/
71
+ end
72
+
73
+ context 'when called inside EM event loop, it either' do
74
+ # include AMQP::EMSpec
75
+
76
+ it 'raises connection error (with wrong AMQP opts), or' do
77
+ expect { @conn = AMQP.connect(host: 'wrong') }.
78
+ to raise_error EventMachine::ConnectionError, /unable to resolve server address/
79
+ done
80
+ end
81
+
82
+ it 'establishes connection to AMQP broker (with right AMQP options). Mind the delay!' do
83
+ @conn = AMQP.connect AMQP_OPTS
84
+ # p (@conn.methods - Object.methods).sort #class.ancestors.first.should == MockClientModule
85
+ @conn.should be_kind_of AMQP::Client::EM_CONNECTION_CLASS
86
+ @conn.should_not be_connected
87
+ done(0.1) { @conn.should be_connected }
88
+ end
89
+
90
+ end
91
+ end
92
+
93
+ describe '.start' do
94
+ it 'starts new EM loop and never returns from it' do
95
+ EM.should_receive(:run).with no_args
96
+ AMQP.start "connect_args"
97
+ end
98
+
99
+ it 'calls .connect inside block given to EM.run (inside EM loop, that is)' do
100
+ EM.should_receive(:run) do |*args, &block|
101
+ args.should be_empty
102
+ AMQP.should_receive(:connect).with("connect_args")
103
+ block.call
104
+ end
105
+ AMQP.start "connect_args"
106
+ end
107
+
108
+ context 'inside EM loop' do
109
+ # include AMQP::EMSpec
110
+ after { AMQP.cleanup_state; done }
111
+
112
+ it 'raises connection error (with wrong AMQP opts)' do
113
+ expect { AMQP.start(host: 'wrong') }.
114
+ to raise_error EventMachine::ConnectionError, /unable to resolve server address/
115
+ done
116
+ end
117
+
118
+ it 'sets AMQP.connection property with client instance returned by .connect' do
119
+ AMQP.connection.should be_nil
120
+ AMQP.start AMQP_OPTS
121
+ AMQP.connection.should be_kind_of AMQP::Client::EM_CONNECTION_CLASS
122
+ done
123
+ end
124
+
125
+ it 'yields to given block AFTER connection is established' do
126
+ AMQP.start AMQP_OPTS do
127
+ @block_fired = true
128
+ AMQP.connection.should be_connected
129
+ end
130
+ done(0.1) { @block_fired.should be_true }
131
+ end
132
+ end
133
+ end
134
+
135
+ describe '.stop' do
136
+ it 'is noop if connection is not established' do
137
+ expect { @res = AMQP.stop }.to_not raise_error
138
+ @res.should be_nil
139
+ end
140
+
141
+ context 'with established AMQP connection' do
142
+ # include AMQP::Spec
143
+ after { AMQP.cleanup_state; done }
144
+ # default_options AMQP_OPTS
145
+
146
+ it 'closes existing connection' do
147
+ AMQP.connection.should_receive(:close).with(no_args)
148
+ AMQP.stop
149
+ done
150
+ end
151
+
152
+ it 'unsets AMQP.connection property. Mind the delay!' do
153
+ AMQP.connection.should be_connected
154
+ AMQP.stop
155
+ AMQP.connection.should_not be_nil
156
+ done(0.1) { AMQP.connection.should be_nil }
157
+ end
158
+
159
+ it 'yields to given block AFTER connection is disconnected (BUT before AMQP.conn is cleared!)' do
160
+ AMQP.stop do
161
+ @block_fired = true
162
+ AMQP.connection.should_not be_nil
163
+ AMQP.instance_variable_get(:@closing).should be_true
164
+ end
165
+ done(0.1) do
166
+ @block_fired.should be_true
167
+ end
168
+ end
169
+ end
170
+ end
171
+
172
+ describe '.fork' do
173
+
174
+ it 'yields to given block in EM.fork (cleaning its own process-local properties first)' do
175
+ pending 'Not implemented in ZM yet'
176
+ EM.should_receive(:fork) do |workers, &block|
177
+ workers.should == 'workers'
178
+ block.call
179
+ Thread.current[:mq].should be_nil
180
+ AMQP.connection.should be_nil
181
+ end
182
+ AMQP.fork('workers') { |*args| p *args }
183
+
184
+ end
185
+ end
186
+ end
data/tasks/common.rake ADDED
@@ -0,0 +1,18 @@
1
+ #task :default => 'test:run'
2
+ #task 'gem:release' => 'test:run'
3
+
4
+ task :notes do
5
+ puts 'Output annotations (TBD)'
6
+ end
7
+
8
+ #Bundler not ready for prime time just yet
9
+ #desc 'Bundle dependencies'
10
+ #task :bundle do
11
+ # output = `bundle check 2>&1`
12
+ #
13
+ # unless $?.to_i == 0
14
+ # puts output
15
+ # system "bundle install"
16
+ # puts
17
+ # end
18
+ #end
data/tasks/doc.rake ADDED
@@ -0,0 +1,14 @@
1
+ desc 'Alias to doc:rdoc'
2
+ task :doc => 'doc:rdoc'
3
+
4
+ namespace :doc do
5
+ require 'rake/rdoctask'
6
+ Rake::RDocTask.new do |rdoc|
7
+ # Rake::RDocTask.new(:rdoc => "rdoc", :clobber_rdoc => "clobber", :rerdoc => "rerdoc") do |rdoc|
8
+ rdoc.rdoc_dir = DOC_PATH.basename.to_s
9
+ rdoc.title = "#{NAME} #{VERSION} Documentation"
10
+ rdoc.main = "README.doc"
11
+ rdoc.rdoc_files.include('README*')
12
+ rdoc.rdoc_files.include('lib/**/*.rb')
13
+ end
14
+ end
data/tasks/gem.rake ADDED
@@ -0,0 +1,40 @@
1
+ desc "Alias to gem:release"
2
+ task :release => 'gem:release'
3
+
4
+ desc "Alias to gem:install"
5
+ task :install => 'gem:install'
6
+
7
+ desc "Alias to gem:build"
8
+ task :gem => 'gem:build'
9
+
10
+ namespace :gem do
11
+ gem_file = "#{NAME}-#{VERSION}.gem"
12
+
13
+ desc "(Re-)Build gem"
14
+ task :build do
15
+ puts "Remove existing gem package"
16
+ rm_rf PKG_PATH
17
+ puts "Build new gem package"
18
+ system "gem build #{NAME}.gemspec"
19
+ puts "Move built gem to package dir"
20
+ mkdir_p PKG_PATH
21
+ mv gem_file, PKG_PATH
22
+ end
23
+
24
+ desc "Cleanup already installed gem(s)"
25
+ task :cleanup do
26
+ puts "Cleaning up installed gem(s)"
27
+ system "gem cleanup #{NAME}"
28
+ end
29
+
30
+ desc "Build and install gem"
31
+ task :install => :build do
32
+ system "gem install #{PKG_PATH}/#{gem_file}"
33
+ end
34
+
35
+ desc "Build and push gem to Gemcutter"
36
+ task :release => [:build, 'git:tag'] do
37
+ puts "Pushing gem to Gemcutter"
38
+ system "gem push #{PKG_PATH}/#{gem_file}"
39
+ end
40
+ end
data/tasks/git.rake ADDED
@@ -0,0 +1,34 @@
1
+ desc "Alias to git:commit"
2
+ task :git => 'git:commit'
3
+
4
+ namespace :git do
5
+
6
+ desc "Stage and commit your work [with message]"
7
+ task :commit, [:message] do |t, args|
8
+ puts "Staging new (unversioned) files"
9
+ system "git add --all"
10
+ if args.message
11
+ puts "Committing with message: #{args.message}"
12
+ system %Q[git commit -a -m "#{args.message}" --author arvicco]
13
+ else
14
+ puts "Committing"
15
+ system %Q[git commit -a -m "No message" --author arvicco]
16
+ end
17
+ end
18
+
19
+ desc "Push local changes to Github"
20
+ task :push => :commit do
21
+ puts "Pushing local changes to remote"
22
+ system "git push"
23
+ end
24
+
25
+ desc "Create (release) tag on Github"
26
+ task :tag => :push do
27
+ tag = VERSION
28
+ puts "Creating git tag: #{tag}"
29
+ system %Q{git tag -a -m "Release tag #{tag}" #{tag}}
30
+ puts "Pushing #{tag} to remote"
31
+ system "git push origin #{tag}"
32
+ end
33
+
34
+ end
data/tasks/spec.rake ADDED
@@ -0,0 +1,16 @@
1
+ desc 'Alias to spec:spec'
2
+ task :spec => 'spec:spec'
3
+
4
+ namespace :spec do
5
+ # require 'spec/rake/spectask'
6
+ require 'rspec/core/rake_task'
7
+
8
+ desc "Run all specs"
9
+ RSpec::Core::RakeTask.new(:spec){|task|}
10
+
11
+ desc "Run specs with RCov"
12
+ RSpec::Core::RakeTask.new(:rcov) do |task|
13
+ task.rcov = true
14
+ task.rcov_opts = ['--exclude', 'spec']
15
+ end
16
+ end
@@ -0,0 +1,71 @@
1
+ class Version
2
+ attr_accessor :major, :minor, :patch, :build
3
+
4
+ def initialize(version_string)
5
+ raise "Invalid version #{version_string}" unless version_string =~ /^(\d+)\.(\d+)\.(\d+)(?:\.(.*?))?$/
6
+ @major = $1.to_i
7
+ @minor = $2.to_i
8
+ @patch = $3.to_i
9
+ @build = $4
10
+ end
11
+
12
+ def bump_major(x)
13
+ @major += x.to_i
14
+ @minor = 0
15
+ @patch = 0
16
+ @build = nil
17
+ end
18
+
19
+ def bump_minor(x)
20
+ @minor += x.to_i
21
+ @patch = 0
22
+ @build = nil
23
+ end
24
+
25
+ def bump_patch(x)
26
+ @patch += x.to_i
27
+ @build = nil
28
+ end
29
+
30
+ def update(major, minor, patch, build=nil)
31
+ @major = major
32
+ @minor = minor
33
+ @patch = patch
34
+ @build = build
35
+ end
36
+
37
+ def write(desc = nil)
38
+ CLASS_NAME::VERSION_FILE.open('w') {|file| file.puts to_s }
39
+ (BASE_PATH + 'HISTORY').open('a') do |file|
40
+ file.puts "\n== #{to_s} / #{Time.now.strftime '%Y-%m-%d'}\n"
41
+ file.puts "\n* #{desc}\n" if desc
42
+ end
43
+ end
44
+
45
+ def to_s
46
+ [major, minor, patch, build].compact.join('.')
47
+ end
48
+ end
49
+
50
+ desc 'Set version: [x.y.z] - explicitly, [1/10/100] - bump major/minor/patch, [.build] - build'
51
+ task :version, [:command, :desc] do |t, args|
52
+ version = Version.new(VERSION)
53
+ case args.command
54
+ when /^(\d+)\.(\d+)\.(\d+)(?:\.(.*?))?$/ # Set version explicitly
55
+ version.update($1, $2, $3, $4)
56
+ when /^\.(.*?)$/ # Set build
57
+ version.build = $1
58
+ when /^(\d{1})$/ # Bump patch
59
+ version.bump_patch $1
60
+ when /^(\d{1})0$/ # Bump minor
61
+ version.bump_minor $1
62
+ when /^(\d{1})00$/ # Bump major
63
+ version.bump_major $1
64
+ else # Unknown command, just display VERSION
65
+ puts "#{NAME} #{version}"
66
+ next
67
+ end
68
+
69
+ puts "Writing version #{version} to VERSION file"
70
+ version.write args.desc
71
+ end
metadata ADDED
@@ -0,0 +1,155 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: zmqp
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 1
9
+ version: 0.0.1
10
+ platform: ruby
11
+ authors:
12
+ - arvicco
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-11-12 00:00:00 +03:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: rspec
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ segments:
29
+ - 2
30
+ - 0
31
+ - 0
32
+ version: 2.0.0
33
+ type: :development
34
+ version_requirements: *id001
35
+ - !ruby/object:Gem::Dependency
36
+ name: cucumber
37
+ prerelease: false
38
+ requirement: &id002 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ segments:
44
+ - 0
45
+ version: "0"
46
+ type: :development
47
+ version_requirements: *id002
48
+ - !ruby/object:Gem::Dependency
49
+ name: bundler
50
+ prerelease: false
51
+ requirement: &id003 !ruby/object:Gem::Requirement
52
+ none: false
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ segments:
57
+ - 1
58
+ - 0
59
+ - 0
60
+ version: 1.0.0
61
+ type: :runtime
62
+ version_requirements: *id003
63
+ - !ruby/object:Gem::Dependency
64
+ name: zmqmachine
65
+ prerelease: false
66
+ requirement: &id004 !ruby/object:Gem::Requirement
67
+ none: false
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ segments:
72
+ - 0
73
+ - 3
74
+ - 2
75
+ version: 0.3.2
76
+ type: :runtime
77
+ version_requirements: *id004
78
+ description: Drop-in replacement for async AMQP library based on ZMQ/ZmqMachine (pre-alpha!).
79
+ email: arvitallian@gmail.com
80
+ executables:
81
+ - zmqp
82
+ extensions: []
83
+
84
+ extra_rdoc_files:
85
+ - LICENSE
86
+ - HISTORY
87
+ - README.md
88
+ files:
89
+ - bin/zmqp
90
+ - lib/version.rb
91
+ - lib/zmqp/client.rb
92
+ - lib/zmqp/spec.rb
93
+ - lib/zmqp.rb
94
+ - spec/amqp.yml
95
+ - spec/mq_spec.rb
96
+ - spec/spec_helper.rb
97
+ - spec/zmqp_spec.rb
98
+ - features/step_definitions/zmqp_steps.rb
99
+ - features/support/env.rb
100
+ - features/support/world.rb
101
+ - features/zmqp.feature
102
+ - tasks/common.rake
103
+ - tasks/doc.rake
104
+ - tasks/gem.rake
105
+ - tasks/git.rake
106
+ - tasks/spec.rake
107
+ - tasks/version.rake
108
+ - Rakefile
109
+ - README.md
110
+ - LICENSE
111
+ - VERSION
112
+ - HISTORY
113
+ - .gitignore
114
+ has_rdoc: true
115
+ homepage: http://github.com/arvicco/zmqp
116
+ licenses: []
117
+
118
+ post_install_message:
119
+ rdoc_options:
120
+ - --charset
121
+ - UTF-8
122
+ - --main
123
+ - README.rdoc
124
+ - --title
125
+ - zmqp
126
+ require_paths:
127
+ - lib
128
+ required_ruby_version: !ruby/object:Gem::Requirement
129
+ none: false
130
+ requirements:
131
+ - - ">="
132
+ - !ruby/object:Gem::Version
133
+ segments:
134
+ - 0
135
+ version: "0"
136
+ required_rubygems_version: !ruby/object:Gem::Requirement
137
+ none: false
138
+ requirements:
139
+ - - ">="
140
+ - !ruby/object:Gem::Version
141
+ segments:
142
+ - 0
143
+ version: "0"
144
+ requirements: []
145
+
146
+ rubyforge_project:
147
+ rubygems_version: 1.3.7
148
+ signing_key:
149
+ specification_version: 3
150
+ summary: Alternative for AMQP library based on ZMQ/ZmqMachine (pre-alpha!).
151
+ test_files:
152
+ - spec/amqp.yml
153
+ - spec/mq_spec.rb
154
+ - spec/spec_helper.rb
155
+ - spec/zmqp_spec.rb