use of com.evolveum.midpoint.repo.sqlbase.ConflictWatcherImpl in project midpoint by Evolveum.
the class AddGetObjectTest method test230WatcherAddWithVersion.
@Test
public void test230WatcherAddWithVersion() throws Exception {
OperationResult result = createOperationResult();
// GIVEN
UserType user = new UserType(prismContext).name("t230").version("2000");
// WHEN
String oid = repositoryService.addObject(user.asPrismObject(), null, result);
ConflictWatcherImpl watcher = (ConflictWatcherImpl) repositoryService.createAndRegisterConflictWatcher(oid);
// the version should be preserved here
watcher.setExpectedVersion(user.getVersion());
// THEN
assertTrue("watcher is not initialized", watcher.isInitialized());
assertFalse("watcher is marked as deleted", watcher.isObjectDeleted());
assertEquals("expectedVersion is wrong", 2000, watcher.getExpectedVersion());
boolean hasConflict = repositoryService.hasConflict(watcher, result);
assertFalse("false conflict reported for " + watcher, hasConflict);
}
use of com.evolveum.midpoint.repo.sqlbase.ConflictWatcherImpl in project midpoint by Evolveum.
the class AddGetObjectTest method test201WatcherOverwriteWithOidNoVersion.
@Test
public void test201WatcherOverwriteWithOidNoVersion() throws Exception {
OperationResult result = new OperationResult("test201WatcherOverwriteWithOidNoVersion");
// GIVEN
UserType user = new UserType(prismContext).name("t200").oid(OID_200);
// WHEN
ConflictWatcherImpl watcher = (ConflictWatcherImpl) repositoryService.createAndRegisterConflictWatcher(OID_200);
repositoryService.addObject(user.asPrismObject(), RepoAddOptions.createOverwrite(), result);
// THEN
assertTrue("watcher is not initialized", watcher.isInitialized());
assertFalse("watcher is marked as deleted", watcher.isObjectDeleted());
assertEquals("expectedVersion is wrong", 1, watcher.getExpectedVersion());
boolean hasConflict = repositoryService.hasConflict(watcher, result);
assertFalse("false conflict reported for " + watcher, hasConflict);
}
use of com.evolveum.midpoint.repo.sqlbase.ConflictWatcherImpl in project midpoint by Evolveum.
the class AddGetObjectTest method test202WatcherOverwriteWithOidNoVersion2.
@Test
public void test202WatcherOverwriteWithOidNoVersion2() throws Exception {
OperationResult result = createOperationResult();
// GIVEN
UserType user = new UserType(prismContext).name("t200").oid(OID_200);
// WHEN
ConflictWatcherImpl watcher = (ConflictWatcherImpl) repositoryService.createAndRegisterConflictWatcher(OID_200);
repositoryService.addObject(user.asPrismObject(), RepoAddOptions.createOverwrite(), result);
// THEN
assertTrue("watcher is not initialized", watcher.isInitialized());
assertFalse("watcher is marked as deleted", watcher.isObjectDeleted());
assertEquals("expectedVersion is wrong", 2, watcher.getExpectedVersion());
boolean hasConflict = repositoryService.hasConflict(watcher, result);
assertFalse("false conflict reported for " + watcher, hasConflict);
}
use of com.evolveum.midpoint.repo.sqlbase.ConflictWatcherImpl in project midpoint by Evolveum.
the class SqlRepositoryServiceImpl method createAndRegisterConflictWatcher.
@Override
public ConflictWatcher createAndRegisterConflictWatcher(@NotNull String oid) {
List<ConflictWatcherImpl> watchers = conflictWatchersThreadLocal.get();
if (watchers.size() >= MAX_CONFLICT_WATCHERS) {
throw new IllegalStateException("Conflicts watchers leaking: reached limit of " + MAX_CONFLICT_WATCHERS + ": " + watchers);
}
ConflictWatcherImpl watcher = new ConflictWatcherImpl(oid);
watchers.add(watcher);
return watcher;
}
use of com.evolveum.midpoint.repo.sqlbase.ConflictWatcherImpl in project midpoint by Evolveum.
the class SqlRepositoryServiceImpl method unregisterConflictWatcher.
@Override
public void unregisterConflictWatcher(ConflictWatcher watcher) {
ConflictWatcherImpl watcherImpl = (ConflictWatcherImpl) watcher;
List<ConflictWatcherImpl> watchers = conflictWatchersThreadLocal.get();
// change these exceptions to logged errors, eventually
if (watchers == null) {
throw new IllegalStateException("No conflict watchers registered for current thread; tried to unregister " + watcher);
} else if (!watchers.remove(watcherImpl)) {
// expecting there's only one
throw new IllegalStateException("Tried to unregister conflict watcher " + watcher + " that was not registered");
}
}
Aggregations