fix(lastleg): preserve followup timestamp on replay
This commit is contained in:
+3
-1
@@ -67,7 +67,9 @@ public class AppointmentFollowupService {
|
||||
value.setStage(request.stage()); value.setVersion(request.expectedVersion()+1); value.setContactedParty(clean(request.contactedParty()));
|
||||
value.setResult(request.result().trim()); value.setNextAction(clean(request.nextAction())); value.setFollowupDate(request.followupDate());
|
||||
value.setOperatorId(operatorId); value.setOperatorName(clean(operatorName)); value.setCommandKey(request.idempotencyKey());
|
||||
value.setRequestHash(hash); value.setCreatedAt(LocalDateTime.now(ZoneOffset.UTC));
|
||||
value.setRequestHash(hash);
|
||||
// Return the same precision that DATETIME(3) can persist, including the first response.
|
||||
value.setCreatedAt(LocalDateTime.now(ZoneOffset.UTC).truncatedTo(java.time.temporal.ChronoUnit.MILLIS));
|
||||
try { mapper.insert(value); }
|
||||
catch (org.springframework.dao.DuplicateKeyException conflict) {
|
||||
var raced = mapper.command(sourceKey,customerId,request.stage(),request.idempotencyKey());
|
||||
|
||||
+8
@@ -35,6 +35,14 @@ class AppointmentFollowupPersistenceTest {
|
||||
assertThrows(RuntimeException.class, () -> mapper.insert(record(13L,"DRAYAGE_CONTACT",2,"key-a")));
|
||||
assertThrows(RuntimeException.class, () -> mapper.insert(record(14L,"DRAYAGE_CONTACT",1,"key-b")));
|
||||
assertEquals(2,mapper.count("ORDER:1","A"));
|
||||
var sources=org.mockito.Mockito.mock(AppointmentSourceService.class);
|
||||
org.mockito.Mockito.when(sources.resolve("ORDER:1","A",null)).thenReturn(new AppointmentSourceService.Source(
|
||||
"ORDER:1","A",1L,"IN-1",null,"CONTAINER","100","US warehouse","FBA:ONT8","ONT8",20,"ORDER:1",true,java.util.List.of()));
|
||||
var service=new AppointmentFollowupService(sources,mapper,new com.fasterxml.jackson.databind.ObjectMapper().findAndRegisterModules());
|
||||
var command=new AppointmentFollowupService.Save("FBA_RECEIVING",1,"timestamp-replay",null,"Test contact",null,null);
|
||||
var saved=service.save("ORDER:1","A",command,"operator","Operator");
|
||||
var replay=service.save("ORDER:1","A",command,"operator","Operator");
|
||||
assertEquals(saved,replay,"Persisted timestamp precision must not change the response on retry");
|
||||
}
|
||||
}
|
||||
private static AppointmentFollowup record(long id,String stage,int version,String key) {
|
||||
|
||||
Reference in New Issue
Block a user