amqp 0.7.0.pre → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (71) hide show
  1. data/.gitignore +4 -0
  2. data/.rspec +2 -0
  3. data/CHANGELOG +8 -2
  4. data/CONTRIBUTORS +22 -0
  5. data/Gemfile +3 -3
  6. data/README.md +20 -11
  7. data/Rakefile +30 -6
  8. data/amqp.gemspec +1 -1
  9. data/bin/cleanify.rb +50 -0
  10. data/examples/amqp/simple.rb +6 -4
  11. data/examples/mq/ack.rb +8 -6
  12. data/examples/mq/automatic_binding_for_default_direct_exchange.rb +65 -0
  13. data/examples/mq/callbacks.rb +9 -1
  14. data/examples/mq/clock.rb +17 -17
  15. data/examples/mq/hashtable.rb +19 -10
  16. data/examples/mq/internal.rb +13 -11
  17. data/examples/mq/logger.rb +38 -36
  18. data/examples/mq/multiclock.rb +16 -7
  19. data/examples/mq/pingpong.rb +16 -7
  20. data/examples/mq/pop.rb +8 -6
  21. data/examples/mq/primes-simple.rb +2 -0
  22. data/examples/mq/primes.rb +7 -5
  23. data/examples/mq/stocks.rb +14 -5
  24. data/lib/amqp.rb +12 -8
  25. data/lib/amqp/buffer.rb +35 -158
  26. data/lib/amqp/client.rb +34 -22
  27. data/lib/amqp/frame.rb +8 -64
  28. data/lib/amqp/protocol.rb +21 -70
  29. data/lib/amqp/server.rb +11 -9
  30. data/lib/amqp/spec.rb +8 -6
  31. data/lib/amqp/version.rb +2 -0
  32. data/lib/ext/blankslate.rb +3 -1
  33. data/lib/ext/em.rb +2 -0
  34. data/lib/ext/emfork.rb +13 -11
  35. data/lib/mq.rb +253 -156
  36. data/lib/mq/collection.rb +6 -88
  37. data/lib/mq/exchange.rb +70 -13
  38. data/lib/mq/header.rb +12 -6
  39. data/lib/mq/logger.rb +9 -7
  40. data/lib/mq/queue.rb +42 -30
  41. data/lib/mq/rpc.rb +6 -4
  42. data/protocol/codegen.rb +20 -18
  43. data/research/api.rb +10 -46
  44. data/research/primes-forked.rb +9 -7
  45. data/research/primes-processes.rb +74 -72
  46. data/research/primes-threaded.rb +9 -7
  47. data/spec/integration/automatic_binding_for_default_direct_exchange_spec.rb +61 -0
  48. data/spec/mq_helper.rb +70 -0
  49. data/spec/spec_helper.rb +84 -29
  50. data/spec/unit/amqp/buffer_spec.rb +178 -0
  51. data/spec/unit/amqp/client_spec.rb +472 -0
  52. data/spec/unit/amqp/frame_spec.rb +60 -0
  53. data/spec/unit/amqp/misc_spec.rb +123 -0
  54. data/spec/unit/amqp/protocol_spec.rb +53 -0
  55. data/spec/unit/mq/channel_close_spec.rb +15 -0
  56. data/spec/unit/mq/collection_spec.rb +129 -0
  57. data/spec/unit/mq/exchange_declaration_spec.rb +524 -0
  58. data/spec/unit/mq/misc_spec.rb +228 -0
  59. data/spec/unit/mq/mq_basic_spec.rb +39 -0
  60. data/spec/unit/mq/queue_declaration_spec.rb +97 -0
  61. data/spec/unit/mq/queue_spec.rb +71 -0
  62. metadata +33 -21
  63. data/Gemfile.lock +0 -16
  64. data/old/README +0 -30
  65. data/old/Rakefile +0 -12
  66. data/old/amqp-0.8.json +0 -606
  67. data/old/amqp_spec.rb +0 -796
  68. data/old/amqpc.rb +0 -695
  69. data/old/codegen.rb +0 -148
  70. data/spec/channel_close_spec.rb +0 -13
  71. data/spec/sync_async_spec.rb +0 -52
