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);
}
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;
}
}
Aggregations