|
| 1 | +create or replace package body test_output_buffer is |
| 2 | + |
| 3 | + procedure test_receive is |
| 4 | + l_actual_text clob; |
| 5 | + l_actual_item_type varchar2(1000); |
| 6 | + l_remaining integer; |
| 7 | + l_expected_text clob; |
| 8 | + l_expected_item_type varchar2(1000); |
| 9 | + l_buffer ut3.ut_output_buffer_base; |
| 10 | + begin |
| 11 | + --Arrange |
| 12 | + l_buffer := ut3.ut_output_table_buffer(); |
| 13 | + l_expected_text := to_clob(lpad('a text', 31000, ',a text')) |
| 14 | + || chr(10) || to_clob(lpad('a text', 31000, ',a text')) |
| 15 | + || chr(13) || to_clob(lpad('a text', 31000, ',a text')) |
| 16 | + || chr(13) || chr(10) || to_clob(lpad('a text', 31000, ',a text')) || to_clob(lpad('a text', 31000, ',a text')); |
| 17 | + l_expected_item_type := lpad('some item type',1000,'-'); |
| 18 | + --Act |
| 19 | + l_buffer.send_clob(l_expected_text, l_expected_item_type); |
| 20 | + l_buffer.close(); |
| 21 | + |
| 22 | + select text, item_type |
| 23 | + into l_actual_text, l_actual_item_type |
| 24 | + from table(l_buffer.get_lines(0,0)); |
| 25 | + |
| 26 | + --Assert |
| 27 | + ut.expect(l_actual_text).to_equal(l_expected_text); |
| 28 | + ut.expect(l_actual_item_type).to_equal(l_expected_item_type); |
| 29 | + |
| 30 | + select count(1) into l_remaining from table(ut3_tester_helper.run_helper.ut_output_buffer_tmp) |
| 31 | + where output_id = l_buffer.output_id; |
| 32 | + |
| 33 | + ut.expect(l_remaining).to_equal(0); |
| 34 | + end; |
| 35 | + |
| 36 | + procedure test_doesnt_send_on_null_text is |
| 37 | + l_cur sys_refcursor; |
| 38 | + l_result integer; |
| 39 | + l_buffer ut3.ut_output_buffer_base := ut3.ut_output_table_buffer(); |
| 40 | + begin |
| 41 | + ut3_tester_helper.run_helper.delete_buffer(); |
| 42 | + --Act |
| 43 | + l_buffer.send_line(null); |
| 44 | + |
| 45 | + open l_cur for select * from table(ut3_tester_helper.run_helper.ut_output_buffer_tmp); |
| 46 | + ut.expect(l_cur).to_be_empty; |
| 47 | + end; |
| 48 | + |
| 49 | + procedure test_send_line is |
| 50 | + l_result varchar2(4000); |
| 51 | + c_expected constant varchar2(4000) := lpad('a text',4000,',a text'); |
| 52 | + l_buffer ut3.ut_output_buffer_base := ut3.ut_output_table_buffer(); |
| 53 | + begin |
| 54 | + l_buffer.send_line(c_expected); |
| 55 | + |
| 56 | + select text into l_result from table(ut3_tester_helper.run_helper.ut_output_buffer_tmp) where output_id = l_buffer.output_id; |
| 57 | + |
| 58 | + ut.expect(l_result).to_equal(c_expected); |
| 59 | + end; |
| 60 | + |
| 61 | + procedure test_waiting_for_data is |
| 62 | + l_result clob; |
| 63 | + l_remaining integer; |
| 64 | + l_expected clob; |
| 65 | + l_buffer ut3.ut_output_buffer_base := ut3.ut_output_table_buffer(); |
| 66 | + l_start timestamp; |
| 67 | + l_duration interval day to second; |
| 68 | + begin |
| 69 | + --Arrange |
| 70 | + l_expected := 'a text'; |
| 71 | + l_buffer.send_line(l_expected); |
| 72 | + l_start := localtimestamp; |
| 73 | + --Act |
| 74 | + begin |
| 75 | + select text into l_result from table(l_buffer.get_lines(1,1)); |
| 76 | + ut.fail('Expected a timeout exception but nothing was raised'); |
| 77 | + exception |
| 78 | + when others then |
| 79 | + l_duration := localtimestamp - l_start; |
| 80 | + --Assert |
| 81 | + --Fetches data from output |
| 82 | + ut.expect(l_result).to_equal(l_expected); |
| 83 | + --Throws a timeout exception |
| 84 | + ut.expect(dbms_utility.format_error_stack()).to_match('ORA'||ut3.ut_utils.gc_out_buffer_timeout); |
| 85 | + --Waited for one second |
| 86 | + ut.expect(l_duration).to_be_greater_than(interval '0.99' second); |
| 87 | + end; |
| 88 | + |
| 89 | + select count(1) into l_remaining from table(ut3_tester_helper.run_helper.ut_output_buffer_tmp) where output_id = l_buffer.output_id; |
| 90 | + --Data got removed from output buffer |
| 91 | + ut.expect(l_remaining).to_equal(0); |
| 92 | + |
| 93 | + end; |
| 94 | + |
| 95 | +end test_output_buffer; |
| 96 | +/ |
0 commit comments