msgpack-rpc 0.4.2 → 0.4.3
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.
- data/ChangeLog +4 -0
- data/lib/msgpack-rpc.rb +1 -0
- data/lib/msgpack/rpc/session.rb +8 -1
- data/lib/msgpack/rpc/session_pool.rb +1 -1
- data/lib/msgpack/rpc/transport/tcp.rb +1 -3
- data/lib/msgpack/rpc/transport/unix.rb +1 -2
- data/lib/msgpack/rpc/version.rb +1 -1
- data/spec/spec.opts +7 -0
- data/spec/unit/client_spec.rb +141 -0
- data/spec/unit/my_server.rb +89 -0
- data/spec/unit/spec_helper.rb +5 -0
- data/tasks/msgpack_rpc_tasks.rake +25 -0
- data/test/msgpack_rpc_test.rb +6 -3
- data/test/test_helper.rb +3 -0
- metadata +27 -7
data/ChangeLog
CHANGED
data/lib/msgpack-rpc.rb
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
require File.join(File.dirname(__FILE__), 'msgpack', 'rpc')
|
data/lib/msgpack/rpc/session.rb
CHANGED
|
@@ -84,7 +84,14 @@ class Session
|
|
|
84
84
|
end
|
|
85
85
|
|
|
86
86
|
# backward compatibility
|
|
87
|
-
|
|
87
|
+
alias_method :send_without_call_async, :send
|
|
88
|
+
def send(method, *args)
|
|
89
|
+
if caller.first =~ /.*_test.rb/ || caller.first =~ /.*_spec.rb/ then
|
|
90
|
+
warn "\n Don't use send method. Use 'call_async' method."
|
|
91
|
+
end
|
|
92
|
+
call_async(method, *args)
|
|
93
|
+
end
|
|
94
|
+
|
|
88
95
|
|
|
89
96
|
# call-seq:
|
|
90
97
|
# callback(symbol, *args) {|future| }
|
|
@@ -48,8 +48,7 @@ class TCPTransport
|
|
|
48
48
|
|
|
49
49
|
# from Rev::TCPSocket
|
|
50
50
|
def on_read(data)
|
|
51
|
-
@pac.
|
|
52
|
-
@pac.each {|obj|
|
|
51
|
+
@pac.feed_each(data) {|obj|
|
|
53
52
|
on_message(obj)
|
|
54
53
|
}
|
|
55
54
|
end
|
|
@@ -115,7 +114,6 @@ class TCPClientTransport
|
|
|
115
114
|
else
|
|
116
115
|
@connecting = 0
|
|
117
116
|
@pending = ""
|
|
118
|
-
@deflate.reset if @deflate
|
|
119
117
|
@session.on_connect_failed
|
|
120
118
|
end
|
|
121
119
|
end
|
data/lib/msgpack/rpc/version.rb
CHANGED
data/spec/spec.opts
ADDED
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
require File.join(File.expand_path(File.dirname(__FILE__)), 'spec_helper.rb')
|
|
2
|
+
require File.join(File.expand_path(File.dirname(__FILE__)), 'my_server.rb')
|
|
3
|
+
include MyServerTest
|
|
4
|
+
|
|
5
|
+
describe 'MessagePack::RPC::Client test' do
|
|
6
|
+
before(:each)do
|
|
7
|
+
@svr,@client = start_server
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
after(:each)do
|
|
11
|
+
@svr.stop
|
|
12
|
+
@client.close
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
it 'should return "ok" value ' do
|
|
17
|
+
@client.call(:hello).should include("ok")
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
it 'should return "3" value ' do
|
|
21
|
+
@client.call(:sum,1,2).should equal 3
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
it 'should return "ok" and "3" when you call with call_async' do
|
|
25
|
+
req1 = @client.call_async(:hello)
|
|
26
|
+
req2 = @client.call_async(:sum,1,2)
|
|
27
|
+
req1.join
|
|
28
|
+
req1.result.should include("ok")
|
|
29
|
+
req1.error.should be_nil
|
|
30
|
+
|
|
31
|
+
req2.join
|
|
32
|
+
req2.result.should equal 3
|
|
33
|
+
req2.error.should be_nil
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
it 'should return "ok" when you set callback(:hello)' do
|
|
37
|
+
@client.callback(:hello) do |error, result|
|
|
38
|
+
result.should include("ok")
|
|
39
|
+
error.should be_nil
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
it 'should return "3" when you set callback(:sum)' do
|
|
44
|
+
|
|
45
|
+
@client.callback(:sum) do |error, result|
|
|
46
|
+
result.shouble equal 3
|
|
47
|
+
error.should be_nil
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
it 'should return nil values when you call notify' do
|
|
52
|
+
@client.notify(:hello).should be_nil
|
|
53
|
+
@client.notify(:sum,1,2).should be_nil
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
it 'should return error when you call private method' do
|
|
57
|
+
lambda{@client.call(:hidden)}.should raise_error(MessagePack::RPC::RemoteError)
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
it 'should be throw exception message when you call exception method' do
|
|
61
|
+
lambda{@client.call(:exception)}.should raise_error(MessagePack::RPC::RemoteError,"raised")
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
it 'should be return "async" when you call with :async parameter' do
|
|
65
|
+
@client.call(:async).should include("async")
|
|
66
|
+
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
it 'should throws exception when you call with async_exception' do
|
|
71
|
+
lambda{@client.call(:async_exception)}.should raise_error(MessagePack::RPC::RemoteError,"async")
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
it 'should be returns correct values when you use MessagePack::RPC::SessionPool' do
|
|
75
|
+
sp = MessagePack::RPC::SessionPool.new
|
|
76
|
+
s = sp.get_session('127.0.0.1', @client.port)
|
|
77
|
+
|
|
78
|
+
s.call(:hello).should include("ok")
|
|
79
|
+
s.call(:sum,1,2).should equal 3
|
|
80
|
+
|
|
81
|
+
sp.close
|
|
82
|
+
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
describe "MessagePack::RPC::TimeoutError test" do
|
|
89
|
+
|
|
90
|
+
before(:each)do
|
|
91
|
+
@client = start_client
|
|
92
|
+
@lsock = TCPServer.new("0.0.0.0",@client.port)
|
|
93
|
+
@client.timeout = 1
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
it 'should return MessagePack::RPC::TimoutError' do
|
|
97
|
+
lambda{@client.call(:hello)}.should raise_error(MessagePack::RPC::TimeoutError)
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
after(:all)do
|
|
101
|
+
@client.close
|
|
102
|
+
@lsock.close
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
describe "MessagePack::RPC::Loop testing" do
|
|
108
|
+
before(:all) do
|
|
109
|
+
@loop = MessagePack::RPC::Loop.new
|
|
110
|
+
|
|
111
|
+
@svr = MessagePack::RPC::Server.new(@loop)
|
|
112
|
+
@svr.listen("0.0.0.0", MyServer.port, MyServer.new(@svr))
|
|
113
|
+
|
|
114
|
+
@cli = MessagePack::RPC::Client.new("127.0.0.1", MyServer.port, @loop)
|
|
115
|
+
@cli.timeout = 10
|
|
116
|
+
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
it "should return correct values when you use MessagePack::RPC::Loop" do
|
|
120
|
+
count = 0
|
|
121
|
+
|
|
122
|
+
@cli.callback(:hello) do |error, result|
|
|
123
|
+
result.should include("ok")
|
|
124
|
+
error.should be_nil
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
@cli.callback(:sum, 1, 2) do |error, result|
|
|
128
|
+
result.should equal 3
|
|
129
|
+
error.should be_nil
|
|
130
|
+
end
|
|
131
|
+
|
|
132
|
+
end
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
after(:all) do
|
|
136
|
+
@cli.close
|
|
137
|
+
@svr.close
|
|
138
|
+
end
|
|
139
|
+
|
|
140
|
+
end
|
|
141
|
+
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
|
|
2
|
+
class MyServer
|
|
3
|
+
@port = 65500
|
|
4
|
+
attr_accessor :port
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
def initialize(svr)
|
|
8
|
+
@svr = svr
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def hello
|
|
12
|
+
"ok"
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def sum(a, b)
|
|
16
|
+
a + b
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def exception
|
|
20
|
+
raise "raised"
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def async
|
|
24
|
+
as = MessagePack::RPC::AsyncResult.new
|
|
25
|
+
@svr.start_timer(1, false) do
|
|
26
|
+
as.result "async"
|
|
27
|
+
end
|
|
28
|
+
as
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def async_exception
|
|
32
|
+
as = MessagePack::RPC::AsyncResult.new
|
|
33
|
+
@svr.start_timer(1, false) do
|
|
34
|
+
as.error "async"
|
|
35
|
+
end
|
|
36
|
+
as
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def self.next_port
|
|
40
|
+
@port += 1
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def self.port
|
|
44
|
+
@port
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
private
|
|
48
|
+
def hidden
|
|
49
|
+
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
module MyServerTest
|
|
57
|
+
def start_client
|
|
58
|
+
cli = MessagePack::RPC::Client.new("127.0.0.1", MyServer.port)
|
|
59
|
+
cli.timeout = 10
|
|
60
|
+
return cli
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
def start_server
|
|
64
|
+
port = MyServer.next_port
|
|
65
|
+
svr = MessagePack::RPC::Server.new
|
|
66
|
+
svr.listen("0.0.0.0", port, MyServer.new(svr))
|
|
67
|
+
Thread.start do
|
|
68
|
+
svr.run
|
|
69
|
+
svr.close
|
|
70
|
+
end
|
|
71
|
+
return svr, start_client
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
def server_start_loop
|
|
75
|
+
|
|
76
|
+
port =MyServer.next_port
|
|
77
|
+
|
|
78
|
+
loop = MessagePack::RPC::Loop.new
|
|
79
|
+
svr =MessagePack::RPC::Server.new(loop)
|
|
80
|
+
svr.listen("0.0.0.0", port ,MyServer.new(svr))
|
|
81
|
+
|
|
82
|
+
cli = MessagePack::RPC::Client.new("127.0.0.1", port, loop)
|
|
83
|
+
cli.timeout = 10
|
|
84
|
+
|
|
85
|
+
return svr,cli
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
end
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# desc "Explaing what task does"
|
|
2
|
+
|
|
3
|
+
begin
|
|
4
|
+
require 'spec'
|
|
5
|
+
require 'spec/rake/spectask'
|
|
6
|
+
namespace :spec do
|
|
7
|
+
desc 'run unit core testing'
|
|
8
|
+
Spec::Rake::SpecTask.new(:unit) do |t|
|
|
9
|
+
spec_dir = File.join(File.dirname(__FILE__), '..', 'spec')
|
|
10
|
+
t.spec_opts = File.read(File.join(spec_dir, 'spec.opts')).split
|
|
11
|
+
t.spec_files = FileList[File.join(spec_dir, 'unit', '**', '*_spec.rb')]
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
rescue LoadError
|
|
15
|
+
warn "Rspec is not installed. Please install Rspec with gems and --pre"
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
namespace :test do
|
|
19
|
+
desc "run test"
|
|
20
|
+
Rake::TestTask.new(:unit) do |t|
|
|
21
|
+
t.libs << 'lib'
|
|
22
|
+
t.pattern = 'test/*_test.rb'
|
|
23
|
+
t.verbose = true
|
|
24
|
+
end
|
|
25
|
+
end
|
data/test/msgpack_rpc_test.rb
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env ruby
|
|
2
|
-
|
|
2
|
+
|
|
3
|
+
require File.expand_path(File.dirname(__FILE__)) + '/test_helper.rb'
|
|
4
|
+
|
|
3
5
|
|
|
4
6
|
$port = 65500
|
|
5
7
|
|
|
@@ -40,6 +42,7 @@ class MessagePackRPCTest < Test::Unit::TestCase
|
|
|
40
42
|
|
|
41
43
|
private
|
|
42
44
|
def hidden
|
|
45
|
+
|
|
43
46
|
end
|
|
44
47
|
end
|
|
45
48
|
|
|
@@ -92,8 +95,8 @@ class MessagePackRPCTest < Test::Unit::TestCase
|
|
|
92
95
|
def test_send
|
|
93
96
|
svr, cli = start_server
|
|
94
97
|
|
|
95
|
-
req1 = cli.
|
|
96
|
-
req2 = cli.
|
|
98
|
+
req1 = cli.call_async(:hello)
|
|
99
|
+
req2 = cli.call_async(:sum, 1, 2)
|
|
97
100
|
|
|
98
101
|
req1.join
|
|
99
102
|
req2.join
|
data/test/test_helper.rb
CHANGED
metadata
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: msgpack-rpc
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
hash:
|
|
4
|
+
hash: 9
|
|
5
5
|
prerelease: false
|
|
6
6
|
segments:
|
|
7
7
|
- 0
|
|
8
8
|
- 4
|
|
9
|
-
-
|
|
10
|
-
version: 0.4.
|
|
9
|
+
- 3
|
|
10
|
+
version: 0.4.3
|
|
11
11
|
platform: ruby
|
|
12
12
|
authors:
|
|
13
13
|
- FURUHASHI Sadayuki
|
|
@@ -15,7 +15,7 @@ autorequire:
|
|
|
15
15
|
bindir: bin
|
|
16
16
|
cert_chain: []
|
|
17
17
|
|
|
18
|
-
date: 2010-
|
|
18
|
+
date: 2010-11-28 00:00:00 +09:00
|
|
19
19
|
default_executable:
|
|
20
20
|
dependencies:
|
|
21
21
|
- !ruby/object:Gem::Dependency
|
|
@@ -26,12 +26,12 @@ dependencies:
|
|
|
26
26
|
requirements:
|
|
27
27
|
- - ">="
|
|
28
28
|
- !ruby/object:Gem::Version
|
|
29
|
-
hash:
|
|
29
|
+
hash: 7
|
|
30
30
|
segments:
|
|
31
31
|
- 0
|
|
32
32
|
- 4
|
|
33
|
-
-
|
|
34
|
-
version: 0.4.
|
|
33
|
+
- 4
|
|
34
|
+
version: 0.4.4
|
|
35
35
|
type: :runtime
|
|
36
36
|
version_requirements: *id001
|
|
37
37
|
- !ruby/object:Gem::Dependency
|
|
@@ -50,6 +50,20 @@ dependencies:
|
|
|
50
50
|
version: 0.3.0
|
|
51
51
|
type: :runtime
|
|
52
52
|
version_requirements: *id002
|
|
53
|
+
- !ruby/object:Gem::Dependency
|
|
54
|
+
name: rspec
|
|
55
|
+
prerelease: false
|
|
56
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
|
57
|
+
none: false
|
|
58
|
+
requirements:
|
|
59
|
+
- - ">="
|
|
60
|
+
- !ruby/object:Gem::Version
|
|
61
|
+
hash: 3
|
|
62
|
+
segments:
|
|
63
|
+
- 0
|
|
64
|
+
version: "0"
|
|
65
|
+
type: :development
|
|
66
|
+
version_requirements: *id003
|
|
53
67
|
description:
|
|
54
68
|
email: frsyuki@users.sourceforge.jp
|
|
55
69
|
executables: []
|
|
@@ -63,6 +77,7 @@ files:
|
|
|
63
77
|
- ChangeLog
|
|
64
78
|
- NOTICE
|
|
65
79
|
- README
|
|
80
|
+
- lib/msgpack-rpc.rb
|
|
66
81
|
- lib/msgpack/rpc.rb
|
|
67
82
|
- lib/msgpack/rpc/address.rb
|
|
68
83
|
- lib/msgpack/rpc/client.rb
|
|
@@ -80,6 +95,11 @@ files:
|
|
|
80
95
|
- lib/msgpack/rpc/transport/udp.rb
|
|
81
96
|
- lib/msgpack/rpc/transport/unix.rb
|
|
82
97
|
- lib/msgpack/rpc/version.rb
|
|
98
|
+
- spec/spec.opts
|
|
99
|
+
- spec/unit/client_spec.rb
|
|
100
|
+
- spec/unit/my_server.rb
|
|
101
|
+
- spec/unit/spec_helper.rb
|
|
102
|
+
- tasks/msgpack_rpc_tasks.rake
|
|
83
103
|
- test/msgpack_rpc_test.rb
|
|
84
104
|
- test/test_helper.rb
|
|
85
105
|
has_rdoc: true
|