}
}
private class MockOperationFacet implements OperationFacet {
public OperationResult invokeOperation(String name, Configuration parameters) throws Exception {
OperationResult opConfig = new OperationResult();
if (name.equals("initialOp")) {
manager.invokeOperation(JOB_2_ID, RESOURCE_2_ID, "secondOp", new Configuration()); // call back into OperationManager on different resource
// The above call to secondOp should be asynchronous and be able to run concurrently with us (because
// we are invoking it on resource 2, and we are running on resource 1).
// If it cannot complete within a few seconds, we have deadlocked.
// That would mean resource 1 is delaying a resource 2 op - which would be a bug.
// Different resources should not delay operations on other resources.
waitForAgentResponse(OPERATION_TIMEOUT_MILLIS, JOB_2_ID);
Object results = opResults.get(JOB_2_ID);
assert results != null : "our called job 2 did not finish";
assert results instanceof Configuration : "our called job 2 did not finish as expected: " + opResults;
assert ((Configuration) results).getSimple("secondOpResults").getStringValue()
.equals("secondOpSuccess") : "our called job 2 did not finish as expected: " + opResults;
opConfig.getComplexResults().put(new PropertySimple("initialOpResults", "initialOpSuccess"));
} else if (name.equals("secondOp")) {
opConfig.getComplexResults().put(new PropertySimple("secondOpResults", "secondOpSuccess"));
} else if (name.equals("initialOpSameResource")) {
manager.invokeOperation(JOB_2_ID, RESOURCE_1_ID, "secondOpSameResource", new Configuration()); // call back into OperationManager on same resource #1
// The above call to secondOp should not be able to run concurrently with us (because
// we are invoking it on resource 1, which is the same resource we are running on).
// This should deadlock - job 2 should never finish because it should never start (at least
// until we finish first).
// Therefore, we are going to wait for an agent response to job 2 that will never come.
// This will in turn cause our job to timeout.
waitForAgentResponse(OPERATION_TIMEOUT_MILLIS + 1000L, JOB_2_ID); // wait longer than the operation timeout
} else if (name.equals("secondOpSameResource")) {
opConfig.getComplexResults().put(
new PropertySimple("secondOpSameResourceResults", "secondOpSameResourceSuccess"));
} else {
throw new IllegalStateException("BAD TEST - unknown operation: " + name);
}