Package org.activiti.engine.runtime

Examples of org.activiti.engine.runtime.Job


        commandContext.getJobEntityManager().send(message);
        return message.getId();
      }
    });

    Job job = managementService.createJobQuery().singleResult();
    assertEquals(3, job.getRetries());
   
    try {
      managementService.executeJob(job.getId());
      fail("exception expected");
    } catch (Exception e) {
      // exception expected;
    }
   
    job = managementService.createJobQuery().singleResult();
    assertEquals(2, job.getRetries());
   
    try {
      managementService.executeJob(job.getId());
      fail("exception expected");
    } catch (Exception e) {
      // exception expected;
    }
   
    job = managementService.createJobQuery().singleResult();
    assertEquals(1, job.getRetries());
   
    try {
      managementService.executeJob(job.getId());
      fail("exception expected");
    } catch (Exception e) {
      // exception expected;
    }
   
    job = managementService.createJobQuery().singleResult();
    assertEquals(0, job.getRetries());
   
    managementService.deleteJob(job.getId());
  }
View Full Code Here


   
    // Start process, forcing error on job-execution
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("timerProcess",
            Collections.singletonMap("error", (Object) Boolean.TRUE));
   
    Job timerJob = managementService.createJobQuery().processInstanceId(processInstance.getId()).timers().singleResult();
    assertNotNull(timerJob);
   
    for(int i=0; i < timerJob.getRetries(); i++) {
      // Force execution of job until retries are exhausted
      try {
        managementService.executeJob(timerJob.getId());
        fail();
      } catch(ActivitiException expected) {
        // Ignore, we expect the exception
      }
    }
    timerJob = managementService.createJobQuery().processInstanceId(processInstance.getId()).timers().singleResult();
    assertEquals(0, timerJob.getRetries());
   
    // Fetch the async-job (which has retries left)
    Job asyncJob = managementService.createJobQuery().processInstanceId(processInstance.getId()).withRetriesLeft().singleResult();
   
    // Test fetching all jobs
    String url = RestUrls.createRelativeResourceUrl(RestUrls.URL_JOB_COLLECTION);
    assertResultsPresentInDataResponse(url, asyncJob.getId(), timerJob.getId());
   
    // Fetch using job-id
    url = RestUrls.createRelativeResourceUrl(RestUrls.URL_JOB_COLLECTION) + "?id=" + asyncJob.getId();
    assertResultsPresentInDataResponse(url, asyncJob.getId());
   
    // Fetch using processInstanceId
    url = RestUrls.createRelativeResourceUrl(RestUrls.URL_JOB_COLLECTION) + "?processInstanceId=" + processInstance.getId();
    assertResultsPresentInDataResponse(url, asyncJob.getId(), timerJob.getId());
   
    url = RestUrls.createRelativeResourceUrl(RestUrls.URL_JOB_COLLECTION) + "?processInstanceId=unexisting";
    assertResultsPresentInDataResponse(url);
   
    // Fetch using executionId
    url = RestUrls.createRelativeResourceUrl(RestUrls.URL_JOB_COLLECTION) + "?executionId=" + asyncJob.getExecutionId();
    assertResultsPresentInDataResponse(url, asyncJob.getId());
   
    url = RestUrls.createRelativeResourceUrl(RestUrls.URL_JOB_COLLECTION) + "?executionId=" + timerJob.getExecutionId();
    assertResultsPresentInDataResponse(url, timerJob.getId());
   
    // Fetch using processDefinitionId
    url = RestUrls.createRelativeResourceUrl(RestUrls.URL_JOB_COLLECTION) + "?processDefinitionId=" + processInstance.getProcessDefinitionId();
    assertResultsPresentInDataResponse(url, asyncJob.getId(), timerJob.getId());
   
    url = RestUrls.createRelativeResourceUrl(RestUrls.URL_JOB_COLLECTION) + "?processDefinitionId=unexisting";
    assertResultsPresentInDataResponse(url);
   
    // Fetch using withRetriesLeft
    url = RestUrls.createRelativeResourceUrl(RestUrls.URL_JOB_COLLECTION) + "?withRetriesLeft=true";
    assertResultsPresentInDataResponse(url, asyncJob.getId());
   
    // Fetch using executable
    url = RestUrls.createRelativeResourceUrl(RestUrls.URL_JOB_COLLECTION) + "?executable=true";
    assertResultsPresentInDataResponse(url, asyncJob.getId());
   
    // Fetch using timers only
    url = RestUrls.createRelativeResourceUrl(RestUrls.URL_JOB_COLLECTION) + "?timersOnly=true";
    assertResultsPresentInDataResponse(url, timerJob.getId());
   
    // Combining messagesOnly with timersOnly should result in exception
    closeResponse(executeRequest(new HttpGet(SERVER_URL_PREFIX +
        RestUrls.createRelativeResourceUrl(RestUrls.URL_JOB_COLLECTION) + "?timersOnly=true&messagesOnly=true"), HttpStatus.SC_BAD_REQUEST));
   
    // Fetch using dueBefore
    url = RestUrls.createRelativeResourceUrl(RestUrls.URL_JOB_COLLECTION) + "?dueBefore=" + getISODateString(inAnHour.getTime());
    assertResultsPresentInDataResponse(url, timerJob.getId());
   
    url = RestUrls.createRelativeResourceUrl(RestUrls.URL_JOB_COLLECTION) + "?dueBefore=" + getISODateString(hourAgo.getTime());
    assertResultsPresentInDataResponse(url);
   
    // Fetch using dueAfter
    url = RestUrls.createRelativeResourceUrl(RestUrls.URL_JOB_COLLECTION) + "?dueAfter=" + getISODateString(hourAgo.getTime());
    assertResultsPresentInDataResponse(url, timerJob.getId());
   
    url = RestUrls.createRelativeResourceUrl(RestUrls.URL_JOB_COLLECTION) + "?dueAfter=" + getISODateString(inAnHour.getTime());
    assertResultsPresentInDataResponse(url);
   
    // Fetch using withException
    url = RestUrls.createRelativeResourceUrl(RestUrls.URL_JOB_COLLECTION) + "?withException=true";
    assertResultsPresentInDataResponse(url, timerJob.getId());
   
    // Fetch with exceptionMessage
    url = RestUrls.createRelativeResourceUrl(RestUrls.URL_JOB_COLLECTION) + "?exceptionMessage=" + encode(timerJob.getExceptionMessage());
    assertResultsPresentInDataResponse(url, timerJob.getId());
   
    // Fetch with empty exceptionMessage
    url = RestUrls.createRelativeResourceUrl(RestUrls.URL_JOB_COLLECTION) + "?exceptionMessage=";
    assertResultsPresentInDataResponse(url);
   
    // Without tenant id, before tenant update
    url = RestUrls.createRelativeResourceUrl(RestUrls.URL_JOB_COLLECTION) + "?withoutTenantId=true";
    assertResultsPresentInDataResponse(url, timerJob.getId(), asyncJob.getId());
   
    // Set tenant on deployment
    managementService.executeCommand(new ChangeDeploymentTenantIdCmd(deploymentId, "myTenant"));

    // Without tenant id, after tenant update
    url = RestUrls.createRelativeResourceUrl(RestUrls.URL_JOB_COLLECTION) + "?withoutTenantId=true";
    assertResultsPresentInDataResponse(url);
   
    // Tenant id
    url = RestUrls.createRelativeResourceUrl(RestUrls.URL_JOB_COLLECTION) + "?tenantId=myTenant";
    assertResultsPresentInDataResponse(url, timerJob.getId(), asyncJob.getId());
   
    url = RestUrls.createRelativeResourceUrl(RestUrls.URL_JOB_COLLECTION) + "?tenantId=anotherTenant";
    assertResultsPresentInDataResponse(url);
   
    // Tenant id like
    url = RestUrls.createRelativeResourceUrl(RestUrls.URL_JOB_COLLECTION) + "?tenantIdLike=" + encode("%enant");
    assertResultsPresentInDataResponse(url, timerJob.getId(), asyncJob.getId());
   
    url = RestUrls.createRelativeResourceUrl(RestUrls.URL_JOB_COLLECTION) + "?tenantIdLike=anotherTenant";
    assertResultsPresentInDataResponse(url);
   
  }
