diff options
| author | Alexandru Scvortov <alexandru@rabbitmq.com> | 2011-07-20 12:42:37 +0100 |
|---|---|---|
| committer | Alexandru Scvortov <alexandru@rabbitmq.com> | 2011-07-20 12:42:37 +0100 |
| commit | 86569edf5653a90cbc1b1a8612544fd37551d1a8 (patch) | |
| tree | 9cc34a45f108d007075b43b0691ffd1bc727e8b8 /src | |
| parent | 381213af0b7b3cc3a3d898fdf77cfacf19574875 (diff) | |
| download | rabbitmq-server-git-86569edf5653a90cbc1b1a8612544fd37551d1a8.tar.gz | |
test that disc nodes are actually disc nodes
The tests used to be slightly wrong. They'd expect:
rabbitmqctl cluster
to create a cluster with a single ram node. It didn't, instead, it
created a cluster with a single disc node. Since we weren't actually
checking the resulting node type, everything went along fine.
Assert_tables_copy_type is complicated by all the cases it has to
handle, namely converting disc -> ram and ram -> disc. For disc ->
ram, we first need to convert all the tables to ram, then, we need to
convert the schema (converting it before fails with "Disc resident
tables"). For ram -> disc, we first need to convert the schema,
otherwise, all the table conversions will fail with 'has_no_disc'.
Regarding an earlier commit, using mensia:system_info(use_dir) to
check if we have a disc node is wrong because we create the directory
for the message_store anyway.
Diffstat (limited to 'src')
| -rw-r--r-- | src/rabbit_mnesia.erl | 18 | ||||
| -rw-r--r-- | src/rabbit_tests.erl | 26 |
2 files changed, 39 insertions, 5 deletions
diff --git a/src/rabbit_mnesia.erl b/src/rabbit_mnesia.erl index 1a6825eeaa..805b415200 100644 --- a/src/rabbit_mnesia.erl +++ b/src/rabbit_mnesia.erl @@ -431,7 +431,7 @@ delete_previously_running_nodes() -> init_db(ClusterNodes, Force, SecondaryPostMnesiaFun) -> UClusterNodes = lists:usort(ClusterNodes), ProperClusterNodes = UClusterNodes -- [node()], - IsDiskNode = lists:member(node(), ClusterNodes), + IsDiskNode = ClusterNodes == [] orelse lists:member(node(), ClusterNodes), WasDiskNode = is_disc_node(), case mnesia:change_config(extra_db_nodes, ProperClusterNodes) of {ok, Nodes} -> @@ -613,6 +613,14 @@ table_has_copy_type(TabDef, DiscType) -> lists:member(node(), proplists:get_value(DiscType, TabDef, [])). assert_tables_copy_type(CopyTypeAlt) -> + case mnesia:table_info(schema, storage_type) of + CopyTypeAlt -> ok; + _ -> case mnesia:change_table_copy_type(schema, node(), CopyTypeAlt) of + {aborted, {"Disc resident tables", _, _}} -> ok; + {atomic, ok} -> ok; + E -> exit({'node_conversion_failed', E}) + end + end, lists:foreach( fun({Tab, TabDef}) -> HasDiscCopies = table_has_copy_type(TabDef, disc_copies), @@ -627,12 +635,16 @@ assert_tables_copy_type(CopyTypeAlt) -> case mnesia:table_info(Tab, storage_type) of StorageType1 -> ok; unknown -> ok; - _ -> io:format("~p to ~p: ~p~n", [Tab, StorageType1, mnesia:change_table_copy_type(Tab, node(), StorageType1)]) + _ -> + {atomic, ok} = mnesia:change_table_copy_type( + Tab, node(), StorageType1) end end, table_definitions()), case mnesia:table_info(schema, storage_type) of CopyTypeAlt -> ok; - _ -> io:format("~p to ~p: ~p~n", [schema, CopyTypeAlt, mnesia:change_table_copy_type(schema, node(), CopyTypeAlt)]) + _ -> + {atomic, ok} = mnesia:change_table_copy_type( + schema, node(), CopyTypeAlt) end. create_local_table_copies(Type) -> diff --git a/src/rabbit_tests.erl b/src/rabbit_tests.erl index adb3e3ed32..700e90bd43 100644 --- a/src/rabbit_tests.erl +++ b/src/rabbit_tests.erl @@ -951,6 +951,7 @@ test_cluster_management() -> ok = control_action(reset, []), ok = control_action(start_app, []), ok = control_action(stop_app, []), + ok = assert_disc_node(), ok = control_action(force_cluster, ["invalid1@invalid", "invalid2@invalid"]), ok = assert_ram_node(), @@ -978,6 +979,7 @@ test_cluster_management2(SecondaryNode) -> %% make a disk node ok = control_action(reset, []), ok = control_action(cluster, [NodeS]), + ok = assert_disc_node(), %% make a ram node ok = control_action(reset, []), ok = control_action(cluster, [SecondaryNodeS]), @@ -1003,24 +1005,38 @@ test_cluster_management2(SecondaryNode) -> ok = control_action(stop_app, []), ok = assert_ram_node(), - %% join empty cluster as a ram node + %% join empty cluster as a ram node (converts to disc) ok = control_action(reset, []), ok = control_action(cluster, []), ok = control_action(start_app, []), ok = control_action(stop_app, []), + ok = assert_disc_node(), + + %% make a new ram node + ok = control_action(reset, []), + ok = control_action(force_cluster, [SecondaryNodeS]), + ok = control_action(start_app, []), + ok = control_action(stop_app, []), ok = assert_ram_node(), %% turn ram node into disk node - ok = control_action(reset, []), ok = control_action(cluster, [SecondaryNodeS, NodeS]), ok = control_action(start_app, []), ok = control_action(stop_app, []), + ok = assert_disc_node(), %% convert a disk node into a ram node + ok = assert_disc_node(), ok = control_action(force_cluster, ["invalid1@invalid", "invalid2@invalid"]), ok = assert_ram_node(), + %% make a new disk node + ok = control_action(force_reset, []), + ok = control_action(start_app, []), + ok = control_action(stop_app, []), + ok = assert_disc_node(), + %% turn a disk node into a ram node ok = control_action(reset, []), ok = control_action(cluster, [SecondaryNodeS]), @@ -1596,6 +1612,12 @@ assert_ram_node() -> false -> ok end. +assert_disc_node() -> + case rabbit_mnesia:is_disc_node() of + true -> ok; + false -> exit('not_disc_node') + end. + delete_file(File) -> case file:delete(File) of ok -> ok; |
