Skip to content

Commit

Permalink
Fix fault injection policy loading issue
Browse files Browse the repository at this point in the history
  • Loading branch information
chenzhiguo committed Dec 30, 2024
1 parent 64873fe commit 390d473
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit 390d473

Please sign in to comment.