blob: 3edff1cbccdd7142d971c6680dcd438bfa945824 [file] [log] [blame]
Mark Sleefc89d392006-09-04 00:04:39 +00001#!/usr/bin/python
2
3import sys
4sys.path.append('./gen-py')
5
6import ThriftTest
7from ThriftTest_types import *
Mark Sleec9676562006-09-05 17:34:52 +00008from thrift.transport import TTransport
Mark Sleefc89d392006-09-04 00:04:39 +00009from thrift.transport import TSocket
10from thrift.protocol import TBinaryProtocol
11
Mark Sleec9676562006-09-05 17:34:52 +000012import timing
13
14transport = TTransport.TBufferedTransport(TSocket.TSocket('localhost', 9090))
Mark Sleefc89d392006-09-04 00:04:39 +000015protocol = TBinaryProtocol.TBinaryProtocol()
16client = ThriftTest.Client(transport, protocol)
17
18transport.open()
19
Mark Sleec9676562006-09-05 17:34:52 +000020# Start debug timing
21timing.start()
22
Mark Sleefc89d392006-09-04 00:04:39 +000023print "testVoid()"
24print client.testVoid()
25
Mark Sleec9676562006-09-05 17:34:52 +000026print "testString('Python')"
27print client.testString('Python')
Mark Sleefc89d392006-09-04 00:04:39 +000028
29print "testByte(63)"
30print client.testByte(63)
31
Mark Sleec9676562006-09-05 17:34:52 +000032print "testI32(-1)"
33print client.testI32(-1)
34
Mark Sleec98d0502006-09-06 02:42:25 +000035print "testI32(0)"
36print client.testI32(0)
37
Mark Sleec9676562006-09-05 17:34:52 +000038print "testI64(-34359738368)"
39print client.testI64(-34359738368)
40
Mark Sleec98d0502006-09-06 02:42:25 +000041print "testDouble(-5.235098235)"
42print client.testDouble(-5.235098235)
43
Mark Sleec9676562006-09-05 17:34:52 +000044print "testStruct({Zero, 1, -3, -5})"
45x = Xtruct()
46x.string_thing = "Zero"
47x.byte_thing = 1
48x.i32_thing = -3
49x.i64_thing = -5
50x = client.testStruct(x)
51print "{%s, %d, %d, %d}" % (x.string_thing, x.byte_thing, x.i32_thing, x.i64_thing)
52
Mark Sleefc89d392006-09-04 00:04:39 +000053print "testException('Safe')"
54print client.testException('Safe')
55
Mark Sleefc89d392006-09-04 00:04:39 +000056try:
Mark Sleec9676562006-09-05 17:34:52 +000057 print "textException('Xception')"
Mark Sleefc89d392006-09-04 00:04:39 +000058 print client.testException('Xception')
Mark Sleec9676562006-09-05 17:34:52 +000059
Mark Sleefc89d392006-09-04 00:04:39 +000060except Xception, x:
Mark Sleec9676562006-09-05 17:34:52 +000061 print "Xception (%d, %s)" % (x.errorCode, x.message)
62
63timing.finish()
64print "Total time: %d microsecs" % timing.micro()
Mark Sleefc89d392006-09-04 00:04:39 +000065
66transport.close()