use of com.squareup.sqlbrite3.BriteDatabase.Transaction in project sqlbrite by square.
the class BriteDatabaseTest method querySubscribedToDuringTransactionOnDifferentThread.
@Test
public void querySubscribedToDuringTransactionOnDifferentThread() throws InterruptedException {
Transaction transaction = db.newTransaction();
final CountDownLatch latch = new CountDownLatch(1);
new Thread() {
@Override
public void run() {
db.createQuery(TABLE_EMPLOYEE, SELECT_EMPLOYEES).subscribe(o);
latch.countDown();
}
}.start();
// Wait for the thread to block on initial query.
Thread.sleep(500);
o.assertNoMoreEvents();
// Allow other queries to continue.
transaction.end();
// Wait for thread to observe initial query.
latch.await(500, MILLISECONDS);
o.assertCursor().hasRow("alice", "Alice Allison").hasRow("bob", "Bob Bobberson").hasRow("eve", "Eve Evenson").isExhausted();
}
Aggregations