private void delayOperation() throws InterruptedException { if (resource != null) { resource.delayOperation(); } }
public DummyObjectClass getAccountObjectClass() throws ConnectException, FileNotFoundException, SchemaViolationException, ConflictException, InterruptedException { breakIt(schemaBreakMode, "schema"); delayOperation(); return accountObjectClass; }
public Collection<DummyOrg> listOrgs() throws ConnectException, FileNotFoundException, SchemaViolationException, ConflictException, InterruptedException { checkBlockOperations(); breakIt(getBreakMode, "get"); delayOperation(); return orgs.values(); }
public Collection<DummyAccount> listAccounts() throws ConnectException, FileNotFoundException, SchemaViolationException, ConflictException, InterruptedException { checkBlockOperations(); breakIt(getBreakMode, "get"); delayOperation(); return accounts.values(); }
public Collection<DummyGroup> listGroups() throws ConnectException, FileNotFoundException, SchemaViolationException, ConflictException, InterruptedException { checkBlockOperations(); breakIt(getBreakMode, "get"); delayOperation(); return groups.values(); }
public Collection<DummyPrivilege> listPrivileges() throws ConnectException, FileNotFoundException, SchemaViolationException, ConflictException, InterruptedException { checkBlockOperations(); breakIt(getBreakMode, "get"); delayOperation(); return privileges.values(); }
private <T extends DummyObject> T getObjectById(Class<T> expectedClass, String id, boolean checkBreak) throws ConnectException, FileNotFoundException, SchemaViolationException, ConflictException, InterruptedException { checkBlockOperations(); if (checkBreak) { breakIt(getBreakMode, "get"); } delayOperation(); DummyObject dummyObject = allObjects.get(id); if (dummyObject == null) { return null; } if (!expectedClass.isInstance(dummyObject)) { throw new IllegalStateException("Arrrr! Wanted "+expectedClass+" with ID "+id+" but got "+dummyObject+" instead"); } return (T)dummyObject; }
private <T extends DummyObject> T getObjectByName(Map<String,T> map, String name, boolean checkBreak) throws ConnectException, FileNotFoundException, SchemaViolationException, ConflictException, InterruptedException { if (!enforceUniqueName) { throw new IllegalStateException("Attempt to search object by name while resource is in non-unique name mode"); } checkBlockOperations(); delayOperation(); if (checkBreak) { breakIt(getBreakMode, "get"); } return map.get(normalize(name)); }
private synchronized <T extends DummyObject> void deleteObjectByName(Class<T> type, Map<String,T> map, String name) throws ObjectDoesNotExistException, ConnectException, FileNotFoundException, SchemaViolationException, ConflictException, InterruptedException { checkBlockOperations(); recordWriteOperation("delete"); breakIt(deleteBreakMode, "delete"); delayOperation(); String normalName = normalize(name); T existingObject; if (!enforceUniqueName) { throw new IllegalStateException("Whoops! got into deleteObjectByName without enforceUniqueName"); } if (map.containsKey(normalName)) { existingObject = map.get(normalName); map.remove(normalName); allObjects.remove(existingObject.getId()); } else { throw new ObjectDoesNotExistException(type.getSimpleName()+" with name '"+normalName+"' does not exist"); } if (syncStyle != DummySyncStyle.NONE) { int syncToken = nextSyncToken(); DummyDelta delta = new DummyDelta(syncToken, type, existingObject.getId(), name, DummyDeltaType.DELETE); deltas.add(delta); } }
private <T extends DummyObject> void renameObject(Class<T> type, Map<String,T> map, String id, String oldName, String newName) throws ObjectDoesNotExistException, ObjectAlreadyExistsException, ConnectException, FileNotFoundException, SchemaViolationException, ConflictException, InterruptedException { checkBlockOperations(); recordWriteOperation("modify"); breakIt(modifyBreakMode, "modify"); delayOperation(); T existingObject; if (enforceUniqueName) { String normalOldName = normalize(oldName); String normalNewName = normalize(newName); existingObject = map.get(normalOldName); if (existingObject == null) { throw new ObjectDoesNotExistException("Cannot rename, "+type.getSimpleName()+" with username '"+normalOldName+"' does not exist"); } if (map.containsKey(normalNewName)) { throw new ObjectAlreadyExistsException("Cannot rename, "+type.getSimpleName()+" with username '"+normalNewName+"' already exists"); } map.put(normalNewName, existingObject); map.remove(normalOldName); } else { existingObject = (T) allObjects.get(id); } existingObject.setName(newName); if (existingObject instanceof DummyAccount) { changeDescriptionIfNeeded((DummyAccount) existingObject); } }
recordWriteOperation("delete"); breakIt(deleteBreakMode, "delete"); delayOperation();
recordWriteOperation("add"); breakIt(addBreakMode, "add"); delayOperation();