use of io.realm.util.RealmThread in project realm-java by realm.
the class RealmTests method waitForChange_runWithRealmThread.
// waitForChange & stopWaitForChange within a simple Thread wrapper.
@Test
public void waitForChange_runWithRealmThread() throws InterruptedException {
final CountDownLatch bgRealmStarted = new CountDownLatch(1);
final CountDownLatch bgRealmFished = new CountDownLatch(1);
final AtomicBoolean bgRealmChangeResult = new AtomicBoolean(false);
final AtomicLong bgRealmResultSize = new AtomicLong(0);
RealmThread thread = new RealmThread(realmConfig, new RealmThread.RealmRunnable() {
@Override
public void run(Realm realm) {
bgRealmStarted.countDown();
bgRealmChangeResult.set(realm.waitForChange());
bgRealmResultSize.set(realm.where(AllTypes.class).count());
realm.close();
bgRealmFished.countDown();
}
});
thread.start();
TestHelper.awaitOrFail(bgRealmStarted);
populateTestRealm();
TestHelper.awaitOrFail(bgRealmFished);
assertTrue(bgRealmChangeResult.get());
assertEquals(TEST_DATA_SIZE, bgRealmResultSize.get());
}
use of io.realm.util.RealmThread in project realm-java by realm.
the class RealmTests method waitForChange_endRealmThread.
@Test
public void waitForChange_endRealmThread() throws InterruptedException {
final CountDownLatch bgRealmStarted = new CountDownLatch(1);
final CountDownLatch bgRealmFished = new CountDownLatch(1);
final AtomicBoolean bgRealmChangeResult = new AtomicBoolean(true);
RealmThread thread = new RealmThread(realmConfig, new RealmThread.RealmRunnable() {
@Override
public void run(Realm realm) {
bgRealmStarted.countDown();
bgRealmChangeResult.set(realm.waitForChange());
realm.close();
bgRealmFished.countDown();
}
});
thread.start();
TestHelper.awaitOrFail(bgRealmStarted);
thread.end();
TestHelper.awaitOrFail(bgRealmFished);
assertFalse(bgRealmChangeResult.get());
}
Aggregations