objectbox / objectbox/objectbox-java

Make it easier to reliably test data observers

Aperta
#616 2 commenti 1 reazione 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

enhancement
Lingua principale
Java
Stelle
4.6k
Fork
311
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

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.

Guida per i contributori

Nessuna guida per i contributori indicizzata per questo repository

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Inizia con la sequenza runInTx, TestObserver e query.subscribe().observer mostrata nell’issue, quindi esamina il comportamento dei data observer e delle transazioni di ObjectBox che essa esercita. Il lavoro è completato quando esiste un modo affidabile per attendere le notifiche della transazione precedente, dimostrato da un test che riceve costantemente l’unico valore previsto.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
java, kotlin
Ambito
databases, testing
Tipo di issue
Funzionalità
Difficoltà
4/5
Tempo stimato
3-5 giorni
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
25/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.