Search in sources :

Example 1 with FailableRunnable

use of com.evolveum.midpoint.util.FailableRunnable in project midpoint by Evolveum.

the class TestConnectorMultiInstance method executeInNewThread.

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

        @Override
        public void run() {
            try {
                login(userAdministrator);
                runnable.run();
            } catch (Throwable e) {
                LOGGER.error("Error in {}: {}", threadName, e.getMessage(), e);
            }
        }
    });
    t.setName(threadName);
    t.start();
    return t;
}
Also used : FailableRunnable(com.evolveum.midpoint.util.FailableRunnable)

Example 2 with FailableRunnable

use of com.evolveum.midpoint.util.FailableRunnable in project midpoint by Evolveum.

the class TestConnectorMultiInstance method test125ReadJackDummyYellowTwoBlocking.

/**
	 * Block two read operations. Make sure that new connector instance is created.
	 */
@Test
public void test125ReadJackDummyYellowTwoBlocking() throws Exception {
    final String TEST_NAME = "test125ReadJackDummyYellowTwoBlocking";
    TestUtil.displayTestTile(this, 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 {
            PrismObject<ShadowType> shadow = getShadowModel(accountJackYellowOid);
            LOGGER.trace("Got shadow {}", shadow);
            shadowHolder1.setValue(shadow);
        }
    });
    Thread t2 = executeInNewThread("get2", new FailableRunnable() {

        @Override
        public void run() throws Exception {
            PrismObject<ShadowType> shadow = getShadowModel(accountJackYellowOid);
            LOGGER.trace("Got shadow {}", shadow);
            shadowHolder2.setValue(shadow);
        }
    });
    // Give the new threads a chance to get blocked
    Thread.sleep(500);
    assertConnectorInstances("yellow (blocked)", RESOURCE_DUMMY_YELLOW_OID, 2, 0);
    assertNull("Unexpected shadow 1", shadowHolder1.getValue());
    assertNull("Unexpected shadow 2", shadowHolder2.getValue());
    dummyResourceYellow.unblockAll();
    t1.join();
    t2.join();
    // THEN
    dummyResourceYellow.setBlockOperations(false);
    PrismObject<ShadowType> shadowYellow1 = shadowHolder1.getValue();
    assertNotNull("No shadow 1", shadowHolder1.getValue());
    display("Shadow yellow 1", shadowYellow1);
    PrismObject<ShadowType> shadowYellow2 = shadowHolder2.getValue();
    assertNotNull("No shadow 2", shadowHolder2.getValue());
    display("Shadow yellow 2", shadowYellow2);
    assertConnectorInstances("yellow", RESOURCE_DUMMY_YELLOW_OID, 0, 2);
    assertConnectorToStringDifferent(shadowYellow2, dummyResourceCtlYellow, getConnectorToString(shadowYellow1, dummyResourceCtlYellow));
    assertConnectorStaticVal(shadowYellow1, dummyResourceCtlYellow, initialConnectorStaticVal);
    assertConnectorStaticVal(shadowYellow2, dummyResourceCtlYellow, initialConnectorStaticVal);
    assertDummyAccount(RESOURCE_DUMMY_YELLOW_NAME, ACCOUNT_JACK_DUMMY_USERNAME, ACCOUNT_JACK_DUMMY_FULLNAME, true);
}
Also used : PrismObject(com.evolveum.midpoint.prism.PrismObject) FailableRunnable(com.evolveum.midpoint.util.FailableRunnable) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) Holder(com.evolveum.midpoint.util.Holder) ConfigurationException(com.evolveum.midpoint.util.exception.ConfigurationException) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ExpressionEvaluationException(com.evolveum.midpoint.util.exception.ExpressionEvaluationException) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) CommunicationException(com.evolveum.midpoint.util.exception.CommunicationException) Test(org.testng.annotations.Test)

Example 3 with FailableRunnable

use of com.evolveum.midpoint.util.FailableRunnable in project midpoint by Evolveum.

the class TestConnectorMultiInstance method test110ReadJackDummyYellowBlocking.

/**
	 * Block the operation during read. Just to make sure that the stats for active
	 * connector instances work.
	 */
