Skip to content

Commit

Permalink
THRIFT-3592 Add basic test client
Browse files Browse the repository at this point in the history
This closes #830
  • Loading branch information
nsuke committed Feb 2, 2016
1 parent f07b4a1 commit d094e79
Show file tree
Hide file tree
Showing 8 changed files with 124 additions and 14 deletions.
2 changes: 1 addition & 1 deletion Makefile.am
Expand Up @@ -46,7 +46,7 @@ empty :=
space := $(empty) $(empty)
comma := ,

CROSS_LANGS = @MAYBE_CPP@ @MAYBE_C_GLIB@ @MAYBE_JAVA@ @MAYBE_CSHARP@ @MAYBE_PYTHON@ @MAYBE_PY3@ @MAYBE_RUBY@ @MAYBE_HASKELL@ @MAYBE_PERL@ @MAYBE_PHP@ @MAYBE_GO@ @MAYBE_NODEJS@ @MAYBE_DART@ @MAYBE_ERLANG@
CROSS_LANGS = @MAYBE_CPP@ @MAYBE_C_GLIB@ @MAYBE_JAVA@ @MAYBE_CSHARP@ @MAYBE_PYTHON@ @MAYBE_PY3@ @MAYBE_RUBY@ @MAYBE_HASKELL@ @MAYBE_PERL@ @MAYBE_PHP@ @MAYBE_GO@ @MAYBE_NODEJS@ @MAYBE_DART@ @MAYBE_ERLANG@ @MAYBE_LUA@
CROSS_LANGS_COMMA_SEPARATED = $(subst $(space),$(comma),$(CROSS_LANGS))

