blob: 0247bc27443f6567659ccd2f810531297763d396 [file] [log] [blame]
Mark Slee57cc25e2007-02-28 21:43:54 +00001#!/usr/bin/env python
Mark Sleec9676562006-09-05 17:34:52 +00002
David Reissdb893b62008-02-18 02:11:48 +00003import sys, glob, time
Mark Slee5299a952007-10-05 00:13:24 +00004sys.path.insert(0, './gen-py')
5sys.path.insert(0, glob.glob('../../lib/py/build/lib.*')[0])
Mark Sleec9676562006-09-05 17:34:52 +00006
Mark Slee57cc25e2007-02-28 21:43:54 +00007from ThriftTest import ThriftTest
8from ThriftTest.ttypes import *
Mark Sleed788b2e2006-09-07 01:26:35 +00009from thrift.transport import TTransport
Mark Sleec9676562006-09-05 17:34:52 +000010from thrift.transport import TSocket
11from thrift.protocol import TBinaryProtocol
12from thrift.server import TServer
13
14class TestHandler:
15
16 def testVoid(self):
17 print 'testVoid()'
18
19 def testString(self, str):
20 print 'testString(%s)' % str
21 return str
22
23 def testByte(self, byte):
24 print 'testByte(%d)' % byte
25 return byte
26
Mark Sleec98d0502006-09-06 02:42:25 +000027 def testI16(self, i16):
28 print 'testI16(%d)' % i16
29 return i16
30
31 def testI32(self, i32):
32 print 'testI32(%d)' % i32
33 return i32
34
35 def testI64(self, i64):
36 print 'testI64(%d)' % i64
37 return i64
38
39 def testDouble(self, dub):
40 print 'testDouble(%f)' % dub
41 return dub
42
43 def testStruct(self, thing):
44 print 'testStruct({%s, %d, %d, %d})' % (thing.string_thing, thing.byte_thing, thing.i32_thing, thing.i64_thing)
45 return thing
46
Mark Sleec9676562006-09-05 17:34:52 +000047 def testException(self, str):
48 print 'testException(%s)' % str
Mark Sleec98d0502006-09-06 02:42:25 +000049 if str == 'Xception':
50 x = Xception()
51 x.errorCode = 1001
52 x.message = str
53 raise x
David Reissbcaa2ad2008-06-10 22:55:26 +000054 elif str == "throw_undeclared":
55 raise ValueError("foo")
Mark Sleec9676562006-09-05 17:34:52 +000056
David Reissdb893b62008-02-18 02:11:48 +000057 def testAsync(self, seconds):
58 print 'testAsync(%d) => sleeping...' % seconds
59 time.sleep(seconds)
60 print 'done sleeping'
61
Mark Sleec9676562006-09-05 17:34:52 +000062handler = TestHandler()
Mark Slee1dd819c2006-10-26 04:56:18 +000063processor = ThriftTest.Processor(handler)
64transport = TSocket.TServerSocket(9090)
65tfactory = TTransport.TBufferedTransportFactory()
66pfactory = TBinaryProtocol.TBinaryProtocolFactory()
David Reissbcaa2ad2008-06-10 22:55:26 +000067
68ServerClass = getattr(TServer, sys.argv[1])
69
70server = ServerClass(processor, transport, tfactory, pfactory)
Mark Slee794993d2006-09-20 01:56:10 +000071server.serve()