View Full Code Here

        commandContext.getJobEntityManager().send(message);
        return message.getId();
      }
    });

    Job job  = managementService.createJobQuery().singleResult();
    assertNotNull(job);
    assertEquals(jobId, job.getId());
   
    assertEquals(0, tweetHandler.getMessages().size());

    managementService.executeJob(job.getId());

    assertEquals("i'm coding a test", tweetHandler.getMessages().get(0));
    assertEquals(1, tweetHandler.getMessages().size());
  }
View Full Code Here

  public void testGetJobStacktrace() throws Exception {
    // Start process, forcing error on job-execution
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("timerProcess",
            Collections.singletonMap("error", (Object) Boolean.TRUE));
   
    Job timerJob = managementService.createJobQuery().processInstanceId(processInstance.getId()).singleResult();
    assertNotNull(timerJob);
   
    // Force execution of job
    try {
      managementService.executeJob(timerJob.getId());
      fail();
    } catch(ActivitiException expected) {
      // Ignore, we expect the exception
    }
   
    Calendar now = Calendar.getInstance();
    now.set(Calendar.MILLISECOND, 0);
    processEngineConfiguration.getClock().setCurrentTime(now.getTime());
   
    CloseableHttpResponse response = executeRequest(new HttpGet(SERVER_URL_PREFIX +
        RestUrls.createRelativeResourceUrl(RestUrls.URL_JOB_EXCEPTION_STRACKTRACE, timerJob.getId())), HttpStatus.SC_OK);
   
    String stack = IOUtils.toString(response.getEntity().getContent());
    assertNotNull(stack);
    assertEquals(managementService.getJobExceptionStacktrace(timerJob.getId()), stack);
   
    // Also check content-type
    assertEquals("text/plain", response.getEntity().getContentType().getValue());
    closeResponse(response);
  }
