[jbpm-commits] JBoss JBPM SVN: r1548 - pvm/trunk/modules/core/src/test/java/org/jbpm/jobexecutor.
do-not-reply at jboss.org
do-not-reply at jboss.org
Tue Jul 8 09:29:27 EDT 2008
Author: porcherg
Date: 2008-07-08 09:29:27 -0400 (Tue, 08 Jul 2008)
New Revision: 1548
Removed:
pvm/trunk/modules/core/src/test/java/org/jbpm/jobexecutor/mappings.hbm.xml
Modified:
pvm/trunk/modules/core/src/test/java/org/jbpm/jobexecutor/JobExecutorTimerSessionTest.java
Log:
fix test
Modified: pvm/trunk/modules/core/src/test/java/org/jbpm/jobexecutor/JobExecutorTimerSessionTest.java
===================================================================
--- pvm/trunk/modules/core/src/test/java/org/jbpm/jobexecutor/JobExecutorTimerSessionTest.java 2008-07-08 13:28:39 UTC (rev 1547)
+++ pvm/trunk/modules/core/src/test/java/org/jbpm/jobexecutor/JobExecutorTimerSessionTest.java 2008-07-08 13:29:27 UTC (rev 1548)
@@ -25,6 +25,7 @@
import org.jbpm.pvm.internal.job.TimerImpl;
import org.jbpm.pvm.internal.jobexecutor.JobDbSession;
import org.jbpm.pvm.internal.jobexecutor.JobExecutor;
+import org.jbpm.pvm.internal.model.ExecutionImpl;
import org.jbpm.pvm.job.Job;
import org.jbpm.pvm.session.PvmDbSession;
import org.jbpm.pvm.session.TimerSession;
@@ -181,9 +182,23 @@
assertTextPresent("null timer", e.getMessage());
}
+ // no execution
+ try {
+ timerImpl = new TimerImpl();
+ timerSession.schedule(timerImpl);
+ // clean before failure
+ timerSession.cancel(timerImpl);
+ fail("Should not happen");
+ } catch (PvmException e) {
+ assertTextPresent("no execution", e.getMessage());
+ }
+
+ ExecutionImpl execution = new ExecutionImpl();
+
// no signal or event
try {
timerImpl = new TimerImpl();
+ timerImpl.setExecution(execution);
timerSession.schedule(timerImpl);
// clean before failure
timerSession.cancel(timerImpl);
@@ -197,6 +212,8 @@
// null dueDate
try {
timerImpl = createTimer("schedule error 1", null);
+ timerImpl.setExecution(execution);
+
timerImpl.setSignalName("timeout");
timerSession.schedule(timerImpl);
// clean before failure
@@ -209,6 +226,8 @@
// date.getTime() negative
try {
timerImpl = createTimer("schedule error 2", new Date(-10));
+ timerImpl.setExecution(execution);
+
timerImpl.setSignalName("timeout");
timerSession.schedule(timerImpl);
// clean before failure
@@ -239,17 +258,26 @@
assertNbTimersEquals(0);
// scheduled non-executed jobImpl
+ ExecutionImpl execution = new ExecutionImpl();
+ getPvmDbSession().save(execution);
+
timerSession = getTimerSession();
timerImpl = createForbiddenTimer("cancel 2", 500);
timerImpl.setSignalName("timeout");
+ timerImpl.setExecution(execution);
+
timerSession.schedule(timerImpl);
newTransaction();
assertNbTimersEquals(1);
timerSession = getTimerSession();
timerSession.cancel(findFirstDueTimer());
+
newTransaction();
assertNbTimersEquals(0);
+ execution = getPvmDbSession().get(ExecutionImpl.class, execution.getDbid());
+ getPvmDbSession().delete(execution);
+
/*
* scheduled jobImpl with repeat
* This is not necessary because in the test, a timer scheduled with
@@ -260,32 +288,59 @@
/** Schedule a jobImpl in the past */
public void testSchedulePastJob() {
- TimerImpl timerImpl = createTimer("schedule past jobImpl", -500);
- timerImpl.setSignalName("timeout");
- getTimerSession().schedule(timerImpl);
- assertNbTimersEquals(1);
- newTransaction();
- waitUntilNbTimerEquals(0);
+ ExecutionImpl execution = new ExecutionImpl();
+ execution = reload(execution);
+ try {
+ TimerImpl timerImpl = createTimer("schedule past jobImpl", -500);
+ timerImpl.setExecution(execution);
+ timerImpl.setEventName("timeout");
+ getTimerSession().schedule(timerImpl);
+ assertNbTimersEquals(1);
+ newTransaction();
+ waitUntilNbTimerEquals(0);
+ } finally {
+ execution = getPvmDbSession().get(ExecutionImpl.class, execution.getDbid());
+ getPvmDbSession().delete(execution);
+ newTransaction();
+ }
}
/** Schedule a jobImpl in the future */
public void testScheduleFutureJob() {
- TimerImpl timerImpl = createTimer("schedule future jobImpl", 500);
- timerImpl.setSignalName("timeout");
- getTimerSession().schedule(timerImpl);
- newTransaction();
- assertNbTimersEquals(1);
- waitUntilNbTimerEquals(0);
+ ExecutionImpl execution = new ExecutionImpl();
+ execution = reload(execution);
+ try {
+ TimerImpl timerImpl = createTimer("schedule future jobImpl", 500);
+ timerImpl.setExecution(execution);
+ timerImpl.setEventName("timeout");
+ getTimerSession().schedule(timerImpl);
+ assertNbTimersEquals(1);
+ newTransaction();
+ waitUntilNbTimerEquals(0);
+ } finally {
+ execution = getPvmDbSession().get(ExecutionImpl.class, execution.getDbid());
+ getPvmDbSession().delete(execution);
+ newTransaction();
+ }
}
/** Test the method schedule with a repeated jobImpl */
public void testScheduleRepeatDelay() {
- TimerImpl timerImpl = createTimer("schedule repeat delay", 200, 400, 3);
- timerImpl.setSignalName("timeout");
- getTimerSession().schedule(timerImpl);
- newTransaction();
- assertNbTimersEquals(1);
- waitUntilNbTimerEquals(0);
+ ExecutionImpl execution = new ExecutionImpl();
+ execution = reload(execution);
+ try {
+ TimerImpl timerImpl = createTimer("schedule repeat delay", 200, 400, 3);
+ timerImpl.setExecution(execution);
+ timerImpl.setEventName("timeout");
+ getTimerSession().schedule(timerImpl);
+ assertNbTimersEquals(1);
+ newTransaction();
+ waitUntilNbTimerEquals(0);
+ } finally {
+ execution = getPvmDbSession().get(ExecutionImpl.class, execution.getDbid());
+ getPvmDbSession().delete(execution);
+ newTransaction();
+ }
}
@@ -295,31 +350,40 @@
private TimerImpl createIncrementingTimer(String name, Date dueDate, String variable) {
TestTimer timer = new TestTimer(name, dueDate, 1);
timer.setVariableName(variable);
- timer.setSignalName("incrementation");
+ timer.setEventName("incrementation");
return timer;
}
private void testManyTimers(int nbTimer, long delayBetweenTimers) {
- long startTime = System.currentTimeMillis();
- for (int i=0; i<nbTimer; i++) {
- Date dueDate = new Date(startTime + 1000 + i*delayBetweenTimers);
- String name = "timer " + i;
- TimerImpl timerImpl = createIncrementingTimer(name, dueDate, name);
- getTimerSession().schedule(timerImpl);
- }
-
- newTransaction();
- assertNbTimersEquals(nbTimer);
- waitUntilNbTimerEquals(0);
- int sum = 0;
- Map<String, Integer> variables = getVariables();
- if (variables != null) {
- for (Entry<String, Integer> variable : variables.entrySet()) {
- assertEquals(variable.getKey(), 1, (int)variable.getValue());
- sum += variable.getValue();
+ ExecutionImpl execution = new ExecutionImpl();
+ execution = reload(execution);
+ try {
+ long startTime = System.currentTimeMillis();
+ for (int i=0; i<nbTimer; i++) {
+ Date dueDate = new Date(startTime + 1000 + i*delayBetweenTimers);
+ String name = "timer " + i;
+ TimerImpl timerImpl = createIncrementingTimer(name, dueDate, name);
+ timerImpl.setExecution(execution);
+ getTimerSession().schedule(timerImpl);
}
- }
- assertEquals(nbTimer, sum);
+
+ newTransaction();
+ assertNbTimersEquals(nbTimer);
+ waitUntilNbTimerEquals(0);
+ int sum = 0;
+ Map<String, Integer> variables = getVariables();
+ if (variables != null) {
+ for (Entry<String, Integer> variable : variables.entrySet()) {
+ assertEquals(variable.getKey(), 1, (int)variable.getValue());
+ sum += variable.getValue();
+ }
+ }
+ assertEquals(nbTimer, sum);
+ } finally {
+ execution = getPvmDbSession().get(ExecutionImpl.class, execution.getDbid());
+ getPvmDbSession().delete(execution);
+ newTransaction();
+ }
}
public void testSeveralTimer() {
Deleted: pvm/trunk/modules/core/src/test/java/org/jbpm/jobexecutor/mappings.hbm.xml
===================================================================
--- pvm/trunk/modules/core/src/test/java/org/jbpm/jobexecutor/mappings.hbm.xml 2008-07-08 13:28:39 UTC (rev 1547)
+++ pvm/trunk/modules/core/src/test/java/org/jbpm/jobexecutor/mappings.hbm.xml 2008-07-08 13:29:27 UTC (rev 1548)
@@ -1,30 +0,0 @@
-<?xml version="1.0"?>
-
-<!DOCTYPE hibernate-mapping PUBLIC
- "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
- "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
-
-<hibernate-mapping package="org.jbpm.jobexecutor" default-access="field">
-
- <subclass name="TestMessage" extends="org.jbpm.pvm.internal.job.MessageImpl" discriminator-value="T">
- <property name="messageId" />
- </subclass>
-
- <subclass name="FailingTestMessage" extends="org.jbpm.pvm.internal.job.MessageImpl" discriminator-value="F">
- </subclass>
-
- <subclass name="ExclusiveTestMessage" extends="org.jbpm.pvm.internal.job.MessageImpl" discriminator-value="E">
- </subclass>
-
- <subclass name="FailOnceTestMessage" extends="org.jbpm.pvm.internal.job.MessageImpl" discriminator-value="O">
- <property name="messageId" />
- </subclass>
-
- <subclass name="TestTimer" extends="org.jbpm.pvm.internal.job.TimerImpl" discriminator-value="TestTimer">
- <property name="name" />
- <property name="nbMaxExecution" />
- <property name="nbExecution" />
- <property name="variableName" />
- </subclass>
-
-</hibernate-mapping>
\ No newline at end of file
More information about the jbpm-commits
mailing list