nutella_lib 0.3.1 → 0.4.0

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,104 @@
1
+ require 'helper'
2
+
3
+ class TestNutellaNetApp < MiniTest::Test
4
+
5
+ # nutella.init_as_app_component('localhost', 'my_app_id', 'my_component_id')
6
+ #
7
+ # def test_app_send_receive
8
+ # cb_executed = false
9
+ # cb = lambda do |message, from|
10
+ # cb_executed = true
11
+ # puts "Received message from #{from['component_id']}/#{from['resource_id']}. Message: #{message}"
12
+ # end
13
+ # nutella.net.app.subscribe('demo0', cb)
14
+ # sleep 1
15
+ # nutella.net.app.publish('demo0', 'test_message')
16
+ # # Make sure we wait for the message to be delivered
17
+ # sleep 1
18
+ # assert cb_executed
19
+ # end
20
+ #
21
+ #
22
+ # def test_app_send_receive_wildcard
23
+ # cb_executed = false
24
+ # nutella.set_resource_id 'my_resource_id_1'
25
+ # cb = lambda do |message, channel, from|
26
+ # cb_executed = true
27
+ # puts "Received message on #{channel} from #{from['component_id']}/#{from['resource_id']}. Message: #{message}"
28
+ # end
29
+ # nutella.net.app.subscribe('demo1/#', cb)
30
+ # sleep 1
31
+ # nutella.net.app.publish('demo1/demo', 'test_message')
32
+ # # Make sure we wait for the message to be delivered
33
+ # sleep 1
34
+ # assert cb_executed
35
+ # end
36
+ #
37
+ #
38
+ # def test_multiple_subscriptions
39
+ # nutella.set_resource_id 'my_resource_id_2'
40
+ # cb = lambda do |message, from|
41
+ # puts "Received message #{from['component_id']}/#{from['resource_id']}. Message: #{message}"
42
+ # end
43
+ # assert_raises RuntimeError do
44
+ # nutella.net.app.subscribe('demo2', cb)
45
+ # nutella.net.app.subscribe('demo2', cb)
46
+ # end
47
+ # nutella.net.app.unsubscribe('demo2')
48
+ # nutella.net.app.subscribe('demo2', cb)
49
+ # end
50
+ #
51
+ #
52
+ # def test_request_response
53
+ # nutella.set_resource_id 'my_resource_id_3'
54
+ #
55
+ # nutella.net.app.subscribe('demo3', lambda do |message, from|
56
+ # puts "Received a message from #{from['component_id']}/#{from['resource_id']}. Message: #{message}"
57
+ # end)
58
+ #
59
+ # nutella.net.app.handle_requests( 'demo3', lambda do |message, from|
60
+ # puts "We received a request: message #{message}, from #{from['component_id']}/#{from['resource_id']}."
61
+ # #Then we are going to return some random JSON
62
+ # {my:'json'}
63
+ # end)
64
+ #
65
+ # response = nutella.net.app.sync_request( 'demo3', 'my request is a string' )
66
+ # assert_equal({'my' => 'json'}, response)
67
+ #
68
+ # nutella.net.app.async_request( 'demo3', 'my request is a string', lambda do |response|
69
+ # assert_equal({'my' => 'json'}, response)
70
+ # end)
71
+ #
72
+ # sleep(2)
73
+ # end
74
+ #
75
+ # def test_app_run_pub_sub_all
76
+ # nutella.set_resource_id 'my_resource_id_5'
77
+ # cb = lambda do |message, run_id, from|
78
+ # puts "Received message from run_id #{from['run_id']} on #{run_id}. Message: #{message}"
79
+ # nutella.net.app.unsubscribe_from_all_runs 'demo5'
80
+ # end
81
+ # nutella.net.app.subscribe_to_all_runs('demo5', cb)
82
+ # sleep 1
83
+ # nutella.net.app.publish_to_all_runs('demo5', 'test_message')
84
+ # # Make sure we wait for the message to be delivered
85
+ # sleep 2
86
+ # end
87
+ #
88
+ # def test_app_run_req_res_all
89
+ # nutella.set_resource_id 'my_resource_id_6'
90
+ #
91
+ # nutella.net.app.handle_requests_on_all_runs('demo6', lambda do |message, run_id, from|
92
+ # puts "We received a request: message '#{message}', on run_id #{run_id} from #{from}."
93
+ # 'response' # Return something
94
+ # end)
95
+ # sleep 1
96
+ # nutella.net.app.async_request_to_all_runs('demo6', 'my request is a string', lambda do |response|
97
+ # puts response
98
+ # end)
99
+ # sleep 2
100
+ # end
101
+
102
+ # TODO do more tests for app to run APIs and broadcasting
103
+
104
+ end
@@ -2,6 +2,7 @@ require 'helper'
2
2
 
