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