Skip to content

Commit a07eee1

Browse files
committed
Merge branch 'release/0.8.2'
2 parents 120921a + 50bc32d commit a07eee1

16 files changed

Lines changed: 92 additions & 33 deletions

File tree

docs/idempotency.md

Lines changed: 57 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@ When a worker is triggered, the process engine worker:
1616

1717
There are three available implementations of the `IdempotencyRegistry`:
1818

19-
| Implementation | Description | Recommended Use |
20-
| --- | --- | --- |
21-
| `NoOpIdempotencyRegistry` | Does nothing. No results are stored or retrieved. | Default, use if idempotency is handled elsewhere. |
22-
| `InMemoryIdempotencyRegistry` | Stores results in a local `ConcurrentHashMap`. | Testing or non-clustered environments. |
23-
| `JpaIdempotencyRegistry` | Stores results in a database using JPA. | Production, clustered environments. |
19+
| Implementation | Description | Recommended Use |
20+
|-------------------------------|---------------------------------------------------|---------------------------------------------------|
21+
| `NoOpIdempotencyRegistry` | Does nothing. No results are stored or retrieved. | Default, use if idempotency is handled elsewhere. |
22+
| `InMemoryIdempotencyRegistry` | Stores results in a local `ConcurrentHashMap`. | Testing or non-clustered environments. |
23+
| `JpaIdempotencyRegistry` | Stores results in a database using JPA. | Production, clustered environments. |
2424

2525
## Setup Procedures
2626

@@ -58,7 +58,58 @@ Add the following dependency to your `pom.xml`:
5858

5959
The `JpaIdempotencyAutoConfiguration` will automatically register the `JpaIdempotencyRegistry` if an `EntityManager` is present and no other `IdempotencyRegistry` bean is defined.
6060

61-
#### 2. Database Schema (Liquibase)
61+
#### 2. Configure JPA
62+
63+
Add the `dev.bpmcrafters.processengine.worker.idempotency.TaskLogEntryRepository` with the following annotation
64+
```java
65+
@EnableJpaRepositories(basePackages = {
66+
"your.package(s)",
67+
"dev.bpmcrafters.processengine.worker.idempotency"
68+
})
69+
```
70+
71+
You can add the entity `dev.bpmcrafters.processengine.worker.idempotency.TaskLogEntry` either via annotation
72+
```java
73+
@EntityScan(basePackages = {
74+
"your.package(s)",
75+
"dev.bpmcrafters.processengine.worker.idempotency"
76+
})
77+
```
78+
or via `META-INF/orm.xml`
79+
```xml
80+
<?xml version="1.0" encoding="UTF-8"?>
81+
<entity-mappings
82+
xmlns="https://jakarta.ee/xml/ns/persistence/orm"
83+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
84+
xsi:schemaLocation="https://jakarta.ee/xml/ns/persistence/orm https://jakarta.ee/xml/ns/persistence/orm/orm_3_2.xsd"
85+
version="3.2"
86+
>
87+
<entity class="dev.bpmcrafters.processengine.worker.idempotency.TaskLogEntry">
88+
<table schema="your_schema" name="task_log_entry"/>
89+
<attributes>
90+
<basic name="taskId">
91+
<column name="task_id" column-definition="varchar2(100)"/>
92+
</basic>
93+
<basic name="processInstanceId">
94+
<column name="process_instance_id" column-definition="varchar2(100)"/>
95+
</basic>
96+
<basic name="createdAt">
97+
<column name="created_at"/>
98+
</basic>
99+
<basic name="result">
100+
<column name="result"/>
101+
</basic>
102+
</attributes>
103+
</entity>
104+
</entity-mappings>
105+
```
106+
Using the `orm.xml` could be useful. E.g., when you
107+
* are using Hibernate's schema validation and the default types mismatch.
108+
* want to relocate the entity into a different schema.
109+
* want to rename the table.
110+
* want to rename columns.
111+
112+
#### 3. Database Schema (Liquibase)
62113

63114
The JPA registry requires a table named `task_log_entry_`. You can use the following Liquibase changeSet to create it:
64115

