2015-12-16 00:07:31 -05:00
|
|
|
# frozen_string_literal: false
|
2003-10-20 11:24:00 -04:00
|
|
|
require 'drb/drb'
|
|
|
|
require 'drb/extserv'
|
|
|
|
require 'timeout'
|
|
|
|
|
2014-05-31 23:07:58 -04:00
|
|
|
module DRbTests
|
|
|
|
|
2003-10-20 11:24:00 -04:00
|
|
|
class XArray < Array
|
|
|
|
def initialize(ary)
|
|
|
|
ary.each do |x|
|
|
|
|
self.push(x)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
class XArray2 < XArray
|
|
|
|
include DRbUndumped
|
|
|
|
end
|
|
|
|
|
|
|
|
class Unknown2
|
|
|
|
def initialize
|
|
|
|
@foo = 'unknown2'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
class DRbEx
|
|
|
|
include DRbUndumped
|
|
|
|
|
|
|
|
class FooBar
|
|
|
|
def initialize
|
|
|
|
@foo = 'bar'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
class UError < RuntimeError; end
|
|
|
|
|
|
|
|
def initialize
|
2012-09-19 10:49:19 -04:00
|
|
|
@xary2_hash = nil
|
|
|
|
@hash = nil
|
2003-10-20 11:24:00 -04:00
|
|
|
@hello = 'hello'
|
|
|
|
end
|
|
|
|
attr_reader :hello
|
|
|
|
|
|
|
|
def sample(a, b, c)
|
|
|
|
a.to_i + b.to_i + c.to_i
|
|
|
|
end
|
|
|
|
|
|
|
|
def sum(*a)
|
|
|
|
s = 0
|
|
|
|
a.each do |e|
|
|
|
|
s += e.to_i
|
|
|
|
end
|
|
|
|
s
|
|
|
|
end
|
|
|
|
|
|
|
|
def do_timeout(n)
|
2015-07-13 06:07:01 -04:00
|
|
|
Timeout.timeout(0.1) do
|
2003-10-20 11:24:00 -04:00
|
|
|
n.sleep(2)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def unknown_module
|
|
|
|
FooBar.new
|
|
|
|
end
|
|
|
|
|
|
|
|
def unknown_class
|
|
|
|
Unknown2.new
|
|
|
|
end
|
|
|
|
|
|
|
|
def unknown_error
|
|
|
|
raise UError
|
|
|
|
end
|
|
|
|
|
2004-12-11 07:12:17 -05:00
|
|
|
def remote_no_method_error
|
|
|
|
invoke_no_method(self)
|
|
|
|
end
|
|
|
|
|
2003-10-20 11:24:00 -04:00
|
|
|
def test_yield
|
|
|
|
yield
|
|
|
|
yield([])
|
|
|
|
yield(*[])
|
|
|
|
end
|
|
|
|
|
|
|
|
def echo_yield(*arg)
|
|
|
|
yield(*arg)
|
|
|
|
nil
|
|
|
|
end
|
|
|
|
|
|
|
|
def echo_yield_0
|
|
|
|
yield
|
|
|
|
nil
|
|
|
|
end
|
|
|
|
|
|
|
|
def echo_yield_1(one)
|
|
|
|
yield(one)
|
|
|
|
nil
|
|
|
|
end
|
|
|
|
|
|
|
|
def echo_yield_2(one, two)
|
|
|
|
yield(one, two)
|
|
|
|
nil
|
|
|
|
end
|
|
|
|
|
|
|
|
def xarray_each
|
|
|
|
xary = [XArray.new([0])]
|
|
|
|
xary.each do |x|
|
|
|
|
yield(x)
|
|
|
|
end
|
|
|
|
nil
|
|
|
|
end
|
|
|
|
|
|
|
|
def xarray2_hash
|
|
|
|
unless @xary2_hash
|
|
|
|
@xary2_hash = { "a" => XArray2.new([0]), "b" => XArray2.new([1]) }
|
|
|
|
end
|
|
|
|
DRbObject.new(@xary2_hash)
|
|
|
|
end
|
|
|
|
|
2003-10-30 08:30:48 -05:00
|
|
|
def simple_hash
|
|
|
|
unless @hash
|
|
|
|
@hash = { 'a'=>:a, 'b'=>:b }
|
|
|
|
end
|
|
|
|
DRbObject.new(@hash)
|
|
|
|
end
|
|
|
|
|
2003-10-20 11:24:00 -04:00
|
|
|
def [](key)
|
|
|
|
key.to_s
|
|
|
|
end
|
|
|
|
|
|
|
|
def to_a
|
|
|
|
[self]
|
|
|
|
end
|
|
|
|
|
2005-07-31 12:19:42 -04:00
|
|
|
def method_missing(msg, *a, &b)
|
|
|
|
if msg == :missing
|
|
|
|
return true
|
|
|
|
else
|
|
|
|
super(msg, *a, &b)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2003-10-20 11:24:00 -04:00
|
|
|
private
|
|
|
|
def call_private_method
|
|
|
|
true
|
|
|
|
end
|
2005-07-31 12:19:42 -04:00
|
|
|
|
|
|
|
protected
|
|
|
|
def call_protected_method
|
|
|
|
true
|
|
|
|
end
|
2003-10-20 11:24:00 -04:00
|
|
|
end
|
|
|
|
|
2014-05-31 23:07:58 -04:00
|
|
|
end
|
|
|
|
|
2003-10-20 11:24:00 -04:00
|
|
|
if __FILE__ == $0
|
|
|
|
def ARGV.shift
|
|
|
|
it = super()
|
|
|
|
raise "usage: #{$0} <manager-uri> <name>" unless it
|
|
|
|
it
|
|
|
|
end
|
|
|
|
|
|
|
|
DRb::DRbServer.default_argc_limit(8)
|
2003-10-30 08:30:48 -05:00
|
|
|
DRb::DRbServer.default_load_limit(4096)
|
2014-05-31 23:07:58 -04:00
|
|
|
DRb.start_service('druby://localhost:0', DRbTests::DRbEx.new)
|
2012-09-19 21:59:52 -04:00
|
|
|
es = DRb::ExtServ.new(ARGV.shift, ARGV.shift)
|
2003-10-20 11:24:00 -04:00
|
|
|
DRb.thread.join
|
2012-09-19 21:59:52 -04:00
|
|
|
es.stop_service if es.alive?
|
2003-10-20 11:24:00 -04:00
|
|
|
end
|