summaryrefslogtreecommitdiffstats
path: root/src/jaegertracing/thrift/test/lua
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 18:45:59 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 18:45:59 +0000
commit19fcec84d8d7d21e796c7624e521b60d28ee21ed (patch)
tree42d26aa27d1e3f7c0b8bd3fd14e7d7082f5008dc /src/jaegertracing/thrift/test/lua
parentInitial commit. (diff)
downloadceph-upstream/16.2.11+ds.tar.xz
ceph-upstream/16.2.11+ds.zip
Adding upstream version 16.2.11+ds.upstream/16.2.11+dsupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/jaegertracing/thrift/test/lua')
-rw-r--r--src/jaegertracing/thrift/test/lua/Makefile.am34
-rw-r--r--src/jaegertracing/thrift/test/lua/test_basic_client.lua179
-rw-r--r--src/jaegertracing/thrift/test/lua/test_basic_server.lua142
3 files changed, 355 insertions, 0 deletions
diff --git a/src/jaegertracing/thrift/test/lua/Makefile.am b/src/jaegertracing/thrift/test/lua/Makefile.am
new file mode 100644
index 000000000..b2683e1b9
--- /dev/null
+++ b/src/jaegertracing/thrift/test/lua/Makefile.am
@@ -0,0 +1,34 @@
+#
+# 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.
+#
+
+THRIFT = $(top_builddir)/compiler/cpp/thrift
+
+# Remove "MapType =" line to ignore some map bug for now
+stubs: ../ThriftTest.thrift $(THRIFT)
+ $(THRIFT) --gen lua $<
+ $(SED) -i.bak 's/MapType =//g' gen-lua/ThriftTest_ttypes.lua
+ $(RM) gen-lua/ThriftTest_ttypes.lua.bak
+
+precross: stubs
+
+clean-local:
+ $(RM) -r gen-lua/
+
+dist-hook:
+ $(RM) -r $(distdir)/gen-lua/
diff --git a/src/jaegertracing/thrift/test/lua/test_basic_client.lua b/src/jaegertracing/thrift/test/lua/test_basic_client.lua
new file mode 100644
index 000000000..77d8d078a
--- /dev/null
+++ b/src/jaegertracing/thrift/test/lua/test_basic_client.lua
@@ -0,0 +1,179 @@
+-- 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.
+
+
+require('TSocket')
+require('TBufferedTransport')
+require('TFramedTransport')
+require('THttpTransport')
+require('TCompactProtocol')
+require('TJsonProtocol')
+require('TBinaryProtocol')
+require('ThriftTest_ThriftTest')
+require('liblualongnumber')
+
+local client
+
+function teardown()
+ if client then
+ -- close the connection
+ client:close()
+ end
+end
+
+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 assertEqual(val1, val2, msg)
+ assert(val1 == val2, msg)
+end
+
+function testBasicClient(rawArgs)
+ local opt = parseArgs(rawArgs)
+ local socket = TSocket:new{
+ port = tonumber(opt.port)
+ }
+ assert(socket, 'Failed to create client socket')
+ socket:setTimeout(5000)
+
+ local transports = {
+ buffered = TBufferedTransport,
+ framed = TFramedTransport,
+ http = THttpTransport,
+ }
+ assert(transports[opt.transport] ~= nil)
+ local transport = transports[opt.transport]:new{
+ trans = socket,
+ isServer = false
+ }
+
+ local protocols = {
+ binary = TBinaryProtocol,
+ compact = TCompactProtocol,
+ json = TJSONProtocol,
+ }
+ assert(protocols[opt.protocol] ~= nil)
+ local protocol = protocols[opt.protocol]:new{
+ trans = transport
+ }
+ assert(protocol, 'Failed to create binary protocol')
+
+ client = ThriftTestClient:new{
+ protocol = protocol
+ }
+ assert(client, 'Failed to create client')
+
+ -- Open the transport
+ local status, _ = pcall(transport.open, transport)
+ assert(status, 'Failed to connect to server')
+
+ -- String
+ assertEqual(client:testString('lala'), 'lala', 'Failed testString')
+ assertEqual(client:testString('wahoo'), 'wahoo', 'Failed testString')
+
+ -- Bool
+ assertEqual(client:testBool(true), true, 'Failed testBool true')
+ assertEqual(client:testBool(false), false, 'Failed testBool false')
+
+ -- Byte
+ assertEqual(client:testByte(0x01), 1, 'Failed testByte 1')
+ assertEqual(client:testByte(0x40), 64, 'Failed testByte 2')
+ assertEqual(client:testByte(0x7f), 127, 'Failed testByte 3')
+ assertEqual(client:testByte(0x80), -128, 'Failed testByte 4')
+ assertEqual(client:testByte(0xbf), -65, 'Failed testByte 5')
+ assertEqual(client:testByte(0xff), -1, 'Failed testByte 6')
+ assertEqual(client:testByte(128), -128, 'Failed testByte 7')
+ assertEqual(client:testByte(255), -1, 'Failed testByte 8')
+
+ -- I32
+ assertEqual(client:testI32(0x00000001), 1, 'Failed testI32 1')
+ assertEqual(client:testI32(0x40000000), 1073741824, 'Failed testI32 2')
+ assertEqual(client:testI32(0x7fffffff), 2147483647, 'Failed testI32 3')
+ assertEqual(client:testI32(0x80000000), -2147483648, 'Failed testI32 4')
+ assertEqual(client:testI32(0xbfffffff), -1073741825, 'Failed testI32 5')
+ assertEqual(client:testI32(0xffffffff), -1, 'Failed testI32 6')
+ assertEqual(client:testI32(2147483648), -2147483648, 'Failed testI32 7')
+ assertEqual(client:testI32(4294967295), -1, 'Failed testI32 8')
+
+ -- I64 (lua only supports 16 decimal precision so larger numbers are
+ -- initialized by their string value)
+ local long = liblualongnumber.new
+ assertEqual(client:testI64(long(0x0000000000000001)),
+ long(1),
+ 'Failed testI64 1')
+ assertEqual(client:testI64(long(0x4000000000000000)),
+ long(4611686018427387904),
+ 'Failed testI64 2')
+ assertEqual(client:testI64(long('0x7fffffffffffffff')),
+ long('9223372036854775807'),
+ 'Failed testI64 3')
+ assertEqual(client:testI64(long(0x8000000000000000)),
+ long(-9223372036854775808),
+ 'Failed testI64 4')
+ assertEqual(client:testI64(long('0xbfffffffffffffff')),
+ long('-4611686018427387905'),
+ 'Failed testI64 5')
+ assertEqual(client:testI64(long('0xffffffffffffffff')),
+ long(-1),
+ 'Failed testI64 6')
+
+ -- Double
+ assertEqual(
+ client:testDouble(1.23456789), 1.23456789, 'Failed testDouble 1')
+ assertEqual(
+ client:testDouble(0.123456789), 0.123456789, 'Failed testDouble 2')
+ assertEqual(
+ client:testDouble(0.123456789), 0.123456789, 'Failed testDouble 3')
+
+ -- TODO testBinary() ...
+
+ -- Accuracy of 16 decimal digits (rounds)
+ local a, b = 1.12345678906666663, 1.12345678906666661
+ assertEqual(a, b)
+ assertEqual(client:testDouble(a), b, 'Failed testDouble 5')
+
+ -- Struct
+ local o = Xtruct:new{
+ string_thing = 'Zero',
+ byte_thing = 1,
+ i32_thing = -3,
+ i64_thing = long(-5)
+ }
+ local r = client:testStruct(o)
+ assertEqual(o.string_thing, r.string_thing, 'Failed testStruct 1')
+ assertEqual(o.byte_thing, r.byte_thing, 'Failed testStruct 2')
+ assertEqual(o.i32_thing, r.i32_thing, 'Failed testStruct 3')
+ assertEqual(o.i64_thing, r.i64_thing, 'Failed testStruct 4')
+
+ -- TODO add list map set exception etc etc
+end
+
+testBasicClient(arg)
+teardown()
diff --git a/src/jaegertracing/thrift/test/lua/test_basic_server.lua b/src/jaegertracing/thrift/test/lua/test_basic_server.lua
new file mode 100644
index 000000000..acd2d79b8
--- /dev/null
+++ b/src/jaegertracing/thrift/test/lua/test_basic_server.lua
@@ -0,0 +1,142 @@
+-- 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.
+
+require('ThriftTest_ThriftTest')
+require('TSocket')
+require('TBufferedTransport')
+require('TFramedTransport')
+require('THttpTransport')
+require('TCompactProtocol')
+require('TJsonProtocol')
+require('TBinaryProtocol')
+require('TServer')
+require('liblualongnumber')
+
+--------------------------------------------------------------------------------
+-- Handler
+TestHandler = ThriftTestIface:new{}
+
+-- Stops the server
+function TestHandler:testVoid()
+end
+
+function TestHandler:testString(str)
+ return str
+end
+
+function TestHandler:testBool(bool)
+ return bool
+end
+
+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
+
+function TestHandler:testBinary(by)
+ return by
+end
+
+function TestHandler:testStruct(thing)
+ return thing
+end
+
+--------------------------------------------------------------------------------
+-- Test
+local server
+
+function teardown()
+ if server then
+ server:close()
+ end
+end
+
+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')
+ local processor = ThriftTestProcessor:new{
+ handler = handler
+ }
+ assert(processor, 'Failed to create processor')
+
+ -- Server Socket
+ local socket = TServerSocket:new{
+ port = opt.port
+ }
+ assert(socket, 'Failed to create server socket')
+
+ -- Transport & Factory
+ local transports = {
+ buffered = TBufferedTransportFactory,
+ framed = TFramedTransportFactory,
+ http = THttpTransportFactory,
+ }
+ 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
+ server = TSimpleServer:new{
+ processor = processor,
+ serverTransport = socket,
+ transportFactory = trans_factory,
+ protocolFactory = prot_factory
+ }
+ assert(server, 'Failed to create server')
+
+ -- Serve
+ server:serve()
+ server = nil
+end
+
+testBasicServer(arg)
+teardown()