Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

use ets more efficiently - fixes #33

  • Loading branch information...
commit 6552703578705344bf5c35d637da8ad1fa409f3f 1 parent bd411a2
@hyperthunk hyperthunk authored
View
34 src/systest_config.erl
@@ -246,9 +246,10 @@ require_config(Key) ->
get_config(Key) ->
systest_log:log(framework,
"reading config key ~p~n", [Key]),
- case gen_server:call(?MODULE, {get_config, Key}) of
- [] -> noconfig;
- Config -> Config
+ case gen_server:call(?MODULE, {get_config, resources, Key}) of
+ [{Key, Config}] -> Config;
+ _ -> noconfig
+
end.
get_config(Key, Default) ->
@@ -258,9 +259,7 @@ get_config(Key, Default) ->
end.
get_config(Key, Node, Default) ->
- systest_log:log(framework,
- "reading config key ~p.~p~n", [Key, Node]),
- case gen_server:call(?MODULE, {get_config, Key, Node}) of
+ case get_config(Key) of
noconfig -> Default;
Nodes -> read(Node, Nodes, Default)
end.
@@ -328,21 +327,7 @@ handle_call({load, Id, Terms}, _From, State) ->
_T -> ok
end,
true = ets:insert(Id, Terms),
- {reply, ok, State};
-handle_call({load, Terms}, _From, State) ->
- Ids = [
- begin
- case ets:info(Id) of
- undefined -> ets:new(Id, [set, named_table,
- protected, {keypos, 1},
- {write_concurrency, false},
- {read_concurrency, true}]);
- _ -> ok
- end,
- true = ets:insert(Id, Config),
- Id
- end || {Id, Config} <- Terms],
- {reply, ok, Ids ++ State};
+ {reply, ok, [Id|State]};
handle_call({get_static, Key}, From, State) ->
handle_call({get_config, systest_static_cs, Key}, From, State);
handle_call({set_static, Key, Value}, _From, State) ->
@@ -350,13 +335,6 @@ handle_call({set_static, Key, Value}, _From, State) ->
{'EXIT', Reason} -> {reply, {error, Reason}, State};
true -> {reply, ok, State}
end;
-handle_call({get_config, Key}, _From, State) ->
- %% TODO: now that we hold dynamic tables in State,
- %% we *could* use lists:member(Key, State) instead...
- case catch(ets:tab2list(Key)) of
- {'EXIT', _Reason} -> {reply, noconfig, State};
- Result -> {reply, Result, State}
- end;
handle_call({get_config, Key, SubKey}, _From, State) ->
%% TODO: now that we hold dynamic tables in State,
%% we *could* use lists:member(Key, State) instead...
View
2  src/systest_runner.erl
@@ -223,7 +223,7 @@ preload_resources(Resources) ->
[begin
case file:consult(Resource) of
{ok, Terms} ->
- systest_config:load_config_terms(Terms);
+ systest_config:load_config_terms(resources, Terms);
Error ->
throw(Error)
end
View
2  test/systest_tests.erl
@@ -40,7 +40,7 @@ pre_loaded_config_test_() ->
systest:start(),
systest_config:start_link(),
{ok, Terms} = file:consult("../samples/test.config"),
- systest_config:load_config_terms(Terms),
+ systest_config:load_config_terms(resources, Terms),
[?_assertMatch({handling_detached_processes,
[{localhost,[yellow,blue]},{on_start,[]}]},
systest_config:sut_config(systest_cli_SUITE,
Please sign in to comment.
Something went wrong with that request. Please try again.