Skip to content

Commit

Permalink
Fixing dummy connector (again) which fixes model-intest
Browse files Browse the repository at this point in the history
  • Loading branch information
semancik committed Jun 9, 2017
1 parent b891a24 commit 3456220
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 44 deletions.
Expand Up @@ -419,6 +419,7 @@ private <T extends DummyObject> T getObjectByName(Map<String,T> map, String name
if (!enforceUniqueName) {
throw new IllegalStateException("Attempt to search object by name while resource is in non-unique name mode");
}
checkBlockOperations();
if (checkBreak) {
breakIt(getBreakMode, "get");
}
Expand Down Expand Up @@ -458,6 +459,7 @@ public DummyOrg getOrgByName(String name, boolean checkBreak) throws ConnectExce
}

private <T extends DummyObject> T getObjectById(Class<T> expectedClass, String id, boolean checkBreak) throws ConnectException, FileNotFoundException, SchemaViolationException, ConflictException {
checkBlockOperations();
if (checkBreak) {
breakIt(getBreakMode, "get");
}
Expand Down
Expand Up @@ -15,7 +15,6 @@
*/
package com.evolveum.midpoint.model.intest;

import static com.evolveum.midpoint.test.IntegrationTestTools.display;
import static org.testng.AssertJUnit.assertEquals;
import static org.testng.AssertJUnit.assertFalse;
import static org.testng.AssertJUnit.assertNotNull;
Expand All @@ -30,7 +29,6 @@
import org.testng.annotations.Test;

import com.evolveum.icf.dummy.resource.DummyResource;
import com.evolveum.midpoint.model.intest.rbac.TestRbac;
import com.evolveum.midpoint.prism.PrismObject;
import com.evolveum.midpoint.schema.result.OperationResult;
import com.evolveum.midpoint.schema.statistics.ConnectorOperationalStatus;
Expand All @@ -48,7 +46,6 @@
import com.evolveum.midpoint.util.exception.SchemaException;
import com.evolveum.midpoint.util.logging.Trace;
import com.evolveum.midpoint.util.logging.TraceManager;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.UserType;

Expand Down Expand Up @@ -93,36 +90,35 @@ public void initSystem(Task initTask, OperationResult initResult) throws Excepti
@Test
public void test000Sanity() throws Exception {
final String TEST_NAME = "test000Sanity";
TestUtil.displayTestTile(this, TEST_NAME);
displayTestTile(TEST_NAME);

// GIVEN
Task task = taskManager.createTaskInstance(TestRbac.class.getName() + "." + TEST_NAME);
Task task = createTask(TEST_NAME);

// WHEN
OperationResult testResult = modelService.testResource(RESOURCE_DUMMY_YELLOW_OID, task);

// THEN
display("Test result", testResult);
assertSuccess(testResult);
TestUtil.assertSuccess("Yellow dummy test result", testResult);

assertEquals("Wrong YELLOW useless string", IntegrationTestTools.CONST_USELESS, dummyResourceYellow.getUselessString());
}

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

// GIVEN
Task task = taskManager.createTaskInstance(TestRbac.class.getName() + "." + TEST_NAME);
Task task = createTask(TEST_NAME);
OperationResult result = task.getResult();

// WHEN
assignAccount(USER_JACK_OID, RESOURCE_DUMMY_YELLOW_OID, null, task, result);

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

PrismObject<UserType> userJack = getUser(USER_JACK_OID);
accountJackYellowOid = getSingleLinkOid(userJack);
Expand All @@ -144,7 +140,7 @@ public void test100JackAssignDummyYellow() throws Exception {
@Test
public void test102ReadJackDummyYellowAgain() throws Exception {
final String TEST_NAME = "test102ReadJackDummyYellowAgain";
TestUtil.displayTestTile(this, TEST_NAME);
displayTestTile(TEST_NAME);

// WHEN
PrismObject<ShadowType> shadowYellow = getShadowModel(accountJackYellowOid);
Expand All @@ -167,20 +163,17 @@ public void test102ReadJackDummyYellowAgain() throws Exception {
@Test
public void test110ReadJackDummyYellowBlocking() throws Exception {
final String TEST_NAME = "test110ReadJackDummyYellowBlocking";
TestUtil.displayTestTile(this, TEST_NAME);
displayTestTile(TEST_NAME);

dummyResourceYellow.setBlockOperations(true);
final Holder<PrismObject<ShadowType>> shadowHolder = new Holder<>();

// WHEN
Thread t = executeInNewThread("get1", new FailableRunnable() {
@Override
public void run() throws Exception {
Thread t = executeInNewThread("get1", () -> {
PrismObject<ShadowType> shadow = getShadowModel(accountJackYellowOid);
LOGGER.trace("Got shadow {}", shadow);
shadowHolder.setValue(shadow);
}
});
});

// Give the new thread a chance to get blocked
Thread.sleep(200);
Expand Down Expand Up @@ -215,21 +208,18 @@ public void run() throws Exception {
@Test
public void test120ReadJackDummyYellowTwoOperationsOneBlocking() throws Exception {
final String TEST_NAME = "test120ReadJackDummyYellowTwoOperationsOneBlocking";
TestUtil.displayTestTile(this, TEST_NAME);
displayTestTile(TEST_NAME);

dummyResourceYellow.setBlockOperations(true);
final Holder<PrismObject<ShadowType>> shadowHolder1 = new Holder<>();
final Holder<PrismObject<ShadowType>> shadowHolder2 = new Holder<>();

// WHEN
Thread t1 = executeInNewThread("get1", new FailableRunnable() {
@Override
public void run() throws Exception {
Thread t1 = executeInNewThread("get1", () -> {
PrismObject<ShadowType> shadow = getShadowModel(accountJackYellowOid);
LOGGER.trace("Got shadow {}", shadow);
shadowHolder1.setValue(shadow);
}
});
});

// Give the new thread a chance to get blocked
Thread.sleep(200);
Expand All @@ -242,14 +232,11 @@ public void run() throws Exception {

// This should not be blocked and it should proceed immediately

Thread t2 = executeInNewThread("get2", new FailableRunnable() {
@Override
public void run() throws Exception {
Thread t2 = executeInNewThread("get2", () -> {
PrismObject<ShadowType> shadow = getShadowModel(accountJackYellowOid);
LOGGER.trace("Got shadow {}", shadow);
shadowHolder2.setValue(shadow);
}
});
});

t2.join(1000);

Expand Down Expand Up @@ -288,21 +275,18 @@ public void run() throws Exception {
@Test
public void test125ReadJackDummyYellowTwoBlocking() throws Exception {
final String TEST_NAME = "test125ReadJackDummyYellowTwoBlocking";
TestUtil.displayTestTile(this, TEST_NAME);
displayTestTile(TEST_NAME);

dummyResourceYellow.setBlockOperations(true);
final Holder<PrismObject<ShadowType>> shadowHolder1 = new Holder<>();
final Holder<PrismObject<ShadowType>> shadowHolder2 = new Holder<>();

// WHEN
Thread t1 = executeInNewThread("get1", new FailableRunnable() {
@Override
public void run() throws Exception {
Thread t1 = executeInNewThread("get1", () -> {
PrismObject<ShadowType> shadow = getShadowModel(accountJackYellowOid);
LOGGER.trace("Got shadow {}", shadow);
shadowHolder1.setValue(shadow);
}
});
});

Thread t2 = executeInNewThread("get2", new FailableRunnable() {
@Override
Expand Down Expand Up @@ -349,18 +333,17 @@ public void run() throws Exception {
@Test
public void test200GuybrushAssignDummyBlack() throws Exception {
final String TEST_NAME = "test200GuybrushAssignDummyBlack";
TestUtil.displayTestTile(this, TEST_NAME);
displayTestTile(TEST_NAME);

// GIVEN
Task task = taskManager.createTaskInstance(TestRbac.class.getName() + "." + TEST_NAME);
Task task = createTask(TEST_NAME);
OperationResult result = task.getResult();

// WHEN
assignAccount(USER_GUYBRUSH_OID, RESOURCE_DUMMY_BLACK_OID, null, task, result);

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

PrismObject<UserType> userJack = getUser(USER_GUYBRUSH_OID);
accountGuybrushBlackOid = getSingleLinkOid(userJack);
Expand All @@ -380,18 +363,14 @@ public void test200GuybrushAssignDummyBlack() throws Exception {
}

private Thread executeInNewThread(final String threadName, final FailableRunnable runnable) {
Thread t = new Thread(new Runnable() {

@Override
public void run() {
Thread t = new Thread(() -> {
try {
login(userAdministrator);
runnable.run();
} catch (Throwable e) {
LOGGER.error("Error in {}: {}", threadName, e.getMessage(), e);
}
}
});
});
t.setName(threadName);
t.start();
return t;
Expand Down

0 comments on commit 3456220

Please sign in to comment.