Roger Meier | 6cf0ffc | 2014-04-05 00:45:42 +0200 | [diff] [blame] | 1 | -- 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 | |
| 18 | require('ThriftTest_ThriftTest') |
| 19 | require('TSocket') |
| 20 | require('TFramedTransport') |
| 21 | require('TBinaryProtocol') |
| 22 | require('TServer') |
| 23 | require('liblualongnumber') |
| 24 | |
| 25 | -------------------------------------------------------------------------------- |
| 26 | -- Handler |
| 27 | TestHandler = ThriftTestIface:new{} |
| 28 | |
| 29 | -- Stops the server |
| 30 | function TestHandler:testVoid() |
| 31 | self.__server:stop() |
| 32 | end |
| 33 | |
| 34 | function TestHandler:testString(str) |
| 35 | return str |
| 36 | end |
| 37 | |
| 38 | function TestHandler:testByte(byte) |
| 39 | return byte |
| 40 | end |
| 41 | |
| 42 | function TestHandler:testI32(i32) |
| 43 | return i32 |
| 44 | end |
| 45 | |
| 46 | function TestHandler:testI64(i64) |
| 47 | return i64 |
| 48 | end |
| 49 | |
| 50 | function TestHandler:testDouble(d) |
| 51 | return d |
| 52 | end |
| 53 | |
Jens Geyer | 8bcfdd9 | 2014-12-14 03:14:26 +0100 | [diff] [blame] | 54 | function TestHandler:testBinary(by) |
| 55 | return by |
| 56 | end |
| 57 | |
Roger Meier | 6cf0ffc | 2014-04-05 00:45:42 +0200 | [diff] [blame] | 58 | function TestHandler:testStruct(thing) |
| 59 | return thing |
| 60 | end |
| 61 | |
| 62 | -------------------------------------------------------------------------------- |
| 63 | -- Test |
| 64 | local server |
| 65 | |
| 66 | function teardown() |
| 67 | if server then |
| 68 | server:close() |
| 69 | end |
| 70 | end |
| 71 | |
| 72 | function 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 |
| 105 | end |
| 106 | |
| 107 | testBasicServer() |
| 108 | teardown() |