Instance primary = (Instance)primaryClass.invoke("new");
Instance primary2 = (Instance)primaryClass.invoke("new");
Instance primary3 = (Instance)primaryClass.invoke("new");
Instance primary4 = (Instance)primaryClass.invoke("new");
Instance scheduler = (Instance)schedulerClass.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);
primary4.setValue("trace", null);
primary4.setValue("throwOuterEx", Boolean.FALSE);
primary4.setValue("throwUncaughtEx", Boolean.FALSE);
/*
* Test: One job, inside time window
*/
schedulerClass.setValue("time", Primitive.toTimestamp(Primitive.createInteger(1000)));
primary.setValue("trace", null);
primary.setValue("queueName", "Semaphore");
primary.invoke("goSemaphore");
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(Boolean.TRUE, assignment.getValue("semaphore"));
assertEquals(Primitive.ONE_INTEGER, assignment.getValue("status"));
invocationList = (List)schedulerClass.getValue("asyncInvokeList");
assertEquals(1, invocationList.size());
assertEquals(assignment.getOID(), invocationList.get(0));
// Simulate run of Job
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();
/*
* Test: Two jobs, queue concurrency = 1
*/
((List)schedulerClass.getValue("asyncInvokeList")).clear();
primary.setValue("queueName", "SemaphoreLowConcurrency");
primary2.setValue("queueName", "SemaphoreLowConcurrency");
primary.setValue("trace", null);
primary2.setValue("trace", null);
primary.invoke("goSemaphore");
Thread.sleep(50);
primary2.invoke("goSemaphore");
// Job 2: NOT 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.ZERO_INTEGER, assignment.getValue("status"));
assertEquals("BEFORE;ASSIGNMENT_CREATE;", primary2.getValue("trace"));
// 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"));
invocationList = (List)schedulerClass.getValue("asyncInvokeList");
assertEquals(1, invocationList.size());
assertEquals(assignment.getOID(), invocationList.get(0));
// Simulate run 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"));
// Job 1 finished, Job 2 should have been run
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"));
invocationList = (List)schedulerClass.getValue("asyncInvokeList");
assertEquals(2, invocationList.size());
assertEquals(assignment.getOID(), invocationList.get(1));
// Simulate run 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();
/*
* Test: Four jobs. System concurrency: 2.
* Job 1: Low concurrency queue RUN...FINISH
* Job 2: Low concurrency queue WAIT | RUN...FINISH
* Job 3: High concurrency queue RUN........|.....FINISH^
* Job 4: High concurrency queue WAIT RUN...........FINISH
*/
((List)schedulerClass.getValue("asyncInvokeList")).clear();
primary.setValue("queueName", "SemaphoreLowConcurrency");
primary2.setValue("queueName", "SemaphoreLowConcurrency");
primary3.setValue("queueName", "Semaphore");
primary4.setValue("queueName", "Semaphore");
primary.setValue("trace", null);
primary2.setValue("trace", null);
primary3.setValue("trace", null);
primary4.setValue("trace", null);
primary.invoke("goSemaphore");
Thread.sleep(50);
primary2.invoke("goSemaphore");
Thread.sleep(50);
primary3.invoke("goSemaphore");
Thread.sleep(50);
primary4.invoke("goSemaphore");
invocationList = (List)schedulerClass.getValue("asyncInvokeList");
assertEquals(2, invocationList.size());
// Job 4: NOT RUNNING
workflowList = (InstanceList)workflowClass.invoke("forInstance",
new Object[]{primary4});
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;", primary4.getValue("trace"));
// Job 2: NOT 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.ZERO_INTEGER, assignment.getValue("status"));
assertEquals("BEFORE;ASSIGNMENT_CREATE;", primary2.getValue("trace"));
// Job 3: 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.ONE_INTEGER, assignment.getValue("status"));
assertEquals(assignment.getOID(), invocationList.get(1));
// 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();
// Job 2 or 4 could run: 4 runs because its queue has higher priority
assertEquals(3, invocationList.size());
// Job 4: RUNNING
workflowList = (InstanceList)workflowClass.invoke("forInstance",
new Object[]{primary4});
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));
// Job 2: NOT 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.ZERO_INTEGER, assignment.getValue("status"));
assertEquals("BEFORE;ASSIGNMENT_CREATE;", primary2.getValue("trace"));
// Job 3: 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.ONE_INTEGER, assignment.getValue("status"));
assertEquals(assignment.getOID(), invocationList.get(1));
// Simulate run/finish of Job 3
assignment.invoke("schedulerRun");
assertEquals(Instance.DELETED, assignment.getState());
assertEquals(Instance.DELETED, workflow.getState());
assertEquals("BEFORE;ASSIGNMENT_CREATE;EXECUTE_SEMAPHORE;END_SEMAPHORE;ASSIGNMENT_DELETE;AFTER;", primary3.getValue("trace"));
commit();
// Job 2 runs
assertEquals(4, invocationList.size());
// 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(assignment.getOID(), invocationList.get(3));
// Job 4: RUNNING
workflowList = (InstanceList)workflowClass.invoke("forInstance",
new Object[]{primary4});
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));
// Simulate run/finish of Job 4
assignment.invoke("schedulerRun");
assertEquals(Instance.DELETED, assignment.getState());
assertEquals(Instance.DELETED, workflow.getState());
assertEquals("BEFORE;ASSIGNMENT_CREATE;EXECUTE_SEMAPHORE;END_SEMAPHORE;ASSIGNMENT_DELETE;AFTER;", primary4.getValue("trace"));
assertEquals(4, invocationList.size());
// 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(assignment.getOID(), invocationList.get(3));
// 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"));
assertEquals(4, invocationList.size());
/*
* Test: One job, outside of time window.
*/
((List)schedulerClass.getValue("asyncInvokeList")).clear();
schedulerClass.setValue("time", Primitive.toTimestamp(Primitive.createInteger(15000)));
primary.setValue("trace", null);
primary.setValue("queueName", "Semaphore");
primary.invoke("goSemaphore");
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(Boolean.TRUE, assignment.getValue("semaphore"));
assertEquals(Primitive.ZERO_INTEGER, assignment.getValue("status"));