Test #1
@@ -6,7 +6,6 @@ import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestHeader;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
|
||||
/** Internal Warehouse contract for a customer's default overseas storage fees. */
|
||||
@FeignClient(name = "warehouse-service", contextId = "overseasStorageFeeClient",
|
||||
@@ -20,9 +19,9 @@ public interface OverseasStorageFeeClient {
|
||||
|
||||
@DeleteMapping("/defaults")
|
||||
ApiResponse<Void> compensate(@RequestHeader("X-Internal-Service-Token") String token,
|
||||
@RequestParam long tenantId,
|
||||
@RequestParam String initializationKey);
|
||||
@RequestBody CompensationRequest request);
|
||||
|
||||
record InitializationRequest(long tenantId, long operatorId, String initializationKey) { }
|
||||
record InitializationResponse(Long configId, boolean createdByThisInitialization) { }
|
||||
record CompensationRequest(long tenantId, String initializationKey) { }
|
||||
}
|
||||
|
||||
+2
-1
@@ -72,7 +72,8 @@ public class OverseasStorageFeeInitializationService {
|
||||
RuntimeException last = null;
|
||||
for (int attempt = 1; attempt <= MAX_ATTEMPTS; attempt++) {
|
||||
try {
|
||||
ApiResponse<Void> response = client.compensate(internalToken, tenantId, key);
|
||||
ApiResponse<Void> response = client.compensate(internalToken,
|
||||
new OverseasStorageFeeClient.CompensationRequest(tenantId, key));
|
||||
if (response != null && response.successful()) return;
|
||||
last = unavailable(response);
|
||||
} catch (RuntimeException ex) { last = ex; }
|
||||
|
||||
+2
-2
@@ -33,10 +33,10 @@ class OverseasStorageFeeInitializationServiceTest {
|
||||
|
||||
@Test void retriesThreeTimesWithDeterministicKey() {
|
||||
when(client.initialize(anyString(), any())).thenThrow(new RuntimeException("timeout"));
|
||||
when(client.compensate(anyString(), anyLong(), anyString())).thenReturn(ApiResponse.success(null));
|
||||
when(client.compensate(anyString(), any(OverseasStorageFeeClient.CompensationRequest.class))).thenReturn(ApiResponse.success(null));
|
||||
BizException error = assertThrows(BizException.class, () -> service.initialize(208L, 9L));
|
||||
assertEquals(ResultCode.SERVICE_UNAVAILABLE, error.getResultCode());
|
||||
verify(client, times(3)).initialize(anyString(), any(OverseasStorageFeeClient.InitializationRequest.class));
|
||||
verify(client).compensate("internal-token", 208L, "iam-customer-create-overseas-fee:208");
|
||||
verify(client).compensate("internal-token", new OverseasStorageFeeClient.CompensationRequest(208L, "iam-customer-create-overseas-fee:208"));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user