Browse Source

Rename pidq => pooler

Seth Falcon 14 years ago
parent
commit
9d8b1d2cca

+ 0 - 17
src/pidq_sup.erl

@@ -1,17 +0,0 @@
--module(pidq_sup).
-
--behaviour(supervisor).
-
--export([start_link/0, init/1]).
-
-start_link() ->
-    supervisor:start_link({local, ?MODULE}, ?MODULE, []).
-
-init([]) ->
-    Config = application:get_all_env(),
-    Pidq = {pidq, {pidq, start_link, [Config]},
-            permanent, 5000, worker, [pidq]},
-    PidqPool = {pidq_pool_sup, {pidq_pool_sup, start_link, []},
-                permanent, 5000, supervisor, [pidq_pool_sup]},
-    {ok, {{one_for_one, 5, 10}, [PidqPool, Pidq]}}.
-

+ 2 - 2
src/pidq.app.src → src/pooler.app.src

@@ -1,4 +1,4 @@
-{application, pidq,
+{application, pooler,
  [
   {description, ""},
   {vsn, git},
@@ -7,6 +7,6 @@
                   kernel,
                   stdlib
                  ]},
-  {mod, { pidq_app, []}},
+  {mod, { pooler_app, []}},
   {env, []}
  ]}.

+ 2 - 2
src/pidq.erl → src/pooler.erl

@@ -1,4 +1,4 @@
--module(pidq).
+-module(pooler).
 -behaviour(gen_server).
 -define(SERVER, ?MODULE).
 
@@ -92,7 +92,7 @@ init(Config) ->
     PoolSups =
         lists:map(
           fun(#pool{name = Name, start_mfa = MFA}) ->
-                  {ok, SupPid} = supervisor:start_child(pidq_pool_sup, [MFA]),
+                  {ok, SupPid} = supervisor:start_child(pooler_pool_sup, [MFA]),
                   {Name, SupPid}
           end, PoolRecs),
     State0 = #state{npools = length(Pools),

+ 2 - 2
src/pidq_app.erl → src/pooler_app.erl

@@ -1,4 +1,4 @@
--module(pidq_app).
+-module(pooler_app).
 
 -behaviour(application).
 
@@ -10,7 +10,7 @@
 %% ===================================================================
 
 start(_StartType, _StartArgs) ->
-    case pidq_sup:start_link() of
+    case pooler_sup:start_link() of
         {ok, Pid} -> {ok, Pid};
         Other -> {error, Other}
     end.

+ 4 - 4
src/pidq_pool_sup.erl → src/pooler_pool_sup.erl

@@ -1,4 +1,4 @@
--module(pidq_pool_sup).
+-module(pooler_pool_sup).
 
 -behaviour(supervisor).
 
@@ -8,8 +8,8 @@ start_link() ->
     supervisor:start_link({local, ?MODULE}, ?MODULE, []).
 
 init([]) ->
-    Worker = {pidq_pooled_worker_sup,
-              {pidq_pooled_worker_sup, start_link, []},
-              temporary, 5000, supervisor, [pidq_pooled_worker_sup]},
+    Worker = {pooler_pooled_worker_sup,
+              {pooler_pooled_worker_sup, start_link, []},
+              temporary, 5000, supervisor, [pooler_pooled_worker_sup]},
     Restart = {simple_one_for_one, 1, 1},
     {ok, {Restart, [Worker]}}.

+ 1 - 1
src/pidq_pooled_worker_sup.erl → src/pooler_pooled_worker_sup.erl

@@ -1,4 +1,4 @@
--module(pidq_pooled_worker_sup).
+-module(pooler_pooled_worker_sup).
 
 -behaviour(supervisor).
 

+ 17 - 0
src/pooler_sup.erl

@@ -0,0 +1,17 @@
+-module(pooler_sup).
+
+-behaviour(supervisor).
+
+-export([start_link/0, init/1]).
+
+start_link() ->
+    supervisor:start_link({local, ?MODULE}, ?MODULE, []).
+
+init([]) ->
+    Config = application:get_all_env(),
+    Pooler = {pooler, {pooler, start_link, [Config]},
+            permanent, 5000, worker, [pooler]},
+    PoolerPool = {pooler_pool_sup, {pooler_pool_sup, start_link, []},
+                permanent, 5000, supervisor, [pooler_pool_sup]},
+    {ok, {{one_for_one, 5, 10}, [PoolerPool, Pooler]}}.
+

+ 31 - 31
test/pidq_test.erl → test/pooler_test.erl

@@ -1,16 +1,16 @@
--module(pidq_test).
+-module(pooler_test).
 
 -include_lib("eunit/include/eunit.hrl").
 
 -compile([export_all]).
 
-% The `user' processes represent users of the pidq library.  A user
+% The `user' processes represent users of the pooler library.  A user
 % process will take a pid, report details on the pid it has, release
 % and take a new pid, stop cleanly, and crash.
 
 start_user() ->
     spawn(fun() ->
-                  TC = pidq:take_pid(),
+                  TC = pooler:take_pid(),
                   user_loop(TC)
           end).
 
@@ -42,17 +42,17 @@ user_loop(MyTC) ->
             From ! pooled_gs:ping_count(MyTC),
             user_loop(MyTC);
         new_tc ->
-            pidq:return_pid(MyTC, ok),
-            MyNewTC = pidq:take_pid(),
+            pooler:return_pid(MyTC, ok),
+            MyNewTC = pooler:take_pid(),
             user_loop(MyNewTC);
         stop ->
-            pidq:return_pid(MyTC, ok),
+            pooler:return_pid(MyTC, ok),
             stopped;
         crash ->
             erlang:error({user_loop, kaboom})
     end.
 
-% The `tc' processes represent the pids tracked by pidq for testing.
+% The `tc' processes represent the pids tracked by pooler for testing.
 % They have a type and an ID and can report their type and ID and
 % stop.
 
@@ -102,7 +102,7 @@ assert_tc_valid(Pid) ->
 %     user_crash(User),
 %     stop_tc(Pid1).
 
-pidq_basics_test_() ->
+pooler_basics_test_() ->
     {foreach,
      % setup
      fun() ->
@@ -111,25 +111,25 @@ pidq_basics_test_() ->
                        {init_count, 2},
                        {start_mfa,
                         {pooled_gs, start_link, [{"type-0"}]}}]],
