blob: 7c175daca9aefa54491024329b9551adab3cad7e [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
54function TestHandler:testStruct(thing)
55 return thing
56end
57
58--------------------------------------------------------------------------------
59-- Test
60local server
61
62function teardown()
63 if server then
64 server:close()
65 end
66end
67
68function testBasicServer()
69 -- Handler & Processor
70 local handler = TestHandler:new{}
71 assert(handler, 'Failed to create handler')
72 local processor = ThriftTestProcessor:new{
73 handler = handler
74 }
75 assert(processor, 'Failed to create processor')
76
77 -- Server Socket
78 local socket = TServerSocket:new{
79 port = 9090
80 }
81 assert(socket, 'Failed to create server socket')
82
83 -- Transport & Factory
84 local trans_factory = TFramedTransportFactory:new{}
85 assert(trans_factory, 'Failed to create framed transport factory')
86 local prot_factory = TBinaryProtocolFactory:new{}
87 assert(prot_factory, 'Failed to create binary protocol factory')
88
89 -- Simple Server
90 server = TSimpleServer:new{
91 processor = processor,
92 serverTransport = socket,
93 transportFactory = trans_factory,
94 protocolFactory = prot_factory
95 }
96 assert(server, 'Failed to create server')
97
98 -- Serve
99 server:serve()
100 server = nil
101end
102
103testBasicServer()
104teardown()