blob: 96a1ae9e0dac2f712372d916fd1f9612414bbba6 [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()
31 self.__server:stop()
32end
33
34function TestHandler:testString(str)
35 return str
36end
37
38function TestHandler:testByte(byte)
39 return byte
40end
41
42function TestHandler:testI32(i32)
43 return i32
44end
45
46function TestHandler:testI64(i64)
47 return i64
48end
49
50function TestHandler:testDouble(d)
51 return d
52end
53
Jens Geyer8bcfdd92014-12-14 03:14:26 +010054function TestHandler:testBinary(by)
55 return by
56end
57
Roger Meier6cf0ffc2014-04-05 00:45:42 +020058function TestHandler:testStruct(thing)
59 return thing
60end
61
62--------------------------------------------------------------------------------
63-- Test
64local server
65
66function teardown()
67 if server then
68 server:close()
69 end
70end
71
72function testBasicServer()
73 -- Handler & Processor
74 local handler = TestHandler:new{}
75 assert(handler, 'Failed to create handler')
76 local processor = ThriftTestProcessor:new{
77 handler = handler
78 }
79 assert(processor, 'Failed to create processor')
80
81 -- Server Socket
82 local socket = TServerSocket:new{
83 port = 9090
84 }
85 assert(socket, 'Failed to create server socket')
86
87 -- Transport & Factory
88 local trans_factory = TFramedTransportFactory:new{}
89 assert(trans_factory, 'Failed to create framed transport factory')
90 local prot_factory = TBinaryProtocolFactory:new{}
91 assert(prot_factory, 'Failed to create binary protocol factory')
92
93 -- Simple Server
94 server = TSimpleServer:new{
95 processor = processor,
96 serverTransport = socket,
97 transportFactory = trans_factory,
98 protocolFactory = prot_factory
99 }
100 assert(server, 'Failed to create server')
101
102 -- Serve
103 server:serve()
104 server = nil
105end
106
107testBasicServer()
108teardown()