01: package test;
02:
03: import dalma.test.WorkflowTestProgram;
04: import dalma.ErrorHandler;
05: import dalma.TimeUnit;
06: import dalma.endpoints.timer.TimerEndPoint;
07: import junit.textui.TestRunner;
08:
09: import java.io.Serializable;
10: import java.io.InputStream;
11: import java.io.NotSerializableException;
12:
13: /**
14: * Makes sure that the persistence failure kills the conversation cleanly.
15: *
16: * @author Kohsuke Kawaguchi
17: */
18: public class PersistenceFailureTest extends WorkflowTestProgram {
19: public PersistenceFailureTest(String name) {
20: super (name);
21: }
22:
23: public static void main(String[] args) {
24: TestRunner.run(PersistenceFailureTest.class);
25: }
26:
27: protected void setupEndPoints() throws Exception {
28: // no endpoint to set up
29: }
30:
31: Throwable reportedError;
32:
33: public void test() throws Exception {
34: engine.setErrorHandler(new ErrorHandler() {
35: public void onError(Throwable t) {
36: // make sure that the error is reported before the completion
37: try {
38: Thread.sleep(1000);
39: } catch (InterruptedException e) {
40: e.printStackTrace();
41: }
42: System.out.println("error reported");
43: reportedError = t;
44: }
45: });
46:
47: createConversation(ErrorConversation.class);
48: engine.waitForCompletion();
49: assert reportedError instanceof NotSerializableException;
50: }
51:
52: private static final class ErrorConversation implements Runnable,
53: Serializable {
54: public ErrorConversation() {
55: }
56:
57: public void run() {
58: System.out.println("Going to die");
59: InputStream in = System.in;
60:
61: TimerEndPoint.waitFor(1000, TimeUnit.DAYS);
62: }
63: }
64: }
|