mirror of
https://github.com/valitydev/thrift.git
synced 2024-11-07 02:45:22 +00:00
THRIFT-211. erlang: Allow clients to be created without connecting
Add a client option to prevent the initial connect (which causes the protocol factory to be ignored). The main use case for this is testing the proper handling of clients that cannot connect. Update the tether test to use this feature instead of a raw gen_server:start call. git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@781635 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
5e530af587
commit
bb97fd90a5
@ -109,16 +109,33 @@ start(ProtocolFactory, Service, ClientOpts)
|
|||||||
start
|
start
|
||||||
end,
|
end,
|
||||||
|
|
||||||
case gen_server:Starter(?MODULE, [Service], []) of
|
Connect =
|
||||||
{ok, Pid} ->
|
case lists:keysearch(connect, 1, ClientOpts) of
|
||||||
case gen_server:call(Pid, {connect, ProtocolFactory}) of
|
{value, {connect, Choice}} ->
|
||||||
ok ->
|
Choice;
|
||||||
{ok, Pid};
|
_ ->
|
||||||
Error ->
|
%% By default, connect at creation-time.
|
||||||
Error
|
true
|
||||||
|
end,
|
||||||
|
|
||||||
|
|
||||||
|
Started = gen_server:Starter(?MODULE, [Service], []),
|
||||||
|
|
||||||
|
if
|
||||||
|
Connect ->
|
||||||
|
case Started of
|
||||||
|
{ok, Pid} ->
|
||||||
|
case gen_server:call(Pid, {connect, ProtocolFactory}) of
|
||||||
|
ok ->
|
||||||
|
{ok, Pid};
|
||||||
|
Error ->
|
||||||
|
Error
|
||||||
|
end;
|
||||||
|
Else ->
|
||||||
|
Else
|
||||||
end;
|
end;
|
||||||
Else ->
|
true ->
|
||||||
Else
|
Started
|
||||||
end.
|
end.
|
||||||
|
|
||||||
call(Client, Function, Args)
|
call(Client, Function, Args)
|
||||||
|
@ -62,6 +62,9 @@ check_extras(N) ->
|
|||||||
io:format("FAIL. Expected ~p more clients.~n", [N])
|
io:format("FAIL. Expected ~p more clients.~n", [N])
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
make_thrift_client(Opts) ->
|
||||||
|
thrift_client:start(fun()->ok end, thriftTest_thrift, Opts).
|
||||||
|
|
||||||
make_protocol_factory(Port) ->
|
make_protocol_factory(Port) ->
|
||||||
{ok, TransportFactory} =
|
{ok, TransportFactory} =
|
||||||
thrift_socket_transport:new_transport_factory(
|
thrift_socket_transport:new_transport_factory(
|
||||||
@ -73,9 +76,9 @@ make_protocol_factory(Port) ->
|
|||||||
|
|
||||||
|
|
||||||
test_start() ->
|
test_start() ->
|
||||||
{ok, Client1} = gen_server:start(thrift_client, [thriftTest_thrift], []),
|
{ok, Client1} = make_thrift_client([{connect, false}]),
|
||||||
tester ! {client, unlinked, Client1},
|
tester ! {client, unlinked, Client1},
|
||||||
{ok, Client2} = gen_server:start(thrift_client, [thriftTest_thrift], []),
|
{ok, Client2} = make_thrift_client([{connect, false}]),
|
||||||
io:format("PASS. Unlinked clients created.~n"),
|
io:format("PASS. Unlinked clients created.~n"),
|
||||||
try
|
try
|
||||||
gen_server:call(Client2, {connect, make_protocol_factory(2)}),
|
gen_server:call(Client2, {connect, make_protocol_factory(2)}),
|
||||||
@ -93,9 +96,9 @@ test_start() ->
|
|||||||
exit(die).
|
exit(die).
|
||||||
|
|
||||||
test_linked() ->
|
test_linked() ->
|
||||||
{ok, Client1} = gen_server:start_link(thrift_client, [thriftTest_thrift], []),
|
{ok, Client1} = make_thrift_client([{connect, false}, {monitor, link}]),
|
||||||
tester ! {client, linked, Client1},
|
tester ! {client, linked, Client1},
|
||||||
{ok, Client2} = gen_server:start_link(thrift_client, [thriftTest_thrift], []),
|
{ok, Client2} = make_thrift_client([{connect, false}, {monitor, link}]),
|
||||||
io:format("PASS. Linked clients created.~n"),
|
io:format("PASS. Linked clients created.~n"),
|
||||||
try
|
try
|
||||||
gen_server:call(Client2, {connect, make_protocol_factory(2)}),
|
gen_server:call(Client2, {connect, make_protocol_factory(2)}),
|
||||||
|
Loading…
Reference in New Issue
Block a user