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

Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
36a061c
Removed parsing of annotation text (params) from ut_annotations as an…
jgebal Oct 6, 2017
a29cabe
Removed duplicate `old_tests` for ut_annotations - the functionality …
jgebal Oct 6, 2017
58c6293
Renamed `ut_annotations` to `ut_annotation_parser` and moved to annot…
jgebal Oct 7, 2017
375a7ff
Removed ``ut_annotations` from uninstall script.
jgebal Oct 7, 2017
13703fa
Fixed failing old tests after refactoring.
jgebal Oct 7, 2017
ac23f15
Refactored ut_annotation_parser API to use `ut_annotations` collectio…
jgebal Oct 7, 2017
df2c763
Added cache mechanism to `ut_annotation_parser`.
jgebal Oct 8, 2017
6088c81
Added ability to get annotations for single object.
jgebal Oct 9, 2017
4ec9eb5
Reworking annotation cache - not to use cast(Collect()) on dba_source.
jgebal Oct 13, 2017
dbf2538
Fixed failing test and test for Wrapped package.
jgebal Oct 14, 2017
ca31e98
Added missing annotation manager.
jgebal Oct 14, 2017
289f006
Removed dbms_output from code.
jgebal Oct 14, 2017
8e26ed0
Merge remote-tracking branch 'upstream/develop' into feature/annotati…
jgebal Oct 14, 2017
239abde
Add grant ut_annotation_manager to public
pesse Oct 16, 2017
6acd2ad
Add grant ut_annotation_manager to ut3_user
pesse Oct 16, 2017
e114aae
Merge branch 'develop' into feature/annotations_restructuring
jgebal Oct 17, 2017
b83e142
Fixed hardcoded schema-name
jgebal Oct 18, 2017
6dcaae9
Merge remote-tracking branch 'upstream/develop' into feature/annotati…
jgebal Oct 18, 2017
aafca84
Refactored annotation cache.
jgebal Oct 22, 2017
cd394c7
Fixed test execution on 12.1.
jgebal Oct 23, 2017
73c15a2
Merge remote-tracking branch 'upstream/develop' into feature/annotati…
jgebal Oct 23, 2017
5967a3a
Fixed test execution on 12.1.
jgebal Oct 23, 2017
1438753
Merge branch 'develop' into feature/annotations_restructuring
jgebal Oct 24, 2017
4f5d870
Merge conflicts cleanup
jgebal Oct 24, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fixed test execution on 12.1.
Added wrapper procedures `purge_cache`, `rebuild_annotation_cache` in `ut_runner`
Added tests for wrappers.
Updated documentation for annotation cache calls.
  • Loading branch information
jgebal committed Oct 23, 2017
commit 5967a3afbaf6c1e071738b4779af49ddfceba29b
23 changes: 23 additions & 0 deletions docs/userguide/annotations.md
Original file line number Diff line number Diff line change
Expand Up @@ -214,3 +214,26 @@ When processing the test suite `test_pkg` defined in [Example of annotated test
rollback to savepoint 'beforeall'

```

# Annotation cache

utPLSQL needs to scan sources of package specifications to identify and parse annotations.
To improve framework startup time, specially when dealing with database users owning large amount of packages the framework has build-in persistent cache for annotations.

Cache is checked for staleness and refreshed automatically on every run.
The initial startup of utPLSQL for a schema will take longer than consecutive executions.

If you're in situation, where your database is controlled via CI/CD server and gets refreshed/wiped before each run of your tests,
consider building upfront and creating the snapshot of our database after the cache was refreshed.

To build annotation cache without actually invoking any tests, call `ut_runner.rebuild_annotation_cache(a_object_owner, a_object_type)` sql block for every unit test owner that you want to have annotations cache prebuilt.

Example:
```sql
exec ut_runner.rebuild_annotation_cache('HR', 'PACKAGE');
```

To purge annotations cache call:
```sql
exec ut_runner.purge_cache('HR', 'PACKAGE');
```
10 changes: 10 additions & 0 deletions source/api/ut_runner.pkb
Original file line number Diff line number Diff line change
Expand Up @@ -119,5 +119,15 @@ create or replace package body ut_runner is
);
end;

procedure rebuild_annotation_cache(a_object_owner varchar2, a_object_type varchar2) is
begin
ut_annotation_manager.rebuild_annotation_cache(a_object_owner, a_object_type);
end;

