Upgrading dependency to Thrift 0.12.0

This commit is contained in:
Renan DelValle 2018-11-27 18:03:50 -08:00
parent 3e4590dcc0
commit 356978cb42
No known key found for this signature in database
GPG key ID: C240AD6D6F443EC9
1302 changed files with 101701 additions and 26784 deletions

View file

@ -18,8 +18,12 @@
#
THRIFT = ../../compiler/cpp/thrift
THRIFT_OMIT_FILE = test/Thrift_omit_without.thrift
THRIFT_FILES = $(wildcard test/*.thrift) \
$(THRIFT_OMIT_FILE) \
../../test/ConstantsDemo.thrift \
../../test/NameConflictTest.thrift \
../../test/DoubleConstantsTest.thrift \
../../test/ThriftTest.thrift
if ERLANG_OTP16
@ -32,6 +36,10 @@ ERL_FLAG = erl
ERL_FLAG_LEGACY = erl:legacynames
ERL_FLAG_MAPS = erl:maps
endif
$(THRIFT_OMIT_FILE): test/Thrift_omit_with.thrift
grep -v omit $< >$@
.generated: $(THRIFT) $(THRIFT_FILES)
for f in $(THRIFT_FILES) ; do \
$(THRIFT) --gen $(ERL_FLAG) -o test $$f ; \
@ -64,6 +72,7 @@ uninstall:
clean:
rm -f .generated
rm -rf test/gen-erl/
rm -f $(THRIFT_OMIT_FILE)
$(REBAR) clean
maintainer-clean-local:
@ -74,6 +83,7 @@ EXTRA_DIST = \
src \
coding_standards.md \
rebar.config \
rebar.config.script \
rebar.test.config \
test \
README.md

View file

@ -1 +1,3 @@
Please follow [General Coding Standards](/doc/coding_standards.md)
Particularly for Erlang please follow the Erlang [Programming Rules and Conventions](http://www.erlang.se/doc/programming_rules.shtml).

View file

@ -20,12 +20,12 @@
-ifndef(THRIFT_PROTOCOL_INCLUDED).
-define(THRIFT_PROTOCOL_INCLUDED, true).
-record(protocol_message_begin, {name, type, seqid}).
-record(protocol_struct_begin, {name}).
-record(protocol_field_begin, {name, type, id}).
-record(protocol_map_begin, {ktype, vtype, size}).
-record(protocol_list_begin, {etype, size}).
-record(protocol_set_begin, {etype, size}).
-record(protocol_message_begin, {name :: string(), type :: integer(), seqid :: integer()}).
-record(protocol_struct_begin, {name :: string()}).
-record(protocol_field_begin, {name :: string(), type :: integer(), id :: integer()}).
-record(protocol_map_begin, {ktype :: integer(), vtype :: integer(), size :: integer()}).
-record(protocol_list_begin, {etype :: integer(), size :: integer()}).
-record(protocol_set_begin, {etype :: integer(), size :: integer()}).
-type tprot_header_val() :: #protocol_message_begin{}
| #protocol_struct_begin{}

View file

@ -1,5 +1,5 @@
{erl_opts, [{platform_define, "^R.*", otp16_or_less}, debug_info]}.
{deps, [
{meck, "", {git, "https://github.com/eproxus/meck.git", {tag, "0.8.2"}}}
{meck, "", {git, "https://github.com/eproxus/meck.git", {tag, "0.8.9"}}}
]}.

View file

@ -62,7 +62,8 @@ when is_integer(Len), Len >= 0 ->
Give = min(iolist_size(NewBinary), Len),
{Result, Remaining} = split_binary(NewBinary, Give),
{State#t_framed{wrapped = NewState, read_buffer = Remaining}, {ok, Result}};
Error -> Error
{NewState, Error} ->
{State#t_framed{wrapped = NewState}, Error}
end;
%% read of zero bytes
<<>> -> {State, {ok, <<>>}};

View file

@ -219,12 +219,11 @@ read_struct_loop(IProto0, SDict, RTuple) ->
end.
skip_field(FType, IProto0, SDict, RTuple) ->
FTypeAtom = thrift_protocol:typeid_to_atom(FType),
{IProto1, ok} = thrift_protocol:skip(IProto0, FTypeAtom),
{IProto1, ok} = skip(IProto0, typeid_to_atom(FType)),
{IProto2, ok} = read(IProto1, field_end),
read_struct_loop(IProto2, SDict, RTuple).
-spec skip(#protocol{}, any()) -> {#protocol{}, ok}.
-spec skip(#protocol{}, atom()) -> {#protocol{}, ok}.
skip(Proto0, struct) ->
{Proto1, ok} = read(Proto0, struct_begin),
@ -261,7 +260,7 @@ skip_struct_loop(Proto0) ->
?tType_STOP ->
{Proto1, ok};
_Else ->
{Proto2, ok} = skip(Proto1, Type),
{Proto2, ok} = skip(Proto1, typeid_to_atom(Type)),
{Proto3, ok} = read(Proto2, field_end),
skip_struct_loop(Proto3)
end.
@ -271,8 +270,8 @@ skip_map_loop(Proto0, Map = #protocol_map_begin{ktype = Ktype,
size = Size}) ->
case Size of
N when N > 0 ->
{Proto1, ok} = skip(Proto0, Ktype),
{Proto2, ok} = skip(Proto1, Vtype),
{Proto1, ok} = skip(Proto0, typeid_to_atom(Ktype)),
{Proto2, ok} = skip(Proto1, typeid_to_atom(Vtype)),
skip_map_loop(Proto2,
Map#protocol_map_begin{size = Size - 1});
0 -> {Proto0, ok}
@ -282,7 +281,7 @@ skip_set_loop(Proto0, Map = #protocol_set_begin{etype = Etype,
size = Size}) ->
case Size of
N when N > 0 ->
{Proto1, ok} = skip(Proto0, Etype),
{Proto1, ok} = skip(Proto0, typeid_to_atom(Etype)),
skip_set_loop(Proto1,
Map#protocol_set_begin{size = Size - 1});
0 -> {Proto0, ok}
@ -292,7 +291,7 @@ skip_list_loop(Proto0, Map = #protocol_list_begin{etype = Etype,
size = Size}) ->
case Size of
N when N > 0 ->
{Proto1, ok} = skip(Proto0, Etype),
{Proto1, ok} = skip(Proto0, typeid_to_atom(Etype)),
skip_list_loop(Proto1,
Map#protocol_list_begin{size = Size - 1});
0 -> {Proto0, ok}

View file

@ -36,7 +36,7 @@
terminate/2,
code_change/3 ]).
-record( state, { client = nil,
-record( state, { client = nil,
host,
port,
thrift_svc,
@ -226,9 +226,9 @@ timer_fun() ->
end.
-else.
timer_fun() ->
T1 = erlang:now(),
T1 = erlang:timestamp(),
fun() ->
T2 = erlang:now(),
T2 = erlang:timestamp(),
timer:now_diff(T2, T1)
end.
-endif.

View file

@ -103,11 +103,9 @@ read_exact(Transport = #t_transport{module = Module}, Len)
when is_integer(Len), Len >= 0 ->
case lists:keyfind(read_exact, 1, Module:module_info(exports)) of
{read_exact, 2} ->
io:fwrite("HAS EXACT"),
{NewState, Result} = Module:read_exact(Transport#t_transport.state, Len),
{Transport#t_transport{state = NewState}, Result};
_ ->
io:fwrite("~p NO EXACT", [Module]),
read(Transport, Len)
end.

View file

@ -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<test1> two // omit
}
struct test4 {
1: i32 one
2: map<i32,test1> two // omit
}

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -628,18 +628,6 @@ service_info_test_() ->
{struct, []},
thrift_test_thrift:function_info(testOneway, exceptions)
)},
{"blahBlah params", ?_assertEqual(
{struct, []},
second_service_thrift:function_info(blahBlah, params_type)
)},
{"blahBlah reply", ?_assertEqual(
{struct, []},
second_service_thrift:function_info(blahBlah, reply_type)
)},
{"blahBlah exceptions", ?_assertEqual(
{struct, []},
second_service_thrift:function_info(blahBlah, exceptions)
)},
{"secondtestString params", ?_assertEqual(
{struct, [{1, string}]},
second_service_thrift:function_info(secondtestString, params_type)