Bryan Duxbury | c657447 | 2010-10-06 00:12:33 +0000 | [diff] [blame] | 1 | -- |
| 2 | -- Licensed to the Apache Software Foundation (ASF) under one |
| 3 | -- or more contributor license agreements. See the NOTICE file |
| 4 | -- distributed with this work for additional information |
| 5 | -- regarding copyright ownership. The ASF licenses this file |
| 6 | -- to you under the Apache License, Version 2.0 (the |
| 7 | -- "License"); you may not use this file except in compliance |
| 8 | -- with the License. You may obtain a copy of the License at |
| 9 | -- |
| 10 | -- http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | -- |
| 12 | -- Unless required by applicable law or agreed to in writing, |
| 13 | -- software distributed under the License is distributed on an |
| 14 | -- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | -- KIND, either express or implied. See the License for the |
| 16 | -- specific language governing permissions and limitations |
| 17 | -- under the License. |
| 18 | -- |
| 19 | |
| 20 | module Main where |
| 21 | |
| 22 | |
| 23 | import qualified Control.Exception |
| 24 | import qualified Network |
| 25 | |
| 26 | import Thrift.Protocol.Binary |
| 27 | import Thrift.Server |
| 28 | import Thrift.Transport.Handle |
| 29 | |
| 30 | import qualified ThriftTestUtils |
| 31 | |
| 32 | import qualified Yowza |
| 33 | import qualified Yowza_Client as Client |
| 34 | import qualified Yowza_Iface as Iface |
| 35 | |
| 36 | |
| 37 | data YowzaHandler = YowzaHandler |
| 38 | instance Iface.Yowza_Iface YowzaHandler where |
| 39 | blingity _ = do |
| 40 | ThriftTestUtils.serverLog "SERVER: Got blingity" |
| 41 | return () |
| 42 | |
| 43 | blangity _ = do |
| 44 | ThriftTestUtils.serverLog "SERVER: Got blangity" |
| 45 | return $ 31 |
| 46 | |
| 47 | |
| 48 | client :: (String, Network.PortID) -> IO () |
| 49 | client addr = do |
| 50 | to <- hOpen addr |
| 51 | let ps = (BinaryProtocol to, BinaryProtocol to) |
| 52 | |
| 53 | Client.blingity ps |
| 54 | |
| 55 | rv <- Client.blangity ps |
| 56 | ThriftTestUtils.clientLog $ show rv |
| 57 | |
| 58 | tClose to |
| 59 | |
| 60 | server :: Network.PortNumber -> IO () |
| 61 | server port = do |
| 62 | ThriftTestUtils.serverLog "Ready..." |
| 63 | (runBasicServer YowzaHandler Yowza.process port) |
| 64 | `Control.Exception.catch` |
| 65 | (\(TransportExn s _) -> error $ "FAILURE: " ++ show s) |
| 66 | |
| 67 | main :: IO () |
| 68 | main = ThriftTestUtils.runTest server client |