JBoss JBPM SVN: r6951 - in jbpm3/branches/jbpm-3.2-soa/core/src: test/java/org/jbpm and 1 other directories.
by do-not-reply@jboss.org
Author: marco.rietveld
Date: 2011-05-30 07:44:59 -0400 (Mon, 30 May 2011)
New Revision: 6951
Added:
jbpm3/branches/jbpm-3.2-soa/core/src/test/java/org/jbpm/jbpm3218/
jbpm3/branches/jbpm-3.2-soa/core/src/test/java/org/jbpm/jbpm3218/JBPM3218Test.java
Modified:
jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/command/ExecuteJobsCommand.java
Log:
JBPM-3218: ExecuteJobsCommand uses a hardcoded number of retries (instead of injected value/configuration value)
Modified: jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/command/ExecuteJobsCommand.java
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/command/ExecuteJobsCommand.java 2011-05-23 15:29:26 UTC (rev 6950)
+++ jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/command/ExecuteJobsCommand.java 2011-05-30 11:44:59 UTC (rev 6951)
@@ -78,11 +78,7 @@
job.setLockOwner(lockOwner);
job.setLockTime(lockTime);
// has job failed previously?
- if (job.getException() == null) {
- // initialize retry count
- job.setRetries(3);
- }
- else {
+ if (job.getException() != null) {
// decrease retry count
int retries = job.getRetries() - 1;
job.setRetries(retries);
Added: jbpm3/branches/jbpm-3.2-soa/core/src/test/java/org/jbpm/jbpm3218/JBPM3218Test.java
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/core/src/test/java/org/jbpm/jbpm3218/JBPM3218Test.java (rev 0)
+++ jbpm3/branches/jbpm-3.2-soa/core/src/test/java/org/jbpm/jbpm3218/JBPM3218Test.java 2011-05-30 11:44:59 UTC (rev 6951)
@@ -0,0 +1,90 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2011, 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.jbpm3218;
+
+import java.text.SimpleDateFormat;
+import java.util.Calendar;
+import java.util.Date;
+
+import org.jbpm.JbpmConfiguration.Configs;
+import org.jbpm.JbpmContext;
+import org.jbpm.command.CommandService;
+import org.jbpm.command.ExecuteJobsCommand;
+import org.jbpm.command.impl.CommandServiceImpl;
+import org.jbpm.db.AbstractDbTestCase;
+import org.jbpm.graph.def.ProcessDefinition;
+import org.jbpm.graph.exe.ProcessInstance;
+import org.jbpm.job.Timer;
+
+/**
+ * ExecuteJobsCommand uses a hardcoded number of retries (instead of injected jbpm.job.retries value)
+ *
+ * @see <a href="https://jira.jboss.org/jira/browse/JBPM-3218">JBPM-3218</a>
+ */
+public class JBPM3218Test extends AbstractDbTestCase {
+
+ private SimpleDateFormat dateFormat = new SimpleDateFormat("dd-MM-yy_HH:mm:ss");
+ private CommandService commandService = new CommandServiceImpl(getJbpmConfiguration());
+
+ protected void setUp() throws Exception {
+ super.setUp();
+
+ ProcessDefinition processDefinition = new ProcessDefinition(getName());
+ deployProcessDefinition(processDefinition);
+ }
+
+ public void testStartDate() {
+ ProcessInstance processInstance = jbpmContext.newProcessInstanceForUpdate(getName());
+
+ // Create and persist timer..
+ Timer timer = new Timer(processInstance.getRootToken());
+ timer.setName("jbpm3218test:" + dateFormat.format(new Date()));
+ timer.setDueDate(getOneHourAgo());
+ // Force retry handling
+ timer.setException("simulated Exception");
+ // Withouth repeat, the job is not available to retrieve after execution
+ timer.setRepeat("1 week");
+ jbpmContext.getServices().getSchedulerService().createTimer(timer);
+ newTransaction();
+
+ ExecuteJobsCommand overdueJobsCommand = new ExecuteJobsCommand();
+ commandService.execute(overdueJobsCommand);
+
+ timer = jobSession.loadTimer(timer.getId());
+ int retries = timer.getRetries();
+
+ String retriesProperty = "jbpm.job.retries";
+ Integer configRetries = Configs.getInt(retriesProperty);
+ assertNotNull(retriesProperty + " could not be retrieved.", configRetries);
+ assertTrue("expected " + (configRetries-1) + " retries, not " + retries, retries == (configRetries-1));
+ }
+
+ private Date getOneHourAgo() {
+ Calendar calendar = Calendar.getInstance();
+ calendar.add(Calendar.HOUR, -1);
+ // databases such as mysql do not have millisecond precision
+ calendar.set(Calendar.MILLISECOND, 0);
+ Date oneHourAgo = calendar.getTime();
+ return oneHourAgo;
+ }
+
+}
Property changes on: jbpm3/branches/jbpm-3.2-soa/core/src/test/java/org/jbpm/jbpm3218/JBPM3218Test.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:eol-style
+ native
12 years, 11 months
JBoss JBPM SVN: r6950 - jbpm3/branches/jbpm-3.2-soa/userguide/src/main/docbook/en-US.
by do-not-reply@jboss.org
Author: marco.rietveld
Date: 2011-05-23 11:29:26 -0400 (Mon, 23 May 2011)
New Revision: 6950
Modified:
jbpm3/branches/jbpm-3.2-soa/userguide/src/main/docbook/en-US/async.xml
Log:
JBPM-3216: added doc that default number retries is 3.
Modified: jbpm3/branches/jbpm-3.2-soa/userguide/src/main/docbook/en-US/async.xml
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/userguide/src/main/docbook/en-US/async.xml 2011-05-23 15:08:29 UTC (rev 6949)
+++ jbpm3/branches/jbpm-3.2-soa/userguide/src/main/docbook/en-US/async.xml 2011-05-23 15:29:26 UTC (rev 6950)
@@ -288,12 +288,13 @@
<listitem>
<para>
The interval that a job will wait between retries, if it
- fails during execution.
+ fails during execution. The default value for this
+ is 3 times.
</para>
<note>
<para>
The maximum number of retries is configured by
- <property>jbpm.job.retries</property>.
+ <property>jbpm.job.retries</property>.
</para>
</note>
</listitem>
12 years, 11 months
JBoss JBPM SVN: r6949 - jbpm3/branches/jbpm-3.2-soa/core/src/main/resources/org/jbpm.
by do-not-reply@jboss.org
Author: marco.rietveld
Date: 2011-05-23 11:08:29 -0400 (Mon, 23 May 2011)
New Revision: 6949
Modified:
jbpm3/branches/jbpm-3.2-soa/core/src/main/resources/org/jbpm/default.jbpm.cfg.xml
Log:
SOA-3076: changed jbpm.jobs.retries to 3.
Modified: jbpm3/branches/jbpm-3.2-soa/core/src/main/resources/org/jbpm/default.jbpm.cfg.xml
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/core/src/main/resources/org/jbpm/default.jbpm.cfg.xml 2011-05-20 11:37:37 UTC (rev 6948)
+++ jbpm3/branches/jbpm-3.2-soa/core/src/main/resources/org/jbpm/default.jbpm.cfg.xml 2011-05-23 15:08:29 UTC (rev 6949)
@@ -127,5 +127,5 @@
</bean>
<!-- job retry count -->
- <int name="jbpm.job.retries" value="10" />
+ <int name="jbpm.job.retries" value="3" />
</jbpm-configuration>
12 years, 11 months
JBoss JBPM SVN: r6946 - jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/db.
by do-not-reply@jboss.org
Author: marco.rietveld
Date: 2011-05-19 11:52:12 -0400 (Thu, 19 May 2011)
New Revision: 6946
Modified:
jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/db/AbstractDbTestCase.java
Log:
Second attempt at experiment failed, reverting to 6859.
Modified: jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/db/AbstractDbTestCase.java
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/db/AbstractDbTestCase.java 2011-05-19 15:46:55 UTC (rev 6945)
+++ jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/db/AbstractDbTestCase.java 2011-05-19 15:52:12 UTC (rev 6946)
@@ -21,11 +21,7 @@
*/
package org.jbpm.db;
-import java.lang.management.ManagementFactory;
-import java.lang.management.ThreadMXBean;
import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
@@ -35,6 +31,7 @@
import org.hibernate.cfg.Environment;
import org.hibernate.criterion.Projections;
import org.hibernate.criterion.Restrictions;
+
import org.jbpm.AbstractJbpmTestCase;
import org.jbpm.JbpmConfiguration;
import org.jbpm.JbpmContext;
@@ -208,10 +205,9 @@
}
}
- protected JobExecutor startJobExecutor() {
+ protected void startJobExecutor() {
jobExecutor = getJbpmConfiguration().getJobExecutor();
jobExecutor.start();
- return jobExecutor;
}
/**
@@ -264,73 +260,6 @@
}
}
- private long getUserTimeInMilliseconds( HashSet threadIdSet ) {
- ThreadMXBean bean = ManagementFactory.getThreadMXBean( );
- if ( ! bean.isThreadCpuTimeSupported( ) ) {
- return 0L;
- }
-
- long totalThreadTimeInNanoSeconds = 0;
- Object [] threadId = new Long[0];
- threadId = threadIdSet.toArray(threadId);
-
- for ( int i = 0; i < threadId.length; ++i ) {
- long threadTime = bean.getThreadUserTime( (Long) threadId[i] );
- if ( threadTime != -1 ) {
- totalThreadTimeInNanoSeconds += threadTime;
- }
- }
-
- return totalThreadTimeInNanoSeconds/1000000;
- }
-
- protected void newWaitForJobs(final long timeout, Map threadMap) {
-
- // Gather thread Id's
- Iterator threadMapIter = threadMap.values().iterator();
- HashSet threadIdSet = new HashSet();
- while(threadMapIter.hasNext()) {
- Thread thisThread = (Thread) threadMapIter.next();
- threadIdSet.add(thisThread.getId());
- }
-
- long waitPeriod = 500;
- for (int currentCount, previousCount = 0; (currentCount = getNbrOfJobsAvailable()) > 0;) {
-
- long elapsedTime = getUserTimeInMilliseconds(threadIdSet);
-
- if (elapsedTime > timeout) {
- fail("test execution exceeded threshold of " + timeout + " ms");
- }
-
- if (currentCount < previousCount) {
- long elapsedTimePerJob = (elapsedTime) / (previousCount - currentCount);
- waitPeriod = currentCount * elapsedTimePerJob;
- if (waitPeriod < 500) waitPeriod = 500;
- }
-
- if (waitPeriod > 5000) {
- waitPeriod = 5000;
- }
- else {
- long remainingTime = timeout - elapsedTime;
- waitPeriod = (waitPeriod > remainingTime) ? remainingTime : waitPeriod;
- }
-
- if (log.isDebugEnabled()) {
- log.debug("waiting " + waitPeriod + " ms for " + currentCount + " jobs");
- }
- try {
- Thread.sleep(waitPeriod);
- }
- catch (InterruptedException e) {
- fail("wait for jobs got interrupted");
- }
-
- previousCount = currentCount;
- }
- }
-
protected int getNbrOfJobsAvailable() {
if (session != null) {
return getJobCount(session);
@@ -376,7 +305,7 @@
* time has elapsed. The current jBPM context is closed before waiting and a new one is opened
* after processing the jobs.
*/
- protected void oldProcessJobs(long timeout) {
+ protected void processJobs(long timeout) {
closeJbpmContext();
try {
startJobExecutor();
@@ -388,18 +317,6 @@
}
}
- protected void processJobs(long timeout) {
- closeJbpmContext();
- try {
- JobExecutor jobExecutor = startJobExecutor();
- newWaitForJobs(timeout, jobExecutor.getThreads());
- }
- finally {
- stopJobExecutor();
- createJbpmContext();
- }
- }
-
protected void stopJobExecutor() {
if (jobExecutor != null) {
try {
12 years, 11 months
JBoss JBPM SVN: r6945 - jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/db.
by do-not-reply@jboss.org
Author: marco.rietveld
Date: 2011-05-19 11:46:55 -0400 (Thu, 19 May 2011)
New Revision: 6945
Modified:
jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/db/AbstractDbTestCase.java
Log:
Experiment with ThreadMXBean: second attempt.
Modified: jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/db/AbstractDbTestCase.java
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/db/AbstractDbTestCase.java 2011-05-19 15:43:13 UTC (rev 6944)
+++ jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/db/AbstractDbTestCase.java 2011-05-19 15:46:55 UTC (rev 6945)
@@ -21,7 +21,11 @@
*/
package org.jbpm.db;
+import java.lang.management.ManagementFactory;
+import java.lang.management.ThreadMXBean;
import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
@@ -31,7 +35,6 @@
import org.hibernate.cfg.Environment;
import org.hibernate.criterion.Projections;
import org.hibernate.criterion.Restrictions;
-
import org.jbpm.AbstractJbpmTestCase;
import org.jbpm.JbpmConfiguration;
import org.jbpm.JbpmContext;
@@ -205,9 +208,10 @@
}
}
- protected void startJobExecutor() {
+ protected JobExecutor startJobExecutor() {
jobExecutor = getJbpmConfiguration().getJobExecutor();
jobExecutor.start();
+ return jobExecutor;
}
/**
@@ -260,6 +264,73 @@
}
}
+ private long getUserTimeInMilliseconds( HashSet threadIdSet ) {
+ ThreadMXBean bean = ManagementFactory.getThreadMXBean( );
+ if ( ! bean.isThreadCpuTimeSupported( ) ) {
+ return 0L;
+ }
+
+ long totalThreadTimeInNanoSeconds = 0;
+ Object [] threadId = new Long[0];
+ threadId = threadIdSet.toArray(threadId);
+
+ for ( int i = 0; i < threadId.length; ++i ) {
+ long threadTime = bean.getThreadUserTime( (Long) threadId[i] );
+ if ( threadTime != -1 ) {
+ totalThreadTimeInNanoSeconds += threadTime;
+ }
+ }
+
+ return totalThreadTimeInNanoSeconds/1000000;
+ }
+
+ protected void newWaitForJobs(final long timeout, Map threadMap) {
+
+ // Gather thread Id's
+ Iterator threadMapIter = threadMap.values().iterator();
+ HashSet threadIdSet = new HashSet();
+ while(threadMapIter.hasNext()) {
+ Thread thisThread = (Thread) threadMapIter.next();
+ threadIdSet.add(thisThread.getId());
+ }
+
+ long waitPeriod = 500;
+ for (int currentCount, previousCount = 0; (currentCount = getNbrOfJobsAvailable()) > 0;) {
+
+ long elapsedTime = getUserTimeInMilliseconds(threadIdSet);
+
+ if (elapsedTime > timeout) {
+ fail("test execution exceeded threshold of " + timeout + " ms");
+ }
+
+ if (currentCount < previousCount) {
+ long elapsedTimePerJob = (elapsedTime) / (previousCount - currentCount);
+ waitPeriod = currentCount * elapsedTimePerJob;
+ if (waitPeriod < 500) waitPeriod = 500;
+ }
+
+ if (waitPeriod > 5000) {
+ waitPeriod = 5000;
+ }
+ else {
+ long remainingTime = timeout - elapsedTime;
+ waitPeriod = (waitPeriod > remainingTime) ? remainingTime : waitPeriod;
+ }
+
+ if (log.isDebugEnabled()) {
+ log.debug("waiting " + waitPeriod + " ms for " + currentCount + " jobs");
+ }
+ try {
+ Thread.sleep(waitPeriod);
+ }
+ catch (InterruptedException e) {
+ fail("wait for jobs got interrupted");
+ }
+
+ previousCount = currentCount;
+ }
+ }
+
protected int getNbrOfJobsAvailable() {
if (session != null) {
return getJobCount(session);
@@ -305,7 +376,7 @@
* time has elapsed. The current jBPM context is closed before waiting and a new one is opened
* after processing the jobs.
*/
- protected void processJobs(long timeout) {
+ protected void oldProcessJobs(long timeout) {
closeJbpmContext();
try {
startJobExecutor();
@@ -317,6 +388,18 @@
}
}
+ protected void processJobs(long timeout) {
+ closeJbpmContext();
+ try {
+ JobExecutor jobExecutor = startJobExecutor();
+ newWaitForJobs(timeout, jobExecutor.getThreads());
+ }
+ finally {
+ stopJobExecutor();
+ createJbpmContext();
+ }
+ }
+
protected void stopJobExecutor() {
if (jobExecutor != null) {
try {
12 years, 11 months
JBoss JBPM SVN: r6944 - jbpm3/branches/jbpm-3.2-soa/core/src/test/java/org/jbpm/job/executor.
by do-not-reply@jboss.org
Author: marco.rietveld
Date: 2011-05-19 11:43:13 -0400 (Thu, 19 May 2011)
New Revision: 6944
Removed:
jbpm3/branches/jbpm-3.2-soa/core/src/test/java/org/jbpm/job/executor/JobExecutorTest.java
Log:
Experiment failed, unable to use ThreadMXBean because jBPM is, of course, java 1.4 compliant.
Deleted: jbpm3/branches/jbpm-3.2-soa/core/src/test/java/org/jbpm/job/executor/JobExecutorTest.java
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/core/src/test/java/org/jbpm/job/executor/JobExecutorTest.java 2011-05-19 15:41:52 UTC (rev 6943)
+++ jbpm3/branches/jbpm-3.2-soa/core/src/test/java/org/jbpm/job/executor/JobExecutorTest.java 2011-05-19 15:43:13 UTC (rev 6944)
@@ -1,13 +0,0 @@
-package org.jbpm.job.executor;
-
-import java.lang.management.ManagementFactory;
-import java.lang.management.ThreadMXBean;
-
-public class JobExecutorTest {
-
- public long getUserTime() {
- ThreadMXBean bean = ManagementFactory.getThreadMXBean();
- return bean.isCurrentThreadCpuTimeSupported() ? bean.getCurrentThreadUserTime() : 0L;
- }
-
-}
12 years, 11 months
JBoss JBPM SVN: r6943 - jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/db.
by do-not-reply@jboss.org
Author: marco.rietveld
Date: 2011-05-19 11:41:52 -0400 (Thu, 19 May 2011)
New Revision: 6943
Modified:
jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/db/AbstractDbTestCase.java
Log:
Experiment failed, unable to use ThreadMXBean because jBPM is, of course, java 1.4 compliant.
Modified: jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/db/AbstractDbTestCase.java
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/db/AbstractDbTestCase.java 2011-05-19 15:34:47 UTC (rev 6942)
+++ jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/db/AbstractDbTestCase.java 2011-05-19 15:41:52 UTC (rev 6943)
@@ -21,11 +21,7 @@
*/
package org.jbpm.db;
-import java.lang.management.ManagementFactory;
-import java.lang.management.ThreadMXBean;
import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
@@ -35,6 +31,7 @@
import org.hibernate.cfg.Environment;
import org.hibernate.criterion.Projections;
import org.hibernate.criterion.Restrictions;
+
import org.jbpm.AbstractJbpmTestCase;
import org.jbpm.JbpmConfiguration;
import org.jbpm.JbpmContext;
@@ -208,10 +205,9 @@
}
}
- protected JobExecutor startJobExecutor() {
+ protected void startJobExecutor() {
jobExecutor = getJbpmConfiguration().getJobExecutor();
jobExecutor.start();
- return jobExecutor;
}
/**
@@ -264,72 +260,6 @@
}
}
- private long getUserTimeInMilliseconds( HashSet<Long> threadIdSet ) {
- ThreadMXBean bean = ManagementFactory.getThreadMXBean( );
- if ( ! bean.isThreadCpuTimeSupported( ) ) {
- return 0L;
- }
-
- long totalThreadTimeInNanoSeconds = 0;
- Long [] threadId = new Long[0];
- threadId = threadIdSet.toArray(threadId);
-
- for ( int i = 0; i < threadId.length; ++i ) {
- long threadTime = bean.getThreadUserTime( threadId[i] );
- if ( threadTime != -1 ) {
- totalThreadTimeInNanoSeconds += threadTime;
- }
- }
-
- return totalThreadTimeInNanoSeconds/1000000;
- }
-
- protected void newWaitForJobs(final long timeout, Map threadMap) {
-
- // Gather thread Id's
- Iterator<Thread> threadMapIter = threadMap.values().iterator();
- HashSet<Long> threadIdSet = new HashSet<Long>();
- while(threadMapIter.hasNext()) {
- threadIdSet.add(threadMapIter.next().getId());
- }
-
- long waitPeriod = 500;
- for (int currentCount, previousCount = 0; (currentCount = getNbrOfJobsAvailable()) > 0;) {
-
- long elapsedTime = getUserTimeInMilliseconds(threadIdSet);
-
- if (elapsedTime > timeout) {
- fail("test execution exceeded threshold of " + timeout + " ms");
- }
-
- if (currentCount < previousCount) {
- long elapsedTimePerJob = (elapsedTime) / (previousCount - currentCount);
- waitPeriod = currentCount * elapsedTimePerJob;
- if (waitPeriod < 500) waitPeriod = 500;
- }
-
- if (waitPeriod > 5000) {
- waitPeriod = 5000;
- }
- else {
- long remainingTime = timeout - elapsedTime;
- waitPeriod = (waitPeriod > remainingTime) ? remainingTime : waitPeriod;
- }
-
- if (log.isDebugEnabled()) {
- log.debug("waiting " + waitPeriod + " ms for " + currentCount + " jobs");
- }
- try {
- Thread.sleep(waitPeriod);
- }
- catch (InterruptedException e) {
- fail("wait for jobs got interrupted");
- }
-
- previousCount = currentCount;
- }
- }
-
protected int getNbrOfJobsAvailable() {
if (session != null) {
return getJobCount(session);
@@ -375,7 +305,7 @@
* time has elapsed. The current jBPM context is closed before waiting and a new one is opened
* after processing the jobs.
*/
- protected void oldProcessJobs(long timeout) {
+ protected void processJobs(long timeout) {
closeJbpmContext();
try {
startJobExecutor();
@@ -387,18 +317,6 @@
}
}
- protected void processJobs(long timeout) {
- closeJbpmContext();
- try {
- JobExecutor jobExecutor = startJobExecutor();
- newWaitForJobs(timeout, jobExecutor.getThreads());
- }
- finally {
- stopJobExecutor();
- createJbpmContext();
- }
- }
-
protected void stopJobExecutor() {
if (jobExecutor != null) {
try {
12 years, 11 months
JBoss JBPM SVN: r6942 - jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/db.
by do-not-reply@jboss.org
Author: marco.rietveld
Date: 2011-05-19 11:34:47 -0400 (Thu, 19 May 2011)
New Revision: 6942
Modified:
jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/db/AbstractDbTestCase.java
Log:
Experiment with ThreadMXBean in order to see if this helps to run JobExecutor tests.
Modified: jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/db/AbstractDbTestCase.java
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/db/AbstractDbTestCase.java 2011-05-19 13:03:08 UTC (rev 6941)
+++ jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/db/AbstractDbTestCase.java 2011-05-19 15:34:47 UTC (rev 6942)
@@ -21,7 +21,11 @@
*/
package org.jbpm.db;
+import java.lang.management.ManagementFactory;
+import java.lang.management.ThreadMXBean;
import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
@@ -31,7 +35,6 @@
import org.hibernate.cfg.Environment;
import org.hibernate.criterion.Projections;
import org.hibernate.criterion.Restrictions;
-
import org.jbpm.AbstractJbpmTestCase;
import org.jbpm.JbpmConfiguration;
import org.jbpm.JbpmContext;
@@ -205,9 +208,10 @@
}
}
- protected void startJobExecutor() {
+ protected JobExecutor startJobExecutor() {
jobExecutor = getJbpmConfiguration().getJobExecutor();
jobExecutor.start();
+ return jobExecutor;
}
/**
@@ -260,6 +264,72 @@
}
}
+ private long getUserTimeInMilliseconds( HashSet<Long> threadIdSet ) {
+ ThreadMXBean bean = ManagementFactory.getThreadMXBean( );
+ if ( ! bean.isThreadCpuTimeSupported( ) ) {
+ return 0L;
+ }
+
+ long totalThreadTimeInNanoSeconds = 0;
+ Long [] threadId = new Long[0];
+ threadId = threadIdSet.toArray(threadId);
+
+ for ( int i = 0; i < threadId.length; ++i ) {
+ long threadTime = bean.getThreadUserTime( threadId[i] );
+ if ( threadTime != -1 ) {
+ totalThreadTimeInNanoSeconds += threadTime;
+ }
+ }
+
+ return totalThreadTimeInNanoSeconds/1000000;
+ }
+
+ protected void newWaitForJobs(final long timeout, Map threadMap) {
+
+ // Gather thread Id's
+ Iterator<Thread> threadMapIter = threadMap.values().iterator();
+ HashSet<Long> threadIdSet = new HashSet<Long>();
+ while(threadMapIter.hasNext()) {
+ threadIdSet.add(threadMapIter.next().getId());
+ }
+
+ long waitPeriod = 500;
+ for (int currentCount, previousCount = 0; (currentCount = getNbrOfJobsAvailable()) > 0;) {
+
+ long elapsedTime = getUserTimeInMilliseconds(threadIdSet);
+
+ if (elapsedTime > timeout) {
+ fail("test execution exceeded threshold of " + timeout + " ms");
+ }
+
+ if (currentCount < previousCount) {
+ long elapsedTimePerJob = (elapsedTime) / (previousCount - currentCount);
+ waitPeriod = currentCount * elapsedTimePerJob;
+ if (waitPeriod < 500) waitPeriod = 500;
+ }
+
+ if (waitPeriod > 5000) {
+ waitPeriod = 5000;
+ }
+ else {
+ long remainingTime = timeout - elapsedTime;
+ waitPeriod = (waitPeriod > remainingTime) ? remainingTime : waitPeriod;
+ }
+
+ if (log.isDebugEnabled()) {
+ log.debug("waiting " + waitPeriod + " ms for " + currentCount + " jobs");
+ }
+ try {
+ Thread.sleep(waitPeriod);
+ }
+ catch (InterruptedException e) {
+ fail("wait for jobs got interrupted");
+ }
+
+ previousCount = currentCount;
+ }
+ }
+
protected int getNbrOfJobsAvailable() {
if (session != null) {
return getJobCount(session);
@@ -305,7 +375,7 @@
* time has elapsed. The current jBPM context is closed before waiting and a new one is opened
* after processing the jobs.
*/
- protected void processJobs(long timeout) {
+ protected void oldProcessJobs(long timeout) {
closeJbpmContext();
try {
startJobExecutor();
@@ -317,6 +387,18 @@
}
}
+ protected void processJobs(long timeout) {
+ closeJbpmContext();
+ try {
+ JobExecutor jobExecutor = startJobExecutor();
+ newWaitForJobs(timeout, jobExecutor.getThreads());
+ }
+ finally {
+ stopJobExecutor();
+ createJbpmContext();
+ }
+ }
+
protected void stopJobExecutor() {
if (jobExecutor != null) {
try {
12 years, 11 months
JBoss JBPM SVN: r6941 - jbpm3/branches/jbpm-3.2-soa/core/src/test/java/org/jbpm/job/executor.
by do-not-reply@jboss.org
Author: marco.rietveld
Date: 2011-05-19 09:03:08 -0400 (Thu, 19 May 2011)
New Revision: 6941
Added:
jbpm3/branches/jbpm-3.2-soa/core/src/test/java/org/jbpm/job/executor/JobExecutorTest.java
Log:
Trying to find a way to measure user time in tests, instead of system time (because of sometimes overloaded test systems).
Added: jbpm3/branches/jbpm-3.2-soa/core/src/test/java/org/jbpm/job/executor/JobExecutorTest.java
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/core/src/test/java/org/jbpm/job/executor/JobExecutorTest.java (rev 0)
+++ jbpm3/branches/jbpm-3.2-soa/core/src/test/java/org/jbpm/job/executor/JobExecutorTest.java 2011-05-19 13:03:08 UTC (rev 6941)
@@ -0,0 +1,13 @@
+package org.jbpm.job.executor;
+
+import java.lang.management.ManagementFactory;
+import java.lang.management.ThreadMXBean;
+
+public class JobExecutorTest {
+
+ public long getUserTime() {
+ ThreadMXBean bean = ManagementFactory.getThreadMXBean();
+ return bean.isCurrentThreadCpuTimeSupported() ? bean.getCurrentThreadUserTime() : 0L;
+ }
+
+}
Property changes on: jbpm3/branches/jbpm-3.2-soa/core/src/test/java/org/jbpm/job/executor/JobExecutorTest.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:eol-style
+ native
12 years, 11 months
JBoss JBPM SVN: r6940 - jbpm3/branches/jbpm-3.2-soa/userguide/src/main/docbook/en-US.
by do-not-reply@jboss.org
Author: marco.rietveld
Date: 2011-05-19 03:49:29 -0400 (Thu, 19 May 2011)
New Revision: 6940
Modified:
jbpm3/branches/jbpm-3.2-soa/userguide/src/main/docbook/en-US/jpdl.xml
Log:
SOA-2010: ensure that documentation is explicit about conditions only being used on transitions leaving decisions.
Modified: jbpm3/branches/jbpm-3.2-soa/userguide/src/main/docbook/en-US/jpdl.xml
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/userguide/src/main/docbook/en-US/jpdl.xml 2011-05-19 06:17:05 UTC (rev 6939)
+++ jbpm3/branches/jbpm-3.2-soa/userguide/src/main/docbook/en-US/jpdl.xml 2011-05-19 07:49:29 UTC (rev 6940)
@@ -1292,7 +1292,8 @@
<entry>optional</entry>
<entry>This is a <firstterm>guard condition</firstterm> expression. Use these condition
attributes (or child elements) in decision nodes, or to calculate the
- available transitions on a token at run-time.
+ available transitions on a token at run-time. Conditions are only allowed on transitions
+ leaving decision nodes.
</entry>
</row>
<row>
@@ -2142,7 +2143,8 @@
which the expression resolves to <code>true</code>. If
none of the conditions resolve to <code>true</code>,
the default leaving transition (the first one) will be
- taken.
+ taken. Conditions are only allowed on transitions leaving
+ decision nodes.
</entry>
</row>
</tbody>
12 years, 11 months