*/
package eu.etaxonomy.taxeditor.service;
-import java.io.Serializable;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.junit.Assert;
import org.junit.Test;
+import eu.etaxonomy.cdm.api.application.CdmApplicationState;
import eu.etaxonomy.cdm.api.service.IProgressMonitorService;
import eu.etaxonomy.cdm.api.service.ITestService;
import eu.etaxonomy.cdm.common.monitor.IRemotingProgressMonitor;
@Test
public void testMonitLongRunningMethod() throws InterruptedException {
- UUID uuid = testService.monitLongRunningMethod(null, null);
+ UUID uuid = testService.monitLongRunningMethod(null, null, 0);
int pollInterval = 1000;
RemotingProgressMonitor expectedMonitor = new RemotingProgressMonitor();
expectedMonitor.setResult("Success");
public void testMonitLongRunningMethodByChangingUser() throws InterruptedException {
IllegalStateException ise = new IllegalStateException("IllegalStateException");
- UUID uuid = testService.monitLongRunningMethod(ise, null);
+ UUID uuid = testService.monitLongRunningMethod(ise, null, 0);
authenticateExtraUser();
IRemotingProgressMonitor monitor = progressMonitorService.getRemotingMonitor(uuid);
Assert.assertNull(monitor);
@Test
public void testMonitLongRunningMethodWithException() throws InterruptedException {
IllegalStateException ise = new IllegalStateException("IllegalStateException");
- UUID uuid = testService.monitLongRunningMethod(ise, null);
+ UUID uuid = testService.monitLongRunningMethod(ise, null, 0);
int pollInterval = 1000;
RemotingProgressMonitor expectedMonitor = new RemotingProgressMonitor();
expectedMonitor.setResult(ise);
@Test
public void testMonitLongRunningMethodWithInterrupt() {
IllegalStateException ise = new IllegalStateException("Interrupted Exception");
- final UUID uuid = testService.monitLongRunningMethod(ise, null);
+ final UUID uuid = testService.monitLongRunningMethod(ise, null, 0);
final int pollInterval = 1000;
final RemotingProgressMonitor expectedMonitor = new RemotingProgressMonitor();
expectedMonitor.setResult(ise);
null,
(IFeedbackGenerator)null,
new NullProgressMonitor());
+ Assert.fail("InterruptedException wrapped in an IllegalStateException should be thrown");
} catch (InterruptedException e) {
+ } catch (IllegalStateException e) {
+
}
}
};
@Test
public void testMonitLongRunningMethodWithCancellation() throws InterruptedException {
- final UUID uuid = testService.monitLongRunningMethod(null, null);
+ final UUID uuid = testService.monitLongRunningMethod(null, null, 0);
final int pollInterval = 1000;
final RemotingProgressMonitor expectedMonitor = new RemotingProgressMonitor();
expectedMonitor.setResult("Cancelled");
final RemotingProgressMonitor expectedMonitor = new RemotingProgressMonitor();
expectedMonitor.setResult("Success");
for(String feedback : feedbacks) {
- feebackGenerators.add(new MockFeedbackGenerator(feedback));
+ feebackGenerators.add(new MockFeedbackGenerator(feedback, 0));
expectedMonitor.addReport(feedback);
}
expectedMonitor.addReport("Report");
expectedMonitor.done();
- final UUID uuid = testService.monitLongRunningMethod(null, feedbacks);
+ final UUID uuid = testService.monitLongRunningMethod(null, feedbacks, 0);
final int pollInterval = 1000;
CdmStore.getProgressMonitorClientManager().pollMonitor("Testing Progress Monitor",
feebackGenerators,
new NullProgressMonitor());
+ }
+
+ @Test
+ public void testMonitLongRunningMethodWithInconsistentWaitForFeedback() throws InterruptedException {
+
+ List<String> feedbacks = Arrays.asList("feedback1", "feedback2");
+ List<IFeedbackGenerator> feebackGenerators = new ArrayList<IFeedbackGenerator>();
+ final RemotingProgressMonitor expectedMonitor = new RemotingProgressMonitor();
+ expectedMonitor.setResult("Success");
+ for(String feedback : feedbacks) {
+ feebackGenerators.add(new MockFeedbackGenerator(feedback, 0));
+ expectedMonitor.addReport(feedback);
+ }
+ expectedMonitor.addReport("Report");
+ expectedMonitor.done();
+
+ final UUID uuid = testService.monitLongRunningMethod(null, feedbacks, 0);
+ final int pollInterval = 1000;
+
feebackGenerators.remove(1);
- final UUID newUuid = testService.monitLongRunningMethod(null, feedbacks);
+ final UUID newUuid = testService.monitLongRunningMethod(null, feedbacks, 0);
try {
CdmStore.getProgressMonitorClientManager().pollMonitor("Testing Progress Monitor",
} catch(IllegalStateException ise) {
}
+ }
+
+ @Test
+ public void testMonitLongRunningMethodWithWaitForFeedbackTimeout() throws InterruptedException {
+ List<String> feedbacks = Arrays.asList("feedback1");
+ List<IFeedbackGenerator> feebackGenerators = new ArrayList<IFeedbackGenerator>();
+ final RemotingProgressMonitor expectedMonitor = new RemotingProgressMonitor();
+ expectedMonitor.setResult(new IllegalStateException(new InterruptedException()));
+ for(String feedback : feedbacks) {
+ feebackGenerators.add(new MockFeedbackGenerator(feedback, 1000 * 15));
+ }
+ expectedMonitor.setCanceled(true);
+ expectedMonitor.setIsFailed(true);
+ expectedMonitor.done();
+
+ expectedMonitor.done();
+
+ final UUID uuid = testService.monitLongRunningMethod(null, feedbacks, 1000 * 5);
+ final int pollInterval = 1000;
+
+
+ try {
+ CdmStore.getProgressMonitorClientManager().pollMonitor("Testing Progress Monitor",
+ uuid,
+ pollInterval,
+ new MockPostMoniteredOperationEnabled(expectedMonitor, uuid),
+ feebackGenerators,
+ new NullProgressMonitor());
+ Assert.fail("Exception due to inconsistent number of feedback generators not thrown");
+ } catch(IllegalStateException ise) {
+
+ }
}
class MockFeedbackGenerator implements IFeedbackGenerator {
private String feedback;
+ private long waitTime;
- public MockFeedbackGenerator(String feedback) {
+ public MockFeedbackGenerator(String feedback, long waitTime) {
this.feedback = feedback;
+ this.waitTime = waitTime;
}
+
/**
* {@inheritDoc}
*/
@Override
- public Serializable generateFeedback() {
- return feedback;
+ public void setFeedbackForMonitor(UUID uuid) {
+ if(waitTime > 0) {
+ try {
+ Thread.sleep(waitTime);
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+ }
+ CdmApplicationState.getCurrentAppConfig().getProgressMonitorService().setFeedback(uuid, feedback);
}
}