bertrpc 0.4.2 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +2 -7
- data/README.md +8 -26
- data/Rakefile +2 -2
- data/VERSION +1 -1
- data/bertrpc.gemspec +10 -11
- data/lib/bertrpc/action.rb +2 -27
- data/lib/bertrpc/errors.rb +1 -11
- data/lib/bertrpc/service.rb +3 -4
- data/lib/bertrpc.rb +1 -2
- data/test/action_test.rb +6 -22
- data/test/service_test.rb +1 -6
- metadata +4 -4
data/History.txt
CHANGED
@@ -1,10 +1,5 @@
|
|
1
|
-
= 0.
|
2
|
-
*
|
3
|
-
* Switch to using raw socket timeouts over buffered io (Linux only)
|
4
|
-
|
5
|
-
= 0.4.1 / 2009-11-26
|
6
|
-
* Major changes
|
7
|
-
* Backport timeout option
|
1
|
+
= 1.0.0 / 2009-10-19
|
2
|
+
* No changes. Production ready!
|
8
3
|
|
9
4
|
= 0.4.0 / 2009-10-08
|
10
5
|
* Major changes
|
data/README.md
CHANGED
@@ -3,28 +3,22 @@ BERTRPC
|
|
3
3
|
|
4
4
|
By Tom Preston-Werner (tom@mojombo.com)
|
5
5
|
|
6
|
-
|
7
|
-
extensive testing. You should not consider this project production ready until
|
8
|
-
it is released as 1.0.
|
6
|
+
BERT-RPC client library for Ruby. Makes it ridiculously simple to interface with BERT-RPC servers.
|
9
7
|
|
8
|
+
See the full BERT-RPC specification at [bert-rpc.org](http://bert-rpc.org).
|
10
9
|
|
11
|
-
|
12
|
-
-----------
|
10
|
+
This library currently only supports the following BERT-RPC features:
|
13
11
|
|
14
|
-
|
12
|
+
* `call` requests
|
13
|
+
* `cast` requests
|
14
|
+
|
15
|
+
BERTRPC was developed for GitHub and is currently in production use performing millions of RPC requests every day. The stability and performance have been exemplary.
|
15
16
|
|
16
17
|
|
17
18
|
Installation
|
18
19
|
------------
|
19
20
|
|
20
|
-
|
21
|
-
|
22
|
-
gem install bertrpc
|
23
|
-
|
24
|
-
From GitHub:
|
25
|
-
|
26
|
-
gem install mojombo-bertrpc -s http://gems.github.com \
|
27
|
-
-s http://gemcutter.org
|
21
|
+
$ gem install bertrpc -s http://gemcutter.org
|
28
22
|
|
29
23
|
|
30
24
|
Examples
|
@@ -56,18 +50,6 @@ The underlying BERT-RPC transaction of the above cast is:
|
|
56
50
|
<- {noreply}
|
57
51
|
|
58
52
|
|
59
|
-
Documentation
|
60
|
-
-------------
|
61
|
-
|
62
|
-
Creating a service:
|
63
|
-
|
64
|
-
# No timeout
|
65
|
-
svc = BERTRPC::Service.new('localhost', 9999)
|
66
|
-
|
67
|
-
# 10s socket read timeout, raises BERTRPC::ReadTimeoutError
|
68
|
-
svc = BERTRPC::Service.new('localhost', 9999, 10)
|
69
|
-
|
70
|
-
|
71
53
|
Copyright
|
72
54
|
---------
|
73
55
|
|
data/Rakefile
CHANGED
@@ -9,8 +9,8 @@ begin
|
|
9
9
|
gem.email = "tom@mojombo.com"
|
10
10
|
gem.homepage = "http://github.com/mojombo/bertrpc"
|
11
11
|
gem.authors = ["Tom Preston-Werner"]
|
12
|
-
gem.add_dependency('bert', '>=
|
13
|
-
gem.add_dependency('erlectricity', '>= 1.0
|
12
|
+
gem.add_dependency('bert', '>= 1.0.0')
|
13
|
+
gem.add_dependency('erlectricity', '>= 1.1.0')
|
14
14
|
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
15
15
|
end
|
16
16
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
1.0.0
|
data/bertrpc.gemspec
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
# Generated by jeweler
|
2
|
-
# DO NOT EDIT THIS FILE
|
3
|
-
# Instead, edit Jeweler::Tasks in
|
2
|
+
# DO NOT EDIT THIS FILE
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run `rake gemspec`
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{bertrpc}
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "1.0.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Tom Preston-Werner"]
|
12
|
-
s.date = %q{2009-
|
12
|
+
s.date = %q{2009-10-19}
|
13
13
|
s.email = %q{tom@mojombo.com}
|
14
14
|
s.extra_rdoc_files = [
|
15
15
|
"LICENSE",
|
@@ -59,15 +59,14 @@ Gem::Specification.new do |s|
|
|
59
59
|
s.specification_version = 3
|
60
60
|
|
61
61
|
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
62
|
-
s.add_runtime_dependency(%q<bert>, [">=
|
63
|
-
s.add_runtime_dependency(%q<erlectricity>, [">= 1.0
|
62
|
+
s.add_runtime_dependency(%q<bert>, [">= 1.0.0"])
|
63
|
+
s.add_runtime_dependency(%q<erlectricity>, [">= 1.1.0"])
|
64
64
|
else
|
65
|
-
s.add_dependency(%q<bert>, [">=
|
66
|
-
s.add_dependency(%q<erlectricity>, [">= 1.0
|
65
|
+
s.add_dependency(%q<bert>, [">= 1.0.0"])
|
66
|
+
s.add_dependency(%q<erlectricity>, [">= 1.1.0"])
|
67
67
|
end
|
68
68
|
else
|
69
|
-
s.add_dependency(%q<bert>, [">=
|
70
|
-
s.add_dependency(%q<erlectricity>, [">= 1.0
|
69
|
+
s.add_dependency(%q<bert>, [">= 1.0.0"])
|
70
|
+
s.add_dependency(%q<erlectricity>, [">= 1.1.0"])
|
71
71
|
end
|
72
72
|
end
|
73
|
-
|
data/lib/bertrpc/action.rb
CHANGED
@@ -24,7 +24,7 @@ module BERTRPC
|
|
24
24
|
end
|
25
25
|
|
26
26
|
def transaction(bert_request)
|
27
|
-
sock =
|
27
|
+
sock = TCPSocket.new(@svc.host, @svc.port)
|
28
28
|
|
29
29
|
if @req.options
|
30
30
|
if @req.options[:cache] && @req.options[:cache][0] == :validation
|
@@ -44,31 +44,6 @@ module BERTRPC
|
|
44
44
|
bert_response
|
45
45
|
rescue Errno::ECONNREFUSED
|
46
46
|
raise ConnectionError.new("Unable to connect to #{@svc.host}:#{@svc.port}")
|
47
|
-
rescue Errno::EAGAIN
|
48
|
-
raise ReadTimeoutError.new(@svc.host, @svc.port, @svc.timeout)
|
49
|
-
end
|
50
|
-
|
51
|
-
# Creates a socket object which does speedy, non-blocking reads
|
52
|
-
# and can perform reliable read timeouts.
|
53
|
-
#
|
54
|
-
# Raises Timeout::Error on timeout.
|
55
|
-
#
|
56
|
-
# +host+ String address of the target TCP server
|
57
|
-
# +port+ Integer port of the target TCP server
|
58
|
-
# +timeout+ Optional Integer (in seconds) of the read timeout
|
59
|
-
def connect_to(host, port, timeout = nil)
|
60
|
-
sock = TCPSocket.new(host, port)
|
61
|
-
sock.setsockopt Socket::IPPROTO_TCP, Socket::TCP_NODELAY, 1
|
62
|
-
|
63
|
-
if timeout
|
64
|
-
secs = Integer(timeout)
|
65
|
-
usecs = Integer((timeout - secs) * 1_000_000)
|
66
|
-
optval = [secs, usecs].pack("l_2")
|
67
|
-
sock.setsockopt Socket::SOL_SOCKET, Socket::SO_RCVTIMEO, optval
|
68
|
-
sock.setsockopt Socket::SOL_SOCKET, Socket::SO_SNDTIMEO, optval
|
69
|
-
end
|
70
|
-
|
71
|
-
sock
|
72
47
|
end
|
73
48
|
end
|
74
|
-
end
|
49
|
+
end
|
data/lib/bertrpc/errors.rb
CHANGED
@@ -28,16 +28,6 @@ module BERTRPC
|
|
28
28
|
|
29
29
|
end
|
30
30
|
|
31
|
-
# Raised when we don't get a response from a server in a timely
|
32
|
-
# manner. This typically occurs in spite of a successful connection.
|
33
|
-
class ReadTimeoutError < BERTRPCError
|
34
|
-
attr_reader :host, :port, :timeout
|
35
|
-
def initialize(host, port, timeout)
|
36
|
-
@host, @port, @timeout = host, port, timeout
|
37
|
-
super("No response from #{host}:#{port} in #{timeout}s")
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
31
|
class ProtocolError < BERTRPCError
|
42
32
|
NO_HEADER = [0, "Unable to read length header from server."]
|
43
33
|
NO_DATA = [1, "Unable to read data from server."]
|
@@ -58,4 +48,4 @@ module BERTRPC
|
|
58
48
|
class InvalidOption < BERTRPCError
|
59
49
|
|
60
50
|
end
|
61
|
-
end
|
51
|
+
end
|
data/lib/bertrpc/service.rb
CHANGED
@@ -1,11 +1,10 @@
|
|
1
1
|
module BERTRPC
|
2
2
|
class Service
|
3
|
-
attr_accessor :host, :port
|
3
|
+
attr_accessor :host, :port
|
4
4
|
|
5
|
-
def initialize(host, port
|
5
|
+
def initialize(host, port)
|
6
6
|
@host = host
|
7
7
|
@port = port
|
8
|
-
@timeout = timeout
|
9
8
|
end
|
10
9
|
|
11
10
|
def call(options = nil)
|
@@ -32,4 +31,4 @@ module BERTRPC
|
|
32
31
|
end
|
33
32
|
end
|
34
33
|
end
|
35
|
-
end
|
34
|
+
end
|
data/lib/bertrpc.rb
CHANGED
data/test/action_test.rb
CHANGED
@@ -49,7 +49,7 @@ class ActionTest < Test::Unit::TestCase
|
|
49
49
|
@req = @svc.call
|
50
50
|
@call = BERTRPC::Action.new(@svc, @req, :mymod, :myfun, [])
|
51
51
|
end
|
52
|
-
|
52
|
+
|
53
53
|
should "read and write BERT-Ps from the socket" do
|
54
54
|
io = stub()
|
55
55
|
io.expects(:write).with("\000\000\000\003")
|
@@ -57,7 +57,7 @@ class ActionTest < Test::Unit::TestCase
|
|
57
57
|
io.expects(:read).with(4).returns("\000\000\000\003")
|
58
58
|
io.expects(:read).with(3).returns("bar")
|
59
59
|
io.expects(:close)
|
60
|
-
|
60
|
+
TCPSocket.expects(:new).returns(io)
|
61
61
|
assert_equal "bar", @call.transaction("foo")
|
62
62
|
end
|
63
63
|
|
@@ -66,7 +66,7 @@ class ActionTest < Test::Unit::TestCase
|
|
66
66
|
io.expects(:write).with("\000\000\000\003")
|
67
67
|
io.expects(:write).with("foo")
|
68
68
|
io.expects(:read).with(4).returns(nil)
|
69
|
-
|
69
|
+
TCPSocket.expects(:new).returns(io)
|
70
70
|
begin
|
71
71
|
@call.transaction("foo")
|
72
72
|
fail "Should have thrown an error"
|
@@ -74,14 +74,14 @@ class ActionTest < Test::Unit::TestCase
|
|
74
74
|
assert_equal 0, e.code
|
75
75
|
end
|
76
76
|
end
|
77
|
-
|
77
|
+
|
78
78
|
should "raise a ProtocolError when the data is invalid" do
|
79
79
|
io = stub()
|
80
80
|
io.expects(:write).with("\000\000\000\003")
|
81
81
|
io.expects(:write).with("foo")
|
82
82
|
io.expects(:read).with(4).returns("\000\000\000\003")
|
83
83
|
io.expects(:read).with(3).returns(nil)
|
84
|
-
|
84
|
+
TCPSocket.expects(:new).returns(io)
|
85
85
|
begin
|
86
86
|
@call.transaction("foo")
|
87
87
|
fail "Should have thrown an error"
|
@@ -89,22 +89,6 @@ class ActionTest < Test::Unit::TestCase
|
|
89
89
|
assert_equal 1, e.code
|
90
90
|
end
|
91
91
|
end
|
92
|
-
|
93
|
-
should "raise a ReadTimeoutError when the connection times out" do
|
94
|
-
io = stub()
|
95
|
-
io.expects(:write).with("\000\000\000\003")
|
96
|
-
io.expects(:write).with("foo")
|
97
|
-
io.expects(:read).with(4).raises(Errno::EAGAIN)
|
98
|
-
@call.expects(:connect_to).returns(io)
|
99
|
-
begin
|
100
|
-
@call.transaction("foo")
|
101
|
-
fail "Should have thrown an error"
|
102
|
-
rescue BERTRPC::ReadTimeoutError => e
|
103
|
-
assert_equal 0, e.code
|
104
|
-
assert_equal 'localhost', e.host
|
105
|
-
assert_equal 9941, e.port
|
106
|
-
end
|
107
|
-
end
|
108
92
|
end
|
109
93
|
end
|
110
|
-
end
|
94
|
+
end
|
data/test/service_test.rb
CHANGED
@@ -2,15 +2,10 @@ require 'test_helper'
|
|
2
2
|
|
3
3
|
class ServiceTest < Test::Unit::TestCase
|
4
4
|
context "A Service" do
|
5
|
-
should "be
|
5
|
+
should "be created with host and port" do
|
6
6
|
svc = BERTRPC::Service.new('localhost', 9941)
|
7
7
|
assert svc.is_a?(BERTRPC::Service)
|
8
8
|
end
|
9
|
-
|
10
|
-
should "be creatable with host, port, and timeout" do
|
11
|
-
svc = BERTRPC::Service.new('localhost', 9941, 5)
|
12
|
-
assert svc.is_a?(BERTRPC::Service)
|
13
|
-
end
|
14
9
|
end
|
15
10
|
|
16
11
|
context "A Service Instance's" do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bertrpc
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tom Preston-Werner
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-
|
12
|
+
date: 2009-10-19 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -20,7 +20,7 @@ dependencies:
|
|
20
20
|
requirements:
|
21
21
|
- - ">="
|
22
22
|
- !ruby/object:Gem::Version
|
23
|
-
version:
|
23
|
+
version: 1.0.0
|
24
24
|
version:
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: erlectricity
|
@@ -30,7 +30,7 @@ dependencies:
|
|
30
30
|
requirements:
|
31
31
|
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: 1.0
|
33
|
+
version: 1.1.0
|
34
34
|
version:
|
35
35
|
description:
|
36
36
|
email: tom@mojombo.com
|