Skip to content

Commit 5a8ba29

Browse files
committed
add tests for delivery with ignorable restrictions
1 parent e0383d4 commit 5a8ba29

File tree

10 files changed

+194
-15
lines changed

10 files changed

+194
-15
lines changed

engine-adapter/c7-embedded-core/src/main/kotlin/dev/bpmcrafters/processengineapi/adapter/c7/embedded/task/delivery/pull/EmbeddedPullServiceTaskDelivery.kt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ class EmbeddedPullServiceTaskDelivery(
207207
return customLockDuration?.toLong() ?: (lockDurationInSeconds * 1000)
208208
}
209209

210-
private fun TaskSubscriptionHandle.matches(task: LockedExternalTask): Boolean {
210+
internal fun TaskSubscriptionHandle.matches(task: LockedExternalTask): Boolean {
211211
return this.taskType==TaskType.EXTERNAL
212212
&& (this.taskDescriptionKey==null || this.taskDescriptionKey==task.topicName)
213213
&& this.restrictions
@@ -224,7 +224,10 @@ class EmbeddedPullServiceTaskDelivery(
224224
CommonRestrictions.PROCESS_DEFINITION_KEY -> it.value==task.processDefinitionKey
225225
CommonRestrictions.PROCESS_DEFINITION_ID -> it.value==task.processDefinitionId
226226
CommonRestrictions.PROCESS_DEFINITION_VERSION_TAG -> it.value==task.processDefinitionVersionTag
227-
else -> false
227+
else -> {
228+
logger.debug { "PROCESS-ENGINE-C7-EMBEDDED-041: Unknown restriction key: ${it.key}" }
229+
false
230+
}
228231
}
229232
}
230233
}

engine-adapter/c7-embedded-core/src/main/kotlin/dev/bpmcrafters/processengineapi/adapter/c7/embedded/task/delivery/pull/EmbeddedPullUserTaskDelivery.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -171,14 +171,11 @@ class EmbeddedPullUserTaskDelivery(
171171
}
172172

173173

