2019-05-23 19:31:03 -07:00
|
|
|
/*
|
|
|
|
|
* ProcessManagerTestImplementation
|
|
|
|
|
*
|
|
|
|
|
* v1.0
|
|
|
|
|
*
|
|
|
|
|
* May 23, 2019
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
package JobServ;
|
|
|
|
|
|
|
|
|
|
import java.util.concurrent.TimeoutException;
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* ProcessManagerTestImplementation
|
|
|
|
|
* inherits ProcessManager and adds useful functions for testing
|
|
|
|
|
*/
|
|
|
|
|
class ProcessManagerTestImplementation extends ProcessManager {
|
|
|
|
|
|
2019-05-23 22:13:57 -07:00
|
|
|
public void longCallHoldsLock(int pid) {
|
2019-05-23 19:31:03 -07:00
|
|
|
try {
|
2019-05-23 22:13:57 -07:00
|
|
|
super.getLock(pid);
|
2019-05-23 19:31:03 -07:00
|
|
|
System.err.println("[1] Long Call Has Lock");
|
|
|
|
|
|
|
|
|
|
// hold lock for 7 seconds, more than double normal timeout.
|
|
|
|
|
Thread.sleep(4000);
|
|
|
|
|
|
2019-05-23 22:13:57 -07:00
|
|
|
super.releaseLock(pid);
|
2019-05-23 19:31:03 -07:00
|
|
|
|
|
|
|
|
} catch (TimeoutException e) {
|
|
|
|
|
System.err.println("[!!] Long Call wasnt able to grab lock!");
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
} catch (InterruptedException e) {
|
2019-05-23 22:13:57 -07:00
|
|
|
super.releaseLock(pid); // this doesnt happen, dont cancel this task
|
2019-05-23 19:31:03 -07:00
|
|
|
System.err.println("[3] Released lock: interrupted");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-05-23 22:13:57 -07:00
|
|
|
public Boolean reportLockState(int pid) {
|
|
|
|
|
return super.lockMap.get(pid);
|
|
|
|
|
}
|
2019-05-23 19:31:03 -07:00
|
|
|
}
|