Skip to content

Commit

Permalink
Adjusting and improving tests, fixing conflict detection delay (MID-4…
Browse files Browse the repository at this point in the history
…154)
  • Loading branch information
semancik committed Sep 29, 2017
1 parent e3b79c0 commit e5823af
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 23 deletions.
Expand Up @@ -244,7 +244,7 @@ private <F extends ObjectType> HookOperationMode resolveFocusConflict(LensContex
return HookOperationMode.FOREGROUND;
}
PrismObject<F> focusObject = context.getFocusContext() != null ? context.getFocusContext().getObjectAny() : null;
ModelExecuteOptions options = null;
ModelExecuteOptions options = new ModelExecuteOptions();
switch (resolutionPolicy.getAction()) {
case FAIL: throw new SystemException("Conflict detected while updating " + focusObject);
case LOG:
Expand All @@ -253,7 +253,7 @@ private <F extends ObjectType> HookOperationMode resolveFocusConflict(LensContex
case RECOMPUTE:
break;
case RECONCILE:
options = ModelExecuteOptions.createReconcile();
options.setReconcile();
break;
default:
throw new IllegalStateException("Unsupported conflict resolution action: " + resolutionPolicy.getAction());
Expand Down Expand Up @@ -290,28 +290,28 @@ private <F extends ObjectType> HookOperationMode resolveFocusConflict(LensContex

int preconditionAttempts = 0;
while (true) {

PrismObject<F> focus = repositoryService.getObject(focusClass, oid, null, result);
LensContext<FocusType> contextNew = contextFactory.createRecomputeContext(focus, options, task, result);
contextNew.setProgressListeners(new ArrayList<>(emptyIfNull(context.getProgressListeners())));

int attemptOld = context.getConflictResolutionAttemptNumber();

int attemptOld = context.getConflictResolutionAttemptNumber();
int attemptNew = attemptOld + 1;
boolean shouldExecuteAttempt = shouldExecuteAttempt(context, resolutionPolicy, attemptNew);
if (!shouldExecuteAttempt) {
LOGGER.warn("CONFLICT: Couldn't resolve conflict even after {} resolution attempt(s), giving up.", attemptOld);
return HookOperationMode.FOREGROUND;
}
contextNew.setConflictResolutionAttemptNumber(attemptNew);
// this is a recursion; but limited to max attempts which should not be a large number

delay(context, resolutionPolicy, attemptNew + preconditionAttempts);

LOGGER.debug("CONFLICT: Recomputing {} as reaction to conflict (options={}, attempts={},{})",
context.getFocusContext().getHumanReadableName(), attemptNew, preconditionAttempts);
PrismObject<F> focus = repositoryService.getObject(focusClass, oid, null, result);
LensContext<FocusType> contextNew = contextFactory.createRecomputeContext(focus, options, task, result);
contextNew.setProgressListeners(new ArrayList<>(emptyIfNull(context.getProgressListeners())));
contextNew.setConflictResolutionAttemptNumber(attemptNew);

LOGGER.debug("CONFLICT: Recomputing {} as reaction to conflict (options={}, attempts={},{}, readVersion={})",
context.getFocusContext().getHumanReadableName(), options, attemptNew, preconditionAttempts, contextNew.getFocusContext().getObjectReadVersion());

try {


// this is a recursion; but limited to max attempts which should not be a large number
HookOperationMode hookOperationMode = run(contextNew, task, result);

// This may be in fact a giveup after recompute that was not able to cleanly proceed.
Expand Down
Expand Up @@ -354,8 +354,8 @@ public void test135ModifyUserHermanCivilisedHermit() throws Exception {
display("Herman (civilised hermit)", user);

hermanCivilisedHermitTs = getTimeSafely();
hermanCivilisedHermitEid = assertObjectAuditRecords(USER_HERMAN_OID, 9);
assertRecordsFromInitial(hermanCivilisedHermitTs, 15);
hermanCivilisedHermitEid = assertObjectAuditRecords(USER_HERMAN_OID, 8);
assertRecordsFromInitial(hermanCivilisedHermitTs, 14);
}

@Test
Expand Down
Expand Up @@ -434,7 +434,7 @@ public void test119ModifyRoleDeleteEntitlement() throws Exception {
dummyAuditService.assertRecords(2);
dummyAuditService.assertSimpleRecordSanity();
dummyAuditService.assertAnyRequestDeltas();
dummyAuditService.assertExecutionDeltas(2);
dummyAuditService.assertExecutionDeltas(3);
dummyAuditService.assertHasDelta(ChangeType.MODIFY, RoleType.class);
dummyAuditService.assertHasDelta(ChangeType.DELETE, ShadowType.class);
dummyAuditService.assertTarget(ROLE_PIRATE_OID);
Expand Down Expand Up @@ -541,7 +541,7 @@ public void test121ModifyRoleLinkEntitlement() throws Exception {
dummyAuditService.assertRecords(2);
dummyAuditService.assertSimpleRecordSanity();
dummyAuditService.assertAnyRequestDeltas();
dummyAuditService.assertExecutionDeltas(2);
dummyAuditService.assertExecutionDeltas(3);
dummyAuditService.assertHasDelta(ChangeType.MODIFY, RoleType.class);
dummyAuditService.assertHasDelta(ChangeType.MODIFY, ShadowType.class);
dummyAuditService.assertTarget(ROLE_PIRATE_OID);
Expand Down Expand Up @@ -761,7 +761,7 @@ public void test132ModifyEntitlement() throws Exception {
dummyAuditService.assertSimpleRecordSanity();
dummyAuditService.assertRecords(3);
dummyAuditService.assertAnyRequestDeltas();
dummyAuditService.assertExecutionDeltas(0, 1);
dummyAuditService.assertExecutionDeltas(0, 2);
dummyAuditService.assertHasDelta(0, ChangeType.MODIFY, ShadowType.class);
dummyAuditService.assertExecutionDeltas(1, 1);
dummyAuditService.assertHasDelta(1, ChangeType.MODIFY, RoleType.class);
Expand Down
Expand Up @@ -431,7 +431,7 @@ public void test150ImportFromResourceDummy() throws Exception {
displayThen(TEST_NAME);
TestUtil.assertSuccess(task.getResult());

assertCounterIncrement(InternalCounters.SHADOW_FETCH_OPERATION_COUNT, 3);
assertCounterIncrement(InternalCounters.SHADOW_FETCH_OPERATION_COUNT, 5);

users = modelService.searchObjects(UserType.class, null, null, task, result);
display("Users after import", users);
Expand Down
Expand Up @@ -77,6 +77,7 @@
<special>self</special>
</object>
<item>credentials</item>
<item>metadata</item>
</authorization>
<authorization>
<action>http://midpoint.evolveum.com/xml/ns/public/security/authorization-model-3#modify</action>
Expand Down
Expand Up @@ -194,8 +194,8 @@ private boolean checkUniqueness(String oid, PrismProperty identifier, ObjectQuer
Collection<SelectorOptions<GetOperationOptions>> options = SelectorOptions.createCollection(GetOperationOptions.createNoFetch());
List<PrismObject<ShadowType>> foundObjects = shadowCache.searchObjects(query, options, true, task, result);
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Uniqueness check of {} resulted in {} results, using query:\n{}",
identifier, foundObjects.size(), query.debugDump());
LOGGER.trace("Uniqueness check of {} resulted in {} results:\n{}\nquery:\n{}",
identifier, foundObjects.size(), foundObjects, query.debugDump(1));
}
if (foundObjects.isEmpty()) {
if (useCache) {
Expand Down
Expand Up @@ -65,7 +65,7 @@ public class TestDummyParallelism extends AbstractBasicDummyTest {

private static final long WAIT_TIMEOUT = 60000L;

private static final int DUMMY_OPERATION_DELAY_RANGE = 1000;
private static final int DUMMY_OPERATION_DELAY_RANGE = 1500;

private String accountMorganOid;
private String accountElizabethOid;
Expand All @@ -79,7 +79,7 @@ protected int getConcurrentTestFastRandomStartDelayRange() {
}

protected int getConcurrentTestSlowRandomStartDelayRange() {
return 1000;
return 150;
}

@Override
Expand Down

0 comments on commit e5823af

Please sign in to comment.