objectbox / objectbox/objectbox-java
Make it easier to reliably test data observers
还没有人认领这个 Issue。
- 主要语言
- Java
- 星标
- 4.6k
- 派生
- 311
- PR 合并指标
- 30 天内没有已合并 PR
描述
In my experience, testing data observers is somewhat brittle. Even with explicit transactions I sometimes get "delayed" notifications that have been triggered by the previous operation.
Let's take this test (ObjectBox 2.2.0 + RxJava 2):
boxStore.runInTx {
boxStore.boxFor(SomeEntity::class.java).put(SomeEntity())
}
val testObserver = TestObserver.create<Optional<SomeEntity>>()
boxStore.runInTx {
repository.find(123).subscribeWith(testObserver)
}
testObserver.awaitCount(1)
testObserver.assertValueCount(1)
Sometimes, I get a value count of 2 from the original put operation. For completeness, the code of the find() method:
fun find(id: Long): Observable<Optional<SomeEntity>> {
return Observable.create { emitter ->
val query = this.boxStore.boxFor(SomeEntity::class)
.query()
.equal(SomeEntity_.id, id)
.build()
query.subscribe().observer { result ->
emitter.onNext(result.firstOrNull().toOptional())
}
}
}
Assuming I did not misunderstand the docs or misuse the ObjectBox API, it would be great if ObjectBox could offer some method e.g. to block until all notifications triggered by the last transaction have been issued.
贡献指南
这个仓库没有索引到贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
从 issue 中所示的 runInTx、TestObserver 和 query.subscribe().observer 序列开始,然后审查该序列所涉及的 ObjectBox 数据观察器和事务行为。完成标准是有一种可靠的方式等待前一个事务发出的通知,并通过一个能够稳定接收到预期单个值的测试加以证明。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- java, kotlin
- 领域
- databases, testing
- Issue 类型
- 功能
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 25/100