Skip to content

Commit

Permalink
MID-2102 Fixed iterator problem (preliminarily).
Browse files Browse the repository at this point in the history
Fixed memleak in some long-running tests.
Reverting some mistakes that creeped in recently.
  • Loading branch information
mederly committed Nov 25, 2014
1 parent 47e8317 commit ef105cf
Show file tree
Hide file tree
Showing 8 changed files with 93 additions and 19 deletions.
Expand Up @@ -140,7 +140,8 @@ private void locateDefinitions() {
shadowDefinition = prismContext.getSchemaRegistry().findObjectDefinitionByCompileTimeClass(ShadowType.class);
}

public <O extends ObjectType> void executeChanges(LensContext<O> syncContext, Task task, OperationResult parentResult) throws ObjectAlreadyExistsException,
// returns true if current operation has to be restarted, see ObjectAlreadyExistsException handling (TODO specify more exactly)
public <O extends ObjectType> boolean executeChanges(LensContext<O> syncContext, Task task, OperationResult parentResult) throws ObjectAlreadyExistsException,
ObjectNotFoundException, SchemaException, CommunicationException, ConfigurationException, SecurityViolationException, ExpressionEvaluationException {

OperationResult result = parentResult.createSubresult(OPERATION_EXECUTE);
Expand Down Expand Up @@ -203,6 +204,8 @@ public <O extends ObjectType> void executeChanges(LensContext<O> syncContext, Ta
// PROJECTIONS

syncContext.checkAbortRequested();

boolean restartRequested = false;

for (LensProjectionContext accCtx : syncContext.getProjectionContexts()) {
if (accCtx.getWave() != syncContext.getExecutionWave()) {
Expand Down Expand Up @@ -300,7 +303,8 @@ public <O extends ObjectType> void executeChanges(LensContext<O> syncContext, Ta
// but we need to set some result
subResult.recordSuccess();
subResult.muteLastSubresultError();
continue;
restartRequested = true;
break; // we will process remaining projections when retrying the wave
} catch (CommunicationException e) {
recordProjectionExecutionException(e, accCtx, subResult, SynchronizationPolicyDecision.BROKEN);
continue;
Expand All @@ -325,6 +329,7 @@ public <O extends ObjectType> void executeChanges(LensContext<O> syncContext, Ta

// Result computation here needs to be slightly different
result.computeStatusComposite();
return restartRequested;

}

Expand Down
Expand Up @@ -399,13 +399,16 @@ private <F extends ObjectType> void processSecondary(LensContext<F> context, Tas
return;
}

changeExecutor.executeChanges(context, task, result);
boolean restartRequested = changeExecutor.executeChanges(context, task, result);

audit(context, AuditEventStage.EXECUTION, task, result);

rotContext(context);

context.incrementExecutionWave();

if (!restartRequested) {
// TODO what if restart is requested indefinitely?
context.incrementExecutionWave();
}

LensUtil.traceContext(LOGGER, "CLOCKWORK (" + context.getState() + ")", "change execution", false, context, false);
}
Expand Down
Expand Up @@ -23,7 +23,6 @@

import com.evolveum.midpoint.model.impl.importer.ImportAccountsFromResourceTaskHandler;
import com.evolveum.midpoint.prism.PrismProperty;
import com.evolveum.midpoint.provisioning.cache.ProvisioningCache;
import com.evolveum.midpoint.util.logging.LoggingUtils;

import com.evolveum.prism.xml.ns._public.types_3.PolyStringType;
Expand Down
Expand Up @@ -107,7 +107,11 @@ public class TestIteration extends AbstractInitializedModelIntegrationTest {

private static final String USER_DEWATT_NAME = "dewatt";
private static final String ACCOUNT_DEWATT_NAME = "DeWatt";


private static final String USER_LARGO_NAME = "largo";
private static final String ACCOUNT_LARGO_NAME = "largo";
public static final String ACCOUNT_LARGO_DUMMY_USERNAME = "largo";

private static final String DESCRIPTION_RUM = "Where's the rum?";

private static final String USER_JACK_RENAMED_NAME = "cptjack";
Expand Down Expand Up @@ -181,7 +185,9 @@ public void initSystem(Task initTask, OperationResult initResult) throws Excepti
dummyResourceCtlMagenta.setResource(resourceDummyMagenta);

addObject(USER_TEMPLATE_ITERATION_FILE);


addObject(USER_LARGO_FILE);

assumeAssignmentPolicy(AssignmentPolicyEnforcementType.RELATIVE);
}

Expand Down Expand Up @@ -439,7 +445,63 @@ public void test220DeWattAssignAccountDummyPinkCaseIgnore() throws Exception {
dummyAuditService.assertExecutionSuccess();
}


@Test
public void test240LargoAssignAccountDummyConflictingNoShadow() throws Exception {
final String TEST_NAME = "test240LargoAssignAccountDummyConflictingNoShadow";
TestUtil.displayTestTile(this, TEST_NAME);

// GIVEN
Task task = taskManager.createTaskInstance(TestIteration.class.getName() + "." + TEST_NAME);
OperationResult result = task.getResult();
dummyAuditService.clear();

// Make sure there is a conflicting account and NO shadow for it
DummyAccount account = new DummyAccount(ACCOUNT_LARGO_DUMMY_USERNAME);
account.setEnabled(true);
account.addAttributeValues(DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_FULLNAME_NAME, "Largo Pinky");
dummyResourcePink.addAccount(account);

Collection<ObjectDelta<? extends ObjectType>> deltas = new ArrayList<ObjectDelta<? extends ObjectType>>();
ObjectDelta<UserType> accountAssignmentUserDelta = createAccountAssignmentUserDelta(USER_LARGO_OID, RESOURCE_DUMMY_PINK_OID, null, true);
deltas.add(accountAssignmentUserDelta);

// WHEN
TestUtil.displayWhen(TEST_NAME);
modelService.executeChanges(deltas, null, task, result);

// THEN
TestUtil.displayThen(TEST_NAME);
result.computeStatus();
TestUtil.assertSuccess(result);

PrismObject<UserType> userLargo = getUser(USER_LARGO_OID);
display("User after change execution", userLargo);
assertUserLargo(userLargo);
String accountOid = getSingleLinkOid(userLargo);

// Check shadow
PrismObject<ShadowType> accountShadow = repositoryService.getObject(ShadowType.class, accountOid, null, result);
assertAccountShadowRepo(accountShadow, accountOid, "largo1", resourceDummyPinkType);

// Check account
PrismObject<ShadowType> accountModel = modelService.getObject(ShadowType.class, accountOid, null, task, result);
assertAccountShadowModel(accountModel, accountOid, "largo1", resourceDummyPinkType);

// Check account in dummy resource
assertDummyAccount(RESOURCE_DUMMY_PINK_NAME, "largo1", null, true);

// Check audit
// USER Largo MODIFY(add-assignment): request + execution (focus(assignment) + account/failed) + execution (focus(linkRef) / account/OK)
display("Audit", dummyAuditService);
dummyAuditService.assertRecords(3);
dummyAuditService.assertSimpleRecordSanity();
dummyAuditService.assertAnyRequestDeltas();
dummyAuditService.assertExecutionDeltas(2);
dummyAuditService.asserHasDelta(ChangeType.MODIFY, UserType.class);
dummyAuditService.asserHasDelta(ChangeType.ADD, ShadowType.class);
dummyAuditService.assertExecutionSuccess();
}

@Test
public void test300JackAssignAccountDummyVioletConflicting() throws Exception {
final String TEST_NAME = "test300JackAssignAccountDummyVioletConflicting";
Expand Down Expand Up @@ -1499,7 +1561,11 @@ public void test764DarkVioletModifyMatusalemFullName() throws Exception {
assertUserNick(ACCOUNT_MILLONARIO_USERNAME, RON_FULLNAME, RON_FULLNAME, "Northern Peru");
assertNoUserNick(ACCOUNT_MILLONARIO_USERNAME, RUM_FULLNAME, RUM_FULLNAME+iterationTokenMillonario);
}


private void assertUserLargo(PrismObject<UserType> userLargo) {
assertUser(userLargo, USER_LARGO_OID, USER_LARGO_NAME, null, "Largo", "LaGrande", null);
}

private void assertUserNick(String accountName, String accountFullName, String expectedUserName) throws SchemaException, ObjectNotFoundException, SecurityViolationException, CommunicationException, ConfigurationException {
assertUserNick(accountName, accountFullName, expectedUserName, null);
}
Expand Down
Expand Up @@ -1680,6 +1680,7 @@ protected void waitForTaskFinish(final Task task, final boolean checkSubresult,f
@Override
public boolean check() throws Exception {
task.refresh(waitResult);
waitResult.summarize();
// Task freshTask = taskManager.getTask(task.getOid(), waitResult);
OperationResult result = task.getResult();
if (verbose) display("Check result", result);
Expand Down
Expand Up @@ -109,7 +109,7 @@ public class TestLdap extends AbstractModelIntegrationTest {
private static final String ACCOUNT_CHARLES_NAME = "charles";

// Make it at least 1501 so it will go over the 3000 entries size limit
private static final int NUM_LDAP_ENTRIES = 50;
private static final int NUM_LDAP_ENTRIES = 1600;

private static final String LDAP_GROUP_PIRATES_DN = "cn=Pirates,ou=groups,dc=example,dc=com";

Expand Down Expand Up @@ -143,9 +143,10 @@ public void initSystem(Task initTask, OperationResult initResult) throws Excepti
"looks like the previous test haven't cleaned it up", e);
}

LoggingConfigurationManager.configure(
ProfilingConfigurationManager.checkSystemProfilingConfiguration(config),
config.asObjectable().getVersion(), initResult);
// to get profiling facilities (until better API is available)
// LoggingConfigurationManager.configure(
// ProfilingConfigurationManager.checkSystemProfilingConfiguration(config),
// config.asObjectable().getVersion(), initResult);

// administrator
PrismObject<UserType> userAdministrator = repoAddObjectFromFile(USER_ADMINISTRATOR_FILE, UserType.class, initResult);
Expand Down
Expand Up @@ -173,8 +173,8 @@ public void test100BigImportWithLinking() throws Exception {
display("Users", userCount);
assertEquals("Unexpected number of users", NUM_LDAP_ENTRIES+1, userCount);

assertUser("u0", task, result);
assertUser("u1", task, result);
assertUser("e0", task, result);
assertUser("e1(u1)", task, result);
}

private void createUsers(String prefix, OperationResult result) throws ObjectAlreadyExistsException, SchemaException {
Expand All @@ -198,7 +198,7 @@ private void createUsers(String prefix, OperationResult result) throws ObjectAlr
}

private void assertUser(String name, Task task, OperationResult result) throws com.evolveum.midpoint.util.exception.ObjectNotFoundException, com.evolveum.midpoint.util.exception.SchemaException, com.evolveum.midpoint.util.exception.SecurityViolationException, com.evolveum.midpoint.util.exception.CommunicationException, com.evolveum.midpoint.util.exception.ConfigurationException {
UserType user = findUserByUsername("u1").asObjectable();
UserType user = findUserByUsername(name).asObjectable();
display("user " + name, user.asPrismObject());

//assertEquals("Wrong number of assignments", 4, user.getAssignment().size());
Expand Down
Expand Up @@ -37,7 +37,6 @@
<import resource="ctx-model.xml"/>
<import resource="ctx-model-test.xml"/>
<import resource="ctx-provisioning.xml"/>
<import resource="ctx-provisioning-cache.xml"/>
<import resource="ctx-common.xml"/>
<import resource="ctx-longtest-test.xml"/>
<import resource="ctx-task.xml"/>
Expand Down

0 comments on commit ef105cf

Please sign in to comment.