Revision cc7c531b
Added by Cherian Mathew over 8 years ago
eu.etaxonomy.taxeditor.test/src/test/java/eu/etaxonomy/taxeditor/service/ProgressMonitorServiceTest.java | ||
---|---|---|
9 | 9 |
*/ |
10 | 10 |
package eu.etaxonomy.taxeditor.service; |
11 | 11 |
|
12 |
import java.io.Serializable; |
|
13 | 12 |
import java.util.ArrayList; |
14 | 13 |
import java.util.Arrays; |
15 | 14 |
import java.util.List; |
... | ... | |
21 | 20 |
import org.junit.Assert; |
22 | 21 |
import org.junit.Test; |
23 | 22 |
|
23 |
import eu.etaxonomy.cdm.api.application.CdmApplicationState; |
|
24 | 24 |
import eu.etaxonomy.cdm.api.service.IProgressMonitorService; |
25 | 25 |
import eu.etaxonomy.cdm.api.service.ITestService; |
26 | 26 |
import eu.etaxonomy.cdm.common.monitor.IRemotingProgressMonitor; |
... | ... | |
52 | 52 |
|
53 | 53 |
@Test |
54 | 54 |
public void testMonitLongRunningMethod() throws InterruptedException { |
55 |
UUID uuid = testService.monitLongRunningMethod(null, null); |
|
55 |
UUID uuid = testService.monitLongRunningMethod(null, null, 0);
|
|
56 | 56 |
int pollInterval = 1000; |
57 | 57 |
RemotingProgressMonitor expectedMonitor = new RemotingProgressMonitor(); |
58 | 58 |
expectedMonitor.setResult("Success"); |
... | ... | |
70 | 70 |
public void testMonitLongRunningMethodByChangingUser() throws InterruptedException { |
71 | 71 |
|
72 | 72 |
IllegalStateException ise = new IllegalStateException("IllegalStateException"); |
73 |
UUID uuid = testService.monitLongRunningMethod(ise, null); |
|
73 |
UUID uuid = testService.monitLongRunningMethod(ise, null, 0);
|
|
74 | 74 |
authenticateExtraUser(); |
75 | 75 |
IRemotingProgressMonitor monitor = progressMonitorService.getRemotingMonitor(uuid); |
76 | 76 |
Assert.assertNull(monitor); |
... | ... | |
80 | 80 |
@Test |
81 | 81 |
public void testMonitLongRunningMethodWithException() throws InterruptedException { |
82 | 82 |
IllegalStateException ise = new IllegalStateException("IllegalStateException"); |
83 |
UUID uuid = testService.monitLongRunningMethod(ise, null); |
|
83 |
UUID uuid = testService.monitLongRunningMethod(ise, null, 0);
|
|
84 | 84 |
int pollInterval = 1000; |
85 | 85 |
RemotingProgressMonitor expectedMonitor = new RemotingProgressMonitor(); |
86 | 86 |
expectedMonitor.setResult(ise); |
... | ... | |
102 | 102 |
@Test |
103 | 103 |
public void testMonitLongRunningMethodWithInterrupt() { |
104 | 104 |
IllegalStateException ise = new IllegalStateException("Interrupted Exception"); |
105 |
final UUID uuid = testService.monitLongRunningMethod(ise, null); |
|
105 |
final UUID uuid = testService.monitLongRunningMethod(ise, null, 0);
|
|
106 | 106 |
final int pollInterval = 1000; |
107 | 107 |
final RemotingProgressMonitor expectedMonitor = new RemotingProgressMonitor(); |
108 | 108 |
expectedMonitor.setResult(ise); |
... | ... | |
120 | 120 |
null, |
121 | 121 |
(IFeedbackGenerator)null, |
122 | 122 |
new NullProgressMonitor()); |
123 |
Assert.fail("InterruptedException wrapped in an IllegalStateException should be thrown"); |
|
123 | 124 |
} catch (InterruptedException e) { |
124 | 125 |
|
126 |
} catch (IllegalStateException e) { |
|
127 |
|
|
125 | 128 |
} |
126 | 129 |
} |
127 | 130 |
}; |
... | ... | |
140 | 143 |
@Test |
141 | 144 |
public void testMonitLongRunningMethodWithCancellation() throws InterruptedException { |
142 | 145 |
|
143 |
final UUID uuid = testService.monitLongRunningMethod(null, null); |
|
146 |
final UUID uuid = testService.monitLongRunningMethod(null, null, 0);
|
|
144 | 147 |
final int pollInterval = 1000; |
145 | 148 |
final RemotingProgressMonitor expectedMonitor = new RemotingProgressMonitor(); |
146 | 149 |
expectedMonitor.setResult("Cancelled"); |
... | ... | |
180 | 183 |
final RemotingProgressMonitor expectedMonitor = new RemotingProgressMonitor(); |
181 | 184 |
expectedMonitor.setResult("Success"); |
182 | 185 |
for(String feedback : feedbacks) { |
183 |
feebackGenerators.add(new MockFeedbackGenerator(feedback)); |
|
186 |
feebackGenerators.add(new MockFeedbackGenerator(feedback, 0));
|
|
184 | 187 |
expectedMonitor.addReport(feedback); |
185 | 188 |
} |
186 | 189 |
expectedMonitor.addReport("Report"); |
187 | 190 |
expectedMonitor.done(); |
188 | 191 |
|
189 |
final UUID uuid = testService.monitLongRunningMethod(null, feedbacks); |
|
192 |
final UUID uuid = testService.monitLongRunningMethod(null, feedbacks, 0);
|
|
190 | 193 |
final int pollInterval = 1000; |
191 | 194 |
|
192 | 195 |
CdmStore.getProgressMonitorClientManager().pollMonitor("Testing Progress Monitor", |
... | ... | |
196 | 199 |
feebackGenerators, |
197 | 200 |
new NullProgressMonitor()); |
198 | 201 |
|
202 |
} |
|
203 |
|
|
204 |
@Test |
|
205 |
public void testMonitLongRunningMethodWithInconsistentWaitForFeedback() throws InterruptedException { |
|
206 |
|
|
207 |
List<String> feedbacks = Arrays.asList("feedback1", "feedback2"); |
|
208 |
List<IFeedbackGenerator> feebackGenerators = new ArrayList<IFeedbackGenerator>(); |
|
209 |
final RemotingProgressMonitor expectedMonitor = new RemotingProgressMonitor(); |
|
210 |
expectedMonitor.setResult("Success"); |
|
211 |
for(String feedback : feedbacks) { |
|
212 |
feebackGenerators.add(new MockFeedbackGenerator(feedback, 0)); |
|
213 |
expectedMonitor.addReport(feedback); |
|
214 |
} |
|
215 |
expectedMonitor.addReport("Report"); |
|
216 |
expectedMonitor.done(); |
|
217 |
|
|
218 |
final UUID uuid = testService.monitLongRunningMethod(null, feedbacks, 0); |
|
219 |
final int pollInterval = 1000; |
|
220 |
|
|
199 | 221 |
feebackGenerators.remove(1); |
200 | 222 |
|
201 |
final UUID newUuid = testService.monitLongRunningMethod(null, feedbacks); |
|
223 |
final UUID newUuid = testService.monitLongRunningMethod(null, feedbacks, 0);
|
|
202 | 224 |
|
203 | 225 |
try { |
204 | 226 |
CdmStore.getProgressMonitorClientManager().pollMonitor("Testing Progress Monitor", |
... | ... | |
211 | 233 |
} catch(IllegalStateException ise) { |
212 | 234 |
|
213 | 235 |
} |
236 |
} |
|
237 |
|
|
238 |
@Test |
|
239 |
public void testMonitLongRunningMethodWithWaitForFeedbackTimeout() throws InterruptedException { |
|
214 | 240 |
|
241 |
List<String> feedbacks = Arrays.asList("feedback1"); |
|
242 |
List<IFeedbackGenerator> feebackGenerators = new ArrayList<IFeedbackGenerator>(); |
|
243 |
final RemotingProgressMonitor expectedMonitor = new RemotingProgressMonitor(); |
|
244 |
expectedMonitor.setResult(new IllegalStateException(new InterruptedException())); |
|
245 |
for(String feedback : feedbacks) { |
|
246 |
feebackGenerators.add(new MockFeedbackGenerator(feedback, 1000 * 15)); |
|
215 | 247 |
|
248 |
} |
|
249 |
expectedMonitor.setCanceled(true); |
|
250 |
expectedMonitor.setIsFailed(true); |
|
251 |
expectedMonitor.done(); |
|
252 |
|
|
253 |
expectedMonitor.done(); |
|
254 |
|
|
255 |
final UUID uuid = testService.monitLongRunningMethod(null, feedbacks, 1000 * 5); |
|
256 |
final int pollInterval = 1000; |
|
257 |
|
|
258 |
|
|
259 |
try { |
|
260 |
CdmStore.getProgressMonitorClientManager().pollMonitor("Testing Progress Monitor", |
|
261 |
uuid, |
|
262 |
pollInterval, |
|
263 |
new MockPostMoniteredOperationEnabled(expectedMonitor, uuid), |
|
264 |
feebackGenerators, |
|
265 |
new NullProgressMonitor()); |
|
266 |
Assert.fail("Exception due to inconsistent number of feedback generators not thrown"); |
|
267 |
} catch(IllegalStateException ise) { |
|
268 |
|
|
269 |
} |
|
216 | 270 |
} |
217 | 271 |
|
218 | 272 |
|
... | ... | |
249 | 303 |
class MockFeedbackGenerator implements IFeedbackGenerator { |
250 | 304 |
|
251 | 305 |
private String feedback; |
306 |
private long waitTime; |
|
252 | 307 |
|
253 |
public MockFeedbackGenerator(String feedback) { |
|
308 |
public MockFeedbackGenerator(String feedback, long waitTime) {
|
|
254 | 309 |
this.feedback = feedback; |
310 |
this.waitTime = waitTime; |
|
255 | 311 |
} |
312 |
|
|
256 | 313 |
/** |
257 | 314 |
* {@inheritDoc} |
258 | 315 |
*/ |
259 | 316 |
@Override |
260 |
public Serializable generateFeedback() { |
|
261 |
return feedback; |
|
317 |
public void setFeedbackForMonitor(UUID uuid) { |
|
318 |
if(waitTime > 0) { |
|
319 |
try { |
|
320 |
Thread.sleep(waitTime); |
|
321 |
} catch (InterruptedException e) { |
|
322 |
e.printStackTrace(); |
|
323 |
} |
|
324 |
} |
|
325 |
CdmApplicationState.getCurrentAppConfig().getProgressMonitorService().setFeedback(uuid, feedback); |
|
262 | 326 |
} |
263 | 327 |
|
264 | 328 |
} |
Also available in: Unified diff
#5297 Implement client side remoting progress monitor feedback mechanism, Add test for monitor feedback timeout
#5297 Add test for monitor feedback timeout