Skip to content

Commit d812a08

Browse files
authored
truncate error messages for storage on workchunks (hapifhir#6717)
1 parent 4d66c6c commit d812a08

File tree

3 files changed

+46
-1
lines changed

3 files changed

+46
-1
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
type: fix
3+
issue: 6716
4+
jira: SMILE-9676
5+
title: "Fixed an issue that was caused by
6+
batch jobs attempting to store error
7+
messages exceeding 500 characters.
8+
"

hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/entity/Batch2WorkChunkEntity.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ public Batch2WorkChunkEntity(
188188
myStartTime = theStartTime;
189189
myUpdateTime = theUpdateTime;
190190
myEndTime = theEndTime;
191-
myErrorMessage = theErrorMessage;
191+
setErrorMessage(theErrorMessage);
192192
myErrorCount = theErrorCount;
193193
myRecordsProcessed = theRecordsProcessed;
194194
myWarningMessage = theWarningMessage;

hapi-fhir-jpaserver-test-utilities/src/test/java/ca/uhn/fhir/jpa/batch2/JpaJobPersistenceImplIT.java

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,24 @@
33
import ca.uhn.fhir.batch2.api.IJobPersistence;
44
import ca.uhn.fhir.batch2.model.JobInstance;
55
import ca.uhn.fhir.batch2.model.StatusEnum;
6+
import ca.uhn.fhir.batch2.model.WorkChunk;
67
import ca.uhn.fhir.batch2.model.WorkChunkStatusEnum;
78
import ca.uhn.fhir.jpa.dao.data.IBatch2WorkChunkRepository;
89
import ca.uhn.fhir.jpa.entity.Batch2WorkChunkEntity;
910
import ca.uhn.fhir.jpa.test.BaseJpaR4Test;
11+
import ca.uhn.fhir.jpa.util.RandomTextUtils;
1012
import org.junit.jupiter.api.Test;
1113
import org.springframework.beans.factory.annotation.Autowired;
1214

1315
import java.time.Instant;
1416
import java.time.temporal.ChronoUnit;
1517
import java.util.Date;
1618
import java.util.List;
19+
import java.util.Optional;
1720

1821
import static org.junit.jupiter.api.Assertions.assertEquals;
22+
import static org.junit.jupiter.api.Assertions.assertNotNull;
23+
import static org.junit.jupiter.api.Assertions.assertTrue;
1924

2025
public class JpaJobPersistenceImplIT extends BaseJpaR4Test {
2126

@@ -24,6 +29,38 @@ public class JpaJobPersistenceImplIT extends BaseJpaR4Test {
2429
@Autowired
2530
private IJobPersistence myJobPersistence;
2631

32+
@Test
33+
public void createWorkChunk_withLongErrorMessage_shouldNotFail() {
34+
// setup
35+
String errorMessage = RandomTextUtils.newSecureRandomAlphaNumericString(700);
36+
37+
JobInstance jobInstance = new JobInstance();
38+
jobInstance.setJobDefinitionId("job-def-id");
39+
jobInstance.setStatus(StatusEnum.IN_PROGRESS);
40+
jobInstance.setJobDefinitionVersion(1);
41+
String instanceId = myJobPersistence.storeNewInstance(jobInstance);
42+
43+
WorkChunk chunk = new WorkChunk();
44+
chunk.setId("id");
45+
chunk.setInstanceId(instanceId);
46+
chunk.setJobDefinitionId(jobInstance.getJobDefinitionId());
47+
chunk.setJobDefinitionVersion(jobInstance.getJobDefinitionVersion());
48+
chunk.setStatus(WorkChunkStatusEnum.FAILED);
49+
chunk.setCreateTime(new Date());
50+
chunk.setTargetStepId("step-id");
51+
chunk.setErrorMessage(errorMessage);
52+
53+
// test
54+
myJobPersistence.createWorkChunk(chunk);
55+
56+
// validate
57+
Optional<Batch2WorkChunkEntity> savedOp = myWorkChunkRepository.findById("id");
58+
assertTrue(savedOp.isPresent());
59+
Batch2WorkChunkEntity saved = savedOp.get();
60+
assertNotNull(saved.getErrorMessage());
61+
assertTrue(errorMessage.startsWith(saved.getErrorMessage()));
62+
}
63+
2764
@Test
2865
public void onWorkChunkPollDelay_withValidData_updatesDeadlineAndPollAttemptCount() {
2966
// setup

0 commit comments

Comments
 (0)