| Noam Zilberstein | af5d64a | 2014-07-31 15:44:13 -0700 | [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 | {-# LANGUAGE OverloadedStrings, RecordWildCards, ScopedTypeVariables #-} | 
 | 21 | module Main where | 
 | 22 |  | 
 | 23 | import Control.Exception | 
 | 24 | import Control.Monad | 
 | 25 | import Data.Functor | 
| cdwijayarathna | d921791 | 2014-08-15 22:18:30 +0530 | [diff] [blame] | 26 | import Data.List.Split | 
| Noam Zilberstein | af5d64a | 2014-07-31 15:44:13 -0700 | [diff] [blame] | 27 | import Data.String | 
 | 28 | import Network | 
| Jens Geyer | d629ea0 | 2015-09-23 21:16:50 +0200 | [diff] [blame] | 29 | import Network.URI | 
| Noam Zilberstein | af5d64a | 2014-07-31 15:44:13 -0700 | [diff] [blame] | 30 | import System.Environment | 
 | 31 | import System.Exit | 
| Jens Geyer | d629ea0 | 2015-09-23 21:16:50 +0200 | [diff] [blame] | 32 | import qualified Data.ByteString.Lazy as LBS | 
| Noam Zilberstein | af5d64a | 2014-07-31 15:44:13 -0700 | [diff] [blame] | 33 | import qualified Data.HashMap.Strict as Map | 
 | 34 | import qualified Data.HashSet as Set | 
 | 35 | import qualified Data.Vector as Vector | 
| Jens Geyer | d629ea0 | 2015-09-23 21:16:50 +0200 | [diff] [blame] | 36 | import qualified System.IO as IO | 
| Noam Zilberstein | af5d64a | 2014-07-31 15:44:13 -0700 | [diff] [blame] | 37 |  | 
 | 38 | import ThriftTest_Iface | 
 | 39 | import ThriftTest_Types | 
 | 40 | import qualified ThriftTest_Client as Client | 
 | 41 |  | 
 | 42 | import Thrift.Transport | 
| Jens Geyer | d629ea0 | 2015-09-23 21:16:50 +0200 | [diff] [blame] | 43 | import Thrift.Transport.Framed | 
| Noam Zilberstein | af5d64a | 2014-07-31 15:44:13 -0700 | [diff] [blame] | 44 | import Thrift.Transport.Handle | 
| Jens Geyer | d629ea0 | 2015-09-23 21:16:50 +0200 | [diff] [blame] | 45 | import Thrift.Transport.HttpClient | 
| Noam Zilberstein | af5d64a | 2014-07-31 15:44:13 -0700 | [diff] [blame] | 46 | import Thrift.Protocol | 
 | 47 | import Thrift.Protocol.Binary | 
 | 48 | import Thrift.Protocol.Compact | 
 | 49 | import Thrift.Protocol.JSON | 
 | 50 |  | 
 | 51 | data Options = Options | 
 | 52 |   { host         :: String | 
 | 53 |   , port         :: Int | 
 | 54 |   , domainSocket :: String | 
 | 55 |   , transport    :: String | 
 | 56 |   , protocol     :: ProtocolType | 
| Jens Geyer | d629ea0 | 2015-09-23 21:16:50 +0200 | [diff] [blame] | 57 |   -- TODO: Haskell lib does not have SSL support | 
| Noam Zilberstein | af5d64a | 2014-07-31 15:44:13 -0700 | [diff] [blame] | 58 |   , ssl          :: Bool | 
 | 59 |   , testLoops    :: Int | 
 | 60 |   } | 
 | 61 |   deriving (Show, Eq) | 
 | 62 |  | 
| Jens Geyer | d629ea0 | 2015-09-23 21:16:50 +0200 | [diff] [blame] | 63 | data TransportType = Buffered IO.Handle | 
 | 64 |                    | Framed (FramedTransport IO.Handle) | 
 | 65 |                    | Http HttpClient | 
 | 66 |                    | NoTransport String | 
 | 67 |  | 
 | 68 | getTransport :: String -> String -> Int -> (IO TransportType) | 
 | 69 | getTransport "buffered" host port = do | 
 | 70 |   h <- hOpen (host, PortNumber $ fromIntegral port) | 
 | 71 |   IO.hSetBuffering h $ IO.BlockBuffering Nothing | 
 | 72 |   return $ Buffered h | 
 | 73 | getTransport "framed" host port = do | 
 | 74 |   h <- hOpen (host, PortNumber $ fromIntegral port) | 
 | 75 |   t <- openFramedTransport h | 
 | 76 |   return $ Framed t | 
 | 77 | getTransport "http" host port = let uriStr = "http://" ++ host ++ ":" ++ show port in | 
 | 78 |                                 case parseURI uriStr of | 
 | 79 |                                   Nothing -> do return (NoTransport $ "Failed to parse URI: " ++ uriStr) | 
 | 80 |                                   Just(uri) -> do | 
 | 81 |                                     t <- openHttpClient uri | 
 | 82 |                                     return $ Http t | 
 | 83 | getTransport t host port = do return (NoTransport $ "Unsupported transport: " ++ t) | 
 | 84 |  | 
| Noam Zilberstein | af5d64a | 2014-07-31 15:44:13 -0700 | [diff] [blame] | 85 | data ProtocolType = Binary | 
 | 86 |                   | Compact | 
 | 87 |                   | JSON | 
 | 88 |                   deriving (Show, Eq) | 
 | 89 |  | 
 | 90 | getProtocol :: String -> ProtocolType | 
 | 91 | getProtocol "binary"  = Binary | 
 | 92 | getProtocol "compact" = Compact | 
 | 93 | getProtocol "json"    = JSON | 
 | 94 | getProtocol p = error $ "Unsupported Protocol: " ++ p | 
 | 95 |  | 
 | 96 | defaultOptions :: Options | 
 | 97 | defaultOptions = Options | 
 | 98 |   { port         = 9090 | 
 | 99 |   , domainSocket = "" | 
 | 100 |   , host         = "localhost" | 
| Jens Geyer | d629ea0 | 2015-09-23 21:16:50 +0200 | [diff] [blame] | 101 |   , transport    = "buffered" | 
| Noam Zilberstein | af5d64a | 2014-07-31 15:44:13 -0700 | [diff] [blame] | 102 |   , protocol     = Binary | 
 | 103 |   , ssl          = False | 
 | 104 |   , testLoops    = 1 | 
 | 105 |   } | 
 | 106 |  | 
 | 107 | runClient :: (Protocol p, Transport t) => p t -> IO () | 
 | 108 | runClient p = do | 
 | 109 |   let prot = (p,p) | 
 | 110 |   putStrLn "Starting Tests" | 
| cdwijayarathna | d921791 | 2014-08-15 22:18:30 +0530 | [diff] [blame] | 111 |  | 
| Noam Zilberstein | af5d64a | 2014-07-31 15:44:13 -0700 | [diff] [blame] | 112 |   -- VOID Test | 
| Jens Geyer | d629ea0 | 2015-09-23 21:16:50 +0200 | [diff] [blame] | 113 |   putStrLn "testVoid" | 
| Noam Zilberstein | af5d64a | 2014-07-31 15:44:13 -0700 | [diff] [blame] | 114 |   Client.testVoid prot | 
| cdwijayarathna | d921791 | 2014-08-15 22:18:30 +0530 | [diff] [blame] | 115 |  | 
| Noam Zilberstein | af5d64a | 2014-07-31 15:44:13 -0700 | [diff] [blame] | 116 |   -- String Test | 
| Jens Geyer | d629ea0 | 2015-09-23 21:16:50 +0200 | [diff] [blame] | 117 |   putStrLn "testString" | 
| Noam Zilberstein | af5d64a | 2014-07-31 15:44:13 -0700 | [diff] [blame] | 118 |   s <- Client.testString prot "Test" | 
 | 119 |   when (s /= "Test") exitFailure | 
 | 120 |  | 
| Jens Geyer | d629ea0 | 2015-09-23 21:16:50 +0200 | [diff] [blame] | 121 |   -- Bool Test | 
 | 122 |   putStrLn "testBool" | 
 | 123 |   bool <- Client.testBool prot True | 
 | 124 |   when (not bool) exitFailure | 
 | 125 |   putStrLn "testBool" | 
 | 126 |   bool <- Client.testBool prot False | 
 | 127 |   when (bool) exitFailure | 
 | 128 |  | 
| Noam Zilberstein | af5d64a | 2014-07-31 15:44:13 -0700 | [diff] [blame] | 129 |   -- Byte Test | 
| Jens Geyer | d629ea0 | 2015-09-23 21:16:50 +0200 | [diff] [blame] | 130 |   putStrLn "testByte" | 
| Noam Zilberstein | af5d64a | 2014-07-31 15:44:13 -0700 | [diff] [blame] | 131 |   byte <- Client.testByte prot 1 | 
 | 132 |   when (byte /= 1) exitFailure | 
| cdwijayarathna | d921791 | 2014-08-15 22:18:30 +0530 | [diff] [blame] | 133 |  | 
| Noam Zilberstein | af5d64a | 2014-07-31 15:44:13 -0700 | [diff] [blame] | 134 |   -- I32 Test | 
| Jens Geyer | d629ea0 | 2015-09-23 21:16:50 +0200 | [diff] [blame] | 135 |   putStrLn "testI32" | 
| Noam Zilberstein | af5d64a | 2014-07-31 15:44:13 -0700 | [diff] [blame] | 136 |   i32 <- Client.testI32 prot (-1) | 
 | 137 |   when (i32 /= -1) exitFailure | 
| cdwijayarathna | d921791 | 2014-08-15 22:18:30 +0530 | [diff] [blame] | 138 |  | 
| Noam Zilberstein | af5d64a | 2014-07-31 15:44:13 -0700 | [diff] [blame] | 139 |   -- I64 Test | 
| Jens Geyer | d629ea0 | 2015-09-23 21:16:50 +0200 | [diff] [blame] | 140 |   putStrLn "testI64" | 
| Noam Zilberstein | af5d64a | 2014-07-31 15:44:13 -0700 | [diff] [blame] | 141 |   i64 <- Client.testI64 prot (-34359738368) | 
 | 142 |   when (i64 /= -34359738368) exitFailure | 
 | 143 |  | 
 | 144 |   -- Double Test | 
| Jens Geyer | d629ea0 | 2015-09-23 21:16:50 +0200 | [diff] [blame] | 145 |   putStrLn "testDouble" | 
| Noam Zilberstein | af5d64a | 2014-07-31 15:44:13 -0700 | [diff] [blame] | 146 |   dub <- Client.testDouble prot (-5.2098523) | 
 | 147 |   when (abs (dub + 5.2098523) > 0.001) exitFailure | 
 | 148 |  | 
| Jens Geyer | d629ea0 | 2015-09-23 21:16:50 +0200 | [diff] [blame] | 149 |   -- Binary Test | 
 | 150 |   putStrLn "testBinary" | 
 | 151 |   bin <- Client.testBinary prot (LBS.pack . reverse $ [-128..127]) | 
 | 152 |   when ((reverse [-128..127]) /= LBS.unpack bin) exitFailure | 
| Jens Geyer | 8bcfdd9 | 2014-12-14 03:14:26 +0100 | [diff] [blame] | 153 |    | 
| Noam Zilberstein | af5d64a | 2014-07-31 15:44:13 -0700 | [diff] [blame] | 154 |   -- Struct Test | 
 | 155 |   let structIn = Xtruct{ xtruct_string_thing = "Zero" | 
 | 156 |                        , xtruct_byte_thing   = 1 | 
 | 157 |                        , xtruct_i32_thing    = -3 | 
 | 158 |                        , xtruct_i64_thing    = -5 | 
 | 159 |                        } | 
| Jens Geyer | d629ea0 | 2015-09-23 21:16:50 +0200 | [diff] [blame] | 160 |   putStrLn "testStruct" | 
| cdwijayarathna | d921791 | 2014-08-15 22:18:30 +0530 | [diff] [blame] | 161 |   structOut <- Client.testStruct prot structIn | 
| Noam Zilberstein | af5d64a | 2014-07-31 15:44:13 -0700 | [diff] [blame] | 162 |   when (structIn /= structOut) exitFailure | 
 | 163 |  | 
 | 164 |   -- Nested Struct Test | 
 | 165 |   let nestIn = Xtruct2{ xtruct2_byte_thing   = 1 | 
 | 166 |                       , xtruct2_struct_thing = structIn | 
 | 167 |                       , xtruct2_i32_thing    = 5 | 
 | 168 |                       } | 
| Jens Geyer | d629ea0 | 2015-09-23 21:16:50 +0200 | [diff] [blame] | 169 |   putStrLn "testNest" | 
| Noam Zilberstein | af5d64a | 2014-07-31 15:44:13 -0700 | [diff] [blame] | 170 |   nestOut <- Client.testNest prot nestIn | 
| Nobuaki Sukegawa | e68ccc2 | 2015-12-13 21:45:39 +0900 | [diff] [blame] | 171 |   when (nestIn /= nestOut) exitFailure | 
| cdwijayarathna | d921791 | 2014-08-15 22:18:30 +0530 | [diff] [blame] | 172 |  | 
| Noam Zilberstein | af5d64a | 2014-07-31 15:44:13 -0700 | [diff] [blame] | 173 |   -- Map Test | 
 | 174 |   let mapIn = Map.fromList $ map (\i -> (i, i-10)) [1..5] | 
| Jens Geyer | d629ea0 | 2015-09-23 21:16:50 +0200 | [diff] [blame] | 175 |   putStrLn "testMap" | 
| Noam Zilberstein | af5d64a | 2014-07-31 15:44:13 -0700 | [diff] [blame] | 176 |   mapOut <- Client.testMap prot mapIn | 
| Nobuaki Sukegawa | e68ccc2 | 2015-12-13 21:45:39 +0900 | [diff] [blame] | 177 |   when (mapIn /= mapOut) exitFailure | 
| cdwijayarathna | d921791 | 2014-08-15 22:18:30 +0530 | [diff] [blame] | 178 |  | 
| Noam Zilberstein | af5d64a | 2014-07-31 15:44:13 -0700 | [diff] [blame] | 179 |   -- Set Test | 
 | 180 |   let setIn = Set.fromList [-2..3] | 
| Jens Geyer | d629ea0 | 2015-09-23 21:16:50 +0200 | [diff] [blame] | 181 |   putStrLn "testSet" | 
| Noam Zilberstein | af5d64a | 2014-07-31 15:44:13 -0700 | [diff] [blame] | 182 |   setOut <- Client.testSet prot setIn | 
 | 183 |   when (setIn /= setOut) exitFailure | 
| cdwijayarathna | d921791 | 2014-08-15 22:18:30 +0530 | [diff] [blame] | 184 |  | 
| Noam Zilberstein | af5d64a | 2014-07-31 15:44:13 -0700 | [diff] [blame] | 185 |   -- List Test | 
 | 186 |   let listIn = Vector.fromList [-2..3] | 
| Jens Geyer | d629ea0 | 2015-09-23 21:16:50 +0200 | [diff] [blame] | 187 |   putStrLn "testList" | 
| Noam Zilberstein | af5d64a | 2014-07-31 15:44:13 -0700 | [diff] [blame] | 188 |   listOut <- Client.testList prot listIn | 
 | 189 |   when (listIn /= listOut) exitFailure | 
| cdwijayarathna | d921791 | 2014-08-15 22:18:30 +0530 | [diff] [blame] | 190 |  | 
| Noam Zilberstein | af5d64a | 2014-07-31 15:44:13 -0700 | [diff] [blame] | 191 |   -- Enum Test | 
| Jens Geyer | d629ea0 | 2015-09-23 21:16:50 +0200 | [diff] [blame] | 192 |   putStrLn "testEnum" | 
| Noam Zilberstein | af5d64a | 2014-07-31 15:44:13 -0700 | [diff] [blame] | 193 |   numz1 <- Client.testEnum prot ONE | 
 | 194 |   when (numz1 /= ONE) exitFailure | 
 | 195 |  | 
| Jens Geyer | d629ea0 | 2015-09-23 21:16:50 +0200 | [diff] [blame] | 196 |   putStrLn "testEnum" | 
| Noam Zilberstein | af5d64a | 2014-07-31 15:44:13 -0700 | [diff] [blame] | 197 |   numz2 <- Client.testEnum prot TWO | 
 | 198 |   when (numz2 /= TWO) exitFailure | 
 | 199 |  | 
| Jens Geyer | d629ea0 | 2015-09-23 21:16:50 +0200 | [diff] [blame] | 200 |   putStrLn "testEnum" | 
| Noam Zilberstein | af5d64a | 2014-07-31 15:44:13 -0700 | [diff] [blame] | 201 |   numz5 <- Client.testEnum prot FIVE | 
 | 202 |   when (numz5 /= FIVE) exitFailure | 
 | 203 |  | 
 | 204 |   -- Typedef Test | 
| Jens Geyer | d629ea0 | 2015-09-23 21:16:50 +0200 | [diff] [blame] | 205 |   putStrLn "testTypedef" | 
| Noam Zilberstein | af5d64a | 2014-07-31 15:44:13 -0700 | [diff] [blame] | 206 |   uid <- Client.testTypedef prot 309858235082523 | 
 | 207 |   when (uid /= 309858235082523) exitFailure | 
| cdwijayarathna | d921791 | 2014-08-15 22:18:30 +0530 | [diff] [blame] | 208 |  | 
| Noam Zilberstein | af5d64a | 2014-07-31 15:44:13 -0700 | [diff] [blame] | 209 |   -- Nested Map Test | 
| Jens Geyer | d629ea0 | 2015-09-23 21:16:50 +0200 | [diff] [blame] | 210 |   putStrLn "testMapMap" | 
| Noam Zilberstein | af5d64a | 2014-07-31 15:44:13 -0700 | [diff] [blame] | 211 |   _ <- Client.testMapMap prot 1 | 
| cdwijayarathna | d921791 | 2014-08-15 22:18:30 +0530 | [diff] [blame] | 212 |  | 
| Noam Zilberstein | af5d64a | 2014-07-31 15:44:13 -0700 | [diff] [blame] | 213 |   -- Exception Test | 
| Jens Geyer | d629ea0 | 2015-09-23 21:16:50 +0200 | [diff] [blame] | 214 |   putStrLn "testException" | 
| Noam Zilberstein | af5d64a | 2014-07-31 15:44:13 -0700 | [diff] [blame] | 215 |   exn1 <- try $ Client.testException prot "Xception" | 
 | 216 |   case exn1 of | 
 | 217 |     Left (Xception _ _) -> return () | 
 | 218 |     _ -> putStrLn (show exn1) >> exitFailure | 
| cdwijayarathna | d921791 | 2014-08-15 22:18:30 +0530 | [diff] [blame] | 219 |  | 
| Jens Geyer | d629ea0 | 2015-09-23 21:16:50 +0200 | [diff] [blame] | 220 |   putStrLn "testException" | 
| Noam Zilberstein | af5d64a | 2014-07-31 15:44:13 -0700 | [diff] [blame] | 221 |   exn2 <- try $ Client.testException prot "TException" | 
 | 222 |   case exn2 of | 
 | 223 |     Left (_ :: SomeException) -> return () | 
 | 224 |     Right _ -> exitFailure | 
| cdwijayarathna | d921791 | 2014-08-15 22:18:30 +0530 | [diff] [blame] | 225 |  | 
| Jens Geyer | d629ea0 | 2015-09-23 21:16:50 +0200 | [diff] [blame] | 226 |   putStrLn "testException" | 
| Noam Zilberstein | af5d64a | 2014-07-31 15:44:13 -0700 | [diff] [blame] | 227 |   exn3 <- try $ Client.testException prot "success" | 
 | 228 |   case exn3 of | 
 | 229 |     Left (_ :: SomeException) -> exitFailure | 
 | 230 |     Right _ -> return () | 
| cdwijayarathna | d921791 | 2014-08-15 22:18:30 +0530 | [diff] [blame] | 231 |  | 
| Noam Zilberstein | af5d64a | 2014-07-31 15:44:13 -0700 | [diff] [blame] | 232 |   -- Multi Exception Test | 
| Jens Geyer | d629ea0 | 2015-09-23 21:16:50 +0200 | [diff] [blame] | 233 |   putStrLn "testMultiException" | 
| Noam Zilberstein | af5d64a | 2014-07-31 15:44:13 -0700 | [diff] [blame] | 234 |   multi1 <- try $ Client.testMultiException prot "Xception" "test 1" | 
 | 235 |   case multi1 of | 
 | 236 |     Left (Xception _ _) -> return () | 
 | 237 |     _ -> exitFailure | 
 | 238 |  | 
| Jens Geyer | d629ea0 | 2015-09-23 21:16:50 +0200 | [diff] [blame] | 239 |   putStrLn "testMultiException" | 
| Noam Zilberstein | af5d64a | 2014-07-31 15:44:13 -0700 | [diff] [blame] | 240 |   multi2 <- try $ Client.testMultiException prot "Xception2" "test 2" | 
 | 241 |   case multi2 of | 
 | 242 |     Left (Xception2 _ _) -> return () | 
 | 243 |     _ -> exitFailure | 
 | 244 |  | 
| Jens Geyer | d629ea0 | 2015-09-23 21:16:50 +0200 | [diff] [blame] | 245 |   putStrLn "testMultiException" | 
| Noam Zilberstein | af5d64a | 2014-07-31 15:44:13 -0700 | [diff] [blame] | 246 |   multi3 <- try $ Client.testMultiException prot "success" "test 3" | 
 | 247 |   case multi3 of | 
 | 248 |     Left (_ :: SomeException) -> exitFailure | 
 | 249 |     Right _ -> return () | 
 | 250 |  | 
 | 251 |  | 
 | 252 | main :: IO () | 
 | 253 | main = do | 
 | 254 |   options <- flip parseFlags defaultOptions <$> getArgs | 
 | 255 |   case options of | 
 | 256 |     Nothing -> showHelp | 
 | 257 |     Just Options{..} -> do | 
| Jens Geyer | d629ea0 | 2015-09-23 21:16:50 +0200 | [diff] [blame] | 258 |       trans <- Main.getTransport transport host port | 
 | 259 |       case trans of | 
 | 260 |         Buffered t -> runTest testLoops protocol t | 
 | 261 |         Framed t   -> runTest testLoops protocol t | 
 | 262 |         Http t     -> runTest testLoops protocol t | 
 | 263 |         NoTransport err -> putStrLn err | 
 | 264 |   where | 
 | 265 |     makeClient p t = case p of | 
 | 266 |                        Binary  -> runClient $ BinaryProtocol t | 
 | 267 |                        Compact -> runClient $ CompactProtocol t | 
 | 268 |                        JSON    -> runClient $ JSONProtocol t | 
 | 269 |     runTest loops p t = do | 
 | 270 |       let client = makeClient p t | 
 | 271 |       replicateM_ loops client | 
| Noam Zilberstein | af5d64a | 2014-07-31 15:44:13 -0700 | [diff] [blame] | 272 |       putStrLn "COMPLETED SUCCESSFULLY" | 
 | 273 |  | 
 | 274 | parseFlags :: [String] -> Options -> Maybe Options | 
| cdwijayarathna | d921791 | 2014-08-15 22:18:30 +0530 | [diff] [blame] | 275 | parseFlags (flag : flags) opts = do | 
 | 276 |   let pieces = splitOn "=" flag | 
 | 277 |   case pieces of | 
 | 278 |     "--port" : arg : _ -> parseFlags flags opts{ port = read arg } | 
 | 279 |     "--domain-socket" : arg : _ -> parseFlags flags opts{ domainSocket = read arg } | 
 | 280 |     "--host" : arg : _ -> parseFlags flags opts{ host = arg } | 
 | 281 |     "--transport" : arg : _ -> parseFlags flags opts{ transport = arg } | 
 | 282 |     "--protocol" : arg : _ -> parseFlags flags opts{ protocol = getProtocol arg } | 
| cdwijayarathna | 7191bc9 | 2014-08-16 23:36:07 +0530 | [diff] [blame] | 283 |     "-n" : arg : _ -> parseFlags flags opts{ testLoops = read arg } | 
| cdwijayarathna | d921791 | 2014-08-15 22:18:30 +0530 | [diff] [blame] | 284 |     "--h" : _ -> Nothing | 
 | 285 |     "--help" : _ -> Nothing | 
 | 286 |     "--ssl" : _ -> parseFlags flags opts{ ssl = True } | 
 | 287 |     "--processor-events" : _ -> parseFlags flags opts | 
| cdwijayarathna | 7191bc9 | 2014-08-16 23:36:07 +0530 | [diff] [blame] | 288 |     _ -> Nothing | 
| Noam Zilberstein | af5d64a | 2014-07-31 15:44:13 -0700 | [diff] [blame] | 289 | parseFlags [] opts = Just opts | 
 | 290 |  | 
 | 291 | showHelp :: IO () | 
 | 292 | showHelp = putStrLn | 
 | 293 |   "Allowed options:\n\ | 
 | 294 |   \  -h [ --help ]               produce help message\n\ | 
 | 295 |   \  --host arg (=localhost)     Host to connect\n\ | 
 | 296 |   \  --port arg (=9090)          Port number to connect\n\ | 
| cdwijayarathna | d921791 | 2014-08-15 22:18:30 +0530 | [diff] [blame] | 297 |   \  --domain-socket arg         Domain Socket (e.g. /tmp/ThriftTest.thrift),\n\ | 
| Noam Zilberstein | af5d64a | 2014-07-31 15:44:13 -0700 | [diff] [blame] | 298 |   \                              instead of host and port\n\ | 
| Jens Geyer | d629ea0 | 2015-09-23 21:16:50 +0200 | [diff] [blame] | 299 |   \  --transport arg (=buffered) Transport: buffered, framed, http\n\ | 
| Noam Zilberstein | af5d64a | 2014-07-31 15:44:13 -0700 | [diff] [blame] | 300 |   \  --protocol arg (=binary)    Protocol: binary, compact, json\n\ | 
 | 301 |   \  --ssl                       Encrypted Transport using SSL\n\ | 
| Jens Geyer | d629ea0 | 2015-09-23 21:16:50 +0200 | [diff] [blame] | 302 |   \  -n [ --testloops ] arg (=1) Number of Tests" |