fix: preserve hold binding replays
This commit is contained in:
+49
-2
@@ -31,7 +31,7 @@ class LoadingModelBridgeServiceTest {
|
||||
@InjectMocks LoadingModelBridgeService service;
|
||||
|
||||
@Test
|
||||
void heldInboundOrPlanBlocksEveryPreloadBindingWriteBoundary() {
|
||||
void heldInboundOrPlanBlocksEveryNewPreloadBindingWriteBoundary() {
|
||||
doThrow(new BizException(ResultCode.CONFLICT, "入库单已扣货"))
|
||||
.when(inboundHoldGuard).requireInboundNotHeld(10L, 20L);
|
||||
doThrow(new BizException(ResultCode.CONFLICT, "入库单已扣货"))
|
||||
@@ -45,7 +45,41 @@ class LoadingModelBridgeServiceTest {
|
||||
40L, 10L, 20L, 7L, "admin", "incremental-held"))
|
||||
.isInstanceOf(BizException.class).hasMessageContaining("扣货");
|
||||
|
||||
verifyNoInteractions(repository);
|
||||
verify(repository).byIdempotency(7L, "bind-held");
|
||||
verify(repository, times(2)).byPair(10L, 20L, 40L);
|
||||
verify(repository).loadingPlan(40L);
|
||||
verifyNoMoreInteractions(repository);
|
||||
}
|
||||
|
||||
@Test
|
||||
void holdDoesNotBreakReadOnlyIdempotentBindingReplays() {
|
||||
var replay = new PreloadLoadingPlanLinkEntity();
|
||||
replay.setRequestHash(hashFor(10L, 20L, 40L, 1, 1));
|
||||
when(repository.byIdempotency(7L, "bind-replay")).thenReturn(replay);
|
||||
Link linked = link("PENDING", 2, "EDITING", 3, 8);
|
||||
when(repository.byInbound(10L, 20L)).thenReturn(List.of(linked));
|
||||
|
||||
assertThat(service.bind(10L, 20L, 40L, 7L, "admin", "bind-replay",
|
||||
new BindRequest(1, 1))).isEqualTo(linked);
|
||||
|
||||
verifyNoInteractions(inboundHoldGuard);
|
||||
verify(repository, never()).insert(any());
|
||||
}
|
||||
|
||||
@Test
|
||||
void holdDoesNotBreakReadOnlyPlanOrIncrementalReplays() {
|
||||
when(repository.loadingPlan(40L)).thenReturn(new LoadingPlanSnapshot(40L, 50L, "C1", "LOADING", 4));
|
||||
when(repository.allocatedScopes(40L)).thenReturn(List.of(new AllocationScope(10L, 20L, 8, "WAIT_SPLIT")));
|
||||
when(repository.byPair(10L, 20L, 40L)).thenReturn(new PreloadLoadingPlanLinkEntity());
|
||||
Link linked = link("CONFIRMED", 3, "LOADING", 4, 8);
|
||||
when(repository.byLoadingPlan(40L)).thenReturn(List.of(linked));
|
||||
|
||||
assertThat(service.bindAllocatedBeforeLoading(40L, 7L, "admin", "push-replay"))
|
||||
.containsExactly(linked);
|
||||
service.bindIncrementalAllocation(40L, 10L, 20L, 7L, "admin", "incremental-replay");
|
||||
|
||||
verifyNoInteractions(inboundHoldGuard);
|
||||
verify(repository, never()).insert(any());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -244,4 +278,17 @@ class LoadingModelBridgeServiceTest {
|
||||
return new Link(1L, 10L, 20L, 30L, preloadStatus, preloadVersion, 40L, 50L, "C1",
|
||||
loadingStatus, loadingVersion, packages, LocalDateTime.now());
|
||||
}
|
||||
|
||||
private static String hashFor(long tenantId, long inboundId, long loadingPlanId,
|
||||
int preloadVersion, int loadingPlanVersion) {
|
||||
try {
|
||||
var digest = java.security.MessageDigest.getInstance("SHA-256");
|
||||
String value = tenantId + "|" + inboundId + "|" + loadingPlanId + "|"
|
||||
+ preloadVersion + "|" + loadingPlanVersion;
|
||||
return java.util.HexFormat.of().formatHex(digest.digest(
|
||||
value.getBytes(java.nio.charset.StandardCharsets.UTF_8)));
|
||||
} catch (java.security.NoSuchAlgorithmException exception) {
|
||||
throw new AssertionError(exception);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user