我编写了一个sqs异步发送函数,将数据发送到sqs,如下所示:
CompletableFuture<SendMessageResult> future = new CompletableFuture<>();
sqs.sendMessageAsync(request, new AsyncHandler<SendMessageRequest, SendMessageResult>() {
@Override
public void onError(Exception exception) {
future.completeExceptionally(exception);
}
@Override
public void onSuccess(SendMessageRequest request, SendMessageResult sendMessageResult) {
future.complete(sendMessageResult);
}
});
return future;
现在我尝试使用mockito模拟它,下面是模拟它的代码:
SendMessageResult sendMessageResult = new SendMessageResult();
sendMessageResult.setMessageId("Dakota Johnson");
sendMessageResult.setMD5OfMessageBody("It rocks");
doReturn(CompletableFuture.completedFuture(sendMessageResult)).when(sqs).sendMessageAsync(any(SendMessageRequest.class), any());
SendMessageRequest request = new SendMessageRequest();
request.setMessageBody("Dakota Johsnon");
request.setQueueUrl("None");
SendMessageResult cf = sqsProducer.sendMessage(request).get();
System.out.println(cf.getMessageId());
函数未完成,将进入无限循环。你能建议一下为什么它会进入无限循环,以及如何纠正这个问题吗?
暂无答案!
目前还没有任何答案,快来回答吧!