ruleBase = SerializationHelper.serializeObject(ruleBase);
StatefulSession session = ruleBase.newStatefulSession();
session = SerializationHelper.getSerialisedStatefulSession(session);
List<String> list = new ArrayList<String>();
session.setGlobal("list", list);
ProcessInstance processInstance = session.startProcess("org.drools.integrationtests.multithread");
final ProcessInstanceSignalRunner[] r = new ProcessInstanceSignalRunner[THREAD_COUNT];
for ( int i = 0; i < t.length; i++ ) {
r[i] = new ProcessInstanceSignalRunner(i, processInstance, "event" + (i+1));
t[i] = new Thread( r[i], "thread-" + i );
t[i].start();
}
for ( int i = 0; i < t.length; i++ ) {
t[i].join();
if ( r[i].getStatus() == ProcessInstanceSignalRunner.Status.FAIL ) {
success = false;
}
}
if ( !success ) {
fail( "Multithread test failed. Look at the stack traces for details. " );
}
assertEquals(2, list.size());
assertFalse(list.get(0).equals(list.get(1)));
assertEquals(ProcessInstance.STATE_COMPLETED, processInstance.getState());
} catch ( Exception e ) {
e.printStackTrace();
fail( "Should not raise any exception: " + e.getMessage() );
}
}