Skip to content

Commit

Permalink
Merge pull request #94 from inaka/jfacorro.51.better.wpool.overrun.se…
Browse files Browse the repository at this point in the history
…ttings

[#51] Better overrun defaults.
  • Loading branch information
Brujo Benavides committed Nov 3, 2014
2 parents 573489f + 54cc503 commit 25248af
Show file tree
Hide file tree
Showing 6 changed files with 163 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ ERLC_OPTS += +warn_export_vars +warn_exported_vars +warn_missing_spec +warn_unty
# Commont Test Config

TEST_ERLC_OPTS += +'{parse_transform, lager_transform}'
CT_SUITES = conditional_logic
CT_SUITES = sumo_config conditional_logic
CT_OPTS = -s emysql -s sumo_db -erl_args -config test/test.config

test-shell: app
Expand Down
6 changes: 6 additions & 0 deletions src/sumo_internal.erl
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@
%%% API for conditional logic.
-export([check_operator/1]).

-export([report_overrun/1]).

-opaque schema() :: #sumo_schema{}.
-opaque doc() :: #sumo_doc{}.
-opaque field() :: #sumo_field{}.
Expand Down Expand Up @@ -215,3 +217,7 @@ check_operator('==') -> ok;
check_operator('/=') -> ok;
check_operator('like') -> ok;
check_operator(Op) -> throw({unknown_operator, Op}).

-spec report_overrun(term()) -> ok.
report_overrun(Report) ->
lager:error("~p", [Report]).
4 changes: 2 additions & 2 deletions src/sumo_repo.erl
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@
start_link(Name, Module, Options) ->
Poolsize = proplists:get_value(workers, Options, 100),
WPoolConfigOpts = application:get_env(sumo_db, wpool_opts, []),
WPoolOptions = [ {overrun_warning, 30000}
, {overrun_handler, {error_logger, warning_report}}
WPoolOptions = [ {overrun_warning, 5000}
, {overrun_handler, {sumo_internal, report_overrun}}
, {workers, Poolsize}
, {worker, {?MODULE, [Module, Options]}}
],
Expand Down
51 changes: 51 additions & 0 deletions test/sumo_config_SUITE.erl
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
-module(sumo_config_SUITE).

-export([
all/0,
init_per_suite/1,
end_per_suite/1
]).

-export([
check_overrun_handler/1
]).

-define(EXCLUDED_FUNS,
[
module_info,
all,
test,
init_per_suite,
end_per_suite,
log
]).

-type config() :: [{atom(), term()}].

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Common test
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

-spec all() -> [atom()].
all() ->
Exports = ?MODULE:module_info(exports),
[F || {F, _} <- Exports, not lists:member(F, ?EXCLUDED_FUNS)].

-spec init_per_suite(config()) -> config().
init_per_suite(Config) ->
application:ensure_all_started(emysql),
application:ensure_all_started(emongo),
application:ensure_all_started(sumo_db),

Config.

-spec end_per_suite(config()) -> config().
end_per_suite(Config) ->
Config.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% Exported Tests Functions
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

check_overrun_handler(_Config) ->
sumo:call(sumo_test_people, takes_too_long, []).
101 changes: 101 additions & 0 deletions test/sumo_test_repo.erl
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% @author Juan Facorro <juan.facorro@inakanetworks.com>
%%% @doc Sumo DB repo
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-module(sumo_test_repo).

-behaviour(sumo_repo).

-include_lib("emysql/include/emysql.hrl").

%%% Default repo functions.
-export(
[ init/1
, create_schema/2
, delete/3
, delete_all/2
, delete_by/3
, execute/2
, execute/3
, find_all/2
, find_all/5
, find_by/3
, find_by/5
, persist/2
]).

%%% Custom repo functions.
-export([
takes_too_long/2
]).

-define(DEG2RAD, 0.017453292519943295).

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% sumo_repo default functions
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%% should be sumo_repo_mysql:state(), we miss the -extends directive
-type state() :: term().

-spec init(term()) -> {ok, state()}.
-spec persist(sumo_internal:doc(), state()) ->
sumo_repo:result(sumo_internal:doc(), state()).
-spec delete(sumo:schema_name(), term(), state()) ->
sumo_repo:result(sumo_repo:affected_rows(), state()).
-spec delete_by(sumo:schema_name(), sumo:conditions(), state()) ->
sumo_repo:result(sumo_repo:affected_rows(), state()).
-spec delete_all(sumo:schema_name(), state()) ->
sumo_repo:result(sumo_repo:affected_rows(), state()).
-spec find_by(sumo:schema_name(), sumo:conditions(), state()) ->
sumo_repo:result([sumo_internal:doc()], state()).
-spec find_by(sumo:schema_name(), sumo:conditions(), non_neg_integer(),
non_neg_integer(), state()) ->
sumo_repo:result([sumo_internal:doc()], state()).
-spec create_schema(sumo:schema(), state()) -> sumo_repo:result(state()).

init(Options) ->
sumo_repo_mysql:init(Options).

create_schema(Schema, State) ->
sumo_repo_mysql:create_schema(Schema, State).

delete(DocName, Id, State) ->
sumo_repo_mysql:delete(DocName, Id, State).

delete_all(DocName, State) ->
sumo_repo_mysql:delete_all(DocName, State).

delete_by(DocName, Conditions, State) ->
sumo_repo_mysql:delete_by(DocName, Conditions, State).

execute(Query, State) ->
sumo_repo_mysql:execute(Query, State).

execute(Query, Args, State) ->
sumo_repo_mysql:execute(Query, Args, State).

find_all(DocName, State) ->
sumo_repo_mysql:find_all(DocName, State).

find_all(DocName, OrderField, Limit, Offset, State) ->
sumo_repo_mysql:find_all(DocName, OrderField, Limit, Offset, State).

find_by(DocName, Conditions, State) ->
sumo_repo_mysql:find_by(DocName, Conditions, State).

find_by(DocName, Conditions, Limit, Offset, State) ->
sumo_repo_mysql:find_by(DocName, Conditions, Limit, Offset, State).

persist(Doc, State) ->
sumo_repo_mysql:persist(Doc, State).

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% sumo_repo custom functions
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

-spec takes_too_long(atom(), term()) ->
[thoughtz_thoughtz:thought()].
takes_too_long(_DocName, State) ->
timer:sleep(1000),
{ok, {docs, []}, State}.
3 changes: 2 additions & 1 deletion test/test.config
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
{
sumo_db,
[
{wpool_opts, [{overrun_warning, 100}]},
{log_queries, true},
{query_timeout, 30000},
{storage_backends,
Expand All @@ -27,7 +28,7 @@
},
{repositories,
[{sumo_test_mysql,
sumo_repo_mysql,
sumo_test_repo,
[{storage_backend, sumo_test_backend},
{workers, 10}]
},
Expand Down

0 comments on commit 25248af

Please sign in to comment.