omf_common 6.0.0.pre.10 → 6.0.0.pre.11

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. data/bin/monitor_topic.rb +80 -0
  2. data/bin/send_create.rb +94 -0
  3. data/bin/send_request.rb +58 -0
  4. data/example/engine_alt.rb +136 -0
  5. data/example/vm_alt.rb +65 -0
  6. data/lib/omf_common.rb +224 -3
  7. data/lib/omf_common/comm.rb +113 -46
  8. data/lib/omf_common/comm/amqp/amqp_communicator.rb +76 -0
  9. data/lib/omf_common/comm/amqp/amqp_topic.rb +91 -0
  10. data/lib/omf_common/comm/local/local_communicator.rb +64 -0
  11. data/lib/omf_common/comm/local/local_topic.rb +42 -0
  12. data/lib/omf_common/comm/topic.rb +190 -0
  13. data/lib/omf_common/{dsl/xmpp.rb → comm/xmpp/communicator.rb} +93 -53
  14. data/lib/omf_common/comm/xmpp/topic.rb +147 -0
  15. data/lib/omf_common/{dsl → comm/xmpp}/xmpp_mp.rb +2 -0
  16. data/lib/omf_common/eventloop.rb +94 -0
  17. data/lib/omf_common/eventloop/em.rb +57 -0
  18. data/lib/omf_common/eventloop/local_evl.rb +78 -0
  19. data/lib/omf_common/message.rb +112 -229
  20. data/lib/omf_common/message/json/json_message.rb +129 -0
  21. data/lib/omf_common/message/xml/message.rb +410 -0
  22. data/lib/omf_common/message/xml/relaxng_schema.rb +17 -0
  23. data/lib/omf_common/message/xml/topic_message.rb +20 -0
  24. data/lib/omf_common/protocol/6.0.rnc +11 -21
  25. data/lib/omf_common/protocol/6.0.rng +52 -119
  26. data/lib/omf_common/version.rb +1 -1
  27. data/omf_common.gemspec +4 -2
  28. data/test/fixture/pubsub.rb +19 -19
  29. data/test/omf_common/{dsl/xmpp_spec.rb → comm/xmpp/communicator_spec.rb} +47 -111
  30. data/test/omf_common/comm/xmpp/topic_spec.rb +113 -0
  31. data/test/omf_common/comm_spec.rb +1 -0
  32. data/test/omf_common/message/xml/message_spec.rb +136 -0
  33. data/test/omf_common/message_spec.rb +37 -131
  34. data/test/test_helper.rb +4 -1
  35. metadata +38 -28
  36. data/lib/omf_common/core_ext/object.rb +0 -21
  37. data/lib/omf_common/relaxng_schema.rb +0 -17
  38. data/lib/omf_common/topic.rb +0 -34
  39. data/lib/omf_common/topic_message.rb +0 -20
  40. data/test/omf_common/topic_message_spec.rb +0 -114
  41. data/test/omf_common/topic_spec.rb +0 -75
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: omf_common
3
3
  version: !ruby/object:Gem::Version
4
- version: 6.0.0.pre.10
4
+ version: 6.0.0.pre.11
5
5
  prerelease: 6
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-01-07 00:00:00.000000000 Z
12
+ date: 2013-03-18 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: minitest
@@ -82,7 +82,7 @@ dependencies:
82
82
  requirements:
83
83
  - - '='
84
84
  - !ruby/object:Gem::Version
85
- version: 0.8.0
85
+ version: 0.8.1
86
86
  type: :runtime
87
87
  prerelease: false
88
88
  version_requirements: !ruby/object:Gem::Requirement
@@ -90,7 +90,7 @@ dependencies:
90
90
  requirements:
91
91
  - - '='
92
92
  - !ruby/object:Gem::Version
93
- version: 0.8.0
93
+ version: 0.8.1
94
94
  - !ruby/object:Gem::Dependency
95
95
  name: logging
96
96
  requirement: !ruby/object:Gem::Requirement
@@ -143,43 +143,61 @@ description: Common library of OMF, a generic framework for controlling and mana
143
143
  networking testbeds.
144
144
  email:
145
145
  - omf-user@lists.nicta.com.au
146
- executables: []
146
+ executables:
147
+ - monitor_topic.rb
148
+ - send_create.rb
149
+ - send_request.rb
147
150
  extensions: []
148
151
  extra_rdoc_files: []
149
152
  files:
150
153
  - .gitignore
151
154
  - Gemfile
152
155
  - Rakefile
156
+ - bin/monitor_topic.rb
157
+ - bin/send_create.rb
158
+ - bin/send_request.rb
159
+ - example/engine_alt.rb
160
+ - example/vm_alt.rb
153
161
  - lib/omf_common.rb
154
162
  - lib/omf_common/comm.rb