procedure purge_cache(a_object_owner varchar2, a_object_type varchar2) is
begin
ut_annotation_manager.purge_cache(a_object_owner, a_object_type);
end;

end ut_runner;
/
19 changes: 19 additions & 0 deletions source/api/ut_runner.pks
Original file line number Diff line number Diff line change
Expand Up @@ -58,5 +58,24 @@ create or replace package ut_runner authid current_user is
a_include_objects ut_varchar2_list := null, a_exclude_objects ut_varchar2_list := null, a_fail_on_errors boolean default false
);

/**
* Rebuilds annotation cache for a specified schema and object type.
* The procedure is called internally by `get_annotated_objects` function.
* It can be used to speedup initial execution of utPLSQL on a given schema
* if it is executed before any call is made to `ut.run` or `ut_runner.run` procedure.
*
* @param a_object_owner owner of objects to get annotations for
* @param a_object_type type of objects to get annotations for
*/
procedure rebuild_annotation_cache(a_object_owner varchar2, a_object_type varchar2);

/**
* Removes cached information about annotations for objects of specified type and specified owner
*
* @param a_object_owner owner of objects to purge annotations for
* @param a_object_type type of objects to purge annotations for
*/
procedure purge_cache(a_object_owner varchar2, a_object_type varchar2);

end ut_runner;
/
64 changes: 0 additions & 64 deletions test/ut_annotation_manager/test_annotation_manager.pkb
Original file line number Diff line number Diff line change
Expand Up @@ -64,39 +64,6 @@ create or replace package body test_annotation_manager is
commit;
end;

procedure setup_cache is
pragma autonomous_transaction;
begin
create_dummy_test_package();
execute immediate q'[create or replace procedure dummy_test_procedure as
--%some_annotation(some_text)
--%rollback(manual)
begin
null;
end;]';
execute immediate q'[create or replace procedure ut3.dummy_test_procedure as
--%some_annotation(some_text)
--%rollback(manual)
begin
null;
end;]';
ut3.ut_annotation_manager.rebuild_annotation_cache(user,'PACKAGE');
ut3.ut_annotation_manager.rebuild_annotation_cache(user,'PROCEDURE');
ut3.ut_annotation_manager.rebuild_annotation_cache('UT3','PROCEDURE');
end;

procedure cleanup_cache is
pragma autonomous_transaction;
begin
delete from ut3.ut_annotation_cache_info
where object_type = 'PROCEDURE' and object_owner in ('UT3',user)
or object_type = 'PACKAGE' and object_owner = user and object_name = 'DUMMY_TEST_PACKAGE';
drop_dummy_test_package();
execute immediate q'[drop procedure dummy_test_procedure]';
execute immediate q'[drop procedure ut3.dummy_test_procedure]';
end;



procedure add_new_package is
l_actual_cache_id integer;
Expand Down Expand Up @@ -285,36 +252,5 @@ create or replace package body test_annotation_manager is
ut.expect(l_actual).to_be_empty();
end;

procedure test_purge_schema_type is
l_actual sys_refcursor;
begin

open l_actual for
select * from ut3.ut_annotation_cache_info
where object_owner = user and object_type = 'PROCEDURE';
ut.expect(l_actual).not_to_be_empty();

--Act
ut3.ut_annotation_cache_manager.purge_cache(user,'PROCEDURE');

--Assert
open l_actual for
select * from ut3.ut_annotation_cache_info
where object_owner = user and object_type = 'PROCEDURE';
--Cache purged for object owner/type
ut.expect(l_actual).to_be_empty();
open l_actual for
select * from ut3.ut_annotation_cache_info
where object_owner = user and object_type = 'PACKAGE';
--Cache not purged for other types
ut.expect(l_actual).not_to_be_empty();
open l_actual for
select * from ut3.ut_annotation_cache_info
where object_owner != user and object_type = 'PROCEDURE';
--Cache not purged for other owners
ut.expect(l_actual).not_to_be_empty();

end;

end test_annotation_manager;
/
8 changes: 0 additions & 8 deletions test/ut_annotation_manager/test_annotation_manager.pks
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,5 @@ create or replace package test_annotation_manager is
--%beforetest(create_dummy_test_package)
procedure no_data_for_dropped_object;

procedure setup_cache;
procedure cleanup_cache;

--%test(Purges cache for a given schema and object type)
--%beforetest(setup_cache)
--%aftertest(cleanup_cache)
procedure test_purge_schema_type;

end test_annotation_manager;
/
98 changes: 98 additions & 0 deletions test/ut_runner/test_ut_runner.pkb
Original file line number Diff line number Diff line change
@@ -1,5 +1,50 @@
create or replace package body test_ut_runner is

procedure setup_cache_objects is
pragma autonomous_transaction;
begin
execute immediate q'[create or replace package dummy_test_package as
--%suite(dummy_test_suite)
--%rollback(manual)

--%test(dummy_test)
--%beforetest(some_procedure)
procedure some_dummy_test_procedure;
end;]';
execute immediate q'[create or replace procedure dummy_test_procedure as
--%some_annotation(some_text)
--%rollback(manual)
begin
null;
end;]';
execute immediate q'[create or replace procedure ut3.dummy_test_procedure as
--%some_annotation(some_text)
--%rollback(manual)
begin
null;
end;]';
end;

procedure setup_cache is
pragma autonomous_transaction;
begin
setup_cache_objects();
ut3.ut_annotation_manager.rebuild_annotation_cache(user,'PACKAGE');
ut3.ut_annotation_manager.rebuild_annotation_cache(user,'PROCEDURE');
ut3.ut_annotation_manager.rebuild_annotation_cache('UT3','PROCEDURE');
end;

procedure cleanup_cache is
pragma autonomous_transaction;
begin
delete from ut3.ut_annotation_cache_info
where object_type = 'PROCEDURE' and object_owner in ('UT3',user)
or object_type = 'PACKAGE' and object_owner = user and object_name = 'DUMMY_TEST_PACKAGE';
execute immediate q'[drop package dummy_test_package]';
execute immediate q'[drop procedure dummy_test_procedure]';
execute immediate q'[drop procedure ut3.dummy_test_procedure]';
end;

procedure create_test_spec
as
pragma autonomous_transaction;
Expand Down Expand Up @@ -160,5 +205,58 @@ end;';
drop_test_package();
end;

procedure test_purge_cache_schema_type is
l_actual sys_refcursor;
begin

open l_actual for
select * from ut3.ut_annotation_cache_info
where object_owner = user and object_type = 'PROCEDURE';
ut.expect(l_actual).not_to_be_empty();

--Act
ut3.ut_runner.purge_cache(user,'PROCEDURE');

--Assert
open l_actual for
select * from ut3.ut_annotation_cache_info
where object_owner = user and object_type = 'PROCEDURE';
--Cache purged for object owner/type
ut.expect(l_actual).to_be_empty();
open l_actual for
select * from ut3.ut_annotation_cache_info
where object_owner = user and object_type = 'PACKAGE';
--Cache not purged for other types
ut.expect(l_actual).not_to_be_empty();
open l_actual for
select * from ut3.ut_annotation_cache_info
where object_owner = 'UT3' and object_type = 'PROCEDURE';
--Cache not purged for other owners
ut.expect(l_actual).not_to_be_empty();

end;

procedure test_rebuild_cache_schema_type is
l_actual integer;
begin
--Act
ut3.ut_annotation_manager.rebuild_annotation_cache(user,'PACKAGE');
--Assert
select count(1) into l_actual
from ut3.ut_annotation_cache_info i
join ut3.ut_annotation_cache c on c.cache_id = i.cache_id
where object_owner = user and object_type = 'PACKAGE' and object_name = 'DUMMY_TEST_PACKAGE';
--Rebuild cache for user/packages
ut.expect(l_actual).to_equal(4);

select count(1) into l_actual
from ut3.ut_annotation_cache_info i
join ut3.ut_annotation_cache c on c.cache_id = i.cache_id
where object_owner = 'UT3' and object_type = 'PROCEDURE';

--Did not rebuild cache for ut3/procedures
ut.expect(l_actual).to_equal(0);
end;

end;
/
15 changes: 15 additions & 0 deletions test/ut_runner/test_ut_runner.pks
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,20 @@ create or replace package test_ut_runner is
--%test(does not consume dbms_output from before the run)
procedure run_keep_dbms_output_buffer;

procedure setup_cache;
procedure cleanup_cache;

--%test(Purges cache for a given schema and object type)
--%beforetest(setup_cache)
--%aftertest(cleanup_cache)
procedure test_purge_cache_schema_type;

procedure setup_cache_objects;

--%test(Rebuilds cache for a given schema and object type)
--%beforetest(setup_cache_objects)
--%aftertest(cleanup_cache)
procedure test_rebuild_cache_schema_type;

end;
/