spring-boot-@sqslistener和@spybean不在一起工作?

aydmsdu9  于 2021-07-04  发布在  Java
关注(0)|答案(0)|浏览(280)

我有一个与aws-sqs集成的简单spring引导应用程序。在集成测试中,我尝试监视用@sqslistener注解的方法,得到了一个bean有时不被监视的行为。
您可以在此处查看示例项目:https://github.com/sanych/aws-sqs-spybean-troubleshooting
mvn clean verify 在此日志中,我们可能会注意到,三分之二的测试方法被成功发现:

2020-09-06 15:39:23.597  INFO 18372 --- [           main] com.aws.test.demo.SQSListenerIT          : Started SQSListenerIT in 0.813 seconds (JVM running for 24.024)
2020-09-06 15:39:23.604  WARN 18372 --- [           main] com.aws.test.demo.SQSListenerIT          : calling class com.aws.test.demo.SQSListener$MockitoMock$1506819983
2020-09-06 15:39:23.604  WARN 18372 --- [           main] com.aws.test.demo.SQSListenerIT          : sendMessage to queue: test 1
2020-09-06 15:39:23.810  WARN 18372 --- [enerContainer-2] com.aws.test.demo.SQSListener            : id: class com.aws.test.demo.SQSListener$MockitoMock$1506819983, received: 'test 1'
2020-09-06 15:39:23.929  WARN 18372 --- [           main] com.aws.test.demo.SQSListenerIT          : calling class com.aws.test.demo.SQSListener$MockitoMock$1506819983
2020-09-06 15:39:23.929  WARN 18372 --- [           main] com.aws.test.demo.SQSListenerIT          : sendMessage to queue: test 2
2020-09-06 15:39:24.052  WARN 18372 --- [enerContainer-2] com.aws.test.demo.SQSListener            : id: class com.aws.test.demo.SQSListener, received: 'test 2'
2020-09-06 15:39:29.148  WARN 18372 --- [           main] com.aws.test.demo.SQSListenerIT          : calling class com.aws.test.demo.SQSListener$MockitoMock$1506819983
2020-09-06 15:39:29.148  WARN 18372 --- [           main] com.aws.test.demo.SQSListenerIT          : sendMessage to queue: test 3
2020-09-06 15:39:29.175  WARN 18372 --- [enerContainer-2] com.aws.test.demo.SQSListener            : id: class com.aws.test.demo.SQSListener$MockitoMock$1506819983, received: 'test 3'
[ERROR] Tests run: 3, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 6.468 s <<< FAILURE! - in com.aws.test.demo.SQSListenerIT
[ERROR] test2  Time elapsed: 5.218 s  <<< ERROR!
org.awaitility.core.ConditionTimeoutException:
Assertion condition defined as a lambda expression in com.aws.test.demo.SQSListenerIT
Wanted but not invoked:
SQSListener.listen(<any string>);
-> at com.aws.test.demo.SQSListenerIT.lambda$sendMessageFromFileAndWaitForListenerToRead$0(SQSListenerIT.java:57)
Actually, there were zero interactions with this mock.
 within 5 seconds.
        at com.aws.test.demo.SQSListenerIT.sendMessageFromFileAndWaitForListenerToRead(SQSListenerIT.java:57)
        at com.aws.test.demo.SQSListenerIT.test2(SQSListenerIT.java:42)
Caused by: org.mockito.exceptions.verification.WantedButNotInvoked:

Wanted but not invoked:
SQSListener.listen(<any string>);
-> at com.aws.test.demo.SQSListenerIT.lambda$sendMessageFromFileAndWaitForListenerToRead$0(SQSListenerIT.java:57)
Actually, there were zero interactions with this mock.
        at com.aws.test.demo.SQSListenerIT.lambda$sendMessageFromFileAndWaitForListenerToRead$0(SQSListenerIT.java:57)

我错过什么了吗?

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题