Skip to content

Commit

Permalink
Update output buffer to support passing array of data to buffer.
Browse files Browse the repository at this point in the history
Update some reporters to pass data as arrays and minimize the IO overhead.
  • Loading branch information
jgebal committed Aug 1, 2017
1 parent 9c3e7cc commit bad487b
Show file tree
Hide file tree
Showing 12 changed files with 158 additions and 52 deletions.
2 changes: 2 additions & 0 deletions source/core/output_buffers/ut_output_buffer_base.tps
Expand Up @@ -19,6 +19,8 @@ create or replace type ut_output_buffer_base authid definer as object(
output_id raw(32),
member procedure init(self in out nocopy ut_output_buffer_base, a_output_id raw),
not instantiable member procedure send_line(self in ut_output_buffer_base, a_text varchar2),
not instantiable member procedure send_lines(self in ut_output_buffer_base, a_lines ut_varchar2_list),
not instantiable member procedure send_lines(self in ut_output_buffer_base, a_lines ut_varchar2_rows),
not instantiable member procedure close(self in ut_output_buffer_base),
not instantiable member function get_lines(a_initial_timeout natural := null, a_timeout_sec natural := null) return ut_varchar2_rows pipelined,
not instantiable member function get_lines_cursor(a_initial_timeout natural := null, a_timeout_sec natural := null) return sys_refcursor,
Expand Down
16 changes: 16 additions & 0 deletions source/core/output_buffers/ut_output_table_buffer.tpb
Expand Up @@ -34,6 +34,22 @@ create or replace type body ut_output_table_buffer is
commit;
end;

overriding member procedure send_lines(self in ut_output_table_buffer, a_lines ut_varchar2_list) is
begin
send_lines(ut_utils.convert_collection(a_lines));
end;

overriding member procedure send_lines(self in ut_output_table_buffer, a_lines ut_varchar2_rows) is
pragma autonomous_transaction;
begin
insert
into ut_output_buffer_tmp(output_id, message_id, text)
select self.output_id, ut_message_id_seq.nextval, t.column_value
from table(a_lines) t
where t.column_value is not null;
commit;
end;

overriding member procedure send_line(self in ut_output_table_buffer, a_text varchar2) is
l_text_list ut_varchar2_rows;
pragma autonomous_transaction;
Expand Down
2 changes: 2 additions & 0 deletions source/core/output_buffers/ut_output_table_buffer.tps
Expand Up @@ -20,6 +20,8 @@ create or replace type ut_output_table_buffer under ut_output_buffer_base (
constructor function ut_output_table_buffer(self in out nocopy ut_output_table_buffer) return self as result,
overriding member procedure init(self in out nocopy ut_output_table_buffer, a_output_id raw),
overriding member procedure send_line(self in ut_output_table_buffer, a_text varchar2),
overriding member procedure send_lines(self in ut_output_table_buffer, a_lines ut_varchar2_list),
overriding member procedure send_lines(self in ut_output_table_buffer, a_lines ut_varchar2_rows),
overriding member procedure close(self in ut_output_table_buffer),
overriding member function get_lines(a_initial_timeout natural := null, a_timeout_sec natural := null) return ut_varchar2_rows pipelined,
overriding member function get_lines_cursor(a_initial_timeout natural := null, a_timeout_sec natural := null) return sys_refcursor,
Expand Down
32 changes: 29 additions & 3 deletions source/core/types/ut_console_reporter_base.tpb
Expand Up @@ -21,14 +21,40 @@ create or replace type body ut_console_reporter_base is
ut_ansiconsole_helper.color_enabled(a_flag);
end;

member function red(self in out nocopy ut_console_reporter_base, a_text varchar2) return varchar2 is
begin
return ut_ansiconsole_helper.red(a_text);
end;

member function red(self in out nocopy ut_console_reporter_base, a_lines ut_varchar2_list) return ut_varchar2_list is
l_lines ut_varchar2_list := a_lines;
begin
if l_lines is not null then
for i in 1 .. l_lines.count loop
l_lines(i) := red(l_lines(i));
end loop;
end if;
return l_lines;
end;

member function green(self in out nocopy ut_console_reporter_base, a_text varchar2) return varchar2 is
begin
return ut_ansiconsole_helper.green(a_text);
end;

member function cyan(self in out nocopy ut_console_reporter_base, a_text varchar2) return varchar2 is
begin
return ut_ansiconsole_helper.cyan(a_text);
end;

member procedure print_red_text(self in out nocopy ut_console_reporter_base, a_text varchar2) is
begin
self.print_text(ut_ansiconsole_helper.red(a_text));
self.print_text(red(a_text));
end;

member procedure print_green_text(self in out nocopy ut_console_reporter_base, a_text varchar2) is
begin
self.print_text(ut_ansiconsole_helper.green(a_text));
self.print_text(green(a_text));
end;

member procedure print_yellow_text(self in out nocopy ut_console_reporter_base, a_text varchar2) is
Expand All @@ -43,7 +69,7 @@ create or replace type body ut_console_reporter_base is

member procedure print_cyan_text(self in out nocopy ut_console_reporter_base, a_text varchar2) is
begin
self.print_text(ut_ansiconsole_helper.cyan(a_text));
self.print_text(cyan(a_text));
end;

member procedure print_magenta_text(self in out nocopy ut_console_reporter_base, a_text varchar2) is
Expand Down
5 changes: 5 additions & 0 deletions source/core/types/ut_console_reporter_base.tps
Expand Up @@ -17,6 +17,11 @@ create or replace type ut_console_reporter_base under ut_output_reporter_base(
*/
static procedure set_color_enabled(a_flag boolean),

member function red(self in out nocopy ut_console_reporter_base, a_text varchar2) return varchar2,
member function red(self in out nocopy ut_console_reporter_base, a_lines ut_varchar2_list) return ut_varchar2_list,
member function green(self in out nocopy ut_console_reporter_base, a_text varchar2) return varchar2,
member function cyan(self in out nocopy ut_console_reporter_base, a_text varchar2) return varchar2,

member procedure print_red_text(self in out nocopy ut_console_reporter_base, a_text varchar2),

member procedure print_green_text(self in out nocopy ut_console_reporter_base, a_text varchar2),
Expand Down
9 changes: 6 additions & 3 deletions source/core/types/ut_output_reporter_base.tpb
Expand Up @@ -34,6 +34,11 @@ create or replace type body ut_output_reporter_base is
self.output_buffer.send_line(a_text);
end;

member procedure print_lines(self in out nocopy ut_output_reporter_base, a_lines ut_varchar2_list) is
begin
self.output_buffer.send_lines(a_lines);
end;

final member function get_lines(a_initial_timeout natural := null, a_timeout_sec natural) return ut_varchar2_rows pipelined is
begin
for i in (select column_value from table(self.output_buffer.get_lines(a_initial_timeout, a_timeout_sec))) loop
Expand All @@ -56,9 +61,7 @@ create or replace type body ut_output_reporter_base is
begin
if a_clob is not null and dbms_lob.getlength(a_clob) > 0 then
l_lines := ut_utils.clob_to_table(a_clob);
for i in 1 .. l_lines.count loop
self.print_text(l_lines(i));
end loop;
self.print_lines(l_lines);
end if;
end;

Expand Down
1 change: 1 addition & 0 deletions source/core/types/ut_output_reporter_base.tps
Expand Up @@ -19,6 +19,7 @@ create or replace type ut_output_reporter_base under ut_reporter_base(
member procedure init(self in out nocopy ut_output_reporter_base, a_self_type varchar2, a_output_buffer ut_output_buffer_base := null),
overriding member procedure set_reporter_id(self in out nocopy ut_output_reporter_base, a_reporter_id raw),
member procedure print_text(self in out nocopy ut_output_reporter_base, a_text varchar2),
member procedure print_lines(self in out nocopy ut_output_reporter_base, a_lines ut_varchar2_list),

member procedure print_clob(self in out nocopy ut_output_reporter_base, a_clob clob),

Expand Down
18 changes: 18 additions & 0 deletions source/core/ut_utils.pkb
Expand Up @@ -328,6 +328,24 @@ create or replace package body ut_utils is
end if;
end;

procedure append(a_src_list in out nocopy ut_varchar2_list, a_text varchar2) is
begin
if a_src_list is null then
a_src_list := ut_varchar2_list();
end if;
a_src_list.extend();
a_src_list(a_src_list.last()) := a_text;
end;

procedure append(a_src_list in out nocopy ut_varchar2_list, a_list ut_varchar2_list) is
begin
if a_list is not null then
for i in 1 .. a_list.count loop
append(a_src_list, a_list(i));
end loop;
end if;
end;

function convert_collection(a_collection ut_varchar2_list) return ut_varchar2_rows is
l_result ut_varchar2_rows;
begin
Expand Down
2 changes: 2 additions & 0 deletions source/core/ut_utils.pks
Expand Up @@ -217,6 +217,8 @@ create or replace package ut_utils authid definer is

procedure append_to_clob(a_src_clob in out nocopy clob, a_new_data clob);
procedure append_to_clob(a_src_clob in out nocopy clob, a_new_data varchar2);
procedure append(a_src_list in out nocopy ut_varchar2_list, a_text varchar2);
procedure append(a_src_list in out nocopy ut_varchar2_list, a_list ut_varchar2_list);

function convert_collection(a_collection ut_varchar2_list) return ut_varchar2_rows;

Expand Down
90 changes: 60 additions & 30 deletions source/reporters/ut_documentation_reporter.tpb
Expand Up @@ -27,17 +27,43 @@ create or replace type body ut_documentation_reporter is
member function tab(self in ut_documentation_reporter) return varchar2 is
begin
return rpad(' ', self.lvl * 2);
end;

member function tab(self in ut_documentation_reporter, a_text varchar2) return varchar2 is
begin
if rtrim(a_text) is not null then
return rtrim(tab||replace(a_text,chr(10), chr(10)||tab()));
else
return a_text;
end if;
end tab;

overriding member procedure print_text(self in out nocopy ut_documentation_reporter, a_text varchar2) is
member function tab(self in ut_documentation_reporter, a_lines ut_varchar2_list) return ut_varchar2_list is
l_lines ut_varchar2_list;
begin
if a_text is not null then
l_lines := ut_utils.string_to_table(a_text);
if a_lines is not null then
l_lines := a_lines;
for i in 1 .. l_lines.count loop
(self as ut_output_reporter_base).print_text(tab || l_lines(i));
l_lines(i) := tab(l_lines(i));
end loop;
end if;
return l_lines;
end tab;

overriding member procedure print_lines(self in out nocopy ut_documentation_reporter, a_lines ut_varchar2_list) is
l_lines ut_varchar2_list := a_lines;
begin
if l_lines is not null then
for i in 1 .. l_lines.count loop
l_lines(i) := tab(l_lines(i));
end loop;
end if;
(self as ut_output_reporter_base).print_lines(l_lines);
end;

overriding member procedure print_text(self in out nocopy ut_documentation_reporter, a_text varchar2) is
begin
(self as ut_output_reporter_base).print_text(tab(a_text));
end;

overriding member procedure before_calling_suite(self in out nocopy ut_documentation_reporter, a_suite ut_logical_suite) as
Expand Down Expand Up @@ -84,39 +110,39 @@ create or replace type body ut_documentation_reporter is
end;

overriding member procedure after_calling_run(self in out nocopy ut_documentation_reporter, a_run in ut_run) as
c_nl varchar2(1) := chr(10);
l_summary_text varchar2(4000);
l_warning_index pls_integer := 0;
-- make all warning indexes uniformly indented
c_warnings_lpad constant integer := length(to_char(a_run.results_count.warnings_count));

procedure print_failure_for_expectation(a_expectation ut_expectation_result) is
function get_failure_for_expectation(a_expectation ut_expectation_result) return ut_varchar2_list is
l_lines ut_varchar2_list;
begin
l_lines := a_expectation.get_result_lines();
for i in 1 .. l_lines.count loop
self.print_red_text(l_lines(i));
end loop;
self.print_cyan_text(a_expectation.caller_info);
self.print_text(' ');
l_lines := self.red(l_lines);
ut_utils.append(l_lines, self.cyan(a_expectation.caller_info));
ut_utils.append(l_lines, ' ');
return l_lines;
end;

procedure print_failures_for_test(a_test ut_test, a_failure_no in out nocopy integer) is
l_failures ut_varchar2_list := ut_varchar2_list();
begin
if a_test.result > ut_utils.tr_success then
a_failure_no := a_failure_no + 1;
self.print_text(lpad(a_failure_no, length(failed_test_running_count) + 2, ' ') || ') ' ||
nvl(a_test.name, a_test.item.form_name));
ut_utils.append( l_failures, lpad(a_failure_no, length(failed_test_running_count) + 2, ' ') || ') '|| nvl(a_test.name, a_test.item.form_name));
self.lvl := self.lvl + 3;

self.print_red_text(ut_utils.table_to_clob(a_test.get_error_stack_traces()));
ut_utils.append(l_failures, tab(self.red(a_test.get_error_stack_traces())));

for j in 1 .. a_test.results.count loop
if a_test.results(j).status > ut_utils.tr_success then
print_failure_for_expectation(a_test.results(j));
ut_utils.append(l_failures, tab(get_failure_for_expectation(a_test.results(j))));
end if;
end loop;

self.lvl := self.lvl - 3;
self.print_lines(l_failures);
end if;
end;

Expand Down Expand Up @@ -146,6 +172,7 @@ create or replace type body ut_documentation_reporter is

procedure print_item_warnings(a_item in ut_suite_item) is
l_items ut_suite_items;
l_warnings ut_varchar2_list;
begin
if a_item is of (ut_logical_suite) then
l_items := treat(a_item as ut_logical_suite).items;
Expand All @@ -157,23 +184,24 @@ create or replace type body ut_documentation_reporter is
end if;

if a_item.warnings is not null and a_item.warnings.count > 0 then
for i in 1 .. a_item.warnings.count loop
l_warnings := a_item.warnings;
self.lvl := self.lvl + 3;
for i in 1 .. l_warnings.count loop
l_warning_index := l_warning_index + 1;
self.print_text(' ' || lpad(l_warning_index, c_warnings_lpad) || ') ' || a_item.path);
self.lvl := self.lvl + 3;
self.print_red_text(a_item.warnings(i));
self.lvl := self.lvl - 3;
l_warnings(i) :=
' ' || lpad(l_warning_index, c_warnings_lpad) || ') ' || a_item.path ||c_nl
||tab(self.red(l_warnings(i)));
end loop;
self.print_text(' ');
self.lvl := self.lvl - 3;
ut_utils.append(l_warnings, ' ');
self.print_lines(l_warnings);
end if;
end;

procedure print_warnings(a_run in ut_run) is
begin
if a_run.results_count.warnings_count > 0 then
self.print_text(' ');
self.print_text('Warnings:');
self.print_text(' ');
self.print_text(' '||c_nl||'Warnings:'||c_nl||' ');
for i in 1 .. a_run.items.count loop
print_item_warnings(treat(a_run.items(i) as ut_suite_item));
end loop;
Expand All @@ -183,18 +211,20 @@ create or replace type body ut_documentation_reporter is
begin
print_failures_details(a_run);
print_warnings(a_run);
self.print_text('Finished in ' || a_run.execution_time || ' seconds');

l_summary_text :=
a_run.results_count.total_count || ' tests, '
|| a_run.results_count.failure_count || ' failed, ' || a_run.results_count.errored_count || ' errored, '
|| a_run.results_count.disabled_count ||' disabled, ' || a_run.results_count.warnings_count || ' warning(s)';
|| a_run.results_count.disabled_count ||' disabled, ' || a_run.results_count.warnings_count || ' warning(s)'||c_nl
||' ';
if a_run.results_count.failure_count + a_run.results_count.errored_count + a_run.results_count.warnings_count > 0 then
self.print_red_text(l_summary_text);
l_summary_text := self.red(l_summary_text);
else
self.print_green_text(l_summary_text);
l_summary_text := self.green(l_summary_text);
end if;
self.print_text(' ');
self.print_text(
'Finished in ' || a_run.execution_time || ' seconds'||c_nl
||l_summary_text
);
end;

end;
Expand Down
3 changes: 3 additions & 0 deletions source/reporters/ut_documentation_reporter.tps
Expand Up @@ -19,8 +19,11 @@ create or replace type ut_documentation_reporter under ut_console_reporter_base(
failed_test_running_count integer,
constructor function ut_documentation_reporter(self in out nocopy ut_documentation_reporter) return self as result,
member function tab(self in ut_documentation_reporter) return varchar2,
member function tab(self in ut_documentation_reporter, a_text varchar2) return varchar2,
member function tab(self in ut_documentation_reporter, a_lines ut_varchar2_list) return ut_varchar2_list,

overriding member procedure print_text(self in out nocopy ut_documentation_reporter, a_text varchar2),
overriding member procedure print_lines(self in out nocopy ut_documentation_reporter, a_lines ut_varchar2_list),
overriding member procedure before_calling_suite(self in out nocopy ut_documentation_reporter, a_suite ut_logical_suite),
overriding member procedure after_calling_test(self in out nocopy ut_documentation_reporter, a_test ut_test),
overriding member procedure after_calling_after_all (self in out nocopy ut_documentation_reporter, a_suite in ut_logical_suite),
Expand Down
30 changes: 14 additions & 16 deletions source/reporters/ut_sonar_test_reporter.tpb
Expand Up @@ -48,28 +48,26 @@ create or replace type body ut_sonar_test_reporter is
l_message varchar2(32757);
l_lines ut_varchar2_list;
begin
self.print_text('<testCase name="'||a_test.name||'" duration="'||round(a_test.execution_time()*1000,0)||'" >');
ut_utils.append(l_lines, '<testCase name="'||a_test.name||'" duration="'||round(a_test.execution_time()*1000,0)||'" >');
if a_test.result = ut_utils.tr_disabled then
self.print_text('<skipped message="skipped"/>');
ut_utils.append(l_lines, '<skipped message="skipped"/>');
elsif a_test.result = ut_utils.tr_error then
self.print_text('<error message="encountered errors">');
self.print_text('<![CDATA[');
self.print_clob(ut_utils.table_to_clob(a_test.get_error_stack_traces()));
self.print_text(']]>');
self.print_text('</error>');
ut_utils.append(l_lines, '<error message="encountered errors">');
ut_utils.append(l_lines, '<![CDATA[');
ut_utils.append(l_lines, a_test.get_error_stack_traces());
ut_utils.append(l_lines, ']]>');
ut_utils.append(l_lines, '</error>');
elsif a_test.result > ut_utils.tr_success then
self.print_text('<failure message="some expectations have failed">');
self.print_text('<![CDATA[');
ut_utils.append(l_lines, '<failure message="some expectations have failed">');
ut_utils.append(l_lines, '<![CDATA[');
for i in 1 .. a_test.results.count loop
l_lines := a_test.results(i).get_result_lines();
for i in 1 .. l_lines.count loop
self.print_text(l_lines(i));
end loop;
ut_utils.append(l_lines, a_test.results(i).get_result_lines());
end loop;
self.print_text(']]>');
self.print_text('</failure>');
ut_utils.append(l_lines, ']]>');
ut_utils.append(l_lines, '</failure>');
end if;
self.print_text('</testCase>');
ut_utils.append(l_lines, '</testCase>');
self.print_lines(l_lines);
end;

overriding member procedure after_calling_suite(self in out nocopy ut_sonar_test_reporter, a_suite ut_logical_suite) is
Expand Down

0 comments on commit bad487b

Please sign in to comment.