Skip to content

Commit b39c5be

Browse files
committed
Added additional tests for annotation cache refresh with/without DDL trigger.
Fixed issues found while testing the code.
1 parent 335e420 commit b39c5be

File tree

13 files changed

+1027
-50
lines changed

13 files changed

+1027
-50
lines changed

.travis/install.sh

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -74,12 +74,6 @@ PROMPT Creating $UT3_TESTER - Power-user for testing internal framework code
7474
create user $UT3_TESTER identified by "$UT3_TESTER_PASSWORD" default tablespace $UT3_TABLESPACE quota unlimited on $UT3_TABLESPACE;
7575
grant create session, create procedure, create type, create table to $UT3_TESTER;
7676
77-
PROMPT Additional grants for disabling DDL trigger and testing parser without trigger enabled/present
78-
79-
grant alter any trigger to $UT3_TESTER;
80-
grant administer database trigger to $UT3_TESTER;
81-
grant execute on dbms_lock to $UT3_TESTER;
82-
8377
PROMPT Granting $UT3_OWNER code to $UT3_TESTER
8478
8579
begin
@@ -98,7 +92,7 @@ end;
9892
PROMPT Granting $UT3_OWNER tables to $UT3_TESTER
9993
10094
begin
101-
for i in ( select table_name from all_tables t where owner = 'UT3' and nested = 'NO' and IOT_NAME is NULL)
95+
for i in ( select table_name from all_tables t where owner = 'UT3' and nested = 'NO' and iot_name is null)
10296
loop
10397
execute immediate 'grant select on UT3.'||i.table_name||' to UT3_TESTER';
10498
end loop;
@@ -124,8 +118,33 @@ grant create public database link to $UT3_TESTER_HELPER;
124118
grant drop public database link to $UT3_TESTER_HELPER;
125119
126120
PROMPT Grants for testing coverage outside of main UT3 schema.
127-
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, create any synonym, drop any synonym to $UT3_TESTER_HELPER;
121+
grant create any procedure, drop any procedure, execute any procedure, create any type, drop any type, execute any type, under any type,
122+
select any table, update any table, insert any table, delete any table, create any table, drop any table, alter any table,
123+
select any dictionary, create any synonym, drop any synonym,
124+
grant any object privilege, grant any privilege
125+
to $UT3_TESTER_HELPER;
126+
128127
grant create job to $UT3_TESTER_HELPER;
129128
129+
PROMPT Additional grants for disabling DDL trigger and testing parser without trigger enabled/present
130+
131+
grant alter any trigger to $UT3_TESTER_HELPER;
132+
grant administer database trigger to $UT3_TESTER_HELPER;
133+
grant execute on dbms_lock to $UT3_TESTER_HELPER;
134+
135+
create user ut3_cache_test_owner identified by ut3;
136+
grant create session, create procedure to ut3_cache_test_owner;
137+
138+
create user ut3_no_extra_priv_user identified by ut3;
139+
grant create session, create procedure to ut3_no_extra_priv_user;
140+
141+
create user ut3_select_catalog_user identified by ut3;
142+
grant create session, create procedure, select_catalog_role to ut3_select_catalog_user;
143+
144+
create user ut3_select_any_table_user identified by ut3;
145+
grant create session, create procedure, select any table to ut3_select_any_table_user;
146+
147+
create user ut3_execute_any_proc_user identified by ut3;
148+
grant create session, create procedure, execute any procedure to ut3_execute_any_proc_user;
130149
exit
131150
SQL

