redis-rpc 1.1.0 → 1.2.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.
- checksums.yaml +4 -4
- data/Gemfile.lock +3 -1
- data/lib/redis-rpc.rb +21 -3
- data/lib/redis-rpc/version.rb +1 -1
- data/redis-rpc.gemspec +1 -0
- data/spec/calculator_spec.rb +48 -31
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d608b2b9dcd7726ea7cf1bd599a2660c14bdcb61
|
4
|
+
data.tar.gz: b092789f2589d8a295e5d107eec22fded3b0d99a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ec293260273ea94bda89e29b7d0529446de63e2f1ed0fd0ecc29dbcdfbe02e74c003a1627ee7622da45653ed6008a1d9ece7317d99fbbb84e5906a1aa892b1a4
|
7
|
+
data.tar.gz: 01b70312c304a9a27b98356aa0fcfd86d1e3518ad4d03d9a7d514918de618e41969b09bf8fbee8ea844e178cc04ddf2d217ff6e5946b6586891e4ab734cc953d
|
data/Gemfile.lock
CHANGED
@@ -1,13 +1,14 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
redis-rpc (1.
|
4
|
+
redis-rpc (1.2.0)
|
5
5
|
multi_json (~> 1.3)
|
6
6
|
redis
|
7
7
|
|
8
8
|
GEM
|
9
9
|
remote: http://rubygems.org/
|
10
10
|
specs:
|
11
|
+
byebug (10.0.2)
|
11
12
|
diff-lcs (1.3)
|
12
13
|
multi_json (1.13.1)
|
13
14
|
rake (0.9.2)
|
@@ -31,6 +32,7 @@ PLATFORMS
|
|
31
32
|
|
32
33
|
DEPENDENCIES
|
33
34
|
bundler
|
35
|
+
byebug
|
34
36
|
rake
|
35
37
|
redis-rpc!
|
36
38
|
rspec
|
data/lib/redis-rpc.rb
CHANGED
@@ -48,13 +48,23 @@ module RedisRpc
|
|
48
48
|
end
|
49
49
|
|
50
50
|
alias :send! :send
|
51
|
+
|
52
|
+
def get_timeout_at
|
53
|
+
# allow mock to manipulate timeout to verify safety behavior
|
54
|
+
Time.now.to_i + @timeout + 60
|
55
|
+
end
|
56
|
+
|
51
57
|
def send( method_name, *args)
|
52
58
|
raise MalformedRequestException, 'block not allowed over RPC' if block_given?
|
53
59
|
|
54
60
|
# request setup
|
55
61
|
function_call = {'name' => method_name.to_s, 'args' => args}
|
56
62
|
response_queue = @message_queue + ':rpc:' + rand_string
|
57
|
-
rpc_request = {
|
63
|
+
rpc_request = {
|
64
|
+
'function_call' => function_call, 'response_queue' => response_queue,
|
65
|
+
'timeout_at' => get_timeout_at,
|
66
|
+
}
|
67
|
+
|
58
68
|
rpc_raw_request = MultiJson.dump rpc_request
|
59
69
|
|
60
70
|
# transport
|
@@ -121,9 +131,17 @@ module RedisRpc
|
|
121
131
|
|
122
132
|
# request execution
|
123
133
|
begin
|
134
|
+
if rpc_request['timeout_at'].nil?
|
135
|
+
raise "Unsafe RPC call: timeout_at not specified"
|
136
|
+
end
|
137
|
+
|
138
|
+
if rpc_request['timeout_at'] < Time.now.to_i
|
139
|
+
raise "Expired RPC call. timeout_at = #{rpc_request['timeout_at']}. Time.now = #{Time.now.to_i}"
|
140
|
+
end
|
141
|
+
|
124
142
|
return_value = @local_object.send( function_call['name'].to_sym, *function_call['args'] )
|
125
143
|
rpc_response = {'return_value' => return_value}
|
126
|
-
rescue
|
144
|
+
rescue Exception => err
|
127
145
|
rpc_response = {'exception' => err.to_s, 'backtrace' => err.backtrace}
|
128
146
|
end
|
129
147
|
|
@@ -142,7 +160,7 @@ module RedisRpc
|
|
142
160
|
|
143
161
|
def timeout
|
144
162
|
@timeout or
|
145
|
-
|
163
|
+
$REDISRPC_SERVER_TIMEOUT or
|
146
164
|
0
|
147
165
|
end
|
148
166
|
end
|
data/lib/redis-rpc/version.rb
CHANGED
data/redis-rpc.gemspec
CHANGED
data/spec/calculator_spec.rb
CHANGED
@@ -2,40 +2,57 @@ require File.expand_path( '../spec_helper.rb', __FILE__ )
|
|
2
2
|
require File.expand_path( '../../examples/calc.rb', __FILE__ )
|
3
3
|
|
4
4
|
describe Calculator do
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
if( over_redisrpc )
|
9
|
-
let(:rpc_server_builder){ lambda{ RedisRpc::Server.new( Redis.new($REDIS_CONFIG), 'calc', Calculator.new ) } }
|
10
|
-
before(:each) do
|
11
|
-
@server_pid = fork{ rpc_server_builder.call.run }
|
12
|
-
end
|
13
|
-
after(:each){ Process.kill(9, @server_pid); rpc_server_builder.call.flush_queue! }
|
14
|
-
let(:calculator){ RedisRpc::Client.new( $REDIS,'calc', 1) }
|
15
|
-
else
|
16
|
-
let(:calculator){ Calculator.new }
|
17
|
-
end
|
5
|
+
context "locally" do
|
6
|
+
let(:calculator){ Calculator.new }
|
18
7
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
8
|
+
it 'should calculate' do
|
9
|
+
calculator.val.should == 0.0
|
10
|
+
calculator.add(3).should == 3.0
|
11
|
+
calculator.sub(2).should == 1.0
|
12
|
+
calculator.mul(14).should == 14.0
|
13
|
+
calculator.div(7).should == 2.0
|
14
|
+
calculator.val.should == 2.0
|
15
|
+
calculator.clr.should == 0.0
|
16
|
+
calculator.val.should == 0.0
|
17
|
+
end
|
29
18
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
19
|
+
it 'should raise when missing method is called' do
|
20
|
+
expect{ calculator.a_missing_method }.to raise_error(NoMethodError)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
context "over rpc" do
|
25
|
+
let(:rpc_server_builder){ lambda{ RedisRpc::Server.new( Redis.new($REDIS_CONFIG), 'calc', Calculator.new ) } }
|
26
|
+
before(:each) do
|
27
|
+
@server_pid = fork{ rpc_server_builder.call.run }
|
28
|
+
end
|
29
|
+
after(:each){ Process.kill(9, @server_pid); rpc_server_builder.call.flush_queue! }
|
30
|
+
let(:calculator){ RedisRpc::Client.new( $REDIS,'calc', 1) }
|
35
31
|
|
36
|
-
|
37
|
-
|
38
|
-
|
32
|
+
it 'should calculate' do
|
33
|
+
calculator.val.should == 0.0
|
34
|
+
calculator.add(3).should == 3.0
|
35
|
+
calculator.sub(2).should == 1.0
|
36
|
+
calculator.mul(14).should == 14.0
|
37
|
+
calculator.div(7).should == 2.0
|
38
|
+
calculator.val.should == 2.0
|
39
|
+
calculator.clr.should == 0.0
|
40
|
+
calculator.val.should == 0.0
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'should raise when missing method is called' do
|
44
|
+
expect{ calculator.a_missing_method }.to raise_error(RedisRpc::RemoteException)
|
45
|
+
end
|
46
|
+
|
47
|
+
it 'should raise timeout when execution expires' do
|
48
|
+
expect{ calculator.send(:sleep,2) }.to raise_error RedisRpc::TimeoutException
|
49
|
+
end
|
50
|
+
|
51
|
+
context "the request is executed late" do
|
52
|
+
it "won't be executed" do
|
53
|
+
allow(calculator).to receive(:get_timeout_at).and_return(Time.now.to_i - 1)
|
54
|
+
expect { calculator.val }.to raise_error(RedisRpc::RemoteException, /Expired RPC call/)
|
55
|
+
end
|
39
56
|
end
|
40
57
|
end
|
41
58
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: redis-rpc
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Phuong Nguyen
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2018-11-
|
12
|
+
date: 2018-11-21 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: redis
|
@@ -81,6 +81,20 @@ dependencies:
|
|
81
81
|
- - ">="
|
82
82
|
- !ruby/object:Gem::Version
|
83
83
|
version: '0'
|
84
|
+
- !ruby/object:Gem::Dependency
|
85
|
+
name: byebug
|
86
|
+
requirement: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - ">="
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: '0'
|
91
|
+
type: :development
|
92
|
+
prerelease: false
|
93
|
+
version_requirements: !ruby/object:Gem::Requirement
|
94
|
+
requirements:
|
95
|
+
- - ">="
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: '0'
|
84
98
|
description: |2
|
85
99
|
RedisRpc is the easiest to use RPC library in the world. (No small claim!).
|
86
100
|
This version is a repackage that only has Ruby implementation.
|