Skip to content

Commit e249cb5

Browse files
committed
Added cleanup of buffer table form data older than 1 day.
Adjusted ut_run.sql to API changes. Fixed issues with calling ut.run as a table function. Refactored Unit Tests after changes to buffer structure and reporter_id.
1 parent 2ca26cd commit e249cb5

11 files changed

Lines changed: 49 additions & 57 deletions

client_source/sqlplus/ut_run.sql

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,6 @@ set define &
121121

122122
spool run_in_backgroung.sql.tmp
123123
declare
124-
l_output_type varchar2(256) := ut_runner.get_streamed_output_type_name();
125124
l_run_params ut_runner.t_run_params := ut_runner.get_run_params();
126125
l_color_enabled varchar2(5) := case when l_run_params.color_enabled then 'true' else 'false' end;
127126
procedure p(a_text varchar2) is
@@ -140,8 +139,8 @@ begin
140139
p( 'begin');
141140
if l_run_params.call_params is not null then
142141
for i in 1 .. l_run_params.call_params.count loop
143-
p(' v_reporter := '||l_run_params.call_params(i).ut_reporter_name||'('||l_output_type||'());');
144-
p(' v_reporter.output.output_id := '''||l_run_params.call_params(i).output_id||''';');
142+
p(' v_reporter := '||l_run_params.call_params(i).ut_reporter_name||'();');
143+
p(' v_reporter.reporter_id := '''||l_run_params.call_params(i).reporter_id||''';');
145144
p(' v_reporters_list.extend; v_reporters_list(v_reporters_list.last) := v_reporter;');
146145
end loop;
147146
end if;
@@ -156,7 +155,6 @@ spool off
156155

157156
spool gather_data_from_outputs.sql.tmp
158157
declare
159-
l_output_type varchar2(256) := ut_runner.get_streamed_output_type_name();
160158
l_run_params ut_runner.t_run_params := ut_runner.get_run_params();
161159
l_need_spool boolean;
162160
procedure p(a_text varchar2) is
@@ -171,7 +169,7 @@ begin
171169
p('set termout '||l_run_params.call_params(i).output_to_screen);
172170
l_need_spool := (l_run_params.call_params(i).output_file_name is not null);
173171
p(case when l_need_spool then 'spool '||l_run_params.call_params(i).output_file_name||chr(10) end||
174-
'select * from table( '||l_output_type||'().get_lines('''||l_run_params.call_params(i).output_id||''') );'||
172+
'select * from table( ut_output_buffer.get_lines('''||l_run_params.call_params(i).reporter_id||''') );'||
175173
case when l_need_spool then chr(10)||'spool off' end);
176174
end loop;
177175
end if;

source/api/ut.pkb

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -70,15 +70,19 @@ create or replace package body ut is
7070
ut_assert_processor.report_error(a_message);
7171
end;
7272

73-
function run(a_paths ut_varchar2_list, a_reporter ut_reporter_base := ut_documentation_reporter(), a_color_console boolean := false) return ut_varchar2_list pipelined is
74-
l_reporter ut_reporter_base := a_reporter;
73+
procedure run_autonomous(a_paths ut_varchar2_list, a_reporter ut_reporter_base, a_color_console integer) is
74+
pragma autonomous_transaction;
75+
begin
76+
ut_runner.run(a_paths, a_reporter, ut_utils.int_to_boolean(a_color_console));
77+
rollback;
78+
end;
79+
80+
function run(a_paths ut_varchar2_list, a_reporter ut_reporter_base := ut_documentation_reporter(), a_color_console integer := 0) return ut_varchar2_list pipelined is
81+
l_reporter ut_reporter_base := coalesce(a_reporter, ut_documentation_reporter());
7582
l_lines sys_refcursor;
7683
l_line varchar2(4000);
7784
begin
78-
if l_reporter is null then
79-
l_reporter := ut_documentation_reporter();
80-
end if;
81-
ut_runner.run(a_paths, l_reporter, a_color_console);
85+
run_autonomous(a_paths, l_reporter, a_color_console);
8286
l_lines := ut_output_buffer.get_lines_cursor(l_reporter.reporter_id);
8387
loop
8488
fetch l_lines into l_line;
@@ -88,15 +92,13 @@ create or replace package body ut is
8892
close l_lines;
8993
end;
9094

91-
function run(a_path varchar2 := null, a_reporter ut_reporter_base := ut_documentation_reporter(), a_color_console boolean := false) return ut_varchar2_list pipelined is
92-
l_reporter ut_reporter_base := a_reporter;
95+
function run(a_path varchar2 := null, a_reporter ut_reporter_base := ut_documentation_reporter(), a_color_console integer := 0) return ut_varchar2_list pipelined is
96+
l_reporter ut_reporter_base := coalesce(a_reporter, ut_documentation_reporter());
97+
l_paths ut_varchar2_list := ut_varchar2_list(coalesce(a_path, sys_context('userenv', 'current_schema')));
9398
l_lines sys_refcursor;
9499
l_line varchar2(4000);
95100
begin
96-
if l_reporter is null then
97-
l_reporter := ut_documentation_reporter();
98-
end if;
99-
ut_runner.run(a_path, a_reporter, a_color_console);
101+
run_autonomous(l_paths, a_reporter, a_color_console );
100102
l_lines := ut_output_buffer.get_lines_cursor(l_reporter.reporter_id);
101103
loop
102104
fetch l_lines into l_line;
@@ -107,18 +109,16 @@ create or replace package body ut is
107109
end;
108110

109111
procedure run(a_paths ut_varchar2_list, a_reporter ut_reporter_base := ut_documentation_reporter(), a_color_console boolean := false) is
110-
l_reporter ut_reporter_base := a_reporter;
112+
l_reporter ut_reporter_base := coalesce(a_reporter, ut_documentation_reporter());
111113
begin
112-
if l_reporter is null then
113-
l_reporter := ut_documentation_reporter();
114-
end if;
115114
ut_runner.run(a_paths, l_reporter, a_color_console);
116115
ut_output_buffer.lines_to_dbms_output(l_reporter.reporter_id);
117116
end;
118117

119118
procedure run(a_path varchar2 := null, a_reporter ut_reporter_base := ut_documentation_reporter(), a_color_console boolean := false) is
119+
l_paths ut_varchar2_list := ut_varchar2_list(coalesce(a_path, sys_context('userenv', 'current_schema')));
120120
begin
121-
ut.run(ut_varchar2_list(coalesce(a_path, sys_context('userenv', 'current_schema'))), a_reporter, a_color_console);
121+
ut.run(l_paths, a_reporter, a_color_console);
122122
end;
123123

124124
end ut;

source/api/ut.pks

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ create or replace package ut authid current_user as
2828

2929
procedure fail(a_message in varchar2);
3030

31-
function run(a_paths ut_varchar2_list, a_reporter ut_reporter_base := ut_documentation_reporter(), a_color_console boolean := false) return ut_varchar2_list pipelined;
31+
function run(a_paths ut_varchar2_list, a_reporter ut_reporter_base := ut_documentation_reporter(), a_color_console integer := 0) return ut_varchar2_list pipelined;
3232

33-
function run(a_path varchar2 := null, a_reporter ut_reporter_base := ut_documentation_reporter(), a_color_console boolean := false) return ut_varchar2_list pipelined;
33+
function run(a_path varchar2 := null, a_reporter ut_reporter_base := ut_documentation_reporter(), a_color_console integer := 0) return ut_varchar2_list pipelined;
3434

3535
procedure run(a_paths ut_varchar2_list, a_reporter ut_reporter_base := ut_documentation_reporter(), a_color_console boolean := false);
3636

source/api/ut_runner.pkb

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ create or replace package body ut_runner is
55
l_listener ut_event_listener;
66
l_current_suite ut_logical_suite;
77
begin
8+
ut_output_buffer.cleanup_buffer();
9+
810
ut_console_reporter_base.set_color_enabled(a_color_console);
911
if a_reporters is null or a_reporters.count = 0 then
1012
l_listener := ut_event_listener(ut_reporters(ut_documentation_reporter()));
@@ -13,13 +15,6 @@ create or replace package body ut_runner is
1315
end if;
1416
l_items_to_run := ut_run( ut_suite_manager.configure_execution_by_path(a_paths) );
1517
l_items_to_run.do_execute(l_listener);
16-
exception
17-
when others then
18-
dbms_output.put_line(dbms_utility.format_error_backtrace());
19-
dbms_output.put_line(dbms_utility.format_error_stack());
20-
--need to use dynamic sql here, so that even if DBMS_PIPE is not used, we will try to run it.
21-
22-
raise;
2318
end;
2419

2520
procedure run(a_paths ut_varchar2_list, a_reporter ut_reporter_base := ut_documentation_reporter(), a_color_console boolean := false) is

source/core/ut_output_buffer.pks

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
create or replace package ut_output_buffer authid definer is
22

3-
gc_max_wait_sec naturaln := 60 * 60 * 4; -- 4 hours
4-
gc_buffer_retention_sec naturaln := 60 * 60 * 24; -- 24 hours
3+
gc_max_wait_sec constant naturaln := 60 * 60 * 4; -- 4 hours
4+
gc_buffer_retention_sec constant naturaln := 60 * 60 * 24; -- 24 hours
55

66
procedure send_line(a_reporter ut_reporter_base, a_text varchar2);
77

source/core/ut_runner_helper.pkb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,7 @@ create or replace package body ut_runner_helper is
6363
procedure setup_reporting_output_ids(a_call_params in out nocopy tt_call_params) is
6464
begin
6565
for i in 1 .. cardinality(a_call_params) loop
66-
execute immediate 'begin :l_output_id := '||get_streamed_output_type_name()||'().generate_output_id(); end;'
67-
using out a_call_params(i).output_id;
66+
a_call_params(i).reporter_id := sys_guid();
6867
end loop;
6968
end;
7069

source/core/ut_runner_helper.pks

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ create or replace package ut_runner_helper authid definer is
44
ut_reporter_name varchar2(4000) := 'ut_documentation_reporter',
55
output_file_name varchar2(4000),
66
output_to_screen varchar2(3) := 'on',
7-
output_id varchar2(4000)
7+
reporter_id raw(32)
88
);
99

1010
type tt_call_params is table of t_call_param;

tests/ut_output_buffer/get_lines.RecievesALineFromBufferTableAndDeletes.sql

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,31 +3,31 @@ declare
33
l_result varchar2(4000);
44
l_remaining integer;
55
l_expected varchar2(4000);
6-
c_id varchar2(250) := 'a_reporter_id';
6+
l_reporter ut_reporter_base := ut_documentation_reporter();
77
begin
88
--Act
99
l_expected := lpad('a text',4000,',a text');
10-
ut_output_buffer.send_line(c_id, l_expected);
10+
ut_output_buffer.send_line(l_reporter, l_expected);
1111

12-
select * into l_result from table(ut_output_buffer.get_lines(c_id,0));
12+
select * into l_result from table(ut_output_buffer.get_lines(l_reporter.reporter_id,0));
1313

1414
ut.expect(l_result).to_equal(l_expected);
1515

16-
select count(1) into l_remaining from ut_output_buffer_tmp where reporter_id = c_id;
16+
select count(1) into l_remaining from ut_output_buffer_tmp where reporter_id = l_reporter.reporter_id;
1717

1818
ut.expect(l_remaining).to_equal(0);
1919

2020
if ut_assert_processor.get_aggregate_asserts_result = ut_utils.tr_success then
2121
:test_result := ut_utils.tr_success;
2222
else
23-
dbms_output.put_line(ut_assert_processor.GET_ASSERTS_RESULTS()(1).get_result_clob);
23+
dbms_output.put_line(ut_assert_processor.get_asserts_results()(1).get_result_clob);
2424
end if;
2525

26-
delete from ut_output_buffer_tmp where reporter_id = c_id;
26+
delete from ut_output_buffer_tmp where reporter_id = l_reporter.reporter_id;
2727
commit;
2828
exception
2929
when others then
30-
delete from ut_output_buffer_tmp where reporter_id = c_id;
30+
delete from ut_output_buffer_tmp where reporter_id = l_reporter.reporter_id;
3131
commit;
3232
raise;
3333
end;

tests/ut_output_buffer/get_lines.WaitsForTheDataToAppearForSpecifiedTime.sql

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,31 +3,31 @@ declare
33
l_result varchar2(4000);
44
l_remaining integer;
55
l_expected varchar2(4000);
6-
c_id varchar2(250) := 'a_reporter_id';
6+
l_reporter ut_reporter_base := ut_documentation_reporter();
77
begin
88
--Act
99
l_expected := lpad('a text',4000,',a text');
10-
ut_output_buffer.send_line(c_id, l_expected);
10+
ut_output_buffer.send_line(l_reporter, l_expected);
1111

12-
select * into l_result from table(ut_output_buffer.get_lines(c_id,0));
12+
select * into l_result from table(ut_output_buffer.get_lines(l_reporter.reporter_id,0));
1313

1414
ut.expect(l_result).to_equal(l_expected);
1515

16-
select count(1) into l_remaining from ut_output_buffer_tmp where reporter_id = c_id;
16+
select count(1) into l_remaining from ut_output_buffer_tmp where reporter_id = l_reporter.reporter_id;
1717

1818
ut.expect(l_remaining).to_equal(0);
1919

2020
if ut_assert_processor.get_aggregate_asserts_result = ut_utils.tr_success then
2121
:test_result := ut_utils.tr_success;
2222
else
23-
dbms_output.put_line(ut_assert_processor.GET_ASSERTS_RESULTS()(1).get_result_clob);
23+
dbms_output.put_line(ut_assert_processor.get_asserts_results()(1).get_result_clob);
2424
end if;
2525

26-
delete from ut_output_buffer_tmp where reporter_id = c_id;
26+
delete from ut_output_buffer_tmp where reporter_id = l_reporter.reporter_id;
2727
commit;
2828
exception
2929
when others then
30-
delete from ut_output_buffer_tmp where reporter_id = c_id;
30+
delete from ut_output_buffer_tmp where reporter_id = l_reporter.reporter_id;
3131
commit;
3232
raise;
3333
end;

tests/ut_output_buffer/send_line.DoesNotSendLineIfNullTextGiven.sql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
--Arrange
22
declare
33
l_result integer;
4-
4+
l_reporter ut_reporter_base := ut_documentation_reporter();
55
begin
66
delete from ut_output_buffer_tmp;
77
--Act
8-
ut_output_buffer.send_line('a_reporter_id',null);
8+
ut_output_buffer.send_line(l_reporter,null);
99

1010
select count(1) into l_result from ut_output_buffer_tmp;
1111

0 commit comments

Comments
 (0)