aboutsummaryrefslogtreecommitdiffstats
path: root/lib/cosTransactions/test/etrap_test_lib.hrl
blob: 01e507d5ac7dfe277d9b9bc2e5a60b20da16ec04 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
%%
%% %CopyrightBegin%
%% 
%% Copyright Ericsson AB 1999-2011. All Rights Reserved.
%% 
%% Licensed under the Apache License, Version 2.0 (the "License");
%% you may not use this file except in compliance with the License.
%% You may obtain a copy of the License at
%%
%%     http://www.apache.org/licenses/LICENSE-2.0
%%
%% Unless required by applicable law or agreed to in writing, software
%% distributed under the License is distributed on an "AS IS" BASIS,
%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
%% See the License for the specific language governing permissions and
%% limitations under the License.
%% 
%% %CopyrightEnd%
%%
%%

-ifndef(ETRAP_TEST_LIB_HRL).
-define(ETRAP_TEST_LIB_HRL, true).

-define(match(ExpectedRes, Expr, Msg),
	fun() ->
	       AcTuAlReS = (catch (Expr)),
	       case AcTuAlReS of
		   ExpectedRes ->
		       io:format("~n------ CORRECT RESULT ------~n~p~n~p~n",
				 [AcTuAlReS, Msg]),
		       ok;
		   _ ->
		       io:format("~n###### ERROR ERROR ######~n~p~n~p~n",
				 [AcTuAlReS, Msg]),
		       exit(AcTuAlReS)
	       end
       end()).

-define(match_inverse(NotExpectedRes, Expr, Msg),
	fun() ->
		AcTuAlReS = (catch (Expr)),
	       case AcTuAlReS of
		   NotExpectedRes ->
		       io:format("~n###### ERROR ERROR ######~n ~p~n~p~n",
				 [AcTuAlReS, Msg]),
		       exit(AcTuAlReS);
		   _ ->
		       io:format("~n------ CORRECT RESULT ------~n~p~n~p~n",
				 [AcTuAlReS, Msg]),
		       ok
	       end
       end()).


-define(crash_and_recover, fun(_Env)-> exit(crash_and_burn) end).

-define(crash_no_recovery, fun(Env)-> throw({stop,normal,{Env,state}}) end).

-define(delay(Time), fun(_Id) -> timer:sleep(Time*1000) end).

-define(TIMEOUT,        4).
-define(SUP_TEST(Env, Name), 
	['etrap_test_server', Env, 
	 [{sup_child, true}, {persistent, true}, 
	  {regname, {global, Name}}]]).

-define(no_context, [[],[],[], []]).
-define(nop, []).
-define(delay_transient(Tag, Ti),
	[{Tag, ?delay(Ti), transient}]).
-define(crash_transient(Tag),
	[{Tag, ?crash_and_recover, transient}]).
-define(crash_permanent(Tag),
	[{Tag, ?crash_no_recovery, permanent}]).

%%-----------------------------------------------------------
%% Definition of 'Resource' action.
%%                         function  action  reply
%%-----------------------------------------------------------
%% raise #'CosTransactions_HeuristicMixed' {}
-define(rollback_mix,     [{rollback, exc, ?tr_mixed}]).
-define(commit_mix,       [{commit,   exc, ?tr_mixed}]).
-define(prepare_mix,      [{prepare,  exc, ?tr_mixed}]).
%% raise #'CosTransactions_HeuristicRollback' {}
-define(rollback_rb,      [{rollback, exc, ?tr_rollback}]).
-define(commit_rb,        [{commit,   exc, ?tr_rollback}]).
%% raise #'CosTransactions_HeuristicCommit' {}
-define(rollback_cm,      [{rollback, exc, ?tr_commit}]).
-define(commit_cm,        [{commit,   exc, ?tr_commit}]).
%% delay reply
-define(rollback_delay,   [{rollback, delay, ?TIMEOUT*2}]).
-define(commit_delay,     [{commit,   delay, ?TIMEOUT*2}]).
-define(prepare_delay,    [{prepare,  delay, ?TIMEOUT*2}]).
%% other reply than default
-define(prepare_commit,   [{prepare,  reply, 'VoteCommit'}]).
-define(prepare_rollback, [{prepare,  stop_reply, 'VoteRollback'}]).

-endif.

%%-------------- EOF ---------------------------------------------------