3
3
  class TestSimpleRubyMqttClient < MiniTest::Test
4
4
 
5
+
5
6
  # def test_connect_and_send_receive_messages_correctly
6
7
  # cb_executed = false
7
8
  # sc1 = SimpleMQTTClient.new 'ltg.evl.uic.edu'
@@ -19,6 +20,7 @@ class TestSimpleRubyMqttClient < MiniTest::Test
19
20
  # assert cb_executed
20
21
  # end
21
22
  #
23
+ #
22
24
  # def test_list_current_subscriptions_correctly
23
25
  # sc3 = SimpleMQTTClient.new 'ltg.evl.uic.edu'
24
26
  # cb2 = lambda {|message| puts message}
@@ -32,14 +34,16 @@ class TestSimpleRubyMqttClient < MiniTest::Test
32
34
  # assert_equal sc3.get_subscribed_channels['channel_3'].length, 1
33
35
  # end
34
36
  #
37
+ #
35
38
  # def test_recognize_wildcard_patters_correctly
36
39
  # sc4 = SimpleMQTTClient.new 'ltg.evl.uic.edu'
37
40
  # sc4.subscribe('run_id/#', lambda {|m| puts m})
38
41
  # refute_nil sc4.send(:get_callbacks, 'run_id/one')
39
42
  # refute_nil sc4.send(:get_callbacks, 'run_id/one/two')
40
43
  # end
41
- #
42
- # def test_multiple_subscriptions
44
+
45
+
46
+ # def test_multiple_simple_subscriptions
43
47
  # sc5 = SimpleMQTTClient.new 'ltg.evl.uic.edu'
44
48
  # total = 0
45
49
  # cb1 = lambda { |message| total += 3; puts "CB1: #{message}"}
@@ -52,4 +56,48 @@ class TestSimpleRubyMqttClient < MiniTest::Test
52
56
  # sleep(1)
53
57
  # assert_equal total, 4
54
58
  # end
59
+
60
+
61
+ # def test_multiple_mixed_subscriptions
62
+ # sc6 = SimpleMQTTClient.new 'ltg.evl.uic.edu'
63
+ # total = 0
64
+ # cba = lambda { |message| total += 1; puts "CBA: #{message}"}
65
+ # cbb = lambda { |message| total += 2; puts "CBB: #{message}"}
66
+ # cbc = lambda { |message| total += 3; puts "CBC: #{message}"}
67
+ # sc6.subscribe('demo4/demo5/demo6', cba)
68
+ # sc6.subscribe('demo4/demo5/#', cbb)
69
+ # sc6.subscribe('demo4/+/demo6', cbc)
70
+ # sc7 = SimpleMQTTClient.new 'ltg.evl.uic.edu'
71
+ # sc7.publish('demo4/demo5/demo6', 'test-message-3')
72
+ # # Make sure we wait for the message to be delivered
73
+ # sleep(1)
74
+ # assert_equal total, 6
75
+ # end
76
+
77
+
78
+ # def test_wildcard_regex
79
+ # sc7 = SimpleMQTTClient.new 'ltg.evl.uic.edu'
80
+ # # Multi-level
81
+ # assert sc7.send :matches_wildcard_pattern, '/any/channel', '#'
82
+ # assert sc7.send :matches_wildcard_pattern, 'any/channel', '#'
83
+ # assert sc7.send :matches_wildcard_pattern, '', '#'
84
+ # assert sc7.send :matches_wildcard_pattern, '/a/channel', '/a/#'
85
+ # # One single-level
86
+ # assert sc7.send :matches_wildcard_pattern, 'a_channel', '+'
87
+ # assert sc7.send :matches_wildcard_pattern, '/a_channel', '/+'
88
+ # assert sc7.send :matches_wildcard_pattern, 'a/channel', 'a/+'
89
+ # assert sc7.send :matches_wildcard_pattern, 'a/channel', '+/channel'
90
+ # assert sc7.send :matches_wildcard_pattern, '/a/channel', '/+/channel'
91
+ # assert sc7.send :matches_wildcard_pattern, '/a/channel/yup', '/a/+/yup'
92
+ # # Two single-level
93
+ # assert sc7.send :matches_wildcard_pattern, 'a/channel', '+/+'
94
+ # assert sc7.send :matches_wildcard_pattern, '/a/channel', '/+/+'
95
+ # assert sc7.send :matches_wildcard_pattern, '/a/channel/yup', '/+/+/yup'
96
+ # # Mix, Multi-level, one single level
97
+ # assert sc7.send :matches_wildcard_pattern, '/a/channel/yup', '/+/channel/#'
98
+ # # Mix, Multi-level, two single level
99
+ # assert sc7.send :matches_wildcard_pattern, '/a/channel/yup/another', '/+/+/yup/#'
100
+ # end
101
+
102
+
55
103
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nutella_lib
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alessandro Gnoli
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-02-17 00:00:00.000000000 Z
11
+ date: 2015-03-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mqtt
@@ -189,12 +189,14 @@ files:
189
189
  - lib/nutella_lib/core.rb
