in my microservice I am trying to introduce retry at the time of saving record into the database
. that is actually working. but I need to test it in lower env without bringing our DB down. for that I googled and found chaos monkey
is an option for the same. so I introduced the same in my code.
below is my service class.
public class DemoService {
@Autowired
private DemoRepo demoRepo;
static private int i=0;
@Retryable(value={SQLException.class},maxAttempts = 3, backoff = @Backoff(delay = 1000))
public Demo save(Demo demo){
log.info("Retry is working"+(i+1));
return demoRepo.save(demo);
}
}
`
and below is my application.yml
file.
spring:
jpa:
hibernate:
ddl-auto: update
datasource:
url: jdbc:mysql://localhost:3306/chaostest
username: root
password: 1234
driver-class-name: com.mysql.cj.jdbc.Driver
profiles:
active: chaos-monkey
chaos:
monkey:
enabled: true
assaults:
exceptionsActive: true
exception:
type: java.sql.SQLException
level: 5
watcher:
demoRepo: true
logging:
level:
de:
codecentric:
spring:
boot:
chaos:
monkey: DEBUG
The problem is chaos monkey is not creating any issue for database. my transaction is getting saved on first time only. I want to test if retry is working properly?
- what changes I need to do on configuration or code so that chaos-monkey works properly
- is there any other way to test the same without bringing DB down?