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

Skip to content

Commit bcb8cea

Browse files
authored
Merge pull request #608 from utPLSQL/feature/distributed_transaction_fix
Fixed `ORA-02055` issue.
2 parents 2debaec + 05748a0 commit bcb8cea

4 files changed

Lines changed: 67 additions & 0 deletions

File tree

.travis/install.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ SQL
2929
set feedback off
3030
@create_utplsql_owner.sql $UT3_TESTER $UT3_TESTER_PASSWORD $UT3_TABLESPACE
3131
32+
--needed for testing distributed transactions
33+
grant create public database link to $UT3_TESTER;
34+
grant drop public database link to $UT3_TESTER;
3235
set feedback on
3336
--Needed for testing coverage outside of main UT3 schema.
3437
grant create any procedure, drop any procedure, execute any procedure, create any type, drop any type, execute any type, under any type, select any table, update any table, insert any table, delete any table, create any table, drop any table, alter any table, select any dictionary to $UT3_TESTER;

source/api/ut_runner.pkb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,11 +93,13 @@ create or replace package body ut_runner is
9393
l_items_to_run.do_execute(l_listener);
9494

9595
finish_run(l_listener);
96+
rollback;
9697
exception
9798
when others then
9899
finish_run(l_listener);
99100
dbms_output.put_line(dbms_utility.format_error_backtrace);
100101
dbms_output.put_line(dbms_utility.format_error_stack);
102+
rollback;
101103
raise;
102104
end;
103105
if a_fail_on_errors and l_items_to_run.result in (ut_utils.tr_failure, ut_utils.tr_error) then

test/api/test_ut_runner.pkb

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,5 +295,59 @@ end;';
295295
ut.expect(l_actual).to_equal(l_expected);
296296
end;
297297

298+
procedure db_link_cleanup is
299+
begin
300+
begin execute immediate 'drop public database link db_loopback'; exception when others then null; end;
301+
begin execute immediate 'drop package test_db_link'; exception when others then null; end;
302+
end;
303+
304+
procedure db_link_setup is
305+
l_service_name varchar2(100);
306+
begin
307+
select global_name into l_service_name from global_name;
308+
execute immediate
309+
'create public database link db_loopback connect to ut3_tester identified by ut3
310+
using ''(DESCRIPTION=
311+
(ADDRESS=(PROTOCOL=TCP)
312+
(HOST='||sys_context('userenv','SERVER_HOST')||')
313+
(PORT=1521)
314+
)
315+
(CONNECT_DATA=(SERVICE_NAME='||l_service_name||')))''';
316+
execute immediate q'[
317+
create or replace package test_db_link is
318+
--%suite
319+
320+
--%test
321+
procedure runs_with_db_link;
322+
end;]';
323+
324+
execute immediate q'[
325+
create or replace package body test_db_link is
326+
procedure runs_with_db_link is
327+
a_value integer;
328+
begin
329+
select 1 into a_value
330+
from dual@db_loopback;
331+
ut3.ut.expect(a_value).to_be_null();
332+
end;
333+
end;]';
334+
335+
end;
336+
337+
procedure raises_20213_on_fail_link is
338+
l_reporter ut3.ut_documentation_reporter := ut3.ut_documentation_reporter();
339+
l_lines ut3.ut_varchar2_list;
340+
begin
341+
--Arrange
342+
--Act
343+
ut3.ut_runner.run(ut3.ut_varchar2_list('test_db_link'), ut3.ut_reporters(l_reporter), a_fail_on_errors=> true);
344+
ut.fail('Expected exception but nothing was raised');
345+
exception
346+
when others then
347+
--Assert
348+
ut.expect(sqlcode).to_equal(-20213);
349+
ut.expect(dbms_utility.format_error_stack||dbms_utility.format_error_backtrace).not_to_be_like('%ORA-02055%');
350+
end;
351+
298352
end;
299353
/

test/api/test_ut_runner.pks

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,5 +53,13 @@ create or replace package test_ut_runner is
5353
--%aftertest(cleanup_cache)
5454
procedure test_get_reporters_list;
5555

56+
procedure db_link_cleanup;
57+
procedure db_link_setup;
58+
59+
--%test(ORA-20213 is thrown with a_raise_on_failure when database link operations are used - regression)
60+
--%beforetest(db_link_setup)
61+
--%aftertest(db_link_cleanup)
62+
procedure raises_20213_on_fail_link;
63+
5664
end;
5765
/

0 commit comments

Comments
 (0)