Skip to content

Commit

Permalink
Merge e131471 into 4f22ebc
Browse files Browse the repository at this point in the history
  • Loading branch information
jgebal committed Mar 14, 2019
2 parents 4f22ebc + e131471 commit 7b20eb2
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 8 deletions.
4 changes: 2 additions & 2 deletions source/core/types/ut_suite_item.tpb
Expand Up @@ -54,7 +54,7 @@ create or replace type body ut_suite_item as
begin
if get_rollback_type() = ut_utils.gc_rollback_auto then
l_savepoint := ut_utils.gen_savepoint_name();
execute immediate 'savepoint ' || l_savepoint;
dbms_transaction.savepoint(l_savepoint);
end if;
return l_savepoint;
end;
Expand All @@ -65,7 +65,7 @@ create or replace type body ut_suite_item as
pragma exception_init(ex_savepoint_not_exists, -1086);
begin
if get_rollback_type() = ut_utils.gc_rollback_auto and a_savepoint is not null then
execute immediate 'rollback to ' || a_savepoint;
dbms_transaction.rollback_savepoint( a_savepoint );
end if;
exception
when ex_savepoint_not_exists then
Expand Down
81 changes: 75 additions & 6 deletions test/api/test_ut_run.pkb
Expand Up @@ -697,19 +697,33 @@ create or replace package body test_ut_run is
execute immediate q'[drop package empty_suite]';
end;

procedure create_test_suite is
procedure create_db_link is
l_service_name varchar2(100);
pragma autonomous_transaction;
begin
select global_name into l_service_name from global_name;
execute immediate
'create public database link db_loopback connect to ut3_tester identified by ut3
using ''(DESCRIPTION=
(ADDRESS=(PROTOCOL=TCP)
(HOST='||sys_context('userenv','SERVER_HOST')||')
'create public database link db_loopback connect to ut3_tester identified by ut3
using ''(DESCRIPTION=
(ADDRESS=(PROTOCOL=TCP)
(HOST='||sys_context('userenv','SERVER_HOST')||')
(PORT=1521)
)
(CONNECT_DATA=(SERVICE_NAME='||l_service_name||')))''';
end;

procedure drop_db_link is
begin
execute immediate 'drop public database link db_loopback';
exception
when others then
null;
end;

procedure create_test_suite is
pragma autonomous_transaction;
begin
create_db_link;
execute immediate q'[
create or replace package stateful_package as
function get_state return varchar2;
Expand Down Expand Up @@ -796,7 +810,7 @@ Failures:%
begin
execute immediate 'drop package stateful_package';
execute immediate 'drop package test_stateful';
begin execute immediate 'drop public database link db_loopback'; exception when others then null; end;
drop_db_link;
end;

procedure run_in_invalid_state is
Expand Down Expand Up @@ -942,5 +956,60 @@ Failures:%
begin
execute immediate 'drop package bad_annotations';
end;

procedure savepoints_on_db_links is
l_results clob;
begin
ut3.ut.run('test_distributed_savepoint');
l_results := core.get_dbms_output_as_clob();
ut.expect(l_results).to_be_like('%1 tests, 0 failed, 0 errored, 0 disabled, 0 warning(s)%');
end;

procedure create_suite_with_link is
pragma autonomous_transaction;
begin
create_db_link;
execute immediate 'create table tst(id number(18,0))';
execute immediate q'[
create or replace package test_distributed_savepoint is
--%suite
--%suitepath(alltests)

--%beforeall
procedure setup;

--%test
procedure test;
end;]';

execute immediate q'[
create or replace package body test_distributed_savepoint is

g_expected constant integer := 1;

procedure setup is
begin
insert into tst@db_loopback values(g_expected);
end;

procedure test is
l_actual integer := 0;
begin
select id into l_actual from tst@db_loopback;

ut.expect(l_actual).to_equal(g_expected);
end;

end;]';
end;

procedure drop_suite_with_link is
pragma autonomous_transaction;
begin
execute immediate 'drop table tst';
execute immediate 'drop package test_distributed_savepoint';
drop_db_link;
end;

end;
/
7 changes: 7 additions & 0 deletions test/api/test_ut_run.pks
Expand Up @@ -56,6 +56,13 @@ create or replace package test_ut_run is
--%aftertest(drop_failing_beforeall_suite)
procedure run_proc_fail_child_suites;

--%test(Savepoints are working properly on distributed transactions - Issue #839)
--%beforetest(create_suite_with_link)
--%aftertest(drop_suite_with_link)
procedure savepoints_on_db_links;
procedure create_suite_with_link;
procedure drop_suite_with_link;

--%endcontext

--%context(run_proc_transaction_control)
Expand Down

0 comments on commit 7b20eb2

Please sign in to comment.