1
2
3
4
5
6
7
8
9
10
11 package org.mule.impl;
12
13 import org.mule.impl.work.MuleWorkManager;
14 import org.mule.tck.AbstractMuleTestCase;
15
16 import javax.resource.spi.work.Work;
17
18 import org.apache.commons.logging.Log;
19 import org.apache.commons.logging.LogFactory;
20
21
22
23
24
25
26
27
28
29
30
31 public class MuleWorkManagerTestCase extends AbstractMuleTestCase
32 {
33 private final transient Log logger = LogFactory.getLog(getClass());
34
35 public void testDoWorkExecutesSynchronously() throws Exception
36 {
37 final Thread callerThread = Thread.currentThread();
38
39 MuleWorkManager wm = new MuleWorkManager();
40
41 try
42 {
43 wm.start();
44
45 wm.doWork(new Work()
46 {
47 public void release()
48 {
49
50 }
51
52 public void run()
53 {
54 Thread calleeThread = Thread.currentThread();
55 assertEquals("WorkManager.doWork() should have been executed in the same thread.",
56 callerThread, calleeThread);
57 if (logger.isDebugEnabled())
58 {
59 logger.debug("WORK: " + Thread.currentThread());
60 }
61 }
62 });
63 if (logger.isDebugEnabled())
64 {
65 logger.debug("MAIN: " + Thread.currentThread());
66 }
67 }
68 finally
69 {
70 wm.stop();
71 }
72
73 }
74
75 public void testScheduleWorkExecutesAsynchronously() throws Exception
76 {
77 final Thread callerThread = Thread.currentThread();
78
79 MuleWorkManager wm = new MuleWorkManager();
80
81 try
82 {
83 wm.start();
84
85 wm.scheduleWork(new Work()
86 {
87 public void release()
88 {
89
90 }
91
92 public void run()
93 {
94 Thread calleeThread = Thread.currentThread();
95 assertFalse("WorkManager.scheduleWork() should have been executed in a different thread.",
96 callerThread.equals(calleeThread));
97 if (logger.isDebugEnabled())
98 {
99 logger.debug("WORK: " + Thread.currentThread());
100 }
101 }
102 });
103 if (logger.isDebugEnabled())
104 {
105 logger.debug("MAIN: " + Thread.currentThread());
106 }
107 }
108 finally
109 {
110 wm.stop();
111 }
112
113 }
114
115 public void testStartWorkExecutesAsynchronously() throws Exception
116 {
117 final Thread callerThread = Thread.currentThread();
118
119 MuleWorkManager wm = new MuleWorkManager();
120
121 try
122 {
123 wm.start();
124
125 wm.startWork(new Work()
126 {
127 public void release()
128 {
129
130 }
131
132 public void run()
133 {
134 Thread calleeThread = Thread.currentThread();
135 assertFalse("WorkManager.startWork() should have been executed in a different thread.",
136 callerThread.equals(calleeThread));
137 if (logger.isDebugEnabled())
138 {
139 logger.debug("WORK: " + Thread.currentThread());
140 }
141 }
142 });
143 if (logger.isDebugEnabled())
144 {
145 logger.debug("MAIN: " + Thread.currentThread());
146 }
147 }
148 finally
149 {
150 wm.stop();
151 }
152
153 }
154
155 }