From 19fcec84d8d7d21e796c7624e521b60d28ee21ed Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 20:45:59 +0200 Subject: Adding upstream version 16.2.11+ds. Signed-off-by: Daniel Baumann --- .../thrift/lib/erl/test/Thrift1151.thrift | 3 + .../thrift/lib/erl/test/Thrift1475.thrift | 34 ++ .../thrift/lib/erl/test/Thrift_omit_with.thrift | 22 + .../thrift/lib/erl/test/flags/LegacyNames.thrift | 33 ++ .../thrift/lib/erl/test/flags/Thrift3214.thrift | 23 + .../thrift/lib/erl/test/legacy_names_test.erl | 69 +++ .../thrift/lib/erl/test/multiplexing.thrift | 7 + .../thrift/lib/erl/test/multiplexing_test.erl | 57 ++ .../thrift/lib/erl/test/name_conflict_test.erl | 299 ++++++++++ .../thrift/lib/erl/test/stress_server.erl | 64 ++ .../thrift/lib/erl/test/test_const.erl | 54 ++ .../thrift/lib/erl/test/test_disklog.erl | 99 ++++ .../thrift/lib/erl/test/test_omit.erl | 79 +++ .../erl/test/test_rendered_double_constants.erl | 68 +++ .../thrift/lib/erl/test/test_thrift_1151.erl | 34 ++ .../thrift/lib/erl/test/test_thrift_3214.erl | 60 ++ .../erl/test/test_thrift_buffered_transport.erl | 359 ++++++++++++ .../lib/erl/test/test_thrift_compact_protocol.erl | 219 +++++++ .../lib/erl/test/test_thrift_file_transport.erl | 213 +++++++ .../lib/erl/test/test_thrift_framed_transport.erl | 404 +++++++++++++ .../erl/test/test_thrift_membuffer_transport.erl | 167 ++++++ .../lib/erl/test/test_thrift_socket_transport.erl | 199 +++++++ .../lib/erl/test/thrift_socket_server_test.erl | 49 ++ .../thrift/lib/erl/test/thrift_test_test.erl | 643 +++++++++++++++++++++ 24 files changed, 3258 insertions(+) create mode 100644 src/jaegertracing/thrift/lib/erl/test/Thrift1151.thrift create mode 100644 src/jaegertracing/thrift/lib/erl/test/Thrift1475.thrift create mode 100644 src/jaegertracing/thrift/lib/erl/test/Thrift_omit_with.thrift create mode 100644 src/jaegertracing/thrift/lib/erl/test/flags/LegacyNames.thrift create mode 100644 src/jaegertracing/thrift/lib/erl/test/flags/Thrift3214.thrift create mode 100644 src/jaegertracing/thrift/lib/erl/test/legacy_names_test.erl create mode 100644 src/jaegertracing/thrift/lib/erl/test/multiplexing.thrift create mode 100644 src/jaegertracing/thrift/lib/erl/test/multiplexing_test.erl create mode 100644 src/jaegertracing/thrift/lib/erl/test/name_conflict_test.erl create mode 100644 src/jaegertracing/thrift/lib/erl/test/stress_server.erl create mode 100644 src/jaegertracing/thrift/lib/erl/test/test_const.erl create mode 100644 src/jaegertracing/thrift/lib/erl/test/test_disklog.erl create mode 100644 src/jaegertracing/thrift/lib/erl/test/test_omit.erl create mode 100644 src/jaegertracing/thrift/lib/erl/test/test_rendered_double_constants.erl create mode 100644 src/jaegertracing/thrift/lib/erl/test/test_thrift_1151.erl create mode 100644 src/jaegertracing/thrift/lib/erl/test/test_thrift_3214.erl create mode 100644 src/jaegertracing/thrift/lib/erl/test/test_thrift_buffered_transport.erl create mode 100644 src/jaegertracing/thrift/lib/erl/test/test_thrift_compact_protocol.erl create mode 100644 src/jaegertracing/thrift/lib/erl/test/test_thrift_file_transport.erl create mode 100644 src/jaegertracing/thrift/lib/erl/test/test_thrift_framed_transport.erl create mode 100644 src/jaegertracing/thrift/lib/erl/test/test_thrift_membuffer_transport.erl create mode 100644 src/jaegertracing/thrift/lib/erl/test/test_thrift_socket_transport.erl create mode 100644 src/jaegertracing/thrift/lib/erl/test/thrift_socket_server_test.erl create mode 100644 src/jaegertracing/thrift/lib/erl/test/thrift_test_test.erl (limited to 'src/jaegertracing/thrift/lib/erl/test') diff --git a/src/jaegertracing/thrift/lib/erl/test/Thrift1151.thrift b/src/jaegertracing/thrift/lib/erl/test/Thrift1151.thrift new file mode 100644 index 000000000..6f934a7b1 --- /dev/null +++ b/src/jaegertracing/thrift/lib/erl/test/Thrift1151.thrift @@ -0,0 +1,3 @@ +struct StructA { 1: i16 x; } +struct StructB { 1: i32 x; } +struct StructC { 1: StructA x; } diff --git a/src/jaegertracing/thrift/lib/erl/test/Thrift1475.thrift b/src/jaegertracing/thrift/lib/erl/test/Thrift1475.thrift new file mode 100644 index 000000000..7adeb7e65 --- /dev/null +++ b/src/jaegertracing/thrift/lib/erl/test/Thrift1475.thrift @@ -0,0 +1,34 @@ +struct StructB +{ + 1: string x +} + +struct StructA +{ + 1: string a, + 2: binary b, + 3: optional string c, + 4: optional binary d, + 5: required string e, + 6: required binary f, + 7: string g = "foo", + 8: i32 h, + 9: optional i32 i, + 10: required i32 j, + 11: required i32 k = 5, + 12: double l, + 13: optional double m, + 14: required double n, + 15: double o = 3.14159, + 16: list string_list, + 17: list byte_list = [1, 2, 3], + 18: required list rsl, + 19: optional list osl, + 20: set string_set, + 21: required set rss, + 22: optional set oss, + 23: map string_map, + 24: required map rsm, + 25: optional map osm, + 26: StructB structb +} diff --git a/src/jaegertracing/thrift/lib/erl/test/Thrift_omit_with.thrift b/src/jaegertracing/thrift/lib/erl/test/Thrift_omit_with.thrift new file mode 100644 index 000000000..8bffc7c73 --- /dev/null +++ b/src/jaegertracing/thrift/lib/erl/test/Thrift_omit_with.thrift @@ -0,0 +1,22 @@ +struct test1 { + 1: i32 one + 2: i32 two // omit + 3: i32 three +} + +struct test2 { + 1: i32 one + 2: test2 two // omit + 3: i32 three +} + +struct test3 { + 1: i32 one + 2: list two // omit +} + +struct test4 { + 1: i32 one + 2: map two // omit +} + diff --git a/src/jaegertracing/thrift/lib/erl/test/flags/LegacyNames.thrift b/src/jaegertracing/thrift/lib/erl/test/flags/LegacyNames.thrift new file mode 100644 index 000000000..38f272907 --- /dev/null +++ b/src/jaegertracing/thrift/lib/erl/test/flags/LegacyNames.thrift @@ -0,0 +1,33 @@ +enum Numberz +{ + ONE = 1, + TWO, + THREE, + FIVE = 5, + SIX, + EIGHT = 8 +} + +const Numberz myNumberz = Numberz.ONE; + +struct CapitalizedStruct +{ + 1: i32 Id, + 2: binary message +} + +struct ListCapitalizedStructs +{ + 1: list structs +} + +exception Xception { + 1: i32 errorCode, + 2: binary message +} + +service LegacyNames +{ + ListCapitalizedStructs Names(1: CapitalizedStruct foo, 2: CapitalizedStruct bar) + throws(1: Xception err) +} \ No newline at end of file diff --git a/src/jaegertracing/thrift/lib/erl/test/flags/Thrift3214.thrift b/src/jaegertracing/thrift/lib/erl/test/flags/Thrift3214.thrift new file mode 100644 index 000000000..a9110cedd --- /dev/null +++ b/src/jaegertracing/thrift/lib/erl/test/flags/Thrift3214.thrift @@ -0,0 +1,23 @@ +/* + * 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. + */ + +struct StringMap +{ + 1: map data = {1: "a", 2: "b"}; +} diff --git a/src/jaegertracing/thrift/lib/erl/test/legacy_names_test.erl b/src/jaegertracing/thrift/lib/erl/test/legacy_names_test.erl new file mode 100644 index 000000000..c16aa3ee2 --- /dev/null +++ b/src/jaegertracing/thrift/lib/erl/test/legacy_names_test.erl @@ -0,0 +1,69 @@ +%% +%% 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. +%% + +-module(legacy_names_test). +-compile(export_all). + +-include_lib("eunit/include/eunit.hrl"). + +-include("gen-erl/legacyNames_constants.hrl"). + +record_generation_test_() -> + [ + {"capitalizedStruct record", ?_assertMatch( + {capitalizedStruct, _, _}, + #capitalizedStruct{id=null,message=null} + )} + ]. + +struct_info_test_() -> + [ + {"capitalizedStruct extended definition", ?_assertEqual( + {struct, [ + {1, undefined, i32, 'id', undefined}, + {2, undefined, string, 'message', undefined} + ]}, + legacyNames_types:struct_info_ext(capitalizedStruct) + )}, + {"listCapitalizedStructs extended definition", ?_assertEqual( + {struct, [ + {1, undefined, {list, {struct, {'legacyNames_types', 'capitalizedStruct'}}}, 'structs', []} + ]}, + legacyNames_types:struct_info_ext(listCapitalizedStructs) + )} + ]. + +service_info_test_() -> + [ + {"names params", ?_assertEqual( + {struct, [ + {1, {struct, {'legacyNames_types', 'capitalizedStruct'}}}, + {2, {struct, {'legacyNames_types', 'capitalizedStruct'}}} + ]}, + legacyNames_thrift:function_info(names, params_type) + )}, + {"names reply", ?_assertEqual( + {struct, {'legacyNames_types', 'listCapitalizedStructs'}}, + legacyNames_thrift:function_info(names, reply_type) + )}, + {"names exceptions", ?_assertEqual( + {struct, [{1, {struct, {'legacyNames_types', 'xception'}}}]}, + legacyNames_thrift:function_info(names, exceptions) + )} + ]. diff --git a/src/jaegertracing/thrift/lib/erl/test/multiplexing.thrift b/src/jaegertracing/thrift/lib/erl/test/multiplexing.thrift new file mode 100644 index 000000000..7c7994b97 --- /dev/null +++ b/src/jaegertracing/thrift/lib/erl/test/multiplexing.thrift @@ -0,0 +1,7 @@ +service Multiplexing_Calculator { + i32 add(1: i32 x, 2: i32 y) +} + +service Multiplexing_WeatherReport { + double getTemperature() +} diff --git a/src/jaegertracing/thrift/lib/erl/test/multiplexing_test.erl b/src/jaegertracing/thrift/lib/erl/test/multiplexing_test.erl new file mode 100644 index 000000000..0f2d616b8 --- /dev/null +++ b/src/jaegertracing/thrift/lib/erl/test/multiplexing_test.erl @@ -0,0 +1,57 @@ +-module(multiplexing_test). + +-include_lib("eunit/include/eunit.hrl"). + +-export([ + handle_function/2 + ,handle_error/2 +]). + +start_multiplexed_server_test() -> + + Port = 9090, + Services = [ + {"Multiplexing_Calculator", multiplexing__calculator_thrift}, + {"Multiplexing_WeatherReport", multiplexing__weather_report_thrift} + ], + + {ok, Pid} = thrift_socket_server:start([ + {ip, "127.0.0.1"}, + {port, Port}, + {name, ?MODULE}, + {service, Services}, + {handler, [ + {"error_handler", ?MODULE}, + {"Multiplexing_Calculator", ?MODULE}, + {"Multiplexing_WeatherReport", ?MODULE} + ]} + ]), + + {ok, [{"Multiplexing_Calculator", CalculatorClient0}, + {"Multiplexing_WeatherReport", WeatherReportClient0}]} = thrift_client_util:new_multiplexed("127.0.0.1", Port, Services, []), + + ?assertMatch({_, {error, {bad_args, _, _}}}, thrift_client:call(WeatherReportClient0, getTemperature, [1])), + ?assertMatch({_, {error, {bad_args, _, _}}}, thrift_client:call(CalculatorClient0, add, [1])), + ?assertMatch({_, {error, {bad_args, _, _}}}, thrift_client:call(CalculatorClient0, add, [1,1,1])), + + ?assertMatch({_, {error, {no_function, _}}}, thrift_client:call(CalculatorClient0, getTemperature, [])), + ?assertMatch({_, {error, {no_function, _}}}, thrift_client:call(WeatherReportClient0, add, [41, 1])), + + ?assertMatch({_, {ok, 42}}, thrift_client:call(CalculatorClient0, add, [41, 1])), + ?assertMatch({_, {ok, 42.0}}, thrift_client:call(WeatherReportClient0, getTemperature, [])), + + thrift_socket_server:stop(Pid). + +%% HANDLE FUNCTIONS + +%% Calculator handles +handle_function(add, {X, Y}) -> + {reply, X + Y}; + +%% WeatherReport handles +handle_function(getTemperature, {}) -> + {reply, 42.0}. + +handle_error(_F, _Reason) -> +%% ?debugHere, ?debugVal({_F, _Reason}), + ok. \ No newline at end of file diff --git a/src/jaegertracing/thrift/lib/erl/test/name_conflict_test.erl b/src/jaegertracing/thrift/lib/erl/test/name_conflict_test.erl new file mode 100644 index 000000000..b01df5732 --- /dev/null +++ b/src/jaegertracing/thrift/lib/erl/test/name_conflict_test.erl @@ -0,0 +1,299 @@ +%% +%% 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. +%% + +-module(name_conflict_test). +-compile(export_all). + +-include_lib("eunit/include/eunit.hrl"). + +-include("gen-erl/name_conflict_test_constants.hrl"). + +record_generation_test_() -> + [ + {"using record", ?_assertMatch( + {using, _, _}, + #using{single=null,integer=null} + )}, + {"delegate record", ?_assertMatch( + {delegate, _, _}, + #delegate{partial=null,delegate=null} + )}, + {"get record", ?_assertMatch( + {get, _}, + #get{sbyte=null} + )}, + {"partial record", ?_assertMatch( + {partial, _, _, _}, + #partial{using=null} + )}, + {"ClassAndProp record", ?_assertMatch( + {'ClassAndProp', _, _, _, _}, + #'ClassAndProp'{ + 'ClassAndProp'=null, + 'ClassAndProp_'=null, + 'ClassAndProp__'=null, + 'ClassAndProper'=null + } + )}, + {"second_chance record", ?_assertMatch( + {second_chance, _, _, _, _}, + #second_chance{ + 'SECOND_CHANCE'=null, + 'SECOND_CHANCE_'=null, + 'SECOND_CHANCE__'=null, + 'SECOND_CHANCES'=null + } + )}, + {"NOW_EAT_THIS record", ?_assertMatch( + {'NOW_EAT_THIS', _, _, _, _}, + #'NOW_EAT_THIS'{ + now_eat_this=null, + now_eat_this_=null, + now_eat_this__=null, + now_eat_this_and_this=null + } + )}, + {"TheEdgeCase record", ?_assertMatch( + {'TheEdgeCase', _, _, _, _, _, _}, + #'TheEdgeCase'{ + theEdgeCase=null, + theEdgeCase_=null, + theEdgeCase__=null, + 'TheEdgeCase'=null, + 'TheEdgeCase_'=null, + 'TheEdgeCase__'=null + } + )}, + {"Tricky_ record", ?_assertMatch( + {'Tricky_', _, _}, + #'Tricky_'{tricky=null,'Tricky'=null} + )}, + {"Nested record", ?_assertMatch( + {'Nested', _, _, _, _, _, _}, + #'Nested'{ + 'ClassAndProp'=null, + second_chance=null, + 'NOW_EAT_THIS'=null, + 'TheEdgeCase'=null, + 'Tricky_'=null, + 'Nested'=null + } + )}, + {"Problem_ record", ?_assertMatch( + {'Problem_', _, _}, + #'Problem_'{problem=null,'Problem'=null} + )} + ]. + +struct_info_test_() -> + [ + {"using definition", ?_assertEqual( + {struct, [{1, double},{2, double}]}, + name_conflict_test_types:struct_info(using) + )}, + {"delegate definition", ?_assertEqual( + {struct, [ + {1, string}, + {2, {struct, {name_conflict_test_types, delegate}}} + ]}, + name_conflict_test_types:struct_info(delegate) + )}, + {"get definition", ?_assertEqual( + {struct, [{1, bool}]}, + name_conflict_test_types:struct_info(get) + )}, + {"partial definition", ?_assertEqual( + {struct, [ + {1, {struct, {name_conflict_test_types, using}}}, + {2, bool}, + {3, bool} + ]}, + name_conflict_test_types:struct_info(partial) + )}, + {"ClassAndProp definition", ?_assertEqual( + {struct, [{1, bool},{2, bool},{3, bool},{4, bool}]}, + name_conflict_test_types:struct_info('ClassAndProp') + )}, + {"second_chance definition", ?_assertEqual( + {struct, [{1, bool},{2, bool},{3, bool},{4, bool}]}, + name_conflict_test_types:struct_info(second_chance) + )}, + {"NOW_EAT_THIS definition", ?_assertEqual( + {struct, [{1, bool},{2, bool},{3, bool},{4, bool}]}, + name_conflict_test_types:struct_info('NOW_EAT_THIS') + )}, + {"TheEdgeCase definition", ?_assertEqual( + {struct, [{1, bool},{2, bool},{3, bool},{4, bool},{5, bool},{6, bool}]}, + name_conflict_test_types:struct_info('TheEdgeCase') + )}, + {"Tricky_ definition", ?_assertEqual( + {struct, [{1, bool},{2, bool}]}, + name_conflict_test_types:struct_info('Tricky_') + )}, + {"Nested definition", ?_assertEqual( + {struct, [ + {1, {struct, {name_conflict_test_types, 'ClassAndProp'}}}, + {2, {struct, {name_conflict_test_types, second_chance}}}, + {3, {struct, {name_conflict_test_types, 'NOW_EAT_THIS'}}}, + {4, {struct, {name_conflict_test_types, 'TheEdgeCase'}}}, + {5, {struct, {name_conflict_test_types, 'Tricky_'}}}, + {6, {struct, {name_conflict_test_types, 'Nested'}}} + ]}, + name_conflict_test_types:struct_info('Nested') + )}, + {"Problem_ definition", ?_assertEqual( + {struct, [{1, bool},{2, bool}]}, + name_conflict_test_types:struct_info('Problem_') + )}, + {"using extended definition", ?_assertEqual( + {struct, [ + {1, undefined, double, single, undefined}, + {2, undefined, double, integer, undefined} + ]}, + name_conflict_test_types:struct_info_ext(using) + )}, + {"delegate extended definition", ?_assertEqual( + {struct, [ + {1, undefined, string, partial, undefined}, + {2, undefined, {struct, {name_conflict_test_types, delegate}}, delegate, undefined} + ]}, + name_conflict_test_types:struct_info_ext(delegate) + )}, + {"get extended definition", ?_assertEqual( + {struct, [{1, undefined, bool, sbyte, undefined}]}, + name_conflict_test_types:struct_info_ext(get) + )}, + {"partial extended definition", ?_assertEqual( + {struct, [ + {1, undefined, {struct, {name_conflict_test_types, using}}, using, #using{}}, + {2, undefined, bool, read, undefined}, + {3, undefined, bool, write, undefined} + ]}, + name_conflict_test_types:struct_info_ext(partial) + )}, + {"ClassAndProp extended definition", ?_assertEqual( + {struct, [ + {1, undefined, bool, 'ClassAndProp', undefined}, + {2, undefined, bool, 'ClassAndProp_', undefined}, + {3, undefined, bool, 'ClassAndProp__', undefined}, + {4, undefined, bool, 'ClassAndProper', undefined} + ]}, + name_conflict_test_types:struct_info_ext('ClassAndProp') + )}, + {"second_chance extended definition", ?_assertEqual( + {struct, [ + {1, undefined, bool, 'SECOND_CHANCE', undefined}, + {2, undefined, bool, 'SECOND_CHANCE_', undefined}, + {3, undefined, bool, 'SECOND_CHANCE__', undefined}, + {4, undefined, bool, 'SECOND_CHANCES', undefined} + ]}, + name_conflict_test_types:struct_info_ext(second_chance) + )}, + {"NOW_EAT_THIS extended definition", ?_assertEqual( + {struct, [ + {1, undefined, bool, now_eat_this, undefined}, + {2, undefined, bool, now_eat_this_, undefined}, + {3, undefined, bool, now_eat_this__, undefined}, + {4, undefined, bool, now_eat_this_and_this, undefined} + ]}, + name_conflict_test_types:struct_info_ext('NOW_EAT_THIS') + )}, + {"TheEdgeCase extended definition", ?_assertEqual( + {struct, [ + {1, undefined, bool, theEdgeCase, undefined}, + {2, undefined, bool, theEdgeCase_, undefined}, + {3, undefined, bool, theEdgeCase__, undefined}, + {4, undefined, bool, 'TheEdgeCase', undefined}, + {5, undefined, bool, 'TheEdgeCase_', undefined}, + {6, undefined, bool, 'TheEdgeCase__', undefined} + ]}, + name_conflict_test_types:struct_info_ext('TheEdgeCase') + )}, + {"Tricky_ extended definition", ?_assertEqual( + {struct, [ + {1, undefined, bool, tricky, undefined}, + {2, undefined, bool, 'Tricky', undefined} + ]}, + name_conflict_test_types:struct_info_ext('Tricky_') + )}, + {"Nested extended definition", ?_assertEqual( + {struct, [ + {1, undefined, {struct, { + name_conflict_test_types, + 'ClassAndProp' + }}, 'ClassAndProp', #'ClassAndProp'{}}, + {2, undefined, {struct, { + name_conflict_test_types, + second_chance + }}, second_chance, #second_chance{}}, + {3, undefined, {struct, { + name_conflict_test_types, + 'NOW_EAT_THIS' + }}, 'NOW_EAT_THIS', #'NOW_EAT_THIS'{}}, + {4, undefined, {struct, { + name_conflict_test_types, + 'TheEdgeCase' + }}, 'TheEdgeCase', #'TheEdgeCase'{}}, + {5, undefined, {struct, { + name_conflict_test_types, + 'Tricky_' + }}, 'Tricky_', #'Tricky_'{}}, + {6, undefined, {struct, { + name_conflict_test_types, + 'Nested' + }}, 'Nested', undefined} + ]}, + name_conflict_test_types:struct_info_ext('Nested') + )}, + {"Problem_ extended definition", ?_assertEqual( + {struct, [ + {1, undefined, bool, problem, undefined}, + {2, undefined, bool, 'Problem', undefined} + ]}, + name_conflict_test_types:struct_info_ext('Problem_') + )} + ]. + +service_info_test_() -> + [ + {"event params", ?_assertEqual( + {struct, [{1, {struct, {name_conflict_test_types, partial}}}]}, + extern_thrift:function_info(event, params_type) + )}, + {"event reply", ?_assertEqual( + {struct, {name_conflict_test_types, delegate}}, + extern_thrift:function_info(event, reply_type) + )}, + {"event exceptions", ?_assertEqual( + {struct, []}, + extern_thrift:function_info(event, exceptions) + )}, + {"Foo params", ?_assertEqual( + {struct, [{1, {struct, {name_conflict_test_types, 'Nested'}}}]}, + extern_thrift:function_info('Foo', params_type) + )}, + {"Foo reply", ?_assertEqual( + {struct, []}, + extern_thrift:function_info('Foo', reply_type) + )}, + {"Foo exceptions", ?_assertEqual( + {struct, [{1, {struct, {name_conflict_test_types, 'Problem_'}}}]}, + extern_thrift:function_info('Foo', exceptions) + )} + ]. diff --git a/src/jaegertracing/thrift/lib/erl/test/stress_server.erl b/src/jaegertracing/thrift/lib/erl/test/stress_server.erl new file mode 100644 index 000000000..35fff0693 --- /dev/null +++ b/src/jaegertracing/thrift/lib/erl/test/stress_server.erl @@ -0,0 +1,64 @@ +%% +%% 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. +%% + +-module(stress_server). + + +-export([start_link/1, + + handle_function/2, + + echoVoid/0, + echoByte/1, + echoI32/1, + echoI64/1, + echoString/1, + echoList/1, + echoSet/1, + echoMap/1 + ]). + +start_link(Port) -> + thrift_server:start_link(Port, service_thrift, ?MODULE). + + +handle_function(Function, Args) -> + case apply(?MODULE, Function, tuple_to_list(Args)) of + ok -> + ok; + Else -> {reply, Else} + end. + + +echoVoid() -> + ok. +echoByte(X) -> + X. +echoI32(X) -> + X. +echoI64(X) -> + X. +echoString(X) -> + X. +echoList(X) -> + X. +echoSet(X) -> + X. +echoMap(X) -> + X. diff --git a/src/jaegertracing/thrift/lib/erl/test/test_const.erl b/src/jaegertracing/thrift/lib/erl/test/test_const.erl new file mode 100644 index 000000000..627777baa --- /dev/null +++ b/src/jaegertracing/thrift/lib/erl/test/test_const.erl @@ -0,0 +1,54 @@ +%% +%% 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. +%% + +-module(test_const). + +-ifdef(TEST). +-include_lib("eunit/include/eunit.hrl"). + +-include("gen-erl/constants_demo_types.hrl"). + +namespace_test() -> + %% Verify that records produced by ConstantsDemo.thrift have the right namespace. + io:format(user, "in namespace_test()\n", []), + {struct, _} = constants_demo_types:struct_info('consts_thing'), + {struct, _} = constants_demo_types:struct_info('consts_Blah'), + ok. + +const_map_test() -> + ?assertEqual(233, constants_demo_constants:gen_map(35532)), + ?assertError(function_clause, constants_demo_constants:gen_map(0)), + + ?assertEqual(853, constants_demo_constants:gen_map(43523, default)), + ?assertEqual(default, constants_demo_constants:gen_map(10110, default)), + + ?assertEqual(98325, constants_demo_constants:gen_map2("lkjsdf")), + ?assertError(function_clause, constants_demo_constants:gen_map2("nonexist")), + + ?assertEqual(233, constants_demo_constants:gen_map2("hello", 321)), + ?assertEqual(321, constants_demo_constants:gen_map2("goodbye", 321)). + +const_list_test() -> + ?assertEqual(23598352, constants_demo_constants:gen_list(2)), + ?assertError(function_clause, constants_demo_constants:gen_list(0)), + + ?assertEqual(3253523, constants_demo_constants:gen_list(3, default)), + ?assertEqual(default, constants_demo_constants:gen_list(10, default)). + +-endif. %% TEST diff --git a/src/jaegertracing/thrift/lib/erl/test/test_disklog.erl b/src/jaegertracing/thrift/lib/erl/test/test_disklog.erl new file mode 100644 index 000000000..dcb6fc1b9 --- /dev/null +++ b/src/jaegertracing/thrift/lib/erl/test/test_disklog.erl @@ -0,0 +1,99 @@ +%% +%% 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. +%% + +-module(test_disklog). + +-ifdef(TEST). +-include_lib("eunit/include/eunit.hrl"). + +disklog_test() -> + {ok, TransportFactory} = + thrift_disk_log_transport:new_transport_factory( + test_disklog, + [{file, "./test_log"}, + {size, {1024*1024, 10}}]), + {ok, ProtocolFactory} = + thrift_binary_protocol:new_protocol_factory( TransportFactory, []), + {ok, Proto} = ProtocolFactory(), + {ok, Client0} = thrift_client:new(Proto, thrift_test_thrift), + + io:format("Client started~n"), + + % We have to make oneway calls into this client only since otherwise it + % will try to read from the disklog and go boom. + {Client1, {ok, ok}} = thrift_client:call(Client0, testOneway, [16#deadbeef]), + io:format("Call written~n"), + + % Use the send_call method to write a non-oneway call into the log + {Client2, ok} = + thrift_client:send_call(Client1, testString, [<<"hello world">>]), + io:format("Non-oneway call sent~n"), + + {_Client3, ok} = thrift_client:close(Client2), + io:format("Client closed~n"), + + lists:foreach(fun(File) -> file:delete(File) end, [ + "./test_log.1", + "./test_log.idx", + "./test_log.siz" + ]), + io:format("Cleaning up test files~n"), + + ok. + +disklog_base64_test() -> + {ok, TransportFactory} = + thrift_disk_log_transport:new_transport_factory( + test_disklog, + [{file, "./test_b64_log"}, + {size, {1024*1024, 10}}]), + {ok, B64Factory} = + thrift_base64_transport:new_transport_factory(TransportFactory), + {ok, BufFactory} = + thrift_buffered_transport:new_transport_factory(B64Factory), + {ok, ProtocolFactory} = + thrift_binary_protocol:new_protocol_factory(BufFactory, []), + {ok, Proto} = ProtocolFactory(), + {ok, Client0} = thrift_client:new(Proto, thrift_test_thrift), + + io:format("Client started~n"), + + % We have to make oneway calls into this client only since otherwise + % it will try to read from the disklog and go boom. + {Client1, {ok, ok}} = thrift_client:call(Client0, testOneway, [16#deadbeef]), + io:format("Call written~n"), + + % Use the send_call method to write a non-oneway call into the log + {Client2, ok} = + thrift_client:send_call(Client1, testString, [<<"hello world">>]), + io:format("Non-oneway call sent~n"), + + {_Client3, ok} = thrift_client:close(Client2), + io:format("Client closed~n"), + + lists:foreach(fun(File) -> file:delete(File) end, [ + "./test_b64_log.1", + "./test_b64_log.idx", + "./test_b64_log.siz" + ]), + io:format("Cleaning up test files~n"), + + ok. + +-endif. diff --git a/src/jaegertracing/thrift/lib/erl/test/test_omit.erl b/src/jaegertracing/thrift/lib/erl/test/test_omit.erl new file mode 100644 index 000000000..80841e291 --- /dev/null +++ b/src/jaegertracing/thrift/lib/erl/test/test_omit.erl @@ -0,0 +1,79 @@ +-module(test_omit). + +-include("gen-erl/thrift_omit_with_types.hrl"). + +-ifdef(TEST). +-include_lib("eunit/include/eunit.hrl"). + +omit_struct1_test() -> + %% In this test, the field that is deleted is a basic type (an i32). + A = #test1{one = 1, three = 3}, + B = #test1{one = 1, two = 2, three = 3}, + {ok, Transport} = thrift_membuffer_transport:new(), + {ok, P0} = thrift_binary_protocol:new(Transport), + + {P1, ok} = thrift_protocol:write(P0, {{struct, {thrift_omit_with_types, element(1, A)}}, A}), + {P2, {ok, O0}} = thrift_protocol:read(P1, {struct, {thrift_omit_without_types, element(1, A)}}), + ?assertEqual(element(1, A), element(1, O0)), + ?assertEqual(element(2, A), element(2, O0)), + ?assertEqual(element(4, A), element(3, O0)), + + {P3, ok} = thrift_protocol:write(P2, {{struct, {thrift_omit_with_types, element(1, B)}}, B}), + {_P4, {ok, O1}} = thrift_protocol:read(P3, {struct, {thrift_omit_without_types, element(1, A)}}), + ?assertEqual(element(1, A), element(1, O1)), + ?assertEqual(element(2, A), element(2, O1)), + ?assertEqual(element(4, A), element(3, O1)), + + ok. + +omit_struct2_test() -> + %% In this test, the field that is deleted is a struct. + A = #test2{one = 1, two = #test2{one = 10, three = 30}, three = 3}, + B = #test2{one = 1, two = #test2{one = 10, two = #test2{one = 100}, three = 30}, three = 3}, + + {ok, Transport} = thrift_membuffer_transport:new(), + {ok, P0} = thrift_binary_protocol:new(Transport), + + {P1, ok} = thrift_protocol:write(P0, {{struct, {thrift_omit_with_types, element(1, A)}}, A}), + {P2, {ok, O0}} = thrift_protocol:read(P1, {struct, {thrift_omit_without_types, element(1, A)}}), + ?assertEqual(element(1, A), element(1, O0)), + ?assertEqual(element(2, A), element(2, O0)), + ?assertEqual(element(4, A), element(3, O0)), + + {P3, ok} = thrift_protocol:write(P2, {{struct, {thrift_omit_with_types, element(1, B)}}, B}), + {_P4, {ok, O1}} = thrift_protocol:read(P3, {struct, {thrift_omit_without_types, element(1, A)}}), + ?assertEqual(element(1, A), element(1, O1)), + ?assertEqual(element(2, A), element(2, O1)), + ?assertEqual(element(4, A), element(3, O1)), + + ok. + +omit_list_test() -> + %% In this test, the field that is deleted is a list. + A = #test1{one = 1, two = 2, three = 3}, + B = #test3{one = 1, two = [ A ]}, + + {ok, Transport} = thrift_membuffer_transport:new(), + {ok, P0} = thrift_binary_protocol:new(Transport), + + {P1, ok} = thrift_protocol:write(P0, {{struct, {thrift_omit_with_types, element(1, B)}}, B}), + {_P2, {ok, O0}} = thrift_protocol:read(P1, {struct, {thrift_omit_without_types, element(1, B)}}), + ?assertEqual(element(2, B), element(2, O0)), + + ok. + +omit_map_test() -> + %% In this test, the field that is deleted is a map. + A = #test1{one = 1, two = 2, three = 3}, + B = #test4{one = 1, two = dict:from_list([ {2, A} ])}, + + {ok, Transport} = thrift_membuffer_transport:new(), + {ok, P0} = thrift_binary_protocol:new(Transport), + + {P1, ok} = thrift_protocol:write(P0, {{struct, {thrift_omit_with_types, element(1, B)}}, B}), + {_P2, {ok, O0}} = thrift_protocol:read(P1, {struct, {thrift_omit_without_types, element(1, B)}}), + ?assertEqual(element(2, B), element(2, O0)), + + ok. + +-endif. %% TEST diff --git a/src/jaegertracing/thrift/lib/erl/test/test_rendered_double_constants.erl b/src/jaegertracing/thrift/lib/erl/test/test_rendered_double_constants.erl new file mode 100644 index 000000000..87fce8130 --- /dev/null +++ b/src/jaegertracing/thrift/lib/erl/test/test_rendered_double_constants.erl @@ -0,0 +1,68 @@ +%% +%% 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. +%% + +-module(test_rendered_double_constants). + +-ifdef(TEST). +-include_lib("eunit/include/eunit.hrl"). + +-include("gen-erl/double_constants_test_constants.hrl"). + +-define(EPSILON, 0.0000001). + +rendered_double_constants_test() -> + ?assert(abs(1.0 - ?DOUBLE_CONSTANTS_TEST_DOUBLE_ASSIGNED_TO_INT_CONSTANT_TEST) =< ?EPSILON), + ?assert(abs(-100.0 - ?DOUBLE_CONSTANTS_TEST_DOUBLE_ASSIGNED_TO_NEGATIVE_INT_CONSTANT_TEST) =< ?EPSILON), + ?assert(abs(9223372036854775807.0 - ?DOUBLE_CONSTANTS_TEST_DOUBLE_ASSIGNED_TO_LARGEST_INT_CONSTANT_TEST) =< ?EPSILON), + ?assert(abs(-9223372036854775807.0 - ?DOUBLE_CONSTANTS_TEST_DOUBLE_ASSIGNED_TO_SMALLEST_INT_CONSTANT_TEST) =< ?EPSILON), + ?assert(abs(3.14159265359 - ?DOUBLE_CONSTANTS_TEST_DOUBLE_ASSIGNED_TO_DOUBLE_WITH_MANY_DECIMALS_TEST) =< ?EPSILON), + ?assert(abs(1000000.1 - ?DOUBLE_CONSTANTS_TEST_DOUBLE_ASSIGNED_TO_FRACTIONAL_DOUBLE_TEST) =< ?EPSILON), + ?assert(abs(-1000000.1 - ?DOUBLE_CONSTANTS_TEST_DOUBLE_ASSIGNED_TO_NEGATIVE_FRACTIONAL_DOUBLE_TEST) =< ?EPSILON), + ?assert(abs(1.7e+308 - ?DOUBLE_CONSTANTS_TEST_DOUBLE_ASSIGNED_TO_LARGE_DOUBLE_TEST) =< ?EPSILON), + ?assert(abs(9223372036854775816.43 - ?DOUBLE_CONSTANTS_TEST_DOUBLE_ASSIGNED_TO_LARGE_FRACTIONAL_DOUBLE_TEST) =< ?EPSILON), + ?assert(abs(-1.7e+308 - ?DOUBLE_CONSTANTS_TEST_DOUBLE_ASSIGNED_TO_SMALL_DOUBLE_TEST) =< ?EPSILON), + ?assert(abs(-9223372036854775816.43 - ?DOUBLE_CONSTANTS_TEST_DOUBLE_ASSIGNED_TO_NEGATIVE_BUT_LARGE_FRACTIONAL_DOUBLE_TEST) =< ?EPSILON), + ?assert(is_float(?DOUBLE_CONSTANTS_TEST_DOUBLE_ASSIGNED_TO_INT_CONSTANT_TEST)), + ?assert(is_float(?DOUBLE_CONSTANTS_TEST_DOUBLE_ASSIGNED_TO_NEGATIVE_INT_CONSTANT_TEST)), + ?assert(is_float(?DOUBLE_CONSTANTS_TEST_DOUBLE_ASSIGNED_TO_LARGEST_INT_CONSTANT_TEST)), + ?assert(is_float(?DOUBLE_CONSTANTS_TEST_DOUBLE_ASSIGNED_TO_SMALLEST_INT_CONSTANT_TEST)), + ?assert(is_float(?DOUBLE_CONSTANTS_TEST_DOUBLE_ASSIGNED_TO_DOUBLE_WITH_MANY_DECIMALS_TEST)), + ?assert(is_float(?DOUBLE_CONSTANTS_TEST_DOUBLE_ASSIGNED_TO_FRACTIONAL_DOUBLE_TEST)), + ?assert(is_float(?DOUBLE_CONSTANTS_TEST_DOUBLE_ASSIGNED_TO_NEGATIVE_FRACTIONAL_DOUBLE_TEST)), + ?assert(is_float(?DOUBLE_CONSTANTS_TEST_DOUBLE_ASSIGNED_TO_LARGE_DOUBLE_TEST)), + ?assert(is_float(?DOUBLE_CONSTANTS_TEST_DOUBLE_ASSIGNED_TO_LARGE_FRACTIONAL_DOUBLE_TEST)), + ?assert(is_float(?DOUBLE_CONSTANTS_TEST_DOUBLE_ASSIGNED_TO_SMALL_DOUBLE_TEST)), + ?assert(is_float(?DOUBLE_CONSTANTS_TEST_DOUBLE_ASSIGNED_TO_NEGATIVE_BUT_LARGE_FRACTIONAL_DOUBLE_TEST)). + +rendered_double_list_test() -> + ?assertEqual(12, length(?DOUBLE_CONSTANTS_TEST_DOUBLE_LIST_TEST)), + ?assert(abs(1.0 - lists:nth(1, ?DOUBLE_CONSTANTS_TEST_DOUBLE_LIST_TEST)) =< ?EPSILON), + ?assert(abs(-100.0 - lists:nth(2, ?DOUBLE_CONSTANTS_TEST_DOUBLE_LIST_TEST)) =< ?EPSILON), + ?assert(abs(100.0 - lists:nth(3, ?DOUBLE_CONSTANTS_TEST_DOUBLE_LIST_TEST)) =< ?EPSILON), + ?assert(abs(9223372036854775807.0 - lists:nth(4, ?DOUBLE_CONSTANTS_TEST_DOUBLE_LIST_TEST)) =< ?EPSILON), + ?assert(abs(-9223372036854775807.0 - lists:nth(5, ?DOUBLE_CONSTANTS_TEST_DOUBLE_LIST_TEST)) =< ?EPSILON), + ?assert(abs(3.14159265359 - lists:nth(6, ?DOUBLE_CONSTANTS_TEST_DOUBLE_LIST_TEST)) =< ?EPSILON), + ?assert(abs(1000000.1 - lists:nth(7, ?DOUBLE_CONSTANTS_TEST_DOUBLE_LIST_TEST)) =< ?EPSILON), + ?assert(abs(-1000000.1 - lists:nth(8, ?DOUBLE_CONSTANTS_TEST_DOUBLE_LIST_TEST)) =< ?EPSILON), + ?assert(abs(1.7e+308 - lists:nth(9, ?DOUBLE_CONSTANTS_TEST_DOUBLE_LIST_TEST)) =< ?EPSILON), + ?assert(abs(-1.7e+308 - lists:nth(10, ?DOUBLE_CONSTANTS_TEST_DOUBLE_LIST_TEST)) =< ?EPSILON), + ?assert(abs(9223372036854775816.43 - lists:nth(11, ?DOUBLE_CONSTANTS_TEST_DOUBLE_LIST_TEST)) =< ?EPSILON), + ?assert(abs(-9223372036854775816.43 - lists:nth(12, ?DOUBLE_CONSTANTS_TEST_DOUBLE_LIST_TEST)) =< ?EPSILON). + +-endif. %% TEST \ No newline at end of file diff --git a/src/jaegertracing/thrift/lib/erl/test/test_thrift_1151.erl b/src/jaegertracing/thrift/lib/erl/test/test_thrift_1151.erl new file mode 100644 index 000000000..f4a910e7d --- /dev/null +++ b/src/jaegertracing/thrift/lib/erl/test/test_thrift_1151.erl @@ -0,0 +1,34 @@ +-module(test_thrift_1151). + +-include("gen-erl/thrift1151_types.hrl"). + +-ifdef(TEST). +-include_lib("eunit/include/eunit.hrl"). + +unmatched_struct_test() -> + S1 = #'StructC'{x=#'StructB'{x=1}}, + {ok, Transport} = thrift_memory_buffer:new(), + {ok, Protocol} = thrift_binary_protocol:new(Transport), + ?assertException( + error, + struct_unmatched, + thrift_protocol:write( + Protocol, + {{struct, element(2, thrift1151_types:struct_info('StructC'))}, S1} + ) + ). + +badarg_test() -> + S2 = #'StructC'{x=#'StructA'{x="1"}}, + {ok, Transport} = thrift_memory_buffer:new(), + {ok, Protocol} = thrift_binary_protocol:new(Transport), + ?assertException( + error, + badarg, + thrift_protocol:write( + Protocol, + {{struct, element(2, thrift1151_types:struct_info('StructC'))}, S2} + ) + ). + +-endif. diff --git a/src/jaegertracing/thrift/lib/erl/test/test_thrift_3214.erl b/src/jaegertracing/thrift/lib/erl/test/test_thrift_3214.erl new file mode 100644 index 000000000..0f9544bef --- /dev/null +++ b/src/jaegertracing/thrift/lib/erl/test/test_thrift_3214.erl @@ -0,0 +1,60 @@ +%% +%% 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. +%% + +-module(test_thrift_3214). +-compile(export_all). + +-include("gen-erl/thrift3214_types.hrl"). + +-ifdef(TEST). +-ifndef(otp16_or_less). +-include_lib("eunit/include/eunit.hrl"). + +record_generation_test_() -> + [ + {"StringMap record", ?_assertMatch( + {'StringMap', _}, + #'StringMap'{data=#{50 => "foo"}} + )}, + {"StringMap record defaults", ?_assertEqual( + {'StringMap', #{1 => "a", 2 => "b"}}, + #'StringMap'{} + )}, + {"StringMap record dict from list", ?_assertNotEqual( + {'StringMap', dict:from_list([{1, "a"}, {2, "b"}])}, + #'StringMap'{} + )}, + {"StringMap record map from list", ?_assertEqual( + {'StringMap', maps:from_list([{1, "a"}, {2, "b"}])}, + #'StringMap'{} + )} + ]. + +struct_info_test_() -> + [ + {"StringMap extended definition", ?_assertEqual( + {struct, [ + {1, undefined, {map, i32, string}, 'data', #{1 => "a", 2 => "b"}} + ]}, + thrift3214_types:struct_info_ext('StringMap') + )} + ]. + +-endif. +-endif. diff --git a/src/jaegertracing/thrift/lib/erl/test/test_thrift_buffered_transport.erl b/src/jaegertracing/thrift/lib/erl/test/test_thrift_buffered_transport.erl new file mode 100644 index 000000000..8519e82a1 --- /dev/null +++ b/src/jaegertracing/thrift/lib/erl/test/test_thrift_buffered_transport.erl @@ -0,0 +1,359 @@ +%% +%% 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. +%% + +-module(test_thrift_buffered_transport). +-include_lib("eunit/include/eunit.hrl"). + + +new(Transport) -> thrift_buffered_transport:new(Transport). + +new_test_() -> + [ + {"new buffered membuffer", ?_assertMatch( + {ok, {t_transport, thrift_buffered_transport, {t_buffered, + {t_transport, thrift_membuffer_transport, {t_membuffer, []}}, + [] + }}}, + new({t_transport, thrift_membuffer_transport, {t_membuffer, []}}) + )} + ]. + + +read(Frame, Bytes) -> thrift_buffered_transport:read(Frame, Bytes). + +read_test_() -> + [ + {"read zero bytes from an empty buffered membuffer", ?_assertMatch( + { + {t_buffered, + {t_transport, thrift_membuffer_transport, {t_membuffer, <<>>}}, + [] + }, + {ok, <<>>} + }, + read( + {t_buffered, + {t_transport, thrift_membuffer_transport, {t_membuffer, <<>>}}, + [] + }, + 0 + ) + )}, + {"read 1 byte from an empty buffered membuffer", ?_assertMatch( + {_, {ok, <<>>}}, + read( + {t_buffered, + {t_transport, thrift_membuffer_transport, {t_membuffer, <<>>}}, + [] + }, + 1 + ) + )}, + {"read zero bytes from nonempty buffered membuffer", ?_assertMatch( + { + {t_buffered, + {t_transport, thrift_membuffer_transport, {t_membuffer, + <<"hallo world">> + }}, + [] + }, + {ok, <<>>} + }, + read( + {t_buffered, + {t_transport, thrift_membuffer_transport, {t_membuffer, + <<"hallo world">> + }}, + [] + }, + 0 + ) + )}, + {"read 1 byte from nonempty buffered membuffer", ?_assertMatch( + { + {t_buffered, + {t_transport, thrift_membuffer_transport, {t_membuffer, <<"allo world">>}}, + [] + }, + {ok, <<"h">>} + }, + read( + {t_buffered, + {t_transport, thrift_membuffer_transport, {t_membuffer, <<"hallo world">>}}, + [] + }, + 1 + ) + )}, + {"read 1 byte from nonempty buffer", ?_assertMatch( + { + {t_buffered, + {t_transport, thrift_membuffer_transport, {t_membuffer, <<"allo world">>}}, + [] + }, + {ok, <<"h">>} + }, + read( + {t_buffered, + {t_transport, thrift_membuffer_transport, {t_membuffer, <<"hallo world">>}}, + [] + }, + 1 + ) + )}, + {"read a zillion bytes from nonempty buffered membuffer", ?_assertMatch( + { + {t_buffered, + {t_transport, thrift_membuffer_transport, {t_membuffer, <<>>}}, + [] + }, + {ok, <<"hallo world">>} + }, + read( + {t_buffered, + {t_transport, thrift_membuffer_transport, {t_membuffer, <<"hallo world">>}}, + [] + }, + 65536 + ) + )} + ]. + + +read_exact(Frame, Bytes) -> thrift_buffered_transport:read_exact(Frame, Bytes). + +read_exact_test_() -> + [ + {"read exactly zero bytes from an empty buffered membuffer", ?_assertMatch( + { + {t_buffered, + {t_transport, thrift_membuffer_transport, {t_membuffer, <<>>}}, + [] + }, + {ok, <<>>} + }, + read_exact( + {t_buffered, + {t_transport, thrift_membuffer_transport, {t_membuffer, <<>>}}, + [] + }, + 0 + ) + )}, + {"read exactly 1 byte from an empty buffered membuffer", ?_assertMatch( + {_, {error, eof}}, + read_exact( + {t_buffered, + {t_transport, thrift_membuffer_transport, {t_membuffer, <<>>}}, + [] + }, + 1 + ) + )}, + {"read exactly zero bytes from nonempty buffered membuffer", ?_assertMatch( + { + {t_buffered, + {t_transport, thrift_membuffer_transport, {t_membuffer, <<"hallo world">>}}, + [] + }, + {ok, <<>>} + }, + read_exact( + {t_buffered, + {t_transport, thrift_membuffer_transport, {t_membuffer, <<"hallo world">>}}, + [] + }, + 0 + ) + )}, + {"read exactly 1 byte from nonempty buffered membuffer", ?_assertMatch( + { + {t_buffered, + {t_transport, thrift_membuffer_transport, {t_membuffer, <<"allo world">>}}, + [] + }, + {ok, <<"h">>} + }, + read_exact( + {t_buffered, + {t_transport, thrift_membuffer_transport, {t_membuffer, + <<"hallo world">> + }}, + [] + }, + 1 + ) + )}, + {"read exactly 1 byte from nonempty buffer", ?_assertMatch( + { + {t_buffered, + {t_transport, thrift_membuffer_transport, {t_membuffer, <<"allo world">>}}, + [] + }, + {ok, <<"h">>} + }, + read_exact( + {t_buffered, + {t_transport, thrift_membuffer_transport, {t_membuffer, <<"hallo world">>}}, + [] + }, + 1 + ) + )}, + {"read exactly a zillion bytes from nonempty buffered membuffer", ?_assertMatch( + { + {t_buffered, + {t_transport, thrift_membuffer_transport, {t_membuffer, <<"hallo world">>}}, + [] + }, + {error, eof} + }, + read_exact( + {t_buffered, + {t_transport, thrift_membuffer_transport, {t_membuffer, + <<"hallo world">> + }}, + [] + }, + 65536 + ) + )} + ]. + + +write(Framed, Data) -> thrift_buffered_transport:write(Framed, Data). + +write_test_() -> + [ + {"write empty list to empty buffered membuffer", ?_assertMatch( + { + {t_buffered, + {t_transport, thrift_membuffer_transport, {t_membuffer, <<>>}}, + [[], []] + }, + ok + }, + write( + {t_buffered, + {t_transport, thrift_membuffer_transport, {t_membuffer, <<>>}}, + [] + }, + [] + ) + )}, + {"write empty list to nonempty buffered membuffer", ?_assertMatch( + { + {t_buffered, + {t_transport, thrift_membuffer_transport, {t_membuffer, <<>>}}, + [["hallo world"], []] + }, + ok + }, + write( + {t_buffered, + {t_transport, thrift_membuffer_transport, {t_membuffer, <<>>}}, + ["hallo world"] + }, + [] + ) + )}, + {"write empty binary to empty buffered membuffer", ?_assertMatch( + { + {t_buffered, + {t_transport, thrift_membuffer_transport, {t_membuffer, <<>>}}, + [[], <<>>] + }, + ok + }, + write( + {t_buffered, + {t_transport, thrift_membuffer_transport, {t_membuffer, <<>>}}, + [] + }, + <<>> + ) + )}, + {"write empty binary to nonempty buffered membuffer", ?_assertMatch( + { + {t_buffered, + {t_transport, thrift_membuffer_transport, {t_membuffer, <<>>}}, + [["hallo world"], <<>>] + }, + ok + }, + write( + {t_buffered, + {t_transport, thrift_membuffer_transport, {t_membuffer, <<>>}}, + ["hallo world"] + }, + <<>> + ) + )} + ]. + + +flush(Transport) -> thrift_buffered_transport:flush(Transport). + +flush_test_() -> + [ + {"flush empty buffered membuffer", ?_assertMatch( + {{t_buffered, + {t_transport, thrift_membuffer_transport, {t_membuffer, <<>>}}, + [] + }, + ok + }, + flush({t_buffered, + {t_transport, thrift_membuffer_transport, {t_membuffer, <<>>}}, + [] + }) + )}, + {"flush nonempty buffered membuffer", ?_assertMatch( + {{t_buffered, + {t_transport, thrift_membuffer_transport, {t_membuffer, + [<<>>, <<"hallo world">>] + }}, + [] + }, + ok + }, + flush({t_buffered, + {t_transport, thrift_membuffer_transport, {t_membuffer, <<>>}}, + <<"hallo world">> + }) + )} + ]. + + +close(Transport) -> thrift_buffered_transport:close(Transport). + +close_test_() -> + {"close buffered membuffer", ?_assertMatch( + {{t_buffered, + {t_transport, thrift_membuffer_transport, {t_membuffer, <<>>}}, + [] + }, + ok + }, + close({t_buffered, + {t_transport, thrift_membuffer_transport, {t_membuffer, <<>>}}, + [] + }) + )}. + diff --git a/src/jaegertracing/thrift/lib/erl/test/test_thrift_compact_protocol.erl b/src/jaegertracing/thrift/lib/erl/test/test_thrift_compact_protocol.erl new file mode 100644 index 000000000..5da78c612 --- /dev/null +++ b/src/jaegertracing/thrift/lib/erl/test/test_thrift_compact_protocol.erl @@ -0,0 +1,219 @@ +%% +%% 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. +%% + +-module(test_thrift_compact_protocol). +-include_lib("eunit/include/eunit.hrl"). +-include("thrift_constants.hrl"). +-include("thrift_protocol.hrl"). + + +new(Transport) -> thrift_compact_protocol:new(Transport). +new() -> + {ok, Transport} = thrift_membuffer_transport:new(), + thrift_compact_protocol:new(Transport). + +new_test() -> + new(thrift_membuffer_transport:new()). + +write(This, Value) -> thrift_protocol:write(This, Value). +read(This, Type) -> thrift_protocol:read(This, Type). + +str(This0, Value0) -> + {This1, ok} = write(This0, {string, Value0}), + {This2, {ok, Value1}} = read(This1, string), + ?assertEqual(Value0, binary_to_list(Value1)), + {This2, ok}. +string_test() -> + {ok, This0} = new(), + {This1, ok} = str(This0, "aaa"), + {This2, ok} = str(This1, ""), + {This2, ok}. + +round_trip(This0, Type, Value0) -> + {This1, ok} = write(This0, {Type, Value0}), + {This2, {ok, Value1}} = read(This1, Type), + ?assertEqual(Value0, Value1), + {This2, ok}. + +bool_test() -> + {ok, This0} = new(), + {This1, ok} = round_trip(This0, bool, true), + {This2, ok} = round_trip(This1, bool, false), + {This2, ok}. + +byte(This0, Value0) -> round_trip(This0, byte, Value0). +byte_test() -> + {ok, This0} = new(), + {This1, ok} = byte(This0, 0), + {This2, ok} = byte(This1, 42), + {This3, ok} = byte(This2, -1), + {This4, ok} = byte(This3, -128), + {This4, ok}. + +i16(This0, Value0) -> round_trip(This0, i16, Value0). +i16_test() -> + {ok, This0} = new(), + {This1, ok} = i16(This0, 0), + {This2, ok} = i16(This1, 42), + {This3, ok} = i16(This2, 30000), + {This4, ok} = i16(This3, -1), + {This5, ok} = i16(This4, -128), + {This6, ok} = i16(This5, -30000), + {This6, ok}. + +i32(This0, Value0) -> round_trip(This0, i32, Value0). +i32_test() -> + {ok, This0} = new(), + {This1, ok} = i32(This0, 0), + {This2, ok} = i32(This1, 42), + {This3, ok} = i32(This2, 30000), + {This4, ok} = i32(This3, 2000000002), + {This5, ok} = i32(This4, -1), + {This6, ok} = i32(This5, -128), + {This7, ok} = i32(This6, -30000), + {This8, ok} = i32(This7, -2000000002), + {This8, ok}. + +i64(This0, Value0) -> round_trip(This0, i64, Value0). +i64_test() -> + {ok, This0} = new(), + {This1, ok} = i64(This0, 0), + {This2, ok} = i64(This1, 42), + {This3, ok} = i64(This2, 30000), + {This4, ok} = i64(This3, 2000000002), + {This5, ok} = i64(This4, 100000000000000064), + {This6, ok} = i64(This5, -1), + {This7, ok} = i64(This6, -128), + {This8, ok} = i64(This7, -30000), + {This9, ok} = i64(This8, -2000000002), + {This10, ok} = i64(This9, -100000000000000064), + {This10, ok}. + +struct_test() -> + {ok, P0} = new(), + {P1, ok} = write(P0, #protocol_message_begin{ name = "Message1", type = ?tType_I8, seqid = 3}), + {P2, ok} = write(P1, #protocol_struct_begin{}), + {P3, ok} = write(P2, #protocol_field_begin{ name = "field1", type = ?tType_I8, id = 1}), + {P4, ok} = write(P3, {byte, 42}), + {P5, ok} = write(P4, field_end), + {P6, ok} = write(P5, #protocol_field_begin{ name = "field2", type = ?tType_I8, id = 14}), + {P7, ok} = write(P6, {byte, 3}), + {P8, ok} = write(P7, field_end), + {P9, ok} = write(P8, #protocol_field_begin{ name = "field3", type = ?tType_I8, id = 42}), + {P10, ok} = write(P9, {byte, 8}), + {P11, ok} = write(P10, field_end), + {P12, ok} = write(P11, field_stop), + {P13, ok} = write(P12, struct_end), + {P14, ok} = write(P13, message_end), + + {P15, #protocol_message_begin{ name = "Message1", type = ?tType_I8, seqid = 3}} = read(P14, message_begin), + {P16, ok} = read(P15, struct_begin), + {P17, #protocol_field_begin{ type = ?tType_I8, id = 1 }} = read(P16, field_begin), + {P18, {ok, 42}} = read(P17, byte), + {P19, ok} = read(P18, field_end), + {P20, #protocol_field_begin{ type = ?tType_I8, id = 14 }} = read(P19, field_begin), + {P21, {ok, 3}} = read(P20, byte), + {P22, ok} = read(P21, field_end), + {P23, #protocol_field_begin{ type = ?tType_I8, id = 42 }} = read(P22, field_begin), + {P24, {ok, 8}} = read(P23, byte), + {P25, ok} = read(P24, field_end), + {P26, #protocol_field_begin{ type = ?tType_STOP}} = read(P25, field_begin), + {P27, ok} = read(P26, struct_end), + {P28, ok} = read(P27, message_end), + {P28, ok}. + +bool_field_test() -> + {ok, P0} = new(), + {P1, ok} = write(P0, #protocol_message_begin{ name = "Message1", type = ?tType_I8, seqid = 3}), + {P2, ok} = write(P1, #protocol_struct_begin{}), + {P3, ok} = write(P2, #protocol_field_begin{ name = "field1", type = ?tType_BOOL, id = 1}), + {P4, ok} = write(P3, {bool, true}), + {P5, ok} = write(P4, field_end), + {P6, ok} = write(P5, #protocol_field_begin{ name = "field2", type = ?tType_BOOL, id = 14}), + {P7, ok} = write(P6, {bool, false}), + {P8, ok} = write(P7, field_end), + {P9, ok} = write(P8, #protocol_field_begin{ name = "field3", type = ?tType_BOOL, id = 42}), + {P10, ok} = write(P9, {bool, true}), + {P11, ok} = write(P10, field_end), + {P12, ok} = write(P11, field_stop), + {P13, ok} = write(P12, struct_end), + {P14, ok} = write(P13, message_end), + + {P15, #protocol_message_begin{ name = "Message1", type = ?tType_I8, seqid = 3}} = read(P14, message_begin), + {P16, ok} = read(P15, struct_begin), + {P17, #protocol_field_begin{ type = ?tType_BOOL, id = 1 }} = read(P16, field_begin), + {P18, {ok, true}} = read(P17, bool), + {P19, ok} = read(P18, field_end), + {P20, #protocol_field_begin{ type = ?tType_BOOL, id = 14 }} = read(P19, field_begin), + {P21, {ok, false}} = read(P20, bool), + {P22, ok} = read(P21, field_end), + {P23, #protocol_field_begin{ type = ?tType_BOOL, id = 42 }} = read(P22, field_begin), + {P24, {ok, true}} = read(P23, bool), + {P25, ok} = read(P24, field_end), + {P26, #protocol_field_begin{ type = ?tType_STOP}} = read(P25, field_begin), + {P27, ok} = read(P26, struct_end), + {P28, ok} = read(P27, message_end), + {P28, ok}. + +nesting_test() -> + {ok, P0} = new(), + {P1, ok} = write(P0, #protocol_message_begin{ name = "Message1", type = ?tType_I8, seqid = 3}), + {P2, ok} = write(P1, #protocol_struct_begin{}), + {P3, ok} = write(P2, #protocol_field_begin{ name = "field1", type = ?tType_BOOL, id = 14}), + {P4, ok} = write(P3, {bool, true}), + {P5, ok} = write(P4, field_end), + + {P6, ok} = write(P5, #protocol_field_begin{ name = "field2", type = ?tType_STRUCT, id = 28}), + {P7, ok} = write(P6, #protocol_struct_begin{}), + {P8, ok} = write(P7, #protocol_field_begin{ name = "field2_1", type = ?tType_BOOL, id = 30000}), + {P9, ok} = write(P8, {bool, false}), + {P10, ok} = write(P9, field_end), + {P11, ok} = write(P10, field_stop), + {P12, ok} = write(P11, struct_end), + {P13, ok} = write(P12, field_end), + + {P14, ok} = write(P13, #protocol_field_begin{ name = "field3", type = ?tType_BOOL, id = 42}), + {P15, ok} = write(P14, {bool, true}), + {P16, ok} = write(P15, field_end), + {P17, ok} = write(P16, field_stop), + {P18, ok} = write(P17, struct_end), + {P19, ok} = write(P18, message_end), + + {P20, #protocol_message_begin{ name = "Message1", type = ?tType_I8, seqid = 3}} = read(P19, message_begin), + {P21, ok} = read(P20, struct_begin), + {P22, #protocol_field_begin{ type = ?tType_BOOL, id = 14 }} = read(P21, field_begin), + {P23, {ok, true}} = read(P22, bool), + {P24, ok} = read(P23, field_end), + + {P25, #protocol_field_begin{ type = ?tType_STRUCT, id = 28 }} = read(P24, field_begin), + {P26, ok} = read(P25, struct_begin), + {P27, #protocol_field_begin{ type = ?tType_BOOL, id = 30000 }} = read(P26, field_begin), + {P28, {ok, false}} = read(P27, bool), + {P29, ok} = read(P28, field_end), + {P30, #protocol_field_begin{ type = ?tType_STOP }} = read(P29, field_begin), + {P31, ok} = read(P30, struct_end), + {P32, ok} = read(P31, field_end), + + {P33, #protocol_field_begin{ type = ?tType_BOOL, id = 42 }} = read(P32, field_begin), + {P34, {ok, true}} = read(P33, bool), + {P35, ok} = read(P34, field_end), + {P36, #protocol_field_begin{ type = ?tType_STOP }} = read(P35, field_begin), + {P37, ok} = read(P36, struct_end), + {P38, ok} = read(P37, message_end), + {P38, ok}. diff --git a/src/jaegertracing/thrift/lib/erl/test/test_thrift_file_transport.erl b/src/jaegertracing/thrift/lib/erl/test/test_thrift_file_transport.erl new file mode 100644 index 000000000..3e5c1d1e4 --- /dev/null +++ b/src/jaegertracing/thrift/lib/erl/test/test_thrift_file_transport.erl @@ -0,0 +1,213 @@ +%% +%% 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. +%% + +-module(test_thrift_file_transport). +-include_lib("eunit/include/eunit.hrl"). + + +new(File) -> thrift_file_transport:new(File). +new(File, Opts) -> thrift_file_transport:new(File, Opts). + +new_test_() -> + [ + {"new file", ?_assertMatch( + {ok, {_, thrift_file_transport, {t_file, a_fake_file, true, write}}}, + new(a_fake_file) + )}, + {"new file in read mode", ?_assertMatch( + {ok, {_, thrift_file_transport, {t_file, a_fake_file, true, read}}}, + new(a_fake_file, [{mode, read}]) + )}, + {"new file in write mode", ?_assertMatch( + {ok, {_, thrift_file_transport, {t_file, a_fake_file, true, write}}}, + new(a_fake_file, [{mode, write}]) + )}, + {"new file in should_close true mode", ?_assertMatch( + {ok, {_, thrift_file_transport, {t_file, a_fake_file, true, write}}}, + new(a_fake_file, [{should_close, true}]) + )}, + {"new file in should_close false mode", ?_assertMatch( + {ok, {_, thrift_file_transport, {t_file, a_fake_file, false, write}}}, + new(a_fake_file, [{should_close, false}]) + )} + ]. + + +read(File, Bytes) -> thrift_file_transport:read(File, Bytes). + +read_test_() -> + {setup, + fun() -> + meck:new(file, [unstick, passthrough]), + meck:expect(file, read, fun(Bin, N) -> + {Result, _} = split_binary(Bin, min(iolist_size(Bin), N)), + {ok, Result} + end) + end, + fun(_) -> meck:unload(file) end, + [ + {"read zero bytes from empty file", ?_assertMatch( + {_, {ok, <<>>}}, + read({t_file, <<>>, true, read}, 0) + )}, + {"read 1 byte from empty file", ?_assertMatch( + {_, {ok, <<>>}}, + read({t_file, <<>>, true, read}, 1) + )}, + {"read zero bytes from nonempty file", ?_assertMatch( + {_, {ok, <<>>}}, + read({t_file, <<"hallo world">>, true, read}, 0) + )}, + {"read 1 byte from nonempty file", ?_assertMatch( + {_, {ok, <<"h">>}}, + read({t_file, <<"hallo world">>, true, read}, 1) + )}, + {"read a zillion bytes from nonempty file", ?_assertMatch( + {_, {ok, <<"hallo world">>}}, + read({t_file, <<"hallo world">>, true, read}, 65536) + )}, + {"read 0 byte from file in write mode", ?_assertMatch( + {_, {error, write_mode}}, + read({t_file, <<>>, true, write}, 0) + )}, + {"read 1 byte from file in write mode", ?_assertMatch( + {_, {error, write_mode}}, + read({t_file, <<>>, true, write}, 1) + )} + ] + }. + + +read_exact(File, Bytes) -> thrift_file_transport:read_exact(File, Bytes). + +read_exact_test_() -> + {setup, + fun() -> + meck:new(file, [unstick, passthrough]), + meck:expect(file, read, fun(Bin, N) -> + {Result, _} = split_binary(Bin, min(iolist_size(Bin), N)), + {ok, Result} + end) + end, + fun(_) -> meck:unload(file) end, + [ + {"read exactly zero bytes from empty file", ?_assertMatch( + {_, {ok, <<>>}}, + read_exact({t_file, <<>>, true, read}, 0) + )}, + {"read exactly 1 byte from empty file", ?_assertMatch( + {_, {error, eof}}, + read_exact({t_file, <<>>, true, read}, 1) + )}, + {"read exactly zero bytes from nonempty file", ?_assertMatch( + {_, {ok, <<>>}}, + read_exact({t_file, <<"hallo world">>, true, read}, 0) + )}, + {"read exactly 1 byte from nonempty file", ?_assertMatch( + {_, {ok, <<"h">>}}, + read_exact({t_file, <<"hallo world">>, true, read}, 1) + )}, + {"read exactly a zillion bytes from nonempty file", ?_assertMatch( + {_, {error, eof}}, + read_exact({t_file, <<"hallo world">>, true, read}, 65536) + )}, + {"read exactly 0 byte from file in write mode", ?_assertMatch( + {_, {error, write_mode}}, + read_exact({t_file, <<>>, true, write}, 0) + )}, + {"read exactly 1 byte from file in write mode", ?_assertMatch( + {_, {error, write_mode}}, + read_exact({t_file, <<>>, true, write}, 1) + )} + ] + }. + + +write(File, Data) -> thrift_file_transport:write(File, Data). + +write_test_() -> + {setup, + fun() -> + meck:new(file, [unstick, passthrough]), + meck:expect(file, write, fun(_, _) -> ok end) + end, + fun(_) -> meck:unload(file) end, + [ + {"write empty list to file", ?_assertMatch( + {{t_file, a_fake_file, true, write}, ok}, + write({t_file, a_fake_file, true, write}, []) + )}, + {"write empty binary to file", ?_assertMatch( + {{t_file, a_fake_file, true, write}, ok}, + write({t_file, a_fake_file, true, write}, <<>>) + )}, + {"write a list to file", ?_assertMatch( + {{t_file, a_fake_file, true, write}, ok}, + write({t_file, a_fake_file, true, write}, "hallo world") + )}, + {"write a binary to file", ?_assertMatch( + {{t_file, a_fake_file, true, write}, ok}, + write({t_file, a_fake_file, true, write}, <<"hallo world">>) + )}, + {"write a binary to file in read mode", ?_assertMatch( + {_, {error, read_mode}}, + write({t_file, a_fake_file, true, read}, <<"hallo world">>) + )}, + {"write a list to file in read mode", ?_assertMatch( + {_, {error, read_mode}}, + write({t_file, a_fake_file, true, read}, "hallo world") + )} + ] + }. + + +flush(Transport) -> thrift_file_transport:flush(Transport). + +flush_test_() -> + {setup, + fun() -> + meck:new(file, [unstick, passthrough]), + meck:expect(file, sync, fun(_File) -> ok end) + end, + fun(_) -> meck:unload(file) end, + [ + {"flush file", ?_assertMatch( + {{t_file, a_fake_file, true, write}, ok}, + flush({t_file, a_fake_file, true, write}) + )} + ] + }. + + +close(Transport) -> thrift_file_transport:close(Transport). + +close_test_() -> + {setup, + fun() -> + meck:new(file, [unstick, passthrough]), + meck:expect(file, close, fun(_) -> ok end) + end, + fun(_) -> meck:unload(file) end, + [ + {"close file", ?_assertMatch( + {{t_file, a_fake_file, true, write}, ok}, + close({t_file, a_fake_file, true, write}) + )} + ] + }. \ No newline at end of file diff --git a/src/jaegertracing/thrift/lib/erl/test/test_thrift_framed_transport.erl b/src/jaegertracing/thrift/lib/erl/test/test_thrift_framed_transport.erl new file mode 100644 index 000000000..8a538a53a --- /dev/null +++ b/src/jaegertracing/thrift/lib/erl/test/test_thrift_framed_transport.erl @@ -0,0 +1,404 @@ +%% +%% 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. +%% + +-module(test_thrift_framed_transport). +-include_lib("eunit/include/eunit.hrl"). + + +new(Transport) -> thrift_framed_transport:new(Transport). + +new_test_() -> + [ + {"new framed membuffer", ?_assertMatch( + {ok, {t_transport, thrift_framed_transport, {t_framed, + {t_transport, thrift_membuffer_transport, {t_membuffer, []}}, + [], + [] + }}}, + new({t_transport, thrift_membuffer_transport, {t_membuffer, []}}) + )} + ]. + + +read(Frame, Bytes) -> thrift_framed_transport:read(Frame, Bytes). + +read_test_() -> + [ + {"read zero bytes from an empty framed membuffer", ?_assertMatch( + { + {t_framed, + {t_transport, thrift_membuffer_transport, {t_membuffer, <<>>}}, + [], + [] + }, + {ok, <<>>} + }, + read( + {t_framed, + {t_transport, thrift_membuffer_transport, {t_membuffer, <<>>}}, + [], + [] + }, + 0 + ) + )}, + {"read 1 byte from an empty framed membuffer", ?_assertMatch( + {_, {error, eof}}, + read( + {t_framed, + {t_transport, thrift_membuffer_transport, {t_membuffer, <<>>}}, + [], + [] + }, + 1 + ) + )}, + {"read zero bytes from nonempty framed membuffer", ?_assertMatch( + { + {t_framed, + {t_transport, thrift_membuffer_transport, {t_membuffer, + <<0, 0, 0, 11, "hallo world">> + }}, + [], + [] + }, + {ok, <<>>} + }, + read( + {t_framed, + {t_transport, thrift_membuffer_transport, {t_membuffer, + <<0, 0, 0, 11, "hallo world">> + }}, + [], + [] + }, + 0 + ) + )}, + {"read 1 byte from nonempty framed membuffer", ?_assertMatch( + { + {t_framed, + {t_transport, thrift_membuffer_transport, {t_membuffer, <<>>}}, + <<"allo world">>, + [] + }, + {ok, <<"h">>} + }, + read( + {t_framed, + {t_transport, thrift_membuffer_transport, {t_membuffer, + <<0, 0, 0, 11, "hallo world">> + }}, + [], + [] + }, + 1 + ) + )}, + {"read 1 byte from nonempty buffer", ?_assertMatch( + { + {t_framed, + {t_transport, thrift_membuffer_transport, {t_membuffer, <<>>}}, + <<"allo world">>, + [] + }, + {ok, <<"h">>} + }, + read( + {t_framed, + {t_transport, thrift_membuffer_transport, {t_membuffer, <<>>}}, + <<"hallo world">>, + [] + }, + 1 + ) + )}, + {"read a zillion bytes from nonempty framed membuffer", ?_assertMatch( + { + {t_framed, + {t_transport, thrift_membuffer_transport, {t_membuffer, <<>>}}, + <<>>, + [] + }, + {ok, <<"hallo world">>} + }, + read( + {t_framed, + {t_transport, thrift_membuffer_transport, {t_membuffer, + <<0, 0, 0, 11, "hallo world">> + }}, + [], + [] + }, + 65536 + ) + )} + ]. + + +read_exact(Frame, Bytes) -> thrift_framed_transport:read_exact(Frame, Bytes). + +read_exact_test_() -> + [ + {"read exactly zero bytes from an empty framed membuffer", ?_assertMatch( + { + {t_framed, + {t_transport, thrift_membuffer_transport, {t_membuffer, <<>>}}, + <<>>, + [] + }, + {ok, <<>>} + }, + read_exact( + {t_framed, + {t_transport, thrift_membuffer_transport, {t_membuffer, <<>>}}, + [], + [] + }, + 0 + ) + )}, + {"read exactly 1 byte from an empty framed membuffer", ?_assertMatch( + {_, {error, eof}}, + read_exact( + {t_framed, + {t_transport, thrift_membuffer_transport, {t_membuffer, <<>>}}, + [], + [] + }, + 1 + ) + )}, + {"read exactly zero bytes from nonempty framed membuffer", ?_assertMatch( + { + {t_framed, + {t_transport, thrift_membuffer_transport, {t_membuffer, + <<0, 0, 0, 11, "hallo world">> + }}, + <<>>, + [] + }, + {ok, <<>>} + }, + read_exact( + {t_framed, + {t_transport, thrift_membuffer_transport, {t_membuffer, + <<0, 0, 0, 11, "hallo world">> + }}, + [], + [] + }, + 0 + ) + )}, + {"read exactly 1 byte from nonempty framed membuffer", ?_assertMatch( + { + {t_framed, + {t_transport, thrift_membuffer_transport, {t_membuffer, <<>>}}, + <<"allo world">>, + [] + }, + {ok, <<"h">>} + }, + read_exact( + {t_framed, + {t_transport, thrift_membuffer_transport, {t_membuffer, + <<0, 0, 0, 11, "hallo world">> + }}, + [], + [] + }, + 1 + ) + )}, + {"read exactly 1 byte from nonempty buffer", ?_assertMatch( + { + {t_framed, + {t_transport, thrift_membuffer_transport, {t_membuffer, <<>>}}, + <<"allo world">>, + [] + }, + {ok, <<"h">>} + }, + read_exact( + {t_framed, + {t_transport, thrift_membuffer_transport, {t_membuffer, <<>>}}, + <<"hallo world">>, + [] + }, + 1 + ) + )}, + {"read exactly a zillion bytes from nonempty framed membuffer", ?_assertMatch( + { + {t_framed, + {t_transport, thrift_membuffer_transport, {t_membuffer, <<>>}}, + [[],<<"hallo world">>], + [] + }, + {error, eof} + }, + read_exact( + {t_framed, + {t_transport, thrift_membuffer_transport, {t_membuffer, + <<0, 0, 0, 11, "hallo world">> + }}, + [], + [] + }, + 65536 + ) + )} + ]. + + +write(Framed, Data) -> thrift_framed_transport:write(Framed, Data). + +write_test_() -> + [ + {"write empty list to empty framed membuffer", ?_assertMatch( + { + {t_framed, + {t_transport, thrift_membuffer_transport, {t_membuffer, <<>>}}, + [], + [[], []] + }, + ok + }, + write( + {t_framed, + {t_transport, thrift_membuffer_transport, {t_membuffer, <<>>}}, + [], + [] + }, + [] + ) + )}, + {"write empty list to nonempty framed membuffer", ?_assertMatch( + { + {t_framed, + {t_transport, thrift_membuffer_transport, {t_membuffer, <<>>}}, + [], + [["hallo world"], []] + }, + ok + }, + write( + {t_framed, + {t_transport, thrift_membuffer_transport, {t_membuffer, <<>>}}, + [], + ["hallo world"] + }, + [] + ) + )}, + {"write empty binary to empty framed membuffer", ?_assertMatch( + { + {t_framed, + {t_transport, thrift_membuffer_transport, {t_membuffer, <<>>}}, + [], + [[], <<>>] + }, + ok + }, + write( + {t_framed, + {t_transport, thrift_membuffer_transport, {t_membuffer, <<>>}}, + [], + [] + }, + <<>> + ) + )}, + {"write empty binary to nonempty framed membuffer", ?_assertMatch( + { + {t_framed, + {t_transport, thrift_membuffer_transport, {t_membuffer, <<>>}}, + [], + [["hallo world"], <<>>] + }, + ok + }, + write( + {t_framed, + {t_transport, thrift_membuffer_transport, {t_membuffer, <<>>}}, + [], + ["hallo world"] + }, + <<>> + ) + )} + ]. + + +flush(Transport) -> thrift_framed_transport:flush(Transport). + +flush_test_() -> + [ + {"flush empty framed membuffer", ?_assertMatch( + {{t_framed, + {t_transport, thrift_membuffer_transport, {t_membuffer, <<>>}}, + [], + [] + }, + ok + }, + flush({t_framed, + {t_transport, thrift_membuffer_transport, {t_membuffer, <<>>}}, + [], + [] + }) + )}, + {"flush nonempty framed membuffer", ?_assertMatch( + {{t_framed, + {t_transport, thrift_membuffer_transport, {t_membuffer, + [<<>>, [<<0, 0, 0, 11>>, <<"hallo world">>]] + }}, + [], + [] + }, + ok + }, + flush({t_framed, + {t_transport, thrift_membuffer_transport, {t_membuffer, <<>>}}, + [], + <<"hallo world">> + }) + )} + ]. + + +close(Transport) -> thrift_framed_transport:close(Transport). + +close_test_() -> + {"close framed membuffer", ?_assertMatch( + {{t_framed, + {t_transport, thrift_membuffer_transport, {t_membuffer, <<>>}}, + [], + [] + }, + ok + }, + close({t_framed, + {t_transport, thrift_membuffer_transport, {t_membuffer, <<>>}}, + [], + [] + }) + )}. + diff --git a/src/jaegertracing/thrift/lib/erl/test/test_thrift_membuffer_transport.erl b/src/jaegertracing/thrift/lib/erl/test/test_thrift_membuffer_transport.erl new file mode 100644 index 000000000..9689c7987 --- /dev/null +++ b/src/jaegertracing/thrift/lib/erl/test/test_thrift_membuffer_transport.erl @@ -0,0 +1,167 @@ +%% +%% 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. +%% + +-module(test_thrift_membuffer_transport). +-include_lib("eunit/include/eunit.hrl"). + + +new() -> thrift_membuffer_transport:new(). +new(Data) -> thrift_membuffer_transport:new(Data). + +new_test_() -> + [ + {"new empty membuffer", ?_assertMatch( + {ok, {_, _, {t_membuffer, []}}}, + new() + )}, + {"new membuffer with <<>>", ?_assertMatch( + {ok, {_, _, {t_membuffer, [<<>>]}}}, + new(<<>>) + )}, + {"new membuffer with []", ?_assertMatch( + {ok, {_, _, {t_membuffer, []}}}, + new([]) + )}, + {"new membuffer with <<\"hallo world\">>", ?_assertMatch( + {ok, {_, _, {t_membuffer, [<<"hallo world">>]}}}, + new(<<"hallo world">>) + )}, + {"new membuffer with \"hallo world\"", ?_assertMatch( + {ok, {_, _, {t_membuffer, "hallo world"}}}, + new("hallo world") + )} + ]. + + +read(Membuffer, Bytes) -> thrift_membuffer_transport:read(Membuffer, Bytes). + +read_test_() -> + [ + {"read zero bytes from an empty membuffer", ?_assertMatch( + {_, {ok, <<>>}}, + read({t_membuffer, []}, 0) + )}, + {"read 1 byte from an empty membuffer", ?_assertMatch( + {_, {ok, <<>>}}, + read({t_membuffer, []}, 1) + )}, + {"read zero bytes from nonempty membuffer", ?_assertMatch( + {{t_membuffer, <<"hallo world">>}, {ok, <<>>}}, + read({t_membuffer, [["hallo", " "], "world"]}, 0) + )}, + {"read 1 byte from nonempty membuffer", ?_assertMatch( + {{t_membuffer, <<"allo world">>}, {ok, <<"h">>}}, + read({t_membuffer, [["hallo", " "], "world"]}, 1) + )}, + {"read a zillion bytes from nonempty buffer", ?_assertMatch( + {{t_membuffer, <<>>}, {ok, <<"hallo world">>}}, + read({t_membuffer, [["hallo", " "], "world"]}, 65536) + )} + ]. + + +read_exact(Membuffer, Bytes) -> + thrift_membuffer_transport:read_exact(Membuffer, Bytes). + +read_exact_test_() -> + [ + {"read exactly zero bytes from an empty membuffer", ?_assertMatch( + {_, {ok, <<>>}}, + read_exact({t_membuffer, []}, 0) + )}, + {"read exactly 1 byte from an empty membuffer", ?_assertMatch( + {_, {error, eof}}, + read_exact({t_membuffer, []}, 1) + )}, + {"read exactly zero bytes from nonempty membuffer", ?_assertMatch( + {{t_membuffer, <<"hallo world">>}, {ok, <<>>}}, + read_exact({t_membuffer, [["hallo", " "], "world"]}, 0) + )}, + {"read exactly 1 byte from nonempty membuffer", ?_assertMatch( + {{t_membuffer, <<"allo world">>}, {ok, <<"h">>}}, + read_exact({t_membuffer, [["hallo", " "], "world"]}, 1) + )}, + {"read exactly a zillion bytes from nonempty buffer", ?_assertMatch( + {{t_membuffer, [["hallo", " "], "world"]}, {error, eof}}, + read_exact({t_membuffer, [["hallo", " "], "world"]}, 65536) + )} + ]. + + +write(Membuffer, Data) -> thrift_membuffer_transport:write(Membuffer, Data). + +write_test_() -> + [ + {"write empty list to empty membuffer", ?_assertMatch( + {{t_membuffer, [[], []]}, ok}, + write({t_membuffer, []}, []) + )}, + {"write empty list to nonempty membuffer", ?_assertMatch( + {{t_membuffer, ["hallo world", []]}, ok}, + write({t_membuffer, "hallo world"}, []) + )}, + {"write empty binary to empty membuffer", ?_assertMatch( + {{t_membuffer, [[], <<>>]}, ok}, + write({t_membuffer, []}, <<>>) + )}, + {"write empty binary to nonempty membuffer", ?_assertMatch( + {{t_membuffer, ["hallo world", <<>>]}, ok}, + write({t_membuffer, "hallo world"}, <<>>) + )}, + {"write a list to empty membuffer", ?_assertMatch( + {{t_membuffer, [[], "hallo world"]}, ok}, + write({t_membuffer, []}, "hallo world") + )}, + {"write a list to nonempty membuffer", ?_assertMatch( + {{t_membuffer, [["hallo", " "], "world"]}, ok}, + write({t_membuffer, ["hallo", " "]}, "world") + )}, + {"write a binary to empty membuffer", ?_assertMatch( + {{t_membuffer, [[], <<"hallo world">>]}, ok}, + write({t_membuffer, []}, <<"hallo world">>) + )}, + {"write a binary to nonempty membuffer", ?_assertMatch( + {{t_membuffer, [["hallo", " "], <<"world">>]}, ok}, + write({t_membuffer, ["hallo", " "]}, <<"world">>) + )} + ]. + + +flush(Transport) -> thrift_membuffer_transport:flush(Transport). + +flush_test_() -> + [ + {"flush empty membuffer", ?_assertMatch( + {{t_membuffer, []}, ok}, + flush({t_membuffer, []}) + )}, + {"flush nonempty membuffer", ?_assertMatch( + {{t_membuffer, [<<"hallo world">>]}, ok}, + flush({t_membuffer, [<<"hallo world">>]}) + )} + ]. + + +close(Transport) -> thrift_membuffer_transport:close(Transport). + +close_test_() -> + {"close membuffer", ?_assertMatch( + {{t_membuffer, _}, ok}, + close({t_membuffer, []}) + )}. \ No newline at end of file diff --git a/src/jaegertracing/thrift/lib/erl/test/test_thrift_socket_transport.erl b/src/jaegertracing/thrift/lib/erl/test/test_thrift_socket_transport.erl new file mode 100644 index 000000000..5bc0f246d --- /dev/null +++ b/src/jaegertracing/thrift/lib/erl/test/test_thrift_socket_transport.erl @@ -0,0 +1,199 @@ +%% +%% 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. +%% + +-module(test_thrift_socket_transport). +-include_lib("eunit/include/eunit.hrl"). + + +new(Socket) -> thrift_socket_transport:new(Socket). +new(Socket, Opts) -> thrift_socket_transport:new(Socket, Opts). + +new_test_() -> + [ + {"new socket", ?_assertMatch( + {ok, {_, thrift_socket_transport, {t_socket, a_fake_socket, 60000, []}}}, + new(a_fake_socket) + )}, + {"new socket with no options", ?_assertMatch( + {ok, {_, thrift_socket_transport, {t_socket, a_fake_socket, 60000, []}}}, + new(a_fake_socket, []) + )}, + {"new socket with integer timeout", ?_assertMatch( + {ok, {_, thrift_socket_transport, {t_socket, a_fake_socket, 5000, []}}}, + new(a_fake_socket, [{recv_timeout, 5000}]) + )}, + {"new socket with infinity timeout", ?_assertMatch( + {ok, {_, thrift_socket_transport, {t_socket, a_fake_socket, infinity, []}}}, + new(a_fake_socket, [{recv_timeout, infinity}]) + )} + ]. + + +read(Socket, Bytes) -> thrift_socket_transport:read(Socket, Bytes). + +read_test_() -> + {setup, + fun() -> + meck:new(gen_tcp, [unstick, passthrough]), + meck:expect(gen_tcp, recv, fun(Bin, 0, _) -> {ok, Bin} end) + end, + fun(_) -> meck:unload(gen_tcp) end, + [ + {"read zero bytes from empty socket", ?_assertMatch( + {_, {ok, <<>>}}, + read({t_socket, <<>>, 60000, []}, 0) + )}, + {"read 1 byte from empty socket", ?_assertMatch( + {_, {ok, <<>>}}, + read({t_socket, <<>>, 60000, []}, 1) + )}, + {"read zero bytes from nonempty socket", ?_assertMatch( + {{t_socket, _, _, _}, {ok, <<>>}}, + read({t_socket, <<"hallo world">>, 60000, []}, 0) + )}, + {"read 1 byte from nonempty socket", ?_assertMatch( + {{t_socket, _, _, <<"allo world">>}, {ok, <<"h">>}}, + read({t_socket, <<"hallo world">>, 60000, []}, 1) + )}, + {"read a zillion bytes from nonempty socket", ?_assertMatch( + {{t_socket, _, _, <<>>}, {ok, <<"hallo world">>}}, + read({t_socket, <<"hallo world">>, 60000, []}, 65536) + )}, + {"read 1 byte from previously buffered socket", ?_assertMatch( + {{t_socket, _, _, <<"allo">>}, {ok, <<"h">>}}, + read({t_socket, <<" world">>, 60000, <<"hallo">>}, 1) + )}, + {"read 6 byte from previously buffered socket", ?_assertMatch( + {{t_socket, _, _, <<"world">>}, {ok, <<"hallo ">>}}, + read({t_socket, <<" world">>, 60000, <<"hallo">>}, 6) + )}, + {"read a zillion bytes from previously buffered socket", ?_assertMatch( + {{t_socket, _, _, <<>>}, {ok, <<"hallo world">>}}, + read({t_socket, <<" world">>, 60000, <<"hallo">>}, 65536) + )} + ] + }. + + +read_exact(Socket, Bytes) -> thrift_socket_transport:read_exact(Socket, Bytes). + +read_exact_test_() -> + {setup, + fun() -> + meck:new(gen_tcp, [unstick, passthrough]), + meck:expect(gen_tcp, recv, fun(Bin, N, _) -> + case N of + 0 -> {ok, Bin}; + 1 -> {ok, <<"h">>}; + N when N > 2 -> {error, timeout} + end + end), + meck:expect(gen_tcp, close, fun(_) -> ok end) + end, + fun(_) -> meck:unload(gen_tcp) end, + [ + {"read_exact zero bytes from empty socket", ?_assertMatch( + {_, {ok, <<>>}}, + read_exact({t_socket, <<>>, 60000, []}, 0) + )}, + {"read_exact zero bytes from nonempty socket", ?_assertMatch( + {{t_socket, _, _, _}, {ok, <<>>}}, + read_exact({t_socket, <<"hallo world">>, 60000, []}, 0) + )}, + {"read_exact 1 byte from nonempty socket", ?_assertMatch( + {{t_socket, _, _, []}, {ok, <<"h">>}}, + read_exact({t_socket, <<"hallo world">>, 60000, []}, 1) + )}, + {"read_exact a zillion bytes from nonempty socket", ?_assertMatch( + {{t_socket, _, _, []}, {error, timeout}}, + read_exact({t_socket, <<"hallo world">>, 60000, []}, 65536) + )}, + {"read_exact 1 byte from previously buffered socket", ?_assertMatch( + {{t_socket, _, _, <<"allo">>}, {ok, <<"h">>}}, + read_exact({t_socket, <<" world">>, 60000, <<"hallo">>}, 1) + )}, + {"read_exact 6 byte from previously buffered socket", ?_assertMatch( + {{t_socket, _, _, []}, {ok, <<"more h">>}}, + read_exact({t_socket, <<"hallo">>, 60000, <<"more ">>}, 6) + )}, + {"read_exact a zillion bytes from previously buffered socket", ?_assertMatch( + {{t_socket, _, _, <<"hallo">>}, {error, timeout}}, + read_exact({t_socket, <<" world">>, 60000, <<"hallo">>}, 65536) + )} + ] + }. + + +write(Socket, Data) -> thrift_socket_transport:write(Socket, Data). + +write_test_() -> + {setup, + fun() -> + meck:new(gen_tcp, [unstick, passthrough]), + meck:expect(gen_tcp, send, fun(_, _) -> ok end) + end, + fun(_) -> meck:unload(gen_tcp) end, + [ + {"write empty list to socket", ?_assertMatch( + {{t_socket, a_fake_socket, 60000, []}, ok}, + write({t_socket, a_fake_socket, 60000, []}, []) + )}, + {"write empty binary to socket", ?_assertMatch( + {{t_socket, a_fake_socket, 60000, []}, ok}, + write({t_socket, a_fake_socket, 60000, []}, <<>>) + )}, + {"write a list to socket", ?_assertMatch( + {{t_socket, a_fake_socket, 60000, []}, ok}, + write({t_socket, a_fake_socket, 60000, []}, "hallo world") + )}, + {"write a binary to socket", ?_assertMatch( + {{t_socket, a_fake_socket, 60000, []}, ok}, + write({t_socket, a_fake_socket, 60000, []}, <<"hallo world">>) + )} + ] + }. + + +flush(Transport) -> thrift_socket_transport:flush(Transport). + +flush_test_() -> + [ + {"flush socket", ?_assertMatch( + {{t_socket, a_fake_socket, 60000, []}, ok}, + flush({t_socket, a_fake_socket, 60000, []}) + )} + ]. + + +close(Transport) -> thrift_socket_transport:close(Transport). + +close_test_() -> + {setup, + fun() -> + meck:new(gen_tcp, [unstick, passthrough]), + meck:expect(gen_tcp, close, fun(_) -> ok end) + end, + fun(_) -> meck:unload(gen_tcp) end, + [ + {"close membuffer", ?_assertMatch( + {{t_socket, a_fake_socket, 60000, []}, ok}, + close({t_socket, a_fake_socket, 60000, []}) + )} + ] + }. \ No newline at end of file diff --git a/src/jaegertracing/thrift/lib/erl/test/thrift_socket_server_test.erl b/src/jaegertracing/thrift/lib/erl/test/thrift_socket_server_test.erl new file mode 100644 index 000000000..0818b844e --- /dev/null +++ b/src/jaegertracing/thrift/lib/erl/test/thrift_socket_server_test.erl @@ -0,0 +1,49 @@ +-module (thrift_socket_server_test). + +-include_lib("eunit/include/eunit.hrl"). + +-include ("thrift_constants.hrl"). + +parse_handler_options_test_() -> + CorrectServiceHandlerOptionList = [{?MULTIPLEXED_ERROR_HANDLER_KEY, ?MODULE}, {"Service1", ?MODULE}, {"Service2", ?MODULE}], + MissingErrorHandlerOptionList = [{"Service1", ?MODULE}, {"Service2", ?MODULE}], + WrongService2HandlerOptionList = [{?MULTIPLEXED_ERROR_HANDLER_KEY, ?MODULE}, {"Service1", ?MODULE}, {"Service2", "Module"}], + WrongServiceKeyOptionList = [{?MULTIPLEXED_ERROR_HANDLER_KEY, ?MODULE}, {'service1', ?MODULE}, {"Service2", ?MODULE}], + CorrectHandlerTestFunction = fun() -> + ?assertMatch({thrift_socket_server,_,_,_,_,_,_,_,_,_,_,_,_,_}, thrift_socket_server:parse_options([{handler, CorrectServiceHandlerOptionList}])), + {thrift_socket_server,_,_, HandlerList,_,_,_,_,_,_,_,_,_,_} = thrift_socket_server:parse_options([{handler, CorrectServiceHandlerOptionList}]), + lists:foreach(fun + ({ServiceName, HandlerModule}) -> + ?assertMatch({ok, HandlerModule} when is_atom(HandlerModule), thrift_multiplexed_map_wrapper:find(ServiceName, HandlerList)) + end, CorrectServiceHandlerOptionList) + end, + [ + {"Bad argument for the handler option", ?_assertThrow(_, thrift_socket_server:parse_options([{handler, []}]))}, + {"Try to parse the handler option twice", ?_assertThrow(_, thrift_socket_server:parse_options([{handler, ?MODULE}, {handler, CorrectServiceHandlerOptionList}]))}, + {"Parse the handler option as a non multiplexed service handler", ?_assertMatch({thrift_socket_server,_,_,?MODULE,_,_,_,_,_,_,_,_,_,_}, thrift_socket_server:parse_options([{handler, ?MODULE}]))}, + {"No error handler was defined", ?_assertThrow(_, thrift_socket_server:parse_options([{handler, MissingErrorHandlerOptionList}]))}, + {"Bad handler module for Service2", ?_assertThrow(_, thrift_socket_server:parse_options([{handler, WrongService2HandlerOptionList}]))}, + {"Bad service key for Service1", ?_assertThrow(_, thrift_socket_server:parse_options([{handler, WrongServiceKeyOptionList}]))}, + {"Try to parse a correct handler option list", CorrectHandlerTestFunction} + ]. + +parse_service_options_test_() -> + CorrectServiceModuleOptionList = [{"Service1", ?MODULE}, {"Service2", ?MODULE}], + WrongService2ModuleOptionList = [{"Service1", ?MODULE}, {"Service2", "thrift_service_module"}], + WrongServiceKeyOptionList = [{'service1', ?MODULE}, {"Service2", ?MODULE}], + CorrectServiceModuleTestFunction = fun() -> + ?assertMatch({thrift_socket_server,_,_,_,_,_,_,_,_,_,_,_,_,_}, thrift_socket_server:parse_options([{service, CorrectServiceModuleOptionList}])), + {thrift_socket_server,_, ServiceModuleList,_,_,_,_,_,_,_,_,_,_,_} = thrift_socket_server:parse_options([{service, CorrectServiceModuleOptionList}]), + lists:foreach(fun + ({ServiceName, ServiceModule}) -> + ?assertMatch({ok, ServiceModule} when is_atom(ServiceModule), thrift_multiplexed_map_wrapper:find(ServiceName, ServiceModuleList)) + end, CorrectServiceModuleOptionList) + end, + [ + {"Bad argument for the service option", ?_assertThrow(_, thrift_socket_server:parse_options([{service, []}]))}, + {"Try to parse the service option twice", ?_assertThrow(_, thrift_socket_server:parse_options([{service, ?MODULE}, {service, CorrectServiceModuleOptionList}]))}, + {"Parse a service module for a non multiplexed service", ?_assertMatch({thrift_socket_server,_,?MODULE,_,_,_,_,_,_,_,_,_,_,_}, thrift_socket_server:parse_options([{service, ?MODULE}]))}, + {"Bad service module for Service2", ?_assertThrow(_, thrift_socket_server:parse_options([{service, WrongService2ModuleOptionList}]))}, + {"Bad service key for Service1", ?_assertThrow(_, thrift_socket_server:parse_options([{service, WrongServiceKeyOptionList}]))}, + {"Try to parse a correct service option list", CorrectServiceModuleTestFunction} + ]. diff --git a/src/jaegertracing/thrift/lib/erl/test/thrift_test_test.erl b/src/jaegertracing/thrift/lib/erl/test/thrift_test_test.erl new file mode 100644 index 000000000..77df61d9a --- /dev/null +++ b/src/jaegertracing/thrift/lib/erl/test/thrift_test_test.erl @@ -0,0 +1,643 @@ +%% +%% 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. +%% + +% don't rename this thrift_test, it clobbers generated files +-module(thrift_test_test). +-compile(export_all). + +-include_lib("eunit/include/eunit.hrl"). + +-include("gen-erl/thrift_test_constants.hrl"). + +constant_test_() -> + [ + {"myNumberz equals 1", ?_assertEqual(1, ?THRIFT_TEST_MYNUMBERZ)} + ]. + +record_generation_test_() -> + [ + {"Bonk record", ?_assertMatch( + {'thrift.test.Bonk', _, _}, + #'thrift.test.Bonk'{message=null,type=null} + )}, + {"Bools record", ?_assertMatch( + {'thrift.test.Bools', _, _}, + #'thrift.test.Bools'{im_true=null,im_false=null} + )}, + {"Xtruct record", ?_assertMatch( + {'thrift.test.Xtruct', _, _, _, _}, + #'thrift.test.Xtruct'{string_thing=null,byte_thing=null,i32_thing=null,i64_thing=null} + )}, + {"Xtruct2 record", ?_assertMatch( + {'thrift.test.Xtruct2', _, _, _}, + #'thrift.test.Xtruct2'{byte_thing=null,struct_thing=null,i32_thing=null} + )}, + {"Xtruct3 record", ?_assertMatch( + {'thrift.test.Xtruct3', _, _, _, _}, + #'thrift.test.Xtruct3'{string_thing=null,changed=null,i32_thing=null,i64_thing=null} + )}, + {"Insanity record", ?_assertMatch( + {'thrift.test.Insanity', _, _}, + #'thrift.test.Insanity'{userMap=null,xtructs=null} + )}, + {"CrazyNesting record", ?_assertMatch( + {'thrift.test.CrazyNesting', _, _, _, _}, + #'thrift.test.CrazyNesting'{ + string_field=null, + set_field=null, + list_field=null, + binary_field=null + } + )}, + {"Xception record", ?_assertMatch( + {'thrift.test.Xception', _, _}, + #'thrift.test.Xception'{errorCode=null,message=null} + )}, + {"Xception2 record", ?_assertMatch( + {'thrift.test.Xception2', _, _}, + #'thrift.test.Xception2'{errorCode=null,struct_thing=null} + )}, + {"EmptyStruct record", ?_assertMatch({'thrift.test.EmptyStruct'}, #'thrift.test.EmptyStruct'{})}, + {"OneField record", ?_assertMatch({'thrift.test.OneField', _}, #'thrift.test.OneField'{field=null})}, + {"VersioningTestV1 record", ?_assertMatch( + {'thrift.test.VersioningTestV1', _, _, _}, + #'thrift.test.VersioningTestV1'{begin_in_both=null,old_string=null,end_in_both=null} + )}, + {"VersioningTestV2 record", ?_assertMatch( + {'thrift.test.VersioningTestV2', _, _, _, _, _, _, _, _, _, _, _, _}, + #'thrift.test.VersioningTestV2'{ + begin_in_both=null, + newint=null, + newbyte=null, + newshort=null, + newlong=null, + newdouble=null, + newstruct=null, + newlist=null, + newset=null, + newmap=null, + newstring=null, + end_in_both=null + } + )}, + {"ListTypeVersioningV1 record", ?_assertMatch( + {'thrift.test.ListTypeVersioningV1', _, _}, + #'thrift.test.ListTypeVersioningV1'{myints=null,hello=null} + )}, + {"ListTypeVersioningV2 record", ?_assertMatch( + {'thrift.test.ListTypeVersioningV2', _, _}, + #'thrift.test.ListTypeVersioningV2'{strings=null,hello=null} + )}, + {"GuessProtocolStruct record", ?_assertMatch( + {'thrift.test.GuessProtocolStruct', _}, + #'thrift.test.GuessProtocolStruct'{map_field=null} + )}, + {"LargeDeltas record", ?_assertMatch( + {'thrift.test.LargeDeltas', _, _, _, _, _, _, _, _, _, _}, + #'thrift.test.LargeDeltas'{ + b1=null, + b10=null, + b100=null, + check_true=null, + b1000=null, + check_false=null, + vertwo2000=null, + a_set2500=null, + vertwo3000=null, + big_numbers=null + } + )}, + {"NestedListsI32x2 record", ?_assertMatch( + {'thrift.test.NestedListsI32x2', _}, + #'thrift.test.NestedListsI32x2'{integerlist=null} + )}, + {"NestedListsI32x3 record", ?_assertMatch( + {'thrift.test.NestedListsI32x3', _}, + #'thrift.test.NestedListsI32x3'{integerlist=null} + )}, + {"NestedMixedx2 record", ?_assertMatch( + {'thrift.test.NestedMixedx2', _, _, _}, + #'thrift.test.NestedMixedx2'{ + int_set_list=null, + map_int_strset=null, + map_int_strset_list=null + } + )}, + {"ListBonks record", ?_assertMatch({'thrift.test.ListBonks', _}, #'thrift.test.ListBonks'{bonk=null})}, + {"NestedListsBonk record", ?_assertMatch( + {'thrift.test.NestedListsBonk', _}, + #'thrift.test.NestedListsBonk'{bonk=null} + )}, + {"BoolTest record", ?_assertMatch( + {'thrift.test.BoolTest', _, _}, + #'thrift.test.BoolTest'{b=null,s=null} + )}, + {"StructA record", ?_assertMatch({'thrift.test.StructA', _}, #'thrift.test.StructA'{s=null})}, + {"StructB record", ?_assertMatch( + {'thrift.test.StructB', _, _}, + #'thrift.test.StructB'{aa=null,ab=null} + )} + ]. + +struct_info_test_() -> + [ + {"Bonk definition (short version)", ?_assertEqual( + {struct, [{1, string}, {2, i32}]}, + thrift_test_types:struct_info('thrift.test.Bonk') + )}, + {"Bonk definition", ?_assertEqual( + {struct, [ + {1, undefined, string, message, undefined}, + {2, undefined, i32, type, undefined} + ]}, + thrift_test_types:struct_info_ext('thrift.test.Bonk') + )}, + {"Bools definition", ?_assertEqual( + {struct, [ + {1, undefined, bool, im_true, undefined}, + {2, undefined, bool, im_false, undefined} + ]}, + thrift_test_types:struct_info_ext('thrift.test.Bools') + )}, + {"Xtruct definition", ?_assertEqual( + {struct, [ + {1, undefined, string, string_thing, undefined}, + {4, undefined, byte, byte_thing, undefined}, + {9, undefined, i32, i32_thing, undefined}, + {11, undefined, i64, i64_thing, undefined} + ]}, + thrift_test_types:struct_info_ext('thrift.test.Xtruct') + )}, + {"Xtruct2 definition", ?_assertEqual( + {struct, [ + {1, undefined, byte, byte_thing, undefined}, + {2, undefined, {struct, {'thrift_test_types', 'thrift.test.Xtruct'}}, struct_thing, #'thrift.test.Xtruct'{}}, + {3, undefined, i32, i32_thing, undefined} + ]}, + thrift_test_types:struct_info_ext('thrift.test.Xtruct2') + )}, + {"Xtruct3 definition", ?_assertEqual( + {struct, [ + {1, undefined, string, string_thing, undefined}, + {4, undefined, i32, changed, undefined}, + {9, undefined, i32, i32_thing, undefined}, + {11, undefined, i64, i64_thing, undefined} + ]}, + thrift_test_types:struct_info_ext('thrift.test.Xtruct3') + )}, + {"Insanity definition", ?_assertEqual( + {struct, [ + {1, undefined, {map, i32, i64}, userMap, dict:new()}, + {2, undefined, {list, {struct, {'thrift_test_types', 'thrift.test.Xtruct'}}}, xtructs, []} + ]}, + thrift_test_types:struct_info_ext('thrift.test.Insanity') + )}, + {"CrazyNesting definition", ?_assertEqual( + {struct, [ + {1, undefined, string, string_field, undefined}, + {2, optional, {set, {struct, {'thrift_test_types', 'thrift.test.Insanity'}}}, set_field, sets:new()}, + {3, required, {list, {map, + {set, i32}, + {map, i32, {set, {list, {map, {struct, {'thrift_test_types', 'thrift.test.Insanity'}}, string}}}} + }}, list_field, []}, + {4, undefined, string, binary_field, undefined} + ]}, + thrift_test_types:struct_info_ext('thrift.test.CrazyNesting') + )}, + {"Xception definition", ?_assertEqual( + {struct, [ + {1, undefined, i32, errorCode, undefined}, + {2, undefined, string, message, undefined} + ]}, + thrift_test_types:struct_info_ext('thrift.test.Xception') + )}, + {"Xception2 definition", ?_assertEqual( + {struct, [ + {1, undefined, i32, errorCode, undefined}, + {2, undefined, {struct, {'thrift_test_types', 'thrift.test.Xtruct'}}, struct_thing, #'thrift.test.Xtruct'{}} + ]}, + thrift_test_types:struct_info_ext('thrift.test.Xception2') + )}, + {"EmptyStruct definition", ?_assertEqual( + {struct, []}, + thrift_test_types:struct_info_ext('thrift.test.EmptyStruct') + )}, + {"OneField definition", ?_assertEqual( + {struct, [ + {1, undefined, {struct, {'thrift_test_types', 'thrift.test.EmptyStruct'}}, field, #'thrift.test.EmptyStruct'{}} + ]}, + thrift_test_types:struct_info_ext('thrift.test.OneField') + )}, + {"VersioningTestV1 definition", ?_assertEqual( + {struct, [ + {1, undefined, i32, begin_in_both, undefined}, + {3, undefined, string, old_string, undefined}, + {12, undefined, i32, end_in_both, undefined} + ]}, + thrift_test_types:struct_info_ext('thrift.test.VersioningTestV1') + )}, + {"VersioningTestV2 definition", ?_assertEqual( + {struct, [ + {1, undefined, i32, begin_in_both, undefined}, + {2, undefined, i32, newint, undefined}, + {3, undefined, byte, newbyte, undefined}, + {4, undefined, i16, newshort, undefined}, + {5, undefined, i64, newlong, undefined}, + {6, undefined, double, newdouble, undefined}, + {7, undefined, {struct, {thrift_test_types, 'thrift.test.Bonk'}}, newstruct, #'thrift.test.Bonk'{}}, + {8, undefined, {list, i32}, newlist, []}, + {9, undefined, {set, i32}, newset, sets:new()}, + {10, undefined, {map, i32, i32}, newmap, dict:new()}, + {11, undefined, string, newstring, undefined}, + {12, undefined, i32, end_in_both, undefined} + ]}, + thrift_test_types:struct_info_ext('thrift.test.VersioningTestV2') + )}, + {"ListTypeVersioningV1 definition", ?_assertEqual( + {struct, [ + {1, undefined, {list, i32}, myints, []}, + {2, undefined, string, hello, undefined} + ]}, + thrift_test_types:struct_info_ext('thrift.test.ListTypeVersioningV1') + )}, + {"ListTypeVersioningV2 definition", ?_assertEqual( + {struct, [ + {1, undefined, {list, string}, strings, []}, + {2, undefined, string, hello, undefined} + ]}, + thrift_test_types:struct_info_ext('thrift.test.ListTypeVersioningV2') + )}, + {"GuessProtocolStruct definition", ?_assertEqual( + {struct, [ + {7, undefined, {map, string, string}, map_field, dict:new()} + ]}, + thrift_test_types:struct_info_ext('thrift.test.GuessProtocolStruct') + )}, + {"LargeDeltas definition", ?_assertEqual( + {struct, [ + {1, undefined, {struct, {thrift_test_types, 'thrift.test.Bools'}}, b1, #'thrift.test.Bools'{}}, + {10, undefined, {struct, {thrift_test_types, 'thrift.test.Bools'}}, b10, #'thrift.test.Bools'{}}, + {100, undefined, {struct, {thrift_test_types, 'thrift.test.Bools'}}, b100, #'thrift.test.Bools'{}}, + {500, undefined, bool, check_true, undefined}, + {1000, undefined, {struct, {thrift_test_types, 'thrift.test.Bools'}}, b1000, #'thrift.test.Bools'{}}, + {1500, undefined, bool, check_false, undefined}, + {2000, undefined, {struct, {thrift_test_types, 'thrift.test.VersioningTestV2'}}, vertwo2000, #'thrift.test.VersioningTestV2'{}}, + {2500, undefined, {set, string}, a_set2500, sets:new()}, + {3000, undefined, {struct, {thrift_test_types, 'thrift.test.VersioningTestV2'}}, vertwo3000, #'thrift.test.VersioningTestV2'{}}, + {4000, undefined, {list, i32}, big_numbers, []} + ]}, + thrift_test_types:struct_info_ext('thrift.test.LargeDeltas') + )}, + {"NestedListsI32x2 definition", ?_assertEqual( + {struct, [ + {1, undefined, {list, {list, i32}}, integerlist, []} + ]}, + thrift_test_types:struct_info_ext('thrift.test.NestedListsI32x2') + )}, + {"NestedListsI32x3 definition", ?_assertEqual( + {struct, [ + {1, undefined, {list, {list, {list, i32}}}, integerlist, []} + ]}, + thrift_test_types:struct_info_ext('thrift.test.NestedListsI32x3') + )}, + {"NestedMixedx2 definition", ?_assertEqual( + {struct, [ + {1, undefined, {list, {set, i32}}, int_set_list, []}, + {2, undefined, {map, i32, {set, string}}, map_int_strset, dict:new()}, + {3, undefined, {list, {map, i32, {set, string}}}, map_int_strset_list, []} + ]}, + thrift_test_types:struct_info_ext('thrift.test.NestedMixedx2') + )}, + {"ListBonks definition", ?_assertEqual( + {struct, [ + {1, undefined, {list, {struct, {thrift_test_types, 'thrift.test.Bonk'}}}, bonk, []} + ]}, + thrift_test_types:struct_info_ext('thrift.test.ListBonks') + )}, + {"NestedListsBonk definition", ?_assertEqual( + {struct, [ + {1, undefined, {list, {list, {list, {struct, {thrift_test_types, 'thrift.test.Bonk'}}}}}, bonk, []} + ]}, + thrift_test_types:struct_info_ext('thrift.test.NestedListsBonk') + )}, + {"BoolTest definition", ?_assertEqual( + {struct, [ + {1, optional, bool, b, true}, + {2, optional, string, s, "true"} + ]}, + thrift_test_types:struct_info_ext('thrift.test.BoolTest') + )}, + {"StructA definition", ?_assertEqual( + {struct, [{1, required, string, s, undefined}]}, + thrift_test_types:struct_info_ext('thrift.test.StructA') + )}, + {"StructB definition", ?_assertEqual( + {struct, [ + {1, optional, {struct, {thrift_test_types, 'thrift.test.StructA'}}, aa, #'thrift.test.StructA'{}}, + {2, required, {struct, {thrift_test_types, 'thrift.test.StructA'}}, ab, #'thrift.test.StructA'{}} + ]}, + thrift_test_types:struct_info_ext('thrift.test.StructB') + )} + ]. + +service_info_test_() -> + [ + {"testVoid params", ?_assertEqual( + {struct, []}, + thrift_test_thrift:function_info(testVoid, params_type) + )}, + {"testVoid reply", ?_assertEqual( + {struct, []}, + thrift_test_thrift:function_info(testVoid, reply_type) + )}, + {"testVoid exceptions", ?_assertEqual( + {struct, []}, + thrift_test_thrift:function_info(testVoid, exceptions) + )}, + {"testString params", ?_assertEqual( + {struct, [{1, string}]}, + thrift_test_thrift:function_info(testString, params_type) + )}, + {"testString reply", ?_assertEqual( + string, + thrift_test_thrift:function_info(testString, reply_type) + )}, + {"testString exceptions", ?_assertEqual( + {struct, []}, + thrift_test_thrift:function_info(testString, exceptions) + )}, + {"testByte params", ?_assertEqual( + {struct, [{1, byte}]}, + thrift_test_thrift:function_info(testByte, params_type) + )}, + {"testByte reply", ?_assertEqual( + byte, + thrift_test_thrift:function_info(testByte, reply_type) + )}, + {"testByte exceptions", ?_assertEqual( + {struct, []}, + thrift_test_thrift:function_info(testByte, exceptions) + )}, + {"testI32 params", ?_assertEqual( + {struct, [{1, i32}]}, + thrift_test_thrift:function_info(testI32, params_type) + )}, + {"testI32 reply", ?_assertEqual( + i32, + thrift_test_thrift:function_info(testI32, reply_type) + )}, + {"testI32 exceptions", ?_assertEqual( + {struct, []}, + thrift_test_thrift:function_info(testI32, exceptions) + )}, + {"testI64 params", ?_assertEqual( + {struct, [{1, i64}]}, + thrift_test_thrift:function_info(testI64, params_type) + )}, + {"testI64 reply", ?_assertEqual( + i64, + thrift_test_thrift:function_info(testI64, reply_type) + )}, + {"testI64 exceptions", ?_assertEqual( + {struct, []}, + thrift_test_thrift:function_info(testI64, exceptions) + )}, + {"testDouble params", ?_assertEqual( + {struct, [{1, double}]}, + thrift_test_thrift:function_info(testDouble, params_type) + )}, + {"testDouble reply", ?_assertEqual( + double, + thrift_test_thrift:function_info(testDouble, reply_type) + )}, + {"testDouble exceptions", ?_assertEqual( + {struct, []}, + thrift_test_thrift:function_info(testDouble, exceptions) + )}, + {"testStruct params", ?_assertEqual( + {struct, [ + {1, {struct, {thrift_test_types, 'thrift.test.Xtruct'}}} + ]}, + thrift_test_thrift:function_info(testStruct, params_type) + )}, + {"testStruct reply", ?_assertEqual( + {struct, {thrift_test_types, 'thrift.test.Xtruct'}}, + thrift_test_thrift:function_info(testStruct, reply_type) + )}, + {"testStruct exceptions", ?_assertEqual( + {struct, []}, + thrift_test_thrift:function_info(testStruct, exceptions) + )}, + {"testNest params", ?_assertEqual( + {struct, [ + {1, {struct, {thrift_test_types, 'thrift.test.Xtruct2'}}} + ]}, + thrift_test_thrift:function_info(testNest, params_type) + )}, + {"testNest reply", ?_assertEqual( + {struct, {thrift_test_types, 'thrift.test.Xtruct2'}}, + thrift_test_thrift:function_info(testNest, reply_type) + )}, + {"testNest exceptions", ?_assertEqual( + {struct, []}, + thrift_test_thrift:function_info(testNest, exceptions) + )}, + {"testMap params", ?_assertEqual( + {struct, [ + {1, {map, i32, i32}} + ]}, + thrift_test_thrift:function_info(testMap, params_type) + )}, + {"testMap reply", ?_assertEqual( + {map, i32, i32}, + thrift_test_thrift:function_info(testMap, reply_type) + )}, + {"testMap exceptions", ?_assertEqual( + {struct, []}, + thrift_test_thrift:function_info(testMap, exceptions) + )}, + {"testStringMap params", ?_assertEqual( + {struct, [ + {1, {map, string, string}} + ]}, + thrift_test_thrift:function_info(testStringMap, params_type) + )}, + {"testStringMap reply", ?_assertEqual( + {map, string, string}, + thrift_test_thrift:function_info(testStringMap, reply_type) + )}, + {"testStringMap exceptions", ?_assertEqual( + {struct, []}, + thrift_test_thrift:function_info(testStringMap, exceptions) + )}, + {"testSet params", ?_assertEqual( + {struct, [ + {1, {set, i32}} + ]}, + thrift_test_thrift:function_info(testSet, params_type) + )}, + {"testSet reply", ?_assertEqual( + {set, i32}, + thrift_test_thrift:function_info(testSet, reply_type) + )}, + {"testSet exceptions", ?_assertEqual( + {struct, []}, + thrift_test_thrift:function_info(testSet, exceptions) + )}, + {"testList params", ?_assertEqual( + {struct, [ + {1, {list, i32}} + ]}, + thrift_test_thrift:function_info(testList, params_type) + )}, + {"testList reply", ?_assertEqual( + {list, i32}, + thrift_test_thrift:function_info(testList, reply_type) + )}, + {"testList exceptions", ?_assertEqual( + {struct, []}, + thrift_test_thrift:function_info(testList, exceptions) + )}, + {"testEnum params", ?_assertEqual( + {struct, [ + {1, i32} + ]}, + thrift_test_thrift:function_info(testEnum, params_type) + )}, + {"testEnum reply", ?_assertEqual( + i32, + thrift_test_thrift:function_info(testEnum, reply_type) + )}, + {"testEnum exceptions", ?_assertEqual( + {struct, []}, + thrift_test_thrift:function_info(testEnum, exceptions) + )}, + {"testTypedef params", ?_assertEqual( + {struct, [{1, i64}]}, + thrift_test_thrift:function_info(testTypedef, params_type) + )}, + {"testTypedef reply", ?_assertEqual( + i64, + thrift_test_thrift:function_info(testTypedef, reply_type) + )}, + {"testTypedef exceptions", ?_assertEqual( + {struct, []}, + thrift_test_thrift:function_info(testTypedef, exceptions) + )}, + {"testMapMap params", ?_assertEqual( + {struct, [ + {1, i32} + ]}, + thrift_test_thrift:function_info(testMapMap, params_type) + )}, + {"testMapMap reply", ?_assertEqual( + {map, i32, {map, i32,i32}}, + thrift_test_thrift:function_info(testMapMap, reply_type) + )}, + {"testMapMap exceptions", ?_assertEqual( + {struct, []}, + thrift_test_thrift:function_info(testMapMap, exceptions) + )}, + {"testInsanity params", ?_assertEqual( + {struct, [ + {1, {struct, {thrift_test_types, 'thrift.test.Insanity'}}} + ]}, + thrift_test_thrift:function_info(testInsanity, params_type) + )}, + {"testInsanity reply", ?_assertEqual( + {map, i64, {map, i32, {struct, {'thrift_test_types', 'thrift.test.Insanity'}}}}, + thrift_test_thrift:function_info(testInsanity, reply_type) + )}, + {"testInsanity exceptions", ?_assertEqual( + {struct, []}, + thrift_test_thrift:function_info(testInsanity, exceptions) + )}, + {"testMulti params", ?_assertEqual( + {struct, [ + {1, byte}, + {2, i32}, + {3, i64}, + {4, {map, i16, string}}, + {5, i32}, + {6, i64} + ]}, + thrift_test_thrift:function_info(testMulti, params_type) + )}, + {"testMulti reply", ?_assertEqual( + {struct, {thrift_test_types, 'thrift.test.Xtruct'}}, + thrift_test_thrift:function_info(testMulti, reply_type) + )}, + {"testMulti exceptions", ?_assertEqual( + {struct, []}, + thrift_test_thrift:function_info(testMulti, exceptions) + )}, + {"testException params", ?_assertEqual( + {struct, [{1, string}]}, + thrift_test_thrift:function_info(testException, params_type) + )}, + {"testException reply", ?_assertEqual( + {struct, []}, + thrift_test_thrift:function_info(testException, reply_type) + )}, + {"testException exceptions", ?_assertEqual( + {struct, [ + {1, {struct, {thrift_test_types, 'thrift.test.Xception'}}} + ]}, + thrift_test_thrift:function_info(testException, exceptions) + )}, + {"testMultiException params", ?_assertEqual( + {struct, [{1, string}, {2, string}]}, + thrift_test_thrift:function_info(testMultiException, params_type) + )}, + {"testMultiException reply", ?_assertEqual( + {struct, {thrift_test_types, 'thrift.test.Xtruct'}}, + thrift_test_thrift:function_info(testMultiException, reply_type) + )}, + {"testMultiException exceptions", ?_assertEqual( + {struct, [ + {1, {struct, {thrift_test_types, 'thrift.test.Xception'}}}, + {2, {struct, {thrift_test_types, 'thrift.test.Xception2'}}} + ]}, + thrift_test_thrift:function_info(testMultiException, exceptions) + )}, + {"testOneway params", ?_assertEqual( + {struct, [{1, i32}]}, + thrift_test_thrift:function_info(testOneway, params_type) + )}, + {"testOneway reply", ?_assertEqual( + oneway_void, + thrift_test_thrift:function_info(testOneway, reply_type) + )}, + {"testOneway exceptions", ?_assertEqual( + {struct, []}, + thrift_test_thrift:function_info(testOneway, exceptions) + )}, + {"secondtestString params", ?_assertEqual( + {struct, [{1, string}]}, + second_service_thrift:function_info(secondtestString, params_type) + )}, + {"secondtestString reply", ?_assertEqual( + string, + second_service_thrift:function_info(secondtestString, reply_type) + )}, + {"secondtestString exceptions", ?_assertEqual( + {struct, []}, + second_service_thrift:function_info(secondtestString, exceptions) + )} + ]. -- cgit v1.2.3