Subversion Repositories SmartDukaan

Rev

Rev 30 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
30 ashish 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
open Thrift
21
open ThriftTest_types
22
 
23
let p = Printf.printf;;
24
exception Die;;
25
let sod = function
26
    Some v -> v
27
  | None -> raise Die;;
28
 
29
 
30
class test_handler =
31
object (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)
39
  method testStruct x = p "testStruct(---)\n"; (sod x)
40
  method testNest x = p "testNest(---)\n"; (sod x)
41
  method testMap x = p "testMap(---)\n"; (sod x)
42
  method testSet x = p "testSet(---)\n"; (sod x)
43
  method testList x = p "testList(---)\n"; (sod x)
44
  method testEnum x = p "testEnum(---)\n"; (sod x)
45
  method testTypedef x = p "testTypedef(---)\n"; (sod x)
46
  method testMapMap x = p "testMapMap(%d)\n" (sod x);
47
    let mm = Hashtbl.create 3 in
48
    let pos = Hashtbl.create 7 in
49
    let neg = Hashtbl.create 7 in
50
      for i=1 to 4 do
51
        Hashtbl.add pos i i;
52
        Hashtbl.add neg (-i) (-i);
53
      done;
54
      Hashtbl.add mm 4 pos;
55
      Hashtbl.add mm (-4) neg;
56
      mm
57
  method testInsanity x = p "testInsanity()\n";
58
    p "testinsanity()\n";
59
    let hello = new xtruct in
60
    let goodbye = new xtruct in
61
    let crazy = new insanity in
62
    let looney = new insanity in
63
    let cumap = Hashtbl.create 7 in
64
    let insane = Hashtbl.create 7 in
65
    let firstmap = Hashtbl.create 7 in
66
    let secondmap = Hashtbl.create 7 in
67
      hello#set_string_thing "Hello2";
68
      hello#set_byte_thing 2;
69
      hello#set_i32_thing 2;
70
      hello#set_i64_thing 2L;
71
      goodbye#set_string_thing "Goodbye4";
72
      goodbye#set_byte_thing 4;
73
      goodbye#set_i32_thing 4;
74
      goodbye#set_i64_thing 4L;
75
      Hashtbl.add cumap Numberz.EIGHT 8L;
76
      Hashtbl.add cumap Numberz.FIVE 5L;
77
      crazy#set_userMap cumap;
78
      crazy#set_xtructs [goodbye; hello];
79
      Hashtbl.add firstmap Numberz.TWO crazy;
80
      Hashtbl.add firstmap Numberz.THREE crazy;
81
      Hashtbl.add secondmap Numberz.SIX looney;
82
      Hashtbl.add insane 1L firstmap;
83
      Hashtbl.add insane 2L secondmap;
84
      insane
85
  method testMulti a0 a1 a2 a3 a4 a5 =
86
    p "testMulti()\n";
87
    let hello = new xtruct in
88
      hello#set_string_thing "Hello2";
89
      hello#set_byte_thing (sod a0);
90
      hello#set_i32_thing (sod a1);
91
      hello#set_i64_thing (sod a2);
92
      hello
93
  method testException s =
94
    p "testException(%S)\n" (sod s);
95
    if (sod s) = "Xception" then
96
      let x = new xception in
97
        x#set_errorCode 1001;
98
        x#set_message "This is an Xception";
99
        raise (Xception x)
100
    else ()
101
  method testMultiException a0 a1 =
102
    p "testMultiException(%S, %S)\n" (sod a0) (sod a1);
103
    if (sod a0) = "Xception" then
104
      let x = new xception in
105
        x#set_errorCode 1001;
106
        x#set_message "This is an Xception";
107
        raise (Xception x)
108
    else (if (sod a0) = "Xception2" then
109
              let x = new xception2 in
110
              let s = new xtruct in
111
                x#set_errorCode 2002;
112
                s#set_string_thing "This as an Xception2";
113
                x#set_struct_thing s;
114
                raise (Xception2 x)
115
          else ());
116
    let res = new xtruct in
117
      res#set_string_thing (sod a1);
118
      res
119
  method testOneway i =
120
    Unix.sleep (sod i)
121
end;;
122
 
123
let h = new test_handler in
124
let proc = new ThriftTest.processor h in
125
let port = 9090 in
126
let pf = new TBinaryProtocol.factory in
127
let server = new TThreadedServer.t
128
  proc
129
  (new TServerSocket.t port)
130
  (new Transport.factory)
131
  pf
132
  pf
133
in
134
  server#serve
135
 
136