1%%
2%% %CopyrightBegin%
3%%
4%% Copyright Ericsson AB 1996-2018. All Rights Reserved.
5%%
6%% Licensed under the Apache License, Version 2.0 (the "License");
7%% you may not use this file except in compliance with the License.
8%% You may obtain a copy of the License at
9%%
10%%     http://www.apache.org/licenses/LICENSE-2.0
11%%
12%% Unless required by applicable law or agreed to in writing, software
13%% distributed under the License is distributed on an "AS IS" BASIS,
14%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15%% See the License for the specific language governing permissions and
16%% limitations under the License.
17%%
18%% %CopyrightEnd%
19%%
20
21%%
22-module(mnesia_measure_test).
23-author('hakan@erix.ericsson.se').
24
25-export([init_per_testcase/2, end_per_testcase/2,
26         init_per_group/2, end_per_group/2,
27         all/0, groups/0]).
28
29-export([cost/1, dbn_meters/1,
30         ram_tpcb/1, disc_tpcb/1, disc_only_tpcb/1,
31         ram_meter/1, disc_meter/1, disc_only_meter/1]).
32
33
34-include("mnesia_test_lib.hrl").
35
36init_per_testcase(Func, Conf) ->
37    mnesia_test_lib:init_per_testcase(Func, Conf).
38
39end_per_testcase(Func, Conf) ->
40    mnesia_test_lib:end_per_testcase(Func, Conf).
41
42-define(init(N, Config),
43	mnesia_test_lib:prepare_test_case([{init_test_case, [mnesia]},
44					   delete_schema],
45					  N, Config, ?FILE, ?LINE)).
46
47%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
48
49all() ->
50    [{group, benchmarks}].
51
52groups() ->
53    [{benchmarks, [],
54      [{group, meter}, cost, dbn_meters,
55       {group, tpcb}]},
56     {tpcb, [], [ram_tpcb, disc_tpcb, disc_only_tpcb]},
57     {meter, [], [ram_meter, disc_meter, disc_only_meter]}].
58
59init_per_group(_GroupName, Config) ->
60    Config.
61
62end_per_group(_GroupName, Config) ->
63    Config.
64
65
66%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
67
68%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
69
70%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
71
72%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
73
74%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
75
76dbn_meters(suite) -> [];
77dbn_meters(Config) when is_list(Config) ->
78    _Nodes = ?init(3, Config),
79    ?match(ok, mnesia_dbn_meters:start()),
80    ok.
81
82
83tpcb(ReplicaType, Config) ->
84    HarakiriDelay = {tc_timeout, timer:minutes(20)},
85    Nodes = ?acquire_nodes(2, Config ++ [HarakiriDelay]),
86    Args = [{n_branches, 2},
87	    {n_drivers_per_node, 1},
88	    {replica_nodes, Nodes},
89	    {driver_nodes, [hd(Nodes)]},
90	    {use_running_mnesia, true},
91	    {use_sticky_locks, true},
92	    {replica_type, ReplicaType}],
93    ?match({ok, _}, mnesia_tpcb:start(Args)),
94    ?verify_mnesia(Nodes, []).
95
96ram_tpcb(suite) -> [];
97ram_tpcb(Config) when is_list(Config) ->
98    tpcb(ram_copies, Config).
99
100disc_tpcb(suite) -> [];
101disc_tpcb(Config) when is_list(Config) ->
102    tpcb(disc_copies, Config).
103
104disc_only_tpcb(suite) -> [];
105disc_only_tpcb(Config) when is_list(Config) ->
106    tpcb(disc_only_copies, Config).
107
108
109ram_meter(suite) -> [];
110ram_meter(Config) when is_list(Config) ->
111    HarakiriDelay = [{tc_timeout, timer:minutes(20)}],
112    Nodes = ?init(3, Config ++ HarakiriDelay),
113    ?match(ok, mnesia_meter:go(ram_copies, Nodes)).
114
115disc_meter(suite) -> [];
116disc_meter(Config) when is_list(Config) ->
117    HarakiriDelay = [{tc_timeout, timer:minutes(20)}],
118    Nodes = ?init(3, Config ++ HarakiriDelay),
119    ?match(ok, mnesia_meter:go(disc_copies, Nodes)).
120
121disc_only_meter(suite) -> [];
122disc_only_meter(Config) when is_list(Config) ->
123    HarakiriDelay = [{tc_timeout, timer:minutes(20)}],
124    Nodes = ?init(3, Config ++ HarakiriDelay),
125    ?match(ok, mnesia_meter:go(disc_only_copies, Nodes)).
126
127cost(suite) -> [];
128cost(Config) when is_list(Config) ->
129    Nodes = ?init(3, Config),
130    ?match(ok, mnesia_cost:go(Nodes)),
131    file:delete("MNESIA_COST").
132