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