syn_create_mnesia_SUITE.erl 11 KB

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