use of rx.functions.Action1 in project realm-java by realm.
the class RxJavaTests method realmList_closeInDoOnUnsubscribe.
@Test
@UiThreadTest
public void realmList_closeInDoOnUnsubscribe() {
realm.beginTransaction();
RealmList<Dog> list = realm.createObject(AllTypes.class).getColumnRealmList();
realm.commitTransaction();
Observable<RealmList<Dog>> observable = list.asObservable().doOnUnsubscribe(new Action0() {
@Override
public void call() {
realm.close();
}
});
subscription = observable.subscribe(new Action1<RealmList<Dog>>() {
@Override
public void call(RealmList<Dog> dogs) {
}
});
subscription.unsubscribe();
assertTrue(realm.isClosed());
}
use of rx.functions.Action1 in project realm-java by realm.
the class RxJavaTests method unsubscribe_sameThread.
@Test
@UiThreadTest
public void unsubscribe_sameThread() {
final AtomicBoolean subscribedNotified = new AtomicBoolean(false);
subscription = realm.asObservable().subscribe(new Action1<Realm>() {
@Override
public void call(Realm rxRealm) {
assertTrue(rxRealm == realm);
subscribedNotified.set(true);
}
});
assertEquals(1, realm.sharedRealm.realmNotifier.getListenersListSize());
subscription.unsubscribe();
assertEquals(0, realm.sharedRealm.realmNotifier.getListenersListSize());
}
use of rx.functions.Action1 in project realm-java by realm.
the class RxJavaTests method realmResults_emittedOnUpdate.
@Test
@RunTestInLooperThread
public void realmResults_emittedOnUpdate() {
final AtomicInteger subscriberCalled = new AtomicInteger(0);
Realm realm = looperThread.realm;
realm.beginTransaction();
RealmResults<AllTypes> results = realm.where(AllTypes.class).findAll();
realm.commitTransaction();
subscription = results.asObservable().subscribe(new Action1<RealmResults<AllTypes>>() {
@Override
public void call(RealmResults<AllTypes> allTypes) {
if (subscriberCalled.incrementAndGet() == 2) {
looperThread.testComplete();
}
}
});
realm.beginTransaction();
realm.createObject(AllTypes.class);
realm.commitTransaction();
}
use of rx.functions.Action1 in project realm-java by realm.
the class RxJavaTests method realmResults_closeInDoOnUnsubscribe.
@Test
@UiThreadTest
public void realmResults_closeInDoOnUnsubscribe() {
Observable<RealmResults<AllTypes>> observable = realm.where(AllTypes.class).findAll().asObservable().doOnUnsubscribe(new Action0() {
@Override
public void call() {
realm.close();
}
});
subscription = observable.subscribe(new Action1<RealmResults<AllTypes>>() {
@Override
public void call(RealmResults<AllTypes> allTypes) {
}
});
subscription.unsubscribe();
assertTrue(realm.isClosed());
}
use of rx.functions.Action1 in project realm-java by realm.
the class RxJavaTests method dynamicRealm_emittedOnUpdate.
@Test
@RunTestInLooperThread
public void dynamicRealm_emittedOnUpdate() {
final DynamicRealm dynamicRealm = DynamicRealm.getInstance(looperThread.realmConfiguration);
final AtomicInteger subscriberCalled = new AtomicInteger(0);
subscription = dynamicRealm.asObservable().subscribe(new Action1<DynamicRealm>() {
@Override
public void call(DynamicRealm rxRealm) {
if (subscriberCalled.incrementAndGet() == 2) {
dynamicRealm.close();
looperThread.testComplete();
}
}
});
dynamicRealm.beginTransaction();
dynamicRealm.createObject("AllTypes");
dynamicRealm.commitTransaction();
}
Aggregations