objectbox / objectbox/objectbox-java
Make it easier to reliably test data observers
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 4.6k
- Forks
- 311
- PR merge metrics
- No merged PRs in 30d
Description
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.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the runInTx, TestObserver, and query.subscribe().observer sequence shown in the issue, then review the ObjectBox data-observer and transaction behavior it exercises. Done means a reliable way to wait for notifications from the preceding transaction, demonstrated by a test that consistently receives the expected single value.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, kotlin
- Domain
- databases, testing
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100