@@ -1,148 +0,0 @@
1
- require 'rubygems'
2
- require 'json'
3
-
4
- s = JSON.parse(File.read('amqp-0.8.json'))
5
-
6
- # require 'pp'
7
- # pp(s)
8
- # exit
9
-
10
- require 'erb'
11
-
12
- puts ERB.new(%q[
13
- module AMQP
14
- HEADER = <%= s['name'].dump %>.freeze
15
- VERSION_MAJOR = <%= s['major-version'] %>
16
- VERSION_MINOR = <%= s['minor-version'] %>
17
- PORT = <%= s['port'] %>
18
-
19
- class Frame
20
- TYPES = [
21
- nil,
22
- <%- s['constants'].select{|c| (1..8).include? c['value'] }.each do |c| -%>
23
- :<%= c['name'].tr('-', '_').gsub(/^FRAME_/,'').upcase -%>,
24
- <%- end -%>
25
- ]
26
- FOOTER = <%= frame_end = s['constants'].find{|c| c['name'] == 'FRAME-END' }['value'] %>
27
- end
28
-
29
- RESPONSES = {
30
- <%- s['constants'].select{|c| c['value'] != frame_end and (200..500).include? c['value'] }.each do |c| -%>
31
- <%= c['value'] %> => :<%= c['name'].tr('-', '_').gsub(/^FRAME_/,'').upcase -%>,
32
- <%- end -%>
33
- }
34
-
35
- FIELDS = [
36
- <%- s['domains'].select{|d| d.first == d.last }.each do |d| -%>
37
- :<%= d.first -%>,
38
- <%- end -%>
39
- ]
40
-
41
- module Protocol
42
- class Class
43
- class << self
44
- FIELDS.each do |f|
45
- class_eval %[
46
- def #{f} name
47
- properties << [ :#{f}, name ] unless properties.include?([:#{f}, name])
48
- attr_accessor name
49
- end
50
- ]
51
- end
52
-
53
- def properties() @properties ||= [] end
54
-
55
- def id() self::ID end
56
- def name() self::NAME end
57
- end
58
-
59
- class Method
60
- class << self
61
- FIELDS.each do |f|
62
- class_eval %[
63
- def #{f} name
64
- arguments << [ :#{f}, name ] unless arguments.include?([:#{f}, name])
65
- attr_accessor name
66
- end
67
- ]
68
- end
69
-
70
- def arguments() @arguments ||= [] end
71
-
72
- def parent() Protocol.const_get(self.to_s[/Protocol::(.+?)::/,1]) end
73
- def id() self::ID end
74
- def name() self::NAME end
75
- end
76
-
77
- def == b
78
- self.class.arguments.inject(true) do |eql, (type, name)|
79
- eql and __send__("#{name}") == b.__send__("#{name}")
80
- end
81
- end
82
- end
83
-
84
- def self.methods() @methods ||= {} end
85
-
86
- def self.Method(id, name)
87
- @_base_methods ||= {}
88
- @_base_methods[id] ||= ::Class.new(Method) do
89
- class_eval %[
90
- def self.inherited klass
91
- klass.const_set(:ID, #{id})
92
- klass.const_set(:NAME, :#{name.to_s})
93
- klass.parent.methods[#{id}] = klass
94
- klass.parent.methods[klass::NAME] = klass
95
- end
96
- ]
97
- end
98
- end
99
- end
100
-
101
- def self.classes() @classes ||= {} end
102
-
103
- def self.Class(id, name)
104
- @_base_classes ||= {}
105
- @_base_classes[id] ||= ::Class.new(Class) do
106
- class_eval %[
107
- def self.inherited klass
108
- klass.const_set(:ID, #{id})
109
- klass.const_set(:NAME, :#{name.to_s})
110
- Protocol.classes[#{id}] = klass
111
- Protocol.classes[klass::NAME] = klass
112
- end
113
- ]
114
- end
115
- end
116
-
117
- <%- s['classes'].each do |c| -%>
118
- class <%= c['name'].capitalize.ljust(12) %> < Class(<%= c['id'] %>, :<%= c['name'] %>); end
119
- <%- end -%>
120
-
121
- <%- s['classes'].each do |c| -%>
122
- class <%= c['name'].capitalize %>
123
- <%- c['properties'].each do |p| -%>
124
- <%= p['type'].ljust(10) %> :<%= p['name'].tr('-','_') %>
125
- <%- end if c['properties'] -%>
126
-
127
- <%- c['methods'].each do |m| -%>
128
- class <%= m['name'].capitalize.gsub(/-(.)/){ "#{$1.upcase}"}.ljust(12) %> < Method(<%= m['id'] %>, :<%= m['name'].tr('- ','_') %>); end
129
- <%- end -%>
130
-
131
- <%- c['methods'].each do |m| -%>
132
- class <%= m['name'].capitalize.gsub(/-(.)/){ "#{$1.upcase}"} %>
133
- <%- m['arguments'].each do |a| -%>
134
- <%- if a['domain'] -%>
135
- <%= s['domains'].find{|k,v| k == a['domain']}.last.ljust(10) %> :<%= a['name'].tr('- ','_') %>
136
- <%- else -%>
137
- <%= a['type'].ljust(10) %> :<%= a['name'].tr('- ','_') %>
138
- <%- end -%>
139
- <%- end if m['arguments'] -%>
140
- end
141
-
142
- <%- end -%>
143
- end
144
-
145
- <%- end -%>
146
- end
147
- end
148
- ].gsub!(/^ /,''), nil, '>-%').result(binding)
@@ -1,13 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require File.expand_path("../spec_helper", __FILE__)
4
-
5
- EM.describe "MQ#close(&callback)" do
6
- default_timeout 5
7
-
8
- should "take a callback which will run when we get back Channel.Close-Ok" do
9
- MQ.new.close do |amq|
10
- done
11
- end
12
- end
13
- end
@@ -1,52 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require File.expand_path("../spec_helper", __FILE__)
4
-
5
- EM.describe MQ::Queue do
6
- default_timeout 5
7
-
8
- before do
9
- @mq = MQ.new
10
- end
11
-
12
- # Queue.Declare
13
- should "update MQ::Queue#name by the name generated by the broker" do
14
- @mq.queue("") do |queue, *args|
15
- queue.name.should.not.be.empty
16
- done
17
- end
18
- end
19
-
20
- # PENDING: this spec is currently failing
21
- # https://github.com/tmm1/amqp/issues/issue/31
22
- should "be able to access message count" do
23
- name = Array.new(16) { rand(256) }.pack("C*").unpack("H*").first
24
- exchange = MQ.fanout("fanout")
25
- @mq.queue!(name) do |queue, *args|
26
- queue.bind(exchange) do
27
- 3.times { exchange.publish("foobar") }
28
- # We have 1 channel per 1 MQ instance, so we can just send a sync request
29
- # and once the requst is finished, we can be sure that the previous one is
30
- # finished as well. So we can be sure that all the Basic.Publish actions are done.
31
- @mq.queue!(name) do |queue, message_count, *args|
32
- message_count.should.eql 3
33
- done
34
- end
35
- end
36
- end
37
- end
38
-
39
- # TODO: this will require quite a lot of code, but it should be tested anyway.
40
- # should "be able to access consumer count" do
41
- # end
42
-
43
- # Queue.Bind
44
- should "work with a callback" do
45
- exchange = MQ.fanout("fanout")
46
- @mq.queue("") do |queue, *args|
47
- queue.bind(exchange) do |*args|
48
- done
49
- end
50
- end
51
- end
52
- end