Skip to content

Commit

Permalink
fix: use upsert instead of update for updates to UserTaskEntity (#17687)
Browse files Browse the repository at this point in the history
## Description

* Use `upsert` instead of `update` in update `UserTaskEntity`

## Related issues

closes #17615
  • Loading branch information
ralfpuchert committed Apr 24, 2024
2 parents 76b2fa1 + 966b9bd commit c87656a
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,11 @@ private void updateUserTask(
final Map<String, Object> updateFields,
final BatchRequest batchRequest)
throws PersistenceException {
batchRequest.update(
userTaskTemplate.getFullQualifiedName(), userTaskEntity.getId(), updateFields);
batchRequest.upsert(
userTaskTemplate.getFullQualifiedName(),
userTaskEntity.getId(),
userTaskEntity,
updateFields);
LOGGER.debug(
"Updated UserTaskEntity {} with update fields {} to batch request",
userTaskEntity.getId(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ void migratedEvent() throws PersistenceException {
1L,
"elementId",
"element id");
verify(batchRequest).update("user-task-index", "1", expectedUpdateFields);
verifyUpsert(batchRequest, expectedUpdateFields);
}

@Test
Expand All @@ -140,7 +140,7 @@ void assignedEvent() throws PersistenceException {
/* then */
final Map<String, Object> expectedUpdateFields =
Map.of("assignee", "Homer Simpson", "action", "assign");
verify(batchRequest).update("user-task-index", "1", expectedUpdateFields);
verifyUpsert(batchRequest, expectedUpdateFields);
}

@Test
Expand All @@ -163,7 +163,7 @@ void unassignedEvent() throws PersistenceException {
userTaskZeebeRecordProcessor.processUserTaskRecord(batchRequest, userTaskRecord);
/* then */
final Map<String, Object> expectedUpdateFields = Map.of("assignee", "", "action", "assign");
verify(batchRequest).update("user-task-index", "1", expectedUpdateFields);
verifyUpsert(batchRequest, expectedUpdateFields);
}

@Test
Expand Down Expand Up @@ -199,7 +199,7 @@ void updatedEvent() throws PersistenceException {
"update",
"changedAttributes",
List.of("candidateUserList", "candidateGroupList", "dueDate"));
verify(batchRequest).update("user-task-index", "1", expectedUpdateFields);
verifyUpsert(batchRequest, expectedUpdateFields);
}

@Test // https://github.com/camunda/zeebe/issues/17611
Expand Down Expand Up @@ -249,7 +249,7 @@ void updateShouldIgnoreMissingAttributes() throws PersistenceException {
"dueDate",
"followUpDate",
"attribute-not-exist"));
verify(batchRequest).update("user-task-index", "1", expectedUpdateFields);
verifyUpsert(batchRequest, expectedUpdateFields);
}

@Test
Expand Down Expand Up @@ -278,7 +278,7 @@ void completedEvent() throws PersistenceException, JsonProcessingException {
"complete",
"variables",
objectMapper.writeValueAsString(variablesDueCompletion));
verify(batchRequest).update("user-task-index", "1", expectedUpdateFields);
verifyUpsert(batchRequest, expectedUpdateFields);
}

@Test
Expand All @@ -299,6 +299,14 @@ void canceledEvent() throws Exception {
userTaskZeebeRecordProcessor.processUserTaskRecord(batchRequest, userTaskRecord);
/* then */
final Map<String, Object> expectedUpdateFields = Map.of("action", "");
verify(batchRequest).update("user-task-index", "1", expectedUpdateFields);
verifyUpsert(batchRequest, expectedUpdateFields);
}