174-
private fun TaskSubscriptionHandle.matches(task: Task): Boolean =
174+
internal fun TaskSubscriptionHandle.matches(task: Task): Boolean =
175175
(this.taskDescriptionKey==null
176176
|| this.taskDescriptionKey==task.taskDefinitionKey
177177
|| this.taskDescriptionKey==task.id
178178
) && this.restrictions
179-
.minus( // ignore some restrictions which are not relevant for external tasks
180-
"workerLockDurationInMilliseconds"
181-
)
182179
.all {
183180
when (it.key) {
184181
CommonRestrictions.EXECUTION_ID -> it.value==task.executionId
@@ -188,7 +185,10 @@ class EmbeddedPullUserTaskDelivery(
188185
CommonRestrictions.PROCESS_DEFINITION_ID -> it.value==task.processDefinitionId
189186
CommonRestrictions.PROCESS_DEFINITION_KEY -> it.value==processDefinitionMetaDataResolver.getProcessDefinitionKey(task.processDefinitionId)
190187
CommonRestrictions.PROCESS_DEFINITION_VERSION_TAG -> it.value==processDefinitionMetaDataResolver.getProcessDefinitionVersionTag(task.processDefinitionId)
191-
else -> false
188+
else -> {
189+
logger.debug { "PROCESS-ENGINE-C7-EMBEDDED-043: Unknown restriction key: ${it.key}" }
190+
false
191+
}
192192
}
193193
}
194194
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
package dev.bpmcrafters.processengineapi.adapter.c7.embedded.task.delivery.pull
2+
3+
import dev.bpmcrafters.processengineapi.impl.task.TaskSubscriptionHandle
4+
import dev.bpmcrafters.processengineapi.task.TaskType
5+
import org.assertj.core.api.Assertions.assertThat
6+
import org.camunda.bpm.engine.externaltask.LockedExternalTask
7+
import org.junit.jupiter.api.Test
8+
import org.mockito.kotlin.mock
9+
import org.mockito.kotlin.whenever
10+
11+
internal class EmbeddedPullServiceTaskDeliveryTest {
12+
13+
private val taskDelivery = EmbeddedPullServiceTaskDelivery(
14+
externalTaskService = mock(),
15+
subscriptionRepository = mock(),
16+
executor = mock(),
17+
lockDurationInSeconds = 30,
18+
workerId = "worker",
19+
maxTasks = 10,
20+
retryTimeoutInSeconds = 60,
21+
retries = 3,
22+
metrics = mock()
23+
)
24+
25+
@Test
26+
fun `matches handles workerLockDurationInMilliseconds`() {
27+
val subscription = TaskSubscriptionHandle(
28+
taskType = TaskType.EXTERNAL,
29+
restrictions = mapOf("workerLockDurationInMilliseconds" to "5000"),
30+
taskDescriptionKey = "topic",
31+
payloadDescription = null,
32+
action = { _, _ -> },
33+
termination = { }
34+
)
35+
val task: LockedExternalTask = mock()
36+
whenever(task.topicName).thenReturn("topic")
37+
38+
with(taskDelivery) {
39+
assertThat(subscription.matches(task)).isTrue()
40+
}
41+
}
42+
43+
@Test
44+
fun `matches returns false for unknown restriction`() {
45+
val subscription = TaskSubscriptionHandle(
46+
taskType = TaskType.EXTERNAL,
47+
restrictions = mapOf("unknown" to "value"),
48+
taskDescriptionKey = "topic",
49+
payloadDescription = null,
50+
action = { _, _ -> },
51+
termination = { }
52+
)
53+
val task: LockedExternalTask = mock()
54+
whenever(task.topicName).thenReturn("topic")
55+
56+
with(taskDelivery) {
57+
assertThat(subscription.matches(task)).isFalse()
58+
}
59+
}
60+
}

engine-adapter/c7-embedded-core/src/test/kotlin/dev/bpmcrafters/processengineapi/adapter/c7/embedded/task/delivery/pull/EmbeddedPullUserTaskDeliveryTest.kt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,23 @@ internal class EmbeddedPullUserTaskDeliveryTest {
114114
assertThat(userTaskSupport.getAllTasks()).hasSize(tasks.size)
115115
}
116116

117+
@Test
118+
fun `matches returns false for unknown restriction`() {
119+
val subscription = TaskSubscriptionHandle(
120+
taskType = TaskType.USER,
121+
restrictions = mapOf("unknown" to "value"),
122+
taskDescriptionKey = null,
123+
payloadDescription = null,
124+
action = { _, _ -> },
125+
termination = { }
126+
)
127+
val task = randomTask()
128+
129+
with(embeddedPullUserTaskDelivery) {
130+
assertThat(subscription.matches(task)).isFalse()
131+
}
132+
}
133+
117134
private fun randomTask() = TaskFake
118135
.builder()
119136
.id(UUID.randomUUID().toString())

engine-adapter/c7-remote-core/src/main/kotlin/dev/bpmcrafters/processengineapi/adapter/c7/remote/task/delivery/pull/PullServiceTaskDelivery.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,10 @@ class PullServiceTaskDelivery(
265265
CommonRestrictions.PROCESS_DEFINITION_KEY -> it.value==task.processDefinitionKey
266266
CommonRestrictions.PROCESS_DEFINITION_ID -> it.value==task.processDefinitionId
267267
CommonRestrictions.PROCESS_DEFINITION_VERSION_TAG -> it.value==task.processDefinitionVersionTag
268-
else -> false
268+
else -> {
269+
logger.debug { "PROCESS-ENGINE-C7-REMOTE-043: Unknown restriction key: ${it.key}" }
270+
false
271+
}
269272
}
270273
}
271274

