redpack 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/AUTHORS ADDED
@@ -0,0 +1,4 @@
1
+ Austin Chau <austin _at_ luxdelux.com>
2
+ Dean Mao <dean _at_ luxdelux.com>
3
+ Furuhashi Sadayuki <frsyuki _at_ users.sourceforge.jp>
4
+ Jason Cooper <jason _at_ luxdelux.com>
data/LICENSE ADDED
@@ -0,0 +1,14 @@
1
+ Copyright [2010] [FURUHASHI Sadayuki]
2
+ Copyright [2010] [Lux Delux Inc]
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
data/NOTICE ADDED
@@ -0,0 +1,14 @@
1
+ Redpack for Ruby/Node/Java is developed by Lux Delux Inc by modifying
2
+ MessagePack-RPC for the purposes of running on top of Redis queues.
3
+ Currently there are modifications that are not completely backwards
4
+ compatible with the original MsgPack-RPC spec so we are making this a
5
+ separate project under the same license.
6
+
7
+ MessagePack-RPC for Ruby is developed by FURUHASHI Sadayuki, licensed under
8
+ Apache License, Version 2.0. The original software and related information
9
+ is available at http://msgpack.sourceforge.net/.
10
+
11
+ MessagePack is developed by FURUHASHI Sadayuki, licensed under Apache License,
12
+ Version 2.0. The original software and related information is available at
13
+ http://msgpack.sourceforge.net/.
14
+
@@ -0,0 +1,286 @@
1
+ #!/usr/bin/env ruby
2
+ require File.dirname(__FILE__) + '/test_helper.rb'
3
+
4
+ $port = 65500
5
+
6
+ class MessagePackRPCTest < Test::Unit::TestCase
7
+
8
+ class MyServer
9
+ def initialize(svr)
10
+ @svr = svr
11
+ end
12
+
13
+ def hello
14
+ "ok"
15
+ end
16
+
17
+ def sum(a, b)
18
+ a + b
19
+ end
20
+
21
+ def exception
22
+ raise "raised"
23
+ end
24
+
25
+ def async
26
+ as = MessagePack::RPC::AsyncResult.new
27
+ @svr.start_timer(1, false) do
28
+ as.result "async"
29
+ end
30
+ as
31
+ end
32
+
33
+ def async_exception
34
+ as = MessagePack::RPC::AsyncResult.new
35
+ @svr.start_timer(1, false) do
36
+ as.error "async"
37
+ end
38
+ as
39
+ end
40
+
41
+ private
42
+ def hidden
43
+ end
44
+ end
45
+
46
+
47
+ def next_port
48
+ port = $port += 1
49
+ end
50
+
51
+
52
+ def test_listen
53
+ port = next_port
54
+
55
+ svr = MessagePack::RPC::Server.new
56
+ svr.listen("0.0.0.0", port, MyServer.new(svr))
57
+ svr.close
58
+ end
59
+
60
+
61
+ def start_server
62
+ port = next_port
63
+
64
+ svr = MessagePack::RPC::Server.new
65
+ svr.listen("0.0.0.0", port, MyServer.new(svr))
66
+ Thread.start do
67
+ svr.run
68
+ svr.close
69
+ end
70
+
71
+ cli = MessagePack::RPC::Client.new("127.0.0.1", port)
72
+ cli.timeout = 10
73
+
74
+ return svr, cli
75
+ end
76
+
77
+
78
+ def test_call
79
+ svr, cli = start_server
80
+
81
+ result = cli.call(:hello)
82
+ assert_equal(result, "ok")
83
+
84
+ result = cli.call(:sum, 1, 2)
85
+ assert_equal(result, 3)
86
+
87
+ cli.close
88
+ svr.stop
89
+ end
90
+
91
+
92
+ def test_send
93
+ svr, cli = start_server
94
+
95
+ req1 = cli.send(:hello)
96
+ req2 = cli.send(:sum, 1, 2)
97
+
98
+ req1.join
99
+ req2.join
100
+
101
+ assert_equal(req1.result, "ok")
102
+ assert_nil(req1.error)
103
+ assert_equal(req2.result, 3)
104
+ assert_nil(req2.error)
105
+
106
+ cli.close
107
+ svr.stop
108
+ end
109
+
110
+
111
+ def test_callback
112
+ svr, cli = start_server
113
+
114
+ count = 0
115
+
116
+ cli.callback(:hello) do |error, result|
117
+ assert_equal(result, "ok")
118
+ assert_nil(error)
119
+ count += 1
120
+ end
121
+
122
+ cli.callback(:sum, 1, 2) do |error, result|
123
+ assert_equal(result, 3)
124
+ assert_nil(error)
125
+ count += 1
126
+ end
127
+
128
+ while count < 2
129
+ cli.loop.run_once
130
+ end
131
+
132
+ cli.close
133
+ svr.stop
134
+ end
135
+
136
+
137
+ def test_notify
138
+ svr, cli = start_server
139
+
140
+ cli.notify(:hello)
141
+ cli.notify(:sum, 1, 2)
142
+
143
+ cli.close
144
+ end
145
+
146
+
147
+ def test_hidden
148
+ svr, cli = start_server
149
+
150
+ count = 0
151
+
152
+ rejected = false
153
+ begin
154
+ cli.call(:hidden)
155
+ rescue MessagePack::RPC::RemoteError
156
+ rejected = true
157
+ end
158
+
159
+ assert_equal(rejected, true)
160
+
161
+ cli.close
162
+ svr.stop
163
+ end
164
+
165
+
166
+ def test_exception
167
+ svr, cli = start_server
168
+
169
+ raised = false
170
+ begin
171
+ cli.call(:exception)
172
+ rescue MessagePack::RPC::RemoteError
173
+ assert_equal($!.message, "raised")
174
+ raised = true
175
+ end
176
+
177
+ assert_equal(raised, true)
178
+
179
+ cli.close
180
+ svr.stop
181
+ end
182
+
183
+
184
+ def test_async
185
+ svr, cli = start_server
186
+
187
+ result = cli.call(:async)
188
+ assert_equal(result, "async")
189
+
190
+ cli.close
191
+ svr.stop
192
+ end
193
+
194
+
195
+ def test_async_exception
196
+ svr, cli = start_server
197
+
198
+ raised = false
199
+ begin
200
+ cli.call(:async_exception)
201
+ rescue MessagePack::RPC::RemoteError
202
+ assert_equal($!.message, "async")
203
+ raised = true
204
+ end
205
+
206
+ assert_equal(raised, true)
207
+
208
+ cli.close
209
+ svr.stop
210
+ end
211
+
212
+
213
+ def test_pool
214
+ svr, cli = start_server
215
+
216
+ sp = MessagePack::RPC::SessionPool.new
217
+ s = sp.get_session('127.0.0.1', cli.port)
218
+
219
+ result = s.call(:hello)
220
+ assert_equal(result, "ok")
221
+
222
+ result = s.call(:sum, 1, 2)
223
+ assert_equal(result, 3)
224
+
225
+ sp.close
226
+ cli.close
227
+ svr.stop
228
+ end
229
+
230
+
231
+ def test_loop
232
+ port = next_port
233
+
234
+ loop = MessagePack::RPC::Loop.new
235
+
236
+ svr = MessagePack::RPC::Server.new(loop)
237
+ svr.listen("0.0.0.0", port, MyServer.new(svr))
238
+
239
+ cli = MessagePack::RPC::Client.new("127.0.0.1", port, loop)
240
+ cli.timeout = 10
241
+
242
+ count = 0
243
+
244
+ cli.callback(:hello) do |error, result|
245
+ assert_equal(result, "ok")
246
+ assert_nil(error)
247
+ count += 1
248
+ end
249
+
250
+ cli.callback(:sum, 1, 2) do |error, result|
251
+ assert_equal(result, 3)
252
+ assert_nil(error)
253
+ count += 1
254
+ end
255
+
256
+ while count < 2
257
+ loop.run_once
258
+ end
259
+
260
+ cli.close
261
+ svr.close
262
+ end
263
+
264
+
265
+ def test_timeout
266
+ port = next_port
267
+
268
+ lsock = TCPServer.new("0.0.0.0", port)
269
+
270
+ cli = MessagePack::RPC::Client.new("127.0.0.1", port)
271
+ cli.timeout = 1
272
+
273
+ timeout = false
274
+ begin
275
+ cli.call(:hello)
276
+ rescue MessagePack::RPC::TimeoutError
277
+ timeout = true
278
+ end
279
+
280
+ assert_equal(timeout, true)
281
+
282
+ cli.close
283
+ lsock.close
284
+ end
285
+ end
286
+
@@ -0,0 +1,7 @@
1
+ begin
2
+ require 'rubygems'
3
+ rescue LoadError
4
+ end
5
+ require 'test/unit'
6
+ $LOAD_PATH.unshift File.dirname(__FILE__)+'/../lib'
7
+ require 'msgpack/rpc'
metadata ADDED
@@ -0,0 +1,97 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: redpack
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 1
7
+ - 0
8
+ - 0
9
+ version: 1.0.0
10
+ platform: ruby
11
+ authors:
12
+ - Dean Mao
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-12-14 00:00:00 -08:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: bson
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ segments:
29
+ - 1
30
+ - 1
31
+ - 4
32
+ version: 1.1.4
33
+ type: :runtime
34
+ version_requirements: *id001
35
+ - !ruby/object:Gem::Dependency
36
+ name: em-redis
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
+ - 3
46
+ - 0
47
+ version: 0.3.0
48
+ type: :runtime
49
+ version_requirements: *id002
50
+ description: Simple Scalable RPC using Redis & BSON
51
+ email: deanmao@gmail.com
52
+ executables: []
53
+
54
+ extensions: []
55
+
56
+ extra_rdoc_files: []
57
+
58
+ files:
59
+ - test/msgpack_rpc_test.rb
60
+ - test/test_helper.rb
61
+ - AUTHORS
62
+ - LICENSE
63
+ - NOTICE
64
+ has_rdoc: true
65
+ homepage: http://github.com/luxdelux/redpack
66
+ licenses: []
67
+
68
+ post_install_message:
69
+ rdoc_options: []
70
+
71
+ require_paths:
72
+ - rblib
73
+ required_ruby_version: !ruby/object:Gem::Requirement
74
+ none: false
75
+ requirements:
76
+ - - ">="
77
+ - !ruby/object:Gem::Version
78
+ segments:
79
+ - 0
80
+ version: "0"
81
+ required_rubygems_version: !ruby/object:Gem::Requirement
82
+ none: false
83
+ requirements:
84
+ - - ">="
85
+ - !ruby/object:Gem::Version
86
+ segments:
87
+ - 0
88
+ version: "0"
89
+ requirements: []
90
+
91
+ rubyforge_project: redpack
92
+ rubygems_version: 1.3.7
93
+ signing_key:
94
+ specification_version: 3
95
+ summary: RedPack, asynchronous redis RPC library derived from MsgPack-RPC using BSON serialization
96
+ test_files:
97
+ - test/test_helper.rb