1 # require 'profile'
2 require 'romp'
3
4 # client = ROMP::Client.new('tcppromp://localhost:4242', false)
5 # client = ROMP::Client.new('udppromp://localhost:4242', false)
6 client = ROMP::Client.new('unixromp:///tmp/foo', false)
7 obj = client.resolve("foo")
8
9 N = 10
10
11 # --- Test normal functions ---
12 puts "Normal functions, no synchronization"
13 GC.start
14 start_time = Time.now
15 for i in 1..N do
16 obj.foo(i)
17 end
18 obj.sync()
19 total_time = Time.now - start_time
20 puts " Total time: #{total_time}"
21 puts " Messages per second: #{N/total_time}"
22
23 sleep(1)
24
25 # --- Test oneway functions ---
26 puts "Oneway functions, with synchronization"
27 GC.start
28 start_time = Time.now
29 for i in 1..N do
30 obj.oneway_sync(:foo, i)
31 # if (i % 1000) == 0 then
32 # obj.sync
33 # end
34 end
35 obj.sync()
36 total_time = Time.now - start_time
37 puts " Total time: #{total_time}"
38 puts " Messages per second: #{N/total_time}"
39
40 puts "You should see the number #{N}:"
41 puts obj.i()
42
43 # -- Test oneway functions without sync ---
44 puts "Oneway functions, no synchronization"
45 puts "(if this is slow, it is because the TCP buffers are being filled too fast)"
46 GC.start
47 start_time = Time.now
48 for i in 1..N do
49 obj.oneway(:foo, i)
50 # if (i % 1000) == 0 then
51 # obj.sync
52 # end
53 end
54 obj.sync()
55 total_time = Time.now - start_time
56 puts " Total time: #{total_time}"
57 puts " Messages per second: #{N/total_time}"
58
59 puts "You should see the number #{N}:"
60 puts obj.i()
61 # --- Test object inspection ---
62 puts "You should see an object Foo with an element @i=#{N}"
63 puts obj.inspect()
64
65 # --- Test dup ---
66 foo = obj.methods()
67 if foo.index("dup") then
68 puts "uh oh, shouldn't have found dup"
69 end
70
71 # --- Test resopnd_to for clone ---
72 if obj.respond_to?("clone") then
73 puts "uh oh, obj should not respond to clone"
74 end
75
76 # --- Test clone ---
77 except = false
78 begin
79 obj.clone()
80 rescue NameError
81 except = true
82 end
83 if !except then
84 puts "uh oh, I was able to clone obj"
85 end
86
87 # -- Test respond_to for foo ---
88 if !obj.respond_to?("foo") then
89 puts "uh oh, obj should respond to foo!"
90 end
91
92 # --- Test iterators ---
93 puts "You should see the numbers 1, 2, and 3 on separate lines:"
94 obj.each do |i|
95 puts i
96 end
97
98 # --- Test object references ---
99 puts "You should see the number #{obj.i + 1}:"
100 b = obj.bar
101 puts b.i
102 b.release
103
104 # --- Test exceptions
105 puts "You should now see a RuntimeError get thrown:"
106 obj.throw_exception()