@@ -91,8 +142,6 @@ databaseChangeLog:
91142
- column:
92143
name: result_
93144
type: blob # or bytea for PostgreSQL
94-
constraints:
95-
nullable: false
96145
- createIndex:
97146
indexName: idx_task_log_entry_process_instance_id_
98147
tableName: task_log_entry_

examples/camunda7-embedded-starter-transaction/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<groupId>dev.bpm-crafters.process-engine-worker</groupId>
77
<artifactId>process-engine-worker-examples</artifactId>
8-
<version>0.8.1</version>
8+
<version>0.8.2</version>
99
<relativePath>../pom.xml</relativePath>
1010
</parent>
1111

examples/camunda7-remote-starter-native/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<groupId>dev.bpm-crafters.process-engine-worker</groupId>
77
<artifactId>process-engine-worker-examples</artifactId>
8-
<version>0.8.1</version>
8+
<version>0.8.2</version>
99
<relativePath>../pom.xml</relativePath>
1010
</parent>
1111

examples/order-fulfillment/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<groupId>dev.bpm-crafters.process-engine-worker</groupId>
77
<artifactId>process-engine-worker-examples</artifactId>
8-
<version>0.8.1</version>
8+
<version>0.8.2</version>
99
<relativePath>../pom.xml</relativePath>
1010
</parent>
1111

examples/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<groupId>dev.bpm-crafters.process-engine-worker</groupId>
77
<artifactId>process-engine-worker-root</artifactId>
8-
<version>0.8.1</version>
8+
<version>0.8.2</version>
99
<relativePath>../pom.xml</relativePath>
1010
</parent>
1111

itest/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<groupId>dev.bpm-crafters.process-engine-worker</groupId>
77
<artifactId>process-engine-worker-root</artifactId>
8-
<version>0.8.1</version>
8+
<version>0.8.2</version>
99
<relativePath>../pom.xml</relativePath>
1010
</parent>
1111

itest/spring-boot-integration-testing/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<parent>
55
<groupId>dev.bpm-crafters.process-engine-worker</groupId>
66
<artifactId>process-engine-worker-itest</artifactId>
7-
<version>0.8.1</version>
7+
<version>0.8.2</version>
88
<relativePath>../pom.xml</relativePath>
99
</parent>
1010

itest/spring-boot-integration-testing/src/main/kotlin/dev/bpmcrafters/processengine/worker/itest/AbstractBehaviorITestBase.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,13 @@ abstract class AbstractBehaviorITestBase {
127127
null
128128
).body as List<IncidentDto>
129129

