Search in sources :

Example 11 with Batch

use of org.camunda.bpm.engine.batch.Batch in project camunda-bpm-platform by camunda.

the class ExternalTaskRestServiceInteractionTest method setUpRuntimeData.

@Before
public void setUpRuntimeData() {
    externalTaskService = mock(ExternalTaskService.class);
    when(processEngine.getExternalTaskService()).thenReturn(externalTaskService);
    runtimeServiceMock = mock(RuntimeServiceImpl.class);
    when(processEngine.getRuntimeService()).thenReturn(runtimeServiceMock);
    historyServiceMock = mock(HistoryServiceImpl.class);
    when(processEngine.getHistoryService()).thenReturn(historyServiceMock);
    // locked external task
    lockedExternalTaskMock = MockProvider.createMockLockedExternalTask();
    // fetching
    fetchTopicBuilder = mock(ExternalTaskQueryTopicBuilder.class);
    when(externalTaskService.fetchAndLock(anyInt(), any(String.class))).thenReturn(fetchTopicBuilder);
    when(externalTaskService.fetchAndLock(anyInt(), any(String.class), any(Boolean.class))).thenReturn(fetchTopicBuilder);
    when(fetchTopicBuilder.topic(any(String.class), anyLong())).thenReturn(fetchTopicBuilder);
    when(fetchTopicBuilder.variables(anyListOf(String.class))).thenReturn(fetchTopicBuilder);
    when(fetchTopicBuilder.variables(any(String[].class))).thenReturn(fetchTopicBuilder);
    when(fetchTopicBuilder.enableCustomObjectDeserialization()).thenReturn(fetchTopicBuilder);
    when(fetchTopicBuilder.topic(any(String.class), anyLong())).thenReturn(fetchTopicBuilder);
    when(fetchTopicBuilder.businessKey(any(String.class))).thenReturn(fetchTopicBuilder);
    when(fetchTopicBuilder.processInstanceVariableEquals(anyMapOf(String.class, Object.class))).thenReturn(fetchTopicBuilder);
    Batch batch = createMockBatch();
    updateRetriesBuilder = mock(UpdateExternalTaskRetriesBuilder.class);
    when(externalTaskService.updateRetries()).thenReturn(updateRetriesBuilder);
    when(updateRetriesBuilder.externalTaskIds(anyListOf(String.class))).thenReturn(updateRetriesBuilder);
    when(updateRetriesBuilder.processInstanceIds(anyListOf(String.class))).thenReturn(updateRetriesBuilder);
    when(updateRetriesBuilder.externalTaskQuery(any(ExternalTaskQuery.class))).thenReturn(updateRetriesBuilder);
    when(updateRetriesBuilder.processInstanceQuery(any(ProcessInstanceQuery.class))).thenReturn(updateRetriesBuilder);
    when(updateRetriesBuilder.historicProcessInstanceQuery(any(HistoricProcessInstanceQuery.class))).thenReturn(updateRetriesBuilder);
    when(updateRetriesBuilder.setAsync(anyInt())).thenReturn(batch);
    // querying
    externalTaskQueryMock = mock(ExternalTaskQuery.class);
    when(externalTaskQueryMock.externalTaskId(any(String.class))).thenReturn(externalTaskQueryMock);
    when(externalTaskService.createExternalTaskQuery()).thenReturn(externalTaskQueryMock);
    // external task
    externalTaskMock = MockProvider.createMockExternalTask();
}
Also used : HistoricProcessInstanceQuery(org.camunda.bpm.engine.history.HistoricProcessInstanceQuery) ProcessInstanceQuery(org.camunda.bpm.engine.runtime.ProcessInstanceQuery) UpdateExternalTaskRetriesBuilder(org.camunda.bpm.engine.externaltask.UpdateExternalTaskRetriesBuilder) ExternalTaskQuery(org.camunda.bpm.engine.externaltask.ExternalTaskQuery) HistoricProcessInstanceQuery(org.camunda.bpm.engine.history.HistoricProcessInstanceQuery) HistoryServiceImpl(org.camunda.bpm.engine.impl.HistoryServiceImpl) MockProvider.createMockBatch(org.camunda.bpm.engine.rest.helper.MockProvider.createMockBatch) Batch(org.camunda.bpm.engine.batch.Batch) ExternalTaskService(org.camunda.bpm.engine.ExternalTaskService) Matchers.anyString(org.mockito.Matchers.anyString) RuntimeServiceImpl(org.camunda.bpm.engine.impl.RuntimeServiceImpl) ExternalTaskQueryTopicBuilder(org.camunda.bpm.engine.externaltask.ExternalTaskQueryTopicBuilder) Before(org.junit.Before)

