diff options
author | Nobuaki Sukegawa <nsuke@apache.org> | 2016-02-19 00:50:17 +0900 |
---|---|---|
committer | Nobuaki Sukegawa <nsuke@apache.org> | 2016-02-20 00:44:54 +0900 |
commit | 23ffb312900bbbadf49dfee270391803e194a436 (patch) | |
tree | 7de80b92cc893207c6c6e9e5e4464d137f9770b8 /test/lua | |
parent | 08d67d7163688a28e7bcae78339e1fe9710437a8 (diff) | |
download | thrift-23ffb312900bbbadf49dfee270391803e194a436.tar.gz |
THIFT-3645 Add command line args and testBool handler to Lua test server
Client: Test (Lua)
Patch: Nobuaki Sukegawa
This closes #876
Diffstat (limited to 'test/lua')
-rw-r--r-- | test/lua/test_basic_server.lua | 47 |
1 files changed, 40 insertions, 7 deletions
diff --git a/test/lua/test_basic_server.lua b/test/lua/test_basic_server.lua index 9dbf7079c..864b63d5d 100644 --- a/test/lua/test_basic_server.lua +++ b/test/lua/test_basic_server.lua @@ -17,7 +17,10 @@ require('ThriftTest_ThriftTest') require('TSocket') +require('TBufferedTransport') require('TFramedTransport') +require('TCompactProtocol') +require('TJsonProtocol') require('TBinaryProtocol') require('TServer') require('liblualongnumber') @@ -34,6 +37,10 @@ function TestHandler:testString(str) return str end +function TestHandler:testBool(bool) + return bool +end + function TestHandler:testByte(byte) return byte end @@ -68,7 +75,24 @@ function teardown() end end -function testBasicServer() +function parseArgs(rawArgs) + local opt = { + protocol='binary', + transport='buffered', + port='9090', + } + for i, str in pairs(rawArgs) do + if i > 0 then + k, v = string.match(str, '--(%w+)=(%w+)') + assert(opt[k] ~= nil, 'Unknown argument') + opt[k] = v + end + end + return opt +end + +function testBasicServer(rawArgs) + local opt = parseArgs(rawArgs) -- Handler & Processor local handler = TestHandler:new{} assert(handler, 'Failed to create handler') @@ -79,14 +103,23 @@ function testBasicServer() -- Server Socket local socket = TServerSocket:new{ - port = 9090 + port = opt.port } assert(socket, 'Failed to create server socket') -- Transport & Factory - local trans_factory = TFramedTransportFactory:new{} - assert(trans_factory, 'Failed to create framed transport factory') - local prot_factory = TBinaryProtocolFactory:new{} + local transports = { + buffered = TBufferedTransportFactory, + framed = TFramedTransportFactory, + } + assert(transports[opt.transport], 'Failed to create framed transport factory') + local trans_factory = transports[opt.transport]:new{} + local protocols = { + binary = TBinaryProtocolFactory, + compact = TCompactProtocolFactory, + json = TJSONProtocolFactory, + } + local prot_factory = protocols[opt.protocol]:new{} assert(prot_factory, 'Failed to create binary protocol factory') -- Simple Server @@ -103,5 +136,5 @@ function testBasicServer() server = nil end -testBasicServer() -teardown()
\ No newline at end of file +testBasicServer(arg) +teardown() |