130+
protected fun setExternalTaskRetries(externalTaskId: String, retries: Int) {
131+
externalTaskApiClient.setExternalTaskRetries(SetRetriesForExternalTasksDto().apply {
132+
externalTaskIds = listOf(externalTaskId)
133+
this.retries = retries
134+
})
135+
}
136+
130137
protected fun getHistoricActivityInstances(processInstanceId: String, activityId: String): List<HistoricActivityInstanceDto> {
131138
return historyApiClient.queryHistoricActivityInstances(
132139
0,

itest/spring-boot-starter-integration-test/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<parent>
55
<groupId>dev.bpm-crafters.process-engine-worker</groupId>
66
<artifactId>process-engine-worker-itest</artifactId>
7-
<version>0.8.1</version>
7+
<version>0.8.2</version>
88
<relativePath>../pom.xml</relativePath>
99
</parent>
1010

itest/spring-boot-starter-integration-test/src/test/kotlin/dev/bpmcrafters/processengine/worker/itest/idempotency/IdempotencyITest.kt

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
package dev.bpmcrafters.processengine.worker.itest.idempotency
22

33
import dev.bpmcrafters.processengine.worker.fixture.InMemoryIdempotencyRegistryConfiguration
4+
import dev.bpmcrafters.processengine.worker.fixture.MyEntity
5+
import dev.bpmcrafters.processengine.worker.fixture.MyEntityRepository
46
import dev.bpmcrafters.processengine.worker.fixture.worker.WorkerWithTransactionalAnnotation
57
import dev.bpmcrafters.processengine.worker.fixture.worker.WorkerWithoutTransactionalAnnotation
68
import dev.bpmcrafters.processengine.worker.idempotency.IdempotencyRegistry
9+
import dev.bpmcrafters.processengine.worker.idempotency.TaskLogEntry
10+
import dev.bpmcrafters.processengine.worker.idempotency.TaskLogEntryRepository
711
import dev.bpmcrafters.processengine.worker.itest.FixtureITestBase
812
import dev.bpmcrafters.processengineapi.task.ServiceTaskCompletionApi
913
import org.assertj.core.api.Assertions.assertThat
@@ -15,7 +19,9 @@ import org.junit.jupiter.api.Test
1519
import org.mockito.kotlin.*
1620
import org.springframework.beans.factory.annotation.Autowired
1721
import org.springframework.beans.factory.annotation.Value
22+
import org.springframework.boot.autoconfigure.domain.EntityScan
1823
import org.springframework.context.annotation.Import
24+
import org.springframework.data.jpa.repository.config.EnableJpaRepositories
1925
import org.springframework.test.context.TestPropertySource
2026
import org.springframework.test.context.bean.override.mockito.MockitoSpyBean
2127
import java.util.*
@@ -24,6 +30,7 @@ import kotlin.time.toJavaDuration
2430

2531
@TestPropertySource(
2632
properties = [
33+
"dev.bpm-crafters.process-api.adapter.c7remote.service-tasks.retries=0",
2734
"dev.bpm-crafters.process-api.worker.complete-tasks-before-commit=false",
2835
"dev.bpm-crafters.process-api.worker.remove-task-result-on-completion=true"
2936
]
@@ -50,12 +57,11 @@ abstract class IdempotencyITest : FixtureITestBase() {
5057
val processInstanceId = startProcess(name, verified = true)
5158
assertThat(processInstanceIsRunning(processInstanceId)).isTrue()
5259
await atMost 30.seconds.toJavaDuration() untilAsserted {
53-
val entity = findEntityByName(name)
54-
assertThat(entity).isNotNull
60+
val incidents = getIncidents(processInstanceId)
61+
assertThat(incidents).hasSize(1)
5562
}
5663
doCallRealMethod().`when`(serviceTaskCompletionApi).completeTask(any())
57-
unlockExternalTask(getExternalTasks(processInstanceId).first().id!!)
58-
print(idempotencyRegistry)
64+
setExternalTaskRetries(getExternalTasks(processInstanceId).first().id!!, 1)
5965
await atMost 30.seconds.toJavaDuration() untilAsserted {
6066
assertThat(processInstanceIsRunning(processInstanceId)).isFalse
6167
}
@@ -94,13 +100,17 @@ abstract class IdempotencyITest : FixtureITestBase() {
94100

95101
@Nested
96102
@Import(WorkerWithoutTransactionalAnnotation::class)
103+
@EntityScan(basePackageClasses = [TaskLogEntry::class])
104+
@EnableJpaRepositories(basePackageClasses = [TaskLogEntryRepository::class])
97105
class JpaIdempotencyWithoutTransactionITest : IdempotencyITest()
98106

99107
@TestPropertySource(properties = ["dev.bpm-crafters.process-api.worker.complete-tasks-before-commit=false"])
100108
class JpaIdempotencyWithoutTransactionNotRemovingTaskResultITest : JpaIdempotencyWithoutTransactionITest()
101109

102110
@Nested
103111
@Import(WorkerWithTransactionalAnnotation::class)
112+
@EntityScan(basePackageClasses = [TaskLogEntry::class])
113+
@EnableJpaRepositories(basePackageClasses = [TaskLogEntryRepository::class])
104114
class JpaIdempotencyWithTransactionITest : IdempotencyITest()
105115

106116
@TestPropertySource(properties = ["dev.bpm-crafters.process-api.worker.complete-tasks-before-commit=false"])

0 commit comments

Comments
 (0)