syn_create_mnesia_SUITE.erl 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  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. %% tests
  35. -export([
  36. single_node_when_mnesia_is_ram/1,
  37. single_node_when_mnesia_is_opt_disc_no_schema_exists/1,
  38. single_node_when_mnesia_is_opt_disc_schema_exists/1,
  39. single_node_when_mnesia_is_disc/1
  40. ]).
  41. -export([
  42. two_nodes_when_mnesia_is_ram/1,
  43. two_nodes_when_mnesia_is_opt_disc_no_schema_exists/1,
  44. two_nodes_when_mnesia_is_opt_disc_schema_exists/1,
  45. two_nodes_when_mnesia_is_disc/1
  46. ]).
  47. %% include
  48. -include_lib("common_test/include/ct.hrl").
  49. %% ===================================================================
  50. %% Callbacks
  51. %% ===================================================================
  52. %% -------------------------------------------------------------------
  53. %% Function: all() -> GroupsAndTestCases | {skip,Reason}
  54. %% GroupsAndTestCases = [{group,GroupName} | TestCase]
  55. %% GroupName = atom()
  56. %% TestCase = atom()
  57. %% Reason = term()
  58. %% -------------------------------------------------------------------
  59. all() ->
  60. [
  61. {group, single_node_mnesia_creation},
  62. {group, two_nodes_mnesia_creation}
  63. ].
  64. %% -------------------------------------------------------------------
  65. %% Function: groups() -> [Group]
  66. %% Group = {GroupName,Properties,GroupsAndTestCases}
  67. %% GroupName = atom()
  68. %% Properties = [parallel | sequence | Shuffle | {RepeatType,N}]
  69. %% GroupsAndTestCases = [Group | {group,GroupName} | TestCase]
  70. %% TestCase = atom()
  71. %% Shuffle = shuffle | {shuffle,{integer(),integer(),integer()}}
  72. %% RepeatType = repeat | repeat_until_all_ok | repeat_until_all_fail |
  73. %% repeat_until_any_ok | repeat_until_any_fail
  74. %% N = integer() | forever
  75. %% -------------------------------------------------------------------
  76. groups() ->
  77. [
  78. {single_node_mnesia_creation, [shuffle], [
  79. single_node_when_mnesia_is_ram,
  80. single_node_when_mnesia_is_opt_disc_no_schema_exists,
  81. single_node_when_mnesia_is_opt_disc_schema_exists,
  82. single_node_when_mnesia_is_disc
  83. ]},
  84. {two_nodes_mnesia_creation, [shuffle], [
  85. two_nodes_when_mnesia_is_ram,
  86. two_nodes_when_mnesia_is_opt_disc_no_schema_exists,
  87. two_nodes_when_mnesia_is_opt_disc_schema_exists,
  88. two_nodes_when_mnesia_is_disc
  89. ]}
  90. ].
  91. %% -------------------------------------------------------------------
  92. %% Function: init_per_suite(Config0) ->
  93. %% Config1 | {skip,Reason} |
  94. %% {skip_and_save,Reason,Config1}
  95. %% Config0 = Config1 = [tuple()]
  96. %% Reason = term()
  97. %% -------------------------------------------------------------------
  98. init_per_suite(Config) ->
  99. %% config
  100. [
  101. {slave_node_short_name, syn_slave}
  102. | Config
  103. ].
  104. %% -------------------------------------------------------------------
  105. %% Function: end_per_suite(Config0) -> void() | {save_config,Config1}
  106. %% Config0 = Config1 = [tuple()]
  107. %% -------------------------------------------------------------------
  108. end_per_suite(_Config) -> ok.
  109. %% -------------------------------------------------------------------
  110. %% Function: init_per_group(GroupName, Config0) ->
  111. %% Config1 | {skip,Reason} |
  112. %% {skip_and_save,Reason,Config1}
  113. %% GroupName = atom()
  114. %% Config0 = Config1 = [tuple()]
  115. %% Reason = term()
  116. %% -------------------------------------------------------------------
  117. init_per_group(two_nodes_mnesia_creation, Config) ->
  118. %% get slave node short name
  119. SlaveNodeShortName = proplists:get_value(slave_node_short_name, Config),
  120. {ok, SlaveNodeName} = syn_test_suite_helper:start_slave(SlaveNodeShortName),
  121. %% config
  122. [
  123. {slave_node_name, SlaveNodeName}
  124. | Config
  125. ];
  126. init_per_group(_GroupName, Config) -> Config.
  127. %% -------------------------------------------------------------------
  128. %% Function: end_per_group(GroupName, Config0) ->
  129. %% void() | {save_config,Config1}
  130. %% GroupName = atom()
  131. %% Config0 = Config1 = [tuple()]
  132. %% -------------------------------------------------------------------
  133. end_per_group(two_nodes_mnesia_creation, Config) ->
  134. %% get slave node name
  135. SlaveNodeName = proplists:get_value(slave_node_name, Config),
  136. %% clean
  137. clean_after_test(SlaveNodeName),
  138. %% stop slave
  139. syn_test_suite_helper:stop_slave(SlaveNodeName);
  140. end_per_group(_GroupName, _Config) ->
  141. clean_after_test().
  142. %% ===================================================================
  143. %% Tests
  144. %% ===================================================================
  145. single_node_when_mnesia_is_ram(_Config) ->
  146. %% set schema location
  147. application:set_env(mnesia, schema_location, ram),
  148. %% start
  149. ok = syn:start(),
  150. %% check table exists
  151. true = lists:member(syn_processes_table, mnesia:system_info(tables)).
  152. single_node_when_mnesia_is_opt_disc_no_schema_exists(_Config) ->
  153. %% set schema location
  154. application:set_env(mnesia, schema_location, opt_disc),
  155. %% start
  156. ok = syn:start(),
  157. %% check table exists
  158. true = lists:member(syn_processes_table, mnesia:system_info(tables)).
  159. single_node_when_mnesia_is_opt_disc_schema_exists(_Config) ->
  160. %% set schema location
  161. application:set_env(mnesia, schema_location, opt_disc),
  162. %% create schema
  163. mnesia:create_schema([node()]),
  164. %% start
  165. ok = syn:start(),
  166. %% check table exists
  167. true = lists:member(syn_processes_table, mnesia:system_info(tables)).
  168. single_node_when_mnesia_is_disc(_Config) ->
  169. %% set schema location
  170. application:set_env(mnesia, schema_location, disc),
  171. %% create schema
  172. mnesia:create_schema([node()]),
  173. %% start
  174. ok = syn:start(),
  175. %% check table exists
  176. true = lists:member(syn_processes_table, mnesia:system_info(tables)).
  177. two_nodes_when_mnesia_is_ram(Config) ->
  178. %% get slave
  179. SlaveNodeName = proplists:get_value(slave_node_name, Config),
  180. %% set schema location
  181. application:set_env(mnesia, schema_location, ram),
  182. rpc:call(SlaveNodeName, mnesia, schema_location, [ram]),
  183. %% start
  184. ok = syn:start(),
  185. ok = rpc:call(SlaveNodeName, syn, start, []),
  186. %% check table exists on local
  187. true = lists:member(syn_processes_table, mnesia:system_info(tables)),
  188. %% check table exists on remote
  189. SlaveNodeMnesiaSystemInfo = rpc:call(SlaveNodeName, mnesia, system_info, [tables]),
  190. true = rpc:call(SlaveNodeName, lists, member, [syn_processes_table, SlaveNodeMnesiaSystemInfo]).
  191. two_nodes_when_mnesia_is_opt_disc_no_schema_exists(Config) ->
  192. %% get slave
  193. SlaveNodeName = proplists:get_value(slave_node_name, Config),
  194. %% set schema location
  195. application:set_env(mnesia, schema_location, opt_disc),
  196. rpc:call(SlaveNodeName, mnesia, schema_location, [opt_disc]),
  197. %% start
  198. ok = syn:start(),
  199. ok = rpc:call(SlaveNodeName, syn, start, []),
  200. %% check table exists on local
  201. true = lists:member(syn_processes_table, mnesia:system_info(tables)),
  202. %% check table exists on remote
  203. SlaveNodeMnesiaSystemInfo = rpc:call(SlaveNodeName, mnesia, system_info, [tables]),
  204. true = rpc:call(SlaveNodeName, lists, member, [syn_processes_table, SlaveNodeMnesiaSystemInfo]).
  205. two_nodes_when_mnesia_is_opt_disc_schema_exists(Config) ->
  206. %% get slave
  207. SlaveNodeName = proplists:get_value(slave_node_name, Config),
  208. %% set schema location
  209. application:set_env(mnesia, schema_location, opt_disc),
  210. rpc:call(SlaveNodeName, mnesia, schema_location, [opt_disc]),
  211. %% create schema
  212. mnesia:create_schema([node(), SlaveNodeName]),
  213. %% start
  214. ok = syn:start(),
  215. ok = rpc:call(SlaveNodeName, syn, start, []),
  216. %% check table exists on local
  217. true = lists:member(syn_processes_table, mnesia:system_info(tables)),
  218. %% check table exists on remote
  219. SlaveNodeMnesiaSystemInfo = rpc:call(SlaveNodeName, mnesia, system_info, [tables]),
  220. true = rpc:call(SlaveNodeName, lists, member, [syn_processes_table, SlaveNodeMnesiaSystemInfo]).
  221. two_nodes_when_mnesia_is_disc(Config) ->
  222. %% get slave
  223. SlaveNodeName = proplists:get_value(slave_node_name, Config),
  224. %% set schema location
  225. application:set_env(mnesia, schema_location, disc),
  226. rpc:call(SlaveNodeName, mnesia, schema_location, [disc]),
  227. %% create schema
  228. mnesia:create_schema([node(), SlaveNodeName]),
  229. %% start
  230. ok = syn:start(),
  231. ok = rpc:call(SlaveNodeName, syn, start, []),
  232. %% check table exists on local
  233. true = lists:member(syn_processes_table, mnesia:system_info(tables)),
  234. %% check table exists on remote
  235. SlaveNodeMnesiaSystemInfo = rpc:call(SlaveNodeName, mnesia, system_info, [tables]),
  236. true = rpc:call(SlaveNodeName, lists, member, [syn_processes_table, SlaveNodeMnesiaSystemInfo]).
  237. %% ===================================================================
  238. %% Internal
  239. %% ===================================================================
  240. clean_after_test() ->
  241. %% stop mnesia
  242. mnesia:stop(),
  243. %% delete schema
  244. mnesia:delete_schema([node()]),
  245. %% stop syn
  246. syn:stop().
  247. clean_after_test(SlaveNodeName) ->
  248. clean_after_test(),
  249. %% stop mnesia
  250. rpc:call(SlaveNodeName, mnesia, stop, []),
  251. %% delete schema
  252. rpc:call(SlaveNodeName, mnesia, delete_schema, [SlaveNodeName]),
  253. %% stop syn
  254. rpc:call(SlaveNodeName, syn, stop, []).