private void verifyUpsert(
final BatchRequest batchRequest, final Map<String, Object> expectedUpdateFields)
throws PersistenceException {
verify(batchRequest)
.upsert(
eq("user-task-index"), eq("1"), any(UserTaskEntity.class), eq(expectedUpdateFields));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,11 @@ private void updateUserTask(
final Map<String, Object> updateFields,
final BatchRequest batchRequest)
throws PersistenceException {
batchRequest.update(
userTaskTemplate.getFullQualifiedName(), userTaskEntity.getId(), updateFields);
batchRequest.upsert(
userTaskTemplate.getFullQualifiedName(),
userTaskEntity.getId(),
userTaskEntity,
updateFields);
LOGGER.debug(
"Updated UserTaskEntity {} with update fields {} to batch request",
userTaskEntity.getId(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ void migratedEvent() throws PersistenceException {
1L,
"elementId",
"element id");
verify(batchRequest).update("user-task-index", "1", expectedUpdateFields);
verifyUpsert(batchRequest, expectedUpdateFields);
}

@Test
Expand All @@ -140,7 +140,7 @@ void assignedEvent() throws PersistenceException {
/* then */
final Map<String, Object> expectedUpdateFields =
Map.of("assignee", "Homer Simpson", "action", "assign");
verify(batchRequest).update("user-task-index", "1", expectedUpdateFields);
verifyUpsert(batchRequest, expectedUpdateFields);
}

@Test
Expand All @@ -163,10 +163,9 @@ void unassignedEvent() throws PersistenceException {
userTaskZeebeRecordProcessor.processUserTaskRecord(batchRequest, userTaskRecord);
/* then */
final Map<String, Object> expectedUpdateFields = Map.of("assignee", "", "action", "assign");
verify(batchRequest).update("user-task-index", "1", expectedUpdateFields);
verifyUpsert(batchRequest, expectedUpdateFields);
}

@Test
void updatedEvent() throws PersistenceException {
/* given */
final var batchRequest = mock(BatchRequest.class);
Expand All @@ -179,7 +178,7 @@ void updatedEvent() throws PersistenceException {
.withCandidateGroupsList(List.of("Simpsons", "Flanders"))
.withDueDate("2023-05-23T01:02:03+01:00")
.withAction("update")
.withChangedAttributes(List.of("candidateUsersList", "candidateGroupsList", "dueDate"))
.withChangedAttributes(List.of("candidateUserList", "candidateGroupList", "dueDate"))
.build();
when(userTaskTemplate.getFullQualifiedName()).thenReturn("user-task-index");
when(userTaskRecord.getIntent()).thenReturn(UserTaskIntent.UPDATED);
Expand All @@ -198,8 +197,8 @@ void updatedEvent() throws PersistenceException {
"action",
"update",
"changedAttributes",
List.of("candidateUsersList", "candidateGroupsList", "dueDate"));
verify(batchRequest).update("user-task-index", "1", expectedUpdateFields);
List.of("candidateUserList", "candidateGroupList", "dueDate"));
verifyUpsert(batchRequest, expectedUpdateFields);
}

@Test // https://github.com/camunda/zeebe/issues/17611
Expand Down Expand Up @@ -249,7 +248,7 @@ void updateShouldIgnoreMissingAttributes() throws PersistenceException {
"dueDate",
"followUpDate",
"attribute-not-exist"));
verify(batchRequest).update("user-task-index", "1", expectedUpdateFields);
verifyUpsert(batchRequest, expectedUpdateFields);
}

@Test
Expand Down Expand Up @@ -278,7 +277,7 @@ void completedEvent() throws PersistenceException, JsonProcessingException {
"complete",
"variables",
objectMapper.writeValueAsString(variablesDueCompletion));
verify(batchRequest).update("user-task-index", "1", expectedUpdateFields);
verifyUpsert(batchRequest, expectedUpdateFields);
}

@Test
Expand All @@ -299,6 +298,14 @@ void canceledEvent() throws Exception {
userTaskZeebeRecordProcessor.processUserTaskRecord(batchRequest, userTaskRecord);
/* then */
final Map<String, Object> expectedUpdateFields = Map.of("action", "");
verify(batchRequest).update("user-task-index", "1", expectedUpdateFields);
verifyUpsert(batchRequest, expectedUpdateFields);
}

private void verifyUpsert(
final BatchRequest batchRequest, final Map<String, Object> expectedUpdateFields)
throws PersistenceException {
verify(batchRequest)
.upsert(
eq("user-task-index"), eq("1"), any(UserTaskEntity.class), eq(expectedUpdateFields));
}
}

0 comments on commit c87656a

Please sign in to comment.