make riak_kv_wterl_backend start the wterl app

This commit is contained in:
Steve Vinoski 2012-03-30 21:01:24 -04:00
parent ea3e73c0d7
commit 29acf9df7a
2 changed files with 43 additions and 47 deletions

View file

@ -87,6 +87,17 @@ start(Partition, Config) ->
lager:error("Failed to create wterl dir: data_root is not set"),
{error, data_root_unset};
DataRoot ->
AppStart = case application:start(wterl) of
ok ->
ok;
{error, {already_started, _}} ->
ok;
{error, Reason} ->
lager:error("Failed to start wterl: ~p", [Reason]),
{error, Reason}
end,
case AppStart of
ok ->
ok = filelib:ensure_dir(filename:join(DataRoot, "x")),
case wterl_conn:open(DataRoot) of
{ok, ConnRef} ->
@ -100,10 +111,13 @@ start(Partition, Config) ->
table=Table,
session=SRef,
partition=Partition}};
{error, Reason} ->
{error, ConnReason}=ConnError ->
lager:error("Failed to start wterl backend: ~p\n",
[Reason]),
{error, Reason}
[ConnReason]),
ConnError
end;
Error ->
Error
end
end.
@ -425,35 +439,13 @@ fetch_status(Cursor, {ok, Stat}, Acc) ->
-ifdef(TEST).
simple_test_() ->
{spawn, [{setup, SF, CF, TF}]} = riak_kv_backend:standard_test(?MODULE, []),
{setup,
fun() ->
?assertCmd("rm -rf test/wterl-backend"),
application:set_env(wterl, data_root, "test/wterl-backend"),
application:start(wterl),
SF()
end,
fun(X) ->
CF(X),
application:stop(wterl)
end,
fun(X) -> TF(X) end}.
riak_kv_backend:standard_test(?MODULE, []).
custom_config_test_() ->
{spawn, [{setup, SF, CF, TF}]} = riak_kv_backend:standard_test(
?MODULE,
[{data_root, "test/wterl-backend"}]),
{setup,
fun() ->
?assertCmd("rm -rf test/wterl-backend"),
application:set_env(wterl, data_root, ""),
application:start(wterl),
SF()
end,
fun(X) ->
CF(X),
application:stop(wterl)
end,
fun(X) -> TF(X) end}.
riak_kv_backend:standard_test(?MODULE, [{data_root, "test/wterl-backend"}]).
-endif.

View file

@ -170,8 +170,12 @@ simple_test_() ->
fun() ->
?assertCmd("rm -rf " ++ ?DATADIR),
?assertMatch(ok, filelib:ensure_dir(filename:join(?DATADIR, "x"))),
{ok, Pid} = start_link(),
case start_link() of
{ok, Pid} ->
Pid;
{error, {already_started, Pid}} ->
Pid
end
end,
fun(_) ->
stop()