syn_create_mnesia_SUITE.erl 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  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. ok = syn:init(),
  170. %% check table exists
  171. true = lists:member(syn_processes_table, mnesia:system_info(tables)).
  172. single_node_when_mnesia_is_opt_disc_no_schema_exists(_Config) ->
  173. %% set schema location
  174. application:set_env(mnesia, schema_location, opt_disc),
  175. %% start
  176. ok = syn:start(),
  177. ok = syn:init(),
  178. %% check table exists
  179. true = lists:member(syn_processes_table, mnesia:system_info(tables)).
  180. single_node_when_mnesia_is_opt_disc_schema_exists(_Config) ->
  181. %% set schema location
  182. application:set_env(mnesia, schema_location, opt_disc),
  183. %% create schema
  184. mnesia:create_schema([node()]),
  185. %% start
  186. ok = syn:start(),
  187. ok = syn:init(),
  188. %% check table exists
  189. true = lists:member(syn_processes_table, mnesia:system_info(tables)).
  190. single_node_when_mnesia_is_disc(_Config) ->
  191. %% set schema location
  192. application:set_env(mnesia, schema_location, disc),
  193. %% create schema
  194. mnesia:create_schema([node()]),
  195. %% start
  196. ok = syn:start(),
  197. ok = syn:init(),
  198. %% check table exists
  199. true = lists:member(syn_processes_table, mnesia:system_info(tables)).
  200. two_nodes_when_mnesia_is_ram(Config) ->
  201. %% get slave
  202. SlaveNode = proplists:get_value(slave_node, Config),
  203. %% set schema location
  204. application:set_env(mnesia, schema_location, ram),
  205. rpc:call(SlaveNode, mnesia, schema_location, [ram]),
  206. %% start
  207. ok = syn:start(),
  208. ok = syn:init(),
  209. ok = rpc:call(SlaveNode, syn, start, []),
  210. ok = rpc:call(SlaveNode, syn, init, []),
  211. timer:sleep(100),
  212. %% check table exists on local
  213. true = lists:member(syn_processes_table, mnesia:system_info(tables)),
  214. %% check table exists on remote
  215. SlaveNodeMnesiaSystemInfo = rpc:call(SlaveNode, mnesia, system_info, [tables]),
  216. true = rpc:call(SlaveNode, lists, member, [syn_processes_table, SlaveNodeMnesiaSystemInfo]).
  217. two_nodes_when_mnesia_is_opt_disc_no_schema_exists(Config) ->
  218. %% get slave
  219. SlaveNode = proplists:get_value(slave_node, Config),
  220. %% set schema location
  221. application:set_env(mnesia, schema_location, opt_disc),
  222. rpc:call(SlaveNode, mnesia, schema_location, [opt_disc]),
  223. %% start
  224. ok = syn:start(),
  225. ok = syn:init(),
  226. ok = rpc:call(SlaveNode, syn, start, []),
  227. ok = rpc:call(SlaveNode, syn, init, []),
  228. timer:sleep(100),
  229. %% check table exists on local
  230. true = lists:member(syn_processes_table, mnesia:system_info(tables)),
  231. %% check table exists on remote
  232. SlaveNodeMnesiaSystemInfo = rpc:call(SlaveNode, mnesia, system_info, [tables]),
  233. true = rpc:call(SlaveNode, lists, member, [syn_processes_table, SlaveNodeMnesiaSystemInfo]).
  234. two_nodes_when_mnesia_is_opt_disc_schema_exists(Config) ->
  235. %% get slave
  236. SlaveNode = proplists:get_value(slave_node, Config),
  237. %% set schema location
  238. application:set_env(mnesia, schema_location, opt_disc),
  239. rpc:call(SlaveNode, mnesia, schema_location, [opt_disc]),
  240. %% create schema
  241. mnesia:create_schema([node(), SlaveNode]),
  242. %% start
  243. ok = syn:start(),
  244. ok = syn:init(),
  245. ok = rpc:call(SlaveNode, syn, start, []),
  246. ok = rpc:call(SlaveNode, syn, init, []),
  247. timer:sleep(100),
  248. %% check table exists on local
  249. true = lists:member(syn_processes_table, mnesia:system_info(tables)),
  250. %% check table exists on remote
  251. SlaveNodeMnesiaSystemInfo = rpc:call(SlaveNode, mnesia, system_info, [tables]),
  252. true = rpc:call(SlaveNode, lists, member, [syn_processes_table, SlaveNodeMnesiaSystemInfo]).
  253. two_nodes_when_mnesia_is_disc(Config) ->
  254. %% get slave
  255. SlaveNode = proplists:get_value(slave_node, Config),
  256. %% set schema location
  257. application:set_env(mnesia, schema_location, disc),
  258. rpc:call(SlaveNode, mnesia, schema_location, [disc]),
  259. %% create schema
  260. mnesia:create_schema([node(), SlaveNode]),
  261. %% start
  262. ok = syn:start(),
  263. ok = syn:init(),
  264. ok = rpc:call(SlaveNode, syn, start, []),
  265. ok = rpc:call(SlaveNode, syn, init, []),
  266. timer:sleep(100),
  267. %% check table exists on local
  268. true = lists:member(syn_processes_table, mnesia:system_info(tables)),
  269. %% check table exists on remote
  270. SlaveNodeMnesiaSystemInfo = rpc:call(SlaveNode, mnesia, system_info, [tables]),
  271. true = rpc:call(SlaveNode, lists, member, [syn_processes_table, SlaveNodeMnesiaSystemInfo]).