syn_create_mnesia_SUITE.erl 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  1. %% ==========================================================================================================
  2. %% Syn - A global process registry.
  3. %%
  4. %% Copyright (C) 2015, Roberto Ostinelli <roberto@ostinelli.net>.
  5. %% All rights reserved.
  6. %%
  7. %% The MIT License (MIT)
  8. %%
  9. %% Copyright (c) 2015 Roberto Ostinelli
  10. %%
  11. %% Permission is hereby granted, free of charge, to any person obtaining a copy
  12. %% of this software and associated documentation files (the "Software"), to deal
  13. %% in the Software without restriction, including without limitation the rights
  14. %% to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  15. %% copies of the Software, and to permit persons to whom the Software is
  16. %% furnished to do so, subject to the following conditions:
  17. %%
  18. %% The above copyright notice and this permission notice shall be included in
  19. %% all copies or substantial portions of the Software.
  20. %%
  21. %% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  22. %% IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  23. %% FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  24. %% AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  25. %% LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  26. %% OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  27. %% THE SOFTWARE.
  28. %% ==========================================================================================================
  29. -module(syn_create_mnesia_SUITE).
  30. %% callbacks
  31. -export([all/0]).
  32. -export([init_per_suite/1, end_per_suite/1]).
  33. -export([groups/0, init_per_group/2, end_per_group/2]).
  34. -export([init_per_testcase/2, end_per_testcase/2]).
  35. %% tests
  36. -export([
  37. single_node_when_mnesia_is_ram/1,
  38. single_node_when_mnesia_is_opt_disc_no_schema_exists/1,
  39. single_node_when_mnesia_is_opt_disc_schema_exists/1,
  40. single_node_when_mnesia_is_disc/1
  41. ]).
  42. -export([
  43. two_nodes_when_mnesia_is_ram/1,
  44. two_nodes_when_mnesia_is_opt_disc_no_schema_exists/1,
  45. two_nodes_when_mnesia_is_opt_disc_schema_exists/1,
  46. two_nodes_when_mnesia_is_disc/1
  47. ]).
  48. %% include
  49. -include_lib("common_test/include/ct.hrl").
  50. %% ===================================================================
  51. %% Callbacks
  52. %% ===================================================================
  53. %% -------------------------------------------------------------------
  54. %% Function: all() -> GroupsAndTestCases | {skip,Reason}
  55. %% GroupsAndTestCases = [{group,GroupName} | TestCase]
  56. %% GroupName = atom()
  57. %% TestCase = atom()
  58. %% Reason = term()
  59. %% -------------------------------------------------------------------
  60. all() ->
  61. [
  62. {group, single_node_mnesia_creation},
  63. {group, two_nodes_mnesia_creation}
  64. ].
  65. %% -------------------------------------------------------------------
  66. %% Function: groups() -> [Group]
  67. %% Group = {GroupName,Properties,GroupsAndTestCases}
  68. %% GroupName = atom()
  69. %% Properties = [parallel | sequence | Shuffle | {RepeatType,N}]
  70. %% GroupsAndTestCases = [Group | {group,GroupName} | TestCase]
  71. %% TestCase = atom()
  72. %% Shuffle = shuffle | {shuffle,{integer(),integer(),integer()}}
  73. %% RepeatType = repeat | repeat_until_all_ok | repeat_until_all_fail |
  74. %% repeat_until_any_ok | repeat_until_any_fail
  75. %% N = integer() | forever
  76. %% -------------------------------------------------------------------
  77. groups() ->
  78. [
  79. {single_node_mnesia_creation, [shuffle], [
  80. single_node_when_mnesia_is_ram,
  81. single_node_when_mnesia_is_opt_disc_no_schema_exists,
  82. single_node_when_mnesia_is_opt_disc_schema_exists,
  83. single_node_when_mnesia_is_disc
  84. ]},
  85. {two_nodes_mnesia_creation, [shuffle], [
  86. two_nodes_when_mnesia_is_ram,
  87. two_nodes_when_mnesia_is_opt_disc_no_schema_exists,
  88. two_nodes_when_mnesia_is_opt_disc_schema_exists,
  89. two_nodes_when_mnesia_is_disc
  90. ]}
  91. ].
  92. %% -------------------------------------------------------------------
  93. %% Function: init_per_suite(Config0) ->
  94. %% Config1 | {skip,Reason} |
  95. %% {skip_and_save,Reason,Config1}
  96. %% Config0 = Config1 = [tuple()]
  97. %% Reason = term()
  98. %% -------------------------------------------------------------------
  99. init_per_suite(Config) ->
  100. %% config
  101. [
  102. {slave_node_short_name, syn_slave}
  103. | Config
  104. ].
  105. %% -------------------------------------------------------------------
  106. %% Function: end_per_suite(Config0) -> void() | {save_config,Config1}
  107. %% Config0 = Config1 = [tuple()]
  108. %% -------------------------------------------------------------------
  109. end_per_suite(_Config) -> ok.
  110. %% -------------------------------------------------------------------
  111. %% Function: init_per_group(GroupName, Config0) ->
  112. %% Config1 | {skip,Reason} |
  113. %% {skip_and_save,Reason,Config1}
  114. %% GroupName = atom()
  115. %% Config0 = Config1 = [tuple()]
  116. %% Reason = term()
  117. %% -------------------------------------------------------------------
  118. init_per_group(two_nodes_mnesia_creation, Config) ->
  119. %% start slave
  120. SlaveNodeShortName = proplists:get_value(slave_node_short_name, Config),
  121. {ok, SlaveNode} = syn_test_suite_helper:start_slave(SlaveNodeShortName),
  122. %% config
  123. [
  124. {slave_node, SlaveNode}
  125. | Config
  126. ];
  127. init_per_group(_GroupName, Config) -> Config.
  128. %% -------------------------------------------------------------------
  129. %% Function: end_per_group(GroupName, Config0) ->
  130. %% void() | {save_config,Config1}
  131. %% GroupName = atom()
  132. %% Config0 = Config1 = [tuple()]
  133. %% -------------------------------------------------------------------
  134. end_per_group(two_nodes_mnesia_creation, Config) ->
  135. %% get slave node name
  136. SlaveNodeShortName = proplists:get_value(slave_node_short_name, Config),
  137. %% stop slave
  138. syn_test_suite_helper:stop_slave(SlaveNodeShortName);
  139. end_per_group(_GroupName, _Config) ->
  140. ok.
  141. % ----------------------------------------------------------------------------------------------------------
  142. % Function: init_per_testcase(TestCase, Config0) ->
  143. % Config1 | {skip,Reason} | {skip_and_save,Reason,Config1}
  144. % TestCase = atom()
  145. % Config0 = Config1 = [tuple()]
  146. % Reason = term()
  147. % ----------------------------------------------------------------------------------------------------------
  148. init_per_testcase(_TestCase, Config) ->
  149. Config.
  150. % ----------------------------------------------------------------------------------------------------------
  151. % Function: end_per_testcase(TestCase, Config0) ->
  152. % void() | {save_config,Config1} | {fail,Reason}
  153. % TestCase = atom()
  154. % Config0 = Config1 = [tuple()]
  155. % Reason = term()
  156. % ----------------------------------------------------------------------------------------------------------
  157. end_per_testcase(_TestCase, Config) ->
  158. %% get slave
  159. SlaveNode = proplists:get_value(slave_node, Config),
  160. syn_test_suite_helper:clean_after_test(SlaveNode).
  161. %% ===================================================================
  162. %% Tests
  163. %% ===================================================================
  164. single_node_when_mnesia_is_ram(_Config) ->
  165. %% set schema location
  166. application:set_env(mnesia, schema_location, ram),
  167. %% start
  168. ok = syn:start(),
  169. %% check table exists
  170. true = lists:member(syn_processes_table, mnesia:system_info(tables)).
  171. single_node_when_mnesia_is_opt_disc_no_schema_exists(_Config) ->
  172. %% set schema location
  173. application:set_env(mnesia, schema_location, opt_disc),
  174. %% start
  175. ok = syn:start(),
  176. %% check table exists
  177. true = lists:member(syn_processes_table, mnesia:system_info(tables)).
  178. single_node_when_mnesia_is_opt_disc_schema_exists(_Config) ->
  179. %% set schema location
  180. application:set_env(mnesia, schema_location, opt_disc),
  181. %% create schema
  182. mnesia:create_schema([node()]),
  183. %% start
  184. ok = syn:start(),
  185. %% check table exists
  186. true = lists:member(syn_processes_table, mnesia:system_info(tables)).
  187. single_node_when_mnesia_is_disc(_Config) ->
  188. %% set schema location
  189. application:set_env(mnesia, schema_location, disc),
  190. %% create schema
  191. mnesia:create_schema([node()]),
  192. %% start
  193. ok = syn:start(),
  194. %% check table exists
  195. true = lists:member(syn_processes_table, mnesia:system_info(tables)).
  196. two_nodes_when_mnesia_is_ram(Config) ->
  197. %% get slave
  198. SlaveNode = proplists:get_value(slave_node, Config),
  199. %% set schema location
  200. application:set_env(mnesia, schema_location, ram),
  201. rpc:call(SlaveNode, mnesia, schema_location, [ram]),
  202. %% start
  203. ok = syn:start(),
  204. ok = rpc:call(SlaveNode, syn, start, []),
  205. timer:sleep(100),
  206. %% check table exists on local
  207. true = lists:member(syn_processes_table, mnesia:system_info(tables)),
  208. %% check table exists on remote
  209. SlaveNodeMnesiaSystemInfo = rpc:call(SlaveNode, mnesia, system_info, [tables]),
  210. true = rpc:call(SlaveNode, lists, member, [syn_processes_table, SlaveNodeMnesiaSystemInfo]).
  211. two_nodes_when_mnesia_is_opt_disc_no_schema_exists(Config) ->
  212. %% get slave
  213. SlaveNode = proplists:get_value(slave_node, Config),
  214. %% set schema location
  215. application:set_env(mnesia, schema_location, opt_disc),
  216. rpc:call(SlaveNode, mnesia, schema_location, [opt_disc]),
  217. %% start
  218. ok = syn:start(),
  219. ok = rpc:call(SlaveNode, syn, start, []),
  220. timer:sleep(100),
  221. %% check table exists on local
  222. true = lists:member(syn_processes_table, mnesia:system_info(tables)),
  223. %% check table exists on remote
  224. SlaveNodeMnesiaSystemInfo = rpc:call(SlaveNode, mnesia, system_info, [tables]),
  225. true = rpc:call(SlaveNode, lists, member, [syn_processes_table, SlaveNodeMnesiaSystemInfo]).
  226. two_nodes_when_mnesia_is_opt_disc_schema_exists(Config) ->
  227. %% get slave
  228. SlaveNode = proplists:get_value(slave_node, Config),
  229. %% set schema location
  230. application:set_env(mnesia, schema_location, opt_disc),
  231. rpc:call(SlaveNode, mnesia, schema_location, [opt_disc]),
  232. %% create schema
  233. mnesia:create_schema([node(), SlaveNode]),
  234. %% start
  235. ok = syn:start(),
  236. ok = rpc:call(SlaveNode, syn, start, []),
  237. timer:sleep(100),
  238. %% check table exists on local
  239. true = lists:member(syn_processes_table, mnesia:system_info(tables)),
  240. %% check table exists on remote
  241. SlaveNodeMnesiaSystemInfo = rpc:call(SlaveNode, mnesia, system_info, [tables]),
  242. true = rpc:call(SlaveNode, lists, member, [syn_processes_table, SlaveNodeMnesiaSystemInfo]).
  243. two_nodes_when_mnesia_is_disc(Config) ->
  244. %% get slave
  245. SlaveNode = proplists:get_value(slave_node, Config),
  246. %% set schema location
  247. application:set_env(mnesia, schema_location, disc),
  248. rpc:call(SlaveNode, mnesia, schema_location, [disc]),
  249. %% create schema
  250. mnesia:create_schema([node(), SlaveNode]),
  251. %% start
  252. ok = syn:start(),
  253. ok = rpc:call(SlaveNode, syn, start, []),
  254. timer:sleep(100),
  255. %% check table exists on local
  256. true = lists:member(syn_processes_table, mnesia:system_info(tables)),
  257. %% check table exists on remote
  258. SlaveNodeMnesiaSystemInfo = rpc:call(SlaveNode, mnesia, system_info, [tables]),
  259. true = rpc:call(SlaveNode, lists, member, [syn_processes_table, SlaveNodeMnesiaSystemInfo]).