2019-05-06 13:19:41 +00:00
|
|
|
-module(dmt_client_cache_SUITE).
|
2020-10-14 09:38:41 +00:00
|
|
|
|
2019-05-06 13:19:41 +00:00
|
|
|
-include_lib("common_test/include/ct.hrl").
|
|
|
|
|
|
|
|
-export([all/0]).
|
|
|
|
-export([groups/0]).
|
|
|
|
-export([init_per_suite/1]).
|
|
|
|
-export([end_per_suite/1]).
|
|
|
|
|
|
|
|
-behaviour(dmt_client_backend).
|
|
|
|
|
|
|
|
-export([commit/3]).
|
|
|
|
-export([checkout/2]).
|
|
|
|
-export([checkout_object/3]).
|
|
|
|
-export([pull_range/3]).
|
|
|
|
|
|
|
|
-export([get_snapshot_success/1]).
|
|
|
|
-export([snapshot_not_found/1]).
|
|
|
|
-export([woody_error/1]).
|
|
|
|
-export([object_not_found/1]).
|
|
|
|
|
2022-06-20 08:17:22 +00:00
|
|
|
-include_lib("damsel/include/dmsl_domain_conf_thrift.hrl").
|
|
|
|
-include_lib("damsel/include/dmsl_domain_thrift.hrl").
|
2019-05-06 13:19:41 +00:00
|
|
|
|
2022-06-20 08:17:22 +00:00
|
|
|
-define(NOTFOUND_VERSION, 1).
|
|
|
|
-define(UNAVAILABLE_VERSION, 2).
|
|
|
|
-define(EXISTING_VERSION, 42).
|
2019-05-06 13:19:41 +00:00
|
|
|
|
|
|
|
-type config() :: [tuple()].
|
|
|
|
-type testcase_or_group() :: atom() | {group, atom()}.
|
|
|
|
|
2022-06-20 08:17:22 +00:00
|
|
|
-define(TESTS_COUNT, 100).
|
2019-05-06 13:19:41 +00:00
|
|
|
|
|
|
|
%%% Common test callbacks
|
|
|
|
|
2020-10-14 09:38:41 +00:00
|
|
|
-spec all() -> [testcase_or_group()].
|
2019-05-06 13:19:41 +00:00
|
|
|
all() ->
|
|
|
|
[
|
|
|
|
{group, main}
|
|
|
|
].
|
|
|
|
|
2020-10-14 09:38:41 +00:00
|
|
|
-spec groups() -> [{atom(), list(), [testcase_or_group()]}].
|
2019-05-06 13:19:41 +00:00
|
|
|
groups() ->
|
|
|
|
[
|
|
|
|
{main, [parallel, shuffle], [
|
|
|
|
{group, get_snapshot_success},
|
|
|
|
{group, snapshot_not_found},
|
|
|
|
{group, woody_error},
|
|
|
|
{group, object_not_found},
|
|
|
|
{group, mixed}
|
|
|
|
]},
|
2022-06-20 08:17:22 +00:00
|
|
|
{get_snapshot_success, [parallel], lists:duplicate(?TESTS_COUNT, get_snapshot_success)},
|
|
|
|
{snapshot_not_found, [parallel], lists:duplicate(?TESTS_COUNT, snapshot_not_found)},
|
|
|
|
{woody_error, [parallel], lists:duplicate(?TESTS_COUNT, woody_error)},
|
|
|
|
{object_not_found, [parallel], lists:duplicate(?TESTS_COUNT, object_not_found)},
|
2019-05-06 13:19:41 +00:00
|
|
|
{mixed, [parallel, shuffle],
|
2022-06-20 08:17:22 +00:00
|
|
|
lists:duplicate(?TESTS_COUNT, get_snapshot_success) ++
|
|
|
|
lists:duplicate(?TESTS_COUNT, snapshot_not_found) ++
|
|
|
|
lists:duplicate(?TESTS_COUNT, woody_error) ++
|
|
|
|
lists:duplicate(?TESTS_COUNT, object_not_found)}
|
2019-05-06 13:19:41 +00:00
|
|
|
].
|
|
|
|
|
2020-10-14 09:38:41 +00:00
|
|
|
-spec init_per_suite(config()) -> config().
|
2019-05-06 13:19:41 +00:00
|
|
|
init_per_suite(C) ->
|
|
|
|
Apps = genlib_app:start_application_with(dmt_client, [
|
|
|
|
{api_module, ?MODULE},
|
2020-10-14 09:38:41 +00:00
|
|
|
% milliseconds
|
|
|
|
{cache_update_interval, 5000},
|
2019-05-06 13:19:41 +00:00
|
|
|
{max_cache_size, #{
|
|
|
|
elements => 1,
|
2020-10-14 09:38:41 +00:00
|
|
|
% 2Kb
|
|
|
|
memory => 2048
|
2019-05-06 13:19:41 +00:00
|
|
|
}},
|
|
|
|
{service_urls, #{
|
|
|
|
'Repository' => <<"http://dominant:8022/v1/domain/repository">>,
|
|
|
|
'RepositoryClient' => <<"http://dominant:8022/v1/domain/repository_client">>
|
|
|
|
}}
|
|
|
|
]),
|
2020-10-14 09:38:41 +00:00
|
|
|
[{apps, Apps} | C].
|
2019-05-06 13:19:41 +00:00
|
|
|
|
2020-10-14 09:38:41 +00:00
|
|
|
-spec end_per_suite(config()) -> any().
|
2019-05-06 13:19:41 +00:00
|
|
|
end_per_suite(C) ->
|
|
|
|
genlib_app:stop_unload_applications(?config(apps, C)).
|
|
|
|
|
|
|
|
%%% Dummy API
|
|
|
|
|
2021-06-30 15:26:34 +00:00
|
|
|
-spec commit(dmt_client:vsn(), dmt_client:commit(), dmt_client:opts()) -> dmt_client:vsn() | no_return().
|
2019-05-06 13:19:41 +00:00
|
|
|
commit(Version, _Commit, _Opts) ->
|
|
|
|
Version.
|
|
|
|
|
2021-06-30 15:26:34 +00:00
|
|
|
-spec checkout(dmt_client:ref(), dmt_client:opts()) -> dmt_client:snapshot() | no_return().
|
2022-06-20 08:17:22 +00:00
|
|
|
checkout({version, ?NOTFOUND_VERSION}, _Opts) ->
|
|
|
|
erlang:throw(#domain_conf_VersionNotFound{});
|
|
|
|
checkout({version, ?UNAVAILABLE_VERSION}, _Opts) ->
|
2019-05-06 13:19:41 +00:00
|
|
|
woody_error:raise(system, {external, resource_unavailable, <<"test">>});
|
2022-06-20 08:17:22 +00:00
|
|
|
checkout({version, ?EXISTING_VERSION}, _Opts) ->
|
2019-05-06 13:19:41 +00:00
|
|
|
timer:sleep(5000),
|
2022-06-20 08:17:22 +00:00
|
|
|
#domain_conf_Snapshot{version = ?EXISTING_VERSION, domain = dmt_domain:new()};
|
|
|
|
checkout({head, #domain_conf_Head{}}, _Opts) ->
|
2019-05-06 13:19:41 +00:00
|
|
|
timer:sleep(5000),
|
2022-06-20 08:17:22 +00:00
|
|
|
#domain_conf_Snapshot{version = ?EXISTING_VERSION, domain = dmt_domain:new()}.
|
2019-05-06 13:19:41 +00:00
|
|
|
|
2021-06-30 15:26:34 +00:00
|
|
|
-spec checkout_object(dmt_client:ref(), dmt_client:object_ref(), dmt_client:opts()) ->
|
2022-06-20 08:17:22 +00:00
|
|
|
no_return().
|
2019-05-06 13:19:41 +00:00
|
|
|
checkout_object(_Reference, _ObjectReference, _Opts) ->
|
2022-06-20 08:17:22 +00:00
|
|
|
erlang:throw(#domain_conf_ObjectNotFound{}).
|
2019-05-06 13:19:41 +00:00
|
|
|
|
2021-06-30 15:26:34 +00:00
|
|
|
-spec pull_range(dmt_client:vsn(), dmt_client:limit(), dmt_client:opts()) -> dmt_client:history() | no_return().
|
2019-05-06 13:19:41 +00:00
|
|
|
pull_range(_Version, _Limit, _Opts) ->
|
|
|
|
timer:sleep(5000),
|
|
|
|
#{}.
|
|
|
|
|
|
|
|
%%% Tests
|
|
|
|
|
2020-10-14 09:38:41 +00:00
|
|
|
-spec get_snapshot_success(config()) -> any().
|
2019-05-06 13:19:41 +00:00
|
|
|
get_snapshot_success(_C) ->
|
2022-06-20 08:17:22 +00:00
|
|
|
{ok, #domain_conf_Snapshot{}} = dmt_client_cache:get(?EXISTING_VERSION, #{}).
|
2019-05-06 13:19:41 +00:00
|
|
|
|
2020-10-14 09:38:41 +00:00
|
|
|
-spec snapshot_not_found(config()) -> any().
|
2019-05-06 13:19:41 +00:00
|
|
|
snapshot_not_found(_C) ->
|
2022-06-20 08:17:22 +00:00
|
|
|
{error, version_not_found} = dmt_client_cache:get(?NOTFOUND_VERSION, #{}).
|
2019-05-06 13:19:41 +00:00
|
|
|
|
2020-10-14 09:38:41 +00:00
|
|
|
-spec woody_error(config()) -> any().
|
2019-05-06 13:19:41 +00:00
|
|
|
woody_error(_C) ->
|
2022-06-20 08:17:22 +00:00
|
|
|
{error, {woody_error, _}} = dmt_client_cache:get(?UNAVAILABLE_VERSION, #{}).
|
2019-05-06 13:19:41 +00:00
|
|
|
|
2020-10-14 09:38:41 +00:00
|
|
|
-spec object_not_found(config()) -> any().
|
2019-05-06 13:19:41 +00:00
|
|
|
object_not_found(_C) ->
|
2022-06-20 08:17:22 +00:00
|
|
|
Ref = {category, #domain_CategoryRef{id = 1}},
|
|
|
|
{error, version_not_found} = dmt_client_cache:get_object(?NOTFOUND_VERSION, Ref, #{}),
|
|
|
|
{error, object_not_found} = dmt_client_cache:get_object(?EXISTING_VERSION, Ref, #{}).
|