summaryrefslogtreecommitdiffstats
path: root/src/jaegertracing/thrift/test/ocaml
diff options
context:
space:
mode:
Diffstat (limited to 'src/jaegertracing/thrift/test/ocaml')
-rw-r--r--src/jaegertracing/thrift/test/ocaml/Makefile24
-rw-r--r--src/jaegertracing/thrift/test/ocaml/client/Makefile26
-rw-r--r--src/jaegertracing/thrift/test/ocaml/client/TestClient.ml82
-rw-r--r--src/jaegertracing/thrift/test/ocaml/server/Makefile27
-rw-r--r--src/jaegertracing/thrift/test/ocaml/server/TestServer.ml137
5 files changed, 296 insertions, 0 deletions
diff --git a/src/jaegertracing/thrift/test/ocaml/Makefile b/src/jaegertracing/thrift/test/ocaml/Makefile
new file mode 100644
index 000000000..a543ce587
--- /dev/null
+++ b/src/jaegertracing/thrift/test/ocaml/Makefile
@@ -0,0 +1,24 @@
+#
+# 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.
+#
+
+all:
+ cd client; make; cd ..; cd server; make
+clean:
+ cd client; make clean; cd ..; cd server; make clean
+
diff --git a/src/jaegertracing/thrift/test/ocaml/client/Makefile b/src/jaegertracing/thrift/test/ocaml/client/Makefile
new file mode 100644
index 000000000..806ed20a9
--- /dev/null
+++ b/src/jaegertracing/thrift/test/ocaml/client/Makefile
@@ -0,0 +1,26 @@
+#
+# 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.
+#
+
+SOURCES = ../gen-ocaml/ThriftTest_types.ml ../gen-ocaml/ThriftTest_consts.ml ../gen-ocaml/SecondService.ml ../gen-ocaml/ThriftTest.ml TestClient.ml
+RESULT = tc
+INCDIRS = "../../../lib/ocaml/src/" "../gen-ocaml/"
+LIBS = unix thrift
+all: nc
+OCAMLMAKEFILE = ../../../lib/ocaml/OCamlMakefile
+include $(OCAMLMAKEFILE)
diff --git a/src/jaegertracing/thrift/test/ocaml/client/TestClient.ml b/src/jaegertracing/thrift/test/ocaml/client/TestClient.ml
new file mode 100644
index 000000000..91783ae42
--- /dev/null
+++ b/src/jaegertracing/thrift/test/ocaml/client/TestClient.ml
@@ -0,0 +1,82 @@
+(*
+ 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.
+*)
+
+open Thrift;;
+open ThriftTest_types;;
+
+let s = new TSocket.t "127.0.0.1" 9090;;
+let p = new TBinaryProtocol.t s;;
+let c = new ThriftTest.client p p;;
+let sod = function
+ Some v -> v
+ | None -> raise Thrift_error;;
+
+s#opn;
+print_string (c#testString "bya");
+print_char '\n';
+print_int (c#testByte 8);
+print_char '\n';
+print_int (c#testByte (-8));
+print_char '\n';
+print_int (c#testI32 32);
+print_char '\n';
+print_string (Int64.to_string (c#testI64 64L));
+print_char '\n';
+print_float (c#testDouble 3.14);
+print_char '\n';
+
+let l = [1;2;3;4] in
+ if l = (c#testList l) then print_string "list ok\n" else print_string "list fail\n";;
+let h = Hashtbl.create 5 in
+let a = Hashtbl.add h in
+ for i=1 to 10 do
+ a i (10*i)
+ done;
+ let r = c#testMap h in
+ for i=1 to 10 do
+ try
+ let g = Hashtbl.find r i in
+ print_int i;
+ print_char ' ';
+ print_int g;
+ print_char '\n'
+ with Not_found -> print_string ("Can't find "^(string_of_int i)^"\n")
+ done;;
+
+let s = Hashtbl.create 5 in
+let a = Hashtbl.add s in
+ for i = 1 to 10 do
+ a i true
+ done;
+ let r = c#testSet s in
+ for i = 1 to 10 do
+ try
+ let g = Hashtbl.find r i in
+ print_int i;
+ print_char '\n'
+ with Not_found -> print_string ("Can't find "^(string_of_int i)^"\n")
+ done;;
+try
+ c#testException "Xception"
+with Xception _ -> print_string "testException ok\n";;
+try
+ ignore(c#testMultiException "Xception" "bya")
+with Xception e -> Printf.printf "%d %s\n" (sod e#get_errorCode) (sod e#get_message);;
+
+
diff --git a/src/jaegertracing/thrift/test/ocaml/server/Makefile b/src/jaegertracing/thrift/test/ocaml/server/Makefile
new file mode 100644
index 000000000..44dcac761
--- /dev/null
+++ b/src/jaegertracing/thrift/test/ocaml/server/Makefile
@@ -0,0 +1,27 @@
+#
+# 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.
+#
+
+SOURCES = ../gen-ocaml/ThriftTest_types.ml ../gen-ocaml/ThriftTest_consts.ml ../gen-ocaml/SecondService.ml ../gen-ocaml/ThriftTest.ml TestServer.ml
+RESULT = ts
+INCDIRS = "../../../lib/ocaml/src/" "../gen-ocaml/"
+LIBS = thrift
+THREADS = yes
+all: nc
+OCAMLMAKEFILE = ../../../lib/ocaml/OCamlMakefile
+include $(OCAMLMAKEFILE)
diff --git a/src/jaegertracing/thrift/test/ocaml/server/TestServer.ml b/src/jaegertracing/thrift/test/ocaml/server/TestServer.ml
new file mode 100644
index 000000000..efe0f4b2b
--- /dev/null
+++ b/src/jaegertracing/thrift/test/ocaml/server/TestServer.ml
@@ -0,0 +1,137 @@
+(*
+ 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.
+*)
+
+open Thrift
+open ThriftTest_types
+
+let p = Printf.printf;;
+exception Die;;
+let sod = function
+ Some v -> v
+ | None -> raise Die;;
+
+
+class test_handler =
+object (self)
+ inherit ThriftTest.iface
+ method testVoid = p "testVoid()\n"
+ method testString x = p "testString(%s)\n" (sod x); (sod x)
+ method testByte x = p "testByte(%d)\n" (sod x); (sod x)
+ method testI32 x = p "testI32(%d)\n" (sod x); (sod x)
+ method testI64 x = p "testI64(%s)\n" (Int64.to_string (sod x)); (sod x)
+ method testDouble x = p "testDouble(%f)\n" (sod x); (sod x)
+ method testBinary x = p "testBinary(%s)\n" (sod x); (sod x)
+ method testStruct x = p "testStruct(---)\n"; (sod x)
+ method testNest x = p "testNest(---)\n"; (sod x)
+ method testMap x = p "testMap(---)\n"; (sod x)
+ method testSet x = p "testSet(---)\n"; (sod x)
+ method testList x = p "testList(---)\n"; (sod x)
+ method testEnum x = p "testEnum(---)\n"; (sod x)
+ method testTypedef x = p "testTypedef(---)\n"; (sod x)
+ method testMapMap x = p "testMapMap(%d)\n" (sod x);
+ let mm = Hashtbl.create 3 in
+ let pos = Hashtbl.create 7 in
+ let neg = Hashtbl.create 7 in
+ for i=1 to 4 do
+ Hashtbl.add pos i i;
+ Hashtbl.add neg (-i) (-i);
+ done;
+ Hashtbl.add mm 4 pos;
+ Hashtbl.add mm (-4) neg;
+ mm
+ method testInsanity x = p "testInsanity()\n";
+ p "testinsanity()\n";
+ let hello = new xtruct in
+ let goodbye = new xtruct in
+ let crazy = new insanity in
+ let looney = new insanity in
+ let cumap = Hashtbl.create 7 in
+ let insane = Hashtbl.create 7 in
+ let firstmap = Hashtbl.create 7 in
+ let secondmap = Hashtbl.create 7 in
+ hello#set_string_thing "Hello2";
+ hello#set_byte_thing 2;
+ hello#set_i32_thing 2;
+ hello#set_i64_thing 2L;
+ goodbye#set_string_thing "Goodbye4";
+ goodbye#set_byte_thing 4;
+ goodbye#set_i32_thing 4;
+ goodbye#set_i64_thing 4L;
+ Hashtbl.add cumap Numberz.EIGHT 8L;
+ Hashtbl.add cumap Numberz.FIVE 5L;
+ crazy#set_userMap cumap;
+ crazy#set_xtructs [goodbye; hello];
+ Hashtbl.add firstmap Numberz.TWO crazy;
+ Hashtbl.add firstmap Numberz.THREE crazy;
+ Hashtbl.add secondmap Numberz.SIX looney;
+ Hashtbl.add insane 1L firstmap;
+ Hashtbl.add insane 2L secondmap;
+ insane
+ method testMulti a0 a1 a2 a3 a4 a5 =
+ p "testMulti()\n";
+ let hello = new xtruct in
+ hello#set_string_thing "Hello2";
+ hello#set_byte_thing (sod a0);
+ hello#set_i32_thing (sod a1);
+ hello#set_i64_thing (sod a2);
+ hello
+ method testException s =
+ p "testException(%S)\n" (sod s);
+ if (sod s) = "Xception" then
+ let x = new xception in
+ x#set_errorCode 1001;
+ x#set_message "This is an Xception";
+ raise (Xception x)
+ else ()
+ method testMultiException a0 a1 =
+ p "testMultiException(%S, %S)\n" (sod a0) (sod a1);
+ if (sod a0) = "Xception" then
+ let x = new xception in
+ x#set_errorCode 1001;
+ x#set_message "This is an Xception";
+ raise (Xception x)
+ else (if (sod a0) = "Xception2" then
+ let x = new xception2 in
+ let s = new xtruct in
+ x#set_errorCode 2002;
+ s#set_string_thing "This as an Xception2";
+ x#set_struct_thing s;
+ raise (Xception2 x)
+ else ());
+ let res = new xtruct in
+ res#set_string_thing (sod a1);
+ res
+ method testOneway i =
+ Unix.sleep (sod i)
+end;;
+
+let h = new test_handler in
+let proc = new ThriftTest.processor h in
+let port = 9090 in
+let pf = new TBinaryProtocol.factory in
+let server = new TThreadedServer.t
+ proc
+ (new TServerSocket.t port)
+ (new Transport.factory)
+ pf
+ pf
+in
+ server#serve
+
+