~ubuntu-branches/ubuntu/hardy/ruby1.8/hardy-updates

« back to all changes in this revision

Viewing changes to test/drb/ut_drb.rb

  • Committer: Bazaar Package Importer
  • Author(s): akira yamada
  • Date: 2007-03-13 22:11:58 UTC
  • mfrom: (1.1.5 upstream)
  • Revision ID: james.westby@ubuntu.com-20070313221158-h3oql37brlaf2go2
Tags: 1.8.6-1
* new upstream version, 1.8.6.
* libruby1.8 conflicts with libopenssl-ruby1.8 (< 1.8.6) (closes: #410018)
* changed packaging style to cdbs from dbs.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
require 'drb/drb'
 
2
require 'drb/extserv'
 
3
require 'timeout'
 
4
 
 
5
class XArray < Array
 
6
  def initialize(ary)
 
7
    ary.each do |x|
 
8
      self.push(x)
 
9
    end
 
10
  end
 
11
end
 
12
 
 
13
class XArray2 < XArray
 
14
  include DRbUndumped
 
15
end
 
16
 
 
17
class Unknown2
 
18
  def initialize
 
19
    @foo = 'unknown2'
 
20
  end
 
21
end
 
22
 
 
23
class DRbEx
 
24
  include DRbUndumped
 
25
 
 
26
  class FooBar
 
27
    def initialize
 
28
      @foo = 'bar'
 
29
    end
 
30
  end
 
31
 
 
32
  class UError < RuntimeError; end
 
33
 
 
34
  def initialize
 
35
    @hello = 'hello'
 
36
  end
 
37
  attr_reader :hello
 
38
 
 
39
  def sample(a, b, c)
 
40
    a.to_i + b.to_i + c.to_i
 
41
  end
 
42
 
 
43
  def sum(*a)
 
44
    s = 0
 
45
    a.each do |e|
 
46
      s += e.to_i
 
47
    end
 
48
    s
 
49
  end
 
50
 
 
51
  def do_timeout(n)
 
52
    timeout(0.1) do
 
53
      n.sleep(2)
 
54
    end
 
55
  end
 
56
 
 
57
  def unknown_module
 
58
    FooBar.new
 
59
  end
 
60
 
 
61
  def unknown_class
 
62
    Unknown2.new
 
63
  end
 
64
 
 
65
  def unknown_error
 
66
    raise UError
 
67
  end
 
68
 
 
69
  def remote_no_method_error
 
70
    invoke_no_method(self)
 
71
  end
 
72
 
 
73
  def test_yield
 
74
    yield
 
75
    yield([])
 
76
    yield(*[])
 
77
  end
 
78
 
 
79
  def echo_yield(*arg)
 
80
    yield(*arg)
 
81
    nil
 
82
  end
 
83
 
 
84
  def echo_yield_0
 
85
    yield
 
86
    nil
 
87
  end
 
88
 
 
89
  def echo_yield_1(one)
 
90
    yield(one)
 
91
    nil
 
92
  end
 
93
 
 
94
  def echo_yield_2(one, two)
 
95
    yield(one, two)
 
96
    nil
 
97
  end
 
98
 
 
99
  def xarray_each
 
100
    xary = [XArray.new([0])]
 
101
    xary.each do |x|
 
102
      yield(x)
 
103
    end
 
104
    nil
 
105
  end
 
106
 
 
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
 
113
 
 
114
  def simple_hash
 
115
    unless @hash
 
116
      @hash = { 'a'=>:a, 'b'=>:b }
 
117
    end
 
118
    DRbObject.new(@hash)
 
119
  end
 
120
 
 
121
  def [](key)
 
122
    key.to_s
 
123
  end
 
124
 
 
125
  def to_a
 
126
    [self]
 
127
  end
 
128
 
 
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
 
136
 
 
137
  private
 
138
  def call_private_method
 
139
    true
 
140
  end
 
141
 
 
142
  protected
 
143
  def call_protected_method
 
144
    true
 
145
  end
 
146
end
 
147
 
 
148
if __FILE__ == $0
 
149
  def ARGV.shift
 
150
    it = super()
 
151
    raise "usage: #{$0} <manager-uri> <name>" unless it
 
152
    it
 
153
  end
 
154
 
 
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
 
160
end