fastbeans 0.3.7 → 0.3.8
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/lib/fastbeans/client.rb +7 -1
- data/lib/fastbeans/connection.rb +6 -6
- data/lib/fastbeans/request.rb +5 -3
- data/lib/fastbeans/version.rb +1 -1
- data/test/connection_test.rb +9 -9
- data/test/test_helper.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 19bd06c785553f14f9ecbfb281189452dfe6580d
|
4
|
+
data.tar.gz: 55df3beda354d29fbe4a3a1ba1bc539d4161e6c0
|
5
5
|
!binary "U0hBNTEy":
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 862bea544dd1bd9e33fca5db3ec105b3bd0672963fbe0451d1cf1b2883ab6c60831d77c8488d2feea4e70e11757116bb257a2e4e718c8bfb43db0475ef0fdbc1
|
7
|
+
data.tar.gz: 1ddb58a6ce2775db33d454c23e1b0ec018a7c8eab3911c7c939d24ba14af56108a9fadac475cbfec1d32e5c57ced6f120f4bd7b34bbe14e133e6fb647e346cf4
|
data/lib/fastbeans/client.rb
CHANGED
@@ -2,6 +2,7 @@ require 'msgpack'
|
|
2
2
|
require 'rufus-lru'
|
3
3
|
require 'connection_pool'
|
4
4
|
require 'fastbeans/connection'
|
5
|
+
require 'fastbeans/request'
|
5
6
|
|
6
7
|
module Fastbeans
|
7
8
|
class Client
|
@@ -31,7 +32,12 @@ module Fastbeans
|
|
31
32
|
def call(*data)
|
32
33
|
Fastbeans.benchmark("Calling: #{data.first.inspect}") do
|
33
34
|
pool.with do |conn|
|
34
|
-
|
35
|
+
if data.last.is_a?(Hash) and (data.last.keys.to_set & Fastbeans::Request::OPTION_KEYS)
|
36
|
+
opts = data.pop
|
37
|
+
else
|
38
|
+
opts = {}
|
39
|
+
end
|
40
|
+
conn.call(data, opts)
|
35
41
|
end
|
36
42
|
end
|
37
43
|
end
|
data/lib/fastbeans/connection.rb
CHANGED
@@ -40,10 +40,10 @@ module Fastbeans
|
|
40
40
|
connect!(@host, @port)
|
41
41
|
end
|
42
42
|
|
43
|
-
def call(
|
43
|
+
def call(data, opts)
|
44
44
|
retries = 0
|
45
45
|
begin
|
46
|
-
call_without_retries(data)
|
46
|
+
call_without_retries(data, opts)
|
47
47
|
rescue Fastbeans::RemoteConnectionFailed, Fastbeans::ResponseReadTimeout => e
|
48
48
|
Fastbeans.debug(e)
|
49
49
|
if retries < MAX_RETRIES
|
@@ -61,8 +61,8 @@ module Fastbeans
|
|
61
61
|
end
|
62
62
|
end
|
63
63
|
|
64
|
-
def call_without_retries(data)
|
65
|
-
perform(data)
|
64
|
+
def call_without_retries(data, opts)
|
65
|
+
perform(data, opts)
|
66
66
|
|
67
67
|
rescue IOError, Errno::EPIPE, Errno::ECONNREFUSED, Errno::ECONNRESET, MessagePack::MalformedFormatError => e
|
68
68
|
disconnect!
|
@@ -82,8 +82,8 @@ module Fastbeans
|
|
82
82
|
raise
|
83
83
|
end
|
84
84
|
|
85
|
-
def perform(data)
|
86
|
-
Request.new(self).perform(data)
|
85
|
+
def perform(data, opts)
|
86
|
+
Request.new(self, opts).perform(data)
|
87
87
|
end
|
88
88
|
end
|
89
89
|
end
|
data/lib/fastbeans/request.rb
CHANGED
@@ -7,9 +7,11 @@ module Fastbeans
|
|
7
7
|
attr_reader :connection
|
8
8
|
|
9
9
|
RESPONSE_READ_TIMEOUT = 120
|
10
|
+
OPTION_KEYS = [:timeout]
|
10
11
|
|
11
|
-
def initialize(connection)
|
12
|
+
def initialize(connection, opts = {})
|
12
13
|
@connection = connection
|
14
|
+
@options = {:timeout => RESPONSE_READ_TIMEOUT}.update(opts)
|
13
15
|
end
|
14
16
|
|
15
17
|
def sign(call_data)
|
@@ -32,13 +34,13 @@ module Fastbeans
|
|
32
34
|
end
|
33
35
|
|
34
36
|
def read_response(sock, call_data)
|
35
|
-
raw_resp = Timeout.timeout(
|
37
|
+
raw_resp = Timeout.timeout(@options[:timeout], Fastbeans::ResponseReadTimeout) do
|
36
38
|
MessagePack.load(sock)
|
37
39
|
end
|
38
40
|
Fastbeans::Response.new(call_data, raw_resp)
|
39
41
|
rescue Fastbeans::ResponseReadTimeout
|
40
42
|
@connection.disconnect!
|
41
|
-
raise Fastbeans::ResponseReadTimeout, "Couldn't read response in #{
|
43
|
+
raise Fastbeans::ResponseReadTimeout, "Couldn't read response in #{@options[:timeout]} seconds"
|
42
44
|
end
|
43
45
|
|
44
46
|
def perform(call_data)
|
data/lib/fastbeans/version.rb
CHANGED
data/test/connection_test.rb
CHANGED
@@ -37,14 +37,14 @@ class ConnectionTest < MiniTest::Unit::TestCase
|
|
37
37
|
|
38
38
|
def test_call_without_retries
|
39
39
|
Fastbeans::Request.any_instance.expects(:perform).with(@test_msg).returns(:reply)
|
40
|
-
assert_equal :reply, @conn.call_without_retries(@test_msg)
|
40
|
+
assert_equal :reply, @conn.call_without_retries(@test_msg, {})
|
41
41
|
end
|
42
42
|
|
43
43
|
def test_exception_during_call
|
44
|
-
@conn.expects(:perform).with(@test_msg).raises(RuntimeError)
|
44
|
+
@conn.expects(:perform).with(@test_msg, {}).raises(RuntimeError)
|
45
45
|
@conn.expects(:disconnect!)
|
46
46
|
assert_raises RuntimeError do
|
47
|
-
@conn.call_without_retries(@test_msg)
|
47
|
+
@conn.call_without_retries(@test_msg, {})
|
48
48
|
end
|
49
49
|
end
|
50
50
|
|
@@ -52,10 +52,10 @@ class ConnectionTest < MiniTest::Unit::TestCase
|
|
52
52
|
ioexcs = [IOError, Errno::EPIPE, MessagePack::MalformedFormatError,
|
53
53
|
Errno::ECONNREFUSED, Errno::ECONNRESET]
|
54
54
|
ioexcs.each do |exc|
|
55
|
-
@conn.expects(:perform).with(@test_msg).raises(exc)
|
55
|
+
@conn.expects(:perform).with(@test_msg, {}).raises(exc)
|
56
56
|
@conn.expects(:disconnect!)
|
57
57
|
assert_raises Fastbeans::RemoteConnectionFailed do
|
58
|
-
@conn.call_without_retries(@test_msg)
|
58
|
+
@conn.call_without_retries(@test_msg, {})
|
59
59
|
end
|
60
60
|
end
|
61
61
|
end
|
@@ -63,17 +63,17 @@ class ConnectionTest < MiniTest::Unit::TestCase
|
|
63
63
|
def test_perform
|
64
64
|
req = mock
|
65
65
|
req.expects(:perform).with(@test_msg).returns(:result)
|
66
|
-
Fastbeans::Request.expects(:new).with(@conn).returns(req)
|
67
|
-
assert_equal :result, @conn.perform(@test_msg)
|
66
|
+
Fastbeans::Request.expects(:new).with(@conn, {}).returns(req)
|
67
|
+
assert_equal :result, @conn.perform(@test_msg, {})
|
68
68
|
end
|
69
69
|
|
70
70
|
def test_call_with_retries
|
71
71
|
@conn.expects(:call_without_retries).
|
72
|
-
with(@test_msg).times(4).
|
72
|
+
with(@test_msg, {}).times(4).
|
73
73
|
raises(Fastbeans::RemoteConnectionFailed)
|
74
74
|
@conn.expects(:reconnect!).times(3)
|
75
75
|
assert_raises Fastbeans::RemoteConnectionDead do
|
76
|
-
assert_nil @conn.call(
|
76
|
+
assert_nil @conn.call(@test_msg, {})
|
77
77
|
end
|
78
78
|
end
|
79
79
|
|
data/test/test_helper.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fastbeans
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dima Sabanin
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-01-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: msgpack
|