kura_pool_ets (kura v2.0.6)
View SourceETS-backed kura_pool implementation. Hands out opaque connection
refs from an ETS-tracked free list. Useful for:
- Conformance tests against the
kura_poolbehaviour without docker. - Unit tests of code that needs to lease/return connections but does not actually need to run SQL.
- A worked example for authors of new pool impls (the second impl is what proves a behaviour is real).
This pool does NOT speak any database protocol. The conn() value
returned from checkout/2 is an opaque reference that callers can
match on in tests but cannot pass to pgo or any other driver.
Pool layout
Each pool owns one ETS table, named after the pool atom. The table holds two rows:
{available, [ref()]}— free connection refs.{checked_out, #{ref() => pid()}}— leased refs and their owner.
pool_size from start_pool/2 opts determines how many refs are
pre-generated. Defaults to 1.
Example
{ok, _Pid} = kura_pool_ets:start_pool(my_test_pool, #{pool_size => 4}),
{ok, Conn, Token} = kura_pool_ets:checkout(my_test_pool, #{}),
%% ... use Conn ...
ok = kura_pool_ets:checkin(my_test_pool, Token),
ok = kura_pool_ets:stop_pool(my_test_pool).
Summary
Functions
Empty capability set. This pool does not speak any database protocol,
so it supports none of the standard SQL feature flags. Consumers that
require any capability via kura_capabilities:require/2 will refuse
to start when configured against this pool, which is the correct
behavior for a fake test pool.
Types
-type conn() :: reference().
Opaque connection ref. Tests may pattern-match on it; production code must not.
Functions
-spec capabilities() -> kura_capabilities:capability_set().
Empty capability set. This pool does not speak any database protocol,
so it supports none of the standard SQL feature flags. Consumers that
require any capability via kura_capabilities:require/2 will refuse
to start when configured against this pool, which is the correct
behavior for a fake test pool.
-spec checkin(kura_pool:name(), kura_pool:token()) -> ok.
-spec checkout(kura_pool:name(), kura_pool:checkout_opts()) -> {ok, kura_pool:conn(), kura_pool:token()} | {error, term()}.
-spec give_away(kura_pool:token(), pid(), term()) -> ok | {error, term()}.
-spec resize(kura_pool:name(), pos_integer()) -> ok | {error, term()}.
-spec start_pool(kura_pool:name(), kura_pool:opts()) -> {ok, pid()} | {error, term()}.
-spec stop_pool(kura_pool:name()) -> ok.