fix: complete pallet code cross-region flow

This commit is contained in:
2026-09-09 19:14:47 +08:00
parent 7678fd85ff
commit e30255ff58
9 changed files with 175 additions and 9 deletions
@@ -86,6 +86,28 @@ class WarehousePalletBatchServiceTest {
.containsExactly("container:plan-a:1", "container:plan-b:2");
}
@Test
void missingSourcePalletCodeUsesWarehouseGeneratedPhysicalCode() {
when(batches.insertIgnore(any())).thenReturn(1);
when(resources.createPallet(anyLong(), anyLong(), any())).thenReturn(301L);
when(resources.pallet(0L, WAREHOUSE, 301L)).thenReturn(pallet(301L, 401L, "PAL-301"));
when(locks.reserve(any())).thenAnswer(call -> {
WarehouseResourceLockRequests.ReserveRequest value = call.getArgument(0);
return lockResponse(value.customerId(), 501L);
});
var request = new WarehousePalletBatchRequests.EnsureReserved(WAREHOUSE, "container-generated", List.of(
new WarehousePalletBatchRequests.Item(CUSTOMER_A, "container:generated:1", "PLAN-G", 1,
"STANDARD", null, null)));
var response = service.ensureReserved(request);
ArgumentCaptor<PalletRequests.SaveRequest> saves = ArgumentCaptor.forClass(PalletRequests.SaveRequest.class);
verify(resources).createPallet(org.mockito.ArgumentMatchers.eq(WarehouseResourceService.PUBLIC_RESOURCE_SCOPE),
org.mockito.ArgumentMatchers.eq(WAREHOUSE), saves.capture());
assertThat(saves.getValue().palletCode()).isNull();
assertThat(response.items()).extracting(value -> value.palletCode()).containsExactly("PAL-301");
}
@Test
void concurrentSameRequestReplaysWinningBatchWithoutCreatingResources() {
AtomicReference<WarehousePalletBatchEntity> inserted = new AtomicReference<>();