fix(warehouse-overseas): avoid pallet batch gap lock

This commit is contained in:
2026-09-08 23:59:50 +08:00
parent a88a04fd24
commit 93704a24ce
4 changed files with 8 additions and 9 deletions
@@ -33,6 +33,7 @@ class WarehousePalletBatchContractTest {
.contains("/internal/v1/warehouse-pallet-batches/confirm:")
.contains("/internal/v1/warehouse-pallet-batches/compensate:")
.contains("业务冲突仍为HTTP 200且响应体code=A0409")
.contains("commandKey幂等作用域为(warehouseId,batchKey,commandKey),无需全局唯一")
.contains("businessKey: { type: string, minLength: 1, maxLength: 100 }")
.contains("palletCode: { type: string, maxLength: 64 }")
.doesNotContain("'409':");
@@ -19,6 +19,7 @@ import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.ArgumentCaptor;
import org.mockito.InOrder;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import org.springframework.test.util.ReflectionTestUtils;
@@ -74,6 +75,7 @@ class WarehousePalletBatchServiceTest {
ArgumentCaptor<Long> scope = ArgumentCaptor.forClass(Long.class);
verify(resources, times(2)).createPallet(scope.capture(), anyLong(), any(PalletRequests.SaveRequest.class));
assertThat(scope.getAllValues()).containsOnly(WarehouseResourceService.PUBLIC_RESOURCE_SCOPE);
verify(batches, never()).lockByKey(WAREHOUSE, "container-1");
ArgumentCaptor<WarehouseResourceLockRequests.ReserveRequest> reservations =
ArgumentCaptor.forClass(WarehouseResourceLockRequests.ReserveRequest.class);
verify(locks, times(2)).reserve(reservations.capture());
@@ -100,6 +102,9 @@ class WarehousePalletBatchServiceTest {
assertThat(response.replayed()).isTrue();
assertThat(response.batchId()).isEqualTo(inserted.get().getId());
InOrder order = org.mockito.Mockito.inOrder(batches);
order.verify(batches).insertIgnore(any());
order.verify(batches).lockByKey(WAREHOUSE, "container-1");
verify(resources, never()).createPallet(anyLong(), anyLong(), any());
verify(locks, never()).reserve(any());
}