vines 0.3.2 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (115) hide show
  1. data/README +5 -9
  2. data/Rakefile +11 -9
  3. data/conf/config.rb +30 -4
  4. data/lib/vines/cluster/connection.rb +26 -0
  5. data/lib/vines/cluster/publisher.rb +55 -0
  6. data/lib/vines/cluster/pubsub.rb +92 -0
  7. data/lib/vines/cluster/sessions.rb +125 -0
  8. data/lib/vines/cluster/subscriber.rb +108 -0
  9. data/lib/vines/cluster.rb +246 -0
  10. data/lib/vines/command/init.rb +21 -24
  11. data/lib/vines/config/host.rb +48 -8
  12. data/lib/vines/config/port.rb +5 -0
  13. data/lib/vines/config/pubsub.rb +108 -0
  14. data/lib/vines/config.rb +74 -20
  15. data/lib/vines/jid.rb +14 -0
  16. data/lib/vines/router.rb +69 -55
  17. data/lib/vines/stanza/iq/disco_info.rb +22 -9
  18. data/lib/vines/stanza/iq/disco_items.rb +6 -3
  19. data/lib/vines/stanza/iq/ping.rb +1 -1
  20. data/lib/vines/stanza/iq/private_storage.rb +4 -8
  21. data/lib/vines/stanza/iq/roster.rb +6 -14
  22. data/lib/vines/stanza/iq/session.rb +2 -7
  23. data/lib/vines/stanza/iq/vcard.rb +4 -6
  24. data/lib/vines/stanza/iq/version.rb +1 -1
  25. data/lib/vines/stanza/iq.rb +8 -10
  26. data/lib/vines/stanza/presence/subscribe.rb +3 -11
  27. data/lib/vines/stanza/presence/subscribed.rb +16 -29
  28. data/lib/vines/stanza/presence/unsubscribe.rb +3 -15
  29. data/lib/vines/stanza/presence/unsubscribed.rb +3 -16
  30. data/lib/vines/stanza/presence.rb +30 -0
  31. data/lib/vines/stanza/pubsub/create.rb +39 -0
  32. data/lib/vines/stanza/pubsub/delete.rb +41 -0
  33. data/lib/vines/stanza/pubsub/publish.rb +66 -0
  34. data/lib/vines/stanza/pubsub/subscribe.rb +44 -0
  35. data/lib/vines/stanza/pubsub/unsubscribe.rb +30 -0
  36. data/lib/vines/stanza/pubsub.rb +22 -0
  37. data/lib/vines/stanza.rb +72 -22
  38. data/lib/vines/storage/couchdb.rb +46 -65
  39. data/lib/vines/storage/local.rb +20 -14
  40. data/lib/vines/storage/mongodb.rb +132 -0
  41. data/lib/vines/storage/null.rb +39 -0
  42. data/lib/vines/storage/redis.rb +61 -68
  43. data/lib/vines/storage/sql.rb +73 -69
  44. data/lib/vines/storage.rb +1 -1
  45. data/lib/vines/stream/client/bind.rb +2 -2
  46. data/lib/vines/stream/client/session.rb +71 -16
  47. data/lib/vines/stream/component/handshake.rb +1 -0
  48. data/lib/vines/stream/component/ready.rb +2 -2
  49. data/lib/vines/stream/http/session.rb +2 -0
  50. data/lib/vines/stream/http.rb +0 -6
  51. data/lib/vines/stream/server/final_restart.rb +1 -0
  52. data/lib/vines/stream/server/outbound/final_features.rb +1 -0
  53. data/lib/vines/stream/server/ready.rb +6 -2
  54. data/lib/vines/stream/server.rb +4 -3
  55. data/lib/vines/stream.rb +10 -6
  56. data/lib/vines/version.rb +1 -1
  57. data/lib/vines.rb +48 -22
  58. data/test/cluster/publisher_test.rb +45 -0
  59. data/test/cluster/sessions_test.rb +54 -0
  60. data/test/cluster/subscriber_test.rb +94 -0
  61. data/test/config/host_test.rb +100 -21
  62. data/test/config/pubsub_test.rb +181 -0
  63. data/test/config_test.rb +225 -43
  64. data/test/jid_test.rb +7 -0
  65. data/test/router_test.rb +181 -9
  66. data/test/stanza/iq/disco_info_test.rb +8 -6
  67. data/test/stanza/iq/disco_items_test.rb +3 -3
  68. data/test/stanza/iq/private_storage_test.rb +8 -19
  69. data/test/stanza/iq/roster_test.rb +1 -1
  70. data/test/stanza/iq/session_test.rb +3 -6
  71. data/test/stanza/iq/vcard_test.rb +6 -2
  72. data/test/stanza/iq/version_test.rb +3 -2
  73. data/test/stanza/iq_test.rb +5 -5
  74. data/test/stanza/message_test.rb +3 -2
  75. data/test/stanza/presence/probe_test.rb +2 -1
  76. data/test/stanza/pubsub/create_test.rb +138 -0
  77. data/test/stanza/pubsub/delete_test.rb +142 -0
  78. data/test/stanza/pubsub/publish_test.rb +373 -0
  79. data/test/stanza/pubsub/subscribe_test.rb +186 -0
  80. data/test/stanza/pubsub/unsubscribe_test.rb +179 -0
  81. data/test/stanza_test.rb +2 -1
  82. data/test/storage/local_test.rb +26 -25
  83. data/test/storage/mock_mongo.rb +40 -0
  84. data/test/storage/mock_redis.rb +98 -0
  85. data/test/storage/mongodb_test.rb +81 -0
  86. data/test/storage/null_test.rb +30 -0
  87. data/test/storage/redis_test.rb +3 -36
  88. data/test/stream/component/handshake_test.rb +4 -0
  89. data/test/stream/component/ready_test.rb +2 -1
  90. data/test/stream/server/ready_test.rb +7 -1
  91. data/web/404.html +5 -3
  92. data/web/chat/coffeescripts/chat.coffee +9 -5
  93. data/web/chat/javascripts/app.js +1 -1
  94. data/web/chat/javascripts/chat.js +14 -8
  95. data/web/chat/stylesheets/chat.css +4 -1
  96. data/web/lib/coffeescripts/button.coffee +9 -5
  97. data/web/lib/coffeescripts/filter.coffee +1 -1
  98. data/web/lib/coffeescripts/login.coffee +14 -1
  99. data/web/lib/coffeescripts/session.coffee +8 -11
  100. data/web/lib/images/dark-gray.png +0 -0
  101. data/web/lib/images/light-gray.png +0 -0
  102. data/web/lib/images/logo-large.png +0 -0
  103. data/web/lib/images/logo-small.png +0 -0
  104. data/web/lib/images/white.png +0 -0
  105. data/web/lib/javascripts/base.js +9 -8
  106. data/web/lib/javascripts/button.js +20 -12
  107. data/web/lib/javascripts/filter.js +1 -1
  108. data/web/lib/javascripts/icons.js +7 -1
  109. data/web/lib/javascripts/jquery.js +4 -4
  110. data/web/lib/javascripts/login.js +16 -2
  111. data/web/lib/javascripts/raphael.js +5 -7
  112. data/web/lib/javascripts/session.js +10 -14
  113. data/web/lib/stylesheets/base.css +7 -11
  114. data/web/lib/stylesheets/login.css +31 -27
  115. metadata +100 -34
