Sign Up
Log In
Log In
or
Sign Up
Places
All Projects
Status Monitor
Collapse sidebar
home:Ledest:erlang:18
pooler
pooler-1.5.2-git.patch
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File pooler-1.5.2-git.patch of Package pooler
diff --git a/Makefile b/Makefile index c4f2adf..06d5930 100644 --- a/Makefile +++ b/Makefile @@ -11,7 +11,8 @@ run: $(REBAR) @$(REBAR) as dev shell --apps pooler --config config/demo.config test: $(REBAR) - $(REBAR) eunit skip_deps=true verbose=3 + $(REBAR) eunit --cover skip_deps=true verbose=3 + $(REBAR) cover doc: $(REBAR) $(REBAR) as dev edoc diff --git a/rebar.config b/rebar.config index cf1e643..07ca0c1 100644 --- a/rebar.config +++ b/rebar.config @@ -22,8 +22,8 @@ warn_unused_function, warn_deprecated_function, - strict_validation, - warn_missing_spec + strict_validation + %, warn_missing_spec ]}. {deps, [ diff --git a/src/pooled_gs.erl b/src/pooled_gs.erl deleted file mode 100644 index 994a1d7..0000000 --- a/src/pooled_gs.erl +++ /dev/null @@ -1,122 +0,0 @@ -%% @doc A gen_server module that can be pooled by pooler. This module -%% is used to test and demo pooler and plays the role of the pooled -%% member. -%% -%% A pooled_gs is started with a `Type' which is intended to help -%% identify the members for testing multi-pool scenarios. Each -%% pooled_gs also sets a unique id. The type and id are retrieved -%% using `get_id/1'. --module(pooled_gs). --behaviour(gen_server). --define(SERVER, ?MODULE). - -%% ------------------------------------------------------------------ -%% API Function Exports -%% ------------------------------------------------------------------ - --export([start_link/1, - get_id/1, - ping/1, - ping_count/1, - crash/1, - error_on_call/1, - do_work/2, - stop/1 - ]). - -%% ------------------------------------------------------------------ -%% gen_server Function Exports -%% ------------------------------------------------------------------ - --export([init/1, handle_call/3, handle_cast/2, handle_info/2, - terminate/2, code_change/3]). - -%% ------------------------------------------------------------------ -%% API Function Definitions -%% ------------------------------------------------------------------ - -start_link(Args ={_Type}) -> - % not registered - gen_server:start_link(?MODULE, Args, []); - -start_link(Args ={_Type, _InitFun}) -> - % not registered - gen_server:start_link(?MODULE, Args, []). - -%% @doc return the type argument passed to this worker at start time -%% along with this worker's unique id. -get_id(S) -> - gen_server:call(S, get_id). - -%% @doc In processing this request, the server will sleep for a time -%% determined by a call to `random:uniform(T)'. Can be useful in -%% stress-testing the pool to simulate consumers taking a member out -%% of the pool for a varied request time. -do_work(S, T) -> - gen_server:call(S, {do_work, T}). - -ping(S) -> - gen_server:call(S, ping). - -ping_count(S) -> - gen_server:call(S, ping_count). - -crash(S) -> - gen_server:cast(S, crash), - sent_crash_request. - -error_on_call(S) -> - gen_server:call(S, error_on_call). - -stop(S) -> - gen_server:call(S, stop). - -%% ------------------------------------------------------------------ -%% gen_server Function Definitions -%% ------------------------------------------------------------------ --record(state, { - type = "", - id, - ping_count = 0 - }). - -init({Type}) -> - {ok, #state{type = Type, id = make_ref()}}; -init({Type, StartFun}) -> - StartFun(), - {ok, #state{type = Type, id = make_ref()}}. - - - -handle_call(get_id, _From, State) -> - {reply, {State#state.type, State#state.id}, State}; -handle_call({do_work, T}, _From, State) -> - Sleep = random:uniform(T), - timer:sleep(Sleep), - {reply, {ok, Sleep}, State}; -handle_call(ping, _From, #state{ping_count = C } = State) -> - State1 = State#state{ping_count = C + 1}, - {reply, pong, State1}; -handle_call(ping_count, _From, #state{ping_count = C } = State) -> - {reply, C, State}; -handle_call(error_on_call, _From, _State) -> - erlang:error({pooled_gs, requested_error}); -handle_call(stop, _From, State) -> - {stop, normal, stop_ok, State}; -handle_call(_Request, _From, State) -> - {noreply, ok, State}. - -handle_cast(crash, _State) -> - erlang:error({pooled_gs, requested_crash}); -handle_cast(_Msg, State) -> - {noreply, State}. - -handle_info(_Info, State) -> - {noreply, State}. - -terminate(_Reason, _State) -> - ok. - -code_change(_OldVsn, State, _Extra) -> - {ok, State}. - diff --git a/src/pooler.erl b/src/pooler.erl index 2d271ed..576b937 100644 --- a/src/pooler.erl +++ b/src/pooler.erl @@ -58,11 +58,6 @@ terminate/2, code_change/3]). -%% To help with testing internal functions --ifdef(TEST). --compile([export_all]). --endif. - %% ------------------------------------------------------------------ %% Application API %% ------------------------------------------------------------------ @@ -553,7 +548,8 @@ init_members_sync(N, #pool{name = PoolName} = Pool) -> {ok, Pool2} end. -collect_init_members(#pool{starting_members = []} = Pool) -> +collect_init_members(#pool{starting_members = Empty} = Pool) + when Empty =:= [] -> Pool; collect_init_members(#pool{member_start_timeout = StartTimeout} = Pool) -> Timeout = time_as_millis(StartTimeout), @@ -844,11 +840,6 @@ send_metric(#pool{name = PoolName, metrics_mod = MetricsMod, MetricName = pool_metric_exometer(PoolName, Label), MetricsMod:update_or_create(MetricName, Value, counter, []), ok; -send_metric(#pool{name = PoolName, metrics_mod = MetricsMod, - metrics_api = exometer}, Label, {dec, Value}, counter) -> - MetricName = pool_metric_exometer(PoolName, Label), - MetricsMod:update_or_create(MetricName, - Value, counter, []), - ok; % Exometer does not support 'history' type metrics right now. send_metric(#pool{name = _PoolName, metrics_mod = _MetricsMod, metrics_api = exometer}, _Label, _Value, history) -> @@ -932,9 +923,7 @@ terminate_pid(Pid, {Mod, Fun, Args}) when is_list(Args) -> terminate_pid(Pid, ?DEFAULT_STOP_MFA); _Result -> ok - end; -terminate_pid(Pid, _) -> - terminate_pid(Pid, ?DEFAULT_STOP_MFA). + end. do_call_free_members(Fun, Pids) -> [do_call_free_member(Fun, P) || P <- Pids]. diff --git a/src/pooler.hrl b/src/pooler.hrl index ffac0e0..22fb141 100644 --- a/src/pooler.hrl +++ b/src/pooler.hrl @@ -99,7 +99,7 @@ %% A queue of requestors for blocking take member requests queued_requestors = queue:new() :: p_requestor_queue(), %% The max depth of the queue - queue_max = 50 + queue_max = 50 :: non_neg_integer() }). -define(gv(X, Y), proplists:get_value(X, Y)). diff --git a/src/pooler_starter.erl b/src/pooler_starter.erl index 52141e4..f3e4dac 100644 --- a/src/pooler_starter.erl +++ b/src/pooler_starter.erl @@ -6,7 +6,6 @@ -behaviour(gen_server). -include("pooler.hrl"). --include_lib("eunit/include/eunit.hrl"). %% ------------------------------------------------------------------ %% API Function Exports @@ -29,11 +28,6 @@ terminate/2, code_change/3]). -%% To help with testing internal functions --ifdef(TEST). --compile([export_all]). --endif. - %% ------------------------------------------------------------------ %% API Function Definitions %% ------------------------------------------------------------------ @@ -84,9 +78,9 @@ stop_member_async(Pid) -> %% ------------------------------------------------------------------ %% gen_server Function Definitions %% ------------------------------------------------------------------ --record(starter, {pool, - parent, - msg}). +-record(starter, {pool :: #pool{}, + parent :: pid() | atom(), + msg :: term()}). -spec init({#pool{}, pid() | atom()}) -> {'ok', #starter{}, 0}. init({Pool, Parent}) -> diff --git a/test/fake_metrics.erl b/test/fake_metrics.erl index fdc8b72..61d820e 100644 --- a/test/fake_metrics.erl +++ b/test/fake_metrics.erl @@ -48,7 +48,7 @@ get_metrics() -> %% gen_server Function Definitions %% ------------------------------------------------------------------ -record(state, { - metrics = [] + metrics = [] :: list() }). init(_) -> diff --git a/test/pooled_gs.erl b/test/pooled_gs.erl new file mode 100644 index 0000000..abac511 --- /dev/null +++ b/test/pooled_gs.erl @@ -0,0 +1,122 @@ +%% @doc A gen_server module that can be pooled by pooler. This module +%% is used to test and demo pooler and plays the role of the pooled +%% member. +%% +%% A pooled_gs is started with a `Type' which is intended to help +%% identify the members for testing multi-pool scenarios. Each +%% pooled_gs also sets a unique id. The type and id are retrieved +%% using `get_id/1'. +-module(pooled_gs). +-behaviour(gen_server). +-define(SERVER, ?MODULE). + +%% ------------------------------------------------------------------ +%% API Function Exports +%% ------------------------------------------------------------------ + +-export([start_link/1, + get_id/1, + ping/1, + ping_count/1, + crash/1, + error_on_call/1, + do_work/2, + stop/1 + ]). + +%% ------------------------------------------------------------------ +%% gen_server Function Exports +%% ------------------------------------------------------------------ + +-export([init/1, handle_call/3, handle_cast/2, handle_info/2, + terminate/2, code_change/3]). + +%% ------------------------------------------------------------------ +%% API Function Definitions +%% ------------------------------------------------------------------ + +start_link(Args ={_Type}) -> + % not registered + gen_server:start_link(?MODULE, Args, []); + +start_link(Args ={_Type, _InitFun}) -> + % not registered + gen_server:start_link(?MODULE, Args, []). + +%% @doc return the type argument passed to this worker at start time +%% along with this worker's unique id. +get_id(S) -> + gen_server:call(S, get_id). + +%% @doc In processing this request, the server will sleep for a time +%% determined by a call to `random:uniform(T)'. Can be useful in +%% stress-testing the pool to simulate consumers taking a member out +%% of the pool for a varied request time. +do_work(S, T) -> + gen_server:call(S, {do_work, T}). + +ping(S) -> + gen_server:call(S, ping). + +ping_count(S) -> + gen_server:call(S, ping_count). + +crash(S) -> + gen_server:cast(S, crash), + sent_crash_request. + +error_on_call(S) -> + gen_server:call(S, error_on_call). + +stop(S) -> + gen_server:call(S, stop). + +%% ------------------------------------------------------------------ +%% gen_server Function Definitions +%% ------------------------------------------------------------------ +-record(state, { + type = "" :: string(), + id :: reference(), + ping_count = 0 :: non_neg_integer() + }). + +init({Type}) -> + {ok, #state{type = Type, id = make_ref()}}; +init({Type, StartFun}) -> + StartFun(), + {ok, #state{type = Type, id = make_ref()}}. + + + +handle_call(get_id, _From, State) -> + {reply, {State#state.type, State#state.id}, State}; +handle_call({do_work, T}, _From, State) -> + Sleep = random:uniform(T), + timer:sleep(Sleep), + {reply, {ok, Sleep}, State}; +handle_call(ping, _From, #state{ping_count = C } = State) -> + State1 = State#state{ping_count = C + 1}, + {reply, pong, State1}; +handle_call(ping_count, _From, #state{ping_count = C } = State) -> + {reply, C, State}; +handle_call(error_on_call, _From, _State) -> + erlang:error({pooled_gs, requested_error}); +handle_call(stop, _From, State) -> + {stop, normal, stop_ok, State}; +handle_call(_Request, _From, State) -> + {noreply, ok, State}. + +handle_cast(crash, _State) -> + erlang:error({pooled_gs, requested_crash}); +handle_cast(_Msg, State) -> + {noreply, State}. + +handle_info(_Info, State) -> + {noreply, State}. + +terminate(_Reason, _State) -> + ok. + +code_change(_OldVsn, State, _Extra) -> + {ok, State}. +
Locations
Projects
Search
Status Monitor
Help
OpenBuildService.org
Documentation
API Documentation
Code of Conduct
Contact
Support
@OBShq
Terms
openSUSE Build Service is sponsored by
The Open Build Service is an
openSUSE project
.
Sign Up
Log In
Places
Places
All Projects
Status Monitor