[jbpm-commits] JBoss JBPM SVN: r4936 - in jbpm3/branches/jbpm-3.2.5-soa/modules/core/src: main/java/org/jbpm/job/executor and 8 other directories.
do-not-reply at jboss.org
do-not-reply at jboss.org
Thu May 28 11:17:35 EDT 2009
Author: alex.guizar at jboss.com
Date: 2009-05-28 11:17:35 -0400 (Thu, 28 May 2009)
New Revision: 4936
Removed:
jbpm3/branches/jbpm-3.2.5-soa/modules/core/src/test/java/org/jbpm/seam/AsyncAction.java
Modified:
jbpm3/branches/jbpm-3.2.5-soa/modules/core/src/main/java/org/jbpm/db/AbstractDbTestCase.java
jbpm3/branches/jbpm-3.2.5-soa/modules/core/src/main/java/org/jbpm/job/executor/JobExecutor.java
jbpm3/branches/jbpm-3.2.5-soa/modules/core/src/main/java/org/jbpm/job/executor/JobExecutorThread.java
jbpm3/branches/jbpm-3.2.5-soa/modules/core/src/main/resources/org/jbpm/context/log/VariableDeleteLog.hbm.xml
jbpm3/branches/jbpm-3.2.5-soa/modules/core/src/main/resources/org/jbpm/context/log/VariableLog.hbm.xml
jbpm3/branches/jbpm-3.2.5-soa/modules/core/src/test/java/org/jbpm/bytes/ByteArrayDbTest.java
jbpm3/branches/jbpm-3.2.5-soa/modules/core/src/test/java/org/jbpm/job/executor/JobExecutorDbTest.java
jbpm3/branches/jbpm-3.2.5-soa/modules/core/src/test/java/org/jbpm/logging/exe/LoggingConfigDbTest.java
jbpm3/branches/jbpm-3.2.5-soa/modules/core/src/test/java/org/jbpm/perf/TasklistEagerLoadingTest.java
jbpm3/branches/jbpm-3.2.5-soa/modules/core/src/test/java/org/jbpm/seam/JobExecutorCustomizationTest.java
jbpm3/branches/jbpm-3.2.5-soa/modules/core/src/test/java/org/jbpm/taskmgmt/exe/TaskInstanceDbTest.java
jbpm3/branches/jbpm-3.2.5-soa/modules/core/src/test/java/org/jbpm/taskmgmt/log/TaskLogDbTest.java
Log:
JBPM-1812: Fix tests that don't cleanup the database (RESOLVED)
Merge r3689 from branch aguizar and r3909 from trunk
Modified: jbpm3/branches/jbpm-3.2.5-soa/modules/core/src/main/java/org/jbpm/db/AbstractDbTestCase.java
===================================================================
--- jbpm3/branches/jbpm-3.2.5-soa/modules/core/src/main/java/org/jbpm/db/AbstractDbTestCase.java 2009-05-28 12:59:30 UTC (rev 4935)
+++ jbpm3/branches/jbpm-3.2.5-soa/modules/core/src/main/java/org/jbpm/db/AbstractDbTestCase.java 2009-05-28 15:17:35 UTC (rev 4936)
@@ -32,7 +32,6 @@
import org.hibernate.Session;
import org.hibernate.cfg.Configuration;
import org.hibernate.cfg.Environment;
-import org.hibernate.tool.hbm2ddl.SchemaExport;
import org.jbpm.AbstractJbpmTestCase;
import org.jbpm.JbpmConfiguration;
@@ -48,9 +47,7 @@
public abstract class AbstractDbTestCase extends AbstractJbpmTestCase {
protected JbpmConfiguration jbpmConfiguration;
-
protected JbpmContext jbpmContext;
- protected SchemaExport schemaExport;
protected Session session;
protected GraphSession graphSession;
@@ -86,7 +83,6 @@
Map rowsPerTable = jbpmSchema.getRowsPerTable();
for (Iterator i = rowsPerTable.entrySet().iterator(); i.hasNext();) {
Map.Entry entry = (Entry) i.next();
- String tableName = (String) entry.getKey();
Long count = (Long) entry.getValue();
if (count.intValue() != 0) {
hasLeftOvers = true;
@@ -97,7 +93,7 @@
" left " +
count +
" records in " +
- tableName);
+ entry.getKey());
}
}
@@ -107,8 +103,8 @@
}
protected String getHibernateDialect() {
- DbPersistenceServiceFactory factory = (DbPersistenceServiceFactory) jbpmContext.getServiceFactory(Services.SERVICENAME_PERSISTENCE);
- return factory.getConfiguration().getProperty(Environment.DIALECT);
+ DbPersistenceServiceFactory persistenceServiceFactory = (DbPersistenceServiceFactory) jbpmContext.getServiceFactory(Services.SERVICENAME_PERSISTENCE);
+ return persistenceServiceFactory.getConfiguration().getProperty(Environment.DIALECT);
}
protected void beginSessionTransaction() {
@@ -196,12 +192,12 @@
if (System.currentTimeMillis() - startTime > timeout) {
fail("test execution exceeded treshold of " + timeout + " milliseconds");
}
- log.debug("waiting for the job executor to process more jobs");
+ log.debug("waiting for job executor to process more jobs");
try {
Thread.sleep(500);
}
catch (InterruptedException e) {
- // keep going
+ fail("wait for job executor to process more jobs got interrupted");
}
}
}
@@ -257,7 +253,7 @@
jobExecutor.stopAndJoin();
}
catch (InterruptedException e) {
- throw new RuntimeException("waiting for job executor to stop and join got interrupted", e);
+ log.debug("wait for job executor to stop and join got interrupted", e);
}
}
}
Modified: jbpm3/branches/jbpm-3.2.5-soa/modules/core/src/main/java/org/jbpm/job/executor/JobExecutor.java
===================================================================
--- jbpm3/branches/jbpm-3.2.5-soa/modules/core/src/main/java/org/jbpm/job/executor/JobExecutor.java 2009-05-28 12:59:30 UTC (rev 4935)
+++ jbpm3/branches/jbpm-3.2.5-soa/modules/core/src/main/java/org/jbpm/job/executor/JobExecutor.java 2009-05-28 15:17:35 UTC (rev 4936)
@@ -7,6 +7,7 @@
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
+import java.util.Hashtable;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
@@ -14,10 +15,10 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+
import org.jbpm.JbpmConfiguration;
-public class JobExecutor implements Serializable
-{
+public class JobExecutor implements Serializable {
private static final long serialVersionUID = 1L;
@@ -26,6 +27,7 @@
protected int nbrOfThreads;
protected int idleInterval;
protected int maxIdleInterval;
+ /** @deprecated this field was never used */
protected int historyMaxSize;
protected int maxLockTime;
@@ -34,261 +36,246 @@
protected Map threads = new HashMap();
protected LockMonitorThread lockMonitorThread;
- protected Map monitoredJobIds = Collections.synchronizedMap(new HashMap());
+ protected Map monitoredJobIds = new Hashtable();
protected boolean isStarted = false;
protected static String hostName;
- public synchronized void start()
- {
- if (!isStarted)
- {
+ public synchronized void start() {
+ if (!isStarted) {
log.debug("starting thread group '" + name + "'...");
- for (int i = 0; i < nbrOfThreads; i++)
- {
+ for (int i = 0; i < nbrOfThreads; i++) {
startThread();
}
lockMonitorThread = new LockMonitorThread(jbpmConfiguration, lockMonitorInterval, maxLockTime, lockBufferTime);
isStarted = true;
}
- else
- {
+ else {
log.debug("ignoring start: thread group '" + name + "' is already started'");
}
}
- /*
- * signals to all threads in this job executor to stop. It may be that threads are in the middle of something and they will finish that firts. Use {@link
- * #stopAndJoin()} in case you want a method that blocks until all the threads are actually finished.
- * @return a list of all the stopped threads. In case no threads were stopped an empty list will be returned.
+ /**
+ * signals to all threads in this job executor to stop. Threads may be in the middle of processing
+ * a job and they will finish that first. Use {@link #stopAndJoin()} in case you want a method
+ * that blocks until all the threads are actually finished.
+ *
+ * @return a list of the stopped threads. In case no threads were stopped an empty list will be
+ * returned.
*/
- public synchronized List stop()
- {
- List stoppedThreads = new ArrayList(threads.size());
- if (isStarted)
- {
+ public synchronized List stop() {
+ List stoppedThreads;
+ if (isStarted) {
log.debug("stopping thread group '" + name + "'...");
- for (int i = 0; i < nbrOfThreads; i++)
- {
+ isStarted = false;
+
+ stoppedThreads = new ArrayList(threads.size());
+ for (int i = 0; i < nbrOfThreads; i++) {
stoppedThreads.add(stopThread());
}
- if (lockMonitorThread != null)
- lockMonitorThread.deactivate();
- isStarted = false;
+
+ if (lockMonitorThread != null) lockMonitorThread.deactivate();
}
- else
- {
+ else {
log.debug("ignoring stop: thread group '" + name + "' not started");
+ stoppedThreads = Collections.EMPTY_LIST;
}
return stoppedThreads;
}
- public void stopAndJoin() throws InterruptedException
- {
- Iterator iter = stop().iterator();
- while (iter.hasNext())
- {
- Thread thread = (Thread)iter.next();
+ public void stopAndJoin() throws InterruptedException {
+ for (Iterator i = stop().iterator(); i.hasNext();) {
+ Thread thread = (Thread) i.next();
thread.join();
}
- if (lockMonitorThread != null)
- lockMonitorThread.join();
+
+ if (lockMonitorThread != null) lockMonitorThread.join();
}
- protected synchronized void startThread()
- {
+ protected synchronized void startThread() {
String threadName = getNextThreadName();
Thread thread = createThread(threadName);
threads.put(threadName, thread);
+
log.debug("starting new job executor thread '" + threadName + "'");
thread.start();
}
- protected Thread createThread(String threadName)
- {
- return new JobExecutorThread(threadName, this, jbpmConfiguration, idleInterval, maxIdleInterval, maxLockTime, historyMaxSize);
+ protected Thread createThread(String threadName) {
+ return new JobExecutorThread(threadName, this);
}
- protected String getNextThreadName()
- {
+ protected String getNextThreadName() {
return getThreadName(threads.size() + 1);
}
- protected String getLastThreadName()
- {
+ protected String getLastThreadName() {
return getThreadName(threads.size());
}
- private String getThreadName(int index)
- {
- return name + ":" + getHostName() + ":" + index;
+ private String getThreadName(int index) {
+ return name + ":" + getHostAddress() + ":" + index;
}
- private static String getHostName()
- {
- if (hostName == null)
- {
- try
- {
+ private static String getHostAddress() {
+ if (hostName == null) {
+ try {
hostName = InetAddress.getLocalHost().getHostAddress();
}
- catch (UnknownHostException e)
- {
+ catch (UnknownHostException e) {
hostName = "127.0.0.1";
}
}
return hostName;
}
- protected synchronized Thread stopThread()
- {
+ protected synchronized Thread stopThread() {
String threadName = getLastThreadName();
- JobExecutorThread thread = (JobExecutorThread)threads.remove(threadName);
log.debug("removing job executor thread '" + threadName + "'");
- thread.deactivate();
+
+ Thread thread = (Thread) threads.remove(threadName);
+ if (thread instanceof JobExecutorThread) {
+ JobExecutorThread jobThread = (JobExecutorThread) thread;
+ jobThread.deactivate();
+ }
return thread;
}
- public void setMonitoredJobIds(Map monitoredJobIds)
- {
- this.monitoredJobIds = monitoredJobIds;
- }
-
- public Set getMonitoredJobIds()
- {
+ public Set getMonitoredJobIds() {
return new HashSet(monitoredJobIds.values());
}
- public void addMonitoredJobId(String threadName, long jobId)
- {
+ public void addMonitoredJobId(String threadName, long jobId) {
monitoredJobIds.put(threadName, new Long(jobId));
}
- public void removeMonitoredJobId(String threadName)
- {
+ public void removeMonitoredJobId(String threadName) {
monitoredJobIds.remove(threadName);
}
- public void setHistoryMaxSize(int historyMaxSize)
- {
- this.historyMaxSize = historyMaxSize;
+ /**
+ * @throws UnsupportedOperationException to prevent invocation
+ * @deprecated <code>monitoredJobIds</code> is an internal control field
+ */
+ public void setMonitoredJobIds(Map monitoredJobIds) {
+ throw new UnsupportedOperationException();
}
- public int getHistoryMaxSize()
- {
+ /** @deprecated this property was never used */
+ public int getHistoryMaxSize() {
return historyMaxSize;
}
- public void setIdleInterval(int idleInterval)
- {
- this.idleInterval = idleInterval;
+ /** @deprecated this property was never used */
+ public void setHistoryMaxSize(int historyMaxSize) {
+ this.historyMaxSize = historyMaxSize;
}
- public int getIdleInterval()
- {
+ public int getIdleInterval() {
return idleInterval;
}
- public void setStarted(boolean isStarted)
- {
- this.isStarted = isStarted;
+ public void setIdleInterval(int idleInterval) {
+ this.idleInterval = idleInterval;
}
- public boolean isStarted()
- {
+ /**
+ * Tells whether this job executor has been {@linkplain #start() started}.
+ */
+ public boolean isStarted() {
return isStarted;
}
- public void setJbpmConfiguration(JbpmConfiguration jbpmConfiguration)
- {
- this.jbpmConfiguration = jbpmConfiguration;
+ /**
+ * @throws UnsupportedOperationException to prevent invocation
+ * @deprecated <code>isStarted</code> is an internal control field
+ */
+ public void setStarted(boolean isStarted) {
+ throw new UnsupportedOperationException();
}
- public JbpmConfiguration getJbpmConfiguration()
- {
+ public JbpmConfiguration getJbpmConfiguration() {
return jbpmConfiguration;
}
- public void setMaxIdleInterval(int maxIdleInterval)
- {
- this.maxIdleInterval = maxIdleInterval;
+ public void setJbpmConfiguration(JbpmConfiguration jbpmConfiguration) {
+ this.jbpmConfiguration = jbpmConfiguration;
}
- public int getMaxIdleInterval()
- {
+ public int getMaxIdleInterval() {
return maxIdleInterval;
}
- public void setName(String name)
- {
- this.name = name;
+ public void setMaxIdleInterval(int maxIdleInterval) {
+ this.maxIdleInterval = maxIdleInterval;
}
- public String getName()
- {
+ public String getName() {
return name;
}
- public void setSize(int nbrOfThreads)
- {
- this.nbrOfThreads = nbrOfThreads;
+ public void setName(String name) {
+ this.name = name;
}
- public int getSize()
- {
+ /**
+ * @deprecated Replaced by {@link #getNbrOfThreads()}
+ */
+ public int getSize() {
return nbrOfThreads;
}
- public void setThreads(Map threads)
- {
- this.threads = threads;
+ /**
+ * @deprecated Replaced by {@link #setNbrOfThreads(int)}
+ */
+ public void setSize(int nbrOfThreads) {
+ this.nbrOfThreads = nbrOfThreads;
}
- public Map getThreads()
- {
+ public Map getThreads() {
return threads;
}
- public void setMaxLockTime(int maxLockTime)
- {
- this.maxLockTime = maxLockTime;
+ /**
+ * @throws UnsupportedOperationException to prevent invocation
+ * @deprecated <code>threads</code> is an internal control field
+ */
+ public void setThreads(Map threads) {
+ throw new UnsupportedOperationException();
}
- public int getMaxLockTime()
- {
+ public int getMaxLockTime() {
return maxLockTime;
}
- public void setLockBufferTime(int lockBufferTime)
- {
- this.lockBufferTime = lockBufferTime;
+ public void setMaxLockTime(int maxLockTime) {
+ this.maxLockTime = maxLockTime;
}
- public int getLockBufferTime()
- {
+ public int getLockBufferTime() {
return lockBufferTime;
}
- public void setLockMonitorInterval(int lockMonitorInterval)
- {
- this.lockMonitorInterval = lockMonitorInterval;
+ public void setLockBufferTime(int lockBufferTime) {
+ this.lockBufferTime = lockBufferTime;
}
- public int getLockMonitorInterval()
- {
+ public int getLockMonitorInterval() {
return lockMonitorInterval;
}
- public void setNbrOfThreads(int nbrOfThreads)
- {
- this.nbrOfThreads = nbrOfThreads;
+ public void setLockMonitorInterval(int lockMonitorInterval) {
+ this.lockMonitorInterval = lockMonitorInterval;
}
- public int getNbrOfThreads()
- {
+ public int getNbrOfThreads() {
return nbrOfThreads;
}
+ public void setNbrOfThreads(int nbrOfThreads) {
+ this.nbrOfThreads = nbrOfThreads;
+ }
+
private static Log log = LogFactory.getLog(JobExecutor.class);
}
Modified: jbpm3/branches/jbpm-3.2.5-soa/modules/core/src/main/java/org/jbpm/job/executor/JobExecutorThread.java
===================================================================
--- jbpm3/branches/jbpm-3.2.5-soa/modules/core/src/main/java/org/jbpm/job/executor/JobExecutorThread.java 2009-05-28 12:59:30 UTC (rev 4935)
+++ jbpm3/branches/jbpm-3.2.5-soa/modules/core/src/main/java/org/jbpm/job/executor/JobExecutorThread.java 2009-05-28 15:17:35 UTC (rev 4936)
@@ -22,6 +22,28 @@
public class JobExecutorThread extends Thread {
+ final JobExecutor jobExecutor;
+ final JbpmConfiguration jbpmConfiguration;
+ final int idleInterval;
+ final int maxIdleInterval;
+ final long maxLockTime;
+
+ int currentIdleInterval;
+ volatile boolean isActive = true;
+
+ public JobExecutorThread(String name, JobExecutor jobExecutor) {
+ super(name);
+ this.jobExecutor = jobExecutor;
+
+ jbpmConfiguration = jobExecutor.getJbpmConfiguration();
+ idleInterval = jobExecutor.getIdleInterval();
+ maxIdleInterval = jobExecutor.getMaxIdleInterval();
+ maxLockTime = jobExecutor.getMaxLockTime();
+ }
+
+ /**
+ * @deprecated use {@link #JobExecutorThread(String, JobExecutor)} instead
+ */
public JobExecutorThread(String name, JobExecutor jobExecutor,
JbpmConfiguration jbpmConfiguration, int idleInterval, int maxIdleInterval, long maxLockTime,
int maxHistory) {
@@ -33,15 +55,6 @@
this.maxLockTime = maxLockTime;
}
- final JobExecutor jobExecutor;
- final JbpmConfiguration jbpmConfiguration;
- final int idleInterval;
- final int maxIdleInterval;
- final long maxLockTime;
-
- int currentIdleInterval;
- volatile boolean isActive = true;
-
public void run() {
currentIdleInterval = idleInterval;
while (isActive) {
@@ -65,9 +78,9 @@
currentIdleInterval = idleInterval;
}
catch (RuntimeException e) {
- log.error("exception in job executor thread. waiting "
- + currentIdleInterval
- + " milliseconds", e);
+ log.error("exception in job executor thread. waiting " +
+ currentIdleInterval +
+ " milliseconds", e);
try {
synchronized (jobExecutor) {
jobExecutor.wait(currentIdleInterval);
@@ -76,7 +89,7 @@
catch (InterruptedException ie) {
log.debug("delay after exception got interrupted", ie);
}
- // after an exception, the current idle interval is doubled to prevent
+ // after an exception, the current idle interval is doubled to prevent
// continuous exception generation when e.g. the db is unreachable
currentIdleInterval <<= 1;
if (currentIdleInterval > maxIdleInterval || currentIdleInterval < 0) {
@@ -107,10 +120,10 @@
ProcessInstance processInstance = job.getProcessInstance();
log.debug("finding other exclusive jobs for " + processInstance);
jobsToLock = jobSession.findExclusiveJobs(lockOwner, processInstance);
- log.debug("trying to obtain exclusive locks on "
- + jobsToLock
- + " for "
- + processInstance);
+ log.debug("trying to obtain exclusive locks on " +
+ jobsToLock +
+ " for " +
+ processInstance);
}
else {
log.debug("trying to obtain lock on " + job);
@@ -141,8 +154,8 @@
catch (JbpmPersistenceException e) {
// if this is a stale state exception, keep it quiet
if (DbPersistenceService.isStaleStateException(e)) {
- StaleObjectLogConfigurer.getStaleObjectExceptionsLog().error(
- "failed to acquire lock on jobs " + jobsToLock);
+ StaleObjectLogConfigurer.getStaleObjectExceptionsLog()
+ .error("failed to acquire lock on jobs " + jobsToLock);
acquiredJobs = Collections.EMPTY_LIST;
}
else {
@@ -197,8 +210,8 @@
catch (JbpmPersistenceException e) {
// if this is a stale state exception, keep it quiet
if (DbPersistenceService.isStaleStateException(e)) {
- StaleObjectLogConfigurer.getStaleObjectExceptionsLog().error(
- "failed to complete job " + job);
+ StaleObjectLogConfigurer.getStaleObjectExceptionsLog().error("failed to complete job " +
+ job);
}
else {
throw e;
@@ -231,8 +244,8 @@
catch (JbpmPersistenceException e) {
// if this is a stale state exception, keep it quiet
if (DbPersistenceService.isStaleStateException(e)) {
- StaleObjectLogConfigurer.getStaleObjectExceptionsLog().error(
- "failed to determine next due date for job executor thread " + threadName);
+ StaleObjectLogConfigurer.getStaleObjectExceptionsLog()
+ .error("failed to determine next due date for job executor thread " + threadName);
nextDueDate = null;
}
else {
Modified: jbpm3/branches/jbpm-3.2.5-soa/modules/core/src/main/resources/org/jbpm/context/log/VariableDeleteLog.hbm.xml
===================================================================
--- jbpm3/branches/jbpm-3.2.5-soa/modules/core/src/main/resources/org/jbpm/context/log/VariableDeleteLog.hbm.xml 2009-05-28 12:59:30 UTC (rev 4935)
+++ jbpm3/branches/jbpm-3.2.5-soa/modules/core/src/main/resources/org/jbpm/context/log/VariableDeleteLog.hbm.xml 2009-05-28 15:17:35 UTC (rev 4936)
@@ -1,5 +1,4 @@
<?xml version="1.0"?>
-
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
@@ -9,6 +8,13 @@
<subclass name="org.jbpm.context.log.VariableDeleteLog"
extends="org.jbpm.context.log.VariableLog"
discriminator-value="D">
+
+ <many-to-one name="variableInstance"
+ column="VARIABLEINSTANCE_"
+ cascade="all"
+ insert="false"
+ update="false" />
+
</subclass>
</hibernate-mapping>
Modified: jbpm3/branches/jbpm-3.2.5-soa/modules/core/src/main/resources/org/jbpm/context/log/VariableLog.hbm.xml
===================================================================
--- jbpm3/branches/jbpm-3.2.5-soa/modules/core/src/main/resources/org/jbpm/context/log/VariableLog.hbm.xml 2009-05-28 12:59:30 UTC (rev 4935)
+++ jbpm3/branches/jbpm-3.2.5-soa/modules/core/src/main/resources/org/jbpm/context/log/VariableLog.hbm.xml 2009-05-28 15:17:35 UTC (rev 4936)
@@ -12,7 +12,6 @@
<many-to-one name="variableInstance"
column="VARIABLEINSTANCE_"
- cascade="save-update"
foreign-key="FK_LOG_VARINST"
index="IDX_LOG_VARINST" />
Modified: jbpm3/branches/jbpm-3.2.5-soa/modules/core/src/test/java/org/jbpm/bytes/ByteArrayDbTest.java
===================================================================
--- jbpm3/branches/jbpm-3.2.5-soa/modules/core/src/test/java/org/jbpm/bytes/ByteArrayDbTest.java 2009-05-28 12:59:30 UTC (rev 4935)
+++ jbpm3/branches/jbpm-3.2.5-soa/modules/core/src/test/java/org/jbpm/bytes/ByteArrayDbTest.java 2009-05-28 15:17:35 UTC (rev 4936)
@@ -31,54 +31,78 @@
byte[] bytes = getMultipleBlockBytes();
ByteArray byteArray = new ByteArray(bytes);
session.save(byteArray);
+
newTransaction();
- ByteArray retrievedByteArray = (ByteArray) session.load(ByteArray.class, new Long(byteArray.getId()));
+ ByteArray retrievedByteArray = (ByteArray) session.load(ByteArray.class, new Long(
+ byteArray.getId()));
assertEquals(byteArray.byteBlocks.size(), retrievedByteArray.getByteBlocks().size());
assertTrue(Arrays.equals(byteArray.getBytes(), retrievedByteArray.getBytes()));
+
+ session.delete(retrievedByteArray);
}
public void testEmptyByteArray() {
byte[] bytes = new byte[0];
ByteArray byteArray = new ByteArray(bytes);
session.save(byteArray);
+
newTransaction();
- ByteArray retrievedByteArray = (ByteArray) session.load(ByteArray.class, new Long(byteArray.getId()));
+ ByteArray retrievedByteArray = (ByteArray) session.load(ByteArray.class, new Long(
+ byteArray.getId()));
assertNull(retrievedByteArray.getBytes());
+
+ session.delete(retrievedByteArray);
}
public void testByteArrayCopy() {
byte[] bytes = getMultipleBlockBytes();
ByteArray byteArray = new ByteArray(bytes);
session.save(byteArray);
+
newTransaction();
- ByteArray retrievedByteArray = (ByteArray) session.load(ByteArray.class, new Long(byteArray.getId()));
+ ByteArray retrievedByteArray = (ByteArray) session.load(ByteArray.class, new Long(
+ byteArray.getId()));
ByteArray copiedByteArray = new ByteArray(retrievedByteArray);
session.save(copiedByteArray);
+
newTransaction();
- retrievedByteArray = (ByteArray) session.load(ByteArray.class, new Long(retrievedByteArray.getId()));
+ retrievedByteArray = (ByteArray) session.load(ByteArray.class, new Long(
+ retrievedByteArray.getId()));
copiedByteArray = (ByteArray) session.load(ByteArray.class, new Long(copiedByteArray.getId()));
assertNotSame(retrievedByteArray.getByteBlocks(), copiedByteArray.getByteBlocks());
- for (int i=0; i<retrievedByteArray.getByteBlocks().size(); i++) {
+
+ for (int i = 0; i < retrievedByteArray.getByteBlocks().size(); i++) {
byte[] retrievedBytes = (byte[]) retrievedByteArray.getByteBlocks().get(i);
byte[] copiedBytes = (byte[]) copiedByteArray.getByteBlocks().get(i);
+
assertNotSame(retrievedBytes, copiedBytes);
assertTrue(Arrays.equals(retrievedBytes, copiedBytes));
}
+
+ session.delete(copiedByteArray);
+ session.delete(retrievedByteArray);
}
public void testNullByteArray() {
byte[] bytes = null;
ByteArray byteArray = new ByteArray(bytes);
session.save(byteArray);
+
newTransaction();
- ByteArray retrievedByteArray = (ByteArray) session.load(ByteArray.class, new Long(byteArray.getId()));
+ ByteArray retrievedByteArray = (ByteArray) session.load(ByteArray.class, new Long(
+ byteArray.getId()));
assertNull(retrievedByteArray.getBytes());
+
+ session.delete(retrievedByteArray);
}
private static byte[] getMultipleBlockBytes() {
- String text = "muchos bytes"; // (10 bytes)
- for (int i=0; i<8; i++) text+=text;
- // now text should be 2560 bytes
- return text.getBytes();
+ byte[] bytes = new byte[2560];
+ Arrays.fill(bytes, 0, 512, (byte) 67);
+ Arrays.fill(bytes, 512, 1024, (byte) 65);
+ Arrays.fill(bytes, 1024, 1536, (byte) 71);
+ Arrays.fill(bytes, 1536, 2048, (byte) 70);
+ Arrays.fill(bytes, 2048, 2560, (byte) 66);
+ return bytes;
}
}
Modified: jbpm3/branches/jbpm-3.2.5-soa/modules/core/src/test/java/org/jbpm/job/executor/JobExecutorDbTest.java
===================================================================
--- jbpm3/branches/jbpm-3.2.5-soa/modules/core/src/test/java/org/jbpm/job/executor/JobExecutorDbTest.java 2009-05-28 12:59:30 UTC (rev 4935)
+++ jbpm3/branches/jbpm-3.2.5-soa/modules/core/src/test/java/org/jbpm/job/executor/JobExecutorDbTest.java 2009-05-28 15:17:35 UTC (rev 4936)
@@ -23,79 +23,83 @@
protected void setUp() throws Exception {
super.setUp();
- deployProcess();
getJbpmConfiguration().getJobExecutor().setNbrOfThreads(4);
}
protected void tearDown() throws Exception {
getJbpmConfiguration().getJobExecutor().setNbrOfThreads(1);
- deleteProcess();
super.tearDown();
}
public void testJobExecutor() {
- launchProcesses();
- processJobs(timeout);
- assertEquals(createExpectedResults(), collectedResults);
+ deployProcessDefinition();
+ try {
+ startProcessInstances();
+ processJobs(timeout);
+ assertEquals(createExpectedResults(), collectedResults);
+ }
+ finally {
+ deleteProcessDefinition();
+ }
}
- void deployProcess() {
+ void deployProcessDefinition() {
ProcessDefinition processDefinition = ProcessDefinition.parseXmlString("<process-definition name='bulk messages'>"
+ " <start-state>"
+ " <transition to='a' />"
+ " </start-state>"
+ " <node name='a' async='true'>"
- + " <action class='"
- + AutomaticActivity.class.getName()
- + "' />"
- + " <transition to='b' />"
- + " </node>"
- + " <node name='b' async='true'>"
- + " <event type='node-enter'>"
- + " <action name='X' async='true' class='"
- + AsyncAction.class.getName()
- + "' />"
- + " </event>"
- + " <action class='"
- + AutomaticActivity.class.getName()
- + "' />"
- + " <transition to='c' />"
- + " </node>"
- + " <node name='c' async='true'>"
- + " <action class='"
- + AutomaticActivity.class.getName()
- + "' />"
- + " <transition to='d'>"
- + " <action name='Y' async='true' class='"
- + AsyncAction.class.getName()
- + "' />"
- + " </transition>"
- + " </node>"
- + " <node name='d' async='true'>"
- + " <action class='"
- + AutomaticActivity.class.getName()
- + "' />"
- + " <transition to='e' />"
- + " <event type='node-leave'>"
- + " <action name='Z' async='true' class='"
- + AsyncAction.class.getName()
- + "' />"
- + " </event>"
- + " </node>"
- + " <node name='e' async='true'>"
- + " <action class='"
- + AutomaticActivity.class.getName()
- + "' />"
- + " <transition to='end' />"
- + " </node>"
- + " <end-state name='end'/>"
- + "</process-definition>");
+ + " <action class='" +
+ AutomaticActivity.class.getName() +
+ "' />" +
+ " <transition to='b' />" +
+ " </node>" +
+ " <node name='b' async='true'>" +
+ " <event type='node-enter'>" +
+ " <action name='X' async='true' class='" +
+ AsyncAction.class.getName() +
+ "' />" +
+ " </event>" +
+ " <action class='" +
+ AutomaticActivity.class.getName() +
+ "' />" +
+ " <transition to='c' />" +
+ " </node>" +
+ " <node name='c' async='true'>" +
+ " <action class='" +
+ AutomaticActivity.class.getName() +
+ "' />" +
+ " <transition to='d'>" +
+ " <action name='Y' async='true' class='" +
+ AsyncAction.class.getName() +
+ "' />" +
+ " </transition>" +
+ " </node>" +
+ " <node name='d' async='true'>" +
+ " <action class='" +
+ AutomaticActivity.class.getName() +
+ "' />" +
+ " <transition to='e' />" +
+ " <event type='node-leave'>" +
+ " <action name='Z' async='true' class='" +
+ AsyncAction.class.getName() +
+ "' />" +
+ " </event>" +
+ " </node>" +
+ " <node name='e' async='true'>" +
+ " <action class='" +
+ AutomaticActivity.class.getName() +
+ "' />" +
+ " <transition to='end' />" +
+ " </node>" +
+ " <end-state name='end'/>" +
+ "</process-definition>");
jbpmContext.deployProcessDefinition(processDefinition);
newTransaction();
}
- void launchProcesses() {
+ void startProcessInstances() {
for (int i = 0; i < nbrOfConcurrentProcessExecutions; i++) {
ProcessInstance processInstance = jbpmContext.newProcessInstanceForUpdate("bulk messages");
processInstance.signal();
@@ -120,7 +124,7 @@
return expectedResults;
}
- void deleteProcess() {
+ void deleteProcessDefinition() {
ProcessDefinition processDefinition = graphSession.findLatestProcessDefinition("bulk messages");
graphSession.deleteProcessDefinition(processDefinition);
}
Modified: jbpm3/branches/jbpm-3.2.5-soa/modules/core/src/test/java/org/jbpm/logging/exe/LoggingConfigDbTest.java
===================================================================
--- jbpm3/branches/jbpm-3.2.5-soa/modules/core/src/test/java/org/jbpm/logging/exe/LoggingConfigDbTest.java 2009-05-28 12:59:30 UTC (rev 4935)
+++ jbpm3/branches/jbpm-3.2.5-soa/modules/core/src/test/java/org/jbpm/logging/exe/LoggingConfigDbTest.java 2009-05-28 15:17:35 UTC (rev 4936)
@@ -1,11 +1,13 @@
package org.jbpm.logging.exe;
-import org.hibernate.Query;
+import java.util.List;
+
import org.jbpm.JbpmConfiguration;
import org.jbpm.db.AbstractDbTestCase;
import org.jbpm.graph.def.ProcessDefinition;
import org.jbpm.graph.exe.ProcessInstance;
+import org.jbpm.logging.log.ProcessLog;
public class LoggingConfigDbTest extends AbstractDbTestCase {
@@ -22,12 +24,15 @@
}
public void testLoggingconfiguration() {
- jbpmContext.deployProcessDefinition(new ProcessDefinition("logging"));
+ ProcessDefinition processDefinition = new ProcessDefinition("logging");
+ jbpmContext.deployProcessDefinition(processDefinition);
ProcessInstance processInstance = jbpmContext.newProcessInstance("logging");
processInstance.getContextInstance().setVariable("a", "1");
+
newTransaction();
+ List logs = session.createCriteria(ProcessLog.class).list();
+ assertEquals(0, logs.size());
- Query query = session.createQuery("from org.jbpm.logging.log.ProcessLog");
- assertEquals(0, query.list().size());
+ graphSession.deleteProcessDefinition(processDefinition.getId());
}
}
Modified: jbpm3/branches/jbpm-3.2.5-soa/modules/core/src/test/java/org/jbpm/perf/TasklistEagerLoadingTest.java
===================================================================
--- jbpm3/branches/jbpm-3.2.5-soa/modules/core/src/test/java/org/jbpm/perf/TasklistEagerLoadingTest.java 2009-05-28 12:59:30 UTC (rev 4935)
+++ jbpm3/branches/jbpm-3.2.5-soa/modules/core/src/test/java/org/jbpm/perf/TasklistEagerLoadingTest.java 2009-05-28 15:17:35 UTC (rev 4936)
@@ -1,6 +1,9 @@
package org.jbpm.perf;
+import java.io.Serializable;
import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Iterator;
import java.util.List;
import org.jbpm.db.AbstractDbTestCase;
@@ -8,32 +11,54 @@
public class TasklistEagerLoadingTest extends AbstractDbTestCase {
+ private List taskInstanceIds = new ArrayList();
+
public void testTasklistEagerLoading() {
- for (int i=0; i<20; i++) {
- TaskInstance taskInstance = new TaskInstance("task "+i);
+ for (int i = 0; i < 20; i++) {
+ TaskInstance taskInstance = new TaskInstance("task " + i);
taskInstance.setActorId("johndoe");
- session.save(taskInstance);
+ save(taskInstance);
}
newTransaction();
-
- assertEquals(20, jbpmContext.getTaskList("johndoe").size());
+ try {
+ assertEquals(20, jbpmContext.getTaskList("johndoe").size());
+ }
+ finally {
+ deleteTaskInstances();
+ }
}
public void testPooledTasklistEagerLoading() {
- for (int i=0; i<20; i++) {
- TaskInstance taskInstance = new TaskInstance("group task "+i);
- taskInstance.setPooledActors(new String[]{"group"+i});
- session.save(taskInstance);
+ for (int i = 0; i < 20; i++) {
+ TaskInstance taskInstance = new TaskInstance("group task " + i);
+ taskInstance.setPooledActors(new String[] { "group" + i });
+ save(taskInstance);
}
- for (int i=0; i<20; i++) {
- TaskInstance taskInstance = new TaskInstance("task "+i);
- taskInstance.setPooledActors(new String[]{"johndoe", "bachelors", "partyanimals", "wildwomen"});
- session.save(taskInstance);
+ for (int i = 0; i < 20; i++) {
+ TaskInstance taskInstance = new TaskInstance("task " + i);
+ taskInstance.setPooledActors(new String[] { "johndoe", "bachelors", "partyanimals",
+ "wildwomen" });
+ save(taskInstance);
}
newTransaction();
-
- List actorIds = new ArrayList();
- actorIds.add("johndoe");
- assertEquals(20, jbpmContext.getGroupTaskList(actorIds).size());
+ try {
+ assertEquals(20, jbpmContext.getGroupTaskList(Collections.singletonList("johndoe")).size());
+ }
+ finally {
+ deleteTaskInstances();
+ }
}
+
+ private void save(TaskInstance taskInstance) {
+ Serializable id = session.save(taskInstance);
+ taskInstanceIds.add(id);
+ }
+
+ private void deleteTaskInstances() {
+ for (Iterator i = taskInstanceIds.iterator(); i.hasNext();) {
+ Serializable id = (Serializable) i.next();
+ Object taskInstance = session.load(TaskInstance.class, id);
+ session.delete(taskInstance);
+ }
+ }
}
Deleted: jbpm3/branches/jbpm-3.2.5-soa/modules/core/src/test/java/org/jbpm/seam/AsyncAction.java
===================================================================
--- jbpm3/branches/jbpm-3.2.5-soa/modules/core/src/test/java/org/jbpm/seam/AsyncAction.java 2009-05-28 12:59:30 UTC (rev 4935)
+++ jbpm3/branches/jbpm-3.2.5-soa/modules/core/src/test/java/org/jbpm/seam/AsyncAction.java 2009-05-28 15:17:35 UTC (rev 4936)
@@ -1,31 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2005, JBoss Inc., and individual contributors as indicated
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jbpm.seam;
-
-import org.jbpm.graph.def.ActionHandler;
-import org.jbpm.graph.exe.ExecutionContext;
-
-public class AsyncAction implements ActionHandler {
- public void execute(ExecutionContext executionContext) throws Exception {
- JobExecutorCustomizationTest.jobEvents.add("execute action");
- }
-}
\ No newline at end of file
Modified: jbpm3/branches/jbpm-3.2.5-soa/modules/core/src/test/java/org/jbpm/seam/JobExecutorCustomizationTest.java
===================================================================
--- jbpm3/branches/jbpm-3.2.5-soa/modules/core/src/test/java/org/jbpm/seam/JobExecutorCustomizationTest.java 2009-05-28 12:59:30 UTC (rev 4935)
+++ jbpm3/branches/jbpm-3.2.5-soa/modules/core/src/test/java/org/jbpm/seam/JobExecutorCustomizationTest.java 2009-05-28 15:17:35 UTC (rev 4936)
@@ -1,15 +1,18 @@
package org.jbpm.seam;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.List;
import org.jbpm.db.AbstractDbTestCase;
+import org.jbpm.graph.def.ActionHandler;
import org.jbpm.graph.def.ProcessDefinition;
+import org.jbpm.graph.exe.ExecutionContext;
import org.jbpm.job.executor.JobExecutor;
public class JobExecutorCustomizationTest extends AbstractDbTestCase {
- public static List jobEvents = new ArrayList();
+ static List jobEvents = new ArrayList();
protected String getJbpmTestConfig() {
return "org/jbpm/seam/custom.job.executor.jbpm.cfg.xml";
@@ -24,46 +27,36 @@
JobExecutor jobExecutor = getJbpmConfiguration().getJobExecutor();
assertEquals(CustomJobExecutor.class, jobExecutor.getClass());
- ProcessDefinition processDefinition = ProcessDefinition.parseXmlString("<process-definition name='customjobexecution' initial='start'>"
- + " <node name='start'>"
- + " <transition to='end'>"
- + " <action async='true' class='"
- + AsyncAction.class.getName()
- + "' />"
- + " </transition>"
- + " </node>"
- + " <state name='end' />"
- + "</process-definition>");
+ ProcessDefinition processDefinition = ProcessDefinition.parseXmlString("<process-definition name='customjobexecution' initial='start'>" +
+ " <node name='start'>" +
+ " <transition to='end'>" +
+ " <action async='true' class='" +
+ AsyncAction.class.getName() +
+ "' />" +
+ " </transition>" +
+ " </node>" +
+ " <state name='end' />" +
+ "</process-definition>");
jbpmContext.deployProcessDefinition(processDefinition);
- long processDefinitionId = processDefinition.getId();
- try {
- newTransaction();
-
+ newTransaction();
+ try {
jbpmContext.newProcessInstanceForUpdate("customjobexecution");
- newTransaction();
-
- jobExecutor.start();
- try {
- waitForJobs(20000);
- }
- finally {
- jobExecutor.stop();
- }
-
+ processJobs(20 * 1000);
+ List expectedJobEvents = Arrays.asList(new String[] { "before", "execute action", "after" });
+ assertEquals(expectedJobEvents, jobEvents);
}
finally {
- newTransaction();
-
- graphSession.deleteProcessDefinition(processDefinitionId);
+ graphSession.deleteProcessDefinition(processDefinition.getId());
}
+ }
- List expectedJobEvents = new ArrayList();
- expectedJobEvents.add("before");
- expectedJobEvents.add("execute action");
- expectedJobEvents.add("after");
+ public static class AsyncAction implements ActionHandler {
+ private static final long serialVersionUID = 1L;
- assertEquals(expectedJobEvents, jobEvents);
+ public void execute(ExecutionContext executionContext) throws Exception {
+ jobEvents.add("execute action");
+ }
}
}
Modified: jbpm3/branches/jbpm-3.2.5-soa/modules/core/src/test/java/org/jbpm/taskmgmt/exe/TaskInstanceDbTest.java
===================================================================
--- jbpm3/branches/jbpm-3.2.5-soa/modules/core/src/test/java/org/jbpm/taskmgmt/exe/TaskInstanceDbTest.java 2009-05-28 12:59:30 UTC (rev 4935)
+++ jbpm3/branches/jbpm-3.2.5-soa/modules/core/src/test/java/org/jbpm/taskmgmt/exe/TaskInstanceDbTest.java 2009-05-28 15:17:35 UTC (rev 4936)
@@ -36,286 +36,252 @@
public class TaskInstanceDbTest extends AbstractDbTestCase {
- public void testTaskInstanceUnrelatedToAProcess()
- {
+ public void testTaskInstanceUnrelatedToAProcess() {
TaskInstance taskInstance = new TaskInstance("do laundry", "someoneelse");
- session.save(taskInstance);
- long id = taskInstance.getId();
-
+ Serializable id = session.save(taskInstance);
newTransaction();
- taskInstance = (TaskInstance)session.load(TaskInstance.class, new Long(id));
+ taskInstance = (TaskInstance) session.load(TaskInstance.class, id);
assertNotNull(taskInstance);
assertEquals("do laundry", taskInstance.getName());
assertEquals("someoneelse", taskInstance.getActorId());
+
+ session.delete(taskInstance);
}
public void testTaskInstanceBasicLifeCycle() {
- ProcessDefinition processDefinition = ProcessDefinition.parseXmlString(
- "<process-definition>" +
- " <start-state>" +
- " <transition to='a' />" +
- " </start-state>" +
- " <task-node name='a'>" +
- " <task name='clean ceiling' />" +
- " <transition to='end' />" +
- " </task-node>" +
- " <end-state name='end' />" +
- "</process-definition>"
- );
+ ProcessDefinition processDefinition = ProcessDefinition.parseXmlString("<process-definition>"
+ + " <start-state>"
+ + " <transition to='a' />"
+ + " </start-state>"
+ + " <task-node name='a'>"
+ + " <task name='clean ceiling' />"
+ + " <transition to='end' />"
+ + " </task-node>"
+ + " <end-state name='end' />"
+ + "</process-definition>");
processDefinition = saveAndReload(processDefinition);
- try
- {
+ try {
ProcessInstance processInstance = new ProcessInstance(processDefinition);
processInstance.signal();
-
+
processInstance = saveAndReload(processInstance);
long tokenId = processInstance.getRootToken().getId();
List taskInstances = taskMgmtSession.findTaskInstancesByToken(tokenId);
assertEquals(1, taskInstances.size());
+
TaskInstance taskInstance = (TaskInstance) taskInstances.get(0);
assertFalse(taskInstance.hasEnded());
assertEquals(tokenId, taskInstance.getToken().getId());
// do some updates
taskInstance.end();
-
+
processInstance = saveAndReload(processInstance);
-
taskInstance = taskMgmtSession.loadTaskInstance(taskInstance.getId());
assertTrue(taskInstance.hasEnded());
}
- finally
- {
+ finally {
jbpmContext.getGraphSession().deleteProcessDefinition(processDefinition.getId());
}
-
+
}
public void testTaskName() {
- ProcessDefinition processDefinition = ProcessDefinition.parseXmlString(
- "<process-definition>" +
- " <start-state>" +
- " <transition to='a' />" +
- " </start-state>" +
- " <task-node name='a'>" +
- " <task name='clean ceiling' />" +
- " <transition to='end' />" +
- " </task-node>" +
- " <end-state name='end' />" +
- "</process-definition>"
- );
+ ProcessDefinition processDefinition = ProcessDefinition.parseXmlString("<process-definition>"
+ + " <start-state>"
+ + " <transition to='a' />"
+ + " </start-state>"
+ + " <task-node name='a'>"
+ + " <task name='clean ceiling' />"
+ + " <transition to='end' />"
+ + " </task-node>"
+ + " <end-state name='end' />"
+ + "</process-definition>");
processDefinition = saveAndReload(processDefinition);
- try
- {
+ try {
ProcessInstance processInstance = new ProcessInstance(processDefinition);
processInstance.signal();
-
- processInstance = saveAndReload(processInstance);
- long tokenId = processInstance.getRootToken().getId();
- List taskInstances = taskMgmtSession.findTaskInstancesByToken(tokenId);
+ processInstance = saveAndReload(processInstance);
+ List taskInstances = taskMgmtSession.findTaskInstancesByToken(processInstance.getRootToken()
+ .getId());
assertEquals(1, taskInstances.size());
+
TaskInstance taskInstance = (TaskInstance) taskInstances.get(0);
assertFalse(taskInstance.hasEnded());
assertEquals("clean ceiling", taskInstance.getName());
assertEquals("clean ceiling", taskInstance.getTask().getName());
// do some updates
taskInstance.setName("clean ceiling thoroughly");
-
+
processInstance = saveAndReload(processInstance);
taskInstance = taskMgmtSession.loadTaskInstance(taskInstance.getId());
-
assertEquals("clean ceiling thoroughly", taskInstance.getName());
assertEquals("clean ceiling", taskInstance.getTask().getName());
}
- finally
- {
+ finally {
jbpmContext.getGraphSession().deleteProcessDefinition(processDefinition.getId());
}
}
-
+
public void testTaskComments() {
- ProcessDefinition processDefinition = ProcessDefinition.parseXmlString(
- "<process-definition>" +
- " <start-state>" +
- " <transition to='a' />" +
- " </start-state>" +
- " <task-node name='a'>" +
- " <task name='clean ceiling' />" +
- " <transition to='end' />" +
- " </task-node>" +
- " <end-state name='end' />" +
- "</process-definition>"
- );
+ ProcessDefinition processDefinition = ProcessDefinition.parseXmlString("<process-definition>"
+ + " <start-state>"
+ + " <transition to='a' />"
+ + " </start-state>"
+ + " <task-node name='a'>"
+ + " <task name='clean ceiling' />"
+ + " <transition to='end' />"
+ + " </task-node>"
+ + " <end-state name='end' />"
+ + "</process-definition>");
processDefinition = saveAndReload(processDefinition);
- try
- {
+ try {
ProcessInstance processInstance = new ProcessInstance(processDefinition);
processInstance.signal();
-
- processInstance = saveAndReload(processInstance);
- long tokenId = processInstance.getRootToken().getId();
- List taskInstances = taskMgmtSession.findTaskInstancesByToken(tokenId);
+ processInstance = saveAndReload(processInstance);
+ List taskInstances = taskMgmtSession.findTaskInstancesByToken(processInstance.getRootToken()
+ .getId());
assertEquals(1, taskInstances.size());
TaskInstance taskInstance = (TaskInstance) taskInstances.get(0);
taskInstance.addComment("please hurry!");
-
+
processInstance = saveAndReload(processInstance);
taskInstance = taskMgmtSession.loadTaskInstance(taskInstance.getId());
-
+
List comments = taskInstance.getComments();
assertEquals(1, comments.size());
-
- Comment comment = (Comment) comments.get(0);
+
+ Comment comment = (Comment) comments.get(0);
assertEquals("please hurry!", comment.getMessage());
assertSame(taskInstance, comment.getTaskInstance());
}
- finally
- {
+ finally {
jbpmContext.getGraphSession().deleteProcessDefinition(processDefinition.getId());
}
}
-
+
public void testBlockingTask() {
- ProcessDefinition processDefinition = ProcessDefinition.parseXmlString(
- "<process-definition>" +
- " <start-state>" +
- " <transition to='a' />" +
- " </start-state>" +
- " <task-node name='a'>" +
- " <task name='laundry' blocking='true' />" +
- " <transition to='b' />" +
- " </task-node>" +
- " <state name='b' />" +
- "</process-definition>"
- );
+ ProcessDefinition processDefinition = ProcessDefinition.parseXmlString("<process-definition>"
+ + " <start-state>"
+ + " <transition to='a' />"
+ + " </start-state>"
+ + " <task-node name='a'>"
+ + " <task name='laundry' blocking='true' />"
+ + " <transition to='b' />"
+ + " </task-node>"
+ + " <state name='b' />"
+ + "</process-definition>");
processDefinition = saveAndReload(processDefinition);
- try
- {
+ try {
ProcessInstance processInstance = new ProcessInstance(processDefinition);
Token token = processInstance.getRootToken();
- processInstance.signal();
+ token.signal();
assertEquals("a", token.getNode().getName());
+
processInstance = saveAndReload(processInstance);
try {
processInstance.signal();
fail("expected exception");
- } catch (IllegalStateException e) {
+ }
+ catch (IllegalStateException e) {
// OK
}
}
- finally
- {
+ finally {
jbpmContext.getGraphSession().deleteProcessDefinition(processDefinition.getId());
}
}
public void testConditionalTasksOne() {
- ProcessDefinition processDefinition = ProcessDefinition.parseXmlString(
- "<process-definition>" +
- " <start-state>" +
- " <transition to='release' />" +
- " </start-state>" +
- " <task-node name='release'>" +
- " <task name='updateWebsite' condition='#{user.admin}' />" +
- " <task name='addNewsItem' />" +
- " <task name='publishRelease' condition='#{user.releaseManager}' />" +
- " </task-node>" +
- "</process-definition>"
- );
+ ProcessDefinition processDefinition = ProcessDefinition.parseXmlString("<process-definition>"
+ + " <start-state>"
+ + " <transition to='release' />"
+ + " </start-state>"
+ + " <task-node name='release'>"
+ + " <task name='updateWebsite' condition='#{user.admin}' />"
+ + " <task name='addNewsItem' />"
+ + " <task name='publishRelease' condition='#{user.releaseManager}' />"
+ + " </task-node>"
+ + "</process-definition>");
processDefinition = saveAndReload(processDefinition);
- try
- {
+ try {
ProcessInstance processInstance = new ProcessInstance(processDefinition);
processInstance.getContextInstance().setVariable("user", new User(true, false));
processInstance.signal();
processInstance = saveAndReload(processInstance);
Collection taskInstances = processInstance.getTaskMgmtInstance().getTaskInstances();
- Set createdTasks = new HashSet();
- Iterator iter = taskInstances.iterator();
- while (iter.hasNext()) {
- TaskInstance taskInstance = (TaskInstance) iter.next();
- createdTasks.add(taskInstance.getName());
- }
- Set expectedTasks = new HashSet();
- expectedTasks.add("updateWebsite");
- expectedTasks.add("addNewsItem");
-
- assertEquals(expectedTasks, createdTasks);
+ Set taskNames = new HashSet();
+ for (Iterator i = taskInstances.iterator(); i.hasNext();) {
+ TaskInstance taskInstance = (TaskInstance) i.next();
+ taskNames.add(taskInstance.getName());
+ }
+ assertEquals(2, taskNames.size());
+ assert taskNames.contains("updateWebsite") : taskNames;
+ assert taskNames.contains("addNewsItem") : taskNames;
}
- finally
- {
+ finally {
jbpmContext.getGraphSession().deleteProcessDefinition(processDefinition.getId());
}
}
public void testConditionalTasksTwo() {
- ProcessDefinition processDefinition = ProcessDefinition.parseXmlString(
- "<process-definition>" +
- " <start-state>" +
- " <transition to='release' />" +
- " </start-state>" +
- " <task-node name='release'>" +
- " <task name='updateWebsite' condition='#{user.admin}' />" +
- " <task name='addNewsItem' />" +
- " <task name='publishRelease' condition='#{user.releaseManager}' />" +
- " </task-node>" +
- "</process-definition>"
- );
+ ProcessDefinition processDefinition = ProcessDefinition.parseXmlString("<process-definition>"
+ + " <start-state>"
+ + " <transition to='release' />"
+ + " </start-state>"
+ + " <task-node name='release'>"
+ + " <task name='updateWebsite' condition='#{user.admin}' />"
+ + " <task name='addNewsItem' />"
+ + " <task name='publishRelease' condition='#{user.releaseManager}' />"
+ + " </task-node>"
+ + "</process-definition>");
processDefinition = saveAndReload(processDefinition);
- try
- {
+ try {
ProcessInstance processInstance = new ProcessInstance(processDefinition);
processInstance.getContextInstance().setVariable("user", new User(false, true));
processInstance.signal();
processInstance = saveAndReload(processInstance);
Collection taskInstances = processInstance.getTaskMgmtInstance().getTaskInstances();
- Set createdTasks = new HashSet();
- Iterator iter = taskInstances.iterator();
- while (iter.hasNext()) {
- TaskInstance taskInstance = (TaskInstance) iter.next();
- createdTasks.add(taskInstance.getName());
+ Set taskNames = new HashSet();
+ for (Iterator i = taskInstances.iterator(); i.hasNext();) {
+ TaskInstance taskInstance = (TaskInstance) i.next();
+ taskNames.add(taskInstance.getName());
}
- Set expectedTasks = new HashSet();
- expectedTasks.add("addNewsItem");
- expectedTasks.add("publishRelease");
-
- assertEquals(expectedTasks, createdTasks);
+ assertEquals(2, taskNames.size());
+ assert taskNames.contains("addNewsItem") : taskNames;
+ assert taskNames.contains("publishRelease") : taskNames;
}
- finally
- {
+ finally {
jbpmContext.getGraphSession().deleteProcessDefinition(processDefinition.getId());
}
}
- public static class User implements Serializable
- {
- private static final long serialVersionUID = 1L;
+ public static class User implements Serializable {
boolean isAdmin;
boolean isReleaseManager;
- public User(boolean isAdmin, boolean isReleaseManager)
- {
+ private static final long serialVersionUID = 1L;
+
+ public User(boolean isAdmin, boolean isReleaseManager) {
this.isAdmin = isAdmin;
this.isReleaseManager = isReleaseManager;
}
- public boolean isAdmin()
- {
+ public boolean isAdmin() {
return isAdmin;
}
- public boolean isReleaseManager()
- {
+ public boolean isReleaseManager() {
return isReleaseManager;
}
}
Modified: jbpm3/branches/jbpm-3.2.5-soa/modules/core/src/test/java/org/jbpm/taskmgmt/log/TaskLogDbTest.java
===================================================================
--- jbpm3/branches/jbpm-3.2.5-soa/modules/core/src/test/java/org/jbpm/taskmgmt/log/TaskLogDbTest.java 2009-05-28 12:59:30 UTC (rev 4935)
+++ jbpm3/branches/jbpm-3.2.5-soa/modules/core/src/test/java/org/jbpm/taskmgmt/log/TaskLogDbTest.java 2009-05-28 15:17:35 UTC (rev 4936)
@@ -24,66 +24,54 @@
import org.jbpm.db.AbstractDbTestCase;
import org.jbpm.taskmgmt.exe.TaskInstance;
-public class TaskLogDbTest extends AbstractDbTestCase
-{
+public class TaskLogDbTest extends AbstractDbTestCase {
- TaskInstance taskInstance = null;
+ TaskInstance taskInstance;
- protected void setUp() throws Exception
- {
+ protected void setUp() throws Exception {
super.setUp();
taskInstance = new TaskInstance();
session.save(taskInstance);
}
- protected void tearDown() throws Exception
- {
- taskInstance = null;
+ protected void tearDown() throws Exception {
+ session.delete(taskInstance);
super.tearDown();
}
- public void testTaskCreateLog()
- {
+ public void testTaskCreateLog() {
TaskCreateLog taskLog = new TaskCreateLog(taskInstance, "someone else");
session.save(taskLog);
newTransaction();
+ taskLog = (TaskCreateLog) session.load(TaskCreateLog.class, new Long(taskLog.getId()));
+ assertEquals(taskInstance.getId(), (taskInstance = taskLog.getTaskInstance()).getId());
+ assertEquals("someone else", taskLog.getTaskActorId());
- taskLog = (TaskCreateLog)session.load(TaskCreateLog.class, new Long(taskLog.getId()));
- assertNotNull(taskLog);
- assertNotNull(taskLog.getTaskInstance());
- assertEquals("someone else", (taskLog.getTaskActorId()));
-
session.delete(taskLog);
}
- public void testTaskAssignLog()
- {
+ public void testTaskAssignLog() {
TaskAssignLog taskLog = new TaskAssignLog(taskInstance, "me", "toyou");
session.save(taskLog);
newTransaction();
+ taskLog = (TaskAssignLog) session.load(TaskAssignLog.class, new Long(taskLog.getId()));
+ assertEquals(taskInstance.getId(), (taskInstance = taskLog.getTaskInstance()).getId());
+ assertEquals("me", taskLog.getTaskOldActorId());
+ assertEquals("toyou", taskLog.getTaskNewActorId());
- taskLog = (TaskAssignLog)session.load(TaskAssignLog.class, new Long(taskLog.getId()));
- assertNotNull(taskLog);
- assertNotNull(taskLog.getTaskInstance());
- assertEquals("me", (taskLog.getTaskOldActorId()));
- assertEquals("toyou", (taskLog.getTaskNewActorId()));
-
session.delete(taskLog);
-}
+ }
- public void testTaskEndLog()
- {
+ public void testTaskEndLog() {
TaskEndLog taskLog = new TaskEndLog(taskInstance);
session.save(taskLog);
newTransaction();
+ taskLog = (TaskEndLog) session.load(TaskEndLog.class, new Long(taskLog.getId()));
+ assertEquals(taskInstance.getId(), (taskInstance = taskLog.getTaskInstance()).getId());
- taskLog = (TaskEndLog)session.load(TaskEndLog.class, new Long(taskLog.getId()));
- assertNotNull(taskLog);
- assertNotNull(taskLog.getTaskInstance());
-
session.delete(taskLog);
}
}
More information about the jbpm-commits
mailing list