Author: dreiss
Date: Thu Jun 4 02:01:28 2009
New Revision: 781635
URL: http://svn.apache.org/viewvc?rev=781635&view=rev
Log:
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.
Modified:
incubator/thrift/trunk/lib/erl/src/thrift_client.erl
incubator/thrift/trunk/test/erl/src/test_tether.erl
Modified: incubator/thrift/trunk/lib/erl/src/thrift_client.erl
URL:
http://svn.apache.org/viewvc/incubator/thrift/trunk/lib/erl/src/thrift_client.erl?rev=781635&r1=781634&r2=781635&view=diff
==============================================================================
--- incubator/thrift/trunk/lib/erl/src/thrift_client.erl (original)
+++ incubator/thrift/trunk/lib/erl/src/thrift_client.erl Thu Jun 4 02:01:28
2009
@@ -109,16 +109,33 @@
start
end,
- case gen_server:Starter(?MODULE, [Service], []) of
- {ok, Pid} ->
- case gen_server:call(Pid, {connect, ProtocolFactory}) of
- ok ->
- {ok, Pid};
- Error ->
- Error
+ Connect =
+ case lists:keysearch(connect, 1, ClientOpts) of
+ {value, {connect, Choice}} ->
+ Choice;
+ _ ->
+ %% By default, connect at creation-time.
+ 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;
- Else ->
- Else
+ true ->
+ Started
end.
call(Client, Function, Args)
Modified: incubator/thrift/trunk/test/erl/src/test_tether.erl
URL:
http://svn.apache.org/viewvc/incubator/thrift/trunk/test/erl/src/test_tether.erl?rev=781635&r1=781634&r2=781635&view=diff
==============================================================================
--- incubator/thrift/trunk/test/erl/src/test_tether.erl (original)
+++ incubator/thrift/trunk/test/erl/src/test_tether.erl Thu Jun 4 02:01:28 2009
@@ -62,6 +62,9 @@
io:format("FAIL. Expected ~p more clients.~n", [N])
end.
+make_thrift_client(Opts) ->
+ thrift_client:start(fun()->ok end, thriftTest_thrift, Opts).
+
make_protocol_factory(Port) ->
{ok, TransportFactory} =
thrift_socket_transport:new_transport_factory(
@@ -73,9 +76,9 @@
test_start() ->
- {ok, Client1} = gen_server:start(thrift_client, [thriftTest_thrift], []),
+ {ok, Client1} = make_thrift_client([{connect, false}]),
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"),
try
gen_server:call(Client2, {connect, make_protocol_factory(2)}),
@@ -93,9 +96,9 @@
exit(die).
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},
- {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"),
try
gen_server:call(Client2, {connect, make_protocol_factory(2)}),