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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
- metadata.gz: 5936875dd05eed4d051e79ade5a96ff780098367
4
- data.tar.gz: 393572d7da151951bdf6d454094e3b52f0dfb149
3
+ metadata.gz: 19bd06c785553f14f9ecbfb281189452dfe6580d
4
+ data.tar.gz: 55df3beda354d29fbe4a3a1ba1bc539d4161e6c0
5
5
  !binary "U0hBNTEy":
6
- metadata.gz: 12a76b54d34d4279983c12be6d6b4ac507c0925b6de12a9d840ab32713d1db5714afbd5173a1f187fbf30f5114ce88b9f7ed6070a5abcfa993ca824e07528b01
7
- data.tar.gz: f868e81095eca258bbd8c510bbcf45d353774bca61f83ce3d1f89a63616b3f3ee287666e16a33a5d5d06b9496ef71d9d9cf814ffeba2f1e22a939955728566e2
6
+ metadata.gz: 862bea544dd1bd9e33fca5db3ec105b3bd0672963fbe0451d1cf1b2883ab6c60831d77c8488d2feea4e70e11757116bb257a2e4e718c8bfb43db0475ef0fdbc1
7
+ data.tar.gz: 1ddb58a6ce2775db33d454c23e1b0ec018a7c8eab3911c7c939d24ba14af56108a9fadac475cbfec1d32e5c57ced6f120f4bd7b34bbe14e133e6fb647e346cf4
@@ -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
- conn.call(*data)
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
@@ -40,10 +40,10 @@ module Fastbeans
40
40
  connect!(@host, @port)
41
41
  end
42
42
 
43
- def call(*data)
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
@@ -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(RESPONSE_READ_TIMEOUT, Fastbeans::ResponseReadTimeout) do
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 #{RESPONSE_READ_TIMEOUT} seconds"
43
+ raise Fastbeans::ResponseReadTimeout, "Couldn't read response in #{@options[:timeout]} seconds"
42
44
  end
43
45
 
44
46
  def perform(call_data)
@@ -1,3 +1,3 @@
1
1
  module Fastbeans
2
- VERSION = "0.3.7"
2
+ VERSION = "0.3.8"
3
3
  end
@@ -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(*@test_msg)
76
+ assert_nil @conn.call(@test_msg, {})
77
77
  end
78
78
  end
79
79
 
data/test/test_helper.rb CHANGED
@@ -9,7 +9,7 @@ require 'fastbeans'
9
9
  class MockConnection
10
10
  def initialize(*any); end
11
11
 
12
- def call(*data)
12
+ def call(data, opts)
13
13
  data
14
14
  end
15
15
 
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.7
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: 2014-08-27 00:00:00.000000000 Z
11
+ date: 2015-01-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: msgpack