THRIFT-407. hs: Refactor and improve Haskell-related code



git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@763031 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/test/hs/Client.hs b/test/hs/Client.hs
index 81d7f0f..c5e4d90 100644
--- a/test/hs/Client.hs
+++ b/test/hs/Client.hs
@@ -18,18 +18,25 @@
 --
 
 module Client where
-import Thrift
+
 import ThriftTest_Client
 import ThriftTest_Types
-import TSocket
-import TBinaryProtocol
 import qualified Data.Map as Map
 import qualified Data.Set as Set
 import Control.Monad
-t = TSocket "127.0.0.1" 9090 Nothing
+import Control.Exception as CE
 
-main = do to <- topen t
-          let p =  TBinaryProtocol to
+import Network
+
+import Thrift
+import Thrift.Transport.Handle
+import Thrift.Protocol.Binary
+
+
+serverAddress = ("127.0.0.1", PortNumber 9090)
+
+main = do to <- hOpen serverAddress
+          let p =  BinaryProtocol to
           let ps = (p,p)
           print =<< testString ps "bya"
           print =<< testByte ps 8
@@ -44,5 +51,8 @@
           print =<< testList ps [1,2,3,4,5]
           print =<< testSet ps (Set.fromList [1,2,3,4,5])
           print =<< testStruct ps (Xtruct (Just "hi") (Just 4) (Just 5) Nothing)
-          tclose to
+          CE.catch (testException ps "e" >> print "bad") (\e -> print (e :: Xception))
+          CE.catch (testMultiException ps "e" "e2" >> print "ok") (\e -> print (e :: Xception))
+          CE.catch (CE.catch (testMultiException ps "e" "e2">> print "bad") (\e -> print (e :: Xception2))) (\(e :: SomeException) -> print "ok")
+          tClose to
 
diff --git a/test/hs/Server.hs b/test/hs/Server.hs
index f9b333f..0ca9d9f 100644
--- a/test/hs/Server.hs
+++ b/test/hs/Server.hs
@@ -18,14 +18,16 @@
 --
 
 module Server where
-import Thrift
+
 import ThriftTest
 import ThriftTest_Iface
 import Data.Map as Map
-import TServer
 import Control.Exception
 import ThriftTest_Types
 
+import Thrift
+import Thrift.Server
+
 
 data TestHandler = TestHandler
 instance ThriftTest_Iface TestHandler where
@@ -45,9 +47,11 @@
     testMapMap a (Just x) = return (Map.fromList [(1,Map.fromList [(2,2)])])
     testInsanity a (Just x) = return (Map.fromList [(1,Map.fromList [(ONE,x)])])
     testMulti a a1 a2 a3 a4 a5 a6 = return (Xtruct Nothing Nothing Nothing Nothing)
-    testException a c = throwDyn (Xception (Just 1) (Just "bya"))
-    testMultiException a c1 c2 = return (Xtruct Nothing Nothing Nothing Nothing)
+    testException a c = throw (Xception (Just 1) (Just "bya"))
+    testMultiException a c1 c2 = throw (Xception (Just 1) (Just "xyz"))
     testOneway a (Just i) = do print i
 
 
-main = do (run_basic_server TestHandler process 9090) `catchDyn` (\(TransportExn s t) -> print s)
+main = do (runBasicServer TestHandler process 9090)
+          `Control.Exception.catch`
+          (\(TransportExn s t) -> print s)
diff --git a/test/hs/runclient.sh b/test/hs/runclient.sh
index 98a3100..b93bbb1 100644
--- a/test/hs/runclient.sh
+++ b/test/hs/runclient.sh
@@ -19,12 +19,8 @@
 # under the License.
 #
 
-if [ -z $BASE_PKG ]; then
-    BASE_PKG=`ghc-pkg --simple-output list base-3* | sed -e "s/.*\(base-3\(.[0-9]\){3}\).*/\1/"`
-fi
-
 if [ -z $BASE ]; then
     BASE=../..
 fi
 
-ghci -fglasgow-exts -package $BASE_PKG -hide-package syb -i$BASE/lib/hs/src -i$BASE/test/hs/gen-hs Client.hs
+ghci -fglasgow-exts -i$BASE/lib/hs/src -i$BASE/test/hs/gen-hs Client.hs
diff --git a/test/hs/runserver.sh b/test/hs/runserver.sh
index 9358665..b23301b 100644
--- a/test/hs/runserver.sh
+++ b/test/hs/runserver.sh
@@ -19,13 +19,9 @@
 # under the License.
 #
 
-if [ -z $BASE_PKG ]; then
-    BASE_PKG=`ghc-pkg --simple-output list base-3* | sed -e "s/.*\(base-3\(.[0-9]\){3}\).*/\1/"`
-fi
-
 if [ -z $BASE ]; then
     BASE=../..
 fi
 
 printf "Starting server... "
-ghc -fglasgow-exts -package $BASE_PKG -hide-package syb -i$BASE/lib/hs/src -i$BASE/test/hs/gen-hs Server.hs -e "putStrLn \"ready.\" >> Server.main"
+ghc -fglasgow-exts -i$BASE/lib/hs/src -i$BASE/test/hs/gen-hs Server.hs -e "putStrLn \"ready.\" >> Server.main"