development/cleanup.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@ drop user ${UT3_RELEASE_VERSION_SCHEMA} cascade;
2323
drop user ${UT3_TESTER} cascade;
2424
drop user ${UT3_TESTER_HELPER} cascade;
2525
drop user ${UT3_USER} cascade;
26+
drop user ut3_cache_test_owner cascade;
27+
drop user ut3_no_extra_priv_user cascade;
28+
drop user ut3_select_catalog_user cascade;
29+
drop user ut3_select_any_table_user cascade;
30+
drop user ut3_execute_any_proc_user cascade;
2631
2732
begin
2833
for i in (

docs/userguide/install.md

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -138,13 +138,6 @@ cd source
138138
sqlplus sys/sys_pass@db as sysdba @install_headless_with_trigger.sql utp3 my_verySecret_password utp3_tablespace
139139
```
140140

141-
**Note:**
142-
>When installing utPLSQL into database with existing unit test packages, utPLSQL will not be able to already-existing unit test packages. When utPSLQL was installed with DDL trigger, you have to do one of:
143-
>- Recompile existing Unit Test packages to make utPLSQL aware of their existence
144-
>- Invoke `exec ut_runner.rebuild_annotation_cache(a_object_owner=> ... );` for every schema containing unit tests in your database
145-
>
146-
> Steps above are required to assure annotation cache is populated properly from existing objects. Rebuilding annotation cache might be faster than code recompilation.
147-
148141
# Recommended Schema
149142
It is highly recommended to install utPLSQL in it's own schema. You are free to choose any name for this schema.
150143
Installing uPLSQL into shared schema is really not recommended as you loose isolation of framework.

source/core/annotations/ut_annotation_cache_manager.pkb

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ create or replace package body ut_annotation_cache_manager as
7878
on o.object_name = i.object_name
7979
and o.object_type = i.object_type
8080
and o.object_owner = i.object_owner
81+
and o.needs_refresh = 'Y'
8182
);
8283

8384
update ut_annotation_cache_schema s
@@ -86,18 +87,22 @@ create or replace package body ut_annotation_cache_manager as
8687
in (
8788
select o.object_owner, o.object_type
8889
from table(a_objects) o
90+
where o.needs_refresh = 'Y'
8991
);
9092

9193
if sql%rowcount = 0 then
9294
insert into ut_annotation_cache_schema s
9395
(object_owner, object_type, max_parse_time)
9496
select distinct o.object_owner, o.object_type, l_timestamp
95-
from table(a_objects) o;
97+
from table(a_objects) o
98+
where o.needs_refresh = 'Y';
9699
end if;
97100

98101
merge into ut_annotation_cache_info i
99102
using (select o.object_name, o.object_type, o.object_owner
100-
from table(a_objects) o ) o
103+
from table(a_objects) o
104+
where o.needs_refresh = 'Y'
105+
) o
101106
on (o.object_name = i.object_name
102107
and o.object_type = i.object_type
103108
and o.object_owner = i.object_owner)

source/core/ut_suite_manager.pkb

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,8 @@ create or replace package body ut_suite_manager is
363363
where a.object_name = c.object_name
364364
and a.owner = c.object_owner
365365
and a.object_type = 'PACKAGE'
366-
);
366+
)
367+
or c.self_type = 'UT_LOGICAL_SUITE';
367368
end if;
368369

369370
return l_result;
@@ -373,10 +374,7 @@ create or replace package body ut_suite_manager is
373374
a_owner_name varchar2
374375
) return boolean is
375376
begin
376-
return sys_context( 'userenv', 'current_schema' ) = a_owner_name or ut_metadata.user_has_execute_any_proc()
377-
or ( ut_trigger_check.is_alive()
378-
and ut_annotation_cache_manager.get_cache_schema_info(a_owner_name, 'PACKAGE').full_refresh_time is not null
379-
);
377+
return sys_context( 'userenv', 'current_schema' ) = a_owner_name or ut_metadata.user_has_execute_any_proc();
380378
end;
381379

382380
procedure build_and_cache_suites(
@@ -611,6 +609,7 @@ create or replace package body ut_suite_manager is
611609
and a.owner = c.object_owner
612610
and a.object_type = 'PACKAGE'
613611
)
612+
or c.item_type = 'UT_LOGICAL_SUITE'
614613
order by c.object_owner, c.object_name, c.item_line_no;
615614
end if;
616615
return l_result;
@@ -630,7 +629,7 @@ create or replace package body ut_suite_manager is
630629

631630
refresh_cache(l_owner_name);
632631
l_item_exists := ut_suite_cache_manager.suite_item_exists( l_owner_name, l_package_name, l_procedure_name );
633-
if not can_skip_all_objects_scan( l_owner_name ) then
632+
if not can_skip_all_objects_scan( l_owner_name ) and l_package_name is not null then
634633
select count(1)
635634
into l_count
636635
from dual c

test/install_ut3_tester_helper.sql

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ alter session set plsql_optimize_level=0;
2626
@@ut3_tester_helper/expectations_helper.pkb
2727
@@ut3_tester_helper/ut_example_tests.pkb
2828

29+
@@ut3_tester_helper/annotation_cache_helper.pks
30+
@@ut3_tester_helper/annotation_cache_helper.pkb
31+
create or replace synonym ut3_tester.annotation_cache_helper for ut3_tester_helper.annotation_cache_helper;
32+
2933
set linesize 200
3034
set define on
3135
set verify off

test/install_ut3_tester_tests.sql

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ alter session set plsql_optimize_level=0;
1313
@@ut3_tester/core/annotations/test_annotation_parser.pks
1414
@@ut3_tester/core/annotations/test_annot_throws_exception.pks
1515
@@ut3_tester/core/annotations/test_annotation_manager.pks
16+
@@ut3_tester/core/annotations/test_annotation_cache.pks
1617
@@ut3_tester/core/expectations/test_expectation_processor.pks
1718
@@ut3_tester/core/test_ut_utils.pks
1819
@@ut3_tester/core/test_ut_test.pks
@@ -27,9 +28,10 @@ alter session set plsql_optimize_level=0;
2728
@@ut3_tester/core.pkb
2829
@@ut3_tester/core/annotations/test_before_after_annotations.pkb
2930
@@ut3_tester/core/annotations/test_annotation_parser.pkb
30-
@@ut3_tester/core/expectations/test_expectation_processor.pkb
3131
@@ut3_tester/core/annotations/test_annotation_manager.pkb
3232
@@ut3_tester/core/annotations/test_annot_throws_exception.pkb
33+
@@ut3_tester/core/annotations/test_annotation_cache.pkb
34+
@@ut3_tester/core/expectations/test_expectation_processor.pkb
3335
@@ut3_tester/core/test_ut_utils.pkb
3436
@@ut3_tester/core/test_ut_test.pkb
3537
@@ut3_tester/core/test_ut_suite.pkb

0 commit comments

Comments
 (0)