% ------------------------------------------------------------------------------------------------------
% Demonstrates the ECA runtime with a rollback transformed in the post condition
% Uses the external Test Case transactionTestCase
% Uses the \ContractLog\ecaruntime.prova implementation of the ContractLog framework
% ------------------------------------------------------------------------------------------------------

:-eval(consult('ContractLog/math.prova')).
:-eval(consult('ContractLog/list.prova')).
:-eval(consult('ContractLog/list_math.prova')).
:-eval(consult('ContractLog/datetime.prova')).
:-eval(consult('ContractLog/timeinterval.prova')).
:-eval(consult('ContractLog/ecaruntime.prova')).
:-eval(consult('ContractLog/testcase.prova')).
:-eval(consult('ContractLog/utils.prova')).
:-eval(consult('ContractLog/update.prova')).
:-eval(consult('ContractLog/integrity.prova')).


%-----------------------------------------------------------------------
% Define ECA rules
%-----------------------------------------------------------------------




% +++++++++++++++  ECA updates and then tests and rollsback ++++++++++++++
% 
%ECA rules

eca(_,not(a()),_,add(tid1,"a()."),testTC(),_). % ECA rule definition


%TIME empty

%EVENT defined in eca rule

%CONDITION emtpy

%ACTION defined in eca rule
	
%POSTCONDITION
testTC():-
	test("examples/function_tests/eca_runtime/transactionTestCase.prova"),
	commit(tid1),
	println(["Test succeeded - commit updates"]),
	!. 		% cut = no rollback
	
testTC():-
	println(["Test failed - rollback updates !!!!"]),
	rollback(update(tid1)),
	fail().

	
start():-
	showTimer(), % show the timer on console
	showConsole(), % print console output
	setInterval(1), % set the timer loop interval to 1 second
	startECARuntime(".\examples\function_tests\eca_runtime\ecaRollback.prova").
	
:- solve(start()).