engine-adapter/c7-remote-core/src/main/kotlin/dev/bpmcrafters/processengineapi/adapter/c7/remote/task/delivery/pull/PullUserTaskDelivery.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -178,14 +178,11 @@ class PullUserTaskDelivery(
178178
}
179179

180180

181-
private fun TaskSubscriptionHandle.matches(task: TaskWithAttachmentAndCommentDto): Boolean =
181+
internal fun TaskSubscriptionHandle.matches(task: TaskWithAttachmentAndCommentDto): Boolean =
182182
(this.taskDescriptionKey==null
183183
|| this.taskDescriptionKey==task.taskDefinitionKey
184184
|| this.taskDescriptionKey==task.id)
185185
&& this.restrictions
186-
.minus( // ignore some restrictions which are not relevant for external tasks
187-
"workerLockDurationInMilliseconds"
188-
)
189186
.all {
190187
when (it.key) {
191188
CommonRestrictions.EXECUTION_ID -> it.value==task.executionId
@@ -195,7 +192,10 @@ class PullUserTaskDelivery(
195192
CommonRestrictions.PROCESS_DEFINITION_ID -> it.value==task.processDefinitionId
196193
CommonRestrictions.PROCESS_DEFINITION_KEY -> it.value==processDefinitionMetaDataResolver.getProcessDefinitionKey(task.processDefinitionId)
197194
CommonRestrictions.PROCESS_DEFINITION_VERSION_TAG -> it.value==processDefinitionMetaDataResolver.getProcessDefinitionVersionTag(task.processDefinitionId)
198-
else -> false
195+
else -> {
196+
logger.debug { "PROCESS-ENGINE-C7-REMOTE-044: Unknown restriction key: ${it.key}" }
197+
false
198+
}
199199
}
200200
}
201201
}

engine-adapter/c7-remote-core/src/main/kotlin/dev/bpmcrafters/processengineapi/adapter/c7/remote/task/delivery/subscribe/SubscribingServiceTaskDelivery.kt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ class SubscribingServiceTaskDelivery(
9595
* Additional restrictions to check.
9696
* The activated job can be completed by the Subscription strategy and is correct type (topic).
9797
*/
98-
private fun TaskSubscriptionHandle.matches(externalTask: ExternalTask): Boolean =
98+
internal fun TaskSubscriptionHandle.matches(externalTask: ExternalTask): Boolean =
9999
(this.taskDescriptionKey==null
100100
|| this.taskDescriptionKey==externalTask.topicName)
101101
&& this.restrictions
@@ -111,7 +111,10 @@ class SubscribingServiceTaskDelivery(
111111
CommonRestrictions.PROCESS_DEFINITION_KEY -> it.value==externalTask.processDefinitionKey
112112
CommonRestrictions.PROCESS_DEFINITION_ID -> it.value==externalTask.processDefinitionId
113113
CommonRestrictions.PROCESS_DEFINITION_VERSION_TAG -> it.value==externalTask.processDefinitionVersionTag
114-
else -> false
114+
else -> {
115+
logger.debug { "PROCESS-ENGINE-C7-REMOTE-045: Unknown restriction key: ${it.key}" }
116+
false
117+
}
115118
}
116119
}
117120

engine-adapter/c7-remote-core/src/test/kotlin/dev/bpmcrafters/processengineapi/adapter/c7/remote/task/delivery/pull/PullServiceTaskDeliveryTest.kt

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,26 @@ internal class PullServiceTaskDeliveryTest {
374374
)
375375
}
376376