@Test
public void test110ReadJackDummyYellowBlocking() throws Exception {
    final String TEST_NAME = "test110ReadJackDummyYellowBlocking";
    TestUtil.displayTestTile(this, 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 {
            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);
    assertConnectorInstances("yellow (blocked)", RESOURCE_DUMMY_YELLOW_OID, 1, 0);
    assertNull("Unexpected shadow", shadowHolder.getValue());
    dummyResourceYellow.unblock();
    // THEN
    t.join();
    dummyResourceYellow.setBlockOperations(false);
    PrismObject<ShadowType> shadowYellow = shadowHolder.getValue();
    assertNotNull("No shadow", shadowHolder.getValue());
    display("Shadow yellow", shadowYellow);
    assertConnectorInstances("yellow", RESOURCE_DUMMY_YELLOW_OID, 0, 1);
    assertConnectorToString(shadowYellow, dummyResourceCtlYellow, initialConnectorToString);
    assertConnectorStaticVal(shadowYellow, dummyResourceCtlYellow, initialConnectorStaticVal);
    assertDummyAccount(RESOURCE_DUMMY_YELLOW_NAME, ACCOUNT_JACK_DUMMY_USERNAME, ACCOUNT_JACK_DUMMY_FULLNAME, true);
}
Also used : PrismObject(com.evolveum.midpoint.prism.PrismObject) FailableRunnable(com.evolveum.midpoint.util.FailableRunnable) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) Holder(com.evolveum.midpoint.util.Holder) ConfigurationException(com.evolveum.midpoint.util.exception.ConfigurationException) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ExpressionEvaluationException(com.evolveum.midpoint.util.exception.ExpressionEvaluationException) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) CommunicationException(com.evolveum.midpoint.util.exception.CommunicationException) Test(org.testng.annotations.Test)

Example 4 with FailableRunnable

use of com.evolveum.midpoint.util.FailableRunnable in project midpoint by Evolveum.

the class TestConnectorMultiInstance method test120ReadJackDummyYellowTwoOperationsOneBlocking.

/**
	 * Block one read operation and let go the other. Make sure that new connector instance is created
	 * for the second operation and that it goes smoothly.
	 */
@Test
public void test120ReadJackDummyYellowTwoOperationsOneBlocking() throws Exception {
    final String TEST_NAME = "test120ReadJackDummyYellowTwoOperationsOneBlocking";
    TestUtil.displayTestTile(this, 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 {
            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);
    assertConnectorInstances("yellow (blocked)", RESOURCE_DUMMY_YELLOW_OID, 1, 0);
    assertNull("Unexpected shadow 1", shadowHolder1.getValue());
    dummyResourceYellow.setBlockOperations(false);
    // This should not be blocked and it should proceed immediately
    Thread t2 = executeInNewThread("get2", new FailableRunnable() {

        @Override
        public void run() throws Exception {
            PrismObject<ShadowType> shadow = getShadowModel(accountJackYellowOid);
            LOGGER.trace("Got shadow {}", shadow);
            shadowHolder2.setValue(shadow);
        }
    });
    t2.join(1000);
    assertConnectorInstances("yellow (blocked)", RESOURCE_DUMMY_YELLOW_OID, 1, 1);
    assertNull("Unexpected shadow 1", shadowHolder1.getValue());
    dummyResourceYellow.unblock();
    t1.join();
    // THEN
    PrismObject<ShadowType> shadowYellow1 = shadowHolder1.getValue();
    assertNotNull("No shadow 1", shadowHolder1.getValue());
    display("Shadow yellow 1", shadowYellow1);
    PrismObject<ShadowType> shadowYellow2 = shadowHolder2.getValue();
    assertNotNull("No shadow 2", shadowHolder2.getValue());
    display("Shadow yellow 2", shadowYellow2);
    assertConnectorInstances("yellow", RESOURCE_DUMMY_YELLOW_OID, 0, 2);
    assertConnectorToString(shadowYellow1, dummyResourceCtlYellow, initialConnectorToString);
    assertConnectorStaticVal(shadowYellow1, dummyResourceCtlYellow, initialConnectorStaticVal);
    assertConnectorToStringDifferent(shadowYellow2, dummyResourceCtlYellow, initialConnectorToString);
    assertConnectorStaticVal(shadowYellow2, dummyResourceCtlYellow, initialConnectorStaticVal);
    assertDummyAccount(RESOURCE_DUMMY_YELLOW_NAME, ACCOUNT_JACK_DUMMY_USERNAME, ACCOUNT_JACK_DUMMY_FULLNAME, true);
}
Also used : PrismObject(com.evolveum.midpoint.prism.PrismObject) FailableRunnable(com.evolveum.midpoint.util.FailableRunnable) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) Holder(com.evolveum.midpoint.util.Holder) ConfigurationException(com.evolveum.midpoint.util.exception.ConfigurationException) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ExpressionEvaluationException(com.evolveum.midpoint.util.exception.ExpressionEvaluationException) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) CommunicationException(com.evolveum.midpoint.util.exception.CommunicationException) Test(org.testng.annotations.Test)

Aggregations

FailableRunnable (com.evolveum.midpoint.util.FailableRunnable)4 PrismObject (com.evolveum.midpoint.prism.PrismObject)3 Holder (com.evolveum.midpoint.util.Holder)3 CommunicationException (com.evolveum.midpoint.util.exception.CommunicationException)3 ConfigurationException (com.evolveum.midpoint.util.exception.ConfigurationException)3 ExpressionEvaluationException (com.evolveum.midpoint.util.exception.ExpressionEvaluationException)3 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)3 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)3 ShadowType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)3 Test (org.testng.annotations.Test)3