blob: efe0f4b2b489cdf4713b708e5812e5c2c581db5a [file] [log] [blame]
David Reissea2cba82009-03-30 21:35:00 +00001(*
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
iproctor9a41a0c2007-07-16 21:59:24 +000020open Thrift
21open ThriftTest_types
22
23let p = Printf.printf;;
24exception Die;;
25let sod = function
26 Some v -> v
27 | None -> raise Die;;
28
29
30class test_handler =
31object (self)
32 inherit ThriftTest.iface
33 method testVoid = p "testVoid()\n"
34 method testString x = p "testString(%s)\n" (sod x); (sod x)
35 method testByte x = p "testByte(%d)\n" (sod x); (sod x)
36 method testI32 x = p "testI32(%d)\n" (sod x); (sod x)
37 method testI64 x = p "testI64(%s)\n" (Int64.to_string (sod x)); (sod x)
38 method testDouble x = p "testDouble(%f)\n" (sod x); (sod x)
Jens Geyer8bcfdd92014-12-14 03:14:26 +010039 method testBinary x = p "testBinary(%s)\n" (sod x); (sod x)
iproctor9a41a0c2007-07-16 21:59:24 +000040 method testStruct x = p "testStruct(---)\n"; (sod x)
41 method testNest x = p "testNest(---)\n"; (sod x)
42 method testMap x = p "testMap(---)\n"; (sod x)
43 method testSet x = p "testSet(---)\n"; (sod x)
44 method testList x = p "testList(---)\n"; (sod x)
45 method testEnum x = p "testEnum(---)\n"; (sod x)
46 method testTypedef x = p "testTypedef(---)\n"; (sod x)
David Reiss0c90f6f2008-02-06 22:18:40 +000047 method testMapMap x = p "testMapMap(%d)\n" (sod x);
iproctor9a41a0c2007-07-16 21:59:24 +000048 let mm = Hashtbl.create 3 in
49 let pos = Hashtbl.create 7 in
50 let neg = Hashtbl.create 7 in
51 for i=1 to 4 do
52 Hashtbl.add pos i i;
53 Hashtbl.add neg (-i) (-i);
54 done;
55 Hashtbl.add mm 4 pos;
56 Hashtbl.add mm (-4) neg;
57 mm
58 method testInsanity x = p "testInsanity()\n";
59 p "testinsanity()\n";
60 let hello = new xtruct in
61 let goodbye = new xtruct in
62 let crazy = new insanity in
63 let looney = new insanity in
64 let cumap = Hashtbl.create 7 in
65 let insane = Hashtbl.create 7 in
66 let firstmap = Hashtbl.create 7 in
67 let secondmap = Hashtbl.create 7 in
68 hello#set_string_thing "Hello2";
69 hello#set_byte_thing 2;
70 hello#set_i32_thing 2;
71 hello#set_i64_thing 2L;
72 goodbye#set_string_thing "Goodbye4";
73 goodbye#set_byte_thing 4;
74 goodbye#set_i32_thing 4;
75 goodbye#set_i64_thing 4L;
76 Hashtbl.add cumap Numberz.EIGHT 8L;
77 Hashtbl.add cumap Numberz.FIVE 5L;
78 crazy#set_userMap cumap;
79 crazy#set_xtructs [goodbye; hello];
80 Hashtbl.add firstmap Numberz.TWO crazy;
81 Hashtbl.add firstmap Numberz.THREE crazy;
82 Hashtbl.add secondmap Numberz.SIX looney;
83 Hashtbl.add insane 1L firstmap;
84 Hashtbl.add insane 2L secondmap;
85 insane
David Reiss0c90f6f2008-02-06 22:18:40 +000086 method testMulti a0 a1 a2 a3 a4 a5 =
iproctor9a41a0c2007-07-16 21:59:24 +000087 p "testMulti()\n";
88 let hello = new xtruct in
89 hello#set_string_thing "Hello2";
90 hello#set_byte_thing (sod a0);
91 hello#set_i32_thing (sod a1);
92 hello#set_i64_thing (sod a2);
93 hello
94 method testException s =
95 p "testException(%S)\n" (sod s);
96 if (sod s) = "Xception" then
97 let x = new xception in
98 x#set_errorCode 1001;
99 x#set_message "This is an Xception";
100 raise (Xception x)
101 else ()
102 method testMultiException a0 a1 =
103 p "testMultiException(%S, %S)\n" (sod a0) (sod a1);
104 if (sod a0) = "Xception" then
105 let x = new xception in
106 x#set_errorCode 1001;
107 x#set_message "This is an Xception";
108 raise (Xception x)
109 else (if (sod a0) = "Xception2" then
110 let x = new xception2 in
111 let s = new xtruct in
112 x#set_errorCode 2002;
113 s#set_string_thing "This as an Xception2";
114 x#set_struct_thing s;
115 raise (Xception2 x)
116 else ());
117 let res = new xtruct in
118 res#set_string_thing (sod a1);
119 res
David Reiss6ce401d2009-03-24 20:01:58 +0000120 method testOneway i =
iproctor8361bf02008-04-10 00:31:55 +0000121 Unix.sleep (sod i)
iproctor9a41a0c2007-07-16 21:59:24 +0000122end;;
123
124let h = new test_handler in
125let proc = new ThriftTest.processor h in
126let port = 9090 in
iproctor7897c922007-08-08 01:43:39 +0000127let pf = new TBinaryProtocol.factory in
David Reiss0c90f6f2008-02-06 22:18:40 +0000128let server = new TThreadedServer.t
129 proc
130 (new TServerSocket.t port)
131 (new Transport.factory)
132 pf
133 pf
iproctor7897c922007-08-08 01:43:39 +0000134in
135 server#serve
David Reiss0c90f6f2008-02-06 22:18:40 +0000136
137