View Full Code Here

   */
  @Deployment(resources = {"org/activiti/rest/service/api/management/JobExceptionStacktraceResourceTest.testTimerProcess.bpmn20.xml"})
  public void testGetStrackForJobWithoutException() throws Exception {
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("timerProcess",
            Collections.singletonMap("error", (Object) Boolean.FALSE));
    Job timerJob = managementService.createJobQuery().processInstanceId(processInstance.getId()).singleResult();
    assertNotNull(timerJob);
   
    closeResponse(executeRequest(new HttpGet(SERVER_URL_PREFIX +
        RestUrls.createRelativeResourceUrl(RestUrls.URL_JOB_EXCEPTION_STRACKTRACE, timerJob.getId())), HttpStatus.SC_NOT_FOUND));
  }
View Full Code Here

   * Test getting a single job.
   */
  @Deployment(resources = {"org/activiti/rest/service/api/management/JobResourceTest.testTimerProcess.bpmn20.xml"})
  public void testGetJob() throws Exception {
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("timerProcess");
    Job timerJob = managementService.createJobQuery().processInstanceId(processInstance.getId()).singleResult();
    assertNotNull(timerJob);
   
    Calendar now = Calendar.getInstance();
    now.set(Calendar.MILLISECOND, 0);
    processEngineConfiguration.getClock().setCurrentTime(now.getTime());
   
    CloseableHttpResponse response = executeRequest(new HttpGet(SERVER_URL_PREFIX +
        RestUrls.createRelativeResourceUrl(RestUrls.URL_JOB, timerJob.getId())), HttpStatus.SC_OK);
    JsonNode responseNode = objectMapper.readTree(response.getEntity().getContent());
    closeResponse(response);
    assertNotNull(responseNode);
    assertEquals(timerJob.getId(), responseNode.get("id").textValue());
    assertEquals(timerJob.getExceptionMessage(), responseNode.get("exceptionMessage").textValue());
    assertEquals(timerJob.getExecutionId(), responseNode.get("executionId").textValue());
    assertEquals(timerJob.getProcessDefinitionId(), responseNode.get("processDefinitionId").textValue());
    assertEquals(timerJob.getProcessInstanceId(), responseNode.get("processInstanceId").textValue());
    assertEquals(timerJob.getRetries(), responseNode.get("retries").intValue());
    assertEquals(timerJob.getDuedate(), getDateFromISOString(responseNode.get("dueDate").textValue()));
    assertEquals(responseNode.get("tenantId").textValue(), "");
   
    // Set tenant on deployment
    managementService.executeCommand(new ChangeDeploymentTenantIdCmd(deploymentId, "myTenant"));
   
    response = executeRequest(new HttpGet(SERVER_URL_PREFIX +
        RestUrls.createRelativeResourceUrl(RestUrls.URL_JOB, timerJob.getId())), HttpStatus.SC_OK);
    responseNode = objectMapper.readTree(response.getEntity().getContent());
    closeResponse(response);
    assertNotNull(responseNode);
    assertEquals("myTenant", responseNode.get("tenantId").textValue());
  }