190
190
  - lib/nutella_lib/ext/kernel.rb
191
191
  - lib/nutella_lib/net.rb
192
+ - lib/nutella_lib/net_app.rb
192
193
  - lib/nutella_lib/noext.rb
193
194
  - lib/nutella_lib/persist.rb
194
195
  - lib/simple_mqtt_client/simple_mqtt_client.rb
195
196
  - nutella_lib.gemspec
196
197
  - test/helper.rb
197
- - test/test_nutella_lib.rb
198
+ - test/test_nutella_net.rb
199
+ - test/test_nutella_net_app.rb
198
200
  - test/test_simple_mqtt_client.rb
199
201
  homepage: https://github.com/nutella-framework/nutella_lib.rb
200
202
  licenses:
@@ -216,7 +218,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
216
218
  version: '0'
217
219
  requirements: []
218
220
  rubyforge_project:
219
- rubygems_version: 2.2.2
221
+ rubygems_version: 2.4.3
220
222
  signing_key:
221
223
  specification_version: 4
222
224
  summary: nutella protocol library for ruby
@@ -1,78 +0,0 @@
1
- require 'helper'
2
-
3
- class TestNutellaLib < MiniTest::Test
4
-
5
-
6
- # def test_connect_and_send_receive_messages_correctly
7
- # cb_executed = false
8
- # nutella.init('my_run_id', 'ltg.evl.uic.edu', 'my_bot_component')
9
- # nutella.set_resource_id 'my_resource_id'
10
- # cb = lambda do |message, component_id, resource_id|
11
- # cb_executed = true
12
- # puts "Received message from #{component_id}/#{resource_id}. Message: #{message}"
13
- # end
14
- # nutella.net.subscribe('demo1', cb)
15
- # sleep 1
16
- # nutella.net.publish('demo1', 'test_message')
17
- # # Make sure we wait for the message to be delivered
18
- # sleep 1
19
- # assert cb_executed
20
- # end
21
- #
22
- #
23
- # def test_connect_and_send_receive_wildcard_messages_correctly
24
- # cb_executed = false
25
- # nutella.init('my_run_id', 'ltg.evl.uic.edu', 'my_bot_component')
26
- # nutella.set_resource_id 'my_resource_id'
27
- # cb = lambda do |message, channel, component_id, resource_id|
28
- # cb_executed = true
29
- # puts "Received message on #{channel} from #{component_id}/#{resource_id}. Message: #{message}"
30
- # end
31
- # nutella.net.subscribe('demo1/#', cb)
32
- # sleep 1
33
- # nutella.net.publish('demo1/demo', 'test_message')
34
- # # Make sure we wait for the message to be delivered
35
- # sleep 1
36
- # assert cb_executed
37
- # end
38
-
39
-
40
- # def test_multiple_subscriptions
41
- # nutella.init('my_run_id', 'ltg.evl.uic.edu', 'my_bot_component')
42
- # nutella.set_resource_id 'my_resource_id'
43
- # cb = lambda do |message, component_id, resource_id|
44
- # puts "Received message #{component_id}/#{resource_id}. Message: #{message}"
45
- # end
46
- # nutella.net.subscribe('demo1', cb)
47
- # nutella.net.subscribe('demo1', cb) # This must raise an error
48
- # end
49
-
50
-
51
- def test_request_response
52
- nutella.init('my_run_id', 'ltg.evl.uic.edu', 'my_bot_component')
53
- nutella.set_resource_id 'my_resource_id'
54
-
55
- nutella.net.subscribe('demo1', lambda do |message, component_id, resource_id|
56
- puts "Received a message from #{component_id}/#{resource_id}. Message: #{message}"
57
- end)
58
-
59
- nutella.net.handle_requests( 'demo1', lambda do |message, component_id, resource_id|
60
- puts "We received a request: message #{message}, from #{component_id}/#{resource_id}"
61
- #Then we are going to return some JSON
62
- {my:'json'}
63
- end)
64
-
65
- response = nutella.net.sync_request( 'demo1', 'my request is a string' )
66
- puts 'Response to sync'
67
- p response
68
-
69
- nutella.net.async_request( 'demo1', 'my request is a string', lambda do |response|
70
- puts 'Response to async'
71
- p response
72
- end)
73
-
74
- nutella.net.listen
75
- end
76
-
77
-
78
- end