Mark Slee | fc89d39 | 2006-09-04 00:04:39 +0000 | [diff] [blame] | 1 | #!/usr/bin/python |
| 2 | |
| 3 | import sys |
| 4 | sys.path.append('./gen-py') |
| 5 | |
| 6 | import ThriftTest |
| 7 | from ThriftTest_types import * |
Mark Slee | c967656 | 2006-09-05 17:34:52 +0000 | [diff] [blame^] | 8 | from thrift.transport import TTransport |
Mark Slee | fc89d39 | 2006-09-04 00:04:39 +0000 | [diff] [blame] | 9 | from thrift.transport import TSocket |
| 10 | from thrift.protocol import TBinaryProtocol |
| 11 | |
Mark Slee | c967656 | 2006-09-05 17:34:52 +0000 | [diff] [blame^] | 12 | import timing |
| 13 | |
| 14 | transport = TTransport.TBufferedTransport(TSocket.TSocket('localhost', 9090)) |
Mark Slee | fc89d39 | 2006-09-04 00:04:39 +0000 | [diff] [blame] | 15 | protocol = TBinaryProtocol.TBinaryProtocol() |
| 16 | client = ThriftTest.Client(transport, protocol) |
| 17 | |
| 18 | transport.open() |
| 19 | |
Mark Slee | c967656 | 2006-09-05 17:34:52 +0000 | [diff] [blame^] | 20 | # Start debug timing |
| 21 | timing.start() |
| 22 | |
Mark Slee | fc89d39 | 2006-09-04 00:04:39 +0000 | [diff] [blame] | 23 | print "testVoid()" |
| 24 | print client.testVoid() |
| 25 | |
Mark Slee | c967656 | 2006-09-05 17:34:52 +0000 | [diff] [blame^] | 26 | print "testString('Python')" |
| 27 | print client.testString('Python') |
Mark Slee | fc89d39 | 2006-09-04 00:04:39 +0000 | [diff] [blame] | 28 | |
| 29 | print "testByte(63)" |
| 30 | print client.testByte(63) |
| 31 | |
Mark Slee | c967656 | 2006-09-05 17:34:52 +0000 | [diff] [blame^] | 32 | print "testI32(-1)" |
| 33 | print client.testI32(-1) |
| 34 | |
| 35 | print "testI64(-34359738368)" |
| 36 | print client.testI64(-34359738368) |
| 37 | |
| 38 | print "testStruct({Zero, 1, -3, -5})" |
| 39 | x = Xtruct() |
| 40 | x.string_thing = "Zero" |
| 41 | x.byte_thing = 1 |
| 42 | x.i32_thing = -3 |
| 43 | x.i64_thing = -5 |
| 44 | x = client.testStruct(x) |
| 45 | print "{%s, %d, %d, %d}" % (x.string_thing, x.byte_thing, x.i32_thing, x.i64_thing) |
| 46 | |
Mark Slee | fc89d39 | 2006-09-04 00:04:39 +0000 | [diff] [blame] | 47 | print "testException('Safe')" |
| 48 | print client.testException('Safe') |
| 49 | |
Mark Slee | fc89d39 | 2006-09-04 00:04:39 +0000 | [diff] [blame] | 50 | try: |
Mark Slee | c967656 | 2006-09-05 17:34:52 +0000 | [diff] [blame^] | 51 | print "textException('Xception')" |
Mark Slee | fc89d39 | 2006-09-04 00:04:39 +0000 | [diff] [blame] | 52 | print client.testException('Xception') |
Mark Slee | c967656 | 2006-09-05 17:34:52 +0000 | [diff] [blame^] | 53 | |
Mark Slee | fc89d39 | 2006-09-04 00:04:39 +0000 | [diff] [blame] | 54 | except Xception, x: |
Mark Slee | c967656 | 2006-09-05 17:34:52 +0000 | [diff] [blame^] | 55 | print "Xception (%d, %s)" % (x.errorCode, x.message) |
| 56 | |
| 57 | timing.finish() |
| 58 | print "Total time: %d microsecs" % timing.micro() |
Mark Slee | fc89d39 | 2006-09-04 00:04:39 +0000 | [diff] [blame] | 59 | |
| 60 | transport.close() |