2016-02-04 21:28:22 +09:00
|
|
|
-- Licensed to the Apache Software Foundation (ASF) under one
|
|
|
|
|
-- or more contributor license agreements. See the NOTICE file
|
|
|
|
|
-- distributed with this work for additional information
|
|
|
|
|
-- regarding copyright ownership. The ASF licenses this file
|
|
|
|
|
-- to you under the Apache License, Version 2.0 (the
|
|
|
|
|
-- "License"); you may not use this file except in compliance
|
|
|
|
|
-- with the License. You may obtain a copy of the License at
|
|
|
|
|
|
|
|
|
|
-- http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
|
|
-- Unless required by applicable law or agreed to in writing,
|
|
|
|
|
-- software distributed under the License is distributed on an
|
|
|
|
|
-- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
|
|
|
-- KIND, either express or implied. See the License for the
|
|
|
|
|
-- specific language governing permissions and limitations
|
|
|
|
|
-- under the License.
|
2014-04-05 00:45:42 +02:00
|
|
|
|
|
|
|
|
require('ThriftTest_ThriftTest')
|
|
|
|
|
require('TSocket')
|
2016-02-19 00:50:17 +09:00
|
|
|
require('TBufferedTransport')
|
2014-04-05 00:45:42 +02:00
|
|
|
require('TFramedTransport')
|
2016-03-09 16:39:03 +08:00
|
|
|
require('THttpTransport')
|
2016-02-19 00:50:17 +09:00
|
|
|
require('TCompactProtocol')
|
|
|
|
|
require('TJsonProtocol')
|
2014-04-05 00:45:42 +02:00
|
|
|
require('TBinaryProtocol')
|
|
|
|
|
require('TServer')
|
2024-07-28 15:32:23 +02:00
|
|
|
local liblualongnumber = require('liblualongnumber')
|
2014-04-05 00:45:42 +02:00
|
|
|
|
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
|
-- Handler
|
|
|
|
|
TestHandler = ThriftTestIface:new{}
|
|
|
|
|
|
|
|
|
|
-- Stops the server
|
|
|
|
|
function TestHandler:testVoid()
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function TestHandler:testString(str)
|
|
|
|
|
return str
|
|
|
|
|
end
|
|
|
|
|
|
2016-02-19 00:50:17 +09:00
|
|
|
function TestHandler:testBool(bool)
|
|
|
|
|
return bool
|
|
|
|
|
end
|
|
|
|
|
|
2014-04-05 00:45:42 +02:00
|
|
|
function TestHandler:testByte(byte)
|
|
|
|
|
return byte
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function TestHandler:testI32(i32)
|
|
|
|
|
return i32
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function TestHandler:testI64(i64)
|
|
|
|
|
return i64
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function TestHandler:testDouble(d)
|
|
|
|
|
return d
|
|
|
|
|
end
|
|
|
|
|
|
THRIFT-2886 Integrate binary type in standard Thrift cross test
Client: C_glib, C++, D, Erlang, Go, Haskell, Lua, Java/Me, JavaScript, Node, Ocaml, Perl, PHP, Python, Ruby
Patch: Jens Geyer
This closes #341
Minimal server-side implementations and TODO stubs for various languages to let "make check" succeeed.
Not contained in this patch and still TODO:
- client side implementations, i.e. calls to testBinary() and appropriate tests
- server side hex printout missing for some languages
2014-12-14 03:14:26 +01:00
|
|
|
function TestHandler:testBinary(by)
|
|
|
|
|
return by
|
|
|
|
|
end
|
|
|
|
|
|
2024-07-28 15:32:23 +02:00
|
|
|
function TestHandler:testUuid(uuid)
|
|
|
|
|
return uuid
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function TestHandler:testNest(thing)
|
|
|
|
|
return thing
|
|
|
|
|
end
|
|
|
|
|
|
2014-04-05 00:45:42 +02:00
|
|
|
function TestHandler:testStruct(thing)
|
|
|
|
|
return thing
|
|
|
|
|
end
|
|
|
|
|
|
2024-07-28 15:32:23 +02:00
|
|
|
function TestHandler:testMap(thing)
|
|
|
|
|
return thing
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function TestHandler:testStringMap(thing)
|
|
|
|
|
return thing
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function TestHandler:testSet(thing)
|
|
|
|
|
return thing
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function TestHandler:testList(thing)
|
|
|
|
|
return thing
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function TestHandler:testEnum(thing)
|
|
|
|
|
return thing
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function TestHandler:testTypedef(thing)
|
|
|
|
|
return thing
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function TestHandler:testMapMap(hello)
|
|
|
|
|
return {
|
|
|
|
|
["-4"] = {
|
|
|
|
|
["-4"] = -4,
|
|
|
|
|
["-3"] = -3,
|
|
|
|
|
["-2"] = -2,
|
|
|
|
|
["-1"] = -1
|
|
|
|
|
},
|
|
|
|
|
["4"] = {
|
|
|
|
|
["1"] = 1,
|
|
|
|
|
["2"] = 2,
|
|
|
|
|
["3"] = 3,
|
|
|
|
|
["4"] = 4
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function TestHandler:testInsanity(argument)
|
|
|
|
|
local first_map = {
|
|
|
|
|
[Numberz.TWO] = argument,
|
|
|
|
|
[Numberz.THREE] = argument
|
|
|
|
|
};
|
|
|
|
|
local second_map = {
|
|
|
|
|
[Numberz.SIX] = Insanity:new {
|
|
|
|
|
userMap = {},
|
|
|
|
|
xtructs = {}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
["1"] = first_map,
|
|
|
|
|
["2"] = second_map
|
|
|
|
|
};
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function TestHandler:testMulti(arg0, arg1, arg2, arg3, arg4, arg5)
|
|
|
|
|
return Xtruct:new {}
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function TestHandler:testException(arg)
|
|
|
|
|
if arg == "Xception" then
|
|
|
|
|
return Xception:new {
|
|
|
|
|
errorCode = 1001,
|
|
|
|
|
message = arg
|
|
|
|
|
}
|
|
|
|
|
elseif arg == "TException" then
|
|
|
|
|
error("")
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function TestHandler:testMultiException(arg0, arg1)
|
|
|
|
|
if arg0 == "Xception" then
|
|
|
|
|
return Xception:new {
|
|
|
|
|
errorCode = 1001,
|
|
|
|
|
message = "This is an Xception"
|
|
|
|
|
}
|
|
|
|
|
elseif arg0 == "Xception2" then
|
|
|
|
|
return Xception2:new {
|
|
|
|
|
errorCode = 2002,
|
|
|
|
|
struct_thing = Xtruct:new {
|
|
|
|
|
string_thing = "This is an Xception2"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
elseif arg0 == "TException" then
|
|
|
|
|
error("")
|
|
|
|
|
end
|
|
|
|
|
return Xtruct:new {
|
|
|
|
|
string_thing = arg1
|
|
|
|
|
}
|
|
|
|
|
end
|
|
|
|
|
|
2020-08-04 22:01:09 +08:00
|
|
|
function TestHandler:testOneway(secondsToSleep)
|
|
|
|
|
print("testOneway secondsToSleep:", secondsToSleep)
|
|
|
|
|
end
|
|
|
|
|
|
2014-04-05 00:45:42 +02:00
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
|
-- Test
|
|
|
|
|
local server
|
|
|
|
|
|
|
|
|
|
function teardown()
|
|
|
|
|
if server then
|
|
|
|
|
server:close()
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2016-02-19 00:50:17 +09:00
|
|
|
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)
|
2014-04-05 00:45:42 +02:00
|
|
|
-- Handler & Processor
|
|
|
|
|
local handler = TestHandler:new{}
|
|
|
|
|
assert(handler, 'Failed to create handler')
|
|
|
|
|
local processor = ThriftTestProcessor:new{
|
|
|
|
|
handler = handler
|
|
|
|
|
}
|
|
|
|
|
assert(processor, 'Failed to create processor')
|
|
|
|
|
|
|
|
|
|
-- Server Socket
|
|
|
|
|
local socket = TServerSocket:new{
|
2016-02-19 00:50:17 +09:00
|
|
|
port = opt.port
|
2014-04-05 00:45:42 +02:00
|
|
|
}
|
|
|
|
|
assert(socket, 'Failed to create server socket')
|
|
|
|
|
|
|
|
|
|
-- Transport & Factory
|
2016-02-19 00:50:17 +09:00
|
|
|
local transports = {
|
|
|
|
|
buffered = TBufferedTransportFactory,
|
|
|
|
|
framed = TFramedTransportFactory,
|
2016-03-09 16:39:03 +08:00
|
|
|
http = THttpTransportFactory,
|
2016-02-19 00:50:17 +09:00
|
|
|
}
|
|
|
|
|
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{}
|
2014-04-05 00:45:42 +02:00
|
|
|
assert(prot_factory, 'Failed to create binary protocol factory')
|
|
|
|
|
|
|
|
|
|
-- Simple Server
|
|
|
|
|
server = TSimpleServer:new{
|
|
|
|
|
processor = processor,
|
|
|
|
|
serverTransport = socket,
|
|
|
|
|
transportFactory = trans_factory,
|
|
|
|
|
protocolFactory = prot_factory
|
|
|
|
|
}
|
|
|
|
|
assert(server, 'Failed to create server')
|
2020-08-04 22:01:09 +08:00
|
|
|
server:setExceptionHandler(function (err) error(err) end)
|
2014-04-05 00:45:42 +02:00
|
|
|
|
|
|
|
|
-- Serve
|
|
|
|
|
server:serve()
|
|
|
|
|
server = nil
|
|
|
|
|
end
|
|
|
|
|
|
2016-02-19 00:50:17 +09:00
|
|
|
testBasicServer(arg)
|
|
|
|
|
teardown()
|