我有使用 java8 和响应式测试异步执行的存储库:
zadd的界面:
Observable<Long> zadd(K key, double score, V member);
public class TargetClass()
{
..
public void executeMethod(List<String> input) {
input.forEach(item -> redisConnection.reactive().zadd(...).subscribe(
result -> log.info("Success")
error -> log.error("Failed...")
));
}
..
}
我的junit测试代码:
@Test
public void testMethod() {
TargetClass targetClass=new TargetClass();
targetClass.executeMethod(Arrays.asList("input1", "input2", "input3"));
//as you can see I must put here Thread.sleep in order to let my execution to finish before continue since we have dependency on it
try {
Thread.sleep(4000);
} catch (InterruptedException e) {
e.printStackTrace();
}
//continue with testing..
如何修改我的代码部分权限。Thread.sleep
添加让异步方法代码发生的感觉不正确
谢谢,雷。