3
3
import ca .uhn .fhir .batch2 .api .IJobPersistence ;
4
4
import ca .uhn .fhir .batch2 .model .JobInstance ;
5
5
import ca .uhn .fhir .batch2 .model .StatusEnum ;
6
+ import ca .uhn .fhir .batch2 .model .WorkChunk ;
6
7
import ca .uhn .fhir .batch2 .model .WorkChunkStatusEnum ;
7
8
import ca .uhn .fhir .jpa .dao .data .IBatch2WorkChunkRepository ;
8
9
import ca .uhn .fhir .jpa .entity .Batch2WorkChunkEntity ;
9
10
import ca .uhn .fhir .jpa .test .BaseJpaR4Test ;
11
+ import ca .uhn .fhir .jpa .util .RandomTextUtils ;
10
12
import org .junit .jupiter .api .Test ;
11
13
import org .springframework .beans .factory .annotation .Autowired ;
12
14
13
15
import java .time .Instant ;
14
16
import java .time .temporal .ChronoUnit ;
15
17
import java .util .Date ;
16
18
import java .util .List ;
19
+ import java .util .Optional ;
17
20
18
21
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 ;
19
24
20
25
public class JpaJobPersistenceImplIT extends BaseJpaR4Test {
21
26
@@ -24,6 +29,38 @@ public class JpaJobPersistenceImplIT extends BaseJpaR4Test {
24
29
@ Autowired
25
30
private IJobPersistence myJobPersistence ;
26
31
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
+
27
64
@ Test
28
65
public void onWorkChunkPollDelay_withValidData_updatesDeadlineAndPollAttemptCount () {
29
66
// setup
0 commit comments