163
+ - lib/omf_common/comm/amqp/amqp_communicator.rb
164
+ - lib/omf_common/comm/amqp/amqp_topic.rb
165
+ - lib/omf_common/comm/local/local_communicator.rb
166
+ - lib/omf_common/comm/local/local_topic.rb
167
+ - lib/omf_common/comm/topic.rb
168
+ - lib/omf_common/comm/xmpp/communicator.rb
169
+ - lib/omf_common/comm/xmpp/topic.rb
170
+ - lib/omf_common/comm/xmpp/xmpp_mp.rb
155
171
  - lib/omf_common/command.rb
156
- - lib/omf_common/core_ext/object.rb
157
172
  - lib/omf_common/core_ext/string.rb
158
173
  - lib/omf_common/default_logging.rb
159
- - lib/omf_common/dsl/xmpp.rb
160
- - lib/omf_common/dsl/xmpp_mp.rb
174
+ - lib/omf_common/eventloop.rb
175
+ - lib/omf_common/eventloop/em.rb
176
+ - lib/omf_common/eventloop/local_evl.rb
161
177
  - lib/omf_common/exec_app.rb
162
178
  - lib/omf_common/key.rb
163
179
  - lib/omf_common/measure.rb
164
180
  - lib/omf_common/message.rb
181
+ - lib/omf_common/message/json/json_message.rb
182
+ - lib/omf_common/message/xml/message.rb
183
+ - lib/omf_common/message/xml/relaxng_schema.rb
184
+ - lib/omf_common/message/xml/topic_message.rb
165
185
  - lib/omf_common/protocol/6.0.rnc
166
186
  - lib/omf_common/protocol/6.0.rng
167
- - lib/omf_common/relaxng_schema.rb
168
- - lib/omf_common/topic.rb
169
- - lib/omf_common/topic_message.rb
170
187
  - lib/omf_common/version.rb
171
188
  - omf_common.gemspec
172
189
  - test/fixture/pubsub.rb
190
+ - test/omf_common/comm/xmpp/communicator_spec.rb
191
+ - test/omf_common/comm/xmpp/topic_spec.rb
173
192
  - test/omf_common/comm_spec.rb
174
193
  - test/omf_common/command_spec.rb
175
194
  - test/omf_common/core_ext/string_spec.rb
176
- - test/omf_common/dsl/xmpp_spec.rb
195
+ - test/omf_common/message/xml/message_spec.rb
177
196
  - test/omf_common/message_spec.rb
178
- - test/omf_common/topic_message_spec.rb
179
- - test/omf_common/topic_spec.rb
180
197
  - test/test_helper.rb
181
- homepage: https://www.mytestbed.net
182
- licenses: []
198
+ homepage: http://omf.mytestbed.net
199
+ licenses:
200
+ - MIT
183
201
  post_install_message:
184
202
  rdoc_options: []
185
203
  require_paths:
@@ -189,7 +207,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
189
207
  requirements:
190
208
  - - ! '>='
191
209
  - !ruby/object:Gem::Version
192
- version: '0'
210
+ version: 1.9.3
193
211
  required_rubygems_version: !ruby/object:Gem::Requirement
194
212
  none: false
195
213
  requirements:
@@ -198,17 +216,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
198
216
  version: 1.3.1
199
217
  requirements: []
200
218
  rubyforge_project: omf_common
201
- rubygems_version: 1.8.24
219
+ rubygems_version: 1.8.25
202
220
  signing_key:
203
221
  specification_version: 3
204
222
  summary: Common library of OMF
