5 Replies Latest reply on Mar 30, 2010 1:09 PM by HuiSheng Xu

    Timer trigger in Junit test

    Sameeh Harfoush Expert

      Hello

      I am using the <timer> in a transition to fire after a specific duedate. My test-case is in a JUnit test and when I run the JPDL workflow the timer never fires the transition and I am firing the timer explicitly to test my workflow. Note that the JBPM database is logging the timer and setting the process as waiting

       

      Is there a configuration that I do in order for the timer to fire by its own, Or should I deploy the workflow in a web container in order for the scheduler to run properly?

       

       

      <transition g="433,186;435,673:-43,-16" name="Manager timeout"  to="Send timesheet to accounts">
                      <timer duedate="20 seconds" />
      </transition>

       

      Thank you

        • 1. Re: Timer trigger in Junit test
          HuiSheng Xu Master

          In unit test, you can use managementService to execute Job/Timer.

           

          ManagementService managementService = processEngine.getManagementService();

          Job job = managementService.createJobQuery().timers().processInstanceId(piId).uniqueResult();

          managementService.execute(job.getId());

          • 2. Re: Timer trigger in Junit test
            Sameeh Harfoush Expert

            Hello,

            Thanks for the reply

             

            The code you wrote is exactly what I am doing, but this way I am explicitly triggering the job / timer. I need the timer to fire on its own after its duedate. This should be done be a scheduler or so

            • 3. Re: Timer trigger in Junit test
              HuiSheng Xu Master

              Hi Sameeh:

                I have known what you mean. But I don't recommand to run a JobExecutor in the unit test. In the unit test environment, we shouldn't depend the container environment to do things like that. Furthermore, if you have configured a JobExecutor and wait for  '20 seconds', you can't exactly decide when the timer was executed, because the jobexecutor doesn't run in real time, commonly it will wait thirty second between every execution.

               

                So I think you shouldnot depend a JobExecutor to decide whether the Timer executed correctly. May be you can setup a integration test environment to verify this.

              • 4. Re: Timer trigger in Junit test
                Sameeh Harfoush Expert

                Ok, I see what you mean

                Will the timer work properly in a web container like tomcat?

                I didn’t deploy the workflow in a web application yet, but I assume that the timer should be triggered automatically according to its duedate and repeat settings.

                 

                Did you try such a scenario?

                 

                Thanks

                • 5. Re: Timer trigger in Junit test
                  HuiSheng Xu Master

                  Hi Sameeh:

                    You can import jbpm.jobexecutor.cfg.xml  to the jbpm.cfg.xml, then when you startup the ProcessEngine, JobExecutor will startup automaticly. The configuration is as following:

                   

                  <?xml version="1.0" encoding="UTF-8"?>

                   


                  <jbpm-configuration>

                   

                    <import resource="ext/jbpm.default.cfg.xml" />
                    <import resource="jbpm.businesscalendar.cfg.xml" />
                    <import resource="jbpm.tx.hibernate.cfg.xml" />
                    <import resource="jbpm.jpdl.cfg.xml" />
                    <import resource="jbpm.identity.cfg.xml" />

                   

                    <import resource="jbpm.jobexecutor.cfg.xml" />

                  </jbpm-configuration>

                   

                   

                    If you user 'show_sql=true' in hibernate, you will see many SQL on the console, it is said that JobExecutor is trying to find Job from database.

                   

                    The JobExecutor needn't a servlet container like tomcat, because it is no more than a TheadPool. You can try like this in your unit test.