Progress 4gl如何锁定自己?

Progress4gl how to lock yourself?

在单元测试中,我需要验证程序在处理 table 时是否跳过锁定的记录。 我一直无法设置锁定记录,因为测试无法自行锁定,这很有意义。

这是我正在努力实现的示例。

  DEV VAR v_isCommitted        AS LOGI NO-UNDO.
  DEF VAR hl                   AS HANDLE   NO-UNDO.
  DEF BUFFER bufl              FOR tablename. 
  hl = BUFFER bufl:HANDLE. 

  LOCKED_RECORDS:
  DO TRANSACTION ON ERROR UNDO, LEAVE LOCKED_RECORDS:
      /*Setup : Create record not committed yet*/
      CREATE tablename.
      ASSIGN tablename.fields = fieldsvalue.



      /*ACT :  Code I'm trying to test*/   
      /*...some code...*/  
      v_isCommitted = hl:FIND-BY-ROWID(ROWID(tablename), EXCLUSIVE-LOCK, NO-WAIT)
                                AND AVAILABLE(bufl) 
                                AND NOT LOCKED(bufl).
      /*...some code touching the record if it is commited...*/   

      /*ASSERT :  program left new record tablename AS IS.*/

  END.

问题是记录可用但未锁定到测试,因为它是由它创建的。
有没有一种方法可以让测试锁定自己的记录,这样 act 部分实际上可以跳过记录,就像它是由其他人创建的一样?

进度:11.7.1

会话无法自行锁定。因此,您需要开始第二个会话。例如:

/* code to set things up ... */

/* spawn a sub process to try to lock the record */

os-command silent value( substitute( '_progres -b -db &1 -p lockit.p -param "&2" && > logfile 2>&&1', dbname, "key" )).

在 lockit.p 中使用 session:parameter 获取要测试的记录的密钥(或者我想是硬编码)。

或者,如以下评论所述:

/* locktest.p
 */

define variable lockStatus as character no-undo format "x(20)".

find first customer exclusive-lock.

input through value( "_progres /data/sports120/sports120 -b -p ./lockit.p" ).
repeat:
  import unformatted lockStatus.
end.

display lockStatus.

和:

/* lockit.p
 */

find first customer exclusive-lock no-wait no-error.
if locked( customer ) then
  put "locked".
 else
  put "not locked".

quit.