I am trying to write unit test for RateLimiter using guava.
下面是我的服务班级,我在那里增加了Limiter。 我想对参加服务班的许可证发放方法。 我将胶片/薄膜定为3。
任何人都能够帮助我进行单位测试,以检查从事或不从事工作的比率。
- any single method
- multiple methods
@Service
class Service{
private RateLimiter rateLimiter;
@Autowired
public void setRateLimiter(RateLimiter rateLimiter) {
this.rateLimiter = rateLimiter;
}
public method1(){
rateLimiter.acquire();
System.out.println(new Date() + ": Beep");
xyzMethod();
}
public method2(){
rateLimiter.acquire();
System.out.println(new Date() + ": Beep");
xyzMethod();
}
public method3(){
rateLimiter.acquire();
System.out.println(new Date() + ": Beep");
xyzMethod();
}
}
@Configuration
public class RatelimiterConfig {
@Value("${tps}")
private int tps;
@Bean
public RateLimiter rateLimiter(){
return RateLimiter.create(tps);
}
}