if WITH_PY3
Expand Down
3 changes: 3 additions & 0 deletions configure.ac
Expand Up @@ -748,6 +748,7 @@ AC_CONFIG_FILES([
test/go/Makefile
test/haxe/Makefile
test/hs/Makefile
test/lua/Makefile
test/php/Makefile
test/dart/Makefile
test/perl/Makefile
Expand Down Expand Up @@ -799,6 +800,8 @@ if test "$have_nodejs" = "yes" ; then MAYBE_NODEJS="nodejs" ; else MAYBE_NODEJS=
AC_SUBST([MAYBE_NODEJS])
if test "$have_erlang" = "yes" ; then MAYBE_ERLANG="erl" ; else MAYBE_ERLANG="" ; fi
AC_SUBST([MAYBE_ERLANG])
if test "$have_lua" = "yes" ; then MAYBE_LUA="lua" ; else MAYBE_LUA="" ; fi
AC_SUBST([MAYBE_LUA])

AC_OUTPUT

Expand Down
5 changes: 5 additions & 0 deletions test/Makefile.am
Expand Up @@ -75,6 +75,11 @@ SUBDIRS += erl
PRECROSS_TARGET += precross-erl
endif

if WITH_LUA
SUBDIRS += lua
PRECROSS_TARGET += precross-lua
endif

#
# generate html for ThriftTest.thrift
#
Expand Down
18 changes: 16 additions & 2 deletions test/known_failures_Linux.json
@@ -1,4 +1,5 @@
[
"c_glib-lua_binary_buffered-ip",
"cpp-cpp_binary_buffered-ip-ssl",
"cpp-cpp_binary_framed-ip-ssl",
"cpp-cpp_binary_http-domain",
Expand Down Expand Up @@ -32,6 +33,7 @@
"cpp-java_compact_http-ip-ssl",
"cpp-java_json_http-ip",
"cpp-java_json_http-ip-ssl",
"cpp-lua_binary_buffered-ip",
"cpp-perl_binary_buffered-ip-ssl",
"cpp-perl_binary_framed-ip-ssl",
"cpp-py_binary-accel_framed-ip-ssl",
Expand All @@ -52,6 +54,7 @@
"csharp-go_compact_framed-ip-ssl",
"csharp-go_json_buffered-ip-ssl",
"csharp-go_json_framed-ip-ssl",
"csharp-lua_binary_buffered-ip",
"csharp-nodejs_binary_buffered-ip-ssl",
"csharp-nodejs_binary_framed-ip-ssl",
"csharp-nodejs_compact_buffered-ip-ssl",
Expand All @@ -78,6 +81,7 @@
"erl-cpp_compact_buffered-ip-ssl",
"erl-cpp_compact_framed-ip",
"erl-cpp_compact_framed-ip-ssl",
"erl-lua_binary_buffered-ip",
"erl-nodejs_binary_buffered-ip",
"erl-nodejs_compact_buffered-ip",
"erl-perl_binary_buffered-ip-ssl",
Expand Down Expand Up @@ -105,30 +109,40 @@
"go-java_compact_http-ip-ssl",
"go-java_json_http-ip",
"go-java_json_http-ip-ssl",
"go-lua_binary_buffered-ip",
"go-perl_binary_buffered-ip-ssl",
"go-perl_binary_framed-ip-ssl",
"hs-csharp_binary_framed-ip",
"hs-csharp_compact_framed-ip",
"hs-csharp_json_framed-ip",
"hs-dart_binary_framed-ip",
"hs-dart_json_framed-ip",
"hs-lua_binary_buffered-ip",
"hs-py3_json_buffered-ip",
"hs-py3_json_framed-ip",
"hs-py_json_buffered-ip",
"hs-py_json_framed-ip",
"java-lua_binary_buffered-ip",
"java-perl_binary_buffered-ip-ssl",
"java-perl_binary_fastframed-framed-ip-ssl",
"java-perl_binary_framed-ip-ssl",
"nodejs-lua_binary_buffered-ip",
"nodejs-perl_binary_buffered-ip-ssl",
"nodejs-perl_binary_framed-ip-ssl",
"perl-lua_binary_buffered-ip",
"perl-perl_binary_buffered-ip-ssl",
"perl-perl_binary_framed-ip-ssl",
"perl-php_binary_framed-ip",
"py-cpp_compact_buffered-ip",
"py-lua_accel-binary_buffered-ip",
"py-lua_binary_buffered-ip",
"py-perl_accel-binary_buffered-ip-ssl",
"py-perl_accel-binary_framed-ip-ssl",
"py-perl_binary_buffered-ip-ssl",
"py-perl_binary_framed-ip-ssl",
"py3-lua_binary_buffered-ip",
"py3-perl_binary_buffered-ip-ssl",
"py3-perl_binary_framed-ip-ssl"
]
"py3-perl_binary_framed-ip-ssl",
"rb-lua_accel-binary_buffered-ip",
"rb-lua_binary_buffered-ip"
]
30 changes: 30 additions & 0 deletions test/lua/Makefile.am
@@ -0,0 +1,30 @@
#
# 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 's/MapType =//g' gen-lua/ThriftTest_ttypes.lua

precross: stubs

clean-local:
$(RM) -r gen-lua
53 changes: 43 additions & 10 deletions test/lua/test_basic_client.lua
Expand Up @@ -17,6 +17,8 @@


require('TSocket')
require('TBufferedTransport')
require('TFramedTransport')
require('TBinaryProtocol')
require('ThriftTest_ThriftTest')
require('liblualongnumber')
Expand All @@ -25,28 +27,56 @@ local client

function teardown()
if client then
-- Shuts down the server
client:testVoid()

-- 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()
function testBasicClient(rawArgs)
local opt = parseArgs(rawArgs)
local socket = TSocket:new{
port = 9090
port = tonumber(opt.port)
}
assert(socket, 'Failed to create client socket')
socket:setTimeout(5000)

local protocol = TBinaryProtocol:new{
local transports = {
buffered = TBufferedTransport,
framed = TFramedTransport,
}
assert(transports[opt.transport] ~= nil)
local transport = transports[opt.transport]:new{
trans = socket
}

local protocols = {
binary = TBinaryProtocol,
-- compact = TCompactProtocol,
}
assert(protocols[opt.protocol] ~= nil)
local protocol = protocols[opt.protocol]:new{
trans = transport
}
assert(protocol, 'Failed to create binary protocol')

client = ThriftTestClient:new{
Expand All @@ -62,6 +92,10 @@ function testBasicClient()
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')
Expand Down Expand Up @@ -130,9 +164,8 @@ function testBasicClient()
-- TODO fix client struct equality
--assertEqual(client:testStruct(a), a, 'Failed testStruct')

-- Call the void function and end the test (handler stops server)
client:testVoid()
-- TODO add list map set exception etc etc
end

testBasicClient()
teardown()
testBasicClient(arg)
teardown()
1 change: 0 additions & 1 deletion test/lua/test_basic_server.lua
Expand Up @@ -28,7 +28,6 @@ TestHandler = ThriftTestIface:new{}

-- Stops the server
function TestHandler:testVoid()
self.__server:stop()
end

function TestHandler:testString(str)
Expand Down
26 changes: 26 additions & 0 deletions test/tests.json
Expand Up @@ -491,5 +491,31 @@
]
},
"workdir": "../lib/js"
},
{
"name": "lua",
"TODO": "Add dll to LUA_CPATH",
"env": {
"LUA_PATH": ";;gen-lua/?.lua;../../lib/lua/?.lua",
"LUA_CPATH": ";;../../lib/lua/.libs/?.so"
},
"client": {
"timeout": 5,
"transports": [
"buffered",
"framed"
],
"sockets": [
"ip"
],
"protocols": [
"binary"
],
"command": [
"lua",
"test_basic_client.lua"
]
},
"workdir": "lua"
}
]

0 comments on commit d094e79

Please sign in to comment.