Example 12 with Batch

use of org.camunda.bpm.engine.batch.Batch in project camunda-bpm-platform by camunda.

the class SetExternalTasksRetriesTest method shouldUpdateRetriesByHistoricProcessInstanceQuery.

@Test
@RequiredHistoryLevel(ProcessEngineConfiguration.HISTORY_AUDIT)
public void shouldUpdateRetriesByHistoricProcessInstanceQuery() {
    // given
    HistoricProcessInstanceQuery query = historyService.createHistoricProcessInstanceQuery();
    // when
    Batch batch = externalTaskService.updateRetries().historicProcessInstanceQuery(query).setAsync(5);
    executeSeedAndBatchJobs(batch);
    // then
    List<ExternalTask> tasks = externalTaskService.createExternalTaskQuery().list();
    assertEquals(6, tasks.size());
    for (ExternalTask task : tasks) {
        assertEquals(5, (int) task.getRetries());
    }
}
Also used : HistoricProcessInstanceQuery(org.camunda.bpm.engine.history.HistoricProcessInstanceQuery) HistoricBatch(org.camunda.bpm.engine.batch.history.HistoricBatch) Batch(org.camunda.bpm.engine.batch.Batch) ExternalTask(org.camunda.bpm.engine.externaltask.ExternalTask) Test(org.junit.Test) RequiredHistoryLevel(org.camunda.bpm.engine.test.RequiredHistoryLevel)

Example 13 with Batch

use of org.camunda.bpm.engine.batch.Batch in project camunda-bpm-platform by camunda.

the class SetExternalTasksRetriesTest method shouldSetExternalTaskRetriesWithListAndQueryAsync.

@Test
public void shouldSetExternalTaskRetriesWithListAndQueryAsync() {
    ExternalTaskQuery externalTaskQuery = externalTaskService.createExternalTaskQuery();
    List<ExternalTask> externalTasks = externalTaskQuery.list();
    ArrayList<String> externalTaskIds = new ArrayList<String>();
    for (ExternalTask task : externalTasks) {
        externalTaskIds.add(task.getId());
    }
    // when
    Batch batch = externalTaskService.setRetriesAsync(externalTaskIds, externalTaskQuery, 5);
    // then
    executeSeedAndBatchJobs(batch);
    externalTasks = externalTaskService.createExternalTaskQuery().list();
    for (ExternalTask task : externalTasks) {
        Assert.assertEquals(5, (int) task.getRetries());
    }
}
Also used : ExternalTaskQuery(org.camunda.bpm.engine.externaltask.ExternalTaskQuery) HistoricBatch(org.camunda.bpm.engine.batch.history.HistoricBatch) Batch(org.camunda.bpm.engine.batch.Batch) ArrayList(java.util.ArrayList) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) ExternalTask(org.camunda.bpm.engine.externaltask.ExternalTask) Test(org.junit.Test)

Example 14 with Batch

use of org.camunda.bpm.engine.batch.Batch in project camunda-bpm-platform by camunda.

the class SetExternalTasksRetriesTest method shouldSetExternalTaskRetriesWithDifferentListAndQueryAsync.

