java - 为什么 `blockingGet()` 有效,但 `assertValue()` 在 RxJava 中写入然后读取 DB 时不起作用?
问题描述
我正在运行一个测试,我运行一个写,然后读操作:
emailRepository.insertEmail(email); // Returns a Completable
emailRepository.getEmail(email); // returns a Maybe<String>
如果我尝试使用TestObserver<String>
以下方法对其进行测试,我会得到一个空Maybe
的getEmail()
并且测试失败:
emailRepository.insertEmail(email)
.andThen(Maybe.defer(() -> emailRepository.getEmail(email)))
.test()
.assertValue(email); // fails -- empty Maybe
但是,如果我使用 运行它blockingGet()
,则相同的测试有效:
String emailFromDb = emailRepository.insertEmail(email)
.andThen(Maybe.defer(() -> emailRepository.getEmail(email)))
.blockingGet();
assertValue(email,emailFromDb); // succeeds
我认为通过链接该test()
方法可以降低竞争条件的风险,但奇怪的是,情况似乎并非如此。
这可能只是一个巧合blockingGet()
吗?我的理解是,一旦将任务移交给数据库(在本例中为 MySql),Completable
就会完成,但数据库可能还没有完成写入。但如果是这样的话,那么我不应该看到它有时也会失败blockingGet()
吗?还是我在这里误解了一些东西?
解决方案
推荐阅读
- unit-testing - 单元测试 - 棱镜 - Xamarin.Forms - INavigationService 问题
- android - 在颤动中使用图像列表多重上传图像
- python - Python:如何在浮点数中打印 100.0 而不是 100
- unit-testing - 使用涉及 dynamo db 的 xunit 进行单元测试
- node.js - 如何使用 express 和 multer 将图像从 Angular 发送到 Node JS?
- javascript - JavaScript Youtube Search API v3:清除结果和验证功能
- reactjs - 如何在反应中将状态变量值传递给非子组件
- plugins - 在超级账本结构中收取交易费用的桥接协议
- css - 如何修复未知属性:Visual Studio 代码中的“scroll-snap-align”错误
- apache - 启用 SSL 后 Tomcat 服务未启动 - https