Search in sources :

Example 6 with Semaphore

use of nl.nn.adapterframework.util.Semaphore in project iaf by ibissource.

the class JdbcTableListenerTest method testParallelChangeProcessState.

public void testParallelChangeProcessState(boolean mainThreadFirst) throws Exception {
    listener.configure();
    listener.open();
    JdbcUtil.executeStatement(dbmsSupport, connection, "DELETE FROM TEMP WHERE TKEY=10", null);
    JdbcUtil.executeStatement(dbmsSupport, connection, "INSERT INTO TEMP (TKEY,TINT) VALUES (10,1)", null);
    ChangeProcessStateTester changeProcessStateTester = new ChangeProcessStateTester(() -> getConnection());
    Object rawMessage1;
    Semaphore waitBeforeUpdate = new Semaphore();
    Semaphore updateDone = new Semaphore();
    Semaphore waitBeforeCommit = new Semaphore();
    Semaphore commitDone = new Semaphore();
    try (Connection conn = getConnection()) {
        conn.setAutoCommit(false);
        try {
            changeProcessStateTester.setWaitBeforeAction(waitBeforeUpdate);
            changeProcessStateTester.setActionDone(updateDone);
            changeProcessStateTester.setWaitAfterAction(waitBeforeCommit);
            changeProcessStateTester.setFinalizeActionDone(commitDone);
            changeProcessStateTester.start();
            if (!mainThreadFirst) {
                waitBeforeUpdate.release();
                updateDone.acquire();
            }
            rawMessage1 = listener.changeProcessState(conn, "10", ProcessState.ERROR, "test");
            if (mainThreadFirst) {
                waitBeforeUpdate.release();
            } else {
                waitBeforeCommit.release();
                commitDone.acquire();
                commitDone.release();
            }
            assertEquals(mainThreadFirst, rawMessage1 != null);
        } finally {
            waitBeforeCommit.release();
            conn.commit();
        }
    }
    commitDone.acquire();
    assertTrue(changeProcessStateTester.numRowsUpdated >= 0);
    assertTrue(changeProcessStateTester.numRowsUpdated <= 1);
    assertEquals(mainThreadFirst, changeProcessStateTester.numRowsUpdated == 0);
}
Also used : Connection(java.sql.Connection) Semaphore(nl.nn.adapterframework.util.Semaphore)

Example 7 with Semaphore

use of nl.nn.adapterframework.util.Semaphore in project iaf by ibissource.

the class PullingListenerContainer method configure.

public void configure() {
    if (receiver.getNumThreadsPolling() > 0 && receiver.getNumThreadsPolling() < receiver.getNumThreads()) {
        pollToken = new Semaphore(receiver.getNumThreadsPolling());
    }
    processToken = new Semaphore(receiver.getNumThreads());
    maxThreadCount = receiver.getNumThreads();
    if (receiver.getTransactionAttribute() != TransactionAttribute.NOTSUPPORTED) {
        DefaultTransactionDefinition txDef = new DefaultTransactionDefinition(TransactionAttribute.REQUIRESNEW.getTransactionAttributeNum());
        if (receiver.getTransactionTimeout() > 0) {
            txDef.setTimeout(receiver.getTransactionTimeout());
        }
        txNew = txDef;
    }
}
Also used : DefaultTransactionDefinition(org.springframework.transaction.support.DefaultTransactionDefinition) Semaphore(nl.nn.adapterframework.util.Semaphore)

Aggregations

Semaphore (nl.nn.adapterframework.util.Semaphore)7 StatisticsKeeper (nl.nn.adapterframework.statistics.StatisticsKeeper)4 PipeRunException (nl.nn.adapterframework.core.PipeRunException)3 PipeRunResult (nl.nn.adapterframework.core.PipeRunResult)2 Connection (java.sql.Connection)1 TransformerConfigurationException (javax.xml.transform.TransformerConfigurationException)1 ConfigurationException (nl.nn.adapterframework.configuration.ConfigurationException)1 IPipe (nl.nn.adapterframework.core.IPipe)1 PipeLineResult (nl.nn.adapterframework.core.PipeLineResult)1 DefaultTransactionDefinition (org.springframework.transaction.support.DefaultTransactionDefinition)1