r1306@dev030 (orig r66287): mcslee | 2007-10-30 09:55:47 -0700
[amiethrift.git] / test / rb / TestServer.rb
blob892037ec7b1c13c0431cd82b69ba1e6aef8e625e
1 #!/usr/bin/env ruby
3 $:.push('gen-rb')
4 $:.push('../../lib/rb/lib')
6 require 'thrift/transport/tsocket'
7 require 'thrift/protocol/tbinaryprotocol'
8 require 'thrift/server/tserver'
9 require 'ThriftTest'
11 class TestHandler
12   def testVoid()
13     print "testVoid()\n"
14   end
16   def testString(thing)
17     print "testString(#{thing})\n"
18     return thing
19   end
21   def testByte(thing)
22     print "testByte(#{thing})\n"
23     return thing
24   end
26   def testI32(thing)
27     print "testI32(#{thing})\n"
28     return thing
29   end
31   def testI64(thing)
32     print "testI64(#{thing})\n"
33     return thing
34   end
36   def testDouble(thing)
37     print "testDouble(#{thing})\n"
38     return thing
39   end
41   def testStruct(thing)
42     print "testStruct(#{thing})\n"
43     print "  with attrs: #{thing.string_thing}, #{thing.byte_thing}, #{thing.i32_thing}"
44     return thing
45   end
47   def testMap(thing)
48     print "testMap(#{thing})\n"
49     return thing
50   end
51     
52   def testSet(thing)
53     print "testSet(#{thing})\n"
54     return thing
55   end
57   def testList(thing)
58     print "testList(#{thing})\n"
59     return thing
60   end
62   def testNest(thing)
63     print "testNest(#{thing})\n"
64     puts "  i32_thing: #{thing.i32_thing}"
65     puts "  with struct: "
66     %w{ string_thing byte_thing i32_thing }.each do |t|
67       puts "    #{t}: #{thing.struct_thing.send(t)}"
68     end
69     return thing
70   end
71   
72   def testNest(thing)
73     print "testNest(#{thing})\n"
74     puts "  i32_thing: #{thing.i32_thing}"
75     puts "  with struct: "
76     %w{ string_thing byte_thing i32_thing }.each do |t|
77       puts "    #{t}: #{thing.struct_thing.send(t)}"
78     end
79     return thing
80   end
81   
82   def testInsanity(thing)
83     puts "insanity:"
84     puts "  #{thing.inspect}"
85     num, uid = thing.userMap.find { true }
86     return {uid => {num => thing}}
87   end
89   def testMapMap(thing)
90     puts "got: #{thing}"
91     return {thing => {thing => thing}}
92   end
94 end
96 handler = TestHandler.new()
97 processor = Thrift::Test::ThriftTest::Processor.new(handler)
98 transport = TServerSocket.new(9090)
99 server = TSimpleServer.new(processor, transport)
100 server.serve()