bertrpc 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.gitignore +5 -0
- data/LICENSE +20 -0
- data/README.md +40 -0
- data/Rakefile +57 -0
- data/VERSION +1 -0
- data/bertrpc.gemspec +63 -0
- data/lib/bertrpc/call.rb +33 -0
- data/lib/bertrpc/call_proxy.rb +11 -0
- data/lib/bertrpc/encodes.rb +61 -0
- data/lib/bertrpc/errors.rb +21 -0
- data/lib/bertrpc/mod.rb +14 -0
- data/lib/bertrpc/service.rb +14 -0
- data/lib/bertrpc.rb +9 -0
- data/test/call_proxy_test.rb +24 -0
- data/test/call_test.rb +85 -0
- data/test/encodes_test.rb +80 -0
- data/test/mod_test.rb +30 -0
- data/test/service_test.rb +28 -0
- data/test/test_helper.rb +12 -0
- metadata +89 -0
data/.document
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 Tom Preston-Werner
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
BERTRPC
|
2
|
+
=======
|
3
|
+
|
4
|
+
By Tom Preston-Werner (tom@mojombo.com)
|
5
|
+
|
6
|
+
WARNING: This software is alpha and should not be used in production without
|
7
|
+
extensive testing. You should not consider this project production ready until
|
8
|
+
it is released as 1.0.
|
9
|
+
|
10
|
+
|
11
|
+
Description
|
12
|
+
-----------
|
13
|
+
|
14
|
+
BERTRPC is a Ruby BERT-RPC client library.
|
15
|
+
|
16
|
+
|
17
|
+
Installation
|
18
|
+
------------
|
19
|
+
|
20
|
+
gem install mojombo-bertrpc -s http://gems.github.com
|
21
|
+
|
22
|
+
|
23
|
+
Example
|
24
|
+
-------
|
25
|
+
|
26
|
+
require 'bertrpc'
|
27
|
+
|
28
|
+
svc = BERTRPC::Service.new('localhost', 9999)
|
29
|
+
svc.call.calc.add(1, 2)
|
30
|
+
# => 3
|
31
|
+
|
32
|
+
This generates a BERT-RPC request like so:
|
33
|
+
|
34
|
+
-> {call, calc, add, [1, 2]}
|
35
|
+
|
36
|
+
|
37
|
+
Copyright
|
38
|
+
---------
|
39
|
+
|
40
|
+
Copyright (c) 2009 Tom Preston-Werner. See LICENSE for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "bertrpc"
|
8
|
+
gem.summary = %Q{BERTRPC is a Ruby BERT-RPC client library.}
|
9
|
+
gem.email = "tom@mojombo.com"
|
10
|
+
gem.homepage = "http://github.com/mojombo/bertrpc"
|
11
|
+
gem.authors = ["Tom Preston-Werner"]
|
12
|
+
gem.add_dependency('erlectricity', '>= 1.0.1')
|
13
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
14
|
+
end
|
15
|
+
|
16
|
+
rescue LoadError
|
17
|
+
puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
|
18
|
+
end
|
19
|
+
|
20
|
+
require 'rake/testtask'
|
21
|
+
Rake::TestTask.new(:test) do |test|
|
22
|
+
test.libs << 'lib' << 'test'
|
23
|
+
test.pattern = 'test/**/*_test.rb'
|
24
|
+
test.verbose = true
|
25
|
+
end
|
26
|
+
|
27
|
+
begin
|
28
|
+
require 'rcov/rcovtask'
|
29
|
+
Rcov::RcovTask.new do |test|
|
30
|
+
test.libs << 'test'
|
31
|
+
test.pattern = 'test/**/*_test.rb'
|
32
|
+
test.verbose = true
|
33
|
+
end
|
34
|
+
rescue LoadError
|
35
|
+
task :rcov do
|
36
|
+
abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
|
41
|
+
task :default => :test
|
42
|
+
|
43
|
+
require 'rake/rdoctask'
|
44
|
+
Rake::RDocTask.new do |rdoc|
|
45
|
+
if File.exist?('VERSION.yml')
|
46
|
+
config = YAML.load(File.read('VERSION.yml'))
|
47
|
+
version = "#{config[:major]}.#{config[:minor]}.#{config[:patch]}"
|
48
|
+
else
|
49
|
+
version = ""
|
50
|
+
end
|
51
|
+
|
52
|
+
rdoc.rdoc_dir = 'rdoc'
|
53
|
+
rdoc.title = "bertrpc #{version}"
|
54
|
+
rdoc.rdoc_files.include('README*')
|
55
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
56
|
+
end
|
57
|
+
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.2.0
|
data/bertrpc.gemspec
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = %q{bertrpc}
|
5
|
+
s.version = "0.2.0"
|
6
|
+
|
7
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
8
|
+
s.authors = ["Tom Preston-Werner"]
|
9
|
+
s.date = %q{2009-08-13}
|
10
|
+
s.email = %q{tom@mojombo.com}
|
11
|
+
s.extra_rdoc_files = [
|
12
|
+
"LICENSE",
|
13
|
+
"README.md"
|
14
|
+
]
|
15
|
+
s.files = [
|
16
|
+
".document",
|
17
|
+
".gitignore",
|
18
|
+
"LICENSE",
|
19
|
+
"README.md",
|
20
|
+
"Rakefile",
|
21
|
+
"VERSION",
|
22
|
+
"bertrpc.gemspec",
|
23
|
+
"lib/bertrpc.rb",
|
24
|
+
"lib/bertrpc/call.rb",
|
25
|
+
"lib/bertrpc/call_proxy.rb",
|
26
|
+
"lib/bertrpc/encodes.rb",
|
27
|
+
"lib/bertrpc/errors.rb",
|
28
|
+
"lib/bertrpc/mod.rb",
|
29
|
+
"lib/bertrpc/service.rb",
|
30
|
+
"test/call_proxy_test.rb",
|
31
|
+
"test/call_test.rb",
|
32
|
+
"test/encodes_test.rb",
|
33
|
+
"test/mod_test.rb",
|
34
|
+
"test/service_test.rb",
|
35
|
+
"test/test_helper.rb"
|
36
|
+
]
|
37
|
+
s.homepage = %q{http://github.com/mojombo/bertrpc}
|
38
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
39
|
+
s.require_paths = ["lib"]
|
40
|
+
s.rubygems_version = %q{1.3.5}
|
41
|
+
s.summary = %q{BERTRPC is a Ruby BERT-RPC client library.}
|
42
|
+
s.test_files = [
|
43
|
+
"test/call_proxy_test.rb",
|
44
|
+
"test/call_test.rb",
|
45
|
+
"test/encodes_test.rb",
|
46
|
+
"test/mod_test.rb",
|
47
|
+
"test/service_test.rb",
|
48
|
+
"test/test_helper.rb"
|
49
|
+
]
|
50
|
+
|
51
|
+
if s.respond_to? :specification_version then
|
52
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
53
|
+
s.specification_version = 3
|
54
|
+
|
55
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
56
|
+
s.add_runtime_dependency(%q<erlectricity>, [">= 1.0.1"])
|
57
|
+
else
|
58
|
+
s.add_dependency(%q<erlectricity>, [">= 1.0.1"])
|
59
|
+
end
|
60
|
+
else
|
61
|
+
s.add_dependency(%q<erlectricity>, [">= 1.0.1"])
|
62
|
+
end
|
63
|
+
end
|
data/lib/bertrpc/call.rb
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
module BERTRPC
|
2
|
+
class Call
|
3
|
+
include Encodes
|
4
|
+
|
5
|
+
def initialize(svc, mod, fun, args)
|
6
|
+
@svc = svc
|
7
|
+
@mod = mod
|
8
|
+
@fun = fun
|
9
|
+
@args = args
|
10
|
+
end
|
11
|
+
|
12
|
+
def execute
|
13
|
+
bert_request = encode_ruby_request([:call, @mod, @fun, @args])
|
14
|
+
bert_response = sync_request(bert_request)
|
15
|
+
decode_bert_response(bert_response)
|
16
|
+
end
|
17
|
+
|
18
|
+
#private
|
19
|
+
|
20
|
+
def sync_request(bert_request)
|
21
|
+
sock = TCPSocket.new(@svc.host, @svc.port)
|
22
|
+
sock.write([bert_request.length].pack("N"))
|
23
|
+
sock.write(bert_request)
|
24
|
+
lenheader = sock.read(4)
|
25
|
+
raise ProtocolError.new("Unable to read length header from server.") unless lenheader
|
26
|
+
len = lenheader.unpack('N').first
|
27
|
+
bert_response = sock.read(len)
|
28
|
+
raise ProtocolError.new("Unable to read data from server.") unless bert_response
|
29
|
+
sock.close
|
30
|
+
bert_response
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
module BERTRPC
|
2
|
+
module Encodes
|
3
|
+
def encode_ruby_request(ruby_request)
|
4
|
+
ruby_payload = convert(ruby_request)
|
5
|
+
Erlectricity::Encoder.encode(ruby_payload)
|
6
|
+
end
|
7
|
+
|
8
|
+
def decode_bert_response(bert_response)
|
9
|
+
ruby_response = Erlectricity::Decoder.decode(bert_response)
|
10
|
+
case ruby_response[0]
|
11
|
+
when :reply
|
12
|
+
deconvert(ruby_response[1])
|
13
|
+
when :error
|
14
|
+
error(ruby_response[1])
|
15
|
+
else
|
16
|
+
raise
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def error(err)
|
21
|
+
case err[0]
|
22
|
+
when :protocol
|
23
|
+
raise ProtocolError.new(err[2])
|
24
|
+
when :server
|
25
|
+
raise ServerError.new(err[2])
|
26
|
+
when :user
|
27
|
+
raise UserError.new(err[2])
|
28
|
+
when :proxy
|
29
|
+
raise ProxyError.new(err[2])
|
30
|
+
else
|
31
|
+
raise
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def convert(item)
|
36
|
+
if item.instance_of?(Hash)
|
37
|
+
a = [:dict]
|
38
|
+
item.each_pair { |k, v| a << [convert(k), convert(v)] }
|
39
|
+
a
|
40
|
+
elsif item.instance_of?(Array)
|
41
|
+
item.map { |x| convert(x) }
|
42
|
+
else
|
43
|
+
item
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def deconvert(item)
|
48
|
+
if item.instance_of?(Array)
|
49
|
+
if item.first == :dict
|
50
|
+
item[1..-1].inject({}) do |acc, x|
|
51
|
+
acc[deconvert(x[0])] = deconvert(x[1]); acc
|
52
|
+
end
|
53
|
+
else
|
54
|
+
item.map { |x| deconvert(x) }
|
55
|
+
end
|
56
|
+
else
|
57
|
+
item
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module BERTRPC
|
2
|
+
class BERTRPCError < StandardError
|
3
|
+
|
4
|
+
end
|
5
|
+
|
6
|
+
class ProtocolError < BERTRPCError
|
7
|
+
|
8
|
+
end
|
9
|
+
|
10
|
+
class ServerError < BERTRPCError
|
11
|
+
|
12
|
+
end
|
13
|
+
|
14
|
+
class UserError < BERTRPCError
|
15
|
+
|
16
|
+
end
|
17
|
+
|
18
|
+
class ProxyError < BERTRPCError
|
19
|
+
|
20
|
+
end
|
21
|
+
end
|
data/lib/bertrpc/mod.rb
ADDED
data/lib/bertrpc.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class CallProxyTest < Test::Unit::TestCase
|
4
|
+
context "A CallProxy" do
|
5
|
+
setup do
|
6
|
+
@svc = BERTRPC::Service.new('localhost', 9941)
|
7
|
+
end
|
8
|
+
|
9
|
+
should "be created with a Service" do
|
10
|
+
assert BERTRPC::CallProxy.new(@svc).is_a?(BERTRPC::CallProxy)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
context "A CallProxy instance" do
|
15
|
+
setup do
|
16
|
+
svc = BERTRPC::Service.new('localhost', 9941)
|
17
|
+
@cp = BERTRPC::CallProxy.new(@svc)
|
18
|
+
end
|
19
|
+
|
20
|
+
should "return a Mod instance" do
|
21
|
+
assert @cp.myfun.is_a?(BERTRPC::Mod)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
data/test/call_test.rb
ADDED
@@ -0,0 +1,85 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class CallTest < Test::Unit::TestCase
|
4
|
+
context "A Call" do
|
5
|
+
setup do
|
6
|
+
@svc = BERTRPC::Service.new('localhost', 9941)
|
7
|
+
end
|
8
|
+
|
9
|
+
should "be created with a Service, module name, fun name, and args" do
|
10
|
+
assert BERTRPC::Call.new(@svc, :mymod, :myfun, [1, 2]).is_a?(BERTRPC::Call)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
context "A Call instance" do
|
15
|
+
setup do
|
16
|
+
@svc = BERTRPC::Service.new('localhost', 9941)
|
17
|
+
@enc = Enc.new
|
18
|
+
end
|
19
|
+
|
20
|
+
should "call with single-arity" do
|
21
|
+
req = @enc.encode_ruby_request([:call, :mymod, :myfun, [1]])
|
22
|
+
res = @enc.encode_ruby_request([:reply, 2])
|
23
|
+
call = BERTRPC::Call.new(@svc, :mymod, :myfun, [1])
|
24
|
+
call.expects(:sync_request).with(req).returns(res)
|
25
|
+
assert_equal 2, call.execute
|
26
|
+
end
|
27
|
+
|
28
|
+
should "call with single-arity array" do
|
29
|
+
req = @enc.encode_ruby_request([:call, :mymod, :myfun, [[1, 2, 3]]])
|
30
|
+
res = @enc.encode_ruby_request([:reply, [4, 5, 6]])
|
31
|
+
call = BERTRPC::Call.new(@svc, :mymod, :myfun, [[1, 2, 3]])
|
32
|
+
call.expects(:sync_request).with(req).returns(res)
|
33
|
+
assert_equal [4, 5, 6], call.execute
|
34
|
+
end
|
35
|
+
|
36
|
+
should "call with multi-arity" do
|
37
|
+
req = @enc.encode_ruby_request([:call, :mymod, :myfun, [1, 2, 3]])
|
38
|
+
res = @enc.encode_ruby_request([:reply, [4, 5, 6]])
|
39
|
+
call = BERTRPC::Call.new(@svc, :mymod, :myfun, [1, 2, 3])
|
40
|
+
call.expects(:sync_request).with(req).returns(res)
|
41
|
+
assert_equal [4, 5, 6], call.execute
|
42
|
+
end
|
43
|
+
|
44
|
+
context "sync_request" do
|
45
|
+
setup do
|
46
|
+
@svc = BERTRPC::Service.new('localhost', 9941)
|
47
|
+
@call = BERTRPC::Call.new(@svc, :mymod, :myfun, [])
|
48
|
+
end
|
49
|
+
|
50
|
+
should "read and write BERT-Ps from the socket" do
|
51
|
+
io = stub()
|
52
|
+
io.expects(:write).with("\000\000\000\003")
|
53
|
+
io.expects(:write).with("foo")
|
54
|
+
io.expects(:read).with(4).returns("\000\000\000\003")
|
55
|
+
io.expects(:read).with(3).returns("bar")
|
56
|
+
io.expects(:close)
|
57
|
+
TCPSocket.expects(:new).returns(io)
|
58
|
+
assert_equal "bar", @call.sync_request("foo")
|
59
|
+
end
|
60
|
+
|
61
|
+
should "raise a ProtocolError when the length is invalid" do
|
62
|
+
io = stub()
|
63
|
+
io.expects(:write).with("\000\000\000\003")
|
64
|
+
io.expects(:write).with("foo")
|
65
|
+
io.expects(:read).with(4).returns(nil)
|
66
|
+
TCPSocket.expects(:new).returns(io)
|
67
|
+
assert_raises(BERTRPC::ProtocolError) do
|
68
|
+
@call.sync_request("foo")
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
should "raise a ProtocolError when the data is invalid" do
|
73
|
+
io = stub()
|
74
|
+
io.expects(:write).with("\000\000\000\003")
|
75
|
+
io.expects(:write).with("foo")
|
76
|
+
io.expects(:read).with(4).returns("\000\000\000\003")
|
77
|
+
io.expects(:read).with(3).returns(nil)
|
78
|
+
TCPSocket.expects(:new).returns(io)
|
79
|
+
assert_raises(BERTRPC::ProtocolError) do
|
80
|
+
@call.sync_request("foo")
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
@@ -0,0 +1,80 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class EncodesTest < Test::Unit::TestCase
|
4
|
+
context "An Encodes includer" do
|
5
|
+
setup do
|
6
|
+
@enc = Enc.new
|
7
|
+
end
|
8
|
+
|
9
|
+
context "converter" do
|
10
|
+
should "convert top level hashes to BERT-RPC dict form" do
|
11
|
+
assert_equal([:dict, [:foo, 1], [:bar, 2]], @enc.convert({:foo => 1, :bar => 2}))
|
12
|
+
end
|
13
|
+
|
14
|
+
should "convert nested hashes in the same way" do
|
15
|
+
assert_equal([1, 2, [:dict, [:foo, 1]]], @enc.convert([1, 2, {:foo => 1}]))
|
16
|
+
end
|
17
|
+
|
18
|
+
should "keep everything else the same" do
|
19
|
+
assert_equal [1, 2, "foo", :bar, 3.14], @enc.convert([1, 2, "foo", :bar, 3.14])
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
context "deconverter" do
|
24
|
+
should "convert top level BERT-RPC dict forms to hashes" do
|
25
|
+
assert_equal({:foo => 1, :bar => 2}, @enc.deconvert([:dict, [:foo, 1], [:bar, 2]]))
|
26
|
+
end
|
27
|
+
|
28
|
+
should "convert nested dicts in the same way" do
|
29
|
+
assert_equal([1, 2, {:foo => 1}], @enc.deconvert([1, 2, [:dict, [:foo, 1]]]))
|
30
|
+
end
|
31
|
+
|
32
|
+
should "keep everything else the same" do
|
33
|
+
assert_equal [1, 2, "foo", :bar, 3.14], @enc.deconvert([1, 2, "foo", :bar, 3.14])
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
context "ruby request encoder" do
|
38
|
+
should "return BERT-RPC encoded request" do
|
39
|
+
bert = "\203h\004d\000\004calld\000\005mymodd\000\005myfunh\003a\001a\002a\003"
|
40
|
+
assert_equal bert, @enc.encode_ruby_request([:call, :mymod, :myfun, [1, 2, 3]])
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
context "bert response decoder" do
|
45
|
+
should "return response when successful" do
|
46
|
+
req = @enc.encode_ruby_request([:reply, [1, 2, 3]])
|
47
|
+
res = @enc.decode_bert_response(req)
|
48
|
+
assert_equal [1, 2, 3], res
|
49
|
+
end
|
50
|
+
|
51
|
+
should "raise a ProtocolError error when protocol level error is returned" do
|
52
|
+
req = @enc.encode_ruby_request([:error, [:protocol, 1, "invalid"]])
|
53
|
+
assert_raises(BERTRPC::ProtocolError) do
|
54
|
+
@enc.decode_bert_response(req)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
should "raise a ServerError error when server level error is returned" do
|
59
|
+
req = @enc.encode_ruby_request([:error, [:server, 1, "invalid"]])
|
60
|
+
assert_raises(BERTRPC::ServerError) do
|
61
|
+
@enc.decode_bert_response(req)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
should "raise a UserError error when user level error is returned" do
|
66
|
+
req = @enc.encode_ruby_request([:error, [:user, 1, "invalid"]])
|
67
|
+
assert_raises(BERTRPC::UserError) do
|
68
|
+
@enc.decode_bert_response(req)
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
should "raise a ProxyError error when proxy level error is returned" do
|
73
|
+
req = @enc.encode_ruby_request([:error, [:proxy, 1, "invalid"]])
|
74
|
+
assert_raises(BERTRPC::ProxyError) do
|
75
|
+
@enc.decode_bert_response(req)
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
data/test/mod_test.rb
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class ModTest < Test::Unit::TestCase
|
4
|
+
context "A Mod" do
|
5
|
+
setup do
|
6
|
+
@svc = BERTRPC::Service.new('localhost', 9941)
|
7
|
+
end
|
8
|
+
|
9
|
+
should "be created with a Service and type and module name" do
|
10
|
+
assert BERTRPC::Mod.new(@svc, BERTRPC::Call, :mymod).is_a?(BERTRPC::Mod)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
context "A Mod instance" do
|
15
|
+
setup do
|
16
|
+
@svc = BERTRPC::Service.new('localhost', 9941)
|
17
|
+
@mod = BERTRPC::Mod.new(@svc, BERTRPC::Call, :mymod)
|
18
|
+
end
|
19
|
+
|
20
|
+
should "call execute on the type" do
|
21
|
+
m = mock(:execute => nil)
|
22
|
+
BERTRPC::Call.expects(:new).with(@svc, :mymod, :myfun, [1, 2, 3]).returns(m)
|
23
|
+
@mod.myfun(1, 2, 3)
|
24
|
+
|
25
|
+
m = mock(:execute => nil)
|
26
|
+
BERTRPC::Call.expects(:new).with(@svc, :mymod, :myfun, [1]).returns(m)
|
27
|
+
@mod.myfun(1)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class ServiceTest < Test::Unit::TestCase
|
4
|
+
context "A Service" do
|
5
|
+
should "be created with host and port" do
|
6
|
+
svc = BERTRPC::Service.new('localhost', 9941)
|
7
|
+
assert svc.is_a?(BERTRPC::Service)
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
context "A Service Instance" do
|
12
|
+
setup do
|
13
|
+
@svc = BERTRPC::Service.new('localhost', 9941)
|
14
|
+
end
|
15
|
+
|
16
|
+
should "return it's host" do
|
17
|
+
assert_equal 'localhost', @svc.host
|
18
|
+
end
|
19
|
+
|
20
|
+
should "return it's port" do
|
21
|
+
assert_equal 9941, @svc.port
|
22
|
+
end
|
23
|
+
|
24
|
+
should "return a Call instance" do
|
25
|
+
assert @svc.call.is_a?(BERTRPC::CallProxy)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'test/unit'
|
3
|
+
require 'shoulda'
|
4
|
+
require 'mocha'
|
5
|
+
|
6
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
7
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
8
|
+
require 'bertrpc'
|
9
|
+
|
10
|
+
class Enc
|
11
|
+
include BERTRPC::Encodes
|
12
|
+
end
|
metadata
ADDED
@@ -0,0 +1,89 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: bertrpc
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Tom Preston-Werner
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-08-13 00:00:00 -07:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: erlectricity
|
17
|
+
type: :runtime
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 1.0.1
|
24
|
+
version:
|
25
|
+
description:
|
26
|
+
email: tom@mojombo.com
|
27
|
+
executables: []
|
28
|
+
|
29
|
+
extensions: []
|
30
|
+
|
31
|
+
extra_rdoc_files:
|
32
|
+
- LICENSE
|
33
|
+
- README.md
|
34
|
+
files:
|
35
|
+
- .document
|
36
|
+
- .gitignore
|
37
|
+
- LICENSE
|
38
|
+
- README.md
|
39
|
+
- Rakefile
|
40
|
+
- VERSION
|
41
|
+
- bertrpc.gemspec
|
42
|
+
- lib/bertrpc.rb
|
43
|
+
- lib/bertrpc/call.rb
|
44
|
+
- lib/bertrpc/call_proxy.rb
|
45
|
+
- lib/bertrpc/encodes.rb
|
46
|
+
- lib/bertrpc/errors.rb
|
47
|
+
- lib/bertrpc/mod.rb
|
48
|
+
- lib/bertrpc/service.rb
|
49
|
+
- test/call_proxy_test.rb
|
50
|
+
- test/call_test.rb
|
51
|
+
- test/encodes_test.rb
|
52
|
+
- test/mod_test.rb
|
53
|
+
- test/service_test.rb
|
54
|
+
- test/test_helper.rb
|
55
|
+
has_rdoc: true
|
56
|
+
homepage: http://github.com/mojombo/bertrpc
|
57
|
+
licenses: []
|
58
|
+
|
59
|
+
post_install_message:
|
60
|
+
rdoc_options:
|
61
|
+
- --charset=UTF-8
|
62
|
+
require_paths:
|
63
|
+
- lib
|
64
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: "0"
|
69
|
+
version:
|
70
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - ">="
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: "0"
|
75
|
+
version:
|
76
|
+
requirements: []
|
77
|
+
|
78
|
+
rubyforge_project:
|
79
|
+
rubygems_version: 1.3.5
|
80
|
+
signing_key:
|
81
|
+
specification_version: 3
|
82
|
+
summary: BERTRPC is a Ruby BERT-RPC client library.
|
83
|
+
test_files:
|
84
|
+
- test/call_proxy_test.rb
|
85
|
+
- test/call_test.rb
|
86
|
+
- test/encodes_test.rb
|
87
|
+
- test/mod_test.rb
|
88
|
+
- test/service_test.rb
|
89
|
+
- test/test_helper.rb
|