diff --git a/joylive-core/joylive-governance-api/src/main/java/com/jd/live/agent/governance/invoke/fault/delay/DelayFaultInjection.java b/joylive-core/joylive-governance-api/src/main/java/com/jd/live/agent/governance/invoke/fault/delay/DelayFaultInjection.java index 4f229b636..247c1d503 100644 --- a/joylive-core/joylive-governance-api/src/main/java/com/jd/live/agent/governance/invoke/fault/delay/DelayFaultInjection.java +++ b/joylive-core/joylive-governance-api/src/main/java/com/jd/live/agent/governance/invoke/fault/delay/DelayFaultInjection.java @@ -35,9 +35,8 @@ public class DelayFaultInjection implements FaultInjection { @Override public void acquire(FaultInjectionPolicy policy) { - if (policy.getDelayTimeMs() != null && policy.getDelayTimeMs() > 0 && - (policy.getPercent() == null - || policy.getPercent() <= 0 + if (policy.getDelayTimeMs() > 0 && + (policy.getPercent() <= 0 || ThreadLocalRandom.current().nextInt(100) < policy.getPercent())) { try { if (logger.isDebugEnabled()) { diff --git a/joylive-core/joylive-governance-api/src/main/java/com/jd/live/agent/governance/invoke/fault/error/ErrorFaultInjection.java b/joylive-core/joylive-governance-api/src/main/java/com/jd/live/agent/governance/invoke/fault/error/ErrorFaultInjection.java index 5e9adf80f..df0624e72 100644 --- a/joylive-core/joylive-governance-api/src/main/java/com/jd/live/agent/governance/invoke/fault/error/ErrorFaultInjection.java +++ b/joylive-core/joylive-governance-api/src/main/java/com/jd/live/agent/governance/invoke/fault/error/ErrorFaultInjection.java @@ -32,8 +32,7 @@ public class ErrorFaultInjection implements FaultInjection { @Override public void acquire(FaultInjectionPolicy policy) { - if (policy.getPercent() == null - || policy.getPercent() <= 0 + if (policy.getPercent() <= 0 || ThreadLocalRandom.current().nextInt(100) < policy.getPercent()) { String errorMsg = policy.getErrorMsg() == null ? "Error by fault injection" : policy.getErrorMsg(); throw new FaultException(policy.getErrorCode(), errorMsg); diff --git a/joylive-core/joylive-governance-api/src/main/java/com/jd/live/agent/governance/policy/service/fault/FaultInjectionPolicy.java b/joylive-core/joylive-governance-api/src/main/java/com/jd/live/agent/governance/policy/service/fault/FaultInjectionPolicy.java index 222a6d16e..b9cf372e8 100644 --- a/joylive-core/joylive-governance-api/src/main/java/com/jd/live/agent/governance/policy/service/fault/FaultInjectionPolicy.java +++ b/joylive-core/joylive-governance-api/src/main/java/com/jd/live/agent/governance/policy/service/fault/FaultInjectionPolicy.java @@ -44,11 +44,11 @@ public class FaultInjectionPolicy extends PolicyId implements PolicyInheritWithI private RelationType relationType; - private Integer percent; + private int percent; - private Long delayTimeMs; + private long delayTimeMs; - private Integer errorCode; + private int errorCode; private String errorMsg;