fix: converge inbound pallets and retries

This commit is contained in:
2026-09-11 00:06:57 +08:00
parent ed12769858
commit 2bd12f8a5f
11 changed files with 65 additions and 15 deletions
@@ -132,6 +132,25 @@ class WarehousePalletBatchServiceTest {
assertThat(response.items()).extracting(value -> value.palletCode()).containsExactly("PAL-301");
}
@Test
void compensatedSourcePalletCodeReusesTheExistingIdlePhysicalPallet() {
when(batches.insertIgnore(any())).thenReturn(1);
WarehousePalletEntity existing = pallet(301L, 401L, "DP-260910-0001");
existing.setStatus("IDLE");
when(resources.reusablePublicPallet(WAREHOUSE, "DP-260910-0001")).thenReturn(existing);
when(locks.reserve(any())).thenReturn(lockResponse(CUSTOMER_A, 501L));
var request = new WarehousePalletBatchRequests.EnsureReserved(WAREHOUSE, "retry-container", List.of(
new WarehousePalletBatchRequests.Item(CUSTOMER_A, "container:dropship-a:1", "PLAN-A", 1,
"STANDARD", null, "DP-260910-0001")));
var response = service.ensureReserved(request);
assertThat(response.items()).extracting(value -> value.palletId()).containsExactly(301L);
assertThat(response.items()).extracting(value -> value.palletCode()).containsExactly("DP-260910-0001");
verify(resources, never()).createPallet(anyLong(), anyLong(), any());
verify(locks).reserve(any());
}
@Test
void concurrentSameRequestReplaysWinningBatchWithoutCreatingResources() {
AtomicReference<WarehousePalletBatchEntity> inserted = new AtomicReference<>();