View Full Code Here

   * Test executing a single job.
   */
  @Deployment(resources = {"org/activiti/rest/service/api/management/JobResourceTest.testTimerProcess.bpmn20.xml"})
  public void testExecuteJob() throws Exception {
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("timerProcess");
    Job timerJob = managementService.createJobQuery().processInstanceId(processInstance.getId()).singleResult();
    assertNotNull(timerJob);
   
    ObjectNode requestNode = objectMapper.createObjectNode();
    requestNode.put("action", "execute");
   
    HttpPost httpPost = new HttpPost(SERVER_URL_PREFIX +
        RestUrls.createRelativeResourceUrl(RestUrls.URL_JOB, timerJob.getId()));
    httpPost.setEntity(new StringEntity(requestNode.toString()));
    CloseableHttpResponse response = executeRequest(httpPost, HttpStatus.SC_NO_CONTENT);
    closeResponse(response);
   
    // Job should be executed
View Full Code Here

   * Test executing an unexisting job.
   */
  @Deployment(resources = {"org/activiti/rest/service/api/management/JobResourceTest.testTimerProcess.bpmn20.xml"})
  public void testExecuteUnexistingJob() throws Exception {
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("timerProcess");
    Job timerJob = managementService.createJobQuery().processInstanceId(processInstance.getId()).singleResult();
    assertNotNull(timerJob);
   
    ObjectNode requestNode = objectMapper.createObjectNode();
    requestNode.put("action", "execute");
   
View Full Code Here

   * Test executing an unexisting job.
   */
  @Deployment(resources = {"org/activiti/rest/service/api/management/JobResourceTest.testTimerProcess.bpmn20.xml"})
  public void testIllegalActionOnJob() throws Exception {
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("timerProcess");
    Job timerJob = managementService.createJobQuery().processInstanceId(processInstance.getId()).singleResult();
    assertNotNull(timerJob);
   
    ObjectNode requestNode = objectMapper.createObjectNode();
    requestNode.put("action", "unexistinAction");
   
    HttpPost httpPost = new HttpPost(SERVER_URL_PREFIX +
        RestUrls.createRelativeResourceUrl(RestUrls.URL_JOB, timerJob.getId()));
    httpPost.setEntity(new StringEntity(requestNode.toString()));
    CloseableHttpResponse response = executeRequest(httpPost, HttpStatus.SC_BAD_REQUEST);
    closeResponse(response);
  }
View Full Code Here

   * Test deleting a single job.
   */
  @Deployment(resources = {"org/activiti/rest/service/api/management/JobResourceTest.testTimerProcess.bpmn20.xml"})
  public void testDeleteJob() throws Exception {
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("timerProcess");
    Job timerJob = managementService.createJobQuery().processInstanceId(processInstance.getId()).singleResult();
    assertNotNull(timerJob);
   
    HttpDelete httpDelete = new HttpDelete(SERVER_URL_PREFIX +
        RestUrls.createRelativeResourceUrl(RestUrls.URL_JOB, timerJob.getId()));
    CloseableHttpResponse response = executeRequest(httpDelete, HttpStatus.SC_NO_CONTENT);
    closeResponse(response);
   
    // Job should be deleted
    assertNull(managementService.createJobQuery().processInstanceId(processInstance.getId()).singleResult());
View Full Code Here

TOP

Related Classes of org.activiti.engine.runtime.Job

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.