1 # require 'profile'
 2 require 'druby3'
 3 
 4 client = DRuby::Client.new('localhost', '4242', false)
 5 obj = client.resolve("foo")
 6 
 7 N = 10000
 8 
 9 # --- Test normal functions ---
10 puts "Normal functions, no synchronization"
11 start_time = Time.now
12 for i in 1..N do
13     obj.foo(i)
14 end
15 obj.sync()
16 total_time = Time.now - start_time
17 puts "  Total time: #{total_time}"
18 puts "  Messages per second: #{N/total_time}"
19 
20 # TODO: For some reason, mixing normal function calls with oneway calls
21 # causes the oneways to run at 1/10 regular speed
22 client = DRuby::Client.new('localhost', '4242', false)
23 obj = client.resolve("foo")
24 
25 # --- Test oneway functions ---
26 puts "Oneway functions, no synchronization"
27 start_time = Time.now
28 for i in 1..N do
29     obj.oneway(:foo, i)
30 end
31 obj.sync()
32 total_time = Time.now - start_time
33 puts "  Total time: #{total_time}"
34 puts "  Messages per second: #{N/total_time}"
35 
36 puts "You should see the number #{N}:"
37 puts obj.i()
38 
39 # --- Test object inspection ---
40 puts "You should see an object Foo with an element @i=#{N}"
41 puts obj.inspect()
42 
43 # --- Test dup ---
44 foo = obj.methods()
45 if foo.index("dup") then
46     puts "uh oh, shouldn't have found dup"
47 end
48 
49 # --- Test resopnd_to for clone ---
50 if obj.respond_to?("clone") then
51     puts "uh oh, obj should not respond to clone"
52 end
53 
54 # --- Test clone ---
55 except = false
56 begin
57     obj.clone()
58 rescue NameError
59     except = true
60 end
61 if !except then
62     puts "uh oh, I was able to clone obj"
63 end
64 
65 # -- Test respond_to for foo ---
66 if !obj.respond_to?("foo") then
67     puts "uh oh, obj should respond to foo!"
68 end
69 
70 # --- Test iterators ---
71 puts "You should see the numbers 1, 2, and 3 on separate lines:"
72 obj.each do |i|
73     puts i
74 end
75 
76 # --- Test object references ---
77 puts "You should see the number #{obj.i + 1}:"
78 b = obj.bar
79 puts b.i
80 
81 # --- Test exceptions
82 puts "You should now see a RuntimeError get thrown:"
83 obj.throw_exception()