use of com.squareup.sqlbrite3.TestDb.Employee in project sqlbrite by square.
the class BriteDatabaseTest method transactionRollbackDoesNotNotify.
@Test
public void transactionRollbackDoesNotNotify() {
db.createQuery(TABLE_EMPLOYEE, SELECT_EMPLOYEES).subscribe(o);
o.assertCursor().hasRow("alice", "Alice Allison").hasRow("bob", "Bob Bobberson").hasRow("eve", "Eve Evenson").isExhausted();
Transaction transaction = db.newTransaction();
try {
db.insert(TABLE_EMPLOYEE, CONFLICT_NONE, employee("john", "John Johnson"));
db.insert(TABLE_EMPLOYEE, CONFLICT_NONE, employee("nick", "Nick Nickers"));
// No call to set successful.
} finally {
transaction.end();
}
o.assertNoMoreEvents();
}
use of com.squareup.sqlbrite3.TestDb.Employee in project sqlbrite by square.
the class BriteDatabaseTest method queryCreatedBeforeTransactionButSubscribedAfter.
@Test
public void queryCreatedBeforeTransactionButSubscribedAfter() {
Observable<Query> query = db.createQuery(TABLE_EMPLOYEE, SELECT_EMPLOYEES);
Transaction transaction = db.newTransaction();
try {
db.insert(TABLE_EMPLOYEE, CONFLICT_NONE, employee("john", "John Johnson"));
db.insert(TABLE_EMPLOYEE, CONFLICT_NONE, employee("nick", "Nick Nickers"));
transaction.markSuccessful();
} finally {
transaction.end();
}
query.subscribe(o);
o.assertCursor().hasRow("alice", "Alice Allison").hasRow("bob", "Bob Bobberson").hasRow("eve", "Eve Evenson").hasRow("john", "John Johnson").hasRow("nick", "Nick Nickers").isExhausted();
}
use of com.squareup.sqlbrite3.TestDb.Employee in project sqlbrite by square.
the class BriteDatabaseTest method queryMapToOne.
@Test
public void queryMapToOne() {
Employee employees = db.createQuery(TABLE_EMPLOYEE, SELECT_EMPLOYEES + " LIMIT 1").mapToOne(Employee.MAPPER).blockingFirst();
assertThat(employees).isEqualTo(new Employee("alice", "Alice Allison"));
}
use of com.squareup.sqlbrite3.TestDb.Employee in project sqlbrite by square.
the class BriteDatabaseTest method nonExclusiveTransactionWorks.
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
@SdkSuppress(minSdkVersion = Build.VERSION_CODES.HONEYCOMB)
@Test
public void nonExclusiveTransactionWorks() throws InterruptedException {
final CountDownLatch transactionStarted = new CountDownLatch(1);
final CountDownLatch transactionProceed = new CountDownLatch(1);
final CountDownLatch transactionCompleted = new CountDownLatch(1);
new Thread() {
@Override
public void run() {
Transaction transaction = db.newNonExclusiveTransaction();
transactionStarted.countDown();
try {
db.insert(TABLE_EMPLOYEE, CONFLICT_NONE, employee("hans", "Hans Hanson"));
transactionProceed.await(10, SECONDS);
} catch (InterruptedException e) {
throw new RuntimeException("Exception in transaction thread", e);
}
transaction.markSuccessful();
transaction.close();
transactionCompleted.countDown();
}
}.start();
assertThat(transactionStarted.await(10, SECONDS)).isTrue();
// Simple query
Employee employees = db.createQuery(TABLE_EMPLOYEE, SELECT_EMPLOYEES + " LIMIT 1").lift(Query.mapToOne(Employee.MAPPER)).blockingFirst();
assertThat(employees).isEqualTo(new Employee("alice", "Alice Allison"));
transactionProceed.countDown();
assertThat(transactionCompleted.await(10, SECONDS)).isTrue();
}
use of com.squareup.sqlbrite3.TestDb.Employee in project sqlbrite by square.
the class BriteDatabaseTest method nestedTransactionsOnlyNotifyOnce.
@Test
public void nestedTransactionsOnlyNotifyOnce() {
db.createQuery(TABLE_EMPLOYEE, SELECT_EMPLOYEES).subscribe(o);
o.assertCursor().hasRow("alice", "Alice Allison").hasRow("bob", "Bob Bobberson").hasRow("eve", "Eve Evenson").isExhausted();
Transaction transactionOuter = db.newTransaction();
try {
db.insert(TABLE_EMPLOYEE, CONFLICT_NONE, employee("john", "John Johnson"));
Transaction transactionInner = db.newTransaction();
try {
db.insert(TABLE_EMPLOYEE, CONFLICT_NONE, employee("nick", "Nick Nickers"));
transactionInner.markSuccessful();
} finally {
transactionInner.end();
}
transactionOuter.markSuccessful();
} finally {
transactionOuter.end();
}
o.assertCursor().hasRow("alice", "Alice Allison").hasRow("bob", "Bob Bobberson").hasRow("eve", "Eve Evenson").hasRow("john", "John Johnson").hasRow("nick", "Nick Nickers").isExhausted();
}
Aggregations