syn_create_mnesia_SUITE.erl 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  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. syn_test_suite_helper:clean_after_test(SlaveNodeName),
  138. %% stop slave
  139. syn_test_suite_helper:stop_slave(SlaveNodeName);
  140. end_per_group(_GroupName, _Config) ->
  141. syn_test_suite_helper: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. timer:sleep(100),
  187. %% check table exists on local
  188. true = lists:member(syn_processes_table, mnesia:system_info(tables)),
  189. %% check table exists on remote
  190. SlaveNodeMnesiaSystemInfo = rpc:call(SlaveNodeName, mnesia, system_info, [tables]),
  191. true = rpc:call(SlaveNodeName, lists, member, [syn_processes_table, SlaveNodeMnesiaSystemInfo]).
  192. two_nodes_when_mnesia_is_opt_disc_no_schema_exists(Config) ->
  193. %% get slave
  194. SlaveNodeName = proplists:get_value(slave_node_name, Config),
  195. %% set schema location
  196. application:set_env(mnesia, schema_location, opt_disc),
  197. rpc:call(SlaveNodeName, mnesia, schema_location, [opt_disc]),
  198. %% start
  199. ok = syn:start(),
  200. ok = rpc:call(SlaveNodeName, syn, start, []),
  201. timer:sleep(100),
  202. %% check table exists on local
  203. true = lists:member(syn_processes_table, mnesia:system_info(tables)),
  204. %% check table exists on remote
  205. SlaveNodeMnesiaSystemInfo = rpc:call(SlaveNodeName, mnesia, system_info, [tables]),
  206. true = rpc:call(SlaveNodeName, lists, member, [syn_processes_table, SlaveNodeMnesiaSystemInfo]).
  207. two_nodes_when_mnesia_is_opt_disc_schema_exists(Config) ->
  208. %% get slave
  209. SlaveNodeName = proplists:get_value(slave_node_name, Config),
  210. %% set schema location
  211. application:set_env(mnesia, schema_location, opt_disc),
  212. rpc:call(SlaveNodeName, mnesia, schema_location, [opt_disc]),
  213. %% create schema
  214. mnesia:create_schema([node(), SlaveNodeName]),
  215. %% start
  216. ok = syn:start(),
  217. ok = rpc:call(SlaveNodeName, syn, start, []),
  218. timer:sleep(100),
  219. %% check table exists on local
  220. true = lists:member(syn_processes_table, mnesia:system_info(tables)),
  221. %% check table exists on remote
  222. SlaveNodeMnesiaSystemInfo = rpc:call(SlaveNodeName, mnesia, system_info, [tables]),
  223. true = rpc:call(SlaveNodeName, lists, member, [syn_processes_table, SlaveNodeMnesiaSystemInfo]).
  224. two_nodes_when_mnesia_is_disc(Config) ->
  225. %% get slave
  226. SlaveNodeName = proplists:get_value(slave_node_name, Config),
  227. %% set schema location
  228. application:set_env(mnesia, schema_location, disc),
  229. rpc:call(SlaveNodeName, mnesia, schema_location, [disc]),
  230. %% create schema
  231. mnesia:create_schema([node(), SlaveNodeName]),
  232. %% start
  233. ok = syn:start(),
  234. ok = rpc:call(SlaveNodeName, syn, start, []),
  235. timer:sleep(100),
  236. %% check table exists on local
  237. true = lists:member(syn_processes_table, mnesia:system_info(tables)),
  238. %% check table exists on remote
  239. SlaveNodeMnesiaSystemInfo = rpc:call(SlaveNodeName, mnesia, system_info, [tables]),
  240. true = rpc:call(SlaveNodeName, lists, member, [syn_processes_table, SlaveNodeMnesiaSystemInfo]).