public void testErrorHandlingInCoreEngine(String dsContext) throws Exception {
assumeFalse(skipTests());
final ConfigurableApplicationContext context = createContext(dsContext);
cleanDB(context.getBean(DataSource.class));
final PersistentScottyEngine engine = context.getBean(PersistentScottyEngine.class);
try {
engine.startup();
final WorkflowInstanceDescr<Serializable> wfInstanceDescr = new WorkflowInstanceDescr<Serializable>("de.scoopgmbh.copper.test.persistent.ExceptionThrowingPersistentUnitTestWorkflow");
wfInstanceDescr.setId(engine.createUUID());
engine.run(wfInstanceDescr);
Thread.sleep(5000);
//check
new RetryingTransaction<Void>(context.getBean(DataSource.class)) {
@Override
protected Void execute() throws Exception {
Statement stmt = createStatement(getConnection());
ResultSet rs = stmt.executeQuery("select * from cop_workflow_instance_error");
assertTrue(rs.next());
assertEquals(wfInstanceDescr.getId(), rs.getString("WORKFLOW_INSTANCE_ID"));
assertNotNull(rs.getString("EXCEPTION"));
assertFalse(rs.next());
rs.close();
stmt.close();
return null;
}
}.run();
engine.restart(wfInstanceDescr.getId());
Thread.sleep(5000);
new RetryingTransaction<Void>(context.getBean(DataSource.class)) {
@Override
protected Void execute() throws Exception {
Statement stmt = createStatement(getConnection());
ResultSet rs = stmt.executeQuery("select * from cop_workflow_instance_error");
assertTrue(rs.next());
assertEquals(wfInstanceDescr.getId(), rs.getString("WORKFLOW_INSTANCE_ID"));
assertNotNull(rs.getString("EXCEPTION"));
assertTrue(rs.next());
assertEquals(wfInstanceDescr.getId(), rs.getString("WORKFLOW_INSTANCE_ID"));
assertNotNull(rs.getString("EXCEPTION"));
assertFalse(rs.next());
rs.close();
stmt.close();
return null;
}
}.run();
}
finally {
closeContext(context);
}
assertEquals(EngineState.STOPPED,engine.getEngineState());
assertEquals(0,engine.getNumberOfWorkflowInstances());
}