blob: 21d199085fa65198ca5b5cc06ddfeb95e328aeb8 [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
35print "testI64(-34359738368)"
36print client.testI64(-34359738368)
37
38print "testStruct({Zero, 1, -3, -5})"
39x = Xtruct()
40x.string_thing = "Zero"
41x.byte_thing = 1
42x.i32_thing = -3
43x.i64_thing = -5
44x = client.testStruct(x)
45print "{%s, %d, %d, %d}" % (x.string_thing, x.byte_thing, x.i32_thing, x.i64_thing)
46
Mark Sleefc89d392006-09-04 00:04:39 +000047print "testException('Safe')"
48print client.testException('Safe')
49
Mark Sleefc89d392006-09-04 00:04:39 +000050try:
Mark Sleec9676562006-09-05 17:34:52 +000051 print "textException('Xception')"
Mark Sleefc89d392006-09-04 00:04:39 +000052 print client.testException('Xception')
Mark Sleec9676562006-09-05 17:34:52 +000053
Mark Sleefc89d392006-09-04 00:04:39 +000054except Xception, x:
Mark Sleec9676562006-09-05 17:34:52 +000055 print "Xception (%d, %s)" % (x.errorCode, x.message)
56
57timing.finish()
58print "Total time: %d microsecs" % timing.micro()
Mark Sleefc89d392006-09-04 00:04:39 +000059
60transport.close()