@@ -0,0 +1,181 @@
1
+ # encoding: UTF-8
2
+
3
+ require 'tmpdir'
4
+ require 'vines'
5
+ require 'ext/nokogiri'
6
+ require 'minitest/autorun'
7
+
8
+ class ConfigPubSubTest < MiniTest::Unit::TestCase
9
+ def setup
10
+ @config = Vines::Config.new do
11
+ host 'wonderland.lit' do
12
+ storage(:fs) { dir Dir.tmpdir }
13
+ pubsub 'topics'
14
+ end
15
+ end
16
+ @pubsub = @config.pubsub('topics.wonderland.lit')
17
+ end
18
+
19
+ def test_add_node
20
+ topic = 'rhode_island_is_neither_a_road_nor_an_island'
21
+ refute @pubsub.node?(topic)
22
+ @pubsub.add_node(topic)
23
+ assert @pubsub.node?(topic)
24
+ @pubsub.delete_node(topic)
25
+ refute @pubsub.node?(topic)
26
+ end
27
+
28
+ def test_delete_missing_node
29
+ topic = 'kittens_vs_puppies'
30
+ refute @pubsub.node?(topic)
31
+ @pubsub.delete_node(topic)
32
+ refute @pubsub.node?(topic)
33
+ end
34
+
35
+ def test_subscribe_with_jid
36
+ topic = 'with_jid'
37
+ jid = Vines::JID.new('alice@wonderland.lit')
38
+ @pubsub.add_node(topic)
39
+ @pubsub.subscribe(topic, jid)
40
+ assert @pubsub.subscribed?(topic, jid.to_s)
41
+ assert @pubsub.subscribed?(topic, jid)
42
+ end
43
+
44
+ def test_subscribe_remote_jid_not_allowed
45
+ topic = 'remote_jids_failed'
46
+ jid = 'romeo@verona.lit'
47
+ @pubsub.add_node(topic)
48
+ @pubsub.subscribe(topic, jid)
49
+ refute @pubsub.subscribed?(topic, jid)
50
+ end
51
+
52
+ def test_subscribe_remote_jid_is_allowed
53
+ topic = 'remote_jids_allowed'
54
+ jid = 'romeo@verona.lit'
55
+ @config.vhosts['wonderland.lit'].cross_domain_messages true
56
+ @pubsub.add_node(topic)
57
+ @pubsub.subscribe(topic, jid)
58
+ assert @pubsub.subscribed?(topic, jid)
59
+ end
60
+
61
+ def test_subscribe_missing_node
62
+ topic = 'bogus'
63
+ jid = 'alice@wonderland.lit'
64
+ refute @pubsub.node?(topic)
65
+ @pubsub.subscribe(topic, jid)
66
+ refute @pubsub.node?(topic)
67
+ refute @pubsub.subscribed?(topic, jid)
68
+ end
69
+
70
+ def test_unsubscribe_deletes_node
71
+ topic = 'delete_me'
72
+ jid = 'alice@wonderland.lit/tea'
73
+ @pubsub.add_node(topic)
74
+ @pubsub.subscribe(topic, jid)
75
+ assert @pubsub.subscribed?(topic, jid)
76
+ @pubsub.unsubscribe(topic, jid)
77
+ refute @pubsub.subscribed?(topic, jid)
78
+ refute @pubsub.node?(topic)
79
+ end
80
+
81
+ def test_unsubscribe_all
82
+ topic = 'pirates_vs_ninjas'
83
+ topic2 = 'pirates_vs_ninjas_2'
84
+ jid = 'alice@wonderland.lit'
85
+ jid2 = 'hatter@wonderland.lit'
86
+ @pubsub.add_node(topic)
87
+ @pubsub.add_node(topic2)
88
+
89
+ @pubsub.subscribe(topic, jid)
90
+ @pubsub.subscribe(topic, jid2)
91
+ @pubsub.subscribe(topic2, jid)
92
+ assert @pubsub.subscribed?(topic, jid)
93
+ assert @pubsub.subscribed?(topic, jid2)
94
+ assert @pubsub.subscribed?(topic2, jid)
95
+
96
+ @pubsub.unsubscribe_all(jid)
97
+ refute @pubsub.node?(topic2)
98
+ refute @pubsub.subscribed?(topic, jid)
99
+ refute @pubsub.subscribed?(topic2, jid)
100
+ assert @pubsub.subscribed?(topic, jid2)
101
+ end
102
+
103
+ def test_publish
104
+ topic = 'pirates_vs_ninjas'
105
+ alice = Vines::JID.new('alice@wonderland.lit')
106
+ romeo = Vines::JID.new('romeo@verona.lit')
107
+
108
+ @config.vhosts['wonderland.lit'].cross_domain_messages true
109
+ def @config.router
110
+ unless @mock_router
111
+ @mock_router = MiniTest::Mock.new
112
+ def @mock_router.nodes; @nodes; end
113
+ def @mock_router.route(node)
114
+ @nodes ||= []
115
+ @nodes << node
116
+ end
117
+ end
118
+ @mock_router
119
+ end
120
+
121
+ recipient = recipient(alice)
122
+ @config.router.expect(:connected_resources, [recipient], [alice, 'topics.wonderland.lit'])
123
+
124
+ @pubsub.add_node(topic)
125
+ @pubsub.subscribe(topic, alice)
126
+ @pubsub.subscribe(topic, romeo)
127
+ assert @pubsub.subscribed?(topic, alice)
128
+ assert @pubsub.subscribed?(topic, romeo)
129
+
130
+ node = node(%q{
131
+ <iq type='set' to='topics.wonderland.lit'>
132
+ <pubsub xmlns='http://jabber.org/protocol/pubsub'>
133
+ <publish node='pirates_vs_ninjas'>
134
+ <item id='item_42'>
135
+ <entry xmlns='http://www.w3.org/2005/Atom'>
136
+ <title>Test</title>
137
+ <summary>This is a summary.</summary>
138
+ </entry>
139
+ </item>
140
+ </publish>
141
+ </pubsub>
142
+ </iq>
143
+ }.strip.gsub(/\n|\s{2,}/, ''))
144
+ expected = node.clone
145
+
146
+ @pubsub.publish(topic, node)
147
+
148
+ assert @config.router.verify
149
+ assert recipient.verify
150
+
151
+ # id is random
152
+ refute_nil recipient.nodes[0]['id']
153
+ refute_nil @config.router.nodes[0]['id']
154
+ recipient.nodes[0].remove_attribute('id')
155
+ @config.router.nodes[0].remove_attribute('id')
156
+
157
+ expected['to'] = 'alice@wonderland.lit'
158
+ expected['from'] = 'topics.wonderland.lit'
159
+ assert_equal expected, recipient.nodes[0]
160
+
161
+ expected['to'] = 'romeo@verona.lit'
162
+ assert_equal expected, @config.router.nodes[0]
163
+ end
164
+
165
+ private
166
+
167
+ def recipient(jid)
168
+ recipient = MiniTest::Mock.new
169
+ recipient.expect(:user, Vines::User.new(jid: jid))
170
+ def recipient.nodes; @nodes; end
171
+ def recipient.write(node)
172
+ @nodes ||= []
173
+ @nodes << node
174
+ end
175
+ recipient
176
+ end
177
+
178
+ def node(xml)
179
+ Nokogiri::XML(xml).root
180
+ end
181
+ end