Updated MSpec source to 1c3ee1c8.
[rbx.git] / test / mri / drb / ut_drb.rb
blobf5720cfca2f5b5a784c1fef2f12e9efcd7581e8f
1 require 'drb/drb'
2 require 'drb/extserv'
3 require 'timeout'
5 class XArray < Array
6   def initialize(ary)
7     ary.each do |x|
8       self.push(x)
9     end
10   end
11 end
13 class XArray2 < XArray
14   include DRbUndumped
15 end
17 class Unknown2
18   def initialize
19     @foo = 'unknown2'
20   end
21 end
23 class DRbEx
24   include DRbUndumped
26   class FooBar
27     def initialize
28       @foo = 'bar'
29     end
30   end
32   class UError < RuntimeError; end
34   def initialize
35     @hello = 'hello'
36   end
37   attr_reader :hello
39   def sample(a, b, c)
40     a.to_i + b.to_i + c.to_i
41   end
43   def sum(*a)
44     s = 0
45     a.each do |e|
46       s += e.to_i
47     end
48     s
49   end
51   def do_timeout(n)
52     timeout(0.1) do
53       n.sleep(2)
54     end
55   end
57   def unknown_module
58     FooBar.new
59   end
61   def unknown_class
62     Unknown2.new
63   end
65   def unknown_error
66     raise UError
67   end
69   def remote_no_method_error
70     invoke_no_method(self)
71   end
73   def test_yield
74     yield
75     yield([])
76     yield(*[])
77   end
79   def echo_yield(*arg)
80     yield(*arg)
81     nil
82   end
84   def echo_yield_0
85     yield
86     nil
87   end
89   def echo_yield_1(one)
90     yield(one)
91     nil
92   end
94   def echo_yield_2(one, two)
95     yield(one, two)
96     nil
97   end
99   def xarray_each
100     xary = [XArray.new([0])]
101     xary.each do |x|
102       yield(x)
103     end
104     nil
105   end
107   def xarray2_hash
108     unless @xary2_hash
109       @xary2_hash = { "a" => XArray2.new([0]), "b" => XArray2.new([1]) }
110     end
111     DRbObject.new(@xary2_hash)
112   end
114   def simple_hash
115     unless @hash
116       @hash = { 'a'=>:a, 'b'=>:b }
117     end
118     DRbObject.new(@hash)
119   end
121   def [](key)
122     key.to_s
123   end
125   def to_a
126     [self]
127   end
129   def method_missing(msg, *a, &b)
130     if msg == :missing
131       return true
132     else
133       super(msg, *a, &b)
134     end
135   end
137   private
138   def call_private_method
139     true
140   end
142   protected
143   def call_protected_method
144     true
145   end
148 if __FILE__ == $0
149   def ARGV.shift
150     it = super()
151     raise "usage: #{$0} <manager-uri> <name>" unless it
152     it
153   end
155   DRb::DRbServer.default_argc_limit(8)
156   DRb::DRbServer.default_load_limit(4096)
157   DRb.start_service('druby://localhost:0', DRbEx.new)
158   es = DRb::ExtServ.new(ARGV.shift, ARGV.shift)
159   DRb.thread.join