text: CREATE OR REPLACE PACKAGE XYZ.TPW_TEST IS
  
    -- AUTHOR  : Abel Cheng
    -- CREATED : 2012-04-16 9:53:17 PM
    -- PURPOSE : Test
  
  
  PROCEDURE TEST_1;
  
  PROCEDURE TEST_2;
  
  PROCEDURE TEST_3;
  
  PROCEDURE TEST_4;
  
  END TPW_TEST;
  /
  CREATE OR REPLACE PACKAGE BODY XYZ.TPW_TEST IS
  
  
  PROCEDURE TEST_1
  AS
  	tPJob_ID	PLS_INTEGER;
  	tSQL		VARCHAR2(256);
  BEGIN
  	tPJob_ID	:= XYZ.TPW_CALL.CREATE_PJOB('App1', 'User1', 'This is test1.');
  
  	tSQL	:= UTL_LMS.FORMAT_MESSAGE('DBMS_LOCK.SLEEP(%d)', 10);
  	XYZ.TPW_CALL.ADD_TASK(tPJob_ID, tSQL, 60, 'Task1 sleep for 10 seconds.');
  	
  	tSQL	:= UTL_LMS.FORMAT_MESSAGE('DBMS_LOCK.SLEEP(%d)', 70);
  	XYZ.TPW_CALL.ADD_TASK(tPJob_ID, tSQL, 60, 'Task2 sleep for 70 seconds.');
  
  	tSQL	:= UTL_LMS.FORMAT_MESSAGE('DBMS_LOCK.SLEEP(%d)', 30);
  	XYZ.TPW_CALL.ADD_TASK(tPJob_ID, tSQL, 60, 'Task3 sleep for 30 seconds.');
  
  	tSQL	:= UTL_LMS.FORMAT_MESSAGE('DBMS_LOCK.SLEEP(%d)', 70);
  	XYZ.TPW_CALL.ADD_TASK(tPJob_ID, tSQL, 120, 'Task4 sleep for 70 seconds.');
  
  	tSQL	:= UTL_LMS.FORMAT_MESSAGE('DBMS_LOCK.SLEEP(%d)', 15);
  	XYZ.TPW_CALL.ADD_CALLBACK_FOR_SUCCESS(tPJob_ID, tSQL, 180, 'Sleep for 15s if all success.');
  
  	tSQL	:= UTL_LMS.FORMAT_MESSAGE('DBMS_LOCK.SLEEP(%d)', 25);
  	XYZ.TPW_CALL.ADD_CALLBACK_FOR_FAIL(tPJob_ID, tSQL, 180, 'Sleep for 25s if fail.');
  
  	XYZ.TPW_CALL.START_PJOB(tPJob_ID);
  
  	DBMS_OUTPUT.PUT_LINE('New PJob_ID#' || tPJob_ID);
  END TEST_1;
  
  
  PROCEDURE TEST_2
  AS
  	tSQL		VARCHAR2(256);
  BEGIN
  	tSQL	:= UTL_LMS.FORMAT_MESSAGE('DBMS_LOCK.SLEEP(%d)', 10);
  	XYZ.TPW_CALL.START_NEW_SINGLE_TASK(tSQL);
  END TEST_2;
  
  
  PROCEDURE TEST_3
  AS
  	tPJob_ID	PLS_INTEGER;
  	tSQL		VARCHAR2(256);
  	bCancel		BOOLEAN;
  	tCan		VARCHAR2(16);
  BEGIN
  	tPJob_ID	:= XYZ.TPW_CALL.CREATE_PJOB('App3', 'User3', 'This is test3.');
  
  	tSQL	:= UTL_LMS.FORMAT_MESSAGE('DBMS_LOCK.SLEEP(%d)', 10);
  	XYZ.TPW_CALL.ADD_TASK(tPJob_ID, tSQL, 60, 'Task1 sleep for 10 seconds.');
  	
  	tSQL	:= UTL_LMS.FORMAT_MESSAGE('DBMS_LOCK.SLEEP(%d)', 20);
  	XYZ.TPW_CALL.ADD_TASK(tPJob_ID, tSQL, 60, 'Task2 sleep for 20 seconds.');
  
  	tSQL	:= UTL_LMS.FORMAT_MESSAGE('DBMS_LOCK.SLEEP(%d)', 30);
  	XYZ.TPW_CALL.ADD_TASK(tPJob_ID, tSQL, 60, 'Task3 sleep for 30 seconds.');
  
  	tSQL	:= UTL_LMS.FORMAT_MESSAGE('DBMS_LOCK.SLEEP(%d)', 15);
  	XYZ.TPW_CALL.ADD_CALLBACK_FOR_SUCCESS(tPJob_ID, tSQL, 180, 'Sleep for 15s if all success.');
  
  	XYZ.TPW_CALL.START_PJOB(tPJob_ID, SYSDATE + 1/24);
  
  	DBMS_OUTPUT.PUT_LINE('New PJob_ID#' || tPJob_ID);
  
  	DBMS_LOCK.SLEEP(30);
  
  	XYZ.TPW_CALL.TRY_CANCEL_PJOB(tPJob_ID, bCancel);
  	IF bCancel THEN
  		tCan := 'has';
  	ELSE
  		tCan := 'cannot';
  	END IF;
  
  	DBMS_OUTPUT.PUT_LINE(UTL_LMS.FORMAT_MESSAGE('PJob_ID#%d %s been canceled.', tPJob_ID, tCan));
  END TEST_3;
  
  
  PROCEDURE TEST_4
  AS
  	tPJob_ID	PLS_INTEGER;
  	tSQL		VARCHAR2(256);
  BEGIN
  	tPJob_ID	:= XYZ.TPW_CALL.CREATE_PJOB('App4', 'User4', 'This is test4.');
  
  	tSQL	:= UTL_LMS.FORMAT_MESSAGE('DBMS_LOCK.SLEEP(%d)', 10);
  	XYZ.TPW_CALL.ADD_TASK(tPJob_ID, tSQL, 60, 'Task1 sleep for 10 seconds.');
  	
  	tSQL	:= UTL_LMS.FORMAT_MESSAGE('DBMS_LOCK.SLEEP(%d)', 20);
  	XYZ.TPW_CALL.ADD_TASK(tPJob_ID, tSQL, 60, 'Task2 sleep for 70 seconds.');
  
  	tSQL	:= UTL_LMS.FORMAT_MESSAGE('DBMS_LOCK.SLEEP(%d)', 30);
  	XYZ.TPW_CALL.ADD_TASK(tPJob_ID, tSQL, 60, 'Task3 sleep for 30 seconds.');
  
  	tSQL	:= UTL_LMS.FORMAT_MESSAGE('DBMS_LOCK.SLEEP(%d)', 70);
  	XYZ.TPW_CALL.ADD_TASK(tPJob_ID, tSQL, 120, 'Task4 sleep for 70 seconds.');
  
  	tSQL	:= UTL_LMS.FORMAT_MESSAGE('DBMS_LOCK.SLEEP(%d)', 15);
  	XYZ.TPW_CALL.ADD_CALLBACK_FOR_SUCCESS(tPJob_ID, tSQL, 180, 'Sleep for 15s if all success.');
  
  	tSQL	:= UTL_LMS.FORMAT_MESSAGE('DBMS_LOCK.SLEEP(%d)', 25);
  	XYZ.TPW_CALL.ADD_CALLBACK_FOR_FAIL(tPJob_ID, tSQL, 180, 'Sleep for 25s if fail.');
  
  	XYZ.TPW_CALL.START_PJOB(tPJob_ID);
  
  	DBMS_OUTPUT.PUT_LINE('New PJob_ID#' || tPJob_ID);
  END TEST_4;
  
  
  END TPW_TEST;
  /
  