-             application:set_env(pidq, pools, Pools),
-             application:start(pidq)
+             application:set_env(pooler, pools, Pools),
+             application:start(pooler)
      end,
      fun(_X) ->
-             application:stop(pidq)
+             application:stop(pooler)
      end,
      [
       {"take and return one",
        fun() ->
-               P = pidq:take_pid(),
+               P = pooler:take_pid(),
                ?assertMatch({"type-0", _Id}, pooled_gs:get_id(P)),
-               ok = pidq:return_pid(P, ok)
+               ok = pooler:return_pid(P, ok)
        end},
 
       {"pids are created on demand until max",
        fun() ->
-               Pids = [pidq:take_pid(), pidq:take_pid(), pidq:take_pid()],
-               ?assertMatch(error_no_pids, pidq:take_pid()),
-               ?assertMatch(error_no_pids, pidq:take_pid()),
+               Pids = [pooler:take_pid(), pooler:take_pid(), pooler:take_pid()],
+               ?assertMatch(error_no_pids, pooler:take_pid()),
+               ?assertMatch(error_no_pids, pooler:take_pid()),
                PRefs = [ R || {_T, R} <- [ pooled_gs:get_id(P) || P <- Pids ] ],
                % no duplicates
                ?assertEqual(length(PRefs), length(lists:usort(PRefs)))
@@ -138,19 +138,19 @@ pidq_basics_test_() ->
 
       {"pids are reused most recent return first",
        fun() ->
-               P1 = pidq:take_pid(),
-               P2 = pidq:take_pid(),
+               P1 = pooler:take_pid(),
+               P2 = pooler:take_pid(),
                ?assertNot(P1 == P2),
-               ok = pidq:return_pid(P1, ok),
-               ok = pidq:return_pid(P2, ok),
+               ok = pooler:return_pid(P1, ok),
+               ok = pooler:return_pid(P2, ok),
                % pids are reused most recent first
-               ?assertEqual(P2, pidq:take_pid()),
-               ?assertEqual(P1, pidq:take_pid())
+               ?assertEqual(P2, pooler:take_pid()),
+               ?assertEqual(P1, pooler:take_pid())
        end},
 
       {"if a pid crashes it is replaced",
        fun() ->
-               Pids0 = [pidq:take_pid(), pidq:take_pid(), pidq:take_pid()],
+               Pids0 = [pooler:take_pid(), pooler:take_pid(), pooler:take_pid()],
                Ids0 = [ pooled_gs:get_id(P) || P <- Pids0 ],
                % crash them all
                [ pooled_gs:crash(P) || P <- Pids0 ],
@@ -162,10 +162,10 @@ pidq_basics_test_() ->
 
       {"if a pid is returned with bad status it is replaced",
        fun() ->
-               Pids0 = [pidq:take_pid(), pidq:take_pid(), pidq:take_pid()],
+               Pids0 = [pooler:take_pid(), pooler:take_pid(), pooler:take_pid()],
                Ids0 = [ pooled_gs:get_id(P) || P <- Pids0 ],
                % return them all marking as bad
-               [ pidq:return_pid(P, fail) || P <- Pids0 ],
+               [ pooler:return_pid(P, fail) || P <- Pids0 ],
                Pids1 = get_n_pids(3, []),
                Ids1 = [ pooled_gs:get_id(P) || P <- Pids1 ],
                [ ?assertNot(lists:member(I, Ids0)) || I <- Ids1 ]
@@ -185,7 +185,7 @@ pidq_basics_test_() ->
      ]}.
 
 
-pidq_integration_test_() ->
+pooler_integration_test_() ->
     {foreach,
      % setup
      fun() ->
@@ -194,15 +194,15 @@ pidq_integration_test_() ->
                        {init_count, 10},
                        {start_mfa,
                         {pooled_gs, start_link, [{"type-0"}]}}]],
-             application:set_env(pidq, pools, Pools),
-             application:start(pidq),
+             application:set_env(pooler, pools, Pools),
+             application:start(pooler),
              Users = [ start_user() || _X <- lists:seq(1, 10) ],
              Users
      end,
      % cleanup
      fun(Users) ->
              [ user_stop(U) || U <- Users ],
-             application:stop(pidq)
+             application:stop(pooler)
      end,
      %
      [
@@ -243,12 +243,12 @@ pidq_integration_test_() ->
     }.
 
 % testing crash recovery means race conditions when either pids
-% haven't yet crashed or pidq hasn't recovered.  So this helper loops
+% haven't yet crashed or pooler hasn't recovered.  So this helper loops
 % forver until N pids are obtained, ignoring error_no_pids.
 get_n_pids(0, Acc) ->
     Acc;
 get_n_pids(N, Acc) ->
-    case pidq:take_pid() of
+    case pooler:take_pid() of
         error_no_pids ->
             get_n_pids(N, Acc);
         Pid ->