assertTrue("DBMS not available",dbmsAvailable);
logger.info("running testMultipleEngines");
final int NUMB = 50;
final ConfigurableApplicationContext context = new ClassPathXmlApplicationContext(new String[] {"/CopperTxnPersistentWorkflowTest/multiengine-oracle-unittest-context.xml"});
cleanDB(context.getBean(DataSource.class));
final PersistentScottyEngine engineRed = context.getBean("persistent.engine.red",PersistentScottyEngine.class);
final PersistentScottyEngine engineBlue = context.getBean("persistent.engine.blue",PersistentScottyEngine.class);
final BackChannelQueue backChannelQueue = context.getBean(BackChannelQueue.class);
engineRed.startup();
engineBlue.startup();
try {
assertEquals(EngineState.STARTED,engineRed.getEngineState());
assertEquals(EngineState.STARTED,engineBlue.getEngineState());
for (int i=0; i<NUMB; i++) {
ProcessingEngine engine = i % 2 == 0 ? engineRed : engineBlue;
engine.run(PersistentUnitTestWorkflow_NAME,null);
}
int x=0;
long startTS = System.currentTimeMillis();
while (x < NUMB && startTS+60000 > System.currentTimeMillis()) {
WorkflowResult wfr = backChannelQueue.poll();
if (wfr != null) {
assertNull(wfr.getResult());
assertNull(wfr.getException());
x++;
}
else {
Thread.sleep(50);
}
}
assertSame("Test failed - Timeout - "+x+" responses so far",x, NUMB);
Thread.sleep(1000);
// check for late queue entries
assertNull(backChannelQueue.poll());
// check AuditTrail Log
new RetryingTransaction<Void>(context.getBean(DataSource.class)) {
@Override
protected Void execute() throws Exception {
ResultSet rs = getConnection().createStatement().executeQuery("SELECT count(*) FROM COP_AUDIT_TRAIL_EVENT");
rs.next();
int count = rs.getInt(1);
assertEquals(NUMB*6, count);
rs.close();
return null;
}
}.run();
}
finally {
context.close();
}
assertEquals(EngineState.STOPPED,engineRed.getEngineState());
assertEquals(EngineState.STOPPED,engineBlue.getEngineState());
assertEquals(0,engineRed.getNumberOfWorkflowInstances());
assertEquals(0,engineBlue.getNumberOfWorkflowInstances());