Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e131471

Browse files
committed
Savepoints are working properly on distributed transactions.
Resolves: #839
1 parent 4f22ebc commit e131471

3 files changed

Lines changed: 84 additions & 8 deletions

File tree

source/core/types/ut_suite_item.tpb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ create or replace type body ut_suite_item as
5454
begin
5555
if get_rollback_type() = ut_utils.gc_rollback_auto then
5656
l_savepoint := ut_utils.gen_savepoint_name();
57-
execute immediate 'savepoint ' || l_savepoint;
57+
dbms_transaction.savepoint(l_savepoint);
5858
end if;
5959
return l_savepoint;
6060
end;
@@ -65,7 +65,7 @@ create or replace type body ut_suite_item as
6565
pragma exception_init(ex_savepoint_not_exists, -1086);
6666
begin
6767
if get_rollback_type() = ut_utils.gc_rollback_auto and a_savepoint is not null then
68-
execute immediate 'rollback to ' || a_savepoint;
68+
dbms_transaction.rollback_savepoint( a_savepoint );
6969
end if;
7070
exception
7171
when ex_savepoint_not_exists then

test/api/test_ut_run.pkb

Lines changed: 75 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -697,19 +697,33 @@ create or replace package body test_ut_run is
697697
execute immediate q'[drop package empty_suite]';
698698
end;
699699

700-
procedure create_test_suite is
700+
procedure create_db_link is
701701
l_service_name varchar2(100);
702702
pragma autonomous_transaction;
703703
begin
704704
select global_name into l_service_name from global_name;
705705
execute immediate
706-
'create public database link db_loopback connect to ut3_tester identified by ut3
707-
using ''(DESCRIPTION=
708-
(ADDRESS=(PROTOCOL=TCP)
709-
(HOST='||sys_context('userenv','SERVER_HOST')||')
706+
'create public database link db_loopback connect to ut3_tester identified by ut3
707+
using ''(DESCRIPTION=
708+
(ADDRESS=(PROTOCOL=TCP)
709+
(HOST='||sys_context('userenv','SERVER_HOST')||')
710710
(PORT=1521)
711711
)
712712
(CONNECT_DATA=(SERVICE_NAME='||l_service_name||')))''';
713+
end;
714+
715+
procedure drop_db_link is
716+
begin
717+
execute immediate 'drop public database link db_loopback';
718+
exception
719+
when others then
720+
null;
721+
end;
722+
723+
procedure create_test_suite is
724+
pragma autonomous_transaction;
725+
begin
726+
create_db_link;
713727
execute immediate q'[
714728
create or replace package stateful_package as
715729
function get_state return varchar2;
@@ -796,7 +810,7 @@ Failures:%
796810
begin
797811
execute immediate 'drop package stateful_package';
798812
execute immediate 'drop package test_stateful';
799-
begin execute immediate 'drop public database link db_loopback'; exception when others then null; end;
813+
drop_db_link;
800814
end;
801815

802816
procedure run_in_invalid_state is
@@ -942,5 +956,60 @@ Failures:%
942956
begin
943957
execute immediate 'drop package bad_annotations';
944958
end;
959+
960+
procedure savepoints_on_db_links is
961+
l_results clob;
962+
begin
963+
ut3.ut.run('test_distributed_savepoint');
964+
l_results := core.get_dbms_output_as_clob();
965+
ut.expect(l_results).to_be_like('%1 tests, 0 failed, 0 errored, 0 disabled, 0 warning(s)%');
966+
end;
967+
968+
procedure create_suite_with_link is
969+
pragma autonomous_transaction;
970+
begin
971+
create_db_link;
972+
execute immediate 'create table tst(id number(18,0))';
973+
execute immediate q'[
974+
create or replace package test_distributed_savepoint is
975+
--%suite
976+
--%suitepath(alltests)
977+
978+
--%beforeall
979+
procedure setup;
980+
981+
--%test
982+
procedure test;
983+
end;]';
984+
985+
execute immediate q'[
986+
create or replace package body test_distributed_savepoint is
987+
988+
g_expected constant integer := 1;
989+
990+
procedure setup is
991+
begin
992+
insert into tst@db_loopback values(g_expected);
993+
end;
994+
995+
procedure test is
996+
l_actual integer := 0;
997+
begin
998+
select id into l_actual from tst@db_loopback;
999+
1000+
ut.expect(l_actual).to_equal(g_expected);
1001+
end;
1002+
1003+
end;]';
1004+
end;
1005+
1006+
procedure drop_suite_with_link is
1007+
pragma autonomous_transaction;
1008+
begin
1009+
execute immediate 'drop table tst';
1010+
execute immediate 'drop package test_distributed_savepoint';
1011+
drop_db_link;
1012+
end;
1013+
9451014
end;
9461015
/

test/api/test_ut_run.pks

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,13 @@ create or replace package test_ut_run is
5656
--%aftertest(drop_failing_beforeall_suite)
5757
procedure run_proc_fail_child_suites;
5858

59+
--%test(Savepoints are working properly on distributed transactions - Issue #839)
60+
--%beforetest(create_suite_with_link)
61+
--%aftertest(drop_suite_with_link)
62+
procedure savepoints_on_db_links;
63+
procedure create_suite_with_link;
64+
procedure drop_suite_with_link;
65+
5966
--%endcontext
6067

6168
--%context(run_proc_transaction_control)

0 commit comments

Comments
 (0)