@Test
public void shouldSetExternalTaskRetriesWithDifferentListAndQueryAsync() {
    // given
    ExternalTaskQuery externalTaskQuery = externalTaskService.createExternalTaskQuery().processInstanceId(processInstanceIds.get(0));
    List<ExternalTask> externalTasks = externalTaskService.createExternalTaskQuery().processInstanceId(processInstanceIds.get(processInstanceIds.size() - 1)).list();
    ArrayList<String> externalTaskIds = new ArrayList<String>();
    for (ExternalTask task : externalTasks) {
        externalTaskIds.add(task.getId());
    }
    // when
    Batch batch = externalTaskService.setRetriesAsync(externalTaskIds, externalTaskQuery, 8);
    executeSeedAndBatchJobs(batch);
    // then
    ExternalTask task = externalTaskService.createExternalTaskQuery().processInstanceId(processInstanceIds.get(0)).singleResult();
    Assert.assertEquals(8, (int) task.getRetries());
    List<ExternalTask> tasks = externalTaskService.createExternalTaskQuery().processInstanceId(processInstanceIds.get(processInstanceIds.size() - 1)).list();
    for (ExternalTask t : tasks) {
        Assert.assertEquals(8, (int) t.getRetries());
    }
}
Also used : ExternalTaskQuery(org.camunda.bpm.engine.externaltask.ExternalTaskQuery) HistoricBatch(org.camunda.bpm.engine.batch.history.HistoricBatch) Batch(org.camunda.bpm.engine.batch.Batch) ArrayList(java.util.ArrayList) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) ExternalTask(org.camunda.bpm.engine.externaltask.ExternalTask) Test(org.junit.Test)

Example 15 with Batch

use of org.camunda.bpm.engine.batch.Batch in project camunda-bpm-platform by camunda.

the class SetExternalTasksRetriesTest method cleanBatch.

@After
public void cleanBatch() {
    List<Batch> batches = managementService.createBatchQuery().list();
    if (batches.size() > 0) {
        for (Batch batch : batches) {
            managementService.deleteBatch(batch.getId(), true);
        }
    }
    HistoricBatch historicBatch = historyService.createHistoricBatchQuery().singleResult();
    if (historicBatch != null) {
        historyService.deleteHistoricBatch(historicBatch.getId());
    }
}
Also used : HistoricBatch(org.camunda.bpm.engine.batch.history.HistoricBatch) HistoricBatch(org.camunda.bpm.engine.batch.history.HistoricBatch) Batch(org.camunda.bpm.engine.batch.Batch) After(org.junit.After)

Aggregations

Batch (org.camunda.bpm.engine.batch.Batch)324 Test (org.junit.Test)286 HistoricBatch (org.camunda.bpm.engine.batch.history.HistoricBatch)125 ProcessDefinition (org.camunda.bpm.engine.repository.ProcessDefinition)95 Job (org.camunda.bpm.engine.runtime.Job)78 ProcessInstance (org.camunda.bpm.engine.runtime.ProcessInstance)64 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)32 Date (java.util.Date)28 JobDefinition (org.camunda.bpm.engine.management.JobDefinition)28 AbstractAsyncOperationsTest (org.camunda.bpm.engine.test.api.AbstractAsyncOperationsTest)26 HistoricProcessInstanceQuery (org.camunda.bpm.engine.history.HistoricProcessInstanceQuery)24 ArrayList (java.util.ArrayList)23 ProcessInstanceQuery (org.camunda.bpm.engine.runtime.ProcessInstanceQuery)19 ProcessEngineException (org.camunda.bpm.engine.ProcessEngineException)18 HistoricDecisionInstanceQuery (org.camunda.bpm.engine.history.HistoricDecisionInstanceQuery)17 ExternalTask (org.camunda.bpm.engine.externaltask.ExternalTask)16 ActivityInstance (org.camunda.bpm.engine.runtime.ActivityInstance)15 Deployment (org.camunda.bpm.engine.test.Deployment)15 ExpectedException (org.junit.rules.ExpectedException)14 Matchers.anyString (org.mockito.Matchers.anyString)14