blob: fb8f074d46c55a27e81b579f651cfbd1f844c9f8 [file] [log] [blame]
Roger Meier6cf0ffc2014-04-05 00:45:42 +02001-- Licensed to the Apache Software Foundation (ASF) under one
2-- or more contributor license agreements. See the NOTICE file
3-- distributed with this work for additional information
4-- regarding copyright ownership. The ASF licenses this file
5-- to you under the Apache License, Version 2.0 (the
6-- "License"); you may not use this file except in compliance
7-- with the License. You may obtain a copy of the License at
8
9-- http://www.apache.org/licenses/LICENSE-2.0
10
11-- Unless required by applicable law or agreed to in writing,
12-- software distributed under the License is distributed on an
13-- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14-- KIND, either express or implied. See the License for the
15-- specific language governing permissions and limitations
16-- under the License.
17
18require('ThriftTest_ThriftTest')
19require('TSocket')
20require('TFramedTransport')
21require('TBinaryProtocol')
22require('TServer')
23require('liblualongnumber')
24
25--------------------------------------------------------------------------------
26-- Handler
27TestHandler = ThriftTestIface:new{}
28
29-- Stops the server
30function TestHandler:testVoid()
Roger Meier6cf0ffc2014-04-05 00:45:42 +020031end
32
33function TestHandler:testString(str)
34 return str
35end
36
37function TestHandler:testByte(byte)
38 return byte
39end
40
41function TestHandler:testI32(i32)
42 return i32
43end
44
45function TestHandler:testI64(i64)
46 return i64
47end
48
49function TestHandler:testDouble(d)
50 return d
51end
52
Jens Geyer8bcfdd92014-12-14 03:14:26 +010053function TestHandler:testBinary(by)
54 return by
55end
56
Roger Meier6cf0ffc2014-04-05 00:45:42 +020057function TestHandler:testStruct(thing)
58 return thing
59end
60
61--------------------------------------------------------------------------------
62-- Test
63local server
64
65function teardown()
66 if server then
67 server:close()
68 end
69end
70
71function testBasicServer()
72 -- Handler & Processor
73 local handler = TestHandler:new{}
74 assert(handler, 'Failed to create handler')
75 local processor = ThriftTestProcessor:new{
76 handler = handler
77 }
78 assert(processor, 'Failed to create processor')
79
80 -- Server Socket
81 local socket = TServerSocket:new{
82 port = 9090
83 }
84 assert(socket, 'Failed to create server socket')
85
86 -- Transport & Factory
87 local trans_factory = TFramedTransportFactory:new{}
88 assert(trans_factory, 'Failed to create framed transport factory')
89 local prot_factory = TBinaryProtocolFactory:new{}
90 assert(prot_factory, 'Failed to create binary protocol factory')
91
92 -- Simple Server
93 server = TSimpleServer:new{
94 processor = processor,
95 serverTransport = socket,
96 transportFactory = trans_factory,
97 protocolFactory = prot_factory
98 }
99 assert(server, 'Failed to create server')
100
101 -- Serve
102 server:serve()
103 server = nil
104end
105
106testBasicServer()
107teardown()