Search in sources :

Example 16 with Action1

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());
}
Also used : Action0(rx.functions.Action0) Action1(rx.functions.Action1) AllTypes(io.realm.entities.AllTypes) Dog(io.realm.entities.Dog) UiThreadTest(android.support.test.annotation.UiThreadTest) Test(org.junit.Test) UiThreadTest(android.support.test.annotation.UiThreadTest)

Example 17 with Action1

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());
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Action1(rx.functions.Action1) UiThreadTest(android.support.test.annotation.UiThreadTest) Test(org.junit.Test) UiThreadTest(android.support.test.annotation.UiThreadTest)

Example 18 with Action1

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();
}
Also used : Action1(rx.functions.Action1) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) AllTypes(io.realm.entities.AllTypes) RunTestInLooperThread(io.realm.rule.RunTestInLooperThread) UiThreadTest(android.support.test.annotation.UiThreadTest) Test(org.junit.Test)

Example 19 with Action1

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());
}
Also used : Action0(rx.functions.Action0) Action1(rx.functions.Action1) AllTypes(io.realm.entities.AllTypes) UiThreadTest(android.support.test.annotation.UiThreadTest) Test(org.junit.Test) UiThreadTest(android.support.test.annotation.UiThreadTest)

Example 20 with Action1

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();
}
Also used : Action1(rx.functions.Action1) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) RunTestInLooperThread(io.realm.rule.RunTestInLooperThread) UiThreadTest(android.support.test.annotation.UiThreadTest) Test(org.junit.Test)

Aggregations

Action1 (rx.functions.Action1)108 Test (org.junit.Test)33 Action0 (rx.functions.Action0)28 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)24 UiThreadTest (android.support.test.annotation.UiThreadTest)20 Observable (rx.Observable)20 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)12 HystrixRuntimeException (com.netflix.hystrix.exception.HystrixRuntimeException)11 ArrayList (java.util.ArrayList)11 CountDownLatch (java.util.concurrent.CountDownLatch)11 TestSubscriber (rx.observers.TestSubscriber)10 AllTypes (io.realm.entities.AllTypes)9 List (java.util.List)9 TestCircuitBreaker (com.netflix.hystrix.HystrixCircuitBreakerTest.TestCircuitBreaker)7 RunTestInLooperThread (io.realm.rule.RunTestInLooperThread)6 IOException (java.io.IOException)6 Func1 (rx.functions.Func1)6 PluginTestVerifier (com.navercorp.pinpoint.bootstrap.plugin.test.PluginTestVerifier)5 Method (java.lang.reflect.Method)5 AtomicReference (java.util.concurrent.atomic.AtomicReference)5