205
- test_files:
206
- - test/fixture/pubsub.rb
207
- - test/omf_common/comm_spec.rb
208
- - test/omf_common/command_spec.rb
209
- - test/omf_common/core_ext/string_spec.rb
210
- - test/omf_common/dsl/xmpp_spec.rb
211
- - test/omf_common/message_spec.rb
212
- - test/omf_common/topic_message_spec.rb
213
- - test/omf_common/topic_spec.rb
214
- - test/test_helper.rb
223
+ test_files: []
224
+ has_rdoc:
@@ -1,21 +0,0 @@
1
- class Object
2
- def stub name, val_or_callable, &block
3
- new_name = "__minitest_stub__#{name}"
4
- metaclass = class << self; self; end
5
- metaclass.send :alias_method, new_name, name
6
- metaclass.send :define_method, name do |*args, &stub_block|
7
- if val_or_callable.respond_to? :call then
8
- val_or_callable.call(*args, &stub_block)
9
- else
10
- val_or_callable
11
- end
12
- end
13
- yield self
14
- ensure
15
- metaclass.send :undef_method, name
16
- metaclass.send :alias_method, name, new_name
17
- metaclass.send :undef_method, new_name
18
- end
19
- end
20
-
21
-
@@ -1,17 +0,0 @@
1
- require 'singleton'
2
-
3
- module OmfCommon
4
- class RelaxNGSchema
5
- include Singleton
6
-
7
- SCHEMA_FILE = "#{File.dirname(__FILE__)}/protocol/#{OmfCommon::PROTOCOL_VERSION}.rng"
8
-
9
- attr_accessor :schema
10
-
11
- def initialize
12
- File.open(SCHEMA_FILE) do |f|
13
- self.schema = Nokogiri::XML::RelaxNG(f.read)
14
- end
15
- end
16
- end
17
- end
@@ -1,34 +0,0 @@
1
- module OmfCommon
2
- class Topic
3
- attr_accessor :id, :comm
4
-
5
- def initialize(id, comm)
6
- self.id ||= id
7
- self.comm ||= comm
8
- end
9
-
10
- def subscribe(&block)
11
- comm.subscribe(id, &block)
12
- end
13
-
14
- def on_message(message_guard_proc = nil, &message_block)
15
- event_block = proc do |event|
16
- message_block.call(Message.parse(event.items.first.payload))
17
- end
18
- guard_block = proc do |event|
19
- (event.items?) && (!event.delayed?) &&
20
- event.items.first.payload &&
21
- (omf_message = Message.parse(event.items.first.payload)) &&
22
- event.node == self.id &&
23
- (valid_guard?(message_guard_proc) ? message_guard_proc.call(omf_message) : true)
24
- end
25
- comm.topic_event(guard_block, &event_block)
26
- end
27
-
28
- private
29
-
30
- def valid_guard?(guard_proc)
31
- guard_proc && guard_proc.class == Proc
32
- end
33
- end
34
- end
@@ -1,20 +0,0 @@
1
- module OmfCommon
2
- class TopicMessage
3
- attr_accessor :body, :comm
4
-
5
- def initialize(body, comm)
6
- self.body ||= body
7
- self.comm ||= comm
8
- end
9
-
10
- def publish(topic_id, &block)
11
- comm.publish(topic_id, body.dup, &block)
12
- end
13
-
14
- %w(created status failed released).each do |inform_type|
15
- define_method("on_inform_#{inform_type}") do |*args, &message_block|
16
- comm.send("on_#{inform_type}_message", body, &message_block)
17
- end
18
- end
19
- end
20
- end
@@ -1,114 +0,0 @@
1
- require 'test_helper'
2
- require 'fixture/pubsub'
3
- require 'em/minitest/spec'
4
-
5
- include OmfCommon
6
-
7
- describe OmfCommon::Topic do
8
- before do
9
- @client = Blather::Client.new
10
- @stream = MiniTest::Mock.new
11
- @stream.expect(:send, true, [Blather::Stanza])
12
- @client.post_init @stream, Blather::JID.new('n@d/r')
13
- @comm = Comm.new(:xmpp)
14
- @topic = @comm.get_topic('mclaren')
15
- @message = @comm.request_message([:bob])
16
- end
17
-
18
- describe "when topic message object initialised" do
19
- include EM::MiniTest::Spec
20
-
21
- it "must be able to publish to a topic" do
22
- Blather::Client.stub :new, @client do
23
- published = Blather::XMPPNode.parse(published_xml)
24
- write_callback = proc do |event|
25
- event.must_be_kind_of Blather::Stanza::PubSub::Publish
26
- event.node.must_equal @topic.id
27
- published.id = event.id
28
- @client.receive_data published
29
- end
30
- @client.stub :write, write_callback do
31
- @message.publish(@topic.id) do |event|
32
- event.must_equal published
33
- end
34
-
35
- # Can publish again
36
- @message.publish(@topic.id) do |event|
37
- event.must_equal published
38
- done!
39
- end
40
- end
41
- end
42
- wait!
43
- end
44
-
45
- end
46
-
47
- describe "when message with same context id arrived " do
48
- include EM::MiniTest::Spec
49
-
50
- it "must react to omf created message" do
51
- Blather::Client.stub :new, @client do
52
- omf_create = @comm.create_message { |v| v.property('type', 'engine') }
53
- omf_create.body.stub :msg_id, "bf840fe9-c176-4fae-b7de-6fc27f183f76" do
54
- omf_created = Blather::XMPPNode.parse(omf_created_xml)
55
- @client.receive_data omf_created
56
- omf_create.on_inform_created do |n|
57
- n.context_id.must_equal "bf840fe9-c176-4fae-b7de-6fc27f183f76"
58
- n.must_equal Message.parse(omf_created.items.first.payload)
59
- done!
60
- end
61
- end
62
- end
63
- wait!
64
- end
65
-
66
- it "must react to omf status message" do
67
- Blather::Client.stub :new, @client do
68
- omf_request = @comm.request_message { |v| v.property('bob') }
69
- omf_request.body.stub :msg_id, "bf840fe9-c176-4fae-b7de-6fc27f183f76" do
70
- omf_status = Blather::XMPPNode.parse(omf_status_xml)
71
- @client.receive_data omf_status
72
- omf_request.on_inform_status do |n|
73
- n.context_id.must_equal "bf840fe9-c176-4fae-b7de-6fc27f183f76"
74
- n.must_equal Message.parse(omf_status.items.first.payload)
75
- done!
76
- end
77
- end
78
- end
79
- wait!
80
- end
81
-
82
- it "must react to omf release message" do
83
- Blather::Client.stub :new, @client do
84
- omf_release = @comm.release_message { |v| v.property('resource_id', '100') }
85
- omf_release.body.stub :msg_id, "bf840fe9-c176-4fae-b7de-6fc27f183f76" do
86
- omf_released = Blather::XMPPNode.parse(omf_released_xml)
87
- @client.receive_data omf_released
88
- omf_release.on_inform_released do |n|
89
- n.context_id.must_equal "bf840fe9-c176-4fae-b7de-6fc27f183f76"
90
- n.must_equal Message.parse(omf_released.items.first.payload)
91
- done!
92
- end
93
- end
94
- end
95
- wait!
96
- end
97
-
98
- it "must react to omf failed message" do
99
- Blather::Client.stub :new, @client do
100
- omf_create = @comm.create_message { |v| v.property('type', 'engine') }
101
- omf_create.body.stub :msg_id, "bf840fe9-c176-4fae-b7de-6fc27f183f76" do
102
- omf_failed = Blather::XMPPNode.parse(omf_failed_xml)
103
- @client.receive_data omf_failed
104
- omf_create.on_inform_failed do |n|
105
- n.context_id.must_equal "bf840fe9-c176-4fae-b7de-6fc27f183f76"
106
- n.must_equal Message.parse(omf_failed.items.first.payload)
107
- done!
108
- end
109
- end
110
- end
111
- wait!
112
- end
113
- end
114
- end
@@ -1,75 +0,0 @@
1
- require 'test_helper'
2
- require 'fixture/pubsub'
3
- require 'em/minitest/spec'
4
-
5
- include OmfCommon
6
-
7
- describe OmfCommon::Topic do
8
- before do
9
- @client = Blather::Client.new
10
- @stream = MiniTest::Mock.new
11
- @stream.expect(:send, true, [Blather::Stanza])
12
- @client.post_init @stream, Blather::JID.new('n@d/r')
13
- @comm = Comm.new(:xmpp)
14
- @topic = @comm.get_topic('mclaren')
15
- end
16
-
17
- describe "when topic object initialised" do
18
- include EM::MiniTest::Spec
19
-
20
- it "must be able to subscribe" do
21
- Blather::Client.stub :new, @client do
22
- subscription = Blather::XMPPNode.parse(subscription_xml)
23
- write_callback = proc do |event|
24
- event.must_be_kind_of Blather::Stanza::PubSub::Subscribe
25
- event.node.must_equal 'mclaren'
26
- subscription.id = event.id
27
- subscription.node = event.node
28
- @client.receive_data subscription
29
- end
30
- @client.stub :write, write_callback do
31
- @topic.subscribe do |e|
32
- e.must_equal subscription
33
- e.node.must_equal 'mclaren'
34
- done!
35
- end
36
- end
37
- end
38
- wait!
39
- end
40
-
41
- it "must react when message arrived" do
42
- Blather::Client.stub :new, @client do
43
- omf_status = Blather::XMPPNode.parse(omf_status_xml)
44
- @client.receive_data omf_status
45
- @topic.on_message do |n|
46
- n.must_equal Message.parse(omf_status.items.first.payload)
47
- done!
48
- end
49
-
50
- invalid_topic = @comm.get_topic('bob')
51
- invalid_topic.on_message do |n|
52
- raise 'Wont come here'
53
- end
54
- end
55
- wait!
56
- end
57
-
58
- it "must react when certain messages arrived, specified by guards" do
59
- Blather::Client.stub :new, @client do
60
- omf_status = Blather::XMPPNode.parse(omf_status_xml)
61
- @client.receive_data omf_status
62
- @topic.on_message proc { |message| message.context_id == 'bob' } do |n|
63
- raise 'Wont come here'
64
- end
65
-
66
- @topic.on_message proc { |message| message.context_id == "bf840fe9-c176-4fae-b7de-6fc27f183f76" } do |n|
67
- n.must_equal Message.parse(omf_status.items.first.payload)
68
- n.context_id.must_equal "bf840fe9-c176-4fae-b7de-6fc27f183f76"
69
- done!
70
- end
71
- end
72
- wait!
73
- end
74
- end
75
- end