Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

khepri_cluster: Accept machine_config in Ra server config #167

Merged
merged 1 commit into from
Nov 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions src/khepri_cluster.erl
Original file line number Diff line number Diff line change
Expand Up @@ -1118,8 +1118,14 @@ complete_ra_server_config(#{cluster_name := StoreId,
end,

UId = ra:new_uid(ra_lib:to_binary(StoreId)),
MachineConfig = #{store_id => StoreId,
member => Member},
MachineConfig0 = case RaServerConfig of
#{machine_config := MachineConfig00} ->
MachineConfig00;
_ ->
#{}
end,
MachineConfig = MachineConfig0#{store_id => StoreId,
member => Member},
Machine = {module, khepri_machine, MachineConfig},
RaServerConfig2#{uid => UId,
log_init_args => #{uid => UId},
Expand Down
70 changes: 67 additions & 3 deletions test/cluster_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

-include("include/khepri.hrl").
-include("src/khepri_error.hrl").
-include("src/khepri_machine.hrl").

-export([all/0,
groups/0,
Expand All @@ -39,7 +40,8 @@
can_use_default_store_on_single_node/1,
can_start_store_in_specified_data_dir_on_single_node/1,
handle_leader_down_on_three_node_cluster_command/1,
handle_leader_down_on_three_node_cluster_response/1]).
handle_leader_down_on_three_node_cluster_response/1,
can_set_snapshot_interval/1]).

all() ->
[can_start_a_single_node,
Expand All @@ -56,7 +58,8 @@ all() ->
can_use_default_store_on_single_node,
can_start_store_in_specified_data_dir_on_single_node,
handle_leader_down_on_three_node_cluster_command,
handle_leader_down_on_three_node_cluster_response].
handle_leader_down_on_three_node_cluster_response,
can_set_snapshot_interval].

groups() ->
[].
Expand All @@ -80,7 +83,8 @@ init_per_testcase(Testcase, Config)
Testcase =:= can_restart_a_single_node_with_ra_server_config orelse
Testcase =:= fail_to_start_with_bad_ra_server_config orelse
Testcase =:= initial_members_are_ignored orelse
Testcase =:= fail_to_join_non_existing_node ->
Testcase =:= fail_to_join_non_existing_node orelse
Testcase =:= can_set_snapshot_interval ->
setup_node(),
{ok, _} = application:ensure_all_started(khepri),
Props = helpers:start_ra_system(Testcase),
Expand Down Expand Up @@ -1091,6 +1095,66 @@ can_start_store_in_specified_data_dir_on_single_node(_Config) ->
helpers:remove_store_dir(DataDir),
?assertNot(filelib:is_dir(DataDir)).

can_set_snapshot_interval(Config) ->
Node = node(),
#{Node := #{ra_system := RaSystem}} = ?config(ra_system_props, Config),
StoreId = RaSystem,

ct:pal("Start database"),
RaServerConfig = #{cluster_name => StoreId,
machine_config => #{snapshot_interval => 3}},
?assertEqual(
{ok, StoreId},
khepri:start(RaSystem, RaServerConfig)),

ct:pal("Verify applied command count is 0"),
?assertEqual(
#{},
khepri_machine:process_query(
StoreId,
fun(#khepri_machine{metrics = Metrics}) -> Metrics end,
#{})),

ct:pal("Use database after starting it"),
?assertEqual(ok, khepri:put(StoreId, [foo], value1)),

ct:pal("Verify applied command count is 1"),
?assertEqual(
#{applied_command_count => 1},
khepri_machine:process_query(
StoreId,
fun(#khepri_machine{metrics = Metrics}) -> Metrics end,
#{})),

ct:pal("Use database after starting it"),
?assertEqual(ok, khepri:put(StoreId, [foo], value1)),

ct:pal("Verify applied command count is 2"),
?assertEqual(
#{applied_command_count => 2},
khepri_machine:process_query(
StoreId,
fun(#khepri_machine{metrics = Metrics}) -> Metrics end,
#{})),

ct:pal("Use database after starting it"),
?assertEqual(ok, khepri:put(StoreId, [foo], value1)),

ct:pal("Verify applied command count is 0"),
?assertEqual(
#{},
khepri_machine:process_query(
StoreId,
fun(#khepri_machine{metrics = Metrics}) -> Metrics end,
#{})),

ct:pal("Stop database"),
?assertEqual(
ok,
khepri:stop(StoreId)),

ok.

%% -------------------------------------------------------------------
%% Internal functions
%% -------------------------------------------------------------------
Expand Down