Skip to content
This repository was archived by the owner on Sep 22, 2024. It is now read-only.

Commit e3a6b55

Browse files
committed
Add erlfmt and mnesia_test module
1 parent 6a06815 commit e3a6b55

File tree

4 files changed

+81
-19
lines changed

4 files changed

+81
-19
lines changed

rebar.config

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
{deps, []}.
33

44
{shell, [
5-
% {config, "config/sys.config"},
5+
% {config, "config/sys.config"},
66
{apps, [elab_demo]}
77
]}.
8+
9+
{project_plugins, [erlfmt]}.

src/elab_demo.app.src

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
1-
{application, elab_demo,
2-
[{description, "Erlang Lab demo app"},
3-
{vsn, "0.1.0"},
4-
{registered, []},
5-
{mod, {elab_demo_app, []}},
6-
{applications,
7-
[kernel,
8-
stdlib
9-
]},
10-
{env,[]},
11-
{modules, []},
1+
{application, elab_demo, [
2+
{description, "Erlang Lab demo app"},
3+
{vsn, "0.1.0"},
4+
{registered, []},
5+
{mod, {elab_demo_app, []}},
6+
{applications, [
7+
kernel,
8+
stdlib,
9+
mnesia
10+
]},
11+
{env, []},
12+
{modules, []},
1213

13-
{licenses, ["Apache 2.0"]},
14-
{links, []}
15-
]}.
14+
{licenses, ["Apache 2.0"]},
15+
{links, []}
16+
]}.

src/elab_demo_sup.erl

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,21 @@ start_link() ->
2626
%% type => worker(), % optional
2727
%% modules => modules()} % optional
2828
init([]) ->
29-
SupFlags = #{strategy => one_for_all,
30-
intensity => 0,
31-
period => 1},
32-
ChildSpecs = [],
29+
SupFlags = #{
30+
strategy => one_for_all,
31+
intensity => 0,
32+
period => 1
33+
},
34+
ChildSpecs = [
35+
#{
36+
id => mnesia_test,
37+
start => {mnesia_test, start_link, []},
38+
restart => temporary,
39+
shutdown => brutal_kill,
40+
type => worker,
41+
modules => [mnesia_test]
42+
}
43+
],
3344
{ok, {SupFlags, ChildSpecs}}.
3445

3546
%% internal functions

src/mnesia_test.erl

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
%%%-------------------------------------------------------------------
2+
%%% @author Michal Slaski
3+
%%% @doc
4+
%%% Starts a process, which inserts 1M elements to a mnesia table.
5+
%%% @end
6+
%%% Created : 25 May 2021 by Michal Slaski
7+
%%%-------------------------------------------------------------------
8+
-module(mnesia_test).
9+
10+
-export([
11+
start_link/0,
12+
init/2,
13+
insert_data/2,
14+
system_continue/3,
15+
system_terminate/4,
16+
system_get_state/1
17+
]).
18+
19+
start_link() ->
20+
proc_lib:start_link(?MODULE, init, [self(), 1000000]).
21+
22+
init(Parent, N) ->
23+
register(?MODULE, self()),
24+
{atomic, ok} = mnesia:create_table(?MODULE, []),
25+
Keys = lists:seq(1, N),
26+
proc_lib:init_ack(Parent, {ok, self()}),
27+
insert_data(Parent, Keys).
28+
29+
insert_data(Parent, [K | Keys]) ->
30+
ok = mnesia:dirty_write({?MODULE, K, <<K:32>>}),
31+
insert_data(Parent, Keys);
32+
insert_data(Parent, []) ->
33+
loop(Parent).
34+
35+
loop(Parent) ->
36+
receive
37+
{system, From, Request} ->
38+
sys:handle_system_msg(Request, From, Parent, ?MODULE, [], [])
39+
end.
40+
41+
system_continue(Parent, _Debug, _State) ->
42+
loop(Parent).
43+
44+
system_terminate(Reason, _Parent, _Debug, _State) ->
45+
exit(Reason).
46+
47+
system_get_state(_State) ->
48+
{ok, mnesia:table_info(?MODULE, all)}.

0 commit comments

Comments
 (0)