@Test public void testIsUpdateAcceptable() { assertTrue(IntentData.isUpdateAcceptable(null, data1)); assertTrue(IntentData.isUpdateAcceptable(data1, data2)); assertFalse(IntentData.isUpdateAcceptable(data2, data1)); IntentData installing = new IntentData(intent1, IntentState.INSTALLING, timestamp1); IntentData installed = new IntentData(intent1, IntentState.INSTALLED, timestamp1); IntentData withdrawing = new IntentData(intent1, IntentState.WITHDRAWING, timestamp1); IntentData withdrawn = new IntentData(intent1, IntentState.WITHDRAWN, timestamp1); IntentData failed = new IntentData(intent1, IntentState.FAILED, timestamp1); IntentData purgeReq = new IntentData(intent1, IntentState.PURGE_REQ, timestamp1); IntentData compiling = new IntentData(intent1, IntentState.COMPILING, timestamp1); IntentData recompiling = new IntentData(intent1, IntentState.RECOMPILING, timestamp1); IntentData installReq = new IntentData(intent1, IntentState.INSTALL_REQ, timestamp1); IntentData withdrawReq = new IntentData(intent1, IntentState.WITHDRAW_REQ, timestamp1); assertFalse(IntentData.isUpdateAcceptable(installing, installing)); assertFalse(IntentData.isUpdateAcceptable(installed, installed)); assertTrue(IntentData.isUpdateAcceptable(installing, installed)); assertFalse(IntentData.isUpdateAcceptable(installing, withdrawing)); assertFalse(IntentData.isUpdateAcceptable(installing, withdrawn)); assertFalse(IntentData.isUpdateAcceptable(installed, withdrawing)); assertFalse(IntentData.isUpdateAcceptable(installed, withdrawn)); assertFalse(IntentData.isUpdateAcceptable(withdrawing, withdrawing)); assertFalse(IntentData.isUpdateAcceptable(withdrawn, withdrawn)); assertTrue(IntentData.isUpdateAcceptable(withdrawing, withdrawn)); assertFalse(IntentData.isUpdateAcceptable(withdrawing, installing)); assertFalse(IntentData.isUpdateAcceptable(withdrawing, installed)); assertFalse(IntentData.isUpdateAcceptable(withdrawn, installing)); assertFalse(IntentData.isUpdateAcceptable(withdrawn, installed)); assertFalse(IntentData.isUpdateAcceptable(failed, failed)); assertTrue(IntentData.isUpdateAcceptable(installing, failed)); assertTrue(IntentData.isUpdateAcceptable(installed, failed)); assertTrue(IntentData.isUpdateAcceptable(withdrawing, failed)); assertTrue(IntentData.isUpdateAcceptable(withdrawn, failed)); assertTrue(IntentData.isUpdateAcceptable(installing, purgeReq)); assertTrue(IntentData.isUpdateAcceptable(installed, purgeReq)); assertTrue(IntentData.isUpdateAcceptable(withdrawing, purgeReq)); assertTrue(IntentData.isUpdateAcceptable(withdrawn, purgeReq)); assertTrue(IntentData.isUpdateAcceptable(failed, purgeReq)); assertFalse(IntentData.isUpdateAcceptable(purgeReq, withdrawn)); assertFalse(IntentData.isUpdateAcceptable(purgeReq, withdrawing)); assertFalse(IntentData.isUpdateAcceptable(purgeReq, installed)); assertFalse(IntentData.isUpdateAcceptable(purgeReq, installing)); assertFalse(IntentData.isUpdateAcceptable(installing, compiling)); assertFalse(IntentData.isUpdateAcceptable(installing, recompiling)); assertFalse(IntentData.isUpdateAcceptable(installing, installReq)); assertFalse(IntentData.isUpdateAcceptable(installing, withdrawReq)); }
public static boolean isUpdateAcceptable(IntentData currentData, IntentData newData) { if (currentData == null) { return true; } else if (currentData.version().isOlderThan(newData.version())) { return true; } else if (currentData.version().isNewerThan(newData.version())) { return false; } IntentState currentState = currentData.state(); IntentState newState = newData.state(); switch (newState) { case INSTALLING: if (currentState == INSTALLING) { return false; } case INSTALLED: if (currentState == INSTALLED) { return false; } else if (currentState == WITHDRAWING || currentState == WITHDRAWN || currentState == PURGE_REQ) { log.warn("Invalid state transition from {} to {} for intent {}", currentState, newState, newData.key()); return false; } return true; case WITHDRAWING: if (currentState == WITHDRAWING) { return false; } case WITHDRAWN: if (currentState == WITHDRAWN) { return false; } else if (currentState == INSTALLING || currentState == INSTALLED || currentState == PURGE_REQ) { log.warn("Invalid state transition from {} to {} for intent {}", currentState, newState, newData.key()); return false; } return true; case FAILED: if (currentState == FAILED) { return false; } return true; case CORRUPT: if (currentState == CORRUPT) { return false; } return true; case PURGE_REQ: return true; case COMPILING: case RECOMPILING: case INSTALL_REQ: case WITHDRAW_REQ: default: log.warn("Invalid state {} for intent {}", newState, newData.key()); return false; } }
IntentData { public static boolean isUpdateAcceptable(IntentData currentData, IntentData newData) { if (currentData == null) { return true; } else if (currentData.version().isOlderThan(newData.version())) { return true; } else if (currentData.version().isNewerThan(newData.version())) { return false; } IntentState currentState = currentData.state(); IntentState newState = newData.state(); switch (newState) { case INSTALLING: if (currentState == INSTALLING) { return false; } case INSTALLED: if (currentState == INSTALLED) { return false; } else if (currentState == WITHDRAWING || currentState == WITHDRAWN || currentState == PURGE_REQ) { log.warn("Invalid state transition from {} to {} for intent {}", currentState, newState, newData.key()); return false; } return true; case WITHDRAWING: if (currentState == WITHDRAWING) { return false; } case WITHDRAWN: if (currentState == WITHDRAWN) { return false; } else if (currentState == INSTALLING || currentState == INSTALLED || currentState == PURGE_REQ) { log.warn("Invalid state transition from {} to {} for intent {}", currentState, newState, newData.key()); return false; } return true; case FAILED: if (currentState == FAILED) { return false; } return true; case CORRUPT: if (currentState == CORRUPT) { return false; } return true; case PURGE_REQ: return true; case COMPILING: case RECOMPILING: case INSTALL_REQ: case WITHDRAW_REQ: default: log.warn("Invalid state {} for intent {}", newState, newData.key()); return false; } } }
IntentData { public static boolean isUpdateAcceptable(IntentData currentData, IntentData newData) { if (currentData == null) { return true; } else if (currentData.version().isOlderThan(newData.version())) { return true; } else if (currentData.version().isNewerThan(newData.version())) { return false; } IntentState currentState = currentData.state(); IntentState newState = newData.state(); switch (newState) { case INSTALLING: if (currentState == INSTALLING) { return false; } case INSTALLED: if (currentState == INSTALLED) { return false; } else if (currentState == WITHDRAWING || currentState == WITHDRAWN || currentState == PURGE_REQ) { log.warn("Invalid state transition from {} to {} for intent {}", currentState, newState, newData.key()); return false; } return true; case WITHDRAWING: if (currentState == WITHDRAWING) { return false; } case WITHDRAWN: if (currentState == WITHDRAWN) { return false; } else if (currentState == INSTALLING || currentState == INSTALLED || currentState == PURGE_REQ) { log.warn("Invalid state transition from {} to {} for intent {}", currentState, newState, newData.key()); return false; } return true; case FAILED: if (currentState == FAILED) { return false; } return true; case CORRUPT: if (currentState == CORRUPT) { return false; } return true; case PURGE_REQ: return true; case COMPILING: case RECOMPILING: case INSTALL_REQ: case WITHDRAW_REQ: default: log.warn("Invalid state {} for intent {}", newState, newData.key()); return false; } } IntentData(Intent intent, IntentState state, Timestamp version);  IntentData(Intent intent, IntentState state, Timestamp version, NodeId origin);  IntentData(IntentData intentData);  IntentData(IntentData original, List<Intent> installables); protected  IntentData(); }
IntentData { public static boolean isUpdateAcceptable(IntentData currentData, IntentData newData) { if (currentData == null) { return true; } else if (currentData.version().isOlderThan(newData.version())) { return true; } else if (currentData.version().isNewerThan(newData.version())) { return false; } IntentState currentState = currentData.state(); IntentState newState = newData.state(); switch (newState) { case INSTALLING: if (currentState == INSTALLING) { return false; } case INSTALLED: if (currentState == INSTALLED) { return false; } else if (currentState == WITHDRAWING || currentState == WITHDRAWN || currentState == PURGE_REQ) { log.warn("Invalid state transition from {} to {} for intent {}", currentState, newState, newData.key()); return false; } return true; case WITHDRAWING: if (currentState == WITHDRAWING) { return false; } case WITHDRAWN: if (currentState == WITHDRAWN) { return false; } else if (currentState == INSTALLING || currentState == INSTALLED || currentState == PURGE_REQ) { log.warn("Invalid state transition from {} to {} for intent {}", currentState, newState, newData.key()); return false; } return true; case FAILED: if (currentState == FAILED) { return false; } return true; case CORRUPT: if (currentState == CORRUPT) { return false; } return true; case PURGE_REQ: return true; case COMPILING: case RECOMPILING: case INSTALL_REQ: case WITHDRAW_REQ: default: log.warn("Invalid state {} for intent {}", newState, newData.key()); return false; } } IntentData(Intent intent, IntentState state, Timestamp version);  IntentData(Intent intent, IntentState state, Timestamp version, NodeId origin);  IntentData(IntentData intentData);  IntentData(IntentData original, List<Intent> installables); protected  IntentData(); Intent intent(); IntentState state(); IntentState request(); Key key(); Timestamp version(); NodeId origin(); void setState(IntentState newState); void incrementErrorCount(); void setErrorCount(int newCount); int errorCount(); List<Intent> installables(); static boolean isUpdateAcceptable(IntentData currentData, IntentData newData); @Override int hashCode(); @Override boolean equals(Object obj); @Override String toString(); }
IntentData { public static boolean isUpdateAcceptable(IntentData currentData, IntentData newData) { if (currentData == null) { return true; } else if (currentData.version().isOlderThan(newData.version())) { return true; } else if (currentData.version().isNewerThan(newData.version())) { return false; } IntentState currentState = currentData.state(); IntentState newState = newData.state(); switch (newState) { case INSTALLING: if (currentState == INSTALLING) { return false; } case INSTALLED: if (currentState == INSTALLED) { return false; } else if (currentState == WITHDRAWING || currentState == WITHDRAWN || currentState == PURGE_REQ) { log.warn("Invalid state transition from {} to {} for intent {}", currentState, newState, newData.key()); return false; } return true; case WITHDRAWING: if (currentState == WITHDRAWING) { return false; } case WITHDRAWN: if (currentState == WITHDRAWN) { return false; } else if (currentState == INSTALLING || currentState == INSTALLED || currentState == PURGE_REQ) { log.warn("Invalid state transition from {} to {} for intent {}", currentState, newState, newData.key()); return false; } return true; case FAILED: if (currentState == FAILED) { return false; } return true; case CORRUPT: if (currentState == CORRUPT) { return false; } return true; case PURGE_REQ: return true; case COMPILING: case RECOMPILING: case INSTALL_REQ: case WITHDRAW_REQ: default: log.warn("Invalid state {} for intent {}", newState, newData.key()); return false; } } IntentData(Intent intent, IntentState state, Timestamp version);  IntentData(Intent intent, IntentState state, Timestamp version, NodeId origin);  IntentData(IntentData intentData);  IntentData(IntentData original, List<Intent> installables); protected  IntentData(); Intent intent(); IntentState state(); IntentState request(); Key key(); Timestamp version(); NodeId origin(); void setState(IntentState newState); void incrementErrorCount(); void setErrorCount(int newCount); int errorCount(); List<Intent> installables(); static boolean isUpdateAcceptable(IntentData currentData, IntentData newData); @Override int hashCode(); @Override boolean equals(Object obj); @Override String toString();  }