Instance primary = (Instance)primaryClass.invoke("new");
Instance primary2 = (Instance)primaryClass.invoke("new");
Instance primary3 = (Instance)primaryClass.invoke("new");
Instance scheduler = (Instance)schedulerClass.getValue("instance");
Instance throttleCounterBatchJob = (Instance)throttleCounterBatchJobClass.getValue("instance");
InstanceList workflowList, assignmentList;
Instance workflow, assignment;
List invocationList;
// Initialization
primary.setValue("trace", null);
primary.setValue("throwOuterEx", Boolean.FALSE);
primary.setValue("throwUncaughtEx", Boolean.FALSE);
primary2.setValue("trace", null);
primary2.setValue("throwOuterEx", Boolean.FALSE);
primary2.setValue("throwUncaughtEx", Boolean.FALSE);
primary3.setValue("trace", null);
primary3.setValue("throwOuterEx", Boolean.FALSE);
primary3.setValue("throwUncaughtEx", Boolean.FALSE);
/*
* Test: 3 jobs:
* Job 1: started at 0 seconds, runs immediately (in window)
* Job 2: started at 8 seconds, runs immediately (in window)
* Job 3: started at 9 seconds, doesn't run (throttle exceeded)
*
* @ 60 seconds: Timer tick, job counter reset, job 3 resumed.
*/
schedulerClass.setValue("time", Primitive.toTimestamp(Primitive.ZERO_INTEGER));
((List)schedulerClass.getValue("asyncInvokeList")).clear();
primary.setValue("queueName", "SemaphoreThrottled");
primary2.setValue("queueName", "SemaphoreThrottled");
primary3.setValue("queueName", "SemaphoreThrottled");
primary.setValue("trace", null);
primary2.setValue("trace", null);
primary3.setValue("trace", null);
primary.invoke("goSemaphore");
invocationList = (List)schedulerClass.getValue("asyncInvokeList");
assertEquals(1, invocationList.size());
// Job 1: RUNNING
workflowList = (InstanceList)workflowClass.invoke("forInstance",
new Object[]{primary});
assertEquals(1, workflowList.size());
workflow = workflowList.getInstance(0);
assignmentList = (InstanceList)workflow.getValue("assignments");
assertEquals(1, assignmentList.size());
assignment = assignmentList.getInstance(0);
assertEquals(Primitive.ONE_INTEGER, assignment.getValue("status"));
assertEquals(assignment.getOID(), invocationList.get(0));
// Simulate run/finish of Job 1
assignment.invoke("schedulerRun");
assertEquals(Instance.DELETED, assignment.getState());
assertEquals(Instance.DELETED, workflow.getState());
assertEquals("BEFORE;ASSIGNMENT_CREATE;EXECUTE_SEMAPHORE;END_SEMAPHORE;ASSIGNMENT_DELETE;AFTER;", primary.getValue("trace"));
commit();
// @ 8 seconds
schedulerClass.setValue("time", Primitive.toTimestamp(Primitive.createInteger(8000)));
primary2.invoke("goSemaphore");
// Job 2: RUNNING
workflowList = (InstanceList)workflowClass.invoke("forInstance",
new Object[]{primary2});
assertEquals(1, workflowList.size());
workflow = workflowList.getInstance(0);
assignmentList = (InstanceList)workflow.getValue("assignments");
assertEquals(1, assignmentList.size());
assignment = assignmentList.getInstance(0);
assertEquals(Primitive.ONE_INTEGER, assignment.getValue("status"));
assertEquals(2, invocationList.size());
assertEquals(assignment.getOID(), invocationList.get(1));
// Simulate run/finish of Job 2
assignment.invoke("schedulerRun");
assertEquals(Instance.DELETED, assignment.getState());
assertEquals(Instance.DELETED, workflow.getState());
assertEquals("BEFORE;ASSIGNMENT_CREATE;EXECUTE_SEMAPHORE;END_SEMAPHORE;ASSIGNMENT_DELETE;AFTER;", primary2.getValue("trace"));
commit();
// @ 9 seconds
schedulerClass.setValue("time", Primitive.toTimestamp(Primitive.createInteger(9000)));
primary3.invoke("goSemaphore");
// Job 3: NOT RUNNING
workflowList = (InstanceList)workflowClass.invoke("forInstance",
new Object[]{primary3});
assertEquals(1, workflowList.size());
workflow = workflowList.getInstance(0);
assignmentList = (InstanceList)workflow.getValue("assignments");
assertEquals(1, assignmentList.size());
assignment = assignmentList.getInstance(0);
assertEquals(Primitive.ZERO_INTEGER, assignment.getValue("status"));
assertEquals("BEFORE;ASSIGNMENT_CREATE;", primary3.getValue("trace"));
assertEquals(2, invocationList.size());
// @ 60 seconds
m_context.setSecure(false);
throttleCounterBatchJob.invoke("run");
m_context.setSecure(true);
schedulerClass.setValue("time", Primitive.toTimestamp(Primitive.createInteger(60000)));
scheduler.invoke("schedule");
assertEquals(3, invocationList.size());
workflowList = (InstanceList)workflowClass.invoke("forInstance",
new Object[]{primary3});
assertEquals(1, workflowList.size());
workflow = workflowList.getInstance(0);
assignmentList = (InstanceList)workflow.getValue("assignments");
assertEquals(1, assignmentList.size());
assignment = assignmentList.getInstance(0);
assertEquals(Primitive.ONE_INTEGER, assignment.getValue("status"));
assertEquals(assignment.getOID(), invocationList.get(2));