1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
|
--
-- Licensed to the Apache Software Foundation (ASF) under one
-- or more contributor license agreements. See the NOTICE file
-- distributed with this work for additional information
-- regarding copyright ownership. The ASF licenses this file
-- to you under the Apache License, Version 2.0 (the
-- "License"); you may not use this file except in compliance
-- with the License. You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing,
-- software distributed under the License is distributed on an
-- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-- KIND, either express or implied. See the License for the
-- specific language governing permissions and limitations
-- under the License.
--
{-# LANGUAGE OverloadedStrings #-}
module Main where
import qualified Control.Exception
import qualified Data.ByteString.Lazy as DBL
import qualified Data.HashMap.Strict as Map
import qualified Data.HashSet as Set
import qualified Data.Vector as Vector
import qualified Network
import Thrift.Protocol.Binary
import Thrift.Server
import Thrift.Transport.Handle
import qualified ThriftTestUtils
import qualified DebugProtoTest_Types as Types
import qualified Inherited
import qualified Inherited_Client as IClient
import qualified Inherited_Iface as IIface
import qualified Srv_Client as SClient
import qualified Srv_Iface as SIface
-- we don't actually need this import, but force it to check the code generator exports proper Haskell syntax
import qualified Srv()
data InheritedHandler = InheritedHandler
instance SIface.Srv_Iface InheritedHandler where
janky _ arg = do
ThriftTestUtils.serverLog $ "Got janky method call: " ++ show arg
return $ 31
voidMethod _ = do
ThriftTestUtils.serverLog "Got voidMethod method call"
return ()
primitiveMethod _ = do
ThriftTestUtils.serverLog "Got primitiveMethod call"
return $ 42
structMethod _ = do
ThriftTestUtils.serverLog "Got structMethod call"
return $ Types.CompactProtoTestStruct {
Types.compactProtoTestStruct_a_byte = 0x01,
Types.compactProtoTestStruct_a_i16 = 0x02,
Types.compactProtoTestStruct_a_i32 = 0x03,
Types.compactProtoTestStruct_a_i64 = 0x04,
Types.compactProtoTestStruct_a_double = 0.1,
Types.compactProtoTestStruct_a_string = "abcdef",
Types.compactProtoTestStruct_a_binary = DBL.empty,
Types.compactProtoTestStruct_true_field = True,
Types.compactProtoTestStruct_false_field = False,
Types.compactProtoTestStruct_empty_struct_field = Types.Empty,
Types.compactProtoTestStruct_byte_list = Vector.empty,
Types.compactProtoTestStruct_i16_list = Vector.empty,
Types.compactProtoTestStruct_i32_list = Vector.empty,
Types.compactProtoTestStruct_i64_list = Vector.empty,
Types.compactProtoTestStruct_double_list = Vector.empty,
Types.compactProtoTestStruct_string_list = Vector.empty,
Types.compactProtoTestStruct_binary_list = Vector.empty,
Types.compactProtoTestStruct_boolean_list = Vector.empty,
Types.compactProtoTestStruct_struct_list = Vector.empty,
Types.compactProtoTestStruct_byte_set = Set.empty,
Types.compactProtoTestStruct_i16_set = Set.empty,
Types.compactProtoTestStruct_i32_set = Set.empty,
Types.compactProtoTestStruct_i64_set = Set.empty,
Types.compactProtoTestStruct_double_set = Set.empty,
Types.compactProtoTestStruct_string_set = Set.empty,
Types.compactProtoTestStruct_binary_set = Set.empty,
Types.compactProtoTestStruct_boolean_set = Set.empty,
Types.compactProtoTestStruct_struct_set = Set.empty,
Types.compactProtoTestStruct_byte_byte_map = Map.empty,
Types.compactProtoTestStruct_i16_byte_map = Map.empty,
Types.compactProtoTestStruct_i32_byte_map = Map.empty,
Types.compactProtoTestStruct_i64_byte_map = Map.empty,
Types.compactProtoTestStruct_double_byte_map = Map.empty,
Types.compactProtoTestStruct_string_byte_map = Map.empty,
Types.compactProtoTestStruct_binary_byte_map = Map.empty,
Types.compactProtoTestStruct_boolean_byte_map = Map.empty,
Types.compactProtoTestStruct_byte_i16_map = Map.empty,
Types.compactProtoTestStruct_byte_i32_map = Map.empty,
Types.compactProtoTestStruct_byte_i64_map = Map.empty,
Types.compactProtoTestStruct_byte_double_map = Map.empty,
Types.compactProtoTestStruct_byte_string_map = Map.empty,
Types.compactProtoTestStruct_byte_binary_map = Map.empty,
Types.compactProtoTestStruct_byte_boolean_map = Map.empty,
Types.compactProtoTestStruct_list_byte_map = Map.empty,
Types.compactProtoTestStruct_set_byte_map = Map.empty,
Types.compactProtoTestStruct_map_byte_map = Map.empty,
Types.compactProtoTestStruct_byte_map_map = Map.empty,
Types.compactProtoTestStruct_byte_set_map = Map.empty,
Types.compactProtoTestStruct_byte_list_map = Map.empty,
Types.compactProtoTestStruct_field500 = 500,
Types.compactProtoTestStruct_field5000 = 5000,
Types.compactProtoTestStruct_field20000 = 20000 }
methodWithDefaultArgs _ arg = do
ThriftTestUtils.serverLog $ "Got methodWithDefaultArgs: " ++ show arg
return ()
onewayMethod _ = do
ThriftTestUtils.serverLog "Got onewayMethod"
instance IIface.Inherited_Iface InheritedHandler where
identity _ arg = do
ThriftTestUtils.serverLog $ "Got identity method: " ++ show arg
return arg
client :: (String, Network.PortID) -> IO ()
client addr = do
to <- hOpen addr
let p = BinaryProtocol to
let ps = (p,p)
v1 <- SClient.janky ps 42
ThriftTestUtils.clientLog $ show v1
SClient.voidMethod ps
v2 <- SClient.primitiveMethod ps
ThriftTestUtils.clientLog $ show v2
v3 <- SClient.structMethod ps
ThriftTestUtils.clientLog $ show v3
SClient.methodWithDefaultArgs ps 42
SClient.onewayMethod ps
v4 <- IClient.identity ps 42
ThriftTestUtils.clientLog $ show v4
return ()
server :: Network.PortNumber -> IO ()
server port = do
ThriftTestUtils.serverLog "Ready..."
(runBasicServer InheritedHandler Inherited.process port)
`Control.Exception.catch`
(\(TransportExn s _) -> error $ "FAILURE: " ++ show s)
main :: IO ()
main = ThriftTestUtils.runTest server client
|