377+
@Test
378+
fun `matches handles workerLockDurationInMilliseconds`() {
379+
val subscription = mockTaskSubscriptionHandle().copy(
380+
restrictions = mapOf("workerLockDurationInMilliseconds" to "5000")
381+
)
382+
val task = mockLockedExternalTaskDto("1")
383+
384+
assertTrue(taskDelivery.matches(task, subscription))
385+
}
386+
387+
@Test
388+
fun `matches returns false for unknown restriction`() {
389+
val subscription = mockTaskSubscriptionHandle().copy(
390+
restrictions = mapOf("unknown" to "value")
391+
)
392+
val task = mockLockedExternalTaskDto("1")
393+
394+
kotlin.test.assertFalse(taskDelivery.matches(task, subscription))
395+
}
396+
377397
fun mockExternalTask(id: String): ExternalTaskDto = ExternalTaskDto().id(id)
378398

379399
fun mockLockedExternalTaskDto(

engine-adapter/c7-remote-core/src/test/kotlin/dev/bpmcrafters/processengineapi/adapter/c7/remote/task/delivery/pull/PullUserTaskDeliveryTest.kt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,23 @@ internal class PullUserTaskDeliveryTest {
122122
assertThat(deliveredViaUserTaskSupport).hasSize(tasks.size)
123123
}
124124

125+
@Test
126+
fun `matches returns false for unknown restriction`() {
127+
val subscription = TaskSubscriptionHandle(
128+
taskType = TaskType.USER,
129+
restrictions = mapOf("unknown" to "value"),
130+
taskDescriptionKey = null,
131+
payloadDescription = null,
132+
action = { _, _ -> },
133+
termination = { }
134+
)
135+
val task = randomTask()
136+
137+
with(embeddedPullUserTaskDelivery) {
138+
assertThat(subscription.matches(task)).isFalse()
139+
}
140+
}
141+
125142
private fun randomTask() = TaskWithAttachmentAndCommentDto()
126143
.id(UUID.randomUUID().toString())
127144
.assignee("kermit")
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
package dev.bpmcrafters.processengineapi.adapter.c7.remote.task.delivery.subscribe
2+
3+
import dev.bpmcrafters.processengineapi.impl.task.TaskSubscriptionHandle
4+
import dev.bpmcrafters.processengineapi.task.TaskType
5+
import org.assertj.core.api.Assertions.assertThat
6+
import org.camunda.bpm.client.task.ExternalTask
7+
import org.junit.jupiter.api.Test
8+
import org.mockito.kotlin.mock
9+
import org.mockito.kotlin.whenever
10+
11+
internal class SubscribingServiceTaskDeliveryTest {
12+
13+
private val taskDelivery = SubscribingServiceTaskDelivery(
14+
externalTaskClient = mock(),
15+
subscriptionRepository = mock(),
16+
lockDurationInSeconds = 30,
17+
retryTimeoutInSeconds = 60,
18+
retries = 3
19+
)
20+
21+
@Test
22+
fun `matches handles workerLockDurationInMilliseconds`() {
23+
val subscription = TaskSubscriptionHandle(
24+
taskType = TaskType.EXTERNAL,
25+
restrictions = mapOf("workerLockDurationInMilliseconds" to "5000"),
26+
taskDescriptionKey = "topic",
27+
payloadDescription = null,
28+
action = { _, _ -> },
29+
termination = { }
30+
)
31+
val externalTask: ExternalTask = mock()
32+
whenever(externalTask.topicName).thenReturn("topic")
33+
34+
with(taskDelivery) {
35+
assertThat(subscription.matches(externalTask)).isTrue()
36+
}
37+
}
38+
39+
@Test
40+
fun `matches returns false for unknown restriction`() {
41+
val subscription = TaskSubscriptionHandle(
42+
taskType = TaskType.EXTERNAL,
43+
restrictions = mapOf("unknown" to "value"),
44+
taskDescriptionKey = "topic",
45+
payloadDescription = null,
46+
action = { _, _ -> },
47+
termination = { }
48+
)
49+
val externalTask: ExternalTask = mock()
50+
whenever(externalTask.topicName).thenReturn("topic")
51+
52+
with(taskDelivery) {
53+
assertThat(subscription.matches(externalTask)).isFalse()
54+
}
55+
}
56+
}

0 commit comments

Comments
 (0)