1
0
mirror of https://github.com/sasjs/core.git synced 2026-01-06 09:00:06 +00:00

feat: mp_lockXXX macros f

These macros provide a centralised approach for locking tables where updates can happen in multiple passes.  The mp_lockfilecheck macro will also verify the ability to create a SAS lock (if a v9 library engine, and not a view)
This commit is contained in:
Allan Bowe
2021-11-25 16:43:39 +00:00
parent 5225e74465
commit 107ab836d6
5 changed files with 455 additions and 1 deletions

View File

@@ -0,0 +1,62 @@
/**
@file
@brief Testing mp_lockfilecheck macro
<h4> SAS Macros </h4>
@li mp_lockanytable.sas
@li mp_assertcols.sas
@li mp_assertcolvals.sas
**/
/* check create table */
%mp_lockanytable(MAKETABLE, ctl_ds=work.controller)
%mp_assertcols(work.controller,
cols=lock_status_cd lock_lib lock_ds lock_user_nm lock_ref lock_pid
lock_start_dttm lock_end_dttm,
test=ALL,
desc=check all control columns exist
)
/* check lock table */
options dlcreatedir;
libname tmp "%sysfunc(pathname(work))/tmp";
data tmp.sometable;
x=1;
run;
%mp_lockanytable(LOCK,lib=tmp,ds=sometable,ref=This Ref, ctl_ds=work.controller)
data work.checkds1;
checkval='SOMETABLE';
run;
%mp_assertcolvals(work.controller.lock_ds,
checkvals=work.checkds1.checkval,
desc=table is captured in lock,
test=ANYVAL
)
data work.checkds2;
checkval='LOCKED';
run;
%mp_assertcolvals(work.controller.lock_status_cd,
checkvals=work.checkds2.checkval,
desc=code is captured in lock,
test=ANYVAL
)
/* check for unsuccessful unlock */
%mp_lockanytable(UNLOCK,lib=tmp,ds=sometable,ref=bye, ctl_ds=work.controller)
data work.checkds3;
checkval='UNLOCKED';
run;
%mp_assertcolvals(work.controller.lock_status_cd,
checkvals=work.checkds3.checkval,
desc=Ref is captured in unlock,
test=ANYVAL
)

View File

@@ -0,0 +1,36 @@
/**
@file
@brief Testing mp_lockfilecheck macro
<h4> SAS Macros </h4>
@li mp_lockfilecheck.sas
@li mp_assert.sas
**/
/* check for regular lock */
data work.test; a=1;run;
%mp_lockfilecheck(work.test)
%mp_assert(
iftrue=(&syscc=0),
desc=Checking regular table can be locked,
outds=work.test_results
)
/* check for unsuccessful lock */
%global success abortme;
%let success=0;
%macro mp_abort(iftrue=,mac=,msg=);
%if &abortme=1 %then %let success=1;
%mend mp_abort;
%mp_lockfilecheck(sashelp.class)
%mp_assert(
iftrue=(&success=1),
desc=Checking sashelp table